diff --git a/build/mac/build_scripts/MozillaBuildList.pm b/build/mac/build_scripts/MozillaBuildList.pm index 88fc8bdd895..1fae07fd54e 100644 --- a/build/mac/build_scripts/MozillaBuildList.pm +++ b/build/mac/build_scripts/MozillaBuildList.pm @@ -759,7 +759,8 @@ sub BuildClientDist() #HTMLPARSER InstallFromManifest(":mozilla:htmlparser:public:MANIFEST", "$distdirectory:htmlparser:"); - + InstallFromManifest(":mozilla:htmlparser:public:MANIFEST_IDL", "$distdirectory:idl:"); + #EXPAT InstallFromManifest(":mozilla:expat:xmlparse:MANIFEST", "$distdirectory:expat:"); diff --git a/content/base/src/nsPlainTextSerializer.h b/content/base/src/nsPlainTextSerializer.h index d9f8d7cee52..b65fb32ab1b 100644 --- a/content/base/src/nsPlainTextSerializer.h +++ b/content/base/src/nsPlainTextSerializer.h @@ -94,7 +94,6 @@ public: NS_IMETHOD OpenContainer(const nsIParserNode& aNode); NS_IMETHOD CloseContainer(const nsIParserNode& aNode); NS_IMETHOD AddLeaf(const nsIParserNode& aNode); - NS_IMETHOD NotifyError(const nsParserError* aError) { return NS_OK; } NS_IMETHOD AddComment(const nsIParserNode& aNode) { return NS_OK; } NS_IMETHOD AddProcessingInstruction(const nsIParserNode& aNode) { return NS_OK; } NS_IMETHOD AddDocTypeDecl(const nsIParserNode& aNode, PRInt32 aMode=0) { return NS_OK; } diff --git a/content/html/document/src/nsHTMLContentSink.cpp b/content/html/document/src/nsHTMLContentSink.cpp index 2a006fec89f..061514a75bd 100644 --- a/content/html/document/src/nsHTMLContentSink.cpp +++ b/content/html/document/src/nsHTMLContentSink.cpp @@ -232,12 +232,15 @@ public: NS_IMETHOD WillInterrupt(void); NS_IMETHOD WillResume(void); NS_IMETHOD SetParser(nsIParser* aParser); + NS_IMETHOD FlushPendingNotifications(); + NS_IMETHOD SetDocumentCharset(nsAWritableString& aCharset); + + + + // nsIHTMLContentSink NS_IMETHOD OpenContainer(const nsIParserNode& aNode); NS_IMETHOD CloseContainer(const nsIParserNode& aNode); NS_IMETHOD AddLeaf(const nsIParserNode& aNode); - NS_IMETHOD NotifyError(const nsParserError* aError); - NS_IMETHOD FlushPendingNotifications(); - NS_IMETHOD SetDocumentCharset(nsAWritableString& aCharset); NS_IMETHOD AddComment(const nsIParserNode& aNode); NS_IMETHOD AddProcessingInstruction(const nsIParserNode& aNode); NS_IMETHOD AddDocTypeDecl(const nsIParserNode& aNode, PRInt32 aMode=0); @@ -246,9 +249,6 @@ public: NS_IMETHOD WillProcessAToken(void); NS_IMETHOD DidProcessAToken(void); NS_IMETHOD NotifyTagObservers(nsIParserNode* aNode); - - - // nsIHTMLContentSink NS_IMETHOD BeginContext(PRInt32 aID); NS_IMETHOD EndContext(PRInt32 aID); NS_IMETHOD SetTitle(const nsString& aValue); @@ -5231,14 +5231,6 @@ HTMLContentSink::ProcessSTYLETag(const nsIParserNode& aNode) return rv; } -NS_IMETHODIMP -HTMLContentSink::NotifyError(const nsParserError* aError) -{ - // Errors in HTML? Who would have thought! - // Why are you telling us, parser. Deal with it yourself. - return NS_OK; -} - NS_IMETHODIMP HTMLContentSink::FlushPendingNotifications() { diff --git a/content/html/document/src/nsHTMLFragmentContentSink.cpp b/content/html/document/src/nsHTMLFragmentContentSink.cpp index 0135916985e..b5f8baf3f80 100644 --- a/content/html/document/src/nsHTMLFragmentContentSink.cpp +++ b/content/html/document/src/nsHTMLFragmentContentSink.cpp @@ -87,7 +87,6 @@ public: NS_IMETHOD OpenContainer(const nsIParserNode& aNode); NS_IMETHOD CloseContainer(const nsIParserNode& aNode); NS_IMETHOD AddLeaf(const nsIParserNode& aNode); - NS_IMETHOD NotifyError(const nsParserError* aError); NS_IMETHOD AddComment(const nsIParserNode& aNode); NS_IMETHOD AddProcessingInstruction(const nsIParserNode& aNode); NS_IMETHOD AddDocTypeDecl(const nsIParserNode& aNode, PRInt32 aMode=0); @@ -663,12 +662,6 @@ nsHTMLFragmentContentSink::AddLeaf(const nsIParserNode& aNode) return result; } -NS_IMETHODIMP -nsHTMLFragmentContentSink::NotifyError(const nsParserError* aError) -{ - return NS_OK; -} - NS_IMETHODIMP nsHTMLFragmentContentSink::AddComment(const nsIParserNode& aNode) { diff --git a/content/shared/public/nsXBLAtomList.h b/content/shared/public/nsXBLAtomList.h index 148023deae0..01037162f06 100644 --- a/content/shared/public/nsXBLAtomList.h +++ b/content/shared/public/nsXBLAtomList.h @@ -96,6 +96,7 @@ XBL_ATOM(content, "content") XBL_ATOM(constructor, "constructor") XBL_ATOM(destructor, "destructor") XBL_ATOM(inheritstyle, "inheritstyle") +XBL_ATOM(button, "button") diff --git a/content/xbl/src/nsXBLAtomList.h b/content/xbl/src/nsXBLAtomList.h index 148023deae0..01037162f06 100644 --- a/content/xbl/src/nsXBLAtomList.h +++ b/content/xbl/src/nsXBLAtomList.h @@ -96,6 +96,7 @@ XBL_ATOM(content, "content") XBL_ATOM(constructor, "constructor") XBL_ATOM(destructor, "destructor") XBL_ATOM(inheritstyle, "inheritstyle") +XBL_ATOM(button, "button") diff --git a/content/xbl/src/nsXBLContentSink.cpp b/content/xbl/src/nsXBLContentSink.cpp index 29c27d654da..c5592982c63 100644 --- a/content/xbl/src/nsXBLContentSink.cpp +++ b/content/xbl/src/nsXBLContentSink.cpp @@ -103,199 +103,6 @@ nsXBLContentSink::Init(nsIDocument* aDoc, return rv; } -PRBool -nsXBLContentSink::OnOpenContainer(const nsIParserNode& aNode, PRInt32 aNameSpaceID, nsIAtom* aTagName) -{ - PRBool ret = PR_TRUE; - if (aNameSpaceID == kNameSpaceID_XBL) { - if (aTagName == nsXBLAtoms::bindings) { - NS_NewXBLDocumentInfo(mDocument, &mDocInfo); - if (!mDocInfo) - return NS_ERROR_FAILURE; - - nsCOMPtr bindingManager; - mDocument->GetBindingManager(getter_AddRefs(bindingManager)); - bindingManager->PutXBLDocumentInfo(mDocInfo); - - nsCOMPtr url; - mDocument->GetDocumentURL(getter_AddRefs(url)); - - PRBool isChrome = PR_FALSE; - PRBool isRes = PR_FALSE; - - url->SchemeIs("chrome", &isChrome); - url->SchemeIs("resource", &isRes); - mIsChromeOrResource = isChrome || isRes; - - nsIXBLDocumentInfo* info = mDocInfo; - NS_RELEASE(info); // We keep a weak ref. We've created a cycle between doc/binding manager/doc info. - } - else if (aTagName == nsXBLAtoms::binding) - mState = eXBL_InBinding; - else if (aTagName == nsXBLAtoms::handlers) { - mState = eXBL_InHandlers; - ret = PR_FALSE; // The XML content sink should not do anything with . - } - else if (aTagName == nsXBLAtoms::handler) { - mSecondaryState = eXBL_InHandler; - ConstructHandler(aNode); - ret = PR_FALSE; - } - else if (aTagName == nsXBLAtoms::resources) { - mState = eXBL_InResources; - ret = PR_FALSE; // The XML content sink should ignore all . - } - else if (mState == eXBL_InResources) { - if (aTagName == nsXBLAtoms::stylesheet || aTagName == nsXBLAtoms::image) - ConstructResource(aNode, aTagName); - ret = PR_FALSE; // The XML content sink should ignore everything within a block. - } - else if (aTagName == nsXBLAtoms::implementation) { - mState = eXBL_InImplementation; - ConstructImplementation(aNode); - ret = PR_FALSE; // The XML content sink should ignore the . - } - else if (mState == eXBL_InImplementation) { - if (aTagName == nsXBLAtoms::constructor) { - mSecondaryState = eXBL_InConstructor; - nsCOMPtr newHandler; - NS_NewXBLPrototypeHandler(nsnull, nsnull, nsnull, nsnull, - nsnull, nsnull, nsnull, nsnull, nsnull, - getter_AddRefs(newHandler)); - newHandler->SetEventName(nsXBLAtoms::constructor); - mBinding->SetConstructor(newHandler); - } - else if (aTagName == nsXBLAtoms::destructor) { - mSecondaryState = eXBL_InDestructor; - nsCOMPtr newHandler; - NS_NewXBLPrototypeHandler(nsnull, nsnull, nsnull, nsnull, - nsnull, nsnull, nsnull, nsnull, nsnull, - getter_AddRefs(newHandler)); - newHandler->SetEventName(nsXBLAtoms::destructor); - mBinding->SetDestructor(newHandler); - } - else if (aTagName == nsXBLAtoms::field) { - mSecondaryState = eXBL_InField; - ConstructField(aNode); - } - else if (aTagName == nsXBLAtoms::property) { - mSecondaryState = eXBL_InProperty; - ConstructProperty(aNode); - } - else if (aTagName == nsXBLAtoms::getter) - mSecondaryState = eXBL_InGetter; - else if (aTagName == nsXBLAtoms::setter) - mSecondaryState = eXBL_InSetter; - else if (aTagName == nsXBLAtoms::method) { - mSecondaryState = eXBL_InMethod; - ConstructMethod(aNode); - } - else if (aTagName == nsXBLAtoms::parameter) - ConstructParameter(aNode); - else if (aTagName == nsXBLAtoms::body) - mSecondaryState = eXBL_InBody; - - ret = PR_FALSE; // Ignore everything we encounter inside an block. - } - } - - return ret; -} - -NS_IMETHODIMP -nsXBLContentSink::OpenContainer(const nsIParserNode& aNode) -{ - nsresult rv = nsXMLContentSink::OpenContainer(aNode); - if (NS_FAILED(rv)) - return rv; - - if (mState == eXBL_InBinding && !mBinding) - ConstructBinding(); - - return rv; -} - -NS_IMETHODIMP -nsXBLContentSink::CloseContainer(const nsIParserNode& aNode) -{ - FlushText(); - - if (mState != eXBL_InDocument) { - nsCOMPtr nameSpacePrefix, tagAtom; - - SplitXMLName(aNode.GetText(), getter_AddRefs(nameSpacePrefix), - getter_AddRefs(tagAtom)); - - PRInt32 nameSpaceID = GetNameSpaceId(nameSpacePrefix); - if (nameSpaceID == kNameSpaceID_XBL) { - if (mState == eXBL_InHandlers) { - if (tagAtom == nsXBLAtoms::handlers) { - mState = eXBL_InBinding; - mHandler = nsnull; - } - else if (tagAtom == nsXBLAtoms::handler) - mSecondaryState = eXBL_None; - return NS_OK; - } - else if (mState == eXBL_InResources) { - if (tagAtom == nsXBLAtoms::resources) - mState = eXBL_InBinding; - return NS_OK; - } - else if (mState == eXBL_InImplementation) { - if (tagAtom == nsXBLAtoms::implementation) - mState = eXBL_InBinding; - else if (tagAtom == nsXBLAtoms::property) { - mSecondaryState = eXBL_None; - mProperty = nsnull; - } - else if (tagAtom == nsXBLAtoms::method) { - mSecondaryState = eXBL_None; - mMethod = nsnull; - } - else if (tagAtom == nsXBLAtoms::field) { - mSecondaryState = eXBL_None; - mField = nsnull; - } - else if (tagAtom == nsXBLAtoms::constructor || - tagAtom == nsXBLAtoms::destructor) - mSecondaryState = eXBL_None; - else if (tagAtom == nsXBLAtoms::getter || - tagAtom == nsXBLAtoms::setter) - mSecondaryState = eXBL_InProperty; - else if (tagAtom == nsXBLAtoms::parameter || - tagAtom == nsXBLAtoms::body) - mSecondaryState = eXBL_InMethod; - return NS_OK; - } - - nsresult rv = nsXMLContentSink::CloseContainer(aNode); - if (NS_FAILED(rv)) - return rv; - - if (mState == eXBL_InImplementation && tagAtom == nsXBLAtoms::implementation) - mState = eXBL_InBinding; - else if (mState == eXBL_InBinding && tagAtom == nsXBLAtoms::binding) { - mState = eXBL_InDocument; - mBinding->Initialize(); - mBinding = nsnull; // Clear our current binding ref. - } - - return NS_OK; - } - } - - return nsXMLContentSink::CloseContainer(aNode); -} - -NS_IMETHODIMP -nsXBLContentSink::AddCDATASection(const nsIParserNode& aNode) -{ - if (mState == eXBL_InHandlers || mState == eXBL_InImplementation) - return AddText(aNode.GetText()); - return nsXMLContentSink::AddCDATASection(aNode); -} - nsresult nsXBLContentSink::FlushText(PRBool aCreateTextNode, PRBool* aDidFlush) @@ -378,29 +185,579 @@ nsXBLContentSink::FlushText(PRBool aCreateTextNode, return nsXMLContentSink::FlushText(aCreateTextNode, aDidFlush); } +NS_IMETHODIMP +nsXBLContentSink::HandleStartElement(const PRUnichar *aName, + const PRUnichar **aAtts, + const PRUint32 aAttsCount, + const PRUint32 aIndex, + const PRUint32 aLineNumber) +{ + nsresult rv = nsXMLContentSink::HandleStartElement(aName,aAtts,aAttsCount,aIndex,aLineNumber); + if (NS_FAILED(rv)) + return rv; + + if (mState == eXBL_InBinding && !mBinding) + ConstructBinding(); + + return rv; +} + +NS_IMETHODIMP +nsXBLContentSink::HandleEndElement(const PRUnichar *aName) +{ + FlushText(); + + if (mState != eXBL_InDocument) { + nsCOMPtr nameSpacePrefix, tagAtom; + + SplitXMLName(nsDependentString(aName), getter_AddRefs(nameSpacePrefix), + getter_AddRefs(tagAtom)); + + PRInt32 nameSpaceID = GetNameSpaceId(nameSpacePrefix); + if (nameSpaceID == kNameSpaceID_XBL) { + if (mState == eXBL_InHandlers) { + if (tagAtom == nsXBLAtoms::handlers) { + mState = eXBL_InBinding; + mHandler = nsnull; + } + else if (tagAtom == nsXBLAtoms::handler) + mSecondaryState = eXBL_None; + return NS_OK; + } + else if (mState == eXBL_InResources) { + if (tagAtom == nsXBLAtoms::resources) + mState = eXBL_InBinding; + return NS_OK; + } + else if (mState == eXBL_InImplementation) { + if (tagAtom == nsXBLAtoms::implementation) + mState = eXBL_InBinding; + else if (tagAtom == nsXBLAtoms::property) { + mSecondaryState = eXBL_None; + mProperty = nsnull; + } + else if (tagAtom == nsXBLAtoms::method) { + mSecondaryState = eXBL_None; + mMethod = nsnull; + } + else if (tagAtom == nsXBLAtoms::field) { + mSecondaryState = eXBL_None; + mField = nsnull; + } + else if (tagAtom == nsXBLAtoms::constructor || + tagAtom == nsXBLAtoms::destructor) + mSecondaryState = eXBL_None; + else if (tagAtom == nsXBLAtoms::getter || + tagAtom == nsXBLAtoms::setter) + mSecondaryState = eXBL_InProperty; + else if (tagAtom == nsXBLAtoms::parameter || + tagAtom == nsXBLAtoms::body) + mSecondaryState = eXBL_InMethod; + return NS_OK; + } + + nsresult rv = nsXMLContentSink::HandleEndElement(aName); + if (NS_FAILED(rv)) + return rv; + + if (mState == eXBL_InImplementation && tagAtom == nsXBLAtoms::implementation) + mState = eXBL_InBinding; + else if (mState == eXBL_InBinding && tagAtom == nsXBLAtoms::binding) { + mState = eXBL_InDocument; + mBinding->Initialize(); + mBinding = nsnull; // Clear our current binding ref. + } + + return NS_OK; + } + } + + return nsXMLContentSink::HandleEndElement(aName); +} + +NS_IMETHODIMP +nsXBLContentSink::HandleCDataSection(const PRUnichar *aData, + PRUint32 aLength) +{ + if (mState == eXBL_InHandlers || mState == eXBL_InImplementation) + return AddText(aData, aLength); + return nsXMLContentSink::HandleCDataSection(aData, aLength); +} + +PRBool +nsXBLContentSink::OnOpenContainer(const PRUnichar **aAtts, + PRUint32 aAttsCount, + PRInt32 aNameSpaceID, + nsIAtom* aTagName) +{ + PRBool ret = PR_TRUE; + if (aNameSpaceID == kNameSpaceID_XBL) { + if (aTagName == nsXBLAtoms::bindings) { + NS_NewXBLDocumentInfo(mDocument, &mDocInfo); + if (!mDocInfo) + return NS_ERROR_FAILURE; + + nsCOMPtr bindingManager; + mDocument->GetBindingManager(getter_AddRefs(bindingManager)); + bindingManager->PutXBLDocumentInfo(mDocInfo); + + nsCOMPtr url; + mDocument->GetDocumentURL(getter_AddRefs(url)); + + PRBool isChrome = PR_FALSE; + PRBool isRes = PR_FALSE; + + url->SchemeIs("chrome", &isChrome); + url->SchemeIs("resource", &isRes); + mIsChromeOrResource = isChrome || isRes; + + nsIXBLDocumentInfo* info = mDocInfo; + NS_RELEASE(info); // We keep a weak ref. We've created a cycle between doc/binding manager/doc info. + } + else if (aTagName == nsXBLAtoms::binding) + mState = eXBL_InBinding; + else if (aTagName == nsXBLAtoms::handlers) { + mState = eXBL_InHandlers; + ret = PR_FALSE; // The XML content sink should not do anything with . + } + else if (aTagName == nsXBLAtoms::handler) { + mSecondaryState = eXBL_InHandler; + ConstructHandler(aAtts); + ret = PR_FALSE; + } + else if (aTagName == nsXBLAtoms::resources) { + mState = eXBL_InResources; + ret = PR_FALSE; // The XML content sink should ignore all . + } + else if (mState == eXBL_InResources) { + if (aTagName == nsXBLAtoms::stylesheet || aTagName == nsXBLAtoms::image) + ConstructResource(aAtts, aTagName); + ret = PR_FALSE; // The XML content sink should ignore everything within a block. + } + else if (aTagName == nsXBLAtoms::implementation) { + mState = eXBL_InImplementation; + ConstructImplementation(aAtts); + ret = PR_FALSE; // The XML content sink should ignore the . + } + else if (mState == eXBL_InImplementation) { + if (aTagName == nsXBLAtoms::constructor) { + mSecondaryState = eXBL_InConstructor; + nsCOMPtr newHandler; + NS_NewXBLPrototypeHandler(nsnull, nsnull, nsnull, nsnull, + nsnull, nsnull, nsnull, nsnull, nsnull, + getter_AddRefs(newHandler)); + newHandler->SetEventName(nsXBLAtoms::constructor); + mBinding->SetConstructor(newHandler); + } + else if (aTagName == nsXBLAtoms::destructor) { + mSecondaryState = eXBL_InDestructor; + nsCOMPtr newHandler; + NS_NewXBLPrototypeHandler(nsnull, nsnull, nsnull, nsnull, + nsnull, nsnull, nsnull, nsnull, nsnull, + getter_AddRefs(newHandler)); + newHandler->SetEventName(nsXBLAtoms::destructor); + mBinding->SetDestructor(newHandler); + } + else if (aTagName == nsXBLAtoms::field) { + mSecondaryState = eXBL_InField; + ConstructField(aAtts); + } + else if (aTagName == nsXBLAtoms::property) { + mSecondaryState = eXBL_InProperty; + ConstructProperty(aAtts); + } + else if (aTagName == nsXBLAtoms::getter) + mSecondaryState = eXBL_InGetter; + else if (aTagName == nsXBLAtoms::setter) + mSecondaryState = eXBL_InSetter; + else if (aTagName == nsXBLAtoms::method) { + mSecondaryState = eXBL_InMethod; + ConstructMethod(aAtts); + } + else if (aTagName == nsXBLAtoms::parameter) + ConstructParameter(aAtts); + else if (aTagName == nsXBLAtoms::body) + mSecondaryState = eXBL_InBody; + + ret = PR_FALSE; // Ignore everything we encounter inside an block. + } + } + + return ret; +} + +void +nsXBLContentSink::ConstructBinding() +{ + nsCOMPtr binding = getter_AddRefs(GetCurrentContent()); + nsAutoString id; + binding->GetAttr(kNameSpaceID_None, nsHTMLAtoms::id, id); + nsCAutoString cid; cid.AssignWithConversion(id); + + if (!cid.IsEmpty()) { + NS_NewXBLPrototypeBinding(cid, binding, mDocInfo, getter_AddRefs(mBinding)); + mDocInfo->SetPrototypeBinding(cid, mBinding); + binding->UnsetAttr(kNameSpaceID_None, nsHTMLAtoms::id, PR_FALSE); + } +} + + +void +nsXBLContentSink::ConstructHandler(const PRUnichar **aAtts) +{ + nsCOMPtr nameSpacePrefix, nameAtom; + + const PRUnichar* event = nsnull; + const PRUnichar* modifiers = nsnull; + const PRUnichar* button = nsnull; + const PRUnichar* clickcount = nsnull; + const PRUnichar* keycode = nsnull; + const PRUnichar* charcode = nsnull; + const PRUnichar* phase = nsnull; + const PRUnichar* command = nsnull; + const PRUnichar* action = nsnull; + + for (; *aAtts; aAtts += 2) { + // Get upper-cased key + + SplitXMLName(nsDependentString(aAtts[0]), getter_AddRefs(nameSpacePrefix), + getter_AddRefs(nameAtom)); + + if (nameSpacePrefix || nameAtom == nsLayoutAtoms::xmlnsNameSpace) { + continue; + } + + // Is this attribute one of the ones we care about? + if (nameAtom == nsXBLAtoms::event) + event = aAtts[1]; + else if (nameAtom == nsXBLAtoms::modifiers) + modifiers = aAtts[1]; + else if (nameAtom == nsXBLAtoms::button) + button = aAtts[1]; + else if (nameAtom == nsXBLAtoms::clickcount) + clickcount = aAtts[1]; + else if (nameAtom == nsXBLAtoms::keycode) + keycode = aAtts[1]; + else if (nameAtom == nsXBLAtoms::key || nameAtom == nsXBLAtoms::charcode) + charcode = aAtts[1]; + else if (nameAtom == nsXBLAtoms::phase) + phase = aAtts[1]; + else if (nameAtom == nsXBLAtoms::command) + command = aAtts[1]; + else if (nameAtom == nsXBLAtoms::action) + action = aAtts[1]; + else { + // Nope, it's some irrelevant attribute. Ignore it and move on. + } + } + + if (command && !mIsChromeOrResource) + // Make sure the XBL doc is chrome or resource if we have a command + // shorthand syntax. + return; // Don't even make this handler. + + // All of our pointers are now filled in. Construct our handler with all of these + // parameters. + nsCOMPtr newHandler; + NS_NewXBLPrototypeHandler(event? &nsDependentString(event):0, + phase? &nsDependentString(phase):0, + action? &nsDependentString(action):0, + command? &nsDependentString(command):0, + keycode? &nsDependentString(keycode):0, + charcode? &nsDependentString(charcode):0, + modifiers? &nsDependentString(modifiers):0, + button? &nsDependentString(button):0, + clickcount? &nsDependentString(clickcount):0, + getter_AddRefs(newHandler)); + if (newHandler) { + // Add this handler to our chain of handlers. + if (mHandler) + mHandler->SetNextHandler(newHandler); // Already have a chain. Just append to the end. + else + mBinding->SetPrototypeHandlers(newHandler); // We're the first handler in the chain. + + mHandler = newHandler; // Adjust our mHandler pointer to point to the new last handler in the chain. + } +} + +void +nsXBLContentSink::ConstructResource(const PRUnichar **aAtts, + nsIAtom* aResourceType) +{ + if (!mBinding) + return; + + nsCOMPtr nameSpacePrefix, nameAtom; + for (; *aAtts; aAtts += 2) { + // Get upper-cased key + const nsDependentString key(aAtts[0]); + + SplitXMLName(key, getter_AddRefs(nameSpacePrefix), + getter_AddRefs(nameAtom)); + + if (nameSpacePrefix || nameAtom == nsLayoutAtoms::xmlnsNameSpace) { + continue; + } + + // Is this attribute one of the ones we care about? + if (key.Equals(NS_LITERAL_STRING("src"))) { + mBinding->AddResource(aResourceType, nsDependentString(aAtts[1])); + break; + } + } +} + +void +nsXBLContentSink::ConstructImplementation(const PRUnichar **aAtts) +{ + mImplementation = nsnull; + mImplMember = nsnull; + + if (!mBinding) + return; + + const PRUnichar* name = nsnull; + + nsCOMPtr nameSpacePrefix, nameAtom; + for (; *aAtts; aAtts +=2) { + // Get upper-cased key + + SplitXMLName(nsDependentString(aAtts[0]), getter_AddRefs(nameSpacePrefix), + getter_AddRefs(nameAtom)); + + if (nameSpacePrefix || nameAtom == nsLayoutAtoms::xmlnsNameSpace) { + continue; + } + + // Is this attribute one of the ones we care about? + if (nameAtom == nsXBLAtoms::name) { + name = aAtts[1]; + } + else if (nameAtom == nsXBLAtoms::implements) { + mBinding->ConstructInterfaceTable(nsDependentString(aAtts[1])); + } + } + + NS_NewXBLProtoImpl(mBinding, name? &nsDependentString(name):0, &mImplementation); +} + +void +nsXBLContentSink::ConstructField(const PRUnichar **aAtts) +{ + nsCOMPtr nameSpacePrefix, nameAtom; + + const PRUnichar* name = nsnull; + const PRUnichar* readonly = nsnull; + + for (; *aAtts; aAtts += 2) { + // Get upper-cased key + SplitXMLName(nsDependentString(aAtts[0]), getter_AddRefs(nameSpacePrefix), + getter_AddRefs(nameAtom)); + + if (nameSpacePrefix || nameAtom == nsLayoutAtoms::xmlnsNameSpace) + continue; + + // Is this attribute one of the ones we care about? + if (nameAtom == nsXBLAtoms::name) { + name = aAtts[1]; + } + else if (nameAtom == nsXBLAtoms::readonly) { + readonly = aAtts[1]; + } + } + + // All of our pointers are now filled in. Construct our field with all of these + // parameters. + mField = new nsXBLProtoImplField(name? &nsDependentString(name):0, + readonly? &nsDependentString(readonly):0); + if (mField) { + // Add this member to our chain. + if (mImplMember) + mImplMember->SetNext(mField); // Already have a chain. Just append to the end. + else + mImplementation->SetMemberList(mField); // We're the first member in the chain. + + mImplMember = mField; // Adjust our pointer to point to the new last member in the chain. + } +} + +void +nsXBLContentSink::ConstructProperty(const PRUnichar **aAtts) +{ + nsCOMPtr nameSpacePrefix, nameAtom; + + const PRUnichar* name = nsnull; + const PRUnichar* readonly = nsnull; + const PRUnichar* onget = nsnull; + const PRUnichar* onset = nsnull; + + for (; *aAtts; aAtts += 2) { + // Get upper-cased key + SplitXMLName(nsDependentString(aAtts[0]), getter_AddRefs(nameSpacePrefix), + getter_AddRefs(nameAtom)); + + if (nameSpacePrefix || nameAtom == nsLayoutAtoms::xmlnsNameSpace) { + continue; + } + + // Is this attribute one of the ones we care about? + if (nameAtom == nsXBLAtoms::name) { + name = aAtts[1]; + } + else if (nameAtom == nsXBLAtoms::readonly) { + readonly = aAtts[1]; + } + else if (nameAtom == nsXBLAtoms::onget) { + onget = aAtts[1]; + } + else if (nameAtom == nsXBLAtoms::onset) { + onset = aAtts[1]; + } + } + + // All of our pointers are now filled in. Construct our property with all of these + // parameters. + mProperty = new nsXBLProtoImplProperty(name? &nsDependentString(name):0, + onget? &nsDependentString(onget):0, + onset? &nsDependentString(onset):0, + readonly? &nsDependentString(readonly):0); + if (mProperty) { + // Add this member to our chain. + if (mImplMember) + mImplMember->SetNext(mProperty); // Already have a chain. Just append to the end. + else + mImplementation->SetMemberList(mProperty); // We're the first member in the chain. + + mImplMember = mProperty; // Adjust our pointer to point to the new last member in the chain. + } +} + +void +nsXBLContentSink::ConstructMethod(const PRUnichar **aAtts) +{ + mMethod = nsnull; + + nsCOMPtr nameSpacePrefix, nameAtom; + + for(; *aAtts; aAtts += 2) { + // Get upper-cased key + SplitXMLName(nsDependentString(aAtts[0]), getter_AddRefs(nameSpacePrefix), + getter_AddRefs(nameAtom)); + + if (nameSpacePrefix || nameAtom == nsLayoutAtoms::xmlnsNameSpace) { + continue; + } + + // Is this attribute one of the ones we care about? + if (nameAtom == nsXBLAtoms::name) { + mMethod = new nsXBLProtoImplMethod(nsDependentString(aAtts[1])); + break; + } + } + + if (mMethod) { + // Add this member to our chain. + if (mImplMember) + mImplMember->SetNext(mMethod); // Already have a chain. Just append to the end. + else + mImplementation->SetMemberList(mMethod); // We're the first member in the chain. + + mImplMember = mMethod; // Adjust our pointer to point to the new last member in the chain. + } +} + +void +nsXBLContentSink::ConstructParameter(const PRUnichar **aAtts) +{ + if (!mMethod) + return; + + nsCOMPtr nameSpacePrefix, nameAtom; + + for (; *aAtts; aAtts += 2) { + // Get upper-cased key + SplitXMLName(nsDependentString(aAtts[0]), getter_AddRefs(nameSpacePrefix), + getter_AddRefs(nameAtom)); + + if (nameSpacePrefix || nameAtom == nsLayoutAtoms::xmlnsNameSpace) { + continue; + } + + // Is this attribute one of the ones we care about? + if (nameAtom == nsXBLAtoms::name) { + mMethod->AddParameter(nsDependentString(aAtts[1])); + break; + } + } +} + nsresult -nsXBLContentSink::AddAttributesToXULPrototype(const nsIParserNode& aNode, nsXULPrototypeElement* aElement) +nsXBLContentSink::CreateElement(const PRUnichar** aAtts, + PRUint32 aAttsCount, + PRInt32 aNameSpaceID, + nsINodeInfo* aNodeInfo, + nsIContent** aResult) +{ + if (aNameSpaceID == nsXULAtoms::nameSpaceID) { + nsXULPrototypeElement* prototype = new nsXULPrototypeElement(0); + if (!prototype) + return NS_ERROR_OUT_OF_MEMORY; + + prototype->mNodeInfo = aNodeInfo; + + // Reset the refcnt to 0. Normally XUL prototype elements get a refcnt of 1 + // to represent ownership by the XUL prototype document. In our case we have + // no prototype document, and our initial ref count of 1 will come from being + // wrapped by a real XUL element in the Create call below. + prototype->mRefCnt = 0; + + AddAttributesToXULPrototype(aAtts, aAttsCount, prototype); + + // Following this function call, the prototype's ref count will be 1. + nsresult rv = nsXULElement::Create(prototype, mDocument, PR_FALSE, aResult); + + if (NS_FAILED(rv)) return rv; + return NS_OK; + } + else + return nsXMLContentSink::CreateElement(aAtts, aAttsCount, aNameSpaceID, aNodeInfo, aResult); +} + +nsresult +nsXBLContentSink::AddAttributes(const PRUnichar** aAtts, + nsIContent* aContent, + PRBool aIsHTML) +{ + if (aContent->IsContentOfType(nsIContent::eXUL)) + return NS_OK; // Nothing to do, since the proto already has the attrs. + else + return nsXMLContentSink::AddAttributes(aAtts, aContent, aIsHTML); +} + +nsresult +nsXBLContentSink::AddAttributesToXULPrototype(const PRUnichar **aAtts, + PRUint32 aAttsCount, + nsXULPrototypeElement* aElement) { // Add tag attributes to the element nsresult rv; - PRInt32 count = aNode.GetAttributeCount(); // Create storage for the attributes nsXULPrototypeAttribute* attrs = nsnull; - if (count > 0) { - attrs = new nsXULPrototypeAttribute[count]; + if (aAttsCount > 0) { + attrs = new nsXULPrototypeAttribute[aAttsCount]; if (!attrs) return NS_ERROR_OUT_OF_MEMORY; } aElement->mAttributes = attrs; - aElement->mNumAttributes = count; + aElement->mNumAttributes = aAttsCount; // Copy the attributes into the prototype nsCOMPtr nameSpacePrefix, nameAtom; - for (PRInt32 i = 0; i < count; i++) { - const nsAReadableString& key = aNode.GetKeyAt(i); + for (; *aAtts; aAtts += 2) { + const nsDependentString key(aAtts[0]); SplitXMLName(key, getter_AddRefs(nameSpacePrefix), getter_AddRefs(nameAtom)); @@ -425,8 +782,7 @@ nsXBLContentSink::AddAttributesToXULPrototype(const nsIParserNode& aNode, nsXULP mNodeInfoManager->GetNodeInfo(nameAtom, nameSpacePrefix, nameSpaceID, *getter_AddRefs(attrs->mNodeInfo)); - const nsAReadableString& valueStr = aNode.GetValueAt(i); - attrs->mValue.SetValue(valueStr); + attrs->mValue.SetValue(nsDependentString(aAtts[1])); ++attrs; } @@ -468,336 +824,3 @@ nsXBLContentSink::AddAttributesToXULPrototype(const nsIParserNode& aNode, nsXULP return NS_OK; } - -nsresult -nsXBLContentSink::CreateElement(const nsIParserNode& aNode, PRInt32 aNameSpaceID, - nsINodeInfo* aNodeInfo, nsIContent** aResult) -{ - if (aNameSpaceID == nsXULAtoms::nameSpaceID) { - nsXULPrototypeElement* prototype = new nsXULPrototypeElement(0); - if (!prototype) - return NS_ERROR_OUT_OF_MEMORY; - - prototype->mNodeInfo = aNodeInfo; - - // Reset the refcnt to 0. Normally XUL prototype elements get a refcnt of 1 - // to represent ownership by the XUL prototype document. In our case we have - // no prototype document, and our initial ref count of 1 will come from being - // wrapped by a real XUL element in the Create call below. - prototype->mRefCnt = 0; - - AddAttributesToXULPrototype(aNode, prototype); - - // Following this function call, the prototype's ref count will be 1. - nsresult rv = nsXULElement::Create(prototype, mDocument, PR_FALSE, aResult); - - if (NS_FAILED(rv)) return rv; - return NS_OK; - } - else - return nsXMLContentSink::CreateElement(aNode, aNameSpaceID, aNodeInfo, aResult); -} - -nsresult -nsXBLContentSink::AddAttributes(const nsIParserNode& aNode, - nsIContent* aContent, - PRBool aIsHTML) -{ - if (aContent->IsContentOfType(nsIContent::eXUL)) - return NS_OK; // Nothing to do, since the proto already has the attrs. - else - return nsXMLContentSink::AddAttributes(aNode, aContent, aIsHTML); -} - -void -nsXBLContentSink::ConstructBinding() -{ - nsCOMPtr binding = getter_AddRefs(GetCurrentContent()); - nsAutoString id; - binding->GetAttr(kNameSpaceID_None, nsHTMLAtoms::id, id); - nsCAutoString cid; cid.AssignWithConversion(id); - - if (!cid.IsEmpty()) { - NS_NewXBLPrototypeBinding(cid, binding, mDocInfo, getter_AddRefs(mBinding)); - mDocInfo->SetPrototypeBinding(cid, mBinding); - binding->UnsetAttr(kNameSpaceID_None, nsHTMLAtoms::id, PR_FALSE); - } -} - -void -nsXBLContentSink::ConstructHandler(const nsIParserNode& aNode) -{ - nsCOMPtr nameSpacePrefix, nameAtom; - PRInt32 ac = aNode.GetAttributeCount(); - - nsAReadableString* event = nsnull; - nsAReadableString* modifiers = nsnull; - nsAReadableString* button = nsnull; - nsAReadableString* clickcount = nsnull; - nsAReadableString* keycode = nsnull; - nsAReadableString* charcode = nsnull; - nsAReadableString* phase = nsnull; - nsAReadableString* command = nsnull; - nsAReadableString* action = nsnull; - - for (PRInt32 i = 0; i < ac; i++) { - // Get upper-cased key - const nsAReadableString& key = aNode.GetKeyAt(i); - - SplitXMLName(key, getter_AddRefs(nameSpacePrefix), - getter_AddRefs(nameAtom)); - - if (nameSpacePrefix || nameAtom == nsLayoutAtoms::xmlnsNameSpace) - continue; - - // Is this attribute one of the ones we care about? - if (key.Equals(NS_LITERAL_STRING("event"))) - event = &(aNode.GetValueAt(i)); - else if (key.Equals(NS_LITERAL_STRING("modifiers"))) - modifiers = &(aNode.GetValueAt(i)); - else if (key.Equals(NS_LITERAL_STRING("button"))) - button = &(aNode.GetValueAt(i)); - else if (key.Equals(NS_LITERAL_STRING("clickcount"))) - clickcount = &(aNode.GetValueAt(i)); - else if (key.Equals(NS_LITERAL_STRING("keycode"))) - keycode = &(aNode.GetValueAt(i)); - else if (key.Equals(NS_LITERAL_STRING("key")) || key.Equals(NS_LITERAL_STRING("charcode"))) - charcode = &(aNode.GetValueAt(i)); - else if (key.Equals(NS_LITERAL_STRING("phase"))) - phase = &(aNode.GetValueAt(i)); - else if (key.Equals(NS_LITERAL_STRING("command"))) - command = &(aNode.GetValueAt(i)); - else if (key.Equals(NS_LITERAL_STRING("action"))) - action = &(aNode.GetValueAt(i)); - else - continue; // Nope, it's some irrelevant attribute. Ignore it and move on. - } - - if (command && !mIsChromeOrResource) - // Make sure the XBL doc is chrome or resource if we have a command - // shorthand syntax. - return; // Don't even make this handler. - - // All of our pointers are now filled in. Construct our handler with all of these - // parameters. - nsCOMPtr newHandler; - NS_NewXBLPrototypeHandler(event, phase, action, command, - keycode, charcode, modifiers, button, clickcount, - getter_AddRefs(newHandler)); - if (newHandler) { - // Add this handler to our chain of handlers. - if (mHandler) - mHandler->SetNextHandler(newHandler); // Already have a chain. Just append to the end. - else - mBinding->SetPrototypeHandlers(newHandler); // We're the first handler in the chain. - - mHandler = newHandler; // Adjust our mHandler pointer to point to the new last handler in the chain. - } -} - -void -nsXBLContentSink::ConstructResource(const nsIParserNode& aNode, nsIAtom* aResourceType) -{ - if (!mBinding) - return; - - nsCOMPtr nameSpacePrefix, nameAtom; - PRInt32 ac = aNode.GetAttributeCount(); - for (PRInt32 i = 0; i < ac; i++) { - // Get upper-cased key - const nsAReadableString& key = aNode.GetKeyAt(i); - - SplitXMLName(key, getter_AddRefs(nameSpacePrefix), - getter_AddRefs(nameAtom)); - - if (nameSpacePrefix || nameAtom == nsLayoutAtoms::xmlnsNameSpace) - continue; - - // Is this attribute one of the ones we care about? - if (key.Equals(NS_LITERAL_STRING("src"))) { - mBinding->AddResource(aResourceType, aNode.GetValueAt(i)); - break; - } - } -} - -void -nsXBLContentSink::ConstructImplementation(const nsIParserNode& aNode) -{ - mImplementation = nsnull; - mImplMember = nsnull; - - if (!mBinding) - return; - - nsAReadableString* name = nsnull; - - nsCOMPtr nameSpacePrefix, nameAtom; - PRInt32 ac = aNode.GetAttributeCount(); - for (PRInt32 i = 0; i < ac; i++) { - // Get upper-cased key - const nsAReadableString& key = aNode.GetKeyAt(i); - - SplitXMLName(key, getter_AddRefs(nameSpacePrefix), - getter_AddRefs(nameAtom)); - - if (nameSpacePrefix || nameAtom == nsLayoutAtoms::xmlnsNameSpace) - continue; - - // Is this attribute one of the ones we care about? - if (key.Equals(NS_LITERAL_STRING("name"))) - name = &(aNode.GetValueAt(i)); - else if (key.Equals(NS_LITERAL_STRING("implements"))) - mBinding->ConstructInterfaceTable(aNode.GetValueAt(i)); - } - - NS_NewXBLProtoImpl(mBinding, name, &mImplementation); -} - -void -nsXBLContentSink::ConstructField(const nsIParserNode& aNode) -{ - nsCOMPtr nameSpacePrefix, nameAtom; - PRInt32 ac = aNode.GetAttributeCount(); - - nsAReadableString* name = nsnull; - nsAReadableString* readonly = nsnull; - - for (PRInt32 i = 0; i < ac; i++) { - // Get upper-cased key - const nsAReadableString& key = aNode.GetKeyAt(i); - - SplitXMLName(key, getter_AddRefs(nameSpacePrefix), - getter_AddRefs(nameAtom)); - - if (nameSpacePrefix || nameAtom == nsLayoutAtoms::xmlnsNameSpace) - continue; - - // Is this attribute one of the ones we care about? - if (key.Equals(NS_LITERAL_STRING("name"))) - name = &(aNode.GetValueAt(i)); - else if (key.Equals(NS_LITERAL_STRING("readonly"))) - readonly = &(aNode.GetValueAt(i)); - } - - // All of our pointers are now filled in. Construct our field with all of these - // parameters. - mField = new nsXBLProtoImplField(name, readonly); - if (mField) { - // Add this member to our chain. - if (mImplMember) - mImplMember->SetNext(mField); // Already have a chain. Just append to the end. - else - mImplementation->SetMemberList(mField); // We're the first member in the chain. - - mImplMember = mField; // Adjust our pointer to point to the new last member in the chain. - } -} - -void -nsXBLContentSink::ConstructProperty(const nsIParserNode& aNode) -{ - nsCOMPtr nameSpacePrefix, nameAtom; - PRInt32 ac = aNode.GetAttributeCount(); - - nsAReadableString* name = nsnull; - nsAReadableString* readonly = nsnull; - nsAReadableString* onget = nsnull; - nsAReadableString* onset = nsnull; - - for (PRInt32 i = 0; i < ac; i++) { - // Get upper-cased key - const nsAReadableString& key = aNode.GetKeyAt(i); - - SplitXMLName(key, getter_AddRefs(nameSpacePrefix), - getter_AddRefs(nameAtom)); - - if (nameSpacePrefix || nameAtom == nsLayoutAtoms::xmlnsNameSpace) - continue; - - // Is this attribute one of the ones we care about? - if (key.Equals(NS_LITERAL_STRING("name"))) - name = &(aNode.GetValueAt(i)); - else if (key.Equals(NS_LITERAL_STRING("readonly"))) - readonly = &(aNode.GetValueAt(i)); - else if (key.Equals(NS_LITERAL_STRING("onget"))) - onget = &(aNode.GetValueAt(i)); - else if (key.Equals(NS_LITERAL_STRING("onset"))) - onset = &(aNode.GetValueAt(i)); - } - - // All of our pointers are now filled in. Construct our property with all of these - // parameters. - mProperty = new nsXBLProtoImplProperty(name, onget, onset, readonly); - if (mProperty) { - // Add this member to our chain. - if (mImplMember) - mImplMember->SetNext(mProperty); // Already have a chain. Just append to the end. - else - mImplementation->SetMemberList(mProperty); // We're the first member in the chain. - - mImplMember = mProperty; // Adjust our pointer to point to the new last member in the chain. - } -} - -void -nsXBLContentSink::ConstructMethod(const nsIParserNode& aNode) -{ - mMethod = nsnull; - - nsCOMPtr nameSpacePrefix, nameAtom; - PRInt32 ac = aNode.GetAttributeCount(); - - for (PRInt32 i = 0; i < ac; i++) { - // Get upper-cased key - const nsAReadableString& key = aNode.GetKeyAt(i); - - SplitXMLName(key, getter_AddRefs(nameSpacePrefix), - getter_AddRefs(nameAtom)); - - if (nameSpacePrefix || nameAtom == nsLayoutAtoms::xmlnsNameSpace) - continue; - - // Is this attribute one of the ones we care about? - if (key.Equals(NS_LITERAL_STRING("name"))) { - mMethod = new nsXBLProtoImplMethod(aNode.GetValueAt(i)); - break; - } - } - - if (mMethod) { - // Add this member to our chain. - if (mImplMember) - mImplMember->SetNext(mMethod); // Already have a chain. Just append to the end. - else - mImplementation->SetMemberList(mMethod); // We're the first member in the chain. - - mImplMember = mMethod; // Adjust our pointer to point to the new last member in the chain. - } -} - -void -nsXBLContentSink::ConstructParameter(const nsIParserNode& aNode) -{ - if (!mMethod) - return; - - nsCOMPtr nameSpacePrefix, nameAtom; - PRInt32 ac = aNode.GetAttributeCount(); - for (PRInt32 i = 0; i < ac; i++) { - // Get upper-cased key - const nsAReadableString& key = aNode.GetKeyAt(i); - - SplitXMLName(key, getter_AddRefs(nameSpacePrefix), - getter_AddRefs(nameAtom)); - - if (nameSpacePrefix || nameAtom == nsLayoutAtoms::xmlnsNameSpace) - continue; - - // Is this attribute one of the ones we care about? - if (key.Equals(NS_LITERAL_STRING("name"))) { - mMethod->AddParameter(aNode.GetValueAt(i)); - break; - } - } -} diff --git a/content/xbl/src/nsXBLContentSink.h b/content/xbl/src/nsXBLContentSink.h index 3b53cb1a24a..0b2ad10af0d 100644 --- a/content/xbl/src/nsXBLContentSink.h +++ b/content/xbl/src/nsXBLContentSink.h @@ -88,33 +88,52 @@ public: nsIWebShell* aContainer); // nsIContentSink overrides - NS_IMETHOD OpenContainer(const nsIParserNode& aNode); - NS_IMETHOD CloseContainer(const nsIParserNode& aNode); - NS_IMETHOD AddCDATASection(const nsIParserNode& aNode); + NS_IMETHOD HandleStartElement(const PRUnichar *aName, + const PRUnichar **aAtts, + const PRUint32 aAttsCount, + const PRUint32 aIndex, + const PRUint32 aLineNumber); + + NS_IMETHOD HandleEndElement(const PRUnichar *aName); + + NS_IMETHOD HandleCDataSection(const PRUnichar *aData, + const PRUint32 aLength); protected: + // nsXMLContentSink overrides + PRBool OnOpenContainer(const PRUnichar **aAtts, + PRUint32 aAttsCount, + PRInt32 aNameSpaceID, + nsIAtom* aTagName); + + nsresult CreateElement(const PRUnichar** aAtts, + PRUint32 aAttsCount, + PRInt32 aNameSpaceID, + nsINodeInfo* aNodeInfo, + nsIContent** aResult); + + nsresult AddAttributes(const PRUnichar** aAtts, + nsIContent* aContent, + PRBool aIsHTML); + + nsresult AddAttributesToXULPrototype(const PRUnichar **aAtts, + PRUint32 aAttsCount, + nsXULPrototypeElement* aElement); + + // Our own helpers for constructing XBL prototype objects. + void ConstructBinding(); + void ConstructHandler(const PRUnichar **aAtts); + void ConstructResource(const PRUnichar **aAtts, nsIAtom* aResourceType); + void ConstructImplementation(const PRUnichar **aAtts); + void ConstructProperty(const PRUnichar **aAtts); + void ConstructMethod(const PRUnichar **aAtts); + void ConstructParameter(const PRUnichar **aAtts); + void ConstructField(const PRUnichar **aAtts); + + // nsXMLContentSink overrides - PRBool OnOpenContainer(const nsIParserNode& aNode, PRInt32 aNameSpaceID, nsIAtom* aTagName); nsresult FlushText(PRBool aCreateTextNode=PR_TRUE, PRBool* aDidFlush=nsnull); - nsresult CreateElement(const nsIParserNode& aNode, PRInt32 aNameSpaceID, - nsINodeInfo* aNodeInfo, nsIContent** aResult); - nsresult AddAttributes(const nsIParserNode& aNode, - nsIContent* aContent, - PRBool aIsHTML); - - // Our own helpers for constructing XBL prototype objects. - void ConstructBinding(); - void ConstructHandler(const nsIParserNode& aNode); - void ConstructResource(const nsIParserNode& aNode, nsIAtom* aResourceType); - void ConstructImplementation(const nsIParserNode& aNode); - void ConstructProperty(const nsIParserNode& aNode); - void ConstructMethod(const nsIParserNode& aNode); - void ConstructParameter(const nsIParserNode& aNode); - void ConstructField(const nsIParserNode& aNode); - - nsresult AddAttributesToXULPrototype(const nsIParserNode& aNode, nsXULPrototypeElement* aElement); - protected: XBLPrimaryState mState; XBLSecondaryState mSecondaryState; diff --git a/content/xbl/src/nsXBLProtoImpl.h b/content/xbl/src/nsXBLProtoImpl.h index 56232ed3a41..0d532183f51 100644 --- a/content/xbl/src/nsXBLProtoImpl.h +++ b/content/xbl/src/nsXBLProtoImpl.h @@ -90,7 +90,7 @@ NS_NewXBLProtoImpl(nsIXBLPrototypeBinding* aBinding, nsXBLProtoImpl* impl = new nsXBLProtoImpl(); if (!impl) return NS_ERROR_OUT_OF_MEMORY; - if (aClassName) + if (aClassName && !aClassName->IsEmpty()) impl->mClassName.AssignWithConversion(*aClassName); else aBinding->GetBindingURI(impl->mClassName); diff --git a/content/xml/document/public/nsIXMLContentSink.h b/content/xml/document/public/nsIXMLContentSink.h index aaf6ed066d5..9c88cfc778f 100644 --- a/content/xml/document/public/nsIXMLContentSink.h +++ b/content/xml/document/public/nsIXMLContentSink.h @@ -78,52 +78,6 @@ public: NS_DEFINE_STATIC_IID_ACCESSOR(NS_IXMLCONTENT_SINK_IID) - /** - * This method is called by the parser when it encounters - * the XML declaration for a document. - * - * @param nsIParserNode reference to parser node interface - */ - NS_IMETHOD AddXMLDecl(const nsIParserNode& aNode)=0; - - /** - * This method is called by the parser when it encounters - * character data - either regular CDATA or a marked CDATA - * section. - * - * XXX Could be removed in favor of nsIContentSink::AddLeaf - * - * @param nsIParserNode reference to parser node interface - */ - NS_IMETHOD AddCharacterData(const nsIParserNode& aNode)=0; - - /** - * This method is called by the parser when it encounters - * an unparsed entity (i.e. NDATA) - * - * @param nsIParserNode reference to parser node interface - */ - NS_IMETHOD AddUnparsedEntity(const nsIParserNode& aNode)=0; - - /** - * This method is called by the parser when it encounters - * a notation. - * - * @param nsIParserNode reference to parser node interface - */ - NS_IMETHOD AddNotation(const nsIParserNode& aNode)=0; - - /** - * This method is called by the parser when it encounters - * an entity reference. Note that the expectation is that - * the content sink itself will expand the entity reference - * in the content model. - * - * @param nsIParserNode reference to parser node interface - */ - NS_IMETHOD AddEntityReference(const nsIParserNode& aNode)=0; - - }; extern nsresult NS_NewXMLContentSink(nsIXMLContentSink** aInstancePtrResult, diff --git a/content/xml/document/src/nsXMLContentSink.cpp b/content/xml/document/src/nsXMLContentSink.cpp index c265d71a989..1b995349b2d 100644 --- a/content/xml/document/src/nsXMLContentSink.cpp +++ b/content/xml/document/src/nsXMLContentSink.cpp @@ -250,15 +250,46 @@ NS_IMPL_THREADSAFE_ADDREF(nsXMLContentSink) NS_IMPL_THREADSAFE_RELEASE(nsXMLContentSink) NS_INTERFACE_MAP_BEGIN(nsXMLContentSink) - NS_INTERFACE_MAP_ENTRY(nsIXMLContentSink) - NS_INTERFACE_MAP_ENTRY(nsIContentSink) - NS_INTERFACE_MAP_ENTRY(nsIObserver) - NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) - NS_INTERFACE_MAP_ENTRY(nsIScriptLoaderObserver) - NS_INTERFACE_MAP_ENTRY(nsICSSLoaderObserver) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIXMLContentSink) + NS_INTERFACE_MAP_ENTRY(nsIXMLContentSink) + NS_INTERFACE_MAP_ENTRY(nsIContentSink) + NS_INTERFACE_MAP_ENTRY(nsIExpatSink) + NS_INTERFACE_MAP_ENTRY(nsIObserver) + NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) + NS_INTERFACE_MAP_ENTRY(nsIScriptLoaderObserver) + NS_INTERFACE_MAP_ENTRY(nsICSSLoaderObserver) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIXMLContentSink) NS_INTERFACE_MAP_END +/** + * DOCTYPE declaration is covered with very strict rules, which + * makes our life here simpler because the XML parser has already + * detected errors. The only slightly problematic case is whitespace + * between the tokens. There MUST be whitespace between the tokens + * EXCEPT right before > and [. + */ +static const char* kWhitespace = " \r\n\t\b"; // Optimized for typical cases + +static void +GetDocTypeToken(nsString& aStr, + nsString& aToken, + PRBool aQuotedString) +{ + aStr.Trim(kWhitespace,PR_TRUE,PR_FALSE); // If we don't do this we must look ahead + // before Cut() and adjust the cut amount. + + if (aQuotedString) { + PRInt32 endQuote = aStr.FindChar(aStr[0],PR_FALSE,1); + aStr.Mid(aToken,1,endQuote-1); + aStr.Cut(0,endQuote+1); + } else { + static const char* kDelimiter = " >[\r\n\t\b"; // Optimized for typical cases + PRInt32 tokenEnd = aStr.FindCharInSet(kDelimiter); + if (tokenEnd > 0) { + aStr.Left(aToken, tokenEnd); + aStr.Cut(0, tokenEnd); + } + } +} // nsIContentSink NS_IMETHODIMP nsXMLContentSink::WillBuildModel(void) @@ -504,153 +535,6 @@ nsXMLContentSink::SetParser(nsIParser* aParser) return NS_OK; } -// XXX Code copied from nsHTMLContentSink. It should be shared. -nsresult -nsXMLContentSink::AddAttributes(const nsIParserNode& aNode, - nsIContent* aContent, - PRBool aIsHTML) -{ - // Add tag attributes to the content attributes - nsCOMPtr nameSpacePrefix, nameAtom; - PRInt32 ac = aNode.GetAttributeCount(); - - for (PRInt32 i = 0; i < ac; i++) { - // Get upper-cased key - const nsAReadableString& key = aNode.GetKeyAt(i); - - SplitXMLName(key, getter_AddRefs(nameSpacePrefix), - getter_AddRefs(nameAtom)); - - PRInt32 nameSpaceID; - - if (nameSpacePrefix) { - nameSpaceID = GetNameSpaceId(nameSpacePrefix); - } else { - if (nameAtom.get() == nsLayoutAtoms::xmlnsNameSpace) - nameSpaceID = kNameSpaceID_XMLNS; - else - nameSpaceID = kNameSpaceID_None; - } - - if (kNameSpaceID_Unknown == nameSpaceID) { - nameSpaceID = kNameSpaceID_None; - nameAtom = dont_AddRef(NS_NewAtom(key)); - nameSpacePrefix = nsnull; - } else if ((kNameSpaceID_XMLNS == nameSpaceID) && aIsHTML) { - // Ooh, what a nice little hack we have here :-) - nsAutoString name; - nameAtom->ToString(name); - nameAtom = dont_AddRef(NS_NewAtom(NS_LITERAL_STRING("xmlns:") + name)); - nameSpaceID = kNameSpaceID_HTML; // XXX this is wrong, but necessary until HTML can store other namespaces for attrs - } - - nsCOMPtr ni; - mNodeInfoManager->GetNodeInfo(nameAtom, nameSpacePrefix, nameSpaceID, - *getter_AddRefs(ni)); - NS_ENSURE_TRUE(ni, NS_ERROR_FAILURE); - - // Add attribute to content - aContent->SetAttr(ni, aNode.GetValueAt(i), PR_FALSE); - } - - // Give autoloading links a chance to fire - if (mWebShell) { - nsCOMPtr xmlcontent(do_QueryInterface(aContent)); - if (xmlcontent) { - nsresult rv = xmlcontent->MaybeTriggerAutoLink(mWebShell); - if (rv == NS_XML_AUTOLINK_REPLACE || - rv == NS_XML_AUTOLINK_UNDEFINED) { - // If we do not terminate the parse, we just keep generating link trigger - // events. We want to parse only up to the first replace link, and stop. - mParser->Terminate(); - } - } - } - - return NS_OK; -} - -nsresult -nsXMLContentSink::PushNameSpacesFrom(const nsIParserNode& aNode) -{ - PRInt32 ac = aNode.GetAttributeCount(); - nsCOMPtr nameSpace; - nsresult rv = NS_OK; - - if (mNameSpaceStack && (0 < mNameSpaceStack->Count())) { - nameSpace = - (nsINameSpace*)mNameSpaceStack->ElementAt(mNameSpaceStack->Count() - 1); - } else { - nsCOMPtr manager; - mDocument->GetNameSpaceManager(*getter_AddRefs(manager)); - - NS_ASSERTION(manager, "no name space manager in document"); - - if (manager) { - rv = manager->CreateRootNameSpace(*getter_AddRefs(nameSpace)); - NS_ENSURE_SUCCESS(rv, rv); - } - } - - NS_ENSURE_TRUE(nameSpace, NS_ERROR_UNEXPECTED); - - static const NS_NAMED_LITERAL_STRING(kNameSpaceDef, "xmlns"); - static const PRUint32 xmlns_len = kNameSpaceDef.Length(); - - for (PRInt32 i = 0; i < ac; i++) { - const nsAReadableString& key = aNode.GetKeyAt(i); - // Look for "xmlns" at the start of the attribute name - - PRUint32 key_len = key.Length(); - - if (key_len >= xmlns_len && - nsDependentSubstring(key, 0, xmlns_len).Equals(kNameSpaceDef)) { - nsCOMPtr prefixAtom; - - // If key_len > xmlns_len we have a xmlns:foo type attribute, - // extract the prefix. If not, we have a xmlns attribute in - // which case there is no prefix. - - if (key_len > xmlns_len) { - nsReadingIterator start, end; - - key.BeginReading(start); - key.EndReading(end); - - start.advance(xmlns_len); - - if (*start == ':') { - ++start; - - prefixAtom = - dont_AddRef(NS_NewAtom(nsDependentSubstring(start, end))); - } - } - - nsCOMPtr child; - rv = nameSpace->CreateChildNameSpace(prefixAtom, aNode.GetValueAt(i), - *getter_AddRefs(child)); - NS_ENSURE_SUCCESS(rv, rv); - - nameSpace = child; - } - } - - if (!mNameSpaceStack) { - mNameSpaceStack = new nsAutoVoidArray(); - - if (!mNameSpaceStack) { - return NS_ERROR_OUT_OF_MEMORY; - } - } - - nsINameSpace *tmp = nameSpace; - mNameSpaceStack->AppendElement(tmp); - NS_ADDREF(tmp); - - return NS_OK; -} - // static void nsXMLContentSink::SplitXMLName(nsAReadableString& aString, nsIAtom **aPrefix, @@ -681,141 +565,8 @@ nsXMLContentSink::SplitXMLName(nsAReadableString& aString, nsIAtom **aPrefix, *aLocalName = NS_NewAtom(aString); } -NS_IMETHODIMP -nsXMLContentSink::OpenContainer(const nsIParserNode& aNode) -{ - nsresult result = NS_OK; - PRBool isHTML = PR_FALSE; - PRBool appendContent = PR_TRUE; - nsCOMPtr content; - - // XXX Hopefully the parser will flag this before we get - // here. If we're in the epilog, there should be no - // new elements - PR_ASSERT(eXMLContentSinkState_InEpilog != mState); - - FlushText(); - - mState = eXMLContentSinkState_InDocumentElement; - - nsCOMPtr nameSpacePrefix, tagAtom; - - SplitXMLName(aNode.GetText(), getter_AddRefs(nameSpacePrefix), - getter_AddRefs(tagAtom)); - - // We must register namespace declarations found in the attribute list - // of an element before creating the element. This is because the - // namespace prefix for an element might be declared within the attribute - // list. - result = PushNameSpacesFrom(aNode); - NS_ENSURE_SUCCESS(result, result); - - PRInt32 nameSpaceID = GetNameSpaceId(nameSpacePrefix); - - if (!OnOpenContainer(aNode, nameSpaceID, tagAtom)) - return NS_OK; - - nsCOMPtr nodeInfo; - - mNodeInfoManager->GetNodeInfo(tagAtom, nameSpacePrefix, nameSpaceID, - *getter_AddRefs(nodeInfo)); - - isHTML = IsHTMLNameSpace(nameSpaceID); - - if (isHTML) { - if (tagAtom.get() == nsHTMLAtoms::script) { - result = ProcessStartSCRIPTTag(aNode); - // Don't append the content to the tree until we're all - // done collecting its contents - appendContent = PR_FALSE; - } else if (tagAtom.get() == nsHTMLAtoms::title) { - if (mTitleText.IsEmpty()) - mInTitle = PR_TRUE; // The first title wins - } - - nsCOMPtr htmlContent; - result = NS_CreateHTMLElement(getter_AddRefs(htmlContent), nodeInfo, PR_TRUE); - content = do_QueryInterface(htmlContent); - - if (tagAtom.get() == nsHTMLAtoms::style) { - mStyleElement = htmlContent; - } else if (tagAtom.get() == nsHTMLAtoms::base) { - if (!mBaseElement) { - mBaseElement = htmlContent; // The first base wins - } - } else if (tagAtom.get() == nsHTMLAtoms::meta) { - if (!mMetaElement) { - mMetaElement = htmlContent; - } - } - } - else - CreateElement(aNode, nameSpaceID, nodeInfo, getter_AddRefs(content)); - - if (NS_OK == result) { - PRInt32 id; - mDocument->GetAndIncrementContentID(&id); - content->SetContentID(id); - - nsCOMPtr ssle(do_QueryInterface(content)); - - if (ssle) { - // We stopped supporting