diff --git a/content/base/src/nsGenericElement.cpp b/content/base/src/nsGenericElement.cpp index 5f2eb6407ccd..a8504c061956 100644 --- a/content/base/src/nsGenericElement.cpp +++ b/content/base/src/nsGenericElement.cpp @@ -2188,14 +2188,6 @@ nsGenericElement::Compact() return NS_OK; } -NS_IMETHODIMP -nsGenericElement::SetHTMLAttribute(nsIAtom* aAttribute, - const nsHTMLValue& aValue, - PRBool aNotify) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - NS_IMETHODIMP nsGenericElement::GetHTMLAttribute(nsIAtom* aAttribute, nsHTMLValue& aValue) const diff --git a/content/base/src/nsGenericElement.h b/content/base/src/nsGenericElement.h index 02ab38b50e05..291aa8ebed22 100644 --- a/content/base/src/nsGenericElement.h +++ b/content/base/src/nsGenericElement.h @@ -434,9 +434,6 @@ public: // nsIHTMLContent interface methods NS_IMETHOD Compact(); - NS_IMETHOD SetHTMLAttribute(nsIAtom* aAttribute, - const nsHTMLValue& aValue, - PRBool aNotify); NS_IMETHOD GetHTMLAttribute(nsIAtom* aAttribute, nsHTMLValue& aValue) const; NS_IMETHOD GetAttributeMappingFunction(nsMapRuleToAttributesFunc& aMapRuleFunc) const; diff --git a/content/html/content/public/nsIHTMLContent.h b/content/html/content/public/nsIHTMLContent.h index df665a764e71..ae31afa00106 100644 --- a/content/html/content/public/nsIHTMLContent.h +++ b/content/html/content/public/nsIHTMLContent.h @@ -70,18 +70,6 @@ public: */ NS_IMETHOD Compact() = 0; - /** - * Set an attribute to an HTMLValue type. (Assumes namespace - * kNameSpaceID_None). - * - * @param aAttribute the attribute to set - * @param aValue the value to set it to - * @param aNotify whether to notify the document of the change - */ - NS_IMETHOD SetHTMLAttribute(nsIAtom* aAttribute, - const nsHTMLValue& aValue, - PRBool aNotify) = 0; - /** * Get an attribute as HTMLValue type * diff --git a/content/html/content/src/nsGenericHTMLElement.cpp b/content/html/content/src/nsGenericHTMLElement.cpp index 905047450630..6d74366915e7 100644 --- a/content/html/content/src/nsGenericHTMLElement.cpp +++ b/content/html/content/src/nsGenericHTMLElement.cpp @@ -303,8 +303,7 @@ nsGenericHTMLElement::CopyInnerTo(nsGenericContainerElement* aDst, nsCOMPtr styleRule = do_QueryInterface(ruleClone); NS_ENSURE_TRUE(styleRule, NS_ERROR_UNEXPECTED); - val.SetCSSStyleRuleValue(styleRule); - rv = aDst->SetHTMLAttribute(nsHTMLAtoms::style, val, PR_FALSE); + rv = aDst->SetInlineStyleRule(styleRule, PR_FALSE); NS_ENSURE_SUCCESS(rv, rv); continue; @@ -1763,9 +1762,10 @@ nsGenericHTMLElement::SetAttrAndNotify(PRInt32 aNamespaceID, mutation.mAttrName = aAttribute; nsAutoString newValue; // It sucks that we have to call GetAttr just to get the stringvalue - // here, but in SetHTMLAttribute we don't know the stringvalue. - // If we remove that (or make nsHTMLValue->string conversion possible) - // we wouldn't have to do this. + // here, but in SetInlineStyleRule we don't have the stringvalue + // directly and it would be a waste of time to get it since in the + // common case it's not needed. If we make nsHTMLValue->string + // conversion possible we wouldn't have to do this. GetAttr(aNamespaceID, aAttribute, newValue); if (!newValue.IsEmpty()) { mutation.mNewAttrValue = do_GetAtom(newValue); @@ -1831,58 +1831,6 @@ PRBool nsGenericHTMLElement::IsEventName(nsIAtom* aName) aName == nsLayoutAtoms::onDOMNodeRemoved); } -nsresult -nsGenericHTMLElement::SetHTMLAttribute(nsIAtom* aAttribute, - const nsHTMLValue& aValue, - PRBool aNotify) -{ - if (aAttribute == nsHTMLAtoms::id || aAttribute == nsHTMLAtoms::kClass) { - nsAutoString str; - aValue.ToString(str); - return SetAttr(kNameSpaceID_None, aAttribute, str, aNotify); - } - - PRBool hasListeners = PR_FALSE; - PRBool modification = PR_FALSE; - nsAutoString oldValueStr; - - if (mDocument) { - hasListeners = nsGenericElement::HasMutationListeners(this, - NS_EVENT_BITS_MUTATION_ATTRMODIFIED); - - // If we have no listeners and aNotify is false, we are almost certainly - // coming from the content sink and will almost certainly have no previous - // value. Even if we do, setting the value is cheap when we have no - // listeners and don't plan to notify. The check for aNotify here is an - // optimization; the check for haveListeners is a correctness issue. - if (hasListeners || aNotify) { - // Do nothing if there is no change. Note that operator== on nsHTMLValue - // assumes that two nsHTMLValues are the same if they have the same unit - // and value. For nsHTMLValues whose value is an nsISupports, this means - // that a new nsISupports pointer _must_ be created in order for attribute - // changes to take proper effect. Currently, this only applies to inline - // style, which satisfies this constraint because style rules are - // immutable. - nsHTMLValue oldValue; - nsresult rv = GetHTMLAttribute(aAttribute, oldValue); - modification = rv != NS_CONTENT_ATTR_NOT_THERE; - if (modification && oldValue == aValue) { - return NS_OK; - } - } - - if (hasListeners) { - // save the old attribute so we can set up the mutation event properly - GetAttr(kNameSpaceID_None, aAttribute, oldValueStr); - } - } - - nsAttrValue attrValue(aValue); - - return SetAttrAndNotify(kNameSpaceID_None, aAttribute, nsnull, oldValueStr, - attrValue, modification, hasListeners, aNotify); -} - nsresult nsGenericHTMLElement::UnsetAttr(PRInt32 aNameSpaceID, nsIAtom* aAttribute, PRBool aNotify) @@ -2101,8 +2049,34 @@ nsresult nsGenericHTMLElement::SetInlineStyleRule(nsICSSStyleRule* aStyleRule, PRBool aNotify) { - return SetHTMLAttribute(nsHTMLAtoms::style, nsHTMLValue(aStyleRule), - aNotify); + PRBool hasListeners = PR_FALSE; + PRBool modification = PR_FALSE; + nsAutoString oldValueStr; + + if (mDocument) { + hasListeners = nsGenericElement::HasMutationListeners(this, + NS_EVENT_BITS_MUTATION_ATTRMODIFIED); + + // There's no point in comparing the stylerule pointers since we're always + // getting a new stylerule here. And we can't compare the stringvalues of + // the old and the new rules since both will point to the same declaration + // and thus will be the same. + if (hasListeners) { + // save the old attribute so we can set up the mutation event properly + modification = GetAttr(kNameSpaceID_None, nsHTMLAtoms::style, + oldValueStr) != NS_CONTENT_ATTR_NOT_THERE; + } + else if (aNotify) { + modification = !!mAttrsAndChildren.GetAttr(nsHTMLAtoms::style); + } + } + + // MSVC won't let me do: nsAttrValue attrValue(nsHTMLValue(aStyleRule)); + nsAttrValue attrValue; + attrValue.SetTo(nsHTMLValue(aStyleRule)); + + return SetAttrAndNotify(kNameSpaceID_None, nsHTMLAtoms::style, nsnull, oldValueStr, + attrValue, modification, hasListeners, aNotify); } already_AddRefed @@ -2772,38 +2746,6 @@ nsGenericHTMLElement::ScrollingValueToString(const nsHTMLValue& aValue, return aValue.EnumValueToString(kScrollingTable, aResult); } -nsresult -nsGenericHTMLElement::AttrToURI(nsIAtom* aAttrName, nsAString& aAbsoluteURI) -{ - nsAutoString attrValue; - nsresult rv = GetAttr(kNameSpaceID_None, aAttrName, attrValue); - if (rv != NS_CONTENT_ATTR_HAS_VALUE) { - aAbsoluteURI.Truncate(); - return NS_OK; - } - - nsCOMPtr baseURI = GetBaseURI(); - - nsIDocument* doc = GetOwnerDocument(); - - nsCOMPtr attrURI; - rv = nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(attrURI), - attrValue, doc, baseURI); - - if (NS_FAILED(rv)) { - // Just use the attr value as the result... - aAbsoluteURI = attrValue; - return NS_OK; - } - - NS_ASSERTION(attrURI, "nsContentUtils::NewURIWithDocumentCharset return value lied"); - - nsCAutoString spec; - attrURI->GetSpec(spec); - CopyUTF8toUTF16(spec, aAbsoluteURI); - return NS_OK; -} - nsresult nsGenericHTMLElement::ReparseStyleAttribute() { @@ -2817,7 +2759,7 @@ nsGenericHTMLElement::ReparseStyleAttribute() oldVal->ToString(stringValue); ParseStyleAttribute(this, mNodeInfo->NamespaceEquals(kNameSpaceID_XHTML), stringValue, attrValue); - // Don't bother going through SetHTMLAttribute, we don't want to fire off + // Don't bother going through SetInlineStyleRule, we don't want to fire off // mutation events or document notifications anyway nsresult rv = mAttrsAndChildren.SetAndTakeAttr(nsHTMLAtoms::style, attrValue); NS_ENSURE_SUCCESS(rv, rv); @@ -3302,6 +3244,80 @@ nsGenericHTMLElement::GetContentsAsText(nsAString& aText) return NS_OK; } +void +nsGenericHTMLElement::GetStringAttrWithDefault(nsIAtom* aAttr, + const nsAString& aDefault, + nsAString& aResult) +{ + nsresult rv = GetAttr(kNameSpaceID_None, aAttr, aResult); + if (rv == NS_CONTENT_ATTR_NOT_THERE) { + aResult = aDefault; + } +} + +nsresult +nsGenericHTMLElement::SetBoolAttr(nsIAtom* aAttr, PRBool aValue) +{ + if (aValue) { + return SetAttr(kNameSpaceID_None, aAttr, EmptyString(), PR_TRUE); + } + + return UnsetAttr(kNameSpaceID_None, aAttr, PR_TRUE); +} + +void +nsGenericHTMLElement::GetIntAttr(nsIAtom* aAttr, PRInt32 aDefault, PRInt32* aResult) +{ + const nsAttrValue* attrVal = mAttrsAndChildren.GetAttr(aAttr); + if (attrVal && attrVal->GetType() == nsAttrValue::eHTMLValue && + attrVal->GetHTMLValue()->GetUnit() == eHTMLUnit_Integer) { + *aResult = attrVal->GetHTMLValue()->GetIntValue(); + } + else { + *aResult = aDefault; + } +} + +nsresult +nsGenericHTMLElement::SetIntAttr(nsIAtom* aAttr, PRInt32 aValue) +{ + nsAutoString value; + value.AppendInt(aValue); + + return SetAttr(kNameSpaceID_None, aAttr, value, PR_TRUE); +} + +void +nsGenericHTMLElement::GetURIAttr(nsIAtom* aAttr, nsAString& aResult) +{ + nsAutoString attrValue; + nsresult rv = GetAttr(kNameSpaceID_None, aAttr, attrValue); + if (rv != NS_CONTENT_ATTR_HAS_VALUE) { + aResult.Truncate(); + + return; + } + + nsCOMPtr baseURI = GetBaseURI(); + nsCOMPtr attrURI; + rv = nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(attrURI), + attrValue, GetOwnerDocument(), + baseURI); + if (NS_FAILED(rv)) { + // Just use the attr value as the result... + aResult = attrValue; + + return; + } + + NS_ASSERTION(attrURI, + "nsContentUtils::NewURIWithDocumentCharset return value lied"); + + nsCAutoString spec; + attrURI->GetSpec(spec); + CopyUTF8toUTF16(spec, aResult); +} + //---------------------------------------------------------------------- nsGenericHTMLFormElement::nsGenericHTMLFormElement() diff --git a/content/html/content/src/nsGenericHTMLElement.h b/content/html/content/src/nsGenericHTMLElement.h index a83049e3ca1c..ddf4e66e5410 100644 --- a/content/html/content/src/nsGenericHTMLElement.h +++ b/content/html/content/src/nsGenericHTMLElement.h @@ -201,8 +201,6 @@ public: nsresult GetHrefURIForAnchors(nsIURI** aURI); // Implementation for nsIHTMLContent - NS_IMETHOD SetHTMLAttribute(nsIAtom* aAttribute, const nsHTMLValue& aValue, - PRBool aNotify); NS_IMETHOD GetHTMLAttribute(nsIAtom* aAttribute, nsHTMLValue& aValue) const; NS_IMETHOD GetID(nsIAtom** aResult) const; NS_IMETHOD GetClasses(nsVoidArray& aArray) const; @@ -464,12 +462,6 @@ public: static PRBool ScrollingValueToString(const nsHTMLValue& aValue, nsAString& aResult); - /** - * Take an attribute name, and return the value of that attribute, - * resolved to an absolute URI. Used by NS_IMPL_URI_ATTR macro. - */ - nsresult AttrToURI(nsIAtom* aAttrName, nsAString& aAbsoluteURI); - /** * Create the style struct from the style attr. Used when an element is first * put into a document. Only has an effect if the old value is a string. @@ -777,6 +769,7 @@ protected: * @param aNotify whether to notify the document of child adds/removes */ nsresult ReplaceContentsWithText(const nsAString& aText, PRBool aNotify); + /** * GetContentsAsText will take all the textnodes that are children * of |this| and concatenate the text in them into aText. It @@ -787,6 +780,63 @@ protected: * @param aText the resulting text [OUT] */ nsresult GetContentsAsText(nsAString& aText); + + /** + * Helpermethod for NS_IMPL_STRING_ATTR_DEFAULT_VALUE macro. + * Gets the value of an attribute, returns specified default value if the + * attribute isn't set. Only works for attributes in null namespace. + * + * @param aAttr name of attribute. + * @param aDefault default-value to return if attribute isn't set. + * @param aResult result value [out] + */ + void GetStringAttrWithDefault(nsIAtom* aAttr, + const nsAString& aDefault, + nsAString& aResult); + + /** + * Helpermethod for NS_IMPL_BOOL_ATTR macro. + * Sets value of boolean attribute by removing attribute or setting it to + * the empty string. Only works for attributes in null namespace. + * + * @param aAttr name of attribute. + * @param aValue Boolean value of attribute. + */ + nsresult SetBoolAttr(nsIAtom* aAttr, PRBool aValue); + + /** + * Helpermethod for NS_IMPL_INT_ATTR macro. + * Gets the integer-value of an attribute, returns specified default value + * if the attribute isn't set or isn't set to an integer. Only works for + * attributes in null namespace. + * + * @param aAttr name of attribute. + * @param aDefault default-value to return if attribute isn't set. + * @param aResult result value [out] + */ + void GetIntAttr(nsIAtom* aAttr, PRInt32 aDefault, PRInt32* aValue); + + /** + * Helpermethod for NS_IMPL_INT_ATTR macro. + * Sets value of attribute to specified integer. Only works for attributes + * in null namespace. + * + * @param aAttr name of attribute. + * @param aValue Integer value of attribute. + */ + nsresult SetIntAttr(nsIAtom* aAttr, PRInt32 aValue); + + /** + * Helpermethod for NS_IMPL_URI_ATTR macro. + * Gets the absolute URI value of an attribute, by resolving any relative + * URIs in the attribute against the baseuri of the element. If the attribute + * isn't a relative URI the value of the attribute is returned as is. Only + * works for attributes in null namespace. + * + * @param aAttr name of attribute. + * @param aResult result value [out] + */ + void GetURIAttr(nsIAtom* aAttr, nsAString& aResult); }; @@ -858,7 +908,19 @@ protected: * SetAttr methods. */ #define NS_IMPL_STRING_ATTR(_class, _method, _atom) \ - NS_IMPL_STRING_ATTR_DEFAULT_VALUE(_class, _method, _atom, "") + NS_IMETHODIMP \ + _class::Get##_method(nsAString& aValue) \ + { \ + GetAttr(kNameSpaceID_None, nsHTMLAtoms::_atom, aValue); \ + \ + return NS_OK; \ + } \ + NS_IMETHODIMP \ + _class::Set##_method(const nsAString& aValue) \ + { \ + return SetAttr(kNameSpaceID_None, nsHTMLAtoms::_atom, aValue, \ + PR_TRUE); \ + } /** * A macro to implement the getter and setter for a given string @@ -869,11 +931,10 @@ protected: NS_IMETHODIMP \ _class::Get##_method(nsAString& aValue) \ { \ - nsresult rv = GetAttr(kNameSpaceID_None, \ - nsHTMLAtoms::_atom, aValue); \ - if (rv == NS_CONTENT_ATTR_NOT_THERE) { \ - aValue.Assign(NS_LITERAL_STRING(_default)); \ - } \ + GetStringAttrWithDefault(nsHTMLAtoms::_atom, \ + NS_LITERAL_STRING(_default), \ + aValue); \ + \ return NS_OK; \ } \ NS_IMETHODIMP \ @@ -892,20 +953,14 @@ protected: NS_IMETHODIMP \ _class::Get##_method(PRBool* aValue) \ { \ - nsHTMLValue val; \ - nsresult rv = GetHTMLAttribute(nsHTMLAtoms::_atom, val); \ - *aValue = NS_CONTENT_ATTR_NOT_THERE != rv; \ + *aValue = HasAttr(kNameSpaceID_None, nsHTMLAtoms::_atom); \ + \ return NS_OK; \ } \ NS_IMETHODIMP \ _class::Set##_method(PRBool aValue) \ { \ - if (aValue) { \ - return SetHTMLAttribute(nsHTMLAtoms::_atom, nsHTMLValue(), \ - PR_TRUE); \ - } \ - UnsetAttr(kNameSpaceID_None, nsHTMLAtoms::_atom, PR_TRUE); \ - return NS_OK; \ + return SetBoolAttr(nsHTMLAtoms::_atom, aValue); \ } /** @@ -916,30 +971,18 @@ protected: #define NS_IMPL_INT_ATTR(_class, _method, _atom) \ NS_IMPL_INT_ATTR_DEFAULT_VALUE(_class, _method, _atom, -1) -/** - * A macro to implement the getter and setter for a given integer - * valued content property with a default value. - * The method uses the generic GetAttr and SetAttr methods. - */ -#define NS_IMPL_INT_ATTR_DEFAULT_VALUE(_class, _method, _atom, _default) \ - NS_IMETHODIMP \ - _class::Get##_method(PRInt32* aValue) \ - { \ - nsHTMLValue value; \ - *aValue = _default; \ - if (NS_CONTENT_ATTR_HAS_VALUE == \ - GetHTMLAttribute(nsHTMLAtoms::_atom, value)) { \ - if (value.GetUnit() == eHTMLUnit_Integer) { \ - *aValue = value.GetIntValue(); \ - } \ - } \ - return NS_OK; \ - } \ - NS_IMETHODIMP \ - _class::Set##_method(PRInt32 aValue) \ - { \ - nsHTMLValue value(aValue, eHTMLUnit_Integer); \ - return SetHTMLAttribute(nsHTMLAtoms::_atom, value, PR_TRUE); \ +#define NS_IMPL_INT_ATTR_DEFAULT_VALUE(_class, _method, _atom, _default) \ + NS_IMETHODIMP \ + _class::Get##_method(PRInt32* aValue) \ + { \ + GetIntAttr(nsHTMLAtoms::_atom, _default, aValue); \ + \ + return NS_OK; \ + } \ + NS_IMETHODIMP \ + _class::Set##_method(PRInt32 aValue) \ + { \ + return SetIntAttr(nsHTMLAtoms::_atom, aValue); \ } /** @@ -949,22 +992,20 @@ protected: * like the NS_IMPL_STRING_ATTR macro, except we make sure the URI is * absolute. */ -#define NS_IMPL_URI_ATTR_GETTER(_class, _method, _atom) \ +#define NS_IMPL_URI_ATTR(_class, _method, _atom) \ NS_IMETHODIMP \ _class::Get##_method(nsAString& aValue) \ { \ - return AttrToURI(nsHTMLAtoms::_atom, aValue); \ - } -#define NS_IMPL_URI_ATTR_SETTER(_class, _method, _atom) \ + GetURIAttr(nsHTMLAtoms::_atom, aValue); \ + \ + return NS_OK; \ + } \ NS_IMETHODIMP \ _class::Set##_method(const nsAString& aValue) \ { \ return SetAttr(kNameSpaceID_None, nsHTMLAtoms::_atom, aValue, \ PR_TRUE); \ } -#define NS_IMPL_URI_ATTR(_class, _method, _atom) \ - NS_IMPL_URI_ATTR_GETTER(_class, _method, _atom) \ - NS_IMPL_URI_ATTR_SETTER(_class, _method, _atom) /** * QueryInterface() implementation helper macros diff --git a/content/html/content/src/nsHTMLBaseFontElement.cpp b/content/html/content/src/nsHTMLBaseFontElement.cpp index 6712e9132c24..35e8c7b3319a 100644 --- a/content/html/content/src/nsHTMLBaseFontElement.cpp +++ b/content/html/content/src/nsHTMLBaseFontElement.cpp @@ -195,7 +195,5 @@ nsHTMLBaseFontElement::GetSize(PRInt32 *aSize) NS_IMETHODIMP nsHTMLBaseFontElement::SetSize(PRInt32 aSize) { - nsHTMLValue value(aSize, eHTMLUnit_Integer); - - return SetHTMLAttribute(nsHTMLAtoms::size, value, PR_TRUE); + return SetIntAttr(nsHTMLAtoms::size, aSize); } diff --git a/content/html/content/src/nsHTMLButtonElement.cpp b/content/html/content/src/nsHTMLButtonElement.cpp index 7b4b5373ca0f..fd031d331ea7 100644 --- a/content/html/content/src/nsHTMLButtonElement.cpp +++ b/content/html/content/src/nsHTMLButtonElement.cpp @@ -214,26 +214,12 @@ nsHTMLButtonElement::GetForm(nsIDOMHTMLFormElement** aForm) return nsGenericHTMLFormElement::GetForm(aForm); } -NS_IMETHODIMP -nsHTMLButtonElement::GetType(nsAString& aType) -{ - return AttributeToString(nsHTMLAtoms::type, - nsHTMLValue(mType, eHTMLUnit_Enumerated), - aType); -} - - -NS_IMETHODIMP -nsHTMLButtonElement::SetType(const nsAString& aType) -{ - return SetAttr(kNameSpaceID_None, nsHTMLAtoms::type, aType, PR_TRUE); -} - NS_IMPL_STRING_ATTR(nsHTMLButtonElement, AccessKey, accesskey) NS_IMPL_BOOL_ATTR(nsHTMLButtonElement, Disabled, disabled) NS_IMPL_STRING_ATTR(nsHTMLButtonElement, Name, name) NS_IMPL_INT_ATTR(nsHTMLButtonElement, TabIndex, tabindex) NS_IMPL_STRING_ATTR(nsHTMLButtonElement, Value, value) +NS_IMPL_STRING_ATTR_DEFAULT_VALUE(nsHTMLButtonElement, Type, type, "submit") NS_IMETHODIMP nsHTMLButtonElement::Blur() diff --git a/content/html/content/src/nsHTMLImageElement.cpp b/content/html/content/src/nsHTMLImageElement.cpp index fec2eb16eecd..83dcb8043c37 100644 --- a/content/html/content/src/nsHTMLImageElement.cpp +++ b/content/html/content/src/nsHTMLImageElement.cpp @@ -265,7 +265,7 @@ NS_IMPL_INT_ATTR(nsHTMLImageElement, Hspace, hspace) NS_IMPL_BOOL_ATTR(nsHTMLImageElement, IsMap, ismap) NS_IMPL_URI_ATTR(nsHTMLImageElement, LongDesc, longdesc) NS_IMPL_STRING_ATTR(nsHTMLImageElement, Lowsrc, lowsrc) -NS_IMPL_URI_ATTR_GETTER(nsHTMLImageElement, Src, src) +NS_IMPL_URI_ATTR(nsHTMLImageElement, Src, src) NS_IMPL_STRING_ATTR(nsHTMLImageElement, UseMap, usemap) NS_IMPL_INT_ATTR(nsHTMLImageElement, Vspace, vspace) @@ -593,7 +593,34 @@ nsHTMLImageElement::SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName, // image load from SetParent. Skip the ImageURIChanged call in that case. if (aNotify && aNameSpaceID == kNameSpaceID_None && aName == nsHTMLAtoms::src) { + + // If caller is not chrome and dom.disable_image_src_set is true, + // prevent setting image.src by exiting early + nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); + if (prefBranch) { + PRBool disableImageSrcSet = PR_FALSE; + prefBranch->GetBoolPref("dom.disable_image_src_set", &disableImageSrcSet); + + if (disableImageSrcSet && !nsContentUtils::IsCallerChrome()) { + return NS_OK; + } + } + + nsCOMPtr oldCurrentRequest = mCurrentRequest; + ImageURIChanged(aValue); + + if (mCurrentRequest && !mPendingRequest && + oldCurrentRequest != mCurrentRequest) { + // We have a current request, and it's not the same one as we used + // to have, and we have no pending request. So imglib already had + // that image. Reset the animation on it -- see bug 210001 + nsCOMPtr container; + mCurrentRequest->GetImage(getter_AddRefs(container)); + if (container) { + container->ResetAnimation(); + } + } } return nsGenericHTMLElement::SetAttr(aNameSpaceID, aName, aPrefix, aValue, @@ -648,9 +675,7 @@ nsHTMLImageElement::Initialize(JSContext* aContext, JSObject *aObj, JSBool ret = JS_ValueToInt32(aContext, argv[0], &width); NS_ENSURE_TRUE(ret, NS_ERROR_INVALID_ARG); - nsHTMLValue widthVal((PRInt32)width, eHTMLUnit_Integer); - - nsresult rv = SetHTMLAttribute(nsHTMLAtoms::width, widthVal, PR_FALSE); + nsresult rv = SetIntAttr(nsHTMLAtoms::width, NS_STATIC_CAST(PRInt32, width)); if (NS_SUCCEEDED(rv) && (argc > 1)) { // The second (optional) argument is the height of the image @@ -658,54 +683,12 @@ nsHTMLImageElement::Initialize(JSContext* aContext, JSObject *aObj, ret = JS_ValueToInt32(aContext, argv[1], &height); NS_ENSURE_TRUE(ret, NS_ERROR_INVALID_ARG); - nsHTMLValue heightVal((PRInt32)height, eHTMLUnit_Integer); - - rv = SetHTMLAttribute(nsHTMLAtoms::height, heightVal, PR_FALSE); + rv = SetIntAttr(nsHTMLAtoms::height, NS_STATIC_CAST(PRInt32, height)); } return rv; } -NS_IMETHODIMP -nsHTMLImageElement::SetSrc(const nsAString& aSrc) -{ - /* - * If caller is not chrome and dom.disable_image_src_set is true, - * prevent setting image.src by exiting early - */ - - nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (prefBranch) { - PRBool disableImageSrcSet = PR_FALSE; - prefBranch->GetBoolPref("dom.disable_image_src_set", &disableImageSrcSet); - - if (disableImageSrcSet && !nsContentUtils::IsCallerChrome()) { - return NS_OK; - } - } - - nsCOMPtr oldCurrentRequest = mCurrentRequest; - - // Call ImageURIChanged first so that our image load will kick off - // before the SetAttr triggers a reflow - ImageURIChanged(aSrc); - - if (mCurrentRequest && !mPendingRequest && - oldCurrentRequest != mCurrentRequest) { - // We have a current request, and it's not the same one as we used - // to have, and we have no pending request. So imglib already had - // that image. Reset the animation on it -- see bug 210001 - nsCOMPtr container; - mCurrentRequest->GetImage(getter_AddRefs(container)); - if (container) { - container->ResetAnimation(); - } - } - - return nsGenericHTMLElement::SetAttr(kNameSpaceID_None, nsHTMLAtoms::src, - aSrc, PR_TRUE); -} - NS_IMETHODIMP nsHTMLImageElement::GetNaturalHeight(PRInt32* aNaturalHeight) { diff --git a/content/html/content/src/nsHTMLInputElement.cpp b/content/html/content/src/nsHTMLInputElement.cpp index 2b75802d69d5..0d2bef7f36a3 100644 --- a/content/html/content/src/nsHTMLInputElement.cpp +++ b/content/html/content/src/nsHTMLInputElement.cpp @@ -468,6 +468,10 @@ nsHTMLInputElement::BeforeSetAttr(PRInt32 aNameSpaceID, nsIAtom* aName, const nsAString* aValue, PRBool aNotify) { + if (aNameSpaceID != kNameSpaceID_None) { + return; + } + // // When name or type changes, radio should be removed from radio group. // (type changes are handled in the form itself currently) @@ -478,10 +482,11 @@ nsHTMLInputElement::BeforeSetAttr(PRInt32 aNameSpaceID, nsIAtom* aName, (mForm || !(GET_BOOLBIT(mBitField, BF_PARSER_CREATING)))) { WillRemoveFromRadioGroup(); } else if (aNotify && aName == nsHTMLAtoms::src && - aNameSpaceID == kNameSpaceID_None && aValue && mType == NS_FORM_INPUT_IMAGE) { // Null value means the attr got unset; don't trigger on that ImageURIChanged(*aValue); + } else if (aNotify && aName == nsHTMLAtoms::disabled) { + SET_BOOLBIT(mBitField, BF_DISABLED_CHANGED, PR_TRUE); } } @@ -490,6 +495,10 @@ nsHTMLInputElement::AfterSetAttr(PRInt32 aNameSpaceID, nsIAtom* aName, const nsAString* aValue, PRBool aNotify) { + if (aNameSpaceID != kNameSpaceID_None) { + return; + } + // // When name or type changes, radio should be added to radio group. // (type changes are handled in the form itself currently) @@ -570,54 +579,14 @@ nsHTMLInputElement::GetForm(nsIDOMHTMLFormElement** aForm) return nsGenericHTMLFormElement::GetForm(aForm); } -NS_IMETHODIMP -nsHTMLInputElement::GetDefaultValue(nsAString& aDefaultValue) -{ - return GetAttr(kNameSpaceID_None, nsHTMLAtoms::value, aDefaultValue); -} - -NS_IMETHODIMP -nsHTMLInputElement::SetDefaultValue(const nsAString& aDefaultValue) -{ - return SetAttr(kNameSpaceID_None, nsHTMLAtoms::value, aDefaultValue, - PR_TRUE); -} - -NS_IMETHODIMP -nsHTMLInputElement::GetDefaultChecked(PRBool* aDefaultChecked) -{ - nsHTMLValue val; - nsresult rv; - rv = GetHTMLAttribute(nsHTMLAtoms::checked, val); - - *aDefaultChecked = (NS_CONTENT_ATTR_NOT_THERE != rv); - - return NS_OK; -} - -NS_IMETHODIMP -nsHTMLInputElement::SetDefaultChecked(PRBool aDefaultChecked) -{ - nsresult rv; - - if (aDefaultChecked) { - rv = SetAttr(kNameSpaceID_None, nsHTMLAtoms::checked, EmptyString(), - PR_TRUE); - } else { - rv = UnsetAttr(kNameSpaceID_None, nsHTMLAtoms::checked, PR_TRUE); - } - - return rv; -} - -//NS_IMPL_STRING_ATTR(nsHTMLInputElement, DefaultValue, defaultvalue) -//NS_IMPL_BOOL_ATTR(nsHTMLInputElement, DefaultChecked, defaultchecked) +NS_IMPL_STRING_ATTR(nsHTMLInputElement, DefaultValue, value) +NS_IMPL_BOOL_ATTR(nsHTMLInputElement, DefaultChecked, checked) NS_IMPL_STRING_ATTR(nsHTMLInputElement, Accept, accept) NS_IMPL_STRING_ATTR(nsHTMLInputElement, AccessKey, accesskey) NS_IMPL_STRING_ATTR(nsHTMLInputElement, Align, align) NS_IMPL_STRING_ATTR(nsHTMLInputElement, Alt, alt) //NS_IMPL_BOOL_ATTR(nsHTMLInputElement, Checked, checked) -//NS_IMPL_BOOL_ATTR(nsHTMLInputElement, Disabled, disabled) +NS_IMPL_BOOL_ATTR(nsHTMLInputElement, Disabled, disabled) NS_IMPL_INT_ATTR(nsHTMLInputElement, MaxLength, maxlength) NS_IMPL_STRING_ATTR(nsHTMLInputElement, Name, name) NS_IMPL_BOOL_ATTR(nsHTMLInputElement, ReadOnly, readonly) @@ -625,28 +594,8 @@ NS_IMPL_STRING_ATTR(nsHTMLInputElement, Src, src) NS_IMPL_INT_ATTR(nsHTMLInputElement, TabIndex, tabindex) NS_IMPL_STRING_ATTR(nsHTMLInputElement, UseMap, usemap) //NS_IMPL_STRING_ATTR(nsHTMLInputElement, Value, value) - -NS_IMETHODIMP -nsHTMLInputElement::GetDisabled(PRBool* aDisabled) -{ - nsHTMLValue val; - nsresult rv = GetHTMLAttribute(nsHTMLAtoms::disabled, val); - *aDisabled = (NS_CONTENT_ATTR_NOT_THERE != rv); - return NS_OK; -} - -NS_IMETHODIMP -nsHTMLInputElement::SetDisabled(PRBool aDisabled) -{ - SET_BOOLBIT(mBitField, BF_DISABLED_CHANGED, PR_TRUE); - - if (aDisabled) { - return SetHTMLAttribute(nsHTMLAtoms::disabled, nsHTMLValue(), PR_TRUE); - } - - UnsetAttr(kNameSpaceID_None, nsHTMLAtoms::disabled, PR_TRUE); - return NS_OK; -} +//NS_IMPL_INT_ATTR_DEFAULT_VALUE(nsHTMLInputElement, Size, size, 0) +NS_IMPL_STRING_ATTR_DEFAULT_VALUE(nsHTMLInputElement, Type, type, "text") NS_IMETHODIMP nsHTMLInputElement::GetSize(PRUint32* aValue) @@ -666,27 +615,10 @@ nsHTMLInputElement::GetSize(PRUint32* aValue) NS_IMETHODIMP nsHTMLInputElement::SetSize(PRUint32 aValue) { - nsHTMLValue value(aValue, eHTMLUnit_Integer); - return SetHTMLAttribute(nsHTMLAtoms::size, value, PR_TRUE); -} + nsAutoString val; + val.AppendInt(aValue); -NS_IMETHODIMP -nsHTMLInputElement::GetType(nsAString& aValue) -{ - nsresult rv = GetAttr(kNameSpaceID_None, nsHTMLAtoms::type, aValue); - - if (rv == NS_CONTENT_ATTR_NOT_THERE) - aValue.Assign(NS_LITERAL_STRING("text")); - - return NS_OK; -} - -NS_IMETHODIMP -nsHTMLInputElement::SetType(const nsAString& aValue) -{ - return SetAttr(kNameSpaceID_None, - nsHTMLAtoms::type, aValue, - PR_TRUE); + return SetAttr(kNameSpaceID_None, nsHTMLAtoms::size, val, PR_TRUE); } NS_IMETHODIMP diff --git a/content/html/content/src/nsHTMLLabelElement.cpp b/content/html/content/src/nsHTMLLabelElement.cpp index 535846539d8f..2ed7539ca444 100644 --- a/content/html/content/src/nsHTMLLabelElement.cpp +++ b/content/html/content/src/nsHTMLLabelElement.cpp @@ -68,95 +68,8 @@ public: // nsIDOMNode NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLFormElement::) - // nsIDOMElement, because of the "htmlFor" attribute handling we can't - // use the NS_FORWARD_NSIDOMHTMLELEMENT macro here... - NS_IMETHOD GetTagName(nsAString& aTagName) { - return nsGenericHTMLFormElement::GetTagName(aTagName); - } - NS_IMETHOD GetAttribute(const nsAString& aName, - nsAString& aReturn) { - nsAutoString name(aName); - if (name.EqualsIgnoreCase("htmlfor")) { - return nsGenericHTMLFormElement::GetAttribute(NS_LITERAL_STRING("for"), aReturn); - } - return nsGenericHTMLFormElement::GetAttribute(aName, aReturn); - } - NS_IMETHOD SetAttribute(const nsAString& aName, - const nsAString& aValue) { - nsAutoString name(aName); - if (name.EqualsIgnoreCase("htmlfor")) { - return nsGenericHTMLFormElement::SetAttribute(NS_LITERAL_STRING("for"), aValue); - } - return nsGenericHTMLFormElement::SetAttribute(aName, aValue); - } - NS_IMETHOD RemoveAttribute(const nsAString& aName) { - nsAutoString name(aName); - if (name.EqualsIgnoreCase("htmlfor")) { - return nsGenericHTMLFormElement::RemoveAttribute(NS_LITERAL_STRING("for")); - } - return nsGenericHTMLFormElement::RemoveAttribute(aName); - } - NS_IMETHOD GetAttributeNode(const nsAString& aName, - nsIDOMAttr** aReturn) { - nsAutoString name(aName); - if (name.EqualsIgnoreCase("htmlfor")) { - return nsGenericHTMLFormElement::GetAttributeNode(NS_LITERAL_STRING("for"), aReturn); - } - return nsGenericHTMLFormElement::GetAttributeNode(aName, aReturn); - } - NS_IMETHOD SetAttributeNode(nsIDOMAttr* aNewAttr, nsIDOMAttr** aReturn) { - return nsGenericHTMLFormElement::SetAttributeNode(aNewAttr, aReturn); - } - NS_IMETHOD RemoveAttributeNode(nsIDOMAttr* aOldAttr, nsIDOMAttr** aReturn) { - return nsGenericHTMLFormElement::RemoveAttributeNode(aOldAttr, aReturn); - } - NS_IMETHOD GetElementsByTagName(const nsAString& aTagname, - nsIDOMNodeList** aReturn) { - return nsGenericHTMLFormElement::GetElementsByTagName(aTagname, aReturn); - } - NS_IMETHOD GetAttributeNS(const nsAString& aNamespaceURI, - const nsAString& aLocalName, - nsAString& aReturn) { - return nsGenericHTMLFormElement::GetAttributeNS(aNamespaceURI, aLocalName, - aReturn); - } - NS_IMETHOD SetAttributeNS(const nsAString& aNamespaceURI, - const nsAString& aQualifiedName, - const nsAString& aValue) { - return nsGenericHTMLFormElement::SetAttributeNS(aNamespaceURI, - aQualifiedName, - aValue); - } - NS_IMETHOD RemoveAttributeNS(const nsAString& aNamespaceURI, - const nsAString& aLocalName) { - return nsGenericHTMLFormElement::RemoveAttributeNS(aNamespaceURI, - aLocalName); - } - NS_IMETHOD GetAttributeNodeNS(const nsAString& aNamespaceURI, - const nsAString& aLocalName, - nsIDOMAttr** aReturn) { - return nsGenericHTMLFormElement::GetAttributeNodeNS(aNamespaceURI, - aLocalName, aReturn); - } - NS_IMETHOD SetAttributeNodeNS(nsIDOMAttr* aNewAttr, nsIDOMAttr** aReturn) { - return nsGenericHTMLFormElement::SetAttributeNodeNS(aNewAttr, aReturn); - } - NS_IMETHOD GetElementsByTagNameNS(const nsAString& aNamespaceURI, - const nsAString& aLocalName, - nsIDOMNodeList** aReturn) { - return nsGenericHTMLFormElement::GetElementsByTagNameNS(aNamespaceURI, - aLocalName, - aReturn); - } - NS_IMETHOD HasAttribute(const nsAString& aName, PRBool* aReturn) { - return nsGenericHTMLFormElement::HasAttribute(aName, aReturn); - } - NS_IMETHOD HasAttributeNS(const nsAString& aNamespaceURI, - const nsAString& aLocalName, - PRBool* aReturn) { - return nsGenericHTMLFormElement::HasAttributeNS(aNamespaceURI, aLocalName, - aReturn); - } + // nsIDOMElement + NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLFormElement::) // nsIDOMHTMLElement NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLFormElement::) @@ -287,26 +200,7 @@ nsHTMLLabelElement::GetForm(nsIDOMHTMLFormElement** aForm) NS_IMPL_STRING_ATTR(nsHTMLLabelElement, AccessKey, accesskey) -//NS_IMPL_STRING_ATTR(nsHTMLLabelElement, HtmlFor, _for) - -NS_IMETHODIMP -nsHTMLLabelElement::GetHtmlFor(nsAString& aValue) -{ - nsGenericHTMLFormElement::GetAttr(kNameSpaceID_None, nsHTMLAtoms::_for, - aValue); - return NS_OK; -} - -NS_IMETHODIMP -nsHTMLLabelElement::SetHtmlFor(const nsAString& aValue) -{ - // trim leading and trailing whitespace - static char whitespace[] = " \r\n\t"; - nsAutoString value(aValue); - value.Trim(whitespace, PR_TRUE, PR_TRUE); - return nsGenericHTMLFormElement::SetAttr(kNameSpaceID_None, - nsHTMLAtoms::_for, value, PR_TRUE); -} +NS_IMPL_STRING_ATTR(nsHTMLLabelElement, HtmlFor, _for) void nsHTMLLabelElement::SetDocument(nsIDocument* aDocument, PRBool aDeep, diff --git a/content/html/content/src/nsHTMLOptionElement.cpp b/content/html/content/src/nsHTMLOptionElement.cpp index 4a2af48083a7..9d5f4ba1c967 100644 --- a/content/html/content/src/nsHTMLOptionElement.cpp +++ b/content/html/content/src/nsHTMLOptionElement.cpp @@ -114,6 +114,14 @@ public: NS_IMETHOD SetSelectedInternal(PRBool aValue, PRBool aNotify); // nsIContent + nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName, + const nsAString& aValue, PRBool aNotify) + { + return SetAttr(aNameSpaceID, aName, nsnull, aValue, aNotify); + } + virtual nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName, + nsIAtom* aPrefix, const nsAString& aValue, + PRBool aNotify); virtual nsresult InsertChildAt(nsIContent* aKid, PRUint32 aIndex, PRBool aNotify, PRBool aDeepSetDocument); virtual nsresult ReplaceChildAt(nsIContent* aKid, PRUint32 aIndex, @@ -348,73 +356,10 @@ nsHTMLOptionElement::SetSelected(PRBool aValue) return NS_OK; } -//NS_IMPL_BOOL_ATTR(nsHTMLOptionElement, DefaultSelected, defaultselected) -//NS_IMPL_INT_ATTR(nsHTMLOptionElement, Index, index) -//NS_IMPL_STRING_ATTR(nsHTMLOptionElement, Label, label) +NS_IMPL_BOOL_ATTR(nsHTMLOptionElement, DefaultSelected, selected) +NS_IMPL_STRING_ATTR(nsHTMLOptionElement, Label, label) //NS_IMPL_STRING_ATTR(nsHTMLOptionElement, Value, value) - -NS_IMETHODIMP -nsHTMLOptionElement::GetDisabled(PRBool* aDisabled) -{ - nsHTMLValue val; - nsresult rv = GetHTMLAttribute(nsHTMLAtoms::disabled, val); - *aDisabled = (NS_CONTENT_ATTR_NOT_THERE != rv); - return NS_OK; -} - -NS_IMETHODIMP -nsHTMLOptionElement::SetDisabled(PRBool aDisabled) -{ - if (aDisabled) { - return SetHTMLAttribute(nsHTMLAtoms::disabled, nsHTMLValue(), PR_TRUE); - } - - return UnsetAttr(kNameSpaceID_None, nsHTMLAtoms::disabled, PR_TRUE); -} - -NS_IMETHODIMP -nsHTMLOptionElement::GetLabel(nsAString& aValue) -{ - nsGenericHTMLElement::GetAttr(kNameSpaceID_None, nsHTMLAtoms::label, aValue); - return NS_OK; -} - -NS_IMETHODIMP -nsHTMLOptionElement::SetLabel(const nsAString& aValue) -{ - nsresult result; - - result = nsGenericHTMLElement::SetAttr(kNameSpaceID_None, nsHTMLAtoms::label, - aValue, PR_TRUE); - // XXX Why does this only happen to the combobox? and what about - // when the text gets set and label is blank? - if (NS_SUCCEEDED(result)) { - NotifyTextChanged(); - } - - return NS_OK; -} - -NS_IMETHODIMP -nsHTMLOptionElement::GetDefaultSelected(PRBool* aDefaultSelected) -{ - nsHTMLValue val; - - nsresult rv = GetHTMLAttribute(nsHTMLAtoms::selected, val); - *aDefaultSelected = (NS_CONTENT_ATTR_NOT_THERE != rv); - - return NS_OK; -} - -NS_IMETHODIMP -nsHTMLOptionElement::SetDefaultSelected(PRBool aDefaultSelected) -{ - if (aDefaultSelected) { - return SetHTMLAttribute(nsHTMLAtoms::selected, nsHTMLValue(), PR_TRUE); - } - - return UnsetAttr(kNameSpaceID_None, nsHTMLAtoms::selected, PR_TRUE); -} +NS_IMPL_BOOL_ATTR(nsHTMLOptionElement, Disabled, disabled) NS_IMETHODIMP nsHTMLOptionElement::GetIndex(PRInt32* aIndex) @@ -556,6 +501,23 @@ nsHTMLOptionElement::NotifyTextChanged() } } +nsresult +nsHTMLOptionElement::SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName, + nsIAtom* aPrefix, const nsAString& aValue, + PRBool aNotify) +{ + nsresult rv = nsGenericHTMLElement::SetAttr(aNameSpaceID, aName, aPrefix, + aValue, aNotify); + if (NS_SUCCEEDED(rv) && aNotify && aName == nsHTMLAtoms::label && + aNameSpaceID == kNameSpaceID_None) { + // XXX Why does this only happen to the combobox? and what about + // when the text gets set and label is blank? + NotifyTextChanged(); + } + + return rv; +} + // // Override nsIContent children changing methods so we can detect when our text // is changing @@ -679,9 +641,8 @@ nsHTMLOptionElement::Initialize(JSContext* aContext, nsAutoString value(NS_REINTERPRET_CAST(const PRUnichar*, JS_GetStringChars(jsstr))); - result = nsGenericHTMLElement::SetAttr(kNameSpaceID_None, - nsHTMLAtoms::value, value, - PR_FALSE); + result = SetAttr(kNameSpaceID_None, nsHTMLAtoms::value, value, + PR_FALSE); if (NS_FAILED(result)) { return result; } @@ -694,7 +655,8 @@ nsHTMLOptionElement::Initialize(JSContext* aContext, argv[2], &defaultSelected)) && (JS_TRUE == defaultSelected)) { - result = SetHTMLAttribute(nsHTMLAtoms::selected, nsHTMLValue(), PR_FALSE); + result = SetAttr(kNameSpaceID_None, nsHTMLAtoms::selected, + EmptyString(), PR_FALSE); NS_ENSURE_SUCCESS(result, result); } diff --git a/content/html/content/src/nsHTMLSelectElement.cpp b/content/html/content/src/nsHTMLSelectElement.cpp index 6025211cf11d..51d0245d3f03 100644 --- a/content/html/content/src/nsHTMLSelectElement.cpp +++ b/content/html/content/src/nsHTMLSelectElement.cpp @@ -1658,12 +1658,7 @@ nsHTMLSelectElement::SetFocus(nsIPresContext* aPresContext) return; // first see if we are disabled or not. If disabled then do nothing. - nsAutoString disabled; - - if (NS_CONTENT_ATTR_HAS_VALUE == - nsGenericHTMLFormElement::GetAttr(kNameSpaceID_None, - nsHTMLAtoms::disabled, - disabled)) { + if (HasAttr(kNameSpaceID_None, nsHTMLAtoms::disabled)) { return; } diff --git a/content/html/document/src/nsPluginDocument.cpp b/content/html/document/src/nsPluginDocument.cpp index 032cc3d4dd3d..10c125727dee 100644 --- a/content/html/document/src/nsPluginDocument.cpp +++ b/content/html/document/src/nsPluginDocument.cpp @@ -157,16 +157,16 @@ nsPluginDocument::CreateSyntheticPluginDocument() NS_ENSURE_SUCCESS(rv, rv); // then attach our plugin - nsCOMPtr body = do_QueryInterface(mBodyContent); + nsCOMPtr body = do_QueryInterface(mBodyContent); if (!body) { NS_WARNING("no body on plugin document!"); return NS_ERROR_FAILURE; } // remove margins from body - nsHTMLValue zero(0, eHTMLUnit_Integer); - body->SetHTMLAttribute(nsHTMLAtoms::marginwidth, zero, PR_FALSE); - body->SetHTMLAttribute(nsHTMLAtoms::marginheight, zero, PR_FALSE); + NS_NAMED_LITERAL_STRING(zero, "0"); + body->SetAttr(kNameSpaceID_None, nsHTMLAtoms::marginwidth, zero, PR_FALSE); + body->SetAttr(kNameSpaceID_None, nsHTMLAtoms::marginheight, zero, PR_FALSE); // make plugin content @@ -182,25 +182,25 @@ nsPluginDocument::CreateSyntheticPluginDocument() mPluginContent->SetDocument(this, PR_FALSE, PR_TRUE); // make it a named element - nsHTMLValue name(NS_LITERAL_STRING("plugin")); - mPluginContent->SetHTMLAttribute(nsHTMLAtoms::name, name, PR_FALSE); + mPluginContent->SetAttr(kNameSpaceID_None, nsHTMLAtoms::name, + NS_LITERAL_STRING("plugin"), PR_FALSE); - // fill viewport and auto-reize - nsHTMLValue percent100 ((float)1.0); - mPluginContent->SetHTMLAttribute(nsHTMLAtoms::width, percent100, PR_FALSE); - mPluginContent->SetHTMLAttribute(nsHTMLAtoms::height, percent100, PR_FALSE); + // fill viewport and auto-resize + NS_NAMED_LITERAL_STRING(percent100, "100%"); + mPluginContent->SetAttr(kNameSpaceID_None, nsHTMLAtoms::width, percent100, + PR_FALSE); + mPluginContent->SetAttr(kNameSpaceID_None, nsHTMLAtoms::height, percent100, + PR_FALSE); // set URL nsCAutoString src; mDocumentURI->GetSpec(src); - - NS_ConvertUTF8toUCS2 srcString(src); - nsHTMLValue val(srcString); - mPluginContent->SetHTMLAttribute(nsHTMLAtoms::src, val, PR_FALSE); + mPluginContent->SetAttr(kNameSpaceID_None, nsHTMLAtoms::src, + NS_ConvertUTF8toUTF16(src), PR_FALSE); // set mime type - val.SetStringValue(NS_ConvertUTF8toUCS2(mMimeType)); - mPluginContent->SetHTMLAttribute(nsHTMLAtoms::type, val, PR_FALSE); + mPluginContent->SetAttr(kNameSpaceID_None, nsHTMLAtoms::type, + NS_ConvertUTF8toUTF16(mMimeType), PR_FALSE); body->AppendChildTo(mPluginContent, PR_FALSE, PR_FALSE); diff --git a/content/html/style/src/nsCSSStyleRule.cpp b/content/html/style/src/nsCSSStyleRule.cpp index 87da00fadc98..cb0052b7d3fc 100644 --- a/content/html/style/src/nsCSSStyleRule.cpp +++ b/content/html/style/src/nsCSSStyleRule.cpp @@ -1274,7 +1274,7 @@ CSSStyleRuleImpl::CSSStyleRuleImpl(CSSStyleRuleImpl& aCopy, #else // We ought to be able to transfer ownership of the selector and the // declaration since this rule should now be unused, but unfortunately - // SetHTMLAttribute might use it before setting the new rule (see + // SetInlineStyleRule might use it before setting the new rule (see // stack in bug 209575). So leave the declaration pointer on the old // rule. mDeclaration->AddRef(); diff --git a/layout/html/tests/TestAttributes.cpp b/layout/html/tests/TestAttributes.cpp index 0d09ab8c3856..2b93769a82f8 100644 --- a/layout/html/tests/TestAttributes.cpp +++ b/layout/html/tests/TestAttributes.cpp @@ -50,18 +50,14 @@ #include "nsINameSpaceManager.h" void testAttributes(nsIHTMLContent* content) { - nsHTMLValue nullValue; - nsIAtom* sBORDER = NS_NewAtom("border"); - nsIAtom* sWIDTH = NS_NewAtom("width"); nsIAtom* sHEIGHT = NS_NewAtom("height"); nsIAtom* sSRC = NS_NewAtom("src"); nsIAtom* sBAD = NS_NewAtom("badattribute"); nsString sempty; nsString sfoo_gif(NS_LITERAL_STRING("foo.gif")); - content->SetHTMLAttribute(sBORDER, nullValue, PR_FALSE); - content->SetHTMLAttribute(sWIDTH, nsHTMLValue(5, eHTMLUnit_Integer), PR_FALSE); + content->SetAttr(kNameSpaceID_None, sBORDER, EmptyString(), PR_FALSE); content->SetAttribute(kNameSpaceID_None, sHEIGHT, sempty, PR_FALSE); content->SetAttribute(kNameSpaceID_None, sSRC, sfoo_gif, PR_FALSE); @@ -72,11 +68,6 @@ void testAttributes(nsIHTMLContent* content) { printf("test 0 failed\n"); } - rv = content->GetHTMLAttribute(sWIDTH, ret); - if (rv != NS_CONTENT_ATTR_HAS_VALUE || !(ret == nsHTMLValue(5, eHTMLUnit_Integer))) { - printf("test 1 failed\n"); - } - rv = content->GetHTMLAttribute(sBAD, ret); if (rv != NS_CONTENT_ATTR_NOT_THERE) { printf("test 2 failed\n"); diff --git a/layout/style/nsCSSStyleRule.cpp b/layout/style/nsCSSStyleRule.cpp index 87da00fadc98..cb0052b7d3fc 100644 --- a/layout/style/nsCSSStyleRule.cpp +++ b/layout/style/nsCSSStyleRule.cpp @@ -1274,7 +1274,7 @@ CSSStyleRuleImpl::CSSStyleRuleImpl(CSSStyleRuleImpl& aCopy, #else // We ought to be able to transfer ownership of the selector and the // declaration since this rule should now be unused, but unfortunately - // SetHTMLAttribute might use it before setting the new rule (see + // SetInlineStyleRule might use it before setting the new rule (see // stack in bug 209575). So leave the declaration pointer on the old // rule. mDeclaration->AddRef();