diff --git a/mozilla/content/base/src/nsContentList.cpp b/mozilla/content/base/src/nsContentList.cpp index d3700fca760..67d37cde98e 100644 --- a/mozilla/content/base/src/nsContentList.cpp +++ b/mozilla/content/base/src/nsContentList.cpp @@ -32,7 +32,7 @@ nsContentList::nsContentList(nsIDocument *aDocument) } nsContentList::nsContentList(nsIDocument *aDocument, - const nsString& aMatchTag) + const nsString& aMatchTag) { mMatchTag = new nsString(aMatchTag); mFunc = nsnull; @@ -40,7 +40,7 @@ nsContentList::nsContentList(nsIDocument *aDocument, } nsContentList::nsContentList(nsIDocument *aDocument, - nsContentListMatchFunc aFunc) + nsContentListMatchFunc aFunc) { mFunc = aFunc; mMatchTag = nsnull; @@ -197,10 +197,10 @@ nsContentList::NamedItem(const nsString& aName, nsIDOMNode** aReturn) nsAutoString name; // XXX Should it be an EqualsIgnoreCase? if (((content->GetAttribute("NAME", name) == eContentAttr_HasValue) && - (aName.Equals(name))) || - ((content->GetAttribute("ID", name) == eContentAttr_HasValue) && - (aName.Equals(name)))) { - return content->QueryInterface(kIDOMNodeIID, (void **)aReturn); + (aName.Equals(name))) || + ((content->GetAttribute("ID", name) == eContentAttr_HasValue) && + (aName.Equals(name)))) { + return content->QueryInterface(kIDOMNodeIID, (void **)aReturn); } } } @@ -274,7 +274,7 @@ void nsContentList::PopulateSelf(nsIContent *aContent) NS_IMETHODIMP nsContentList::ContentAppended(nsIDocument *aDocument, - nsIContent* aContainer) + nsIContent* aContainer) { if (aContainer->ChildCount() > 0) { nsIContent *content = aContainer->ChildAt(aContainer->ChildCount()-1); @@ -292,9 +292,9 @@ nsContentList::ContentAppended(nsIDocument *aDocument, NS_IMETHODIMP nsContentList::ContentInserted(nsIDocument *aDocument, - nsIContent* aContainer, - nsIContent* aChild, - PRInt32 aIndexInContainer) + nsIContent* aContainer, + nsIContent* aChild, + PRInt32 aIndexInContainer) { if (MatchSelf(aChild)) { Reset(); @@ -308,10 +308,10 @@ nsContentList::ContentInserted(nsIDocument *aDocument, NS_IMETHODIMP nsContentList::ContentReplaced(nsIDocument *aDocument, - nsIContent* aContainer, - nsIContent* aOldChild, - nsIContent* aNewChild, - PRInt32 aIndexInContainer) + nsIContent* aContainer, + nsIContent* aOldChild, + nsIContent* aNewChild, + PRInt32 aIndexInContainer) { if (MatchSelf(aOldChild) || MatchSelf(aNewChild)) { Reset(); @@ -325,9 +325,9 @@ nsContentList::ContentReplaced(nsIDocument *aDocument, NS_IMETHODIMP nsContentList::ContentHasBeenRemoved(nsIDocument *aDocument, - nsIContent* aContainer, - nsIContent* aChild, - PRInt32 aIndexInContainer) + nsIContent* aContainer, + nsIContent* aChild, + PRInt32 aIndexInContainer) { if (MatchSelf(aChild)) { Reset(); diff --git a/mozilla/content/html/content/src/nsHTMLAtoms.cpp b/mozilla/content/html/content/src/nsHTMLAtoms.cpp index 1bf20043b1f..f96a09a8909 100644 --- a/mozilla/content/html/content/src/nsHTMLAtoms.cpp +++ b/mozilla/content/html/content/src/nsHTMLAtoms.cpp @@ -21,7 +21,9 @@ nsIAtom* nsHTMLAtoms::_baseHref; nsIAtom* nsHTMLAtoms::_baseTarget; nsIAtom* nsHTMLAtoms::a; nsIAtom* nsHTMLAtoms::above; +nsIAtom* nsHTMLAtoms::accept; nsIAtom* nsHTMLAtoms::acceptcharset; +nsIAtom* nsHTMLAtoms::accesskey; nsIAtom* nsHTMLAtoms::action; nsIAtom* nsHTMLAtoms::active; nsIAtom* nsHTMLAtoms::align; @@ -63,6 +65,7 @@ nsIAtom* nsHTMLAtoms::enctype; nsIAtom* nsHTMLAtoms::face; nsIAtom* nsHTMLAtoms::font; nsIAtom* nsHTMLAtoms::fontWeight; +nsIAtom* nsHTMLAtoms::form; nsIAtom* nsHTMLAtoms::frame; nsIAtom* nsHTMLAtoms::frameborder; nsIAtom* nsHTMLAtoms::frameset; @@ -81,6 +84,7 @@ nsIAtom* nsHTMLAtoms::hspace; nsIAtom* nsHTMLAtoms::httpEquiv; nsIAtom* nsHTMLAtoms::id; nsIAtom* nsHTMLAtoms::iframe; +nsIAtom* nsHTMLAtoms::img; nsIAtom* nsHTMLAtoms::ismap; nsIAtom* nsHTMLAtoms::lang; nsIAtom* nsHTMLAtoms::li; @@ -145,6 +149,7 @@ nsIAtom* nsHTMLAtoms::start; nsIAtom* nsHTMLAtoms::style; nsIAtom* nsHTMLAtoms::summary; nsIAtom* nsHTMLAtoms::suppress; +nsIAtom* nsHTMLAtoms::tabindex; nsIAtom* nsHTMLAtoms::table; nsIAtom* nsHTMLAtoms::tabstop; nsIAtom* nsHTMLAtoms::target; @@ -176,7 +181,9 @@ void nsHTMLAtoms::AddrefAtoms() _baseTarget = NS_NewAtom(NS_HTML_BASE_TARGET); a = NS_NewAtom("A"); above = NS_NewAtom("ABOVE"); + accept = NS_NewAtom("ACCEPT"); acceptcharset = NS_NewAtom("ACCEPTCHARSET"); + accesskey = NS_NewAtom("ACCESSKEY"); action = NS_NewAtom("ACTION"); active = NS_NewAtom("ACTIVE"); align = NS_NewAtom("ALIGN"); @@ -218,6 +225,7 @@ void nsHTMLAtoms::AddrefAtoms() face = NS_NewAtom("FACE"); font = NS_NewAtom("FONT"); fontWeight = NS_NewAtom("FONT-WEIGHT"); + form = NS_NewAtom("FORM"); frame = NS_NewAtom("FRAME"); frameborder = NS_NewAtom("FRAMEBORDER"); frameset = NS_NewAtom("FRAMESET"); @@ -236,6 +244,7 @@ void nsHTMLAtoms::AddrefAtoms() httpEquiv = NS_NewAtom("HTTP-EQUIV"); id = NS_NewAtom("ID"); iframe = NS_NewAtom("IFRAME"); + img = NS_NewAtom("IMG"); ismap = NS_NewAtom("ISMAP"); lang = NS_NewAtom("LANG"); li = NS_NewAtom("LI"); @@ -299,6 +308,7 @@ void nsHTMLAtoms::AddrefAtoms() style = NS_NewAtom("STYLE"); summary = NS_NewAtom("SUMMARY"); suppress = NS_NewAtom("SUPPRESS"); + tabindex = NS_NewAtom("TABINDEX"); table = NS_NewAtom("TABLE"); tabstop = NS_NewAtom("TABSTOP"); target = NS_NewAtom("TARGET"); diff --git a/mozilla/content/html/content/src/nsHTMLAtoms.h b/mozilla/content/html/content/src/nsHTMLAtoms.h index 49bc2b14b3b..58af240c228 100644 --- a/mozilla/content/html/content/src/nsHTMLAtoms.h +++ b/mozilla/content/html/content/src/nsHTMLAtoms.h @@ -42,7 +42,9 @@ public: // Alphabetical list of html attribute atoms static nsIAtom* a; static nsIAtom* above; + static nsIAtom* accept; static nsIAtom* acceptcharset; + static nsIAtom* accesskey; static nsIAtom* action; static nsIAtom* active; static nsIAtom* align; @@ -89,6 +91,7 @@ public: static nsIAtom* face; static nsIAtom* font; static nsIAtom* fontWeight; + static nsIAtom* form; static nsIAtom* frame; static nsIAtom* frameborder; static nsIAtom* frameset; @@ -110,6 +113,7 @@ public: static nsIAtom* id; static nsIAtom* iframe; + static nsIAtom* img; static nsIAtom* ismap; static nsIAtom* lang; @@ -182,6 +186,7 @@ public: static nsIAtom* summary; static nsIAtom* suppress; + static nsIAtom* tabindex; static nsIAtom* table; static nsIAtom* tabstop; static nsIAtom* target; diff --git a/mozilla/content/html/document/src/nsHTMLContentSink.cpp b/mozilla/content/html/document/src/nsHTMLContentSink.cpp index 63ef9a726e4..4aff1f49859 100644 --- a/mozilla/content/html/document/src/nsHTMLContentSink.cpp +++ b/mozilla/content/html/document/src/nsHTMLContentSink.cpp @@ -101,6 +101,7 @@ static PRLogModuleInfo* gSinkLogModuleInfo; static NS_DEFINE_IID(kIScrollableViewIID, NS_ISCROLLABLEVIEW_IID); static NS_DEFINE_IID(kIHTMLContentSinkIID, NS_IHTML_CONTENT_SINK_IID); static NS_DEFINE_IID(kIFormControlIID, NS_IFORMCONTROL_IID); +static NS_DEFINE_IID(kIContentIID, NS_ICONTENT_IID); class HTMLContentSink : public nsIHTMLContentSink { public: @@ -566,6 +567,11 @@ HTMLContentSink::OpenForm(const nsIParserNode& aNode) // XXX Temporary code till forms become real content // Add the form to the document ((nsHTMLDocument*)mDocument)->AddForm(mCurrentForm); + nsIContent *content; + if (NS_OK == mCurrentForm->QueryInterface(kIContentIID, (void **)&content)) { + content->SetDocument(mDocument); + NS_RELEASE(content); + } } return NS_OK; @@ -1484,7 +1490,6 @@ HTMLContentSink::FlushText() { if (nsnull != mCurrentText) { // XXX sleazyTextHackXXX repair document pointer in text object - static NS_DEFINE_IID(kIContentIID, NS_ICONTENT_IID); nsIContent* content = nsnull; mCurrentText->QueryInterface(kIContentIID, (void**) &content); content->SetDocument(mDocument); @@ -1802,7 +1807,7 @@ nsresult HTMLContentSink::ProcessSCRIPTTag(const nsIParserNode& aNode) NS_RELEASE(context); NS_RELEASE(owner); } - delete script; + delete [] script; } return rv; diff --git a/mozilla/content/html/document/src/nsHTMLDocument.cpp b/mozilla/content/html/document/src/nsHTMLDocument.cpp index 847e30d7fff..83f37b24d3c 100644 --- a/mozilla/content/html/document/src/nsHTMLDocument.cpp +++ b/mozilla/content/html/document/src/nsHTMLDocument.cpp @@ -56,6 +56,7 @@ static NS_DEFINE_IID(kIDOMElementIID, NS_IDOMELEMENT_IID); static NS_DEFINE_IID(kIDOMTextIID, NS_IDOMTEXT_IID); static NS_DEFINE_IID(kIHTMLDocumentIID, NS_IHTMLDOCUMENT_IID); static NS_DEFINE_IID(kIDOMHTMLDocumentIID, NS_IDOMHTMLDOCUMENT_IID); +static NS_DEFINE_IID(kIDOMNSHTMLDocumentIID, NS_IDOMNSHTMLDOCUMENT_IID); NS_LAYOUT nsresult NS_NewHTMLDocument(nsIDocument** aInstancePtrResult) @@ -89,9 +90,7 @@ nsHTMLDocument::~nsHTMLDocument() NS_RELEASE(form); } } - if (nsnull != mNamedItems) { - PL_HashTableDestroy(mNamedItems); - } + DeleteNamedItems(); NS_IF_RELEASE(mImages); NS_IF_RELEASE(mApplets); NS_IF_RELEASE(mEmbeds); @@ -121,6 +120,11 @@ NS_IMETHODIMP nsHTMLDocument::QueryInterface(REFNSIID aIID, *aInstancePtr = (void**) (nsIDOMHTMLDocument *)this; return NS_OK; } + if (aIID.Equals(kIDOMNSHTMLDocumentIID)) { + AddRef(); + *aInstancePtr = (void**) (nsIDOMNSHTMLDocument *)this; + return NS_OK; + } return nsDocument::QueryInterface(aIID, aInstancePtr); } @@ -325,20 +329,6 @@ nsHTMLDocument::GetFormAt(PRInt32 aIndex, nsIFormManager **aForm) const return 1;/* XXX NS_NOT_FOUND */ } -NS_IMETHODIMP -nsHTMLDocument::AddNamedItem(const nsString& aName, nsIContent *aContent) -{ - //XXX TBI - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -nsHTMLDocument::RemoveNamedItem(const nsString& aName) -{ - //XXX TBI - return NS_ERROR_NOT_IMPLEMENTED; -} - NS_IMETHODIMP nsHTMLDocument::GetAttributeStyleSheet(nsIHTMLStyleSheet** aResult) { NS_PRECONDITION(nsnull != aResult, "null ptr"); @@ -730,12 +720,50 @@ nsHTMLDocument::Writeln(JSContext *cx, jsval *argv, PRUint32 argc) return result; } +nsIContent * +nsHTMLDocument::MatchName(nsIContent *aContent, const nsString& aName) +{ + static nsAutoString name("NAME"), id("ID"); + nsAutoString value; + nsIContent *result = nsnull; + + if ((eContentAttr_HasValue == aContent->GetAttribute(id, value)) && + aName.Equals(value)) { + return aContent; + } + else if ((eContentAttr_HasValue == aContent->GetAttribute(name, value)) && + aName.Equals(value)) { + return aContent; + } + + PRInt32 i, count; + count = aContent->ChildCount(); + for (i = 0; i < count && result == nsnull; i++) { + nsIContent *child = aContent->ChildAt(i); + result = MatchName(child, aName); + NS_RELEASE(child); + } + + return result; +} NS_IMETHODIMP nsHTMLDocument::GetElementById(const nsString& aElementId, nsIDOMElement** aReturn) { - //XXX TBI - return NS_ERROR_NOT_IMPLEMENTED; + nsIContent *content; + + // XXX For now, we do a brute force search of the content tree. + // We should come up with a more efficient solution. + content = MatchName(mRootContent, aElementId); + + if (nsnull != content) { + return content->QueryInterface(kIDOMElementIID, (void **)aReturn); + } + else { + *aReturn = nsnull; + } + + return NS_OK; } NS_IMETHODIMP @@ -745,10 +773,201 @@ nsHTMLDocument::GetElementsByName(const nsString& aElementName, nsIDOMNodeList** return NS_ERROR_NOT_IMPLEMENTED; } -NS_IMETHODIMP -nsHTMLDocument::GetNamedItem(const nsString& aName, nsIDOMElement **aReturn) +NS_IMETHODIMP +nsHTMLDocument::GetAlinkColor(nsString& aAlinkColor) { - return NS_OK; + //XXX TBI + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsHTMLDocument::SetAlinkColor(const nsString& aAlinkColor) +{ + //XXX TBI + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsHTMLDocument::GetLinkColor(nsString& aLinkColor) +{ + //XXX TBI + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsHTMLDocument::SetLinkColor(const nsString& aLinkColor) +{ + //XXX TBI + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsHTMLDocument::GetVlinkColor(nsString& aVlinkColor) +{ + //XXX TBI + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsHTMLDocument::SetVlinkColor(const nsString& aVlinkColor) +{ + //XXX TBI + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsHTMLDocument::GetBgColor(nsString& aBgColor) +{ + //XXX TBI + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsHTMLDocument::SetBgColor(const nsString& aBgColor) +{ + //XXX TBI + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsHTMLDocument::GetFgColor(nsString& aFgColor) +{ + //XXX TBI + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsHTMLDocument::SetFgColor(const nsString& aFgColor) +{ + //XXX TBI + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsHTMLDocument::GetLastModified(nsString& aLastModified) +{ + //XXX TBI + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsHTMLDocument::GetEmbeds(nsIDOMHTMLCollection** aEmbeds) +{ + //XXX TBI + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsHTMLDocument::GetLayers(nsIDOMHTMLCollection** aLayers) +{ + //XXX TBI + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsHTMLDocument::GetPlugins(nsIDOMHTMLCollection** aPlugins) +{ + //XXX TBI + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsHTMLDocument::GetSelection(nsString& aReturn) +{ + //XXX TBI + return NS_ERROR_NOT_IMPLEMENTED; +} + +PRIntn +nsHTMLDocument::RemoveStrings(PLHashEntry *he, PRIntn i, void *arg) +{ + char *str = (char *)he->key; + + delete [] str; + return HT_ENUMERATE_REMOVE; +} + +void +nsHTMLDocument::DeleteNamedItems() +{ + if (nsnull != mNamedItems) { + PL_HashTableEnumerateEntries(mNamedItems, RemoveStrings, nsnull); + PL_HashTableDestroy(mNamedItems); + mNamedItems = nsnull; + } +} + +void +nsHTMLDocument::RegisterNamedItems(nsIContent *aContent, PRBool aInForm) +{ + static nsAutoString name("NAME"); + nsAutoString value; + nsIAtom *tag = aContent->GetTag(); + PRBool inForm; + + // Only the content types reflected in Level 0 with a NAME + // attribute are registered. Images and forms always get + // reflected up to the document. Applets and embeds only go + // to the closest container (which could be a form). + if ((tag == nsHTMLAtoms::img) || (tag == nsHTMLAtoms::form) || + (!aInForm && ((tag == nsHTMLAtoms::applet) || + (tag == nsHTMLAtoms::embed)))) { + if (eContentAttr_HasValue == aContent->GetAttribute(name, value)) { + char *nameStr = value.ToNewCString(); + PL_HashTableAdd(mNamedItems, nameStr, aContent); + } + } + + inForm = aInForm || (tag == nsHTMLAtoms::form); + NS_IF_RELEASE(tag); + + PRInt32 i, count; + count = aContent->ChildCount(); + for (i = 0; i < count; i++) { + nsIContent *child = aContent->ChildAt(i); + RegisterNamedItems(child, inForm); + NS_RELEASE(child); + } +} + +NS_IMETHODIMP +nsHTMLDocument::NamedItem(const nsString& aName, nsIDOMElement** aReturn) +{ + static nsAutoString name("NAME"); + nsresult result = NS_OK; + nsIContent *content; + + if (nsnull == mNamedItems) { + mNamedItems = PL_NewHashTable(10, PL_HashString, PL_CompareStrings, + PL_CompareValues, nsnull, nsnull); + RegisterNamedItems(mRootContent, PR_FALSE); + // XXX Need to do this until forms become real content + PRInt32 i, count = mTempForms.Count(); + for (i = 0; i < count; i++) { + nsIFormManager *form = (nsIFormManager *)mTempForms.ElementAt(i); + if (NS_OK == form->QueryInterface(kIContentIID, (void **)&content)) { + nsAutoString value; + if (eContentAttr_HasValue == content->GetAttribute(name, value)) { + char *nameStr = value.ToNewCString(); + PL_HashTableAdd(mNamedItems, nameStr, content); + } + NS_RELEASE(content); + } + } + } + + char *str = aName.ToNewCString(); + + content = (nsIContent *)PL_HashTableLookup(mNamedItems, str); + if (nsnull != content) { + result = content->QueryInterface(kIDOMElementIID, (void **)aReturn); + } + else { + *aReturn = nsnull; + } + + delete [] str; + return result; } NS_IMETHODIMP diff --git a/mozilla/content/html/document/src/nsHTMLDocument.h b/mozilla/content/html/document/src/nsHTMLDocument.h index 7fe15b68570..4b4dff32fda 100644 --- a/mozilla/content/html/document/src/nsHTMLDocument.h +++ b/mozilla/content/html/document/src/nsHTMLDocument.h @@ -22,6 +22,7 @@ #include "nsMarkupDocument.h" #include "nsIHTMLDocument.h" #include "nsIDOMHTMLDocument.h" +#include "nsIDOMNSHTMLDocument.h" #include "plhash.h" class nsIHTMLStyleSheet; @@ -29,7 +30,7 @@ class nsContentList; class nsIContentViewerContainer; class nsIParser; -class nsHTMLDocument : public nsMarkupDocument, public nsIHTMLDocument, public nsIDOMHTMLDocument { +class nsHTMLDocument : public nsMarkupDocument, public nsIHTMLDocument, public nsIDOMHTMLDocument, public nsIDOMNSHTMLDocument { public: nsHTMLDocument(); virtual ~nsHTMLDocument(); @@ -45,8 +46,6 @@ public: NS_IMETHOD EndLoad(); - NS_IMETHOD SetTitle(const nsString& aTitle); - NS_IMETHOD AddImageMap(nsIImageMap* aMap); NS_IMETHOD GetImageMap(const nsString& aMapName, nsIImageMap** aResult); @@ -62,10 +61,6 @@ public: // XXX // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX - NS_IMETHOD AddNamedItem(const nsString& aName, nsIContent *aContent); - - NS_IMETHOD RemoveNamedItem(const nsString& aName); - NS_IMETHOD GetAttributeStyleSheet(nsIHTMLStyleSheet** aStyleSheet); // nsIDOMDocument interface @@ -97,35 +92,18 @@ public: NS_FORWARD_IDOMNODE(nsDocument) // nsIDOMHTMLDocument interface - NS_IMETHOD GetTitle(nsString& aTitle); - NS_IMETHOD GetReferrer(nsString& aReferrer); - NS_IMETHOD GetFileSize(nsString& aFileSize); - NS_IMETHOD GetFileCreatedDate(nsString& aFileCreatedDate); - NS_IMETHOD GetFileModifiedDate(nsString& aFileModifiedDate); - NS_IMETHOD GetFileUpdatedDate(nsString& aFileUpdatedDate); - NS_IMETHOD GetDomain(nsString& aDomain); - NS_IMETHOD GetURL(nsString& aURL); - NS_IMETHOD GetBody(nsIDOMHTMLElement** aBody); - NS_IMETHOD SetBody(nsIDOMHTMLElement* aBody); - NS_IMETHOD GetImages(nsIDOMHTMLCollection** aImages); - NS_IMETHOD GetApplets(nsIDOMHTMLCollection** aApplets); - NS_IMETHOD GetLinks(nsIDOMHTMLCollection** aLinks); - NS_IMETHOD GetForms(nsIDOMHTMLCollection** aForms); - NS_IMETHOD GetAnchors(nsIDOMHTMLCollection** aAnchors); - NS_IMETHOD GetCookie(nsString& aCookie); - NS_IMETHOD SetCookie(const nsString& aCookie); - NS_IMETHOD Open(JSContext *cx, jsval *argv, PRUint32 argc); - NS_IMETHOD Close(); - NS_IMETHOD Write(JSContext *cx, jsval *argv, PRUint32 argc); - NS_IMETHOD Writeln(JSContext *cx, jsval *argv, PRUint32 argc); - NS_IMETHOD GetElementById(const nsString& aElementId, nsIDOMElement** aReturn); - NS_IMETHOD GetElementsByName(const nsString& aElementName, nsIDOMNodeList** aReturn); - NS_IMETHOD GetNamedItem(const nsString& aName, nsIDOMElement **aReturn); + NS_DECL_IDOMHTMLDOCUMENT + NS_DECL_IDOMNSHTMLDOCUMENT // From nsIScriptObjectOwner interface, implemented by nsDocument NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); protected: + static PRIntn RemoveStrings(PLHashEntry *he, PRIntn i, void *arg); + void RegisterNamedItems(nsIContent *aContent, PRBool aInForm); + void DeleteNamedItems(); + nsIContent *MatchName(nsIContent *aContent, const nsString& aName); + virtual void AddStyleSheetToSet(nsIStyleSheet* aSheet, nsIStyleSet* aSet); static PRBool MatchLinks(nsIContent *aContent); static PRBool MatchAnchors(nsIContent *aContent); diff --git a/mozilla/content/html/document/src/nsIHTMLDocument.h b/mozilla/content/html/document/src/nsIHTMLDocument.h index 1b2e04482f2..0fd6da7bef5 100644 --- a/mozilla/content/html/document/src/nsIHTMLDocument.h +++ b/mozilla/content/html/document/src/nsIHTMLDocument.h @@ -50,10 +50,6 @@ public: // XXX // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX - NS_IMETHOD AddNamedItem(const nsString& aName, nsIContent *aContent) = 0; - - NS_IMETHOD RemoveNamedItem(const nsString& aName) = 0; - NS_IMETHOD GetAttributeStyleSheet(nsIHTMLStyleSheet** aStyleSheet) = 0; }; diff --git a/mozilla/content/shared/public/nsHTMLAtoms.h b/mozilla/content/shared/public/nsHTMLAtoms.h index 49bc2b14b3b..58af240c228 100644 --- a/mozilla/content/shared/public/nsHTMLAtoms.h +++ b/mozilla/content/shared/public/nsHTMLAtoms.h @@ -42,7 +42,9 @@ public: // Alphabetical list of html attribute atoms static nsIAtom* a; static nsIAtom* above; + static nsIAtom* accept; static nsIAtom* acceptcharset; + static nsIAtom* accesskey; static nsIAtom* action; static nsIAtom* active; static nsIAtom* align; @@ -89,6 +91,7 @@ public: static nsIAtom* face; static nsIAtom* font; static nsIAtom* fontWeight; + static nsIAtom* form; static nsIAtom* frame; static nsIAtom* frameborder; static nsIAtom* frameset; @@ -110,6 +113,7 @@ public: static nsIAtom* id; static nsIAtom* iframe; + static nsIAtom* img; static nsIAtom* ismap; static nsIAtom* lang; @@ -182,6 +186,7 @@ public: static nsIAtom* summary; static nsIAtom* suppress; + static nsIAtom* tabindex; static nsIAtom* table; static nsIAtom* tabstop; static nsIAtom* target; diff --git a/mozilla/content/shared/src/nsHTMLAtoms.cpp b/mozilla/content/shared/src/nsHTMLAtoms.cpp index 1bf20043b1f..f96a09a8909 100644 --- a/mozilla/content/shared/src/nsHTMLAtoms.cpp +++ b/mozilla/content/shared/src/nsHTMLAtoms.cpp @@ -21,7 +21,9 @@ nsIAtom* nsHTMLAtoms::_baseHref; nsIAtom* nsHTMLAtoms::_baseTarget; nsIAtom* nsHTMLAtoms::a; nsIAtom* nsHTMLAtoms::above; +nsIAtom* nsHTMLAtoms::accept; nsIAtom* nsHTMLAtoms::acceptcharset; +nsIAtom* nsHTMLAtoms::accesskey; nsIAtom* nsHTMLAtoms::action; nsIAtom* nsHTMLAtoms::active; nsIAtom* nsHTMLAtoms::align; @@ -63,6 +65,7 @@ nsIAtom* nsHTMLAtoms::enctype; nsIAtom* nsHTMLAtoms::face; nsIAtom* nsHTMLAtoms::font; nsIAtom* nsHTMLAtoms::fontWeight; +nsIAtom* nsHTMLAtoms::form; nsIAtom* nsHTMLAtoms::frame; nsIAtom* nsHTMLAtoms::frameborder; nsIAtom* nsHTMLAtoms::frameset; @@ -81,6 +84,7 @@ nsIAtom* nsHTMLAtoms::hspace; nsIAtom* nsHTMLAtoms::httpEquiv; nsIAtom* nsHTMLAtoms::id; nsIAtom* nsHTMLAtoms::iframe; +nsIAtom* nsHTMLAtoms::img; nsIAtom* nsHTMLAtoms::ismap; nsIAtom* nsHTMLAtoms::lang; nsIAtom* nsHTMLAtoms::li; @@ -145,6 +149,7 @@ nsIAtom* nsHTMLAtoms::start; nsIAtom* nsHTMLAtoms::style; nsIAtom* nsHTMLAtoms::summary; nsIAtom* nsHTMLAtoms::suppress; +nsIAtom* nsHTMLAtoms::tabindex; nsIAtom* nsHTMLAtoms::table; nsIAtom* nsHTMLAtoms::tabstop; nsIAtom* nsHTMLAtoms::target; @@ -176,7 +181,9 @@ void nsHTMLAtoms::AddrefAtoms() _baseTarget = NS_NewAtom(NS_HTML_BASE_TARGET); a = NS_NewAtom("A"); above = NS_NewAtom("ABOVE"); + accept = NS_NewAtom("ACCEPT"); acceptcharset = NS_NewAtom("ACCEPTCHARSET"); + accesskey = NS_NewAtom("ACCESSKEY"); action = NS_NewAtom("ACTION"); active = NS_NewAtom("ACTIVE"); align = NS_NewAtom("ALIGN"); @@ -218,6 +225,7 @@ void nsHTMLAtoms::AddrefAtoms() face = NS_NewAtom("FACE"); font = NS_NewAtom("FONT"); fontWeight = NS_NewAtom("FONT-WEIGHT"); + form = NS_NewAtom("FORM"); frame = NS_NewAtom("FRAME"); frameborder = NS_NewAtom("FRAMEBORDER"); frameset = NS_NewAtom("FRAMESET"); @@ -236,6 +244,7 @@ void nsHTMLAtoms::AddrefAtoms() httpEquiv = NS_NewAtom("HTTP-EQUIV"); id = NS_NewAtom("ID"); iframe = NS_NewAtom("IFRAME"); + img = NS_NewAtom("IMG"); ismap = NS_NewAtom("ISMAP"); lang = NS_NewAtom("LANG"); li = NS_NewAtom("LI"); @@ -299,6 +308,7 @@ void nsHTMLAtoms::AddrefAtoms() style = NS_NewAtom("STYLE"); summary = NS_NewAtom("SUMMARY"); suppress = NS_NewAtom("SUPPRESS"); + tabindex = NS_NewAtom("TABINDEX"); table = NS_NewAtom("TABLE"); tabstop = NS_NewAtom("TABSTOP"); target = NS_NewAtom("TARGET"); diff --git a/mozilla/layout/base/src/nsContentList.cpp b/mozilla/layout/base/src/nsContentList.cpp index d3700fca760..67d37cde98e 100644 --- a/mozilla/layout/base/src/nsContentList.cpp +++ b/mozilla/layout/base/src/nsContentList.cpp @@ -32,7 +32,7 @@ nsContentList::nsContentList(nsIDocument *aDocument) } nsContentList::nsContentList(nsIDocument *aDocument, - const nsString& aMatchTag) + const nsString& aMatchTag) { mMatchTag = new nsString(aMatchTag); mFunc = nsnull; @@ -40,7 +40,7 @@ nsContentList::nsContentList(nsIDocument *aDocument, } nsContentList::nsContentList(nsIDocument *aDocument, - nsContentListMatchFunc aFunc) + nsContentListMatchFunc aFunc) { mFunc = aFunc; mMatchTag = nsnull; @@ -197,10 +197,10 @@ nsContentList::NamedItem(const nsString& aName, nsIDOMNode** aReturn) nsAutoString name; // XXX Should it be an EqualsIgnoreCase? if (((content->GetAttribute("NAME", name) == eContentAttr_HasValue) && - (aName.Equals(name))) || - ((content->GetAttribute("ID", name) == eContentAttr_HasValue) && - (aName.Equals(name)))) { - return content->QueryInterface(kIDOMNodeIID, (void **)aReturn); + (aName.Equals(name))) || + ((content->GetAttribute("ID", name) == eContentAttr_HasValue) && + (aName.Equals(name)))) { + return content->QueryInterface(kIDOMNodeIID, (void **)aReturn); } } } @@ -274,7 +274,7 @@ void nsContentList::PopulateSelf(nsIContent *aContent) NS_IMETHODIMP nsContentList::ContentAppended(nsIDocument *aDocument, - nsIContent* aContainer) + nsIContent* aContainer) { if (aContainer->ChildCount() > 0) { nsIContent *content = aContainer->ChildAt(aContainer->ChildCount()-1); @@ -292,9 +292,9 @@ nsContentList::ContentAppended(nsIDocument *aDocument, NS_IMETHODIMP nsContentList::ContentInserted(nsIDocument *aDocument, - nsIContent* aContainer, - nsIContent* aChild, - PRInt32 aIndexInContainer) + nsIContent* aContainer, + nsIContent* aChild, + PRInt32 aIndexInContainer) { if (MatchSelf(aChild)) { Reset(); @@ -308,10 +308,10 @@ nsContentList::ContentInserted(nsIDocument *aDocument, NS_IMETHODIMP nsContentList::ContentReplaced(nsIDocument *aDocument, - nsIContent* aContainer, - nsIContent* aOldChild, - nsIContent* aNewChild, - PRInt32 aIndexInContainer) + nsIContent* aContainer, + nsIContent* aOldChild, + nsIContent* aNewChild, + PRInt32 aIndexInContainer) { if (MatchSelf(aOldChild) || MatchSelf(aNewChild)) { Reset(); @@ -325,9 +325,9 @@ nsContentList::ContentReplaced(nsIDocument *aDocument, NS_IMETHODIMP nsContentList::ContentHasBeenRemoved(nsIDocument *aDocument, - nsIContent* aContainer, - nsIContent* aChild, - PRInt32 aIndexInContainer) + nsIContent* aContainer, + nsIContent* aChild, + PRInt32 aIndexInContainer) { if (MatchSelf(aChild)) { Reset(); diff --git a/mozilla/layout/html/base/src/nsHTMLAtoms.cpp b/mozilla/layout/html/base/src/nsHTMLAtoms.cpp index 1bf20043b1f..f96a09a8909 100644 --- a/mozilla/layout/html/base/src/nsHTMLAtoms.cpp +++ b/mozilla/layout/html/base/src/nsHTMLAtoms.cpp @@ -21,7 +21,9 @@ nsIAtom* nsHTMLAtoms::_baseHref; nsIAtom* nsHTMLAtoms::_baseTarget; nsIAtom* nsHTMLAtoms::a; nsIAtom* nsHTMLAtoms::above; +nsIAtom* nsHTMLAtoms::accept; nsIAtom* nsHTMLAtoms::acceptcharset; +nsIAtom* nsHTMLAtoms::accesskey; nsIAtom* nsHTMLAtoms::action; nsIAtom* nsHTMLAtoms::active; nsIAtom* nsHTMLAtoms::align; @@ -63,6 +65,7 @@ nsIAtom* nsHTMLAtoms::enctype; nsIAtom* nsHTMLAtoms::face; nsIAtom* nsHTMLAtoms::font; nsIAtom* nsHTMLAtoms::fontWeight; +nsIAtom* nsHTMLAtoms::form; nsIAtom* nsHTMLAtoms::frame; nsIAtom* nsHTMLAtoms::frameborder; nsIAtom* nsHTMLAtoms::frameset; @@ -81,6 +84,7 @@ nsIAtom* nsHTMLAtoms::hspace; nsIAtom* nsHTMLAtoms::httpEquiv; nsIAtom* nsHTMLAtoms::id; nsIAtom* nsHTMLAtoms::iframe; +nsIAtom* nsHTMLAtoms::img; nsIAtom* nsHTMLAtoms::ismap; nsIAtom* nsHTMLAtoms::lang; nsIAtom* nsHTMLAtoms::li; @@ -145,6 +149,7 @@ nsIAtom* nsHTMLAtoms::start; nsIAtom* nsHTMLAtoms::style; nsIAtom* nsHTMLAtoms::summary; nsIAtom* nsHTMLAtoms::suppress; +nsIAtom* nsHTMLAtoms::tabindex; nsIAtom* nsHTMLAtoms::table; nsIAtom* nsHTMLAtoms::tabstop; nsIAtom* nsHTMLAtoms::target; @@ -176,7 +181,9 @@ void nsHTMLAtoms::AddrefAtoms() _baseTarget = NS_NewAtom(NS_HTML_BASE_TARGET); a = NS_NewAtom("A"); above = NS_NewAtom("ABOVE"); + accept = NS_NewAtom("ACCEPT"); acceptcharset = NS_NewAtom("ACCEPTCHARSET"); + accesskey = NS_NewAtom("ACCESSKEY"); action = NS_NewAtom("ACTION"); active = NS_NewAtom("ACTIVE"); align = NS_NewAtom("ALIGN"); @@ -218,6 +225,7 @@ void nsHTMLAtoms::AddrefAtoms() face = NS_NewAtom("FACE"); font = NS_NewAtom("FONT"); fontWeight = NS_NewAtom("FONT-WEIGHT"); + form = NS_NewAtom("FORM"); frame = NS_NewAtom("FRAME"); frameborder = NS_NewAtom("FRAMEBORDER"); frameset = NS_NewAtom("FRAMESET"); @@ -236,6 +244,7 @@ void nsHTMLAtoms::AddrefAtoms() httpEquiv = NS_NewAtom("HTTP-EQUIV"); id = NS_NewAtom("ID"); iframe = NS_NewAtom("IFRAME"); + img = NS_NewAtom("IMG"); ismap = NS_NewAtom("ISMAP"); lang = NS_NewAtom("LANG"); li = NS_NewAtom("LI"); @@ -299,6 +308,7 @@ void nsHTMLAtoms::AddrefAtoms() style = NS_NewAtom("STYLE"); summary = NS_NewAtom("SUMMARY"); suppress = NS_NewAtom("SUPPRESS"); + tabindex = NS_NewAtom("TABINDEX"); table = NS_NewAtom("TABLE"); tabstop = NS_NewAtom("TABSTOP"); target = NS_NewAtom("TARGET"); diff --git a/mozilla/layout/html/base/src/nsHTMLAtoms.h b/mozilla/layout/html/base/src/nsHTMLAtoms.h index 49bc2b14b3b..58af240c228 100644 --- a/mozilla/layout/html/base/src/nsHTMLAtoms.h +++ b/mozilla/layout/html/base/src/nsHTMLAtoms.h @@ -42,7 +42,9 @@ public: // Alphabetical list of html attribute atoms static nsIAtom* a; static nsIAtom* above; + static nsIAtom* accept; static nsIAtom* acceptcharset; + static nsIAtom* accesskey; static nsIAtom* action; static nsIAtom* active; static nsIAtom* align; @@ -89,6 +91,7 @@ public: static nsIAtom* face; static nsIAtom* font; static nsIAtom* fontWeight; + static nsIAtom* form; static nsIAtom* frame; static nsIAtom* frameborder; static nsIAtom* frameset; @@ -110,6 +113,7 @@ public: static nsIAtom* id; static nsIAtom* iframe; + static nsIAtom* img; static nsIAtom* ismap; static nsIAtom* lang; @@ -182,6 +186,7 @@ public: static nsIAtom* summary; static nsIAtom* suppress; + static nsIAtom* tabindex; static nsIAtom* table; static nsIAtom* tabstop; static nsIAtom* target; diff --git a/mozilla/layout/html/document/src/nsHTMLContentSink.cpp b/mozilla/layout/html/document/src/nsHTMLContentSink.cpp index 63ef9a726e4..4aff1f49859 100644 --- a/mozilla/layout/html/document/src/nsHTMLContentSink.cpp +++ b/mozilla/layout/html/document/src/nsHTMLContentSink.cpp @@ -101,6 +101,7 @@ static PRLogModuleInfo* gSinkLogModuleInfo; static NS_DEFINE_IID(kIScrollableViewIID, NS_ISCROLLABLEVIEW_IID); static NS_DEFINE_IID(kIHTMLContentSinkIID, NS_IHTML_CONTENT_SINK_IID); static NS_DEFINE_IID(kIFormControlIID, NS_IFORMCONTROL_IID); +static NS_DEFINE_IID(kIContentIID, NS_ICONTENT_IID); class HTMLContentSink : public nsIHTMLContentSink { public: @@ -566,6 +567,11 @@ HTMLContentSink::OpenForm(const nsIParserNode& aNode) // XXX Temporary code till forms become real content // Add the form to the document ((nsHTMLDocument*)mDocument)->AddForm(mCurrentForm); + nsIContent *content; + if (NS_OK == mCurrentForm->QueryInterface(kIContentIID, (void **)&content)) { + content->SetDocument(mDocument); + NS_RELEASE(content); + } } return NS_OK; @@ -1484,7 +1490,6 @@ HTMLContentSink::FlushText() { if (nsnull != mCurrentText) { // XXX sleazyTextHackXXX repair document pointer in text object - static NS_DEFINE_IID(kIContentIID, NS_ICONTENT_IID); nsIContent* content = nsnull; mCurrentText->QueryInterface(kIContentIID, (void**) &content); content->SetDocument(mDocument); @@ -1802,7 +1807,7 @@ nsresult HTMLContentSink::ProcessSCRIPTTag(const nsIParserNode& aNode) NS_RELEASE(context); NS_RELEASE(owner); } - delete script; + delete [] script; } return rv; diff --git a/mozilla/layout/html/document/src/nsHTMLDocument.cpp b/mozilla/layout/html/document/src/nsHTMLDocument.cpp index 847e30d7fff..83f37b24d3c 100644 --- a/mozilla/layout/html/document/src/nsHTMLDocument.cpp +++ b/mozilla/layout/html/document/src/nsHTMLDocument.cpp @@ -56,6 +56,7 @@ static NS_DEFINE_IID(kIDOMElementIID, NS_IDOMELEMENT_IID); static NS_DEFINE_IID(kIDOMTextIID, NS_IDOMTEXT_IID); static NS_DEFINE_IID(kIHTMLDocumentIID, NS_IHTMLDOCUMENT_IID); static NS_DEFINE_IID(kIDOMHTMLDocumentIID, NS_IDOMHTMLDOCUMENT_IID); +static NS_DEFINE_IID(kIDOMNSHTMLDocumentIID, NS_IDOMNSHTMLDOCUMENT_IID); NS_LAYOUT nsresult NS_NewHTMLDocument(nsIDocument** aInstancePtrResult) @@ -89,9 +90,7 @@ nsHTMLDocument::~nsHTMLDocument() NS_RELEASE(form); } } - if (nsnull != mNamedItems) { - PL_HashTableDestroy(mNamedItems); - } + DeleteNamedItems(); NS_IF_RELEASE(mImages); NS_IF_RELEASE(mApplets); NS_IF_RELEASE(mEmbeds); @@ -121,6 +120,11 @@ NS_IMETHODIMP nsHTMLDocument::QueryInterface(REFNSIID aIID, *aInstancePtr = (void**) (nsIDOMHTMLDocument *)this; return NS_OK; } + if (aIID.Equals(kIDOMNSHTMLDocumentIID)) { + AddRef(); + *aInstancePtr = (void**) (nsIDOMNSHTMLDocument *)this; + return NS_OK; + } return nsDocument::QueryInterface(aIID, aInstancePtr); } @@ -325,20 +329,6 @@ nsHTMLDocument::GetFormAt(PRInt32 aIndex, nsIFormManager **aForm) const return 1;/* XXX NS_NOT_FOUND */ } -NS_IMETHODIMP -nsHTMLDocument::AddNamedItem(const nsString& aName, nsIContent *aContent) -{ - //XXX TBI - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -nsHTMLDocument::RemoveNamedItem(const nsString& aName) -{ - //XXX TBI - return NS_ERROR_NOT_IMPLEMENTED; -} - NS_IMETHODIMP nsHTMLDocument::GetAttributeStyleSheet(nsIHTMLStyleSheet** aResult) { NS_PRECONDITION(nsnull != aResult, "null ptr"); @@ -730,12 +720,50 @@ nsHTMLDocument::Writeln(JSContext *cx, jsval *argv, PRUint32 argc) return result; } +nsIContent * +nsHTMLDocument::MatchName(nsIContent *aContent, const nsString& aName) +{ + static nsAutoString name("NAME"), id("ID"); + nsAutoString value; + nsIContent *result = nsnull; + + if ((eContentAttr_HasValue == aContent->GetAttribute(id, value)) && + aName.Equals(value)) { + return aContent; + } + else if ((eContentAttr_HasValue == aContent->GetAttribute(name, value)) && + aName.Equals(value)) { + return aContent; + } + + PRInt32 i, count; + count = aContent->ChildCount(); + for (i = 0; i < count && result == nsnull; i++) { + nsIContent *child = aContent->ChildAt(i); + result = MatchName(child, aName); + NS_RELEASE(child); + } + + return result; +} NS_IMETHODIMP nsHTMLDocument::GetElementById(const nsString& aElementId, nsIDOMElement** aReturn) { - //XXX TBI - return NS_ERROR_NOT_IMPLEMENTED; + nsIContent *content; + + // XXX For now, we do a brute force search of the content tree. + // We should come up with a more efficient solution. + content = MatchName(mRootContent, aElementId); + + if (nsnull != content) { + return content->QueryInterface(kIDOMElementIID, (void **)aReturn); + } + else { + *aReturn = nsnull; + } + + return NS_OK; } NS_IMETHODIMP @@ -745,10 +773,201 @@ nsHTMLDocument::GetElementsByName(const nsString& aElementName, nsIDOMNodeList** return NS_ERROR_NOT_IMPLEMENTED; } -NS_IMETHODIMP -nsHTMLDocument::GetNamedItem(const nsString& aName, nsIDOMElement **aReturn) +NS_IMETHODIMP +nsHTMLDocument::GetAlinkColor(nsString& aAlinkColor) { - return NS_OK; + //XXX TBI + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsHTMLDocument::SetAlinkColor(const nsString& aAlinkColor) +{ + //XXX TBI + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsHTMLDocument::GetLinkColor(nsString& aLinkColor) +{ + //XXX TBI + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsHTMLDocument::SetLinkColor(const nsString& aLinkColor) +{ + //XXX TBI + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsHTMLDocument::GetVlinkColor(nsString& aVlinkColor) +{ + //XXX TBI + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsHTMLDocument::SetVlinkColor(const nsString& aVlinkColor) +{ + //XXX TBI + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsHTMLDocument::GetBgColor(nsString& aBgColor) +{ + //XXX TBI + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsHTMLDocument::SetBgColor(const nsString& aBgColor) +{ + //XXX TBI + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsHTMLDocument::GetFgColor(nsString& aFgColor) +{ + //XXX TBI + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsHTMLDocument::SetFgColor(const nsString& aFgColor) +{ + //XXX TBI + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsHTMLDocument::GetLastModified(nsString& aLastModified) +{ + //XXX TBI + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsHTMLDocument::GetEmbeds(nsIDOMHTMLCollection** aEmbeds) +{ + //XXX TBI + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsHTMLDocument::GetLayers(nsIDOMHTMLCollection** aLayers) +{ + //XXX TBI + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsHTMLDocument::GetPlugins(nsIDOMHTMLCollection** aPlugins) +{ + //XXX TBI + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsHTMLDocument::GetSelection(nsString& aReturn) +{ + //XXX TBI + return NS_ERROR_NOT_IMPLEMENTED; +} + +PRIntn +nsHTMLDocument::RemoveStrings(PLHashEntry *he, PRIntn i, void *arg) +{ + char *str = (char *)he->key; + + delete [] str; + return HT_ENUMERATE_REMOVE; +} + +void +nsHTMLDocument::DeleteNamedItems() +{ + if (nsnull != mNamedItems) { + PL_HashTableEnumerateEntries(mNamedItems, RemoveStrings, nsnull); + PL_HashTableDestroy(mNamedItems); + mNamedItems = nsnull; + } +} + +void +nsHTMLDocument::RegisterNamedItems(nsIContent *aContent, PRBool aInForm) +{ + static nsAutoString name("NAME"); + nsAutoString value; + nsIAtom *tag = aContent->GetTag(); + PRBool inForm; + + // Only the content types reflected in Level 0 with a NAME + // attribute are registered. Images and forms always get + // reflected up to the document. Applets and embeds only go + // to the closest container (which could be a form). + if ((tag == nsHTMLAtoms::img) || (tag == nsHTMLAtoms::form) || + (!aInForm && ((tag == nsHTMLAtoms::applet) || + (tag == nsHTMLAtoms::embed)))) { + if (eContentAttr_HasValue == aContent->GetAttribute(name, value)) { + char *nameStr = value.ToNewCString(); + PL_HashTableAdd(mNamedItems, nameStr, aContent); + } + } + + inForm = aInForm || (tag == nsHTMLAtoms::form); + NS_IF_RELEASE(tag); + + PRInt32 i, count; + count = aContent->ChildCount(); + for (i = 0; i < count; i++) { + nsIContent *child = aContent->ChildAt(i); + RegisterNamedItems(child, inForm); + NS_RELEASE(child); + } +} + +NS_IMETHODIMP +nsHTMLDocument::NamedItem(const nsString& aName, nsIDOMElement** aReturn) +{ + static nsAutoString name("NAME"); + nsresult result = NS_OK; + nsIContent *content; + + if (nsnull == mNamedItems) { + mNamedItems = PL_NewHashTable(10, PL_HashString, PL_CompareStrings, + PL_CompareValues, nsnull, nsnull); + RegisterNamedItems(mRootContent, PR_FALSE); + // XXX Need to do this until forms become real content + PRInt32 i, count = mTempForms.Count(); + for (i = 0; i < count; i++) { + nsIFormManager *form = (nsIFormManager *)mTempForms.ElementAt(i); + if (NS_OK == form->QueryInterface(kIContentIID, (void **)&content)) { + nsAutoString value; + if (eContentAttr_HasValue == content->GetAttribute(name, value)) { + char *nameStr = value.ToNewCString(); + PL_HashTableAdd(mNamedItems, nameStr, content); + } + NS_RELEASE(content); + } + } + } + + char *str = aName.ToNewCString(); + + content = (nsIContent *)PL_HashTableLookup(mNamedItems, str); + if (nsnull != content) { + result = content->QueryInterface(kIDOMElementIID, (void **)aReturn); + } + else { + *aReturn = nsnull; + } + + delete [] str; + return result; } NS_IMETHODIMP diff --git a/mozilla/layout/html/document/src/nsHTMLDocument.h b/mozilla/layout/html/document/src/nsHTMLDocument.h index 7fe15b68570..4b4dff32fda 100644 --- a/mozilla/layout/html/document/src/nsHTMLDocument.h +++ b/mozilla/layout/html/document/src/nsHTMLDocument.h @@ -22,6 +22,7 @@ #include "nsMarkupDocument.h" #include "nsIHTMLDocument.h" #include "nsIDOMHTMLDocument.h" +#include "nsIDOMNSHTMLDocument.h" #include "plhash.h" class nsIHTMLStyleSheet; @@ -29,7 +30,7 @@ class nsContentList; class nsIContentViewerContainer; class nsIParser; -class nsHTMLDocument : public nsMarkupDocument, public nsIHTMLDocument, public nsIDOMHTMLDocument { +class nsHTMLDocument : public nsMarkupDocument, public nsIHTMLDocument, public nsIDOMHTMLDocument, public nsIDOMNSHTMLDocument { public: nsHTMLDocument(); virtual ~nsHTMLDocument(); @@ -45,8 +46,6 @@ public: NS_IMETHOD EndLoad(); - NS_IMETHOD SetTitle(const nsString& aTitle); - NS_IMETHOD AddImageMap(nsIImageMap* aMap); NS_IMETHOD GetImageMap(const nsString& aMapName, nsIImageMap** aResult); @@ -62,10 +61,6 @@ public: // XXX // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX - NS_IMETHOD AddNamedItem(const nsString& aName, nsIContent *aContent); - - NS_IMETHOD RemoveNamedItem(const nsString& aName); - NS_IMETHOD GetAttributeStyleSheet(nsIHTMLStyleSheet** aStyleSheet); // nsIDOMDocument interface @@ -97,35 +92,18 @@ public: NS_FORWARD_IDOMNODE(nsDocument) // nsIDOMHTMLDocument interface - NS_IMETHOD GetTitle(nsString& aTitle); - NS_IMETHOD GetReferrer(nsString& aReferrer); - NS_IMETHOD GetFileSize(nsString& aFileSize); - NS_IMETHOD GetFileCreatedDate(nsString& aFileCreatedDate); - NS_IMETHOD GetFileModifiedDate(nsString& aFileModifiedDate); - NS_IMETHOD GetFileUpdatedDate(nsString& aFileUpdatedDate); - NS_IMETHOD GetDomain(nsString& aDomain); - NS_IMETHOD GetURL(nsString& aURL); - NS_IMETHOD GetBody(nsIDOMHTMLElement** aBody); - NS_IMETHOD SetBody(nsIDOMHTMLElement* aBody); - NS_IMETHOD GetImages(nsIDOMHTMLCollection** aImages); - NS_IMETHOD GetApplets(nsIDOMHTMLCollection** aApplets); - NS_IMETHOD GetLinks(nsIDOMHTMLCollection** aLinks); - NS_IMETHOD GetForms(nsIDOMHTMLCollection** aForms); - NS_IMETHOD GetAnchors(nsIDOMHTMLCollection** aAnchors); - NS_IMETHOD GetCookie(nsString& aCookie); - NS_IMETHOD SetCookie(const nsString& aCookie); - NS_IMETHOD Open(JSContext *cx, jsval *argv, PRUint32 argc); - NS_IMETHOD Close(); - NS_IMETHOD Write(JSContext *cx, jsval *argv, PRUint32 argc); - NS_IMETHOD Writeln(JSContext *cx, jsval *argv, PRUint32 argc); - NS_IMETHOD GetElementById(const nsString& aElementId, nsIDOMElement** aReturn); - NS_IMETHOD GetElementsByName(const nsString& aElementName, nsIDOMNodeList** aReturn); - NS_IMETHOD GetNamedItem(const nsString& aName, nsIDOMElement **aReturn); + NS_DECL_IDOMHTMLDOCUMENT + NS_DECL_IDOMNSHTMLDOCUMENT // From nsIScriptObjectOwner interface, implemented by nsDocument NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); protected: + static PRIntn RemoveStrings(PLHashEntry *he, PRIntn i, void *arg); + void RegisterNamedItems(nsIContent *aContent, PRBool aInForm); + void DeleteNamedItems(); + nsIContent *MatchName(nsIContent *aContent, const nsString& aName); + virtual void AddStyleSheetToSet(nsIStyleSheet* aSheet, nsIStyleSet* aSet); static PRBool MatchLinks(nsIContent *aContent); static PRBool MatchAnchors(nsIContent *aContent); diff --git a/mozilla/layout/html/document/src/nsIHTMLDocument.h b/mozilla/layout/html/document/src/nsIHTMLDocument.h index 1b2e04482f2..0fd6da7bef5 100644 --- a/mozilla/layout/html/document/src/nsIHTMLDocument.h +++ b/mozilla/layout/html/document/src/nsIHTMLDocument.h @@ -50,10 +50,6 @@ public: // XXX // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX - NS_IMETHOD AddNamedItem(const nsString& aName, nsIContent *aContent) = 0; - - NS_IMETHOD RemoveNamedItem(const nsString& aName) = 0; - NS_IMETHOD GetAttributeStyleSheet(nsIHTMLStyleSheet** aStyleSheet) = 0; }; diff --git a/mozilla/layout/html/forms/public/nsIFormControl.h b/mozilla/layout/html/forms/public/nsIFormControl.h index 42e0051ecaf..9f74d634bae 100644 --- a/mozilla/layout/html/forms/public/nsIFormControl.h +++ b/mozilla/layout/html/forms/public/nsIFormControl.h @@ -60,10 +60,11 @@ public: /** * Get the name of this control. Controls without names will not have any * data submitted. - * @param aResult the nsString which will be set to the name (out parm) - * @return PR_TRUE if there was a name, PR_FALSE otherwise + * @param aResult the nsString which will be set to the name (out parm). + * If the result has a length of 0, the control has no name + * @return NS_OK if successful */ - virtual PRBool GetName(nsString& aResult) const = 0; + virtual nsresult GetName(nsString& aResult) = 0; /** * Get the number of references to this control by other objects. diff --git a/mozilla/layout/html/forms/src/nsForm.cpp b/mozilla/layout/html/forms/src/nsForm.cpp index 002f7f940e5..f475526a099 100644 --- a/mozilla/layout/html/forms/src/nsForm.cpp +++ b/mozilla/layout/html/forms/src/nsForm.cpp @@ -42,6 +42,7 @@ #include "nsDocument.h" #include "nsHTMLContainer.h" #include "nsIDOMHTMLFormElement.h" +#include "nsIDOMNSHTMLFormElement.h" #include "nsIDOMHTMLCollection.h" #include "nsIScriptObjectOwner.h" @@ -103,9 +104,14 @@ nsString* URLEncode(nsString& aString) //---------------------------------------------------------------------- static NS_DEFINE_IID(kIFormManagerIID, NS_IFORMMANAGER_IID); +static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID); +static NS_DEFINE_IID(kIDOMElementIID, NS_IDOMELEMENT_IID); +static NS_DEFINE_IID(kIDOMHTMLFormElementIID, NS_IDOMHTMLFORMELEMENT_IID); +static NS_DEFINE_IID(kIDOMNSHTMLFormElementIID, NS_IDOMNSHTMLFORMELEMENT_IID); +static NS_DEFINE_IID(kIContentIID, NS_ICONTENT_IID); class nsFormElementList; -class nsForm : public nsHTMLContainer, public nsIFormManager, public nsIDOMHTMLFormElement +class nsForm : public nsHTMLContainer, public nsIFormManager, public nsIDOMHTMLFormElement, public nsIDOMNSHTMLFormElement { public: // Construct a new Form Element with no attributes. This needs to be @@ -163,6 +169,7 @@ public: NS_FORWARD_IDOMHTMLELEMENT(nsHTMLContainer) NS_DECL_IDOMHTMLFORMELEMENT + NS_DECL_IDOMNSHTMLFORMELEMENT NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); @@ -269,6 +276,16 @@ nsresult nsForm::QueryInterface(REFNSIID aIID, void** aInstancePtr) AddRef(); return NS_OK; } + if (aIID.Equals(kIDOMHTMLFormElementIID)) { + *aInstancePtr = (void*)(nsIDOMHTMLFormElement*)this; + AddRef(); + return NS_OK; + } + if (aIID.Equals(kIDOMNSHTMLFormElementIID)) { + *aInstancePtr = (void*)(nsIDOMNSHTMLFormElement*)this; + AddRef(); + return NS_OK; + } } return res; @@ -384,16 +401,8 @@ void nsForm::OnSubmit(nsIPresContext* aPresContext, nsIFrame* aFrame, if (NS_OK == aPresContext->GetLinkHandler(&handler)) { // Resolve url to an absolute url nsIURL* docURL = nsnull; - nsIContent* content; - aFrame->GetContent(content); - if (nsnull != content) { - nsIDocument* doc = nsnull; - content->GetDocument(doc); - if (nsnull != doc) { - docURL = doc->GetDocumentURL(); - NS_RELEASE(doc); - } - NS_RELEASE(content); + if (nsnull != mDocument) { + docURL = mDocument->GetDocumentURL(); } nsAutoString target; @@ -925,7 +934,8 @@ void nsForm::Init(PRBool aReinit) for (int i = 0; i < numControls; i++) { nsIFormControl* control = (nsIFormControl *)GetFormControlAt(i); nsString name; - PRBool hasName = control->GetName(name); + control->GetName(name); + PRBool hasName = name.Length() > 0; nsString type; control->GetType(type); if (type.EqualsIgnoreCase("submit")) { // XXX make constant @@ -976,7 +986,8 @@ void nsForm::OnRadioChecked(nsIFormControl& aControl) { nsString radioName; - if (!aControl.GetName(radioName)) { // don't consider a radio without a name + aControl.GetName(radioName); + if (0 == radioName.Length()) { // don't consider a radio without a name return; } @@ -1097,6 +1108,85 @@ nsForm::SetTarget(const nsString& aTarget) return NS_OK; } +NS_IMETHODIMP +nsForm::Reset() +{ + OnReset(); + + return NS_OK; +} + +NS_IMETHODIMP +nsForm::Submit() +{ + // XXX Need to do something special with mailto: or news: URLs + if (nsnull != mDocument) { + nsIPresShell *shell = mDocument->GetShellAt(0); + if (nsnull != shell) { + nsIPresContext *context = shell->GetPresContext(); + if (nsnull != context) { + // XXX We're currently passing in null for the frame and + // the submitter. It works for now, but might not always + // be correct. In the future, we might not need the + // frame to be passed to the link handler. + OnSubmit(context, nsnull, nsnull); + NS_RELEASE(context); + } + NS_RELEASE(shell); + } + } + + return NS_OK; +} + +NS_IMETHODIMP +nsForm::GetEncoding(nsString& aEncoding) +{ + return GetEnctype(aEncoding); +} + +NS_IMETHODIMP +nsForm::GetLength(PRUint32* aLength) +{ + *aLength = mChildren.Count(); + + return NS_OK; +} + +NS_IMETHODIMP +nsForm::NamedItem(const nsString& aName, nsIDOMElement** aReturn) +{ + // XXX For now we just search our element list. When forms become + // real content, we'll have to look at all our children, similar + // to the way HTMLDocuments do this. + PRInt32 i, count = GetFormControlCount(); + nsresult result = NS_OK; + + *aReturn = nsnull; + for (i = 0; i < count && *aReturn == nsnull; i++) { + nsIFormControl *control = (nsIFormControl *)GetFormControlAt(i); + if (nsnull != control) { + nsIContent *content; + + result = control->QueryInterface(kIContentIID, (void **)&content); + if (NS_OK == result) { + nsAutoString name; + // XXX Should it be an EqualsIgnoreCase? + if (((content->GetAttribute("NAME", name) == eContentAttr_HasValue) && + (aName.Equals(name))) || + ((content->GetAttribute("ID", name) == eContentAttr_HasValue) && + (aName.Equals(name)))) { + result = control->QueryInterface(kIDOMElementIID, (void **)aReturn); + } + NS_RELEASE(content); + } + NS_RELEASE(control); + } + } + + return result; +} + nsresult nsForm::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject) { @@ -1291,8 +1381,6 @@ char* nsForm::Temp_GenerateTempFileName(PRInt32 aMaxSize, char* file_buf) // // Implementation of nsFormElementList // -static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID); -static NS_DEFINE_IID(kIContentIID, NS_ICONTENT_IID); nsFormElementList::nsFormElementList(nsForm *aForm) : mForm(aForm) { @@ -1395,7 +1483,7 @@ nsFormElementList::NamedItem(const nsString& aName, nsIDOMNode** aReturn) nsresult result = NS_OK; *aReturn = nsnull; - for (i = 0; i < count, *aReturn == nsnull; i++) { + for (i = 0; i < count && *aReturn == nsnull; i++) { nsIFormControl *control = (nsIFormControl *)mForm->GetFormControlAt(i); if (nsnull != control) { nsIContent *content; diff --git a/mozilla/layout/html/forms/src/nsInput.cpp b/mozilla/layout/html/forms/src/nsInput.cpp index c30ddc127d5..d7e80f9a1e6 100644 --- a/mozilla/layout/html/forms/src/nsInput.cpp +++ b/mozilla/layout/html/forms/src/nsInput.cpp @@ -35,6 +35,7 @@ #include "nsIWidget.h" #include "nsHTMLForms.h" #include "nsStyleConsts.h" +#include "nsIDOMHTMLFormElement.h" #define ALIGN_UNSET PRUint8(-1) @@ -123,17 +124,28 @@ void nsInput::MapAttributesInto(nsIStyleContext* aContext, static NS_DEFINE_IID(kIFormControlIID, NS_IFORMCONTROL_IID); +static NS_DEFINE_IID(kIDOMHTMLInputElementIID, NS_IDOMHTMLINPUTELEMENT_IID); nsresult nsInput::QueryInterface(REFNSIID aIID, void** aInstancePtr) { if (aIID.Equals(kIFormControlIID)) { AddRef(); - *aInstancePtr = (void**) &mControl; + *aInstancePtr = (void*) (nsIFormControl *)&mControl; + return NS_OK; + } + if (aIID.Equals(kIDOMHTMLInputElementIID)) { + AddRef(); + *aInstancePtr = (void*) (nsIDOMHTMLInputElement *)this; return NS_OK; } return nsHTMLContainer::QueryInterface(aIID, aInstancePtr); } +nsrefcnt nsInput::AddRef(void) +{ + return nsHTMLContainer::AddRef(); +} + PRBool nsInput::IsSuccessful(nsIFormControl* aSubmitter) const { if (nsnull == mName) { @@ -241,17 +253,20 @@ nsInput::GetFormManager() const } /** - * Get the name associated with this form element. If there is no name - * then return PR_FALSE (form elements without names are not submitable). + * Get the name associated with this form element. + * (note that form elements without names are not submitable). */ -PRBool -nsInput::GetName(nsString& aName) const +NS_IMETHODIMP +nsInput::GetName(nsString& aName) { if ((nsnull != mName) && (0 != mName->Length())) { aName = *mName; - return PR_TRUE; } - return PR_FALSE; + else { + aName.SetLength(0); + } + + return NS_OK; } void @@ -420,6 +435,338 @@ void nsInput::SetChecked(PRBool aState, PRBool aSetInitialValue) { } +NS_IMETHODIMP +nsInput::GetDefaultValue(nsString& aDefaultValue) +{ + ((nsHTMLContainer *)this)->GetAttribute(nsHTMLAtoms::value, aDefaultValue); + + return NS_OK; +} + +NS_IMETHODIMP +nsInput::SetDefaultValue(const nsString& aDefaultValue) +{ + ((nsHTMLContainer *)this)->SetAttribute(nsHTMLAtoms::value, aDefaultValue); + + return NS_OK; +} + +NS_IMETHODIMP +nsInput::GetDefaultChecked(PRBool* aDefaultChecked) +{ + *aDefaultChecked = GetChecked(PR_TRUE); + + return NS_OK; +} + +NS_IMETHODIMP +nsInput::SetDefaultChecked(PRBool aDefaultChecked) +{ + SetChecked(aDefaultChecked, PR_TRUE); + + return NS_OK; +} + +NS_IMETHODIMP +nsInput::GetForm(nsIDOMHTMLFormElement** aForm) +{ + static NS_DEFINE_IID(kIDOMHTMLFormElementIID, NS_IDOMHTMLFORMELEMENT_IID); + if (nsnull != mFormMan) { + return mFormMan->QueryInterface(kIDOMHTMLFormElementIID, (void **)aForm); + } + + *aForm = nsnull; + return NS_OK; +} + +NS_IMETHODIMP +nsInput::GetAccept(nsString& aAccept) +{ + ((nsHTMLContainer *)this)->GetAttribute(nsHTMLAtoms::accept, aAccept); + + return NS_OK; +} + +NS_IMETHODIMP +nsInput::SetAccept(const nsString& aAccept) +{ + ((nsHTMLContainer *)this)->SetAttribute(nsHTMLAtoms::accept, aAccept); + + return NS_OK; +} + +NS_IMETHODIMP +nsInput::GetAccessKey(nsString& aAccessKey) +{ + ((nsHTMLContainer *)this)->GetAttribute(nsHTMLAtoms::accesskey, aAccessKey); + + return NS_OK; +} + +NS_IMETHODIMP +nsInput::SetAccessKey(const nsString& aAccessKey) +{ + ((nsHTMLContainer *)this)->SetAttribute(nsHTMLAtoms::accesskey, aAccessKey); + + return NS_OK; +} + +NS_IMETHODIMP +nsInput::GetAlign(nsString& aAlign) +{ + ((nsHTMLContainer *)this)->GetAttribute(nsHTMLAtoms::align, aAlign); + + return NS_OK; +} + +NS_IMETHODIMP +nsInput::SetAlign(const nsString& aAlign) +{ + ((nsHTMLContainer *)this)->SetAttribute(nsHTMLAtoms::align, aAlign); + + return NS_OK; +} + +NS_IMETHODIMP +nsInput::GetAlt(nsString& aAlt) +{ + ((nsHTMLContainer *)this)->GetAttribute(nsHTMLAtoms::alt, aAlt); + + return NS_OK; +} + +NS_IMETHODIMP +nsInput::SetAlt(const nsString& aAlt) +{ + ((nsHTMLContainer *)this)->SetAttribute(nsHTMLAtoms::alt, aAlt); + + return NS_OK; +} + +NS_IMETHODIMP +nsInput::GetChecked(PRBool* aChecked) +{ + *aChecked = GetChecked(PR_FALSE); + + return NS_OK; +} + +NS_IMETHODIMP +nsInput::SetChecked(PRBool aChecked) +{ + SetChecked(aChecked, PR_FALSE); + + return NS_OK; +} + +NS_IMETHODIMP +nsInput::GetDisabled(PRBool* aDisabled) +{ + nsAutoString result; + + *aDisabled = (PRBool)(eContentAttr_HasValue == ((nsHTMLContainer *)this)->GetAttribute(nsHTMLAtoms::disabled, result)); + + return NS_OK; +} + +NS_IMETHODIMP +nsInput::SetDisabled(PRBool aDisabled) +{ + if (PR_TRUE == aDisabled) { + ((nsHTMLContainer *)this)->SetAttribute(nsHTMLAtoms::disabled, ""); + } + else { + UnsetAttribute(nsHTMLAtoms::disabled); + } + + return NS_OK; +} + +NS_IMETHODIMP +nsInput::GetMaxLength(PRInt32* aMaxLength) +{ + nsHTMLValue val; + + ((nsHTMLContainer *)this)->GetAttribute(nsHTMLAtoms::maxlength, val); + *aMaxLength = val.GetIntValue(); + + return NS_OK; +} + +NS_IMETHODIMP +nsInput::SetMaxLength(PRInt32 aMaxLength) +{ + nsHTMLValue val; + + val.SetIntValue(aMaxLength, eHTMLUnit_Integer); + ((nsHTMLTagContent *)this)->SetAttribute(nsHTMLAtoms::maxlength, val); + + return NS_OK; +} + +NS_IMETHODIMP +nsInput::SetName(const nsString& aName) +{ + ((nsHTMLContainer *)this)->SetAttribute(nsHTMLAtoms::name, aName); + + return NS_OK; +} + +NS_IMETHODIMP +nsInput::GetReadOnly(PRBool* aReadOnly) +{ + nsAutoString result; + + *aReadOnly = (PRBool)(eContentAttr_HasValue == ((nsHTMLContainer *)this)->GetAttribute(nsHTMLAtoms::readonly, result)); + + return NS_OK; +} + +NS_IMETHODIMP +nsInput::SetReadOnly(PRBool aReadOnly) +{ + if (PR_TRUE == aReadOnly) { + ((nsHTMLContainer *)this)->SetAttribute(nsHTMLAtoms::readonly, ""); + } + else { + UnsetAttribute(nsHTMLAtoms::readonly); + } + + return NS_OK; +} + +NS_IMETHODIMP +nsInput::GetSize(nsString& aSize) +{ + ((nsHTMLContainer *)this)->GetAttribute(nsHTMLAtoms::size, aSize); + + return NS_OK; +} + +NS_IMETHODIMP +nsInput::SetSize(const nsString& aSize) +{ + ((nsHTMLContainer *)this)->SetAttribute(nsHTMLAtoms::size, aSize); + + return NS_OK; +} + +NS_IMETHODIMP +nsInput::GetSrc(nsString& aSrc) +{ + ((nsHTMLContainer *)this)->GetAttribute(nsHTMLAtoms::src, aSrc); + + return NS_OK; +} + +NS_IMETHODIMP +nsInput::SetSrc(const nsString& aSrc) +{ + ((nsHTMLContainer *)this)->SetAttribute(nsHTMLAtoms::src, aSrc); + + return NS_OK; +} + +NS_IMETHODIMP +nsInput::GetTabIndex(PRInt32* aTabIndex) +{ + nsHTMLValue val; + + ((nsHTMLContainer *)this)->GetAttribute(nsHTMLAtoms::tabindex, val); + *aTabIndex = val.GetIntValue(); + + return NS_OK; +} + +NS_IMETHODIMP +nsInput::SetTabIndex(PRInt32 aTabIndex) +{ + nsHTMLValue val; + + val.SetIntValue(aTabIndex, eHTMLUnit_Integer); + ((nsHTMLTagContent *)this)->SetAttribute(nsHTMLAtoms::tabindex, val); + + return NS_OK; +} + +NS_IMETHODIMP +nsInput::GetType(nsString& aType) +{ + ((nsHTMLContainer *)this)->GetAttribute(nsHTMLAtoms::type, aType); + + return NS_OK; +} + +NS_IMETHODIMP +nsInput::GetUseMap(nsString& aUseMap) +{ + ((nsHTMLContainer *)this)->GetAttribute(nsHTMLAtoms::usemap, aUseMap); + + return NS_OK; +} + +NS_IMETHODIMP +nsInput::SetUseMap(const nsString& aUseMap) +{ + ((nsHTMLContainer *)this)->SetAttribute(nsHTMLAtoms::usemap, aUseMap); + + return NS_OK; +} + +NS_IMETHODIMP +nsInput::GetValue(nsString& aValue) +{ + ((nsHTMLContainer *)this)->GetAttribute(nsHTMLAtoms::value, aValue); + + return NS_OK; +} + +NS_IMETHODIMP +nsInput::SetValue(const nsString& aValue) +{ + ((nsHTMLContainer *)this)->SetAttribute(nsHTMLAtoms::value, aValue); + + return NS_OK; +} + +NS_IMETHODIMP +nsInput::Blur() +{ + //XXX TBI + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsInput::Focus() +{ + //XXX TBI + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsInput::Select() +{ + //XXX TBI + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsInput::Click() +{ + //XXX TBI + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsInput::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject) +{ + nsresult res = NS_OK; + if (nsnull == mScriptObject) { + res = NS_NewScriptHTMLInputElement(aContext, this, mParent, (void**)&mScriptObject); + } + *aScriptObject = mScriptObject; + return res; +} //---------------------------------------------------------------------- @@ -448,7 +795,7 @@ nsresult nsInput::AggInputControl::QueryInterface(REFNSIID aIID, void** aInstanc return GET_OUTER()->QueryInterface(aIID, aInstancePtr); } -PRBool nsInput::AggInputControl::GetName(nsString& aName) const +nsresult nsInput::AggInputControl::GetName(nsString& aName) { return GET_OUTER()->GetName(aName); } diff --git a/mozilla/layout/html/forms/src/nsInput.h b/mozilla/layout/html/forms/src/nsInput.h index 7d893b8d9cb..b69106184a8 100644 --- a/mozilla/layout/html/forms/src/nsInput.h +++ b/mozilla/layout/html/forms/src/nsInput.h @@ -20,6 +20,7 @@ #define nsInput_h___ #include "nsHTMLContainer.h" +#include "nsIDOMHTMLInputElement.h" #include "nsIFormControl.h" #include "nsPoint.h" class nsIFormManager; @@ -33,7 +34,7 @@ class nsIPresContext; * the various Input types (button, checkbox, file, hidden, password, * reset, radio, submit, text) */ -class nsInput : public nsHTMLContainer { +class nsInput : public nsHTMLContainer, public nsIDOMHTMLInputElement { public: typedef nsHTMLContainer nsInputSuper; /** @@ -53,6 +54,7 @@ public: virtual void MapAttributesInto(nsIStyleContext* aContext, nsIPresContext* aPresContext); + /** * @see nsISupports QueryInterface */ @@ -63,6 +65,11 @@ public: */ NS_IMETHOD_(nsrefcnt) Release(void); + /** + * @see nsISupports Release + */ + NS_IMETHOD_(nsrefcnt) AddRef(void); + // nsIFormControl methods virtual PRBool GetCanSubmit() const; @@ -79,11 +86,6 @@ public: */ virtual PRInt32 GetMaxNumValues(); - /** - * @see nsIFormControl GetFormManager - */ - virtual PRBool GetName(nsString& aName) const; - /** * @see nsIFormControl GetFormManager */ @@ -130,6 +132,13 @@ public: */ virtual void SetAttribute(nsIAtom* aAttribute, const nsString& aValue); + NS_FORWARD_IDOMNODE(nsHTMLContainer) + NS_FORWARD_IDOMELEMENT(nsHTMLContainer) + NS_FORWARD_IDOMHTMLELEMENT(nsHTMLContainer) + + NS_DECL_IDOMHTMLINPUTELEMENT + + NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); // misc methods @@ -200,7 +209,7 @@ protected: // nsIFormControl virtual PRBool GetCanSubmit() const; virtual PRBool GetContent(nsString& aResult) const; - virtual PRBool GetName(nsString& aName) const; + virtual nsresult GetName(nsString& aName); virtual void GetType(nsString& aType) const; virtual PRInt32 GetMaxNumValues(); virtual PRBool GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues, diff --git a/mozilla/layout/html/forms/src/nsInputText.h b/mozilla/layout/html/forms/src/nsInputText.h index 164f65fbef1..38cee90b2d4 100644 --- a/mozilla/layout/html/forms/src/nsInputText.h +++ b/mozilla/layout/html/forms/src/nsInputText.h @@ -55,6 +55,10 @@ public: PRInt32 GetMaxLength() const { return mMaxLength; } + // From nsIDOMHTMLInputElement interface + NS_IMETHOD GetMaxLength(PRInt32* aMaxLength) + { *aMaxLength = mMaxLength; return NS_OK; } + virtual PRBool GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues, nsString* aValues, nsString* aNames);