diff --git a/mozilla/content/base/public/Makefile.in b/mozilla/content/base/public/Makefile.in index 2c868e66a9b..0ed2b6115b6 100644 --- a/mozilla/content/base/public/Makefile.in +++ b/mozilla/content/base/public/Makefile.in @@ -60,6 +60,7 @@ nsINameSpace.h \ nsINameSpaceManager.h \ nsINodeInfo.h \ nsIRangeUtils.h \ +nsIScriptElement.h \ nsIStyledContent.h \ nsIStyleRule.h \ nsIStyleRuleSupplier.h \ diff --git a/mozilla/content/base/public/nsIContent.h b/mozilla/content/base/public/nsIContent.h index 913f93fe985..3809e82be0d 100644 --- a/mozilla/content/base/public/nsIContent.h +++ b/mozilla/content/base/public/nsIContent.h @@ -468,7 +468,9 @@ public: /** XUL elements */ eXUL = 0x00000010, /** xml processing instructions */ - ePROCESSING_INSTRUCTION = 0x00000020 + ePROCESSING_INSTRUCTION = 0x00000020, + /** svg elements */ + eSVG = 0x00000040 }; /** diff --git a/mozilla/content/base/public/nsIScriptElement.h b/mozilla/content/base/public/nsIScriptElement.h new file mode 100644 index 00000000000..a49d9fcf1ee --- /dev/null +++ b/mozilla/content/base/public/nsIScriptElement.h @@ -0,0 +1,66 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * The contents of this file are subject to the Mozilla Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is Mozilla. + * + * The Initial Developer of the Original Code is Netscape + * Communications. Portions created by Netscape Communications are + * Copyright (C) 2001 by Netscape Communications. All + * Rights Reserved. + * + * Contributor(s): + * Vidur Apparao (original author) + */ + +#ifndef nsIScriptElement_h___ +#define nsIScriptElement_h___ + +#include "nsISupports.h" +#include "nsIURI.h" +#include "nsCOMPtr.h" + +#define NS_ISCRIPTELEMENT_IID \ +{ /*fa304da4-5e9c-45a6-a017-8cb011dc46b4 */ \ + 0xfa304da4, 0x5e9c, 0x45a6, \ + {0xa0, 0x17, 0x8c, 0xb0, 0x11, 0xdc, 0x46, 0xb4}} \ + +/** + * Internal interface implemented by script elements + */ +class nsIScriptElement : public nsISupports { +public: + NS_DEFINE_STATIC_IID_ACCESSOR(NS_ISCRIPTELEMENT_IID) + + /** + * Content type identifying the scripting language. Can be empty, in + * which case javascript will be assumed. + */ + virtual void GetScriptType(nsAString& type) = 0; + + /** + * Location of script source text. Can return null, in which case + * this is assumed to be an inline script element. + */ + virtual already_AddRefed GetScriptURI() = 0; + + /** + * Script source text for inline script elements. + */ + virtual void GetScriptText(nsAString& text) = 0; + + virtual void GetScriptCharset(nsAString& charset) = 0; + + virtual void SetScriptLineNumber(PRUint32 aLineNumber) = 0; + virtual PRUint32 GetScriptLineNumber() = 0; +}; + +#endif // nsIScriptElement_h___ diff --git a/mozilla/content/base/public/nsIScriptLoader.idl b/mozilla/content/base/public/nsIScriptLoader.idl index a813a45a770..ecdb7ace771 100644 --- a/mozilla/content/base/public/nsIScriptLoader.idl +++ b/mozilla/content/base/public/nsIScriptLoader.idl @@ -39,7 +39,7 @@ #include "nsISupports.idl" interface nsIDocument; -interface nsIDOMHTMLScriptElement; +interface nsIScriptElement; interface nsIScriptLoaderObserver; [scriptable, uuid(501209d3-7edf-437d-9948-3c6d1c08ef7a)] @@ -86,7 +86,7 @@ interface nsIScriptLoader : nsISupports { * @param aObserver An observer for this script load only * */ - void processScriptElement(in nsIDOMHTMLScriptElement aElement, + void processScriptElement(in nsIScriptElement aElement, in nsIScriptLoaderObserver aObserver); /** diff --git a/mozilla/content/base/public/nsIScriptLoaderObserver.idl b/mozilla/content/base/public/nsIScriptLoaderObserver.idl index cfdb9508895..03b747b1aa9 100644 --- a/mozilla/content/base/public/nsIScriptLoaderObserver.idl +++ b/mozilla/content/base/public/nsIScriptLoaderObserver.idl @@ -38,7 +38,7 @@ #include "nsISupports.idl" -interface nsIDOMHTMLScriptElement; +interface nsIScriptElement; interface nsIURI; [scriptable, uuid(501209d3-7edf-437d-9948-3c6d1c08ef7f)] @@ -65,7 +65,7 @@ interface nsIScriptLoaderObserver : nsISupports { * @param aScript String representation of the string to be evaluated. */ void scriptAvailable(in nsresult aResult, - in nsIDOMHTMLScriptElement aElement, + in nsIScriptElement aElement, in boolean aIsInline, in boolean aWasPending, in nsIURI aURI, @@ -85,7 +85,7 @@ interface nsIScriptLoaderObserver : nsISupports { * script was delayed? */ void scriptEvaluated(in nsresult aResult, - in nsIDOMHTMLScriptElement aElement, + in nsIScriptElement aElement, in boolean aIsInline, in boolean aWasPending); diff --git a/mozilla/content/base/src/nsContentSink.cpp b/mozilla/content/base/src/nsContentSink.cpp index 1d5e837442a..c13bacf6b0a 100644 --- a/mozilla/content/base/src/nsContentSink.cpp +++ b/mozilla/content/base/src/nsContentSink.cpp @@ -51,7 +51,7 @@ #include "nsNetUtil.h" #include "nsIHttpChannel.h" #include "nsIContent.h" -#include "nsIDOMHTMLScriptElement.h" +#include "nsIScriptElement.h" #include "nsIParser.h" #include "nsContentErrors.h" #include "nsIPresShell.h" @@ -107,7 +107,7 @@ NS_IMPL_ISUPPORTS1(nsScriptLoaderObserverProxy, nsIScriptLoaderObserver) NS_IMETHODIMP nsScriptLoaderObserverProxy::ScriptAvailable(nsresult aResult, - nsIDOMHTMLScriptElement *aElement, + nsIScriptElement *aElement, PRBool aIsInline, PRBool aWasPending, nsIURI *aURI, @@ -126,7 +126,7 @@ nsScriptLoaderObserverProxy::ScriptAvailable(nsresult aResult, NS_IMETHODIMP nsScriptLoaderObserverProxy::ScriptEvaluated(nsresult aResult, - nsIDOMHTMLScriptElement *aElement, + nsIScriptElement *aElement, PRBool aIsInline, PRBool aWasPending) { @@ -203,7 +203,7 @@ nsContentSink::StyleSheetLoaded(nsICSSStyleSheet* aSheet, NS_IMETHODIMP nsContentSink::ScriptAvailable(nsresult aResult, - nsIDOMHTMLScriptElement *aElement, + nsIScriptElement *aElement, PRBool aIsInline, PRBool aWasPending, nsIURI *aURI, @@ -250,7 +250,7 @@ nsContentSink::ScriptAvailable(nsresult aResult, NS_IMETHODIMP nsContentSink::ScriptEvaluated(nsresult aResult, - nsIDOMHTMLScriptElement *aElement, + nsIScriptElement *aElement, PRBool aIsInline, PRBool aWasPending) { diff --git a/mozilla/content/base/src/nsContentSink.h b/mozilla/content/base/src/nsContentSink.h index c71e33c3682..6d45644f458 100644 --- a/mozilla/content/base/src/nsContentSink.h +++ b/mozilla/content/base/src/nsContentSink.h @@ -113,7 +113,7 @@ protected: nsCOMPtr mCSSLoader; nsRefPtr mNodeInfoManager; - nsCOMArray mScriptElements; + nsCOMArray mScriptElements; nsCString mRef; // ScrollTo #ref PRBool mNeedToBlockParser; diff --git a/mozilla/content/base/src/nsGenericElement.cpp b/mozilla/content/base/src/nsGenericElement.cpp index ea03617a91a..702df06d15b 100644 --- a/mozilla/content/base/src/nsGenericElement.cpp +++ b/mozilla/content/base/src/nsGenericElement.cpp @@ -3586,3 +3586,26 @@ nsGenericElement::IndexOf(nsIContent* aPossibleChild) const return mAttrsAndChildren.IndexOfChild(aPossibleChild); } + +void +nsGenericElement::GetContentsAsText(nsAString& aText) +{ + aText.Truncate(); + PRInt32 children = GetChildCount(); + + nsCOMPtr tc; + nsAutoString textData; + + PRInt32 i; + for (i = 0; i < children; ++i) { + tc = do_QueryInterface(GetChildAt(i)); + if (tc) { + if (aText.IsEmpty()) { + tc->GetData(aText); + } else { + tc->GetData(textData); + aText.Append(textData); + } + } + } +} diff --git a/mozilla/content/base/src/nsGenericElement.h b/mozilla/content/base/src/nsGenericElement.h index eac631e3eaf..7554708b9c9 100644 --- a/mozilla/content/base/src/nsGenericElement.h +++ b/mozilla/content/base/src/nsGenericElement.h @@ -743,6 +743,17 @@ protected: return NS_REINTERPRET_CAST(nsIContent *, mParentPtrBits); } + /** + * GetContentsAsText will take all the textnodes that are children + * of |this| and concatenate the text in them into aText. It + * completely ignores any non-text-node children of |this|; in + * particular it does not descend into any children of |this| that + * happen to be container elements. + * + * @param aText the resulting text [OUT] + */ + void GetContentsAsText(nsAString& aText); + /** * Information about this type of node */ diff --git a/mozilla/content/base/src/nsScriptLoader.cpp b/mozilla/content/base/src/nsScriptLoader.cpp index d1887637338..f1cc9149a45 100644 --- a/mozilla/content/base/src/nsScriptLoader.cpp +++ b/mozilla/content/base/src/nsScriptLoader.cpp @@ -54,6 +54,7 @@ #include "nsIDOMWindow.h" #include "nsIHttpChannel.h" #include "nsIScriptElement.h" +#include "nsIDOMHTMLScriptElement.h" #include "nsIDocShell.h" #include "jsapi.h" #include "nsContentUtils.h" @@ -104,7 +105,7 @@ IntersectPrincipalCerts(nsIPrincipal *aOld, nsIPrincipal *aNew) class nsScriptLoadRequest : public nsISupports { public: - nsScriptLoadRequest(nsIDOMHTMLScriptElement* aElement, + nsScriptLoadRequest(nsIScriptElement* aElement, nsIScriptLoaderObserver* aObserver, const char* aVersionString); virtual ~nsScriptLoadRequest(); @@ -115,7 +116,7 @@ public: const nsAFlatString& aScript); void FireScriptEvaluated(nsresult aResult); - nsCOMPtr mElement; + nsCOMPtr mElement; nsCOMPtr mObserver; PRPackedBool mLoading; // Are we still waiting for a load to complete? PRPackedBool mWasPending; // Processed immediately or pending @@ -126,7 +127,7 @@ public: PRInt32 mLineNo; }; -nsScriptLoadRequest::nsScriptLoadRequest(nsIDOMHTMLScriptElement* aElement, +nsScriptLoadRequest::nsScriptLoadRequest(nsIScriptElement* aElement, nsIScriptLoaderObserver* aObserver, const char* aVersionString) : mElement(aElement), mObserver(aObserver), @@ -239,7 +240,7 @@ nsScriptLoader::RemoveObserver(nsIScriptLoaderObserver *aObserver) } PRBool -nsScriptLoader::InNonScriptingContainer(nsIDOMHTMLScriptElement* aScriptElement) +nsScriptLoader::InNonScriptingContainer(nsIScriptElement* aScriptElement) { nsCOMPtr node(do_QueryInterface(aScriptElement)); nsCOMPtr parent; @@ -285,7 +286,7 @@ nsScriptLoader::InNonScriptingContainer(nsIDOMHTMLScriptElement* aScriptElement) //