diff --git a/mozilla/content/base/src/nsDocument.cpp b/mozilla/content/base/src/nsDocument.cpp index 290344c761d..0015adaee4a 100644 --- a/mozilla/content/base/src/nsDocument.cpp +++ b/mozilla/content/base/src/nsDocument.cpp @@ -2586,7 +2586,9 @@ nsDocument::AddBinding(nsIDOMElement* aContent, const nsAString& aURL) GetBindingManager(getter_AddRefs(bm)); nsCOMPtr content(do_QueryInterface(aContent)); - return bm->AddLayeredBinding(content, aURL); + nsCOMPtr uri; + NS_NewURI(getter_AddRefs(uri), aURL); + return bm->AddLayeredBinding(content, uri); } NS_IMETHODIMP @@ -2599,7 +2601,9 @@ nsDocument::RemoveBinding(nsIDOMElement* aContent, const nsAString& aURL) if (mBindingManager) { nsCOMPtr content(do_QueryInterface(aContent)); - return mBindingManager->RemoveLayeredBinding(content, aURL); + nsCOMPtr uri; + NS_NewURI(getter_AddRefs(uri), aURL); + return mBindingManager->RemoveLayeredBinding(content, uri); } return NS_ERROR_FAILURE; diff --git a/mozilla/content/base/src/nsRuleNode.cpp b/mozilla/content/base/src/nsRuleNode.cpp index 61bba67ac11..11d24f40a90 100644 --- a/mozilla/content/base/src/nsRuleNode.cpp +++ b/mozilla/content/base/src/nsRuleNode.cpp @@ -2321,7 +2321,7 @@ nsRuleNode::ComputeUserInterfaceData(nsStyleStruct* aStartData, ui->mCursor = NS_STYLE_CURSOR_AUTO; } else if (eCSSUnit_URL == list->mValue.GetUnit()) { - list->mValue.GetStringValue(ui->mCursorImage); + ui->mCursorImage = list->mValue.GetURLValue(); } else if (eCSSUnit_Inherit == list->mValue.GetUnit()) { inherited = PR_TRUE; @@ -2530,10 +2530,10 @@ nsRuleNode::ComputeDisplayData(nsStyleStruct* aStartStruct, // binding: url, none, inherit if (eCSSUnit_URL == displayData.mBinding.GetUnit()) { - displayData.mBinding.GetStringValue(display->mBinding); + display->mBinding = displayData.mBinding.GetURLValue(); } else if (eCSSUnit_None == displayData.mBinding.GetUnit()) { - display->mBinding.Truncate(); + display->mBinding = nsnull; } else if (eCSSUnit_Inherit == displayData.mBinding.GetUnit()) { inherited = PR_TRUE; @@ -2926,11 +2926,11 @@ nsRuleNode::ComputeBackgroundData(nsStyleStruct* aStartStruct, // background-image: url, none, inherit if (eCSSUnit_URL == colorData.mBackImage.GetUnit()) { - colorData.mBackImage.GetStringValue(bg->mBackgroundImage); + bg->mBackgroundImage = colorData.mBackImage.GetURLValue(); bg->mBackgroundFlags &= ~NS_STYLE_BG_IMAGE_NONE; } else if (eCSSUnit_None == colorData.mBackImage.GetUnit()) { - bg->mBackgroundImage.Truncate(); + bg->mBackgroundImage = nsnull; bg->mBackgroundFlags |= NS_STYLE_BG_IMAGE_NONE; } else if (eCSSUnit_Inherit == colorData.mBackImage.GetUnit()) { @@ -3448,10 +3448,10 @@ nsRuleNode::ComputeListData(nsStyleStruct* aStartStruct, // list-style-image: url, none, inherit if (eCSSUnit_URL == listData.mImage.GetUnit()) { - listData.mImage.GetStringValue(list->mListStyleImage); + list->mListStyleImage = listData.mImage.GetURLValue(); } else if (eCSSUnit_None == listData.mImage.GetUnit()) { - list->mListStyleImage.Truncate(); + list->mListStyleImage = nsnull; } else if (eCSSUnit_Inherit == listData.mImage.GetUnit()) { inherited = PR_TRUE; @@ -3813,10 +3813,8 @@ nsRuleNode::ComputeContentData(nsStyleStruct* aStartStruct, inherited = PR_TRUE; count = parentContent->ContentCount(); if (NS_SUCCEEDED(content->AllocateContents(count))) { - nsStyleContentType type; while (0 < count--) { - parentContent->GetContentAt(count, type, buffer); - content->SetContentAt(count, type, buffer); + content->ContentAt(count) = parentContent->ContentAt(count); } } } @@ -3834,6 +3832,7 @@ nsRuleNode::ComputeContentData(nsStyleStruct* aStartStruct, const nsCSSValue& value = contentValue->mValue; nsCSSUnit unit = value.GetUnit(); nsStyleContentType type; + nsStyleContentData &data = content->ContentAt(count++); switch (unit) { case eCSSUnit_String: type = eStyleContentType_String; break; case eCSSUnit_URL: type = eStyleContentType_URL; break; @@ -3857,13 +3856,18 @@ nsRuleNode::ComputeContentData(nsStyleStruct* aStartStruct, default: NS_ERROR("bad content type"); } - if (type < eStyleContentType_OpenQuote) { + data.mType = type; + if (type == eStyleContentType_URL) { + data.mContent.mURL = value.GetURLValue(); + NS_IF_ADDREF(data.mContent.mURL); + } + else if (type < eStyleContentType_OpenQuote) { value.GetStringValue(buffer); Unquote(buffer); - content->SetContentAt(count++, type, buffer); + data.mContent.mString = nsCRT::strdup(buffer.get()); } else { - content->SetContentAt(count++, type, nullStr); + data.mContent.mString = nsnull; } contentValue = contentValue->mNext; } diff --git a/mozilla/content/html/content/src/nsGenericHTMLElement.cpp b/mozilla/content/html/content/src/nsGenericHTMLElement.cpp index a4a6fdf0a76..b335b65bafc 100644 --- a/mozilla/content/html/content/src/nsGenericHTMLElement.cpp +++ b/mozilla/content/html/content/src/nsGenericHTMLElement.cpp @@ -3419,7 +3419,6 @@ nsGenericHTMLElement::MapBackgroundAttributesInto(const nsIHTMLMappedAttributes* if (NS_CONTENT_ATTR_HAS_VALUE == aAttributes->GetAttribute(nsHTMLAtoms::background, value)) { if (eHTMLUnit_String == value.GetUnit()) { - nsAutoString absURLSpec; nsAutoString spec; value.GetStringValue(spec); if (!spec.IsEmpty()) { @@ -3437,10 +3436,11 @@ nsGenericHTMLElement::MapBackgroundAttributesInto(const nsIHTMLMappedAttributes* aAttributes->GetAttribute(nsHTMLAtoms::_baseHref, baseHref); nsGenericHTMLElement::GetBaseURL(baseHref, doc, getter_AddRefs(docURL)); - rv = NS_MakeAbsoluteURI(absURLSpec, spec, docURL); + nsCOMPtr uri; + rv = nsContentUtils::NewURIWithDocumentCharset( + getter_AddRefs(uri), spec, doc, docURL); if (NS_SUCCEEDED(rv)) - aData->mColorData->mBackImage.SetStringValue(absURLSpec, - eCSSUnit_URL); + aData->mColorData->mBackImage.SetURLValue(uri); } } } @@ -3451,8 +3451,7 @@ nsGenericHTMLElement::MapBackgroundAttributesInto(const nsIHTMLMappedAttributes* aData->mPresContext->GetCompatibilityMode(&mode); if (eCompatibility_NavQuirks == mode && eHTMLUnit_Empty == value.GetUnit()) - aData->mColorData->mBackImage.SetStringValue(NS_LITERAL_STRING(""), - eCSSUnit_URL); + aData->mColorData->mBackImage.SetNoneValue(); } } } diff --git a/mozilla/content/html/style/src/nsCSSDeclaration.cpp b/mozilla/content/html/style/src/nsCSSDeclaration.cpp index dcb3c6f3a5d..dd26f79903b 100644 --- a/mozilla/content/html/style/src/nsCSSDeclaration.cpp +++ b/mozilla/content/html/style/src/nsCSSDeclaration.cpp @@ -282,8 +282,6 @@ PRBool nsCSSDeclaration::AppendCSSValueToString(nsCSSProperty aProperty, const n if ((eCSSUnit_String <= unit) && (unit <= eCSSUnit_Counters)) { switch (unit) { - case eCSSUnit_URL: aResult.Append(NS_LITERAL_STRING("url(")); - break; case eCSSUnit_Attr: aResult.Append(NS_LITERAL_STRING("attr(")); break; case eCSSUnit_Counter: aResult.Append(NS_LITERAL_STRING("counter(")); @@ -385,7 +383,7 @@ PRBool nsCSSDeclaration::AppendCSSValueToString(nsCSSProperty aProperty, const n aResult.Append(NS_ConvertASCIItoUCS2(name)); } } - else if (eCSSUnit_Color == unit){ + else if (eCSSUnit_Color == unit) { nsAutoString tmpStr; nscolor color = aValue.GetColorValue(); @@ -406,6 +404,13 @@ PRBool nsCSSDeclaration::AppendCSSValueToString(nsCSSProperty aProperty, const n aResult.Append(PRUnichar(')')); } + else if (eCSSUnit_URL == unit) { + nsCAutoString spec; + aValue.GetURLValue()->GetSpec(spec); + aResult.Append(NS_LITERAL_STRING("url(") + + NS_ConvertUTF8toUCS2(spec) + + NS_LITERAL_STRING(")")); + } else if (eCSSUnit_Percent == unit) { nsAutoString tmpStr; tmpStr.AppendFloat(aValue.GetPercentValue() * 100.0f); @@ -426,7 +431,7 @@ PRBool nsCSSDeclaration::AppendCSSValueToString(nsCSSProperty aProperty, const n case eCSSUnit_Normal: aResult.Append(NS_LITERAL_STRING("normal")); break; case eCSSUnit_String: break; - case eCSSUnit_URL: + case eCSSUnit_URL: break; case eCSSUnit_Attr: case eCSSUnit_Counter: case eCSSUnit_Counters: aResult.Append(PRUnichar(')')); break; diff --git a/mozilla/content/html/style/src/nsCSSParser.cpp b/mozilla/content/html/style/src/nsCSSParser.cpp index b1cdffd94c9..b3dba2dacfe 100644 --- a/mozilla/content/html/style/src/nsCSSParser.cpp +++ b/mozilla/content/html/style/src/nsCSSParser.cpp @@ -3602,13 +3602,6 @@ PRBool CSSParserImpl::ParseAttr(PRInt32& aErrorCode, nsCSSValue& aValue) return PR_FALSE; } -inline static PRBool -css_RequiresAbsoluteURI(const nsString& uri) -{ - // cheap shot at figuring out if this requires an absolute url translation - return !StringBeginsWith(uri, NS_LITERAL_STRING("chrome:")); -} - PRBool CSSParserImpl::ParseURL(PRInt32& aErrorCode, nsCSSValue& aValue) { if (ExpectSymbol(aErrorCode, '(', PR_FALSE)) { @@ -3620,16 +3613,12 @@ PRBool CSSParserImpl::ParseURL(PRInt32& aErrorCode, nsCSSValue& aValue) // Translate url into an absolute url if the url is relative to // the style sheet. // XXX editors won't like this - too bad for now - nsAutoString absURL; - nsresult rv = NS_ERROR_FAILURE; - if (mURL && css_RequiresAbsoluteURI(tk->mIdent)) { - rv = NS_MakeAbsoluteURI(absURL, tk->mIdent, mURL); - } - if (NS_FAILED(rv)) { - absURL = tk->mIdent; - } + nsCOMPtr url; + NS_NewURI(getter_AddRefs(url), tk->mIdent, nsnull, mURL); if (ExpectSymbol(aErrorCode, ')', PR_TRUE)) { - aValue.SetStringValue(absURL, eCSSUnit_URL); + // Set a null value on failure. Most failure cases should be + // NS_ERROR_MALFORMED_URI. + aValue.SetURLValue(url); return PR_TRUE; } } diff --git a/mozilla/content/html/style/src/nsCSSValue.cpp b/mozilla/content/html/style/src/nsCSSValue.cpp index bf5e042e2c0..fc2d28c4cf4 100644 --- a/mozilla/content/html/style/src/nsCSSValue.cpp +++ b/mozilla/content/html/style/src/nsCSSValue.cpp @@ -90,6 +90,13 @@ nsCSSValue::nsCSSValue(nscolor aValue) mValue.mColor = aValue; } +nsCSSValue::nsCSSValue(nsIURI* aValue) + : mUnit(eCSSUnit_URL) +{ + mValue.mURL = aValue; + NS_IF_ADDREF(aValue); +} + nsCSSValue::nsCSSValue(const nsCSSValue& aCopy) : mUnit(aCopy.mUnit) { @@ -107,6 +114,10 @@ nsCSSValue::nsCSSValue(const nsCSSValue& aCopy) else if (eCSSUnit_Color == mUnit){ mValue.mColor = aCopy.mValue.mColor; } + else if (eCSSUnit_URL == mUnit){ + mValue.mURL = aCopy.mValue.mURL; + NS_IF_ADDREF(mValue.mURL); + } else { mValue.mFloat = aCopy.mValue.mFloat; } @@ -127,6 +138,10 @@ nsCSSValue& nsCSSValue::operator=(const nsCSSValue& aCopy) else if (eCSSUnit_Color == mUnit){ mValue.mColor = aCopy.mValue.mColor; } + else if (eCSSUnit_URL == mUnit){ + mValue.mURL = aCopy.mValue.mURL; + NS_IF_ADDREF(mValue.mURL); + } else { mValue.mFloat = aCopy.mValue.mFloat; } @@ -147,13 +162,20 @@ PRBool nsCSSValue::operator==(const nsCSSValue& aOther) const } } else if ((eCSSUnit_Integer <= mUnit) && (mUnit <= eCSSUnit_Enumerated)) { - return PRBool(mValue.mInt == aOther.mValue.mInt); + return mValue.mInt == aOther.mValue.mInt; } - else if (eCSSUnit_Color == mUnit){ - return PRBool(mValue.mColor == aOther.mValue.mColor); + else if (eCSSUnit_Color == mUnit) { + return mValue.mColor == aOther.mValue.mColor; + } + else if (eCSSUnit_URL == mUnit) { + PRBool eq; + return (mValue.mURL == aOther.mValue.mURL || // handles null == null + (mValue.mURL && aOther.mValue.mURL && + NS_SUCCEEDED(mValue.mURL->Equals(aOther.mValue.mURL, &eq)) && + eq)); } else { - return PRBool(mValue.mFloat == aOther.mValue.mFloat); + return mValue.mFloat == aOther.mValue.mFloat; } } return PR_FALSE; @@ -189,6 +211,14 @@ void nsCSSValue::SetColorValue(nscolor aValue) mValue.mColor = aValue; } +void nsCSSValue::SetURLValue(nsIURI* aValue) +{ + Reset(); + mUnit = eCSSUnit_URL; + mValue.mURL = aValue; + NS_IF_ADDREF(mValue.mURL); +} + void nsCSSValue::SetAutoValue(void) { Reset(); @@ -261,7 +291,7 @@ void nsCSSValue::AppendToString(nsAString& aBuffer, aBuffer.Append(PRUnichar(']')); } - else if (eCSSUnit_Color == mUnit){ + else if (eCSSUnit_Color == mUnit) { aBuffer.Append(NS_LITERAL_STRING("(0x")); nsAutoString intStr; @@ -288,6 +318,15 @@ void nsCSSValue::AppendToString(nsAString& aBuffer, aBuffer.Append(PRUnichar(')')); } + else if (eCSSUnit_URL == mUnit) { + if (mValue.mURL) { + nsCAutoString spec; + mValue.mURL->GetSpec(spec); + AppendUTF8toUTF16(spec, aBuffer); + } else { + aBuffer.Append(NS_LITERAL_STRING("url(invalid-url:)")); + } + } else if (eCSSUnit_Percent == mUnit) { nsAutoString floatString; floatString.AppendFloat(mValue.mFloat * 100.0f); @@ -351,4 +390,3 @@ void nsCSSValue::ToString(nsAString& aBuffer, aBuffer.Truncate(); AppendToString(aBuffer, aPropID); } - diff --git a/mozilla/content/html/style/src/nsCSSValue.h b/mozilla/content/html/style/src/nsCSSValue.h index 1afbf2443d7..3f730eab873 100644 --- a/mozilla/content/html/style/src/nsCSSValue.h +++ b/mozilla/content/html/style/src/nsCSSValue.h @@ -44,7 +44,7 @@ #include "nsCoord.h" #include "nsCSSProperty.h" #include "nsUnitConversion.h" - +#include "nsIURI.h" enum nsCSSUnit { eCSSUnit_Null = 0, // (n/a) null unit, value is not specified @@ -53,11 +53,11 @@ enum nsCSSUnit { eCSSUnit_Initial = 3, // (n/a) value is default UA value eCSSUnit_None = 4, // (n/a) value is none eCSSUnit_Normal = 5, // (n/a) value is normal (algorithmic, different than auto) - eCSSUnit_String = 10, // (nsString) a string value - eCSSUnit_URL = 11, // (nsString) a URL value - eCSSUnit_Attr = 12, // (nsString) a attr(string) value - eCSSUnit_Counter = 13, // (nsString) a counter(string,[string]) value - eCSSUnit_Counters = 14, // (nsString) a counters(string,string[,string]) value + eCSSUnit_String = 10, // (PRUnichar*) a string value + eCSSUnit_Attr = 11, // (PRUnichar*) a attr(string) value + eCSSUnit_Counter = 12, // (PRUnichar*) a counter(string,[string]) value + eCSSUnit_Counters = 13, // (PRUnichar*) a counters(string,string[,string]) value + eCSSUnit_URL = 14, // (nsIURI*) a URL value (null == invalid URI) eCSSUnit_Integer = 50, // (int) simple value eCSSUnit_Enumerated = 51, // (int) value has enumerated meaning eCSSUnit_Color = 80, // (color) an RGBA value @@ -129,6 +129,7 @@ public: nsCSSValue(float aValue, nsCSSUnit aUnit); nsCSSValue(const nsAString& aValue, nsCSSUnit aUnit); nsCSSValue(nscolor aValue); + nsCSSValue(nsIURI* aValue); nsCSSValue(const nsCSSValue& aCopy); ~nsCSSValue(void) { @@ -138,7 +139,11 @@ public: nsCSSValue& operator=(const nsCSSValue& aCopy); PRBool operator==(const nsCSSValue& aOther) const; - PRBool operator!=(const nsCSSValue& aOther) const; + + PRBool operator!=(const nsCSSValue& aOther) const + { + return !(*this == aOther); + } nsCSSUnit GetUnit(void) const { return mUnit; }; PRBool IsLengthUnit(void) const @@ -154,11 +159,56 @@ public: PRBool IsTimeUnit(void) const { return PRBool((eCSSUnit_Seconds <= mUnit) && (mUnit <= eCSSUnit_Milliseconds)); } - PRInt32 GetIntValue(void) const; - float GetPercentValue(void) const; - float GetFloatValue(void) const; - nsAString& GetStringValue(nsAString& aBuffer) const; - nscolor GetColorValue(void) const; + PRInt32 GetIntValue(void) const + { + NS_ASSERTION(mUnit == eCSSUnit_Integer || mUnit == eCSSUnit_Enumerated, + "not an int value"); + return mValue.mInt; + } + + float GetPercentValue(void) const + { + NS_ASSERTION(mUnit == eCSSUnit_Percent, "not a percent value"); + return mValue.mFloat; + } + + float GetFloatValue(void) const + { + NS_ASSERTION(eCSSUnit_Number <= mUnit, "not a float value"); + return mValue.mFloat; + } + + nsAString& GetStringValue(nsAString& aBuffer) const + { + NS_ASSERTION(eCSSUnit_String <= mUnit && mUnit <= eCSSUnit_Counters, + "not a string value"); + aBuffer.Truncate(); + if (nsnull != mValue.mString) { + aBuffer.Append(mValue.mString); + } + return aBuffer; + } + + const PRUnichar* GetStringBufferValue() const + { + NS_ASSERTION(eCSSUnit_String <= mUnit && mUnit <= eCSSUnit_Counters, + "not a string value"); + return mValue.mString; + } + + nscolor GetColorValue(void) const + { + NS_ASSERTION((mUnit == eCSSUnit_Color), "not a color value"); + return mValue.mColor; + } + + nsIURI* GetURLValue(void) const + { + NS_ASSERTION(mUnit == eCSSUnit_URL, "not a URL value"); + return mValue.mURL; + } + + nscoord GetLengthTwips(void) const { NS_ASSERTION(IsFixedLengthUnit(), "not a fixed length unit"); @@ -202,6 +252,8 @@ public: if ((eCSSUnit_String <= mUnit) && (mUnit <= eCSSUnit_Counters) && (nsnull != mValue.mString)) { nsCRT::free(mValue.mString); + } else if (eCSSUnit_URL == mUnit) { + NS_IF_RELEASE(mValue.mURL); } mUnit = eCSSUnit_Null; mValue.mInt = 0; @@ -227,6 +279,7 @@ public: void SetStringValue(const nsAString& aValue, nsCSSUnit aUnit); void SetColorValue(nscolor aValue); + void SetURLValue(nsIURI* aURI); void SetAutoValue(void); void SetInheritValue(void); void SetInitialValue(void); @@ -234,6 +287,7 @@ public: void SetNormalValue(void); // debugging methods only + // XXXldb Not anymore! void AppendToString(nsAString& aBuffer, nsCSSProperty aPropID = eCSSProperty_UNKNOWN) const; void ToString(nsAString& aBuffer, nsCSSProperty aPropID = eCSSProperty_UNKNOWN) const; @@ -244,64 +298,9 @@ protected: float mFloat; PRUnichar* mString; nscolor mColor; + nsIURI* mURL; } mValue; }; -inline PRInt32 nsCSSValue::GetIntValue(void) const -{ - NS_ASSERTION((mUnit == eCSSUnit_Integer) || - (mUnit == eCSSUnit_Enumerated), "not an int value"); - if ((mUnit == eCSSUnit_Integer) || - (mUnit == eCSSUnit_Enumerated)) { - return mValue.mInt; - } - return 0; -} - -inline float nsCSSValue::GetPercentValue(void) const -{ - NS_ASSERTION((mUnit == eCSSUnit_Percent), "not a percent value"); - if ((mUnit == eCSSUnit_Percent)) { - return mValue.mFloat; - } - return 0.0f; -} - -inline float nsCSSValue::GetFloatValue(void) const -{ - NS_ASSERTION((eCSSUnit_Number <= mUnit), "not a float value"); - if ((mUnit >= eCSSUnit_Number)) { - return mValue.mFloat; - } - return 0.0f; -} - -inline nsAString& nsCSSValue::GetStringValue(nsAString& aBuffer) const -{ - NS_ASSERTION((eCSSUnit_String <= mUnit) && (mUnit <= eCSSUnit_Counters), "not a string value"); - aBuffer.Truncate(); - if ((eCSSUnit_String <= mUnit) && (mUnit <= eCSSUnit_Counters) && - (nsnull != mValue.mString)) { - aBuffer.Append(mValue.mString); - } - return aBuffer; -} - -inline nscolor nsCSSValue::GetColorValue(void) const -{ - NS_ASSERTION((mUnit == eCSSUnit_Color), "not a color value"); - if (mUnit == eCSSUnit_Color) { - return mValue.mColor; - } - return NS_RGB(0,0,0); -} - -inline PRBool nsCSSValue::operator!=(const nsCSSValue& aOther) const -{ - return PRBool(! ((*this) == aOther)); -} - - - #endif /* nsCSSValue_h___ */ diff --git a/mozilla/content/html/style/src/nsComputedDOMStyle.cpp b/mozilla/content/html/style/src/nsComputedDOMStyle.cpp index 7113e1befee..0d728a9a73b 100644 --- a/mozilla/content/html/style/src/nsComputedDOMStyle.cpp +++ b/mozilla/content/html/style/src/nsComputedDOMStyle.cpp @@ -339,7 +339,7 @@ nsComputedDOMStyle::GetBinding(nsIFrame *aFrame, GetStyleData(eStyleStruct_Display, (const nsStyleStruct*&)display, aFrame); - if (display && !display->mBinding.IsEmpty()) { + if (display && display->mBinding) { val->SetURI(display->mBinding); } else { val->SetIdent(NS_LITERAL_STRING("none")); @@ -1307,7 +1307,7 @@ nsComputedDOMStyle::GetListStyleImage(nsIFrame *aFrame, GetStyleData(eStyleStruct_List, (const nsStyleStruct*&)list, aFrame); if (list) { - if (list->mListStyleImage.IsEmpty()) { + if (!list->mListStyleImage) { val->SetIdent(NS_LITERAL_STRING("none")); } else { val->SetURI(list->mListStyleImage); @@ -1741,7 +1741,7 @@ nsComputedDOMStyle::GetCursor(nsIFrame *aFrame, GetStyleData(eStyleStruct_UserInterface, (const nsStyleStruct*&)ui, aFrame); if (ui) { - if (!ui->mCursorImage.IsEmpty()) { + if (ui->mCursorImage) { val->SetURI(ui->mCursorImage); } else { if (ui->mCursor == NS_STYLE_CURSOR_AUTO) { diff --git a/mozilla/content/html/style/src/nsROCSSPrimitiveValue.cpp b/mozilla/content/html/style/src/nsROCSSPrimitiveValue.cpp index 75a1b521a10..6c1c1ace849 100644 --- a/mozilla/content/html/style/src/nsROCSSPrimitiveValue.cpp +++ b/mozilla/content/html/style/src/nsROCSSPrimitiveValue.cpp @@ -58,16 +58,20 @@ nsROCSSPrimitiveValue::~nsROCSSPrimitiveValue() } void -nsROCSSPrimitiveValue::GetEscapedURI(PRUnichar *aURI, PRUnichar **aReturn) +nsROCSSPrimitiveValue::GetEscapedURI(nsIURI *aURI, PRUnichar **aReturn) { - PRUint16 length = nsCRT::strlen(aURI); + nsCAutoString specUTF8; + aURI->GetSpec(specUTF8); + NS_ConvertUTF8toUCS2 spec(specUTF8); + + PRUint16 length = spec.Length(); PRUnichar *escaped = (PRUnichar *)nsMemory::Alloc(length * 2 * sizeof(PRUnichar) + sizeof(PRUnichar('\0'))); if (escaped) { PRUnichar *ptr = escaped; for (PRUint16 i = 0; i < length; ++i) { - switch (aURI[i]) { + switch (spec[i]) { case ' ' : // space case '\t': // tab case '(' : // opening parenthesis @@ -83,7 +87,7 @@ nsROCSSPrimitiveValue::GetEscapedURI(PRUnichar *aURI, PRUnichar **aReturn) default: break; } - *ptr++ = aURI[i]; + *ptr++ = spec[i]; } *ptr = 0; } @@ -159,10 +163,16 @@ nsROCSSPrimitiveValue::GetCssText(nsAString& aCssText) case CSS_URI : { nsXPIDLString uri; - GetEscapedURI(mValue.mString, getter_Copies(uri)); - tmpStr.Assign(NS_LITERAL_STRING("url(") + - uri + - NS_LITERAL_STRING(")")); + if (mValue.mURI) { + GetEscapedURI(mValue.mURI, getter_Copies(uri)); + tmpStr.Assign(NS_LITERAL_STRING("url(") + + uri + + NS_LITERAL_STRING(")")); + } else { + // XXXldb Any better ideas? It's good to have something that + // doesn't parse so that things round-trip "correctly". + tmpStr.Assign(NS_LITERAL_STRING("url(invalid-url:)")); + } break; } case CSS_PERCENTAGE : @@ -401,9 +411,14 @@ nsROCSSPrimitiveValue::GetStringValue(nsAString& aReturn) switch (mType) { case CSS_IDENT: case CSS_STRING: - case CSS_URI: aReturn.Assign(mValue.mString); break; + case CSS_URI: { + nsCAutoString spec; + if (mValue.mURI) + mValue.mURI->GetSpec(spec); + CopyUTF8toUTF16(spec, aReturn); + } break; case CSS_ATTR: default: aReturn.Truncate(); diff --git a/mozilla/content/html/style/src/nsROCSSPrimitiveValue.h b/mozilla/content/html/style/src/nsROCSSPrimitiveValue.h index b7f47a9caa8..d46528621f4 100644 --- a/mozilla/content/html/style/src/nsROCSSPrimitiveValue.h +++ b/mozilla/content/html/style/src/nsROCSSPrimitiveValue.h @@ -44,6 +44,7 @@ #include "nsCoord.h" #include "nsUnitConversion.h" #include "nsReadableUtils.h" +#include "nsIURI.h" #include "nsCOMPtr.h" #include "nsDOMError.h" @@ -151,26 +152,12 @@ public: } } - void SetURI(const nsACString& aString) + void SetURI(nsIURI *aURI) { Reset(); - mValue.mString = ToNewUnicode(aString); - if (mValue.mString) { - mType = CSS_URI; - } else { - mType = CSS_UNKNOWN; - } - } - - void SetURI(const nsAString& aString) - { - Reset(); - mValue.mString = ToNewUnicode(aString); - if (mValue.mString) { - mType = CSS_URI; - } else { - mType = CSS_UNKNOWN; - } + mValue.mURI = aURI; + NS_IF_ADDREF(mValue.mURI); + mType = CSS_URI; } void SetColor(nsIDOMRGBColor* aColor) @@ -206,11 +193,13 @@ public: switch (mType) { case CSS_IDENT: case CSS_STRING: - case CSS_URI: NS_ASSERTION(mValue.mString, "Null string should never happen"); nsMemory::Free(mValue.mString); mValue.mString = nsnull; break; + case CSS_URI: + NS_IF_RELEASE(mValue.mURI); + break; case CSS_RECT: NS_ASSERTION(mValue.mRect, "Null Rect should never happen"); NS_RELEASE(mValue.mRect); @@ -225,7 +214,7 @@ public: } private: - void GetEscapedURI(PRUnichar *aURI, PRUnichar **aReturn); + void GetEscapedURI(nsIURI *aURI, PRUnichar **aReturn); PRUint16 mType; @@ -235,6 +224,7 @@ private: nsIDOMRGBColor* mColor; nsIDOMRect* mRect; PRUnichar* mString; + nsIURI* mURI; } mValue; float mT2P; diff --git a/mozilla/content/shared/public/nsStyleStruct.h b/mozilla/content/shared/public/nsStyleStruct.h index 34381e87c16..c10c15bc946 100644 --- a/mozilla/content/shared/public/nsStyleStruct.h +++ b/mozilla/content/shared/public/nsStyleStruct.h @@ -52,6 +52,7 @@ #include "nsIPresShell.h" #include "nsCOMPtr.h" #include "nsILanguageAtom.h" +#include "nsIURI.h" class nsIFrame; @@ -183,7 +184,7 @@ struct nsStyleBackground : public nsStyleStruct { mBackgroundYPosition; // [reset] nscolor mBackgroundColor; // [reset] - nsString mBackgroundImage; // [reset] absolute url string + nsCOMPtr mBackgroundImage; // [reset] PRBool IsTransparent() const { @@ -586,7 +587,7 @@ struct nsStyleList : public nsStyleStruct { PRUint8 mListStyleType; // [inherited] See nsStyleConsts.h PRUint8 mListStylePosition; // [inherited] - nsString mListStyleImage; // [inherited] absolute url string + nsCOMPtr mListStyleImage; // [inherited] nsRect mImageRegion; // [inherited] the rect to use within an image }; @@ -732,7 +733,7 @@ struct nsStyleDisplay : public nsStyleStruct { nsChangeHint CalcDifference(const nsStyleDisplay& aOther) const; - nsString mBinding; // [reset] absolute url string + nsCOMPtr mBinding; // [reset] #if 0 // XXX This is how it is defined in the CSS2 spec, but the errata // changed it to be consistent with the positioning draft and how @@ -834,7 +835,48 @@ enum nsStyleContentType { struct nsStyleContentData { nsStyleContentType mType; - nsString mContent; + union { + PRUnichar *mString; + nsIURI *mURL; + } mContent; + + ~nsStyleContentData() { + if (mType == eStyleContentType_URL) { + NS_IF_RELEASE(mContent.mURL); + } else if (mContent.mString) { + nsCRT::free(mContent.mString); + } + } + + nsStyleContentData& operator=(const nsStyleContentData& aOther) { + mType = aOther.mType; + if (mType == eStyleContentType_URL) { + mContent.mURL = aOther.mContent.mURL; + NS_IF_ADDREF(mContent.mURL); + } else if (aOther.mContent.mString) { + mContent.mString = nsCRT::strdup(aOther.mContent.mString); + } else { + mContent.mString = nsnull; + } + return *this; + } + + PRBool operator==(const nsStyleContentData& aOther) { + if (mType != aOther.mType) + return PR_FALSE; + if (mType == eStyleContentType_URL) { + PRBool eq; + return mContent.mURL == aOther.mContent.mURL || // handles null==null + (mContent.mURL && aOther.mContent.mURL && + NS_SUCCEEDED(mContent.mURL->Equals(aOther.mContent.mURL, &eq)) && + eq); + } + return mContent.mString == aOther.mContent.mString; + } + + PRBool operator!=(const nsStyleContentData& aOther) { + return !(*this == aOther); + } }; struct nsStyleCounterData { @@ -926,13 +968,15 @@ struct nsStyleContent: public nsStyleStruct { nsChangeHint CalcDifference(const nsStyleContent& aOther) const; PRUint32 ContentCount(void) const { return mContentCount; } // [reset] - nsresult GetContentAt(PRUint32 aIndex, nsStyleContentType& aType, nsString& aContent) const { - if (aIndex < mContentCount) { - aType = mContents[aIndex].mType; - aContent = mContents[aIndex].mContent; - return NS_OK; - } - return NS_ERROR_ILLEGAL_VALUE; + + const nsStyleContentData& ContentAt(PRUint32 aIndex) const { + NS_ASSERTION(aIndex < mContentCount, "out of range"); + return mContents[aIndex]; + } + + nsStyleContentData& ContentAt(PRUint32 aIndex) { + NS_ASSERTION(aIndex < mContentCount, "out of range"); + return mContents[aIndex]; } nsresult AllocateContents(PRUint32 aCount) { @@ -950,20 +994,6 @@ struct nsStyleContent: public nsStyleStruct { return NS_OK; } - nsresult SetContentAt(PRUint32 aIndex, nsStyleContentType aType, const nsString& aContent) { - if (aIndex < mContentCount) { - mContents[aIndex].mType = aType; - if (aType < eStyleContentType_OpenQuote) { - mContents[aIndex].mContent = aContent; - } - else { - mContents[aIndex].mContent.Truncate(); - } - return NS_OK; - } - return NS_ERROR_ILLEGAL_VALUE; - } - PRUint32 CounterIncrementCount(void) const { return mIncrementCount; } // [reset] nsresult GetCounterIncrementAt(PRUint32 aIndex, nsString& aCounter, PRInt32& aIncrement) const { if (aIndex < mIncrementCount) { @@ -1094,7 +1124,7 @@ struct nsStyleUserInterface: public nsStyleStruct { PRUint8 mUserFocus; // [inherited] (auto-select) PRUint8 mCursor; // [inherited] See nsStyleConsts.h NS_STYLE_CURSOR_* - nsString mCursorImage; // [inherited] url string + nsCOMPtr mCursorImage; // [inherited] url string }; struct nsStyleXUL : public nsStyleStruct { diff --git a/mozilla/content/shared/src/nsStyleStruct.cpp b/mozilla/content/shared/src/nsStyleStruct.cpp index f6886c08c89..a4b9438d1e6 100644 --- a/mozilla/content/shared/src/nsStyleStruct.cpp +++ b/mozilla/content/shared/src/nsStyleStruct.cpp @@ -701,7 +701,6 @@ nsStyleList::nsStyleList() { mListStyleType = NS_STYLE_LIST_STYLE_BASIC; mListStylePosition = NS_STYLE_LIST_STYLE_POSITION_OUTSIDE; - mListStyleImage.Truncate(); } nsStyleList::~nsStyleList() @@ -709,10 +708,10 @@ nsStyleList::~nsStyleList() } nsStyleList::nsStyleList(const nsStyleList& aSource) + : mListStyleType(aSource.mListStyleType), + mListStylePosition(aSource.mListStylePosition), + mListStyleImage(aSource.mListStyleImage) { - mListStyleType = aSource.mListStyleType; - mListStylePosition = aSource.mListStylePosition; - mListStyleImage = aSource.mListStyleImage; } nsChangeHint nsStyleList::CalcDifference(const nsStyleList& aOther) const @@ -1192,7 +1191,7 @@ nsStyleContent::nsStyleContent(const nsStyleContent& aSource) PRUint32 index; if (NS_SUCCEEDED(AllocateContents(aSource.ContentCount()))) { for (index = 0; index < mContentCount; index++) { - aSource.GetContentAt(index, mContents[index].mType, mContents[index].mContent); + ContentAt(index) = aSource.ContentAt(index); } } @@ -1219,8 +1218,7 @@ nsChangeHint nsStyleContent::CalcDifference(const nsStyleContent& aOther) const (mResetCount == aOther.mResetCount)) { PRUint32 ix = mContentCount; while (0 < ix--) { - if ((mContents[ix].mType != aOther.mContents[ix].mType) || - (mContents[ix].mContent != aOther.mContents[ix].mContent)) { + if (mContents[ix] != aOther.mContents[ix]) { // Unfortunately we need to reframe here; a simple reflow // will not pick up different text or different image URLs, // since we set all that up in the CSSFrameConstructor diff --git a/mozilla/content/xbl/public/nsIBindingManager.h b/mozilla/content/xbl/public/nsIBindingManager.h index 925bbd8a6d0..1967ac1f894 100644 --- a/mozilla/content/xbl/public/nsIBindingManager.h +++ b/mozilla/content/xbl/public/nsIBindingManager.h @@ -54,6 +54,7 @@ class nsIXBLBinding; class nsIXBLDocumentInfo; class nsIAtom; class nsIStreamListener; +class nsIURI; class nsIXPConnectWrappedJS; class nsIDOMNodeList; class nsVoidArray; @@ -150,8 +151,8 @@ public: NS_IMETHOD GetSingleInsertionPoint(nsIContent* aParent, nsIContent** aResult, PRUint32* aIndex, PRBool* aMultipleInsertionPoints) = 0; - NS_IMETHOD AddLayeredBinding(nsIContent* aContent, const nsAString& aURL) = 0; - NS_IMETHOD RemoveLayeredBinding(nsIContent* aContent, const nsAString& aURL) = 0; + NS_IMETHOD AddLayeredBinding(nsIContent* aContent, nsIURI* aURL) = 0; + NS_IMETHOD RemoveLayeredBinding(nsIContent* aContent, nsIURI* aURL) = 0; NS_IMETHOD LoadBindingDocument(nsIDocument* aDocument, const nsAString& aURL, nsIDocument** aResult) = 0; diff --git a/mozilla/content/xbl/public/nsIXBLService.h b/mozilla/content/xbl/public/nsIXBLService.h index 326dcad7ed6..4dd1297ffdf 100644 --- a/mozilla/content/xbl/public/nsIXBLService.h +++ b/mozilla/content/xbl/public/nsIXBLService.h @@ -69,7 +69,7 @@ public: // This function loads a particular XBL file and installs all of the bindings // onto the element. - NS_IMETHOD LoadBindings(nsIContent* aContent, const nsAString& aURL, PRBool aAugmentFlag, + NS_IMETHOD LoadBindings(nsIContent* aContent, nsIURI* aURL, PRBool aAugmentFlag, nsIXBLBinding** aBinding, PRBool* aResolveStyle) = 0; // Indicates whether or not a binding is fully loaded. diff --git a/mozilla/content/xbl/src/nsBindingManager.cpp b/mozilla/content/xbl/src/nsBindingManager.cpp index 86b046ec9a3..c1f919dd65a 100644 --- a/mozilla/content/xbl/src/nsBindingManager.cpp +++ b/mozilla/content/xbl/src/nsBindingManager.cpp @@ -352,8 +352,8 @@ public: NS_IMETHOD GetSingleInsertionPoint(nsIContent* aParent, nsIContent** aResult, PRUint32* aIndex, PRBool* aMultipleInsertionPoints); - NS_IMETHOD AddLayeredBinding(nsIContent* aContent, const nsAString& aURL); - NS_IMETHOD RemoveLayeredBinding(nsIContent* aContent, const nsAString& aURL); + NS_IMETHOD AddLayeredBinding(nsIContent* aContent, nsIURI* aURL); + NS_IMETHOD RemoveLayeredBinding(nsIContent* aContent, nsIURI* aURL); NS_IMETHOD LoadBindingDocument(nsIDocument* aBoundDoc, const nsAString& aURL, nsIDocument** aResult); @@ -801,7 +801,7 @@ nsBindingManager::GetSingleInsertionPoint(nsIContent* aParent, nsIContent** aRes } NS_IMETHODIMP -nsBindingManager::AddLayeredBinding(nsIContent* aContent, const nsAString& aURL) +nsBindingManager::AddLayeredBinding(nsIContent* aContent, nsIURI* aURL) { // First we need to load our binding. nsresult rv; @@ -823,7 +823,7 @@ nsBindingManager::AddLayeredBinding(nsIContent* aContent, const nsAString& aURL) } NS_IMETHODIMP -nsBindingManager::RemoveLayeredBinding(nsIContent* aContent, const nsAString& aURL) +nsBindingManager::RemoveLayeredBinding(nsIContent* aContent, nsIURI* aURL) { nsCOMPtr binding; GetBinding(aContent, getter_AddRefs(binding)); @@ -844,11 +844,8 @@ nsBindingManager::RemoveLayeredBinding(nsIContent* aContent, const nsAString& aU nsresult rv = NS_NewURI(getter_AddRefs(bindingUri), bindingUriStr); NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr uri; - rv = NS_NewURI(getter_AddRefs(uri), aURL); - NS_ENSURE_SUCCESS(rv, rv); PRBool equalUri; - rv = uri->Equals(bindingUri, &equalUri); + rv = aURL->Equals(bindingUri, &equalUri); NS_ENSURE_SUCCESS(rv, rv); if (!equalUri) { return NS_OK; diff --git a/mozilla/content/xbl/src/nsXBLService.cpp b/mozilla/content/xbl/src/nsXBLService.cpp index 7f6709d86b9..b5f44fd3d97 100644 --- a/mozilla/content/xbl/src/nsXBLService.cpp +++ b/mozilla/content/xbl/src/nsXBLService.cpp @@ -528,7 +528,7 @@ nsXBLService::~nsXBLService(void) // This function loads a particular XBL file and installs all of the bindings // onto the element. NS_IMETHODIMP -nsXBLService::LoadBindings(nsIContent* aContent, const nsAString& aURL, PRBool aAugmentFlag, +nsXBLService::LoadBindings(nsIContent* aContent, nsIURI* aURL, PRBool aAugmentFlag, nsIXBLBinding** aBinding, PRBool* aResolveStyle) { *aBinding = nsnull; @@ -559,14 +559,16 @@ nsXBLService::LoadBindings(nsIContent* aContent, const nsAString& aURL, PRBool a } else { // See if the URIs match. - nsCAutoString uri; - styleBinding->GetBindingURI(uri); - if (uri.Equals(NS_ConvertUCS2toUTF8(aURL))) + nsCAutoString spec; + styleBinding->GetBindingURI(spec); + nsCOMPtr uri; + // XXX This needs an origin charset. + NS_NewURI(getter_AddRefs(uri), spec.get()); + PRBool equal; + if (NS_SUCCEEDED(uri->Equals(aURL, &equal)) && equal) return NS_OK; - else { - FlushStyleBindings(aContent); - binding = nsnull; - } + FlushStyleBindings(aContent); + binding = nsnull; } } } @@ -579,29 +581,29 @@ nsXBLService::LoadBindings(nsIContent* aContent, const nsAString& aURL, PRBool a rv = docURI->SchemeIs("chrome", &isChrome); if (NS_FAILED(rv) || !isChrome) { - nsCOMPtr bindingURI; - rv = NS_NewURI(getter_AddRefs(bindingURI), aURL); - NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr secMan( do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv)); NS_ENSURE_SUCCESS(rv, rv); - rv = secMan->CheckLoadURI(docURI, bindingURI, + rv = secMan->CheckLoadURI(docURI, aURL, nsIScriptSecurityManager::ALLOW_CHROME); if (NS_FAILED(rv)) return rv; } nsCOMPtr newBinding; - nsCAutoString url; url.AssignWithConversion(aURL); - if (NS_FAILED(rv = GetBinding(aContent, url, getter_AddRefs(newBinding)))) { + nsCAutoString spec; + aURL->GetSpec(spec); + if (NS_FAILED(rv = GetBinding(aContent, spec, getter_AddRefs(newBinding)))) { return rv; } if (!newBinding) { - nsCAutoString str( "Failed to locate XBL binding. XBL is now using id instead of name to reference bindings. Make sure you have switched over. The invalid binding name is: "); - str.AppendWithConversion(aURL); +#ifdef DEBUG + nsCAutoString spec; + aURL->GetSpec(spec); + nsCAutoString str(NS_LITERAL_CSTRING("Failed to locate XBL binding. XBL is now using id instead of name to reference bindings. Make sure you have switched over. The invalid binding name is: ") + spec); NS_ERROR(str.get()); +#endif return NS_OK; } diff --git a/mozilla/content/xbl/src/nsXBLService.h b/mozilla/content/xbl/src/nsXBLService.h index e719e9f629b..5813a75c425 100644 --- a/mozilla/content/xbl/src/nsXBLService.h +++ b/mozilla/content/xbl/src/nsXBLService.h @@ -67,7 +67,7 @@ class nsXBLService : public nsIXBLService, // This function loads a particular XBL file and installs all of the bindings // onto the element. - NS_IMETHOD LoadBindings(nsIContent* aContent, const nsAString& aURL, PRBool aAugmentFlag, + NS_IMETHOD LoadBindings(nsIContent* aContent, nsIURI* aURL, PRBool aAugmentFlag, nsIXBLBinding** aBinding, PRBool* aResolveStyle); // Indicates whether or not a binding is fully loaded. diff --git a/mozilla/dom/src/base/nsDOMClassInfo.cpp b/mozilla/dom/src/base/nsDOMClassInfo.cpp index 35a077b7d4f..2c31dbba713 100644 --- a/mozilla/dom/src/base/nsDOMClassInfo.cpp +++ b/mozilla/dom/src/base/nsDOMClassInfo.cpp @@ -4661,9 +4661,9 @@ nsElementSH::PostCreate(nsIXPConnectWrappedNative *wrapper, JSContext *cx, // the DOM computed style API. We can get rid of this hack if we merge // the jsdom library with layout. - nsAutoString bindingURL; - pctx->GetXBLBindingURL(content, bindingURL); - if (bindingURL.IsEmpty()) { + nsCOMPtr bindingURL; + pctx->GetXBLBindingURL(content, getter_AddRefs(bindingURL)); + if (!binding) { // No binding, nothing left to do here. return NS_OK; } diff --git a/mozilla/embedding/browser/webBrowser/nsContextMenuInfo.cpp b/mozilla/embedding/browser/webBrowser/nsContextMenuInfo.cpp index 0f29e0ae82e..e6ffb21c685 100644 --- a/mozilla/embedding/browser/webBrowser/nsContextMenuInfo.cpp +++ b/mozilla/embedding/browser/webBrowser/nsContextMenuInfo.cpp @@ -269,9 +269,9 @@ nsContextMenuInfo::GetBackgroundImageRequest(nsIDOMNode * aDOMNode, imgIRequest do { bg = frame->GetStyleBackground(); frame = frame->GetParent(); - } while (bg && bg->mBackgroundImage.IsEmpty() && frame); + } while (!bg->mBackgroundImage && frame); - if (bg && !bg->mBackgroundImage.IsEmpty()) + if (bg->mBackgroundImage) { nsIFrame *pBGFrame = nsnull; rv = GetFrameForBackgroundUpdate(presContext, frame, &pBGFrame); @@ -304,7 +304,7 @@ nsContextMenuInfo::GetBackgroundImageRequest(nsIDOMNode * aDOMNode, imgIRequest PRBool isCanvas; PRBool foundBackground; presContext->FindFrameBackground(frame, &bg, &isCanvas, &foundBackground); - if (bg && !bg->mBackgroundImage.IsEmpty()) + if (bg && bg->mBackgroundImage) { nsIFrame *pBGFrame = nsnull; rv = GetFrameForBackgroundUpdate(presContext, frame, &pBGFrame); diff --git a/mozilla/extensions/inspector/base/src/inCSSValueSearch.cpp b/mozilla/extensions/inspector/base/src/inCSSValueSearch.cpp index 2a7bfe8988c..6c39e143195 100644 --- a/mozilla/extensions/inspector/base/src/inCSSValueSearch.cpp +++ b/mozilla/extensions/inspector/base/src/inCSSValueSearch.cpp @@ -332,12 +332,16 @@ inCSSValueSearch::SearchStyleValue(nsICSSStyleRule* aRule, nsCSSProperty aProp) aRule->GetValue(aProp, value); if (value.GetUnit() == eCSSUnit_URL) { - nsAutoString* result = new nsAutoString(); - value.GetStringValue(*result); - if (mReturnRelativeURLs) + nsCAutoString spec; + nsIURI* url = value.GetURLValue(); + if (url) { + url->GetSpec(spec); + nsAutoString* result = new NS_ConvertUTF8toUTF16(spec); + if (mReturnRelativeURLs) EqualizeURL(result); - mResults->AppendElement((void*)result); - mResultCount++; + mResults->AppendElement(result); + mResultCount++; + } } return NS_OK; diff --git a/mozilla/layout/base/nsCSSFrameConstructor.cpp b/mozilla/layout/base/nsCSSFrameConstructor.cpp index b156ed393f6..c826f880248 100644 --- a/mozilla/layout/base/nsCSSFrameConstructor.cpp +++ b/mozilla/layout/base/nsCSSFrameConstructor.cpp @@ -1367,9 +1367,8 @@ nsCSSFrameConstructor::CreateGeneratedFrameFor(nsIPresContext* aPresContex *aFrame = nsnull; // initialize OUT parameter // Get the content value - nsStyleContentType type; - nsAutoString contentString; - aStyleContent->GetContentAt(aContentIndex, type, contentString); + const nsStyleContentData &data = aStyleContent->ContentAt(aContentIndex); + nsStyleContentType type = data.mType; nsCOMPtr shell; aPresContext->GetShell(getter_AddRefs(shell)); @@ -1395,8 +1394,10 @@ nsCSSFrameConstructor::CreateGeneratedFrameFor(nsIPresContext* aPresContex rv = ef->CreateInstanceByTag(nodeInfo,getter_AddRefs(content)); NS_ENSURE_SUCCESS(rv, rv); - content->SetAttr(kNameSpaceID_None, nsHTMLAtoms::src, contentString, - PR_FALSE); + nsCAutoString spec; + data.mContent.mURL->GetSpec(spec); // XXXldb Ugh. + content->SetAttr(kNameSpaceID_None, nsHTMLAtoms::src, + NS_ConvertUTF8toUCS2(spec), PR_FALSE); // Set aContent as the parent content and set the document object. This // way event handling works @@ -1421,6 +1422,8 @@ nsCSSFrameConstructor::CreateGeneratedFrameFor(nsIPresContext* aPresContex } else { + nsAutoString contentString(data.mContent.mString); + switch (type) { case eStyleContentType_String: break; @@ -3356,7 +3359,7 @@ nsCSSFrameConstructor::ConstructDocElementFrame(nsIPresShell* aPresShell, const nsStyleDisplay* display = styleContext->GetStyleDisplay(); // Ensure that our XBL bindings are installed. - if (!display->mBinding.IsEmpty()) { + if (display->mBinding) { // Get the XBL loader. nsresult rv; PRBool resolveStyle; @@ -7112,7 +7115,7 @@ nsCSSFrameConstructor::ConstructFrameInternal( nsIPresShell* aPresShe { // Ensure that our XBL bindings are installed. - if (!display->mBinding.IsEmpty()) { + if (display->mBinding) { // Get the XBL loader. nsresult rv; // Load the bindings. diff --git a/mozilla/layout/base/nsCSSRendering.cpp b/mozilla/layout/base/nsCSSRendering.cpp index bda5c1108cd..90b60a34cb1 100644 --- a/mozilla/layout/base/nsCSSRendering.cpp +++ b/mozilla/layout/base/nsCSSRendering.cpp @@ -2926,7 +2926,7 @@ nsCSSRendering::PaintBackgroundWithSC(nsIPresContext* aPresContext, } // if there is no background image or background images are turned off, try a color. - if (aColor.mBackgroundImage.IsEmpty() || !canDrawBackgroundImage) { + if (!aColor.mBackgroundImage || !canDrawBackgroundImage) { PaintBackgroundColor(aPresContext, aRenderingContext, aForFrame, bgClipArea, aColor, aBorder, aPadding, canDrawBackgroundColor); return; diff --git a/mozilla/layout/base/nsFrameManager.cpp b/mozilla/layout/base/nsFrameManager.cpp index 80615d5bf52..5cdff410f61 100644 --- a/mozilla/layout/base/nsFrameManager.cpp +++ b/mozilla/layout/base/nsFrameManager.cpp @@ -1564,12 +1564,11 @@ HasAttributeContent(nsStyleContext* aStyleContext, const nsStyleContent* content = aStyleContext->GetStyleContent(); PRUint32 count = content->ContentCount(); while ((0 < count) && (! result)) { - nsStyleContentType contentType; - nsAutoString contentString; - content->GetContentAt(--count, contentType, contentString); - if (eStyleContentType_Attr == contentType) { + const nsStyleContentData &data = content->ContentAt(--count); + if (eStyleContentType_Attr == data.mType) { nsIAtom* attrName = nsnull; PRInt32 attrNameSpace = kNameSpaceID_None; + nsAutoString contentString(data.mContent.mString); PRInt32 barIndex = contentString.FindChar('|'); // CSS namespace delimiter if (-1 != barIndex) { nsAutoString nameSpaceVal; @@ -1731,8 +1730,12 @@ FrameManager::ReResolveStyleContext(nsIPresContext* aPresContext, const nsStyleBackground* oldColor = oldContext->GetStyleBackground(); const nsStyleBackground* newColor = newContext->GetStyleBackground(); - if (!oldColor->mBackgroundImage.IsEmpty() && - oldColor->mBackgroundImage != newColor->mBackgroundImage) { + PRBool equal; + if (oldColor->mBackgroundImage && + (!newColor->mBackgroundImage || + NS_FAILED(oldColor->mBackgroundImage->Equals( + newColor->mBackgroundImage, &equal)) || + !equal)) { // stop the image loading for the frame, the image has changed aPresContext->StopImagesFor(aFrame); } diff --git a/mozilla/layout/base/nsPresContext.cpp b/mozilla/layout/base/nsPresContext.cpp index b46330a52d0..fafab68d844 100644 --- a/mozilla/layout/base/nsPresContext.cpp +++ b/mozilla/layout/base/nsPresContext.cpp @@ -985,13 +985,14 @@ nsPresContext::ProbePseudoStyleContextFor(nsIContent* aParentContent, } NS_IMETHODIMP -nsPresContext::GetXBLBindingURL(nsIContent* aContent, nsAString& aResult) +nsPresContext::GetXBLBindingURL(nsIContent* aContent, nsIURI** aResult) { nsRefPtr sc; sc = ResolveStyleContextFor(aContent, nsnull); NS_ENSURE_TRUE(sc, NS_ERROR_FAILURE); - aResult = sc->GetStyleDisplay()->mBinding; + *aResult = sc->GetStyleDisplay()->mBinding; + NS_IF_ADDREF(*aResult); return NS_OK; } @@ -1357,7 +1358,7 @@ nsPresContext::GetImageLoadFlags(nsLoadFlags& aLoadFlags) } NS_IMETHODIMP -nsPresContext::LoadImage(const nsString& aURL, +nsPresContext::LoadImage(nsIURI* aURL, nsIFrame* aTargetFrame, imgIRequest **aRequest) { @@ -1368,18 +1369,6 @@ nsPresContext::LoadImage(const nsString& aURL, nsVoidKey key(aTargetFrame); nsImageLoader *loader = NS_REINTERPRET_CAST(nsImageLoader*, mImageLoaders.Get(&key)); // addrefs - nsCOMPtr doc; - rv = mShell->GetDocument(getter_AddRefs(doc)); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr baseURI; - doc->GetBaseURL(getter_AddRefs(baseURI)); - - nsCOMPtr uri; - nsCOMPtr ioService; - GetIOService(getter_AddRefs(ioService)); - NS_NewURI(getter_AddRefs(uri), aURL, nsnull, baseURI, ioService); - if (!loader) { nsIContent* content = aTargetFrame->GetContent(); @@ -1402,7 +1391,7 @@ nsPresContext::LoadImage(const nsString& aURL, PRBool shouldLoad = PR_TRUE; rv = NS_CheckContentLoadPolicy(nsIContentPolicy::IMAGE, - uri, element, domWin, &shouldLoad); + aURL, element, domWin, &shouldLoad); if (NS_SUCCEEDED(rv) && !shouldLoad) return NS_ERROR_FAILURE; } @@ -1431,7 +1420,7 @@ nsPresContext::LoadImage(const nsString& aURL, aTargetFrame->AddStateBits(NS_FRAME_HAS_LOADED_IMAGES); } - loader->Load(uri); + loader->Load(aURL); loader->GetRequest(aRequest); diff --git a/mozilla/layout/base/nsPresContext.h b/mozilla/layout/base/nsPresContext.h index 846bc91a731..2d1c61573d6 100644 --- a/mozilla/layout/base/nsPresContext.h +++ b/mozilla/layout/base/nsPresContext.h @@ -247,10 +247,9 @@ public: /** * Resolve a new style context for a content node and return the URL - * for its XBL binding, or the empty string if it has no binding - * specified in CSS. + * for its XBL binding, or null if it has no binding specified in CSS. */ - NS_IMETHOD GetXBLBindingURL(nsIContent* aContent, nsAString& aResult) = 0; + NS_IMETHOD GetXBLBindingURL(nsIContent* aContent, nsIURI** aResult) = 0; /** * For a given frame tree, get a new style context that is the equivalent @@ -319,7 +318,7 @@ public: * method will be invoked (via the ViewManager) so that the * appropriate damage repair is done. */ - NS_IMETHOD LoadImage(const nsString& aURL, + NS_IMETHOD LoadImage(nsIURI* aURL, nsIFrame* aTargetFrame, imgIRequest **aRequest) = 0; diff --git a/mozilla/layout/base/public/nsIPresContext.h b/mozilla/layout/base/public/nsIPresContext.h index 846bc91a731..2d1c61573d6 100644 --- a/mozilla/layout/base/public/nsIPresContext.h +++ b/mozilla/layout/base/public/nsIPresContext.h @@ -247,10 +247,9 @@ public: /** * Resolve a new style context for a content node and return the URL - * for its XBL binding, or the empty string if it has no binding - * specified in CSS. + * for its XBL binding, or null if it has no binding specified in CSS. */ - NS_IMETHOD GetXBLBindingURL(nsIContent* aContent, nsAString& aResult) = 0; + NS_IMETHOD GetXBLBindingURL(nsIContent* aContent, nsIURI** aResult) = 0; /** * For a given frame tree, get a new style context that is the equivalent @@ -319,7 +318,7 @@ public: * method will be invoked (via the ViewManager) so that the * appropriate damage repair is done. */ - NS_IMETHOD LoadImage(const nsString& aURL, + NS_IMETHOD LoadImage(nsIURI* aURL, nsIFrame* aTargetFrame, imgIRequest **aRequest) = 0; diff --git a/mozilla/layout/base/public/nsPresContext.h b/mozilla/layout/base/public/nsPresContext.h index 846bc91a731..2d1c61573d6 100644 --- a/mozilla/layout/base/public/nsPresContext.h +++ b/mozilla/layout/base/public/nsPresContext.h @@ -247,10 +247,9 @@ public: /** * Resolve a new style context for a content node and return the URL - * for its XBL binding, or the empty string if it has no binding - * specified in CSS. + * for its XBL binding, or null if it has no binding specified in CSS. */ - NS_IMETHOD GetXBLBindingURL(nsIContent* aContent, nsAString& aResult) = 0; + NS_IMETHOD GetXBLBindingURL(nsIContent* aContent, nsIURI** aResult) = 0; /** * For a given frame tree, get a new style context that is the equivalent @@ -319,7 +318,7 @@ public: * method will be invoked (via the ViewManager) so that the * appropriate damage repair is done. */ - NS_IMETHOD LoadImage(const nsString& aURL, + NS_IMETHOD LoadImage(nsIURI* aURL, nsIFrame* aTargetFrame, imgIRequest **aRequest) = 0; diff --git a/mozilla/layout/base/src/nsPresContext.cpp b/mozilla/layout/base/src/nsPresContext.cpp index b46330a52d0..fafab68d844 100644 --- a/mozilla/layout/base/src/nsPresContext.cpp +++ b/mozilla/layout/base/src/nsPresContext.cpp @@ -985,13 +985,14 @@ nsPresContext::ProbePseudoStyleContextFor(nsIContent* aParentContent, } NS_IMETHODIMP -nsPresContext::GetXBLBindingURL(nsIContent* aContent, nsAString& aResult) +nsPresContext::GetXBLBindingURL(nsIContent* aContent, nsIURI** aResult) { nsRefPtr sc; sc = ResolveStyleContextFor(aContent, nsnull); NS_ENSURE_TRUE(sc, NS_ERROR_FAILURE); - aResult = sc->GetStyleDisplay()->mBinding; + *aResult = sc->GetStyleDisplay()->mBinding; + NS_IF_ADDREF(*aResult); return NS_OK; } @@ -1357,7 +1358,7 @@ nsPresContext::GetImageLoadFlags(nsLoadFlags& aLoadFlags) } NS_IMETHODIMP -nsPresContext::LoadImage(const nsString& aURL, +nsPresContext::LoadImage(nsIURI* aURL, nsIFrame* aTargetFrame, imgIRequest **aRequest) { @@ -1368,18 +1369,6 @@ nsPresContext::LoadImage(const nsString& aURL, nsVoidKey key(aTargetFrame); nsImageLoader *loader = NS_REINTERPRET_CAST(nsImageLoader*, mImageLoaders.Get(&key)); // addrefs - nsCOMPtr doc; - rv = mShell->GetDocument(getter_AddRefs(doc)); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr baseURI; - doc->GetBaseURL(getter_AddRefs(baseURI)); - - nsCOMPtr uri; - nsCOMPtr ioService; - GetIOService(getter_AddRefs(ioService)); - NS_NewURI(getter_AddRefs(uri), aURL, nsnull, baseURI, ioService); - if (!loader) { nsIContent* content = aTargetFrame->GetContent(); @@ -1402,7 +1391,7 @@ nsPresContext::LoadImage(const nsString& aURL, PRBool shouldLoad = PR_TRUE; rv = NS_CheckContentLoadPolicy(nsIContentPolicy::IMAGE, - uri, element, domWin, &shouldLoad); + aURL, element, domWin, &shouldLoad); if (NS_SUCCEEDED(rv) && !shouldLoad) return NS_ERROR_FAILURE; } @@ -1431,7 +1420,7 @@ nsPresContext::LoadImage(const nsString& aURL, aTargetFrame->AddStateBits(NS_FRAME_HAS_LOADED_IMAGES); } - loader->Load(uri); + loader->Load(aURL); loader->GetRequest(aRequest); diff --git a/mozilla/layout/base/src/nsPresContext.h b/mozilla/layout/base/src/nsPresContext.h index f4bb03af3a6..9ca3f93073c 100644 --- a/mozilla/layout/base/src/nsPresContext.h +++ b/mozilla/layout/base/src/nsPresContext.h @@ -105,7 +105,7 @@ public: nsIAtom* aPseudoTag, nsStyleContext* aParentContext); - NS_IMETHOD GetXBLBindingURL(nsIContent* aContent, nsAString& aResult); + NS_IMETHOD GetXBLBindingURL(nsIContent* aContent, nsIURI** aResult); NS_IMETHOD ReParentStyleContext(nsIFrame* aFrame, nsStyleContext* aNewParentContext); NS_IMETHOD GetMetricsFor(const nsFont& aFont, nsIFontMetrics** aResult); @@ -133,7 +133,7 @@ public: NS_IMETHOD SetDefaultLinkColor(nscolor aColor); NS_IMETHOD SetDefaultVisitedLinkColor(nscolor aColor); - NS_IMETHOD LoadImage(const nsString& aURL, + NS_IMETHOD LoadImage(nsIURI* aURL, nsIFrame* aTargetFrame, imgIRequest **aRequest); diff --git a/mozilla/layout/forms/nsGfxCheckboxControlFrame.cpp b/mozilla/layout/forms/nsGfxCheckboxControlFrame.cpp index dba59377cd3..9918a1830be 100644 --- a/mozilla/layout/forms/nsGfxCheckboxControlFrame.cpp +++ b/mozilla/layout/forms/nsGfxCheckboxControlFrame.cpp @@ -231,7 +231,7 @@ nsGfxCheckboxControlFrame::Paint(nsIPresContext* aPresContext, if (!mCheckButtonFaceStyle && GetCheckboxState()) { const nsStyleBackground* myColor = mCheckButtonFaceStyle->GetStyleBackground(); - if (!myColor->mBackgroundImage.IsEmpty()) { + if (myColor->mBackgroundImage) { const nsStyleBorder* myBorder = mCheckButtonFaceStyle->GetStyleBorder(); const nsStylePadding* myPadding = mCheckButtonFaceStyle->GetStylePadding(); const nsStylePosition* myPosition = mCheckButtonFaceStyle->GetStylePosition(); diff --git a/mozilla/layout/generic/nsBulletFrame.cpp b/mozilla/layout/generic/nsBulletFrame.cpp index 1ad649a1b61..d78847be840 100644 --- a/mozilla/layout/generic/nsBulletFrame.cpp +++ b/mozilla/layout/generic/nsBulletFrame.cpp @@ -124,9 +124,8 @@ nsBulletFrame::Init(nsIPresContext* aPresContext, nsresult rv = nsFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow); - const nsStyleList* myList = GetStyleList(); - - if (!myList->mListStyleImage.IsEmpty()) { + nsIURI *imgURI = GetStyleList()->mListStyleImage; + if (imgURI) { nsCOMPtr il(do_GetService("@mozilla.org/image/loader;1", &rv)); if (NS_FAILED(rv)) return rv; @@ -134,12 +133,6 @@ nsBulletFrame::Init(nsIPresContext* aPresContext, nsCOMPtr loadGroup; GetLoadGroup(aPresContext, getter_AddRefs(loadGroup)); - nsCOMPtr baseURI; - mContent->GetBaseURL(getter_AddRefs(baseURI)); - - nsCOMPtr imgURI; - NS_NewURI(getter_AddRefs(imgURI), myList->mListStyleImage, nsnull, baseURI); - // Get the document URI for the referrer... nsCOMPtr documentURI; nsCOMPtr doc; @@ -201,7 +194,7 @@ nsBulletFrame::Paint(nsIPresContext* aPresContext, const nsStyleList* myList = GetStyleList(); PRUint8 listStyleType = myList->mListStyleType; - if (!myList->mListStyleImage.IsEmpty() && mImageRequest) { + if (myList->mListStyleImage && mImageRequest) { PRUint32 status; mImageRequest->GetImageStatus(&status); if (status & imgIRequest::STATUS_LOAD_COMPLETE && @@ -1379,7 +1372,7 @@ nsBulletFrame::GetDesiredSize(nsIPresContext* aCX, const nsStyleList* myList = GetStyleList(); nscoord ascent; - if (!myList->mListStyleImage.IsEmpty() && mImageRequest) { + if (myList->mListStyleImage && mImageRequest) { PRUint32 status; mImageRequest->GetImageStatus(&status); if (status & imgIRequest::STATUS_SIZE_AVAILABLE && @@ -1595,12 +1588,9 @@ nsBulletFrame::Reflow(nsIPresContext* aPresContext, } if (isStyleChange) { - nsCOMPtr baseURI; - mContent->GetBaseURL(getter_AddRefs(baseURI)); + nsIURI *newURI = GetStyleList()->mListStyleImage; - const nsStyleList* myList = GetStyleList(); - - if (!myList->mListStyleImage.IsEmpty()) { + if (newURI) { if (!mListener) { nsBulletListener *listener; @@ -1612,10 +1602,6 @@ nsBulletFrame::Reflow(nsIPresContext* aPresContext, NS_RELEASE(listener); } - - nsCOMPtr newURI; - NS_NewURI(getter_AddRefs(newURI), myList->mListStyleImage, nsnull, baseURI); - PRBool needNewRequest = PR_TRUE; if (mImageRequest) { diff --git a/mozilla/layout/html/base/src/nsBulletFrame.cpp b/mozilla/layout/html/base/src/nsBulletFrame.cpp index 1ad649a1b61..d78847be840 100644 --- a/mozilla/layout/html/base/src/nsBulletFrame.cpp +++ b/mozilla/layout/html/base/src/nsBulletFrame.cpp @@ -124,9 +124,8 @@ nsBulletFrame::Init(nsIPresContext* aPresContext, nsresult rv = nsFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow); - const nsStyleList* myList = GetStyleList(); - - if (!myList->mListStyleImage.IsEmpty()) { + nsIURI *imgURI = GetStyleList()->mListStyleImage; + if (imgURI) { nsCOMPtr il(do_GetService("@mozilla.org/image/loader;1", &rv)); if (NS_FAILED(rv)) return rv; @@ -134,12 +133,6 @@ nsBulletFrame::Init(nsIPresContext* aPresContext, nsCOMPtr loadGroup; GetLoadGroup(aPresContext, getter_AddRefs(loadGroup)); - nsCOMPtr baseURI; - mContent->GetBaseURL(getter_AddRefs(baseURI)); - - nsCOMPtr imgURI; - NS_NewURI(getter_AddRefs(imgURI), myList->mListStyleImage, nsnull, baseURI); - // Get the document URI for the referrer... nsCOMPtr documentURI; nsCOMPtr doc; @@ -201,7 +194,7 @@ nsBulletFrame::Paint(nsIPresContext* aPresContext, const nsStyleList* myList = GetStyleList(); PRUint8 listStyleType = myList->mListStyleType; - if (!myList->mListStyleImage.IsEmpty() && mImageRequest) { + if (myList->mListStyleImage && mImageRequest) { PRUint32 status; mImageRequest->GetImageStatus(&status); if (status & imgIRequest::STATUS_LOAD_COMPLETE && @@ -1379,7 +1372,7 @@ nsBulletFrame::GetDesiredSize(nsIPresContext* aCX, const nsStyleList* myList = GetStyleList(); nscoord ascent; - if (!myList->mListStyleImage.IsEmpty() && mImageRequest) { + if (myList->mListStyleImage && mImageRequest) { PRUint32 status; mImageRequest->GetImageStatus(&status); if (status & imgIRequest::STATUS_SIZE_AVAILABLE && @@ -1595,12 +1588,9 @@ nsBulletFrame::Reflow(nsIPresContext* aPresContext, } if (isStyleChange) { - nsCOMPtr baseURI; - mContent->GetBaseURL(getter_AddRefs(baseURI)); + nsIURI *newURI = GetStyleList()->mListStyleImage; - const nsStyleList* myList = GetStyleList(); - - if (!myList->mListStyleImage.IsEmpty()) { + if (newURI) { if (!mListener) { nsBulletListener *listener; @@ -1612,10 +1602,6 @@ nsBulletFrame::Reflow(nsIPresContext* aPresContext, NS_RELEASE(listener); } - - nsCOMPtr newURI; - NS_NewURI(getter_AddRefs(newURI), myList->mListStyleImage, nsnull, baseURI); - PRBool needNewRequest = PR_TRUE; if (mImageRequest) { diff --git a/mozilla/layout/html/base/src/nsFrameManager.cpp b/mozilla/layout/html/base/src/nsFrameManager.cpp index 80615d5bf52..5cdff410f61 100644 --- a/mozilla/layout/html/base/src/nsFrameManager.cpp +++ b/mozilla/layout/html/base/src/nsFrameManager.cpp @@ -1564,12 +1564,11 @@ HasAttributeContent(nsStyleContext* aStyleContext, const nsStyleContent* content = aStyleContext->GetStyleContent(); PRUint32 count = content->ContentCount(); while ((0 < count) && (! result)) { - nsStyleContentType contentType; - nsAutoString contentString; - content->GetContentAt(--count, contentType, contentString); - if (eStyleContentType_Attr == contentType) { + const nsStyleContentData &data = content->ContentAt(--count); + if (eStyleContentType_Attr == data.mType) { nsIAtom* attrName = nsnull; PRInt32 attrNameSpace = kNameSpaceID_None; + nsAutoString contentString(data.mContent.mString); PRInt32 barIndex = contentString.FindChar('|'); // CSS namespace delimiter if (-1 != barIndex) { nsAutoString nameSpaceVal; @@ -1731,8 +1730,12 @@ FrameManager::ReResolveStyleContext(nsIPresContext* aPresContext, const nsStyleBackground* oldColor = oldContext->GetStyleBackground(); const nsStyleBackground* newColor = newContext->GetStyleBackground(); - if (!oldColor->mBackgroundImage.IsEmpty() && - oldColor->mBackgroundImage != newColor->mBackgroundImage) { + PRBool equal; + if (oldColor->mBackgroundImage && + (!newColor->mBackgroundImage || + NS_FAILED(oldColor->mBackgroundImage->Equals( + newColor->mBackgroundImage, &equal)) || + !equal)) { // stop the image loading for the frame, the image has changed aPresContext->StopImagesFor(aFrame); } diff --git a/mozilla/layout/html/forms/src/nsGfxCheckboxControlFrame.cpp b/mozilla/layout/html/forms/src/nsGfxCheckboxControlFrame.cpp index dba59377cd3..9918a1830be 100644 --- a/mozilla/layout/html/forms/src/nsGfxCheckboxControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsGfxCheckboxControlFrame.cpp @@ -231,7 +231,7 @@ nsGfxCheckboxControlFrame::Paint(nsIPresContext* aPresContext, if (!mCheckButtonFaceStyle && GetCheckboxState()) { const nsStyleBackground* myColor = mCheckButtonFaceStyle->GetStyleBackground(); - if (!myColor->mBackgroundImage.IsEmpty()) { + if (myColor->mBackgroundImage) { const nsStyleBorder* myBorder = mCheckButtonFaceStyle->GetStyleBorder(); const nsStylePadding* myPadding = mCheckButtonFaceStyle->GetStylePadding(); const nsStylePosition* myPosition = mCheckButtonFaceStyle->GetStylePosition(); diff --git a/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp b/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp index b156ed393f6..c826f880248 100644 --- a/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp +++ b/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp @@ -1367,9 +1367,8 @@ nsCSSFrameConstructor::CreateGeneratedFrameFor(nsIPresContext* aPresContex *aFrame = nsnull; // initialize OUT parameter // Get the content value - nsStyleContentType type; - nsAutoString contentString; - aStyleContent->GetContentAt(aContentIndex, type, contentString); + const nsStyleContentData &data = aStyleContent->ContentAt(aContentIndex); + nsStyleContentType type = data.mType; nsCOMPtr shell; aPresContext->GetShell(getter_AddRefs(shell)); @@ -1395,8 +1394,10 @@ nsCSSFrameConstructor::CreateGeneratedFrameFor(nsIPresContext* aPresContex rv = ef->CreateInstanceByTag(nodeInfo,getter_AddRefs(content)); NS_ENSURE_SUCCESS(rv, rv); - content->SetAttr(kNameSpaceID_None, nsHTMLAtoms::src, contentString, - PR_FALSE); + nsCAutoString spec; + data.mContent.mURL->GetSpec(spec); // XXXldb Ugh. + content->SetAttr(kNameSpaceID_None, nsHTMLAtoms::src, + NS_ConvertUTF8toUCS2(spec), PR_FALSE); // Set aContent as the parent content and set the document object. This // way event handling works @@ -1421,6 +1422,8 @@ nsCSSFrameConstructor::CreateGeneratedFrameFor(nsIPresContext* aPresContex } else { + nsAutoString contentString(data.mContent.mString); + switch (type) { case eStyleContentType_String: break; @@ -3356,7 +3359,7 @@ nsCSSFrameConstructor::ConstructDocElementFrame(nsIPresShell* aPresShell, const nsStyleDisplay* display = styleContext->GetStyleDisplay(); // Ensure that our XBL bindings are installed. - if (!display->mBinding.IsEmpty()) { + if (display->mBinding) { // Get the XBL loader. nsresult rv; PRBool resolveStyle; @@ -7112,7 +7115,7 @@ nsCSSFrameConstructor::ConstructFrameInternal( nsIPresShell* aPresShe { // Ensure that our XBL bindings are installed. - if (!display->mBinding.IsEmpty()) { + if (display->mBinding) { // Get the XBL loader. nsresult rv; // Load the bindings. diff --git a/mozilla/layout/html/style/src/nsCSSRendering.cpp b/mozilla/layout/html/style/src/nsCSSRendering.cpp index bda5c1108cd..90b60a34cb1 100644 --- a/mozilla/layout/html/style/src/nsCSSRendering.cpp +++ b/mozilla/layout/html/style/src/nsCSSRendering.cpp @@ -2926,7 +2926,7 @@ nsCSSRendering::PaintBackgroundWithSC(nsIPresContext* aPresContext, } // if there is no background image or background images are turned off, try a color. - if (aColor.mBackgroundImage.IsEmpty() || !canDrawBackgroundImage) { + if (!aColor.mBackgroundImage || !canDrawBackgroundImage) { PaintBackgroundColor(aPresContext, aRenderingContext, aForFrame, bgClipArea, aColor, aBorder, aPadding, canDrawBackgroundColor); return; diff --git a/mozilla/layout/style/nsCSSDeclaration.cpp b/mozilla/layout/style/nsCSSDeclaration.cpp index dcb3c6f3a5d..dd26f79903b 100644 --- a/mozilla/layout/style/nsCSSDeclaration.cpp +++ b/mozilla/layout/style/nsCSSDeclaration.cpp @@ -282,8 +282,6 @@ PRBool nsCSSDeclaration::AppendCSSValueToString(nsCSSProperty aProperty, const n if ((eCSSUnit_String <= unit) && (unit <= eCSSUnit_Counters)) { switch (unit) { - case eCSSUnit_URL: aResult.Append(NS_LITERAL_STRING("url(")); - break; case eCSSUnit_Attr: aResult.Append(NS_LITERAL_STRING("attr(")); break; case eCSSUnit_Counter: aResult.Append(NS_LITERAL_STRING("counter(")); @@ -385,7 +383,7 @@ PRBool nsCSSDeclaration::AppendCSSValueToString(nsCSSProperty aProperty, const n aResult.Append(NS_ConvertASCIItoUCS2(name)); } } - else if (eCSSUnit_Color == unit){ + else if (eCSSUnit_Color == unit) { nsAutoString tmpStr; nscolor color = aValue.GetColorValue(); @@ -406,6 +404,13 @@ PRBool nsCSSDeclaration::AppendCSSValueToString(nsCSSProperty aProperty, const n aResult.Append(PRUnichar(')')); } + else if (eCSSUnit_URL == unit) { + nsCAutoString spec; + aValue.GetURLValue()->GetSpec(spec); + aResult.Append(NS_LITERAL_STRING("url(") + + NS_ConvertUTF8toUCS2(spec) + + NS_LITERAL_STRING(")")); + } else if (eCSSUnit_Percent == unit) { nsAutoString tmpStr; tmpStr.AppendFloat(aValue.GetPercentValue() * 100.0f); @@ -426,7 +431,7 @@ PRBool nsCSSDeclaration::AppendCSSValueToString(nsCSSProperty aProperty, const n case eCSSUnit_Normal: aResult.Append(NS_LITERAL_STRING("normal")); break; case eCSSUnit_String: break; - case eCSSUnit_URL: + case eCSSUnit_URL: break; case eCSSUnit_Attr: case eCSSUnit_Counter: case eCSSUnit_Counters: aResult.Append(PRUnichar(')')); break; diff --git a/mozilla/layout/style/nsCSSParser.cpp b/mozilla/layout/style/nsCSSParser.cpp index b1cdffd94c9..b3dba2dacfe 100644 --- a/mozilla/layout/style/nsCSSParser.cpp +++ b/mozilla/layout/style/nsCSSParser.cpp @@ -3602,13 +3602,6 @@ PRBool CSSParserImpl::ParseAttr(PRInt32& aErrorCode, nsCSSValue& aValue) return PR_FALSE; } -inline static PRBool -css_RequiresAbsoluteURI(const nsString& uri) -{ - // cheap shot at figuring out if this requires an absolute url translation - return !StringBeginsWith(uri, NS_LITERAL_STRING("chrome:")); -} - PRBool CSSParserImpl::ParseURL(PRInt32& aErrorCode, nsCSSValue& aValue) { if (ExpectSymbol(aErrorCode, '(', PR_FALSE)) { @@ -3620,16 +3613,12 @@ PRBool CSSParserImpl::ParseURL(PRInt32& aErrorCode, nsCSSValue& aValue) // Translate url into an absolute url if the url is relative to // the style sheet. // XXX editors won't like this - too bad for now - nsAutoString absURL; - nsresult rv = NS_ERROR_FAILURE; - if (mURL && css_RequiresAbsoluteURI(tk->mIdent)) { - rv = NS_MakeAbsoluteURI(absURL, tk->mIdent, mURL); - } - if (NS_FAILED(rv)) { - absURL = tk->mIdent; - } + nsCOMPtr url; + NS_NewURI(getter_AddRefs(url), tk->mIdent, nsnull, mURL); if (ExpectSymbol(aErrorCode, ')', PR_TRUE)) { - aValue.SetStringValue(absURL, eCSSUnit_URL); + // Set a null value on failure. Most failure cases should be + // NS_ERROR_MALFORMED_URI. + aValue.SetURLValue(url); return PR_TRUE; } } diff --git a/mozilla/layout/style/nsCSSValue.cpp b/mozilla/layout/style/nsCSSValue.cpp index bf5e042e2c0..fc2d28c4cf4 100644 --- a/mozilla/layout/style/nsCSSValue.cpp +++ b/mozilla/layout/style/nsCSSValue.cpp @@ -90,6 +90,13 @@ nsCSSValue::nsCSSValue(nscolor aValue) mValue.mColor = aValue; } +nsCSSValue::nsCSSValue(nsIURI* aValue) + : mUnit(eCSSUnit_URL) +{ + mValue.mURL = aValue; + NS_IF_ADDREF(aValue); +} + nsCSSValue::nsCSSValue(const nsCSSValue& aCopy) : mUnit(aCopy.mUnit) { @@ -107,6 +114,10 @@ nsCSSValue::nsCSSValue(const nsCSSValue& aCopy) else if (eCSSUnit_Color == mUnit){ mValue.mColor = aCopy.mValue.mColor; } + else if (eCSSUnit_URL == mUnit){ + mValue.mURL = aCopy.mValue.mURL; + NS_IF_ADDREF(mValue.mURL); + } else { mValue.mFloat = aCopy.mValue.mFloat; } @@ -127,6 +138,10 @@ nsCSSValue& nsCSSValue::operator=(const nsCSSValue& aCopy) else if (eCSSUnit_Color == mUnit){ mValue.mColor = aCopy.mValue.mColor; } + else if (eCSSUnit_URL == mUnit){ + mValue.mURL = aCopy.mValue.mURL; + NS_IF_ADDREF(mValue.mURL); + } else { mValue.mFloat = aCopy.mValue.mFloat; } @@ -147,13 +162,20 @@ PRBool nsCSSValue::operator==(const nsCSSValue& aOther) const } } else if ((eCSSUnit_Integer <= mUnit) && (mUnit <= eCSSUnit_Enumerated)) { - return PRBool(mValue.mInt == aOther.mValue.mInt); + return mValue.mInt == aOther.mValue.mInt; } - else if (eCSSUnit_Color == mUnit){ - return PRBool(mValue.mColor == aOther.mValue.mColor); + else if (eCSSUnit_Color == mUnit) { + return mValue.mColor == aOther.mValue.mColor; + } + else if (eCSSUnit_URL == mUnit) { + PRBool eq; + return (mValue.mURL == aOther.mValue.mURL || // handles null == null + (mValue.mURL && aOther.mValue.mURL && + NS_SUCCEEDED(mValue.mURL->Equals(aOther.mValue.mURL, &eq)) && + eq)); } else { - return PRBool(mValue.mFloat == aOther.mValue.mFloat); + return mValue.mFloat == aOther.mValue.mFloat; } } return PR_FALSE; @@ -189,6 +211,14 @@ void nsCSSValue::SetColorValue(nscolor aValue) mValue.mColor = aValue; } +void nsCSSValue::SetURLValue(nsIURI* aValue) +{ + Reset(); + mUnit = eCSSUnit_URL; + mValue.mURL = aValue; + NS_IF_ADDREF(mValue.mURL); +} + void nsCSSValue::SetAutoValue(void) { Reset(); @@ -261,7 +291,7 @@ void nsCSSValue::AppendToString(nsAString& aBuffer, aBuffer.Append(PRUnichar(']')); } - else if (eCSSUnit_Color == mUnit){ + else if (eCSSUnit_Color == mUnit) { aBuffer.Append(NS_LITERAL_STRING("(0x")); nsAutoString intStr; @@ -288,6 +318,15 @@ void nsCSSValue::AppendToString(nsAString& aBuffer, aBuffer.Append(PRUnichar(')')); } + else if (eCSSUnit_URL == mUnit) { + if (mValue.mURL) { + nsCAutoString spec; + mValue.mURL->GetSpec(spec); + AppendUTF8toUTF16(spec, aBuffer); + } else { + aBuffer.Append(NS_LITERAL_STRING("url(invalid-url:)")); + } + } else if (eCSSUnit_Percent == mUnit) { nsAutoString floatString; floatString.AppendFloat(mValue.mFloat * 100.0f); @@ -351,4 +390,3 @@ void nsCSSValue::ToString(nsAString& aBuffer, aBuffer.Truncate(); AppendToString(aBuffer, aPropID); } - diff --git a/mozilla/layout/style/nsCSSValue.h b/mozilla/layout/style/nsCSSValue.h index 1afbf2443d7..3f730eab873 100644 --- a/mozilla/layout/style/nsCSSValue.h +++ b/mozilla/layout/style/nsCSSValue.h @@ -44,7 +44,7 @@ #include "nsCoord.h" #include "nsCSSProperty.h" #include "nsUnitConversion.h" - +#include "nsIURI.h" enum nsCSSUnit { eCSSUnit_Null = 0, // (n/a) null unit, value is not specified @@ -53,11 +53,11 @@ enum nsCSSUnit { eCSSUnit_Initial = 3, // (n/a) value is default UA value eCSSUnit_None = 4, // (n/a) value is none eCSSUnit_Normal = 5, // (n/a) value is normal (algorithmic, different than auto) - eCSSUnit_String = 10, // (nsString) a string value - eCSSUnit_URL = 11, // (nsString) a URL value - eCSSUnit_Attr = 12, // (nsString) a attr(string) value - eCSSUnit_Counter = 13, // (nsString) a counter(string,[string]) value - eCSSUnit_Counters = 14, // (nsString) a counters(string,string[,string]) value + eCSSUnit_String = 10, // (PRUnichar*) a string value + eCSSUnit_Attr = 11, // (PRUnichar*) a attr(string) value + eCSSUnit_Counter = 12, // (PRUnichar*) a counter(string,[string]) value + eCSSUnit_Counters = 13, // (PRUnichar*) a counters(string,string[,string]) value + eCSSUnit_URL = 14, // (nsIURI*) a URL value (null == invalid URI) eCSSUnit_Integer = 50, // (int) simple value eCSSUnit_Enumerated = 51, // (int) value has enumerated meaning eCSSUnit_Color = 80, // (color) an RGBA value @@ -129,6 +129,7 @@ public: nsCSSValue(float aValue, nsCSSUnit aUnit); nsCSSValue(const nsAString& aValue, nsCSSUnit aUnit); nsCSSValue(nscolor aValue); + nsCSSValue(nsIURI* aValue); nsCSSValue(const nsCSSValue& aCopy); ~nsCSSValue(void) { @@ -138,7 +139,11 @@ public: nsCSSValue& operator=(const nsCSSValue& aCopy); PRBool operator==(const nsCSSValue& aOther) const; - PRBool operator!=(const nsCSSValue& aOther) const; + + PRBool operator!=(const nsCSSValue& aOther) const + { + return !(*this == aOther); + } nsCSSUnit GetUnit(void) const { return mUnit; }; PRBool IsLengthUnit(void) const @@ -154,11 +159,56 @@ public: PRBool IsTimeUnit(void) const { return PRBool((eCSSUnit_Seconds <= mUnit) && (mUnit <= eCSSUnit_Milliseconds)); } - PRInt32 GetIntValue(void) const; - float GetPercentValue(void) const; - float GetFloatValue(void) const; - nsAString& GetStringValue(nsAString& aBuffer) const; - nscolor GetColorValue(void) const; + PRInt32 GetIntValue(void) const + { + NS_ASSERTION(mUnit == eCSSUnit_Integer || mUnit == eCSSUnit_Enumerated, + "not an int value"); + return mValue.mInt; + } + + float GetPercentValue(void) const + { + NS_ASSERTION(mUnit == eCSSUnit_Percent, "not a percent value"); + return mValue.mFloat; + } + + float GetFloatValue(void) const + { + NS_ASSERTION(eCSSUnit_Number <= mUnit, "not a float value"); + return mValue.mFloat; + } + + nsAString& GetStringValue(nsAString& aBuffer) const + { + NS_ASSERTION(eCSSUnit_String <= mUnit && mUnit <= eCSSUnit_Counters, + "not a string value"); + aBuffer.Truncate(); + if (nsnull != mValue.mString) { + aBuffer.Append(mValue.mString); + } + return aBuffer; + } + + const PRUnichar* GetStringBufferValue() const + { + NS_ASSERTION(eCSSUnit_String <= mUnit && mUnit <= eCSSUnit_Counters, + "not a string value"); + return mValue.mString; + } + + nscolor GetColorValue(void) const + { + NS_ASSERTION((mUnit == eCSSUnit_Color), "not a color value"); + return mValue.mColor; + } + + nsIURI* GetURLValue(void) const + { + NS_ASSERTION(mUnit == eCSSUnit_URL, "not a URL value"); + return mValue.mURL; + } + + nscoord GetLengthTwips(void) const { NS_ASSERTION(IsFixedLengthUnit(), "not a fixed length unit"); @@ -202,6 +252,8 @@ public: if ((eCSSUnit_String <= mUnit) && (mUnit <= eCSSUnit_Counters) && (nsnull != mValue.mString)) { nsCRT::free(mValue.mString); + } else if (eCSSUnit_URL == mUnit) { + NS_IF_RELEASE(mValue.mURL); } mUnit = eCSSUnit_Null; mValue.mInt = 0; @@ -227,6 +279,7 @@ public: void SetStringValue(const nsAString& aValue, nsCSSUnit aUnit); void SetColorValue(nscolor aValue); + void SetURLValue(nsIURI* aURI); void SetAutoValue(void); void SetInheritValue(void); void SetInitialValue(void); @@ -234,6 +287,7 @@ public: void SetNormalValue(void); // debugging methods only + // XXXldb Not anymore! void AppendToString(nsAString& aBuffer, nsCSSProperty aPropID = eCSSProperty_UNKNOWN) const; void ToString(nsAString& aBuffer, nsCSSProperty aPropID = eCSSProperty_UNKNOWN) const; @@ -244,64 +298,9 @@ protected: float mFloat; PRUnichar* mString; nscolor mColor; + nsIURI* mURL; } mValue; }; -inline PRInt32 nsCSSValue::GetIntValue(void) const -{ - NS_ASSERTION((mUnit == eCSSUnit_Integer) || - (mUnit == eCSSUnit_Enumerated), "not an int value"); - if ((mUnit == eCSSUnit_Integer) || - (mUnit == eCSSUnit_Enumerated)) { - return mValue.mInt; - } - return 0; -} - -inline float nsCSSValue::GetPercentValue(void) const -{ - NS_ASSERTION((mUnit == eCSSUnit_Percent), "not a percent value"); - if ((mUnit == eCSSUnit_Percent)) { - return mValue.mFloat; - } - return 0.0f; -} - -inline float nsCSSValue::GetFloatValue(void) const -{ - NS_ASSERTION((eCSSUnit_Number <= mUnit), "not a float value"); - if ((mUnit >= eCSSUnit_Number)) { - return mValue.mFloat; - } - return 0.0f; -} - -inline nsAString& nsCSSValue::GetStringValue(nsAString& aBuffer) const -{ - NS_ASSERTION((eCSSUnit_String <= mUnit) && (mUnit <= eCSSUnit_Counters), "not a string value"); - aBuffer.Truncate(); - if ((eCSSUnit_String <= mUnit) && (mUnit <= eCSSUnit_Counters) && - (nsnull != mValue.mString)) { - aBuffer.Append(mValue.mString); - } - return aBuffer; -} - -inline nscolor nsCSSValue::GetColorValue(void) const -{ - NS_ASSERTION((mUnit == eCSSUnit_Color), "not a color value"); - if (mUnit == eCSSUnit_Color) { - return mValue.mColor; - } - return NS_RGB(0,0,0); -} - -inline PRBool nsCSSValue::operator!=(const nsCSSValue& aOther) const -{ - return PRBool(! ((*this) == aOther)); -} - - - #endif /* nsCSSValue_h___ */ diff --git a/mozilla/layout/style/nsComputedDOMStyle.cpp b/mozilla/layout/style/nsComputedDOMStyle.cpp index 7113e1befee..0d728a9a73b 100644 --- a/mozilla/layout/style/nsComputedDOMStyle.cpp +++ b/mozilla/layout/style/nsComputedDOMStyle.cpp @@ -339,7 +339,7 @@ nsComputedDOMStyle::GetBinding(nsIFrame *aFrame, GetStyleData(eStyleStruct_Display, (const nsStyleStruct*&)display, aFrame); - if (display && !display->mBinding.IsEmpty()) { + if (display && display->mBinding) { val->SetURI(display->mBinding); } else { val->SetIdent(NS_LITERAL_STRING("none")); @@ -1307,7 +1307,7 @@ nsComputedDOMStyle::GetListStyleImage(nsIFrame *aFrame, GetStyleData(eStyleStruct_List, (const nsStyleStruct*&)list, aFrame); if (list) { - if (list->mListStyleImage.IsEmpty()) { + if (!list->mListStyleImage) { val->SetIdent(NS_LITERAL_STRING("none")); } else { val->SetURI(list->mListStyleImage); @@ -1741,7 +1741,7 @@ nsComputedDOMStyle::GetCursor(nsIFrame *aFrame, GetStyleData(eStyleStruct_UserInterface, (const nsStyleStruct*&)ui, aFrame); if (ui) { - if (!ui->mCursorImage.IsEmpty()) { + if (ui->mCursorImage) { val->SetURI(ui->mCursorImage); } else { if (ui->mCursor == NS_STYLE_CURSOR_AUTO) { diff --git a/mozilla/layout/style/nsROCSSPrimitiveValue.cpp b/mozilla/layout/style/nsROCSSPrimitiveValue.cpp index 75a1b521a10..6c1c1ace849 100644 --- a/mozilla/layout/style/nsROCSSPrimitiveValue.cpp +++ b/mozilla/layout/style/nsROCSSPrimitiveValue.cpp @@ -58,16 +58,20 @@ nsROCSSPrimitiveValue::~nsROCSSPrimitiveValue() } void -nsROCSSPrimitiveValue::GetEscapedURI(PRUnichar *aURI, PRUnichar **aReturn) +nsROCSSPrimitiveValue::GetEscapedURI(nsIURI *aURI, PRUnichar **aReturn) { - PRUint16 length = nsCRT::strlen(aURI); + nsCAutoString specUTF8; + aURI->GetSpec(specUTF8); + NS_ConvertUTF8toUCS2 spec(specUTF8); + + PRUint16 length = spec.Length(); PRUnichar *escaped = (PRUnichar *)nsMemory::Alloc(length * 2 * sizeof(PRUnichar) + sizeof(PRUnichar('\0'))); if (escaped) { PRUnichar *ptr = escaped; for (PRUint16 i = 0; i < length; ++i) { - switch (aURI[i]) { + switch (spec[i]) { case ' ' : // space case '\t': // tab case '(' : // opening parenthesis @@ -83,7 +87,7 @@ nsROCSSPrimitiveValue::GetEscapedURI(PRUnichar *aURI, PRUnichar **aReturn) default: break; } - *ptr++ = aURI[i]; + *ptr++ = spec[i]; } *ptr = 0; } @@ -159,10 +163,16 @@ nsROCSSPrimitiveValue::GetCssText(nsAString& aCssText) case CSS_URI : { nsXPIDLString uri; - GetEscapedURI(mValue.mString, getter_Copies(uri)); - tmpStr.Assign(NS_LITERAL_STRING("url(") + - uri + - NS_LITERAL_STRING(")")); + if (mValue.mURI) { + GetEscapedURI(mValue.mURI, getter_Copies(uri)); + tmpStr.Assign(NS_LITERAL_STRING("url(") + + uri + + NS_LITERAL_STRING(")")); + } else { + // XXXldb Any better ideas? It's good to have something that + // doesn't parse so that things round-trip "correctly". + tmpStr.Assign(NS_LITERAL_STRING("url(invalid-url:)")); + } break; } case CSS_PERCENTAGE : @@ -401,9 +411,14 @@ nsROCSSPrimitiveValue::GetStringValue(nsAString& aReturn) switch (mType) { case CSS_IDENT: case CSS_STRING: - case CSS_URI: aReturn.Assign(mValue.mString); break; + case CSS_URI: { + nsCAutoString spec; + if (mValue.mURI) + mValue.mURI->GetSpec(spec); + CopyUTF8toUTF16(spec, aReturn); + } break; case CSS_ATTR: default: aReturn.Truncate(); diff --git a/mozilla/layout/style/nsROCSSPrimitiveValue.h b/mozilla/layout/style/nsROCSSPrimitiveValue.h index b7f47a9caa8..d46528621f4 100644 --- a/mozilla/layout/style/nsROCSSPrimitiveValue.h +++ b/mozilla/layout/style/nsROCSSPrimitiveValue.h @@ -44,6 +44,7 @@ #include "nsCoord.h" #include "nsUnitConversion.h" #include "nsReadableUtils.h" +#include "nsIURI.h" #include "nsCOMPtr.h" #include "nsDOMError.h" @@ -151,26 +152,12 @@ public: } } - void SetURI(const nsACString& aString) + void SetURI(nsIURI *aURI) { Reset(); - mValue.mString = ToNewUnicode(aString); - if (mValue.mString) { - mType = CSS_URI; - } else { - mType = CSS_UNKNOWN; - } - } - - void SetURI(const nsAString& aString) - { - Reset(); - mValue.mString = ToNewUnicode(aString); - if (mValue.mString) { - mType = CSS_URI; - } else { - mType = CSS_UNKNOWN; - } + mValue.mURI = aURI; + NS_IF_ADDREF(mValue.mURI); + mType = CSS_URI; } void SetColor(nsIDOMRGBColor* aColor) @@ -206,11 +193,13 @@ public: switch (mType) { case CSS_IDENT: case CSS_STRING: - case CSS_URI: NS_ASSERTION(mValue.mString, "Null string should never happen"); nsMemory::Free(mValue.mString); mValue.mString = nsnull; break; + case CSS_URI: + NS_IF_RELEASE(mValue.mURI); + break; case CSS_RECT: NS_ASSERTION(mValue.mRect, "Null Rect should never happen"); NS_RELEASE(mValue.mRect); @@ -225,7 +214,7 @@ public: } private: - void GetEscapedURI(PRUnichar *aURI, PRUnichar **aReturn); + void GetEscapedURI(nsIURI *aURI, PRUnichar **aReturn); PRUint16 mType; @@ -235,6 +224,7 @@ private: nsIDOMRGBColor* mColor; nsIDOMRect* mRect; PRUnichar* mString; + nsIURI* mURI; } mValue; float mT2P; diff --git a/mozilla/layout/style/nsRuleNode.cpp b/mozilla/layout/style/nsRuleNode.cpp index 61bba67ac11..11d24f40a90 100644 --- a/mozilla/layout/style/nsRuleNode.cpp +++ b/mozilla/layout/style/nsRuleNode.cpp @@ -2321,7 +2321,7 @@ nsRuleNode::ComputeUserInterfaceData(nsStyleStruct* aStartData, ui->mCursor = NS_STYLE_CURSOR_AUTO; } else if (eCSSUnit_URL == list->mValue.GetUnit()) { - list->mValue.GetStringValue(ui->mCursorImage); + ui->mCursorImage = list->mValue.GetURLValue(); } else if (eCSSUnit_Inherit == list->mValue.GetUnit()) { inherited = PR_TRUE; @@ -2530,10 +2530,10 @@ nsRuleNode::ComputeDisplayData(nsStyleStruct* aStartStruct, // binding: url, none, inherit if (eCSSUnit_URL == displayData.mBinding.GetUnit()) { - displayData.mBinding.GetStringValue(display->mBinding); + display->mBinding = displayData.mBinding.GetURLValue(); } else if (eCSSUnit_None == displayData.mBinding.GetUnit()) { - display->mBinding.Truncate(); + display->mBinding = nsnull; } else if (eCSSUnit_Inherit == displayData.mBinding.GetUnit()) { inherited = PR_TRUE; @@ -2926,11 +2926,11 @@ nsRuleNode::ComputeBackgroundData(nsStyleStruct* aStartStruct, // background-image: url, none, inherit if (eCSSUnit_URL == colorData.mBackImage.GetUnit()) { - colorData.mBackImage.GetStringValue(bg->mBackgroundImage); + bg->mBackgroundImage = colorData.mBackImage.GetURLValue(); bg->mBackgroundFlags &= ~NS_STYLE_BG_IMAGE_NONE; } else if (eCSSUnit_None == colorData.mBackImage.GetUnit()) { - bg->mBackgroundImage.Truncate(); + bg->mBackgroundImage = nsnull; bg->mBackgroundFlags |= NS_STYLE_BG_IMAGE_NONE; } else if (eCSSUnit_Inherit == colorData.mBackImage.GetUnit()) { @@ -3448,10 +3448,10 @@ nsRuleNode::ComputeListData(nsStyleStruct* aStartStruct, // list-style-image: url, none, inherit if (eCSSUnit_URL == listData.mImage.GetUnit()) { - listData.mImage.GetStringValue(list->mListStyleImage); + list->mListStyleImage = listData.mImage.GetURLValue(); } else if (eCSSUnit_None == listData.mImage.GetUnit()) { - list->mListStyleImage.Truncate(); + list->mListStyleImage = nsnull; } else if (eCSSUnit_Inherit == listData.mImage.GetUnit()) { inherited = PR_TRUE; @@ -3813,10 +3813,8 @@ nsRuleNode::ComputeContentData(nsStyleStruct* aStartStruct, inherited = PR_TRUE; count = parentContent->ContentCount(); if (NS_SUCCEEDED(content->AllocateContents(count))) { - nsStyleContentType type; while (0 < count--) { - parentContent->GetContentAt(count, type, buffer); - content->SetContentAt(count, type, buffer); + content->ContentAt(count) = parentContent->ContentAt(count); } } } @@ -3834,6 +3832,7 @@ nsRuleNode::ComputeContentData(nsStyleStruct* aStartStruct, const nsCSSValue& value = contentValue->mValue; nsCSSUnit unit = value.GetUnit(); nsStyleContentType type; + nsStyleContentData &data = content->ContentAt(count++); switch (unit) { case eCSSUnit_String: type = eStyleContentType_String; break; case eCSSUnit_URL: type = eStyleContentType_URL; break; @@ -3857,13 +3856,18 @@ nsRuleNode::ComputeContentData(nsStyleStruct* aStartStruct, default: NS_ERROR("bad content type"); } - if (type < eStyleContentType_OpenQuote) { + data.mType = type; + if (type == eStyleContentType_URL) { + data.mContent.mURL = value.GetURLValue(); + NS_IF_ADDREF(data.mContent.mURL); + } + else if (type < eStyleContentType_OpenQuote) { value.GetStringValue(buffer); Unquote(buffer); - content->SetContentAt(count++, type, buffer); + data.mContent.mString = nsCRT::strdup(buffer.get()); } else { - content->SetContentAt(count++, type, nullStr); + data.mContent.mString = nsnull; } contentValue = contentValue->mNext; } diff --git a/mozilla/layout/style/nsStyleStruct.cpp b/mozilla/layout/style/nsStyleStruct.cpp index f6886c08c89..a4b9438d1e6 100644 --- a/mozilla/layout/style/nsStyleStruct.cpp +++ b/mozilla/layout/style/nsStyleStruct.cpp @@ -701,7 +701,6 @@ nsStyleList::nsStyleList() { mListStyleType = NS_STYLE_LIST_STYLE_BASIC; mListStylePosition = NS_STYLE_LIST_STYLE_POSITION_OUTSIDE; - mListStyleImage.Truncate(); } nsStyleList::~nsStyleList() @@ -709,10 +708,10 @@ nsStyleList::~nsStyleList() } nsStyleList::nsStyleList(const nsStyleList& aSource) + : mListStyleType(aSource.mListStyleType), + mListStylePosition(aSource.mListStylePosition), + mListStyleImage(aSource.mListStyleImage) { - mListStyleType = aSource.mListStyleType; - mListStylePosition = aSource.mListStylePosition; - mListStyleImage = aSource.mListStyleImage; } nsChangeHint nsStyleList::CalcDifference(const nsStyleList& aOther) const @@ -1192,7 +1191,7 @@ nsStyleContent::nsStyleContent(const nsStyleContent& aSource) PRUint32 index; if (NS_SUCCEEDED(AllocateContents(aSource.ContentCount()))) { for (index = 0; index < mContentCount; index++) { - aSource.GetContentAt(index, mContents[index].mType, mContents[index].mContent); + ContentAt(index) = aSource.ContentAt(index); } } @@ -1219,8 +1218,7 @@ nsChangeHint nsStyleContent::CalcDifference(const nsStyleContent& aOther) const (mResetCount == aOther.mResetCount)) { PRUint32 ix = mContentCount; while (0 < ix--) { - if ((mContents[ix].mType != aOther.mContents[ix].mType) || - (mContents[ix].mContent != aOther.mContents[ix].mContent)) { + if (mContents[ix] != aOther.mContents[ix]) { // Unfortunately we need to reframe here; a simple reflow // will not pick up different text or different image URLs, // since we set all that up in the CSSFrameConstructor diff --git a/mozilla/layout/style/nsStyleStruct.h b/mozilla/layout/style/nsStyleStruct.h index 34381e87c16..c10c15bc946 100644 --- a/mozilla/layout/style/nsStyleStruct.h +++ b/mozilla/layout/style/nsStyleStruct.h @@ -52,6 +52,7 @@ #include "nsIPresShell.h" #include "nsCOMPtr.h" #include "nsILanguageAtom.h" +#include "nsIURI.h" class nsIFrame; @@ -183,7 +184,7 @@ struct nsStyleBackground : public nsStyleStruct { mBackgroundYPosition; // [reset] nscolor mBackgroundColor; // [reset] - nsString mBackgroundImage; // [reset] absolute url string + nsCOMPtr mBackgroundImage; // [reset] PRBool IsTransparent() const { @@ -586,7 +587,7 @@ struct nsStyleList : public nsStyleStruct { PRUint8 mListStyleType; // [inherited] See nsStyleConsts.h PRUint8 mListStylePosition; // [inherited] - nsString mListStyleImage; // [inherited] absolute url string + nsCOMPtr mListStyleImage; // [inherited] nsRect mImageRegion; // [inherited] the rect to use within an image }; @@ -732,7 +733,7 @@ struct nsStyleDisplay : public nsStyleStruct { nsChangeHint CalcDifference(const nsStyleDisplay& aOther) const; - nsString mBinding; // [reset] absolute url string + nsCOMPtr mBinding; // [reset] #if 0 // XXX This is how it is defined in the CSS2 spec, but the errata // changed it to be consistent with the positioning draft and how @@ -834,7 +835,48 @@ enum nsStyleContentType { struct nsStyleContentData { nsStyleContentType mType; - nsString mContent; + union { + PRUnichar *mString; + nsIURI *mURL; + } mContent; + + ~nsStyleContentData() { + if (mType == eStyleContentType_URL) { + NS_IF_RELEASE(mContent.mURL); + } else if (mContent.mString) { + nsCRT::free(mContent.mString); + } + } + + nsStyleContentData& operator=(const nsStyleContentData& aOther) { + mType = aOther.mType; + if (mType == eStyleContentType_URL) { + mContent.mURL = aOther.mContent.mURL; + NS_IF_ADDREF(mContent.mURL); + } else if (aOther.mContent.mString) { + mContent.mString = nsCRT::strdup(aOther.mContent.mString); + } else { + mContent.mString = nsnull; + } + return *this; + } + + PRBool operator==(const nsStyleContentData& aOther) { + if (mType != aOther.mType) + return PR_FALSE; + if (mType == eStyleContentType_URL) { + PRBool eq; + return mContent.mURL == aOther.mContent.mURL || // handles null==null + (mContent.mURL && aOther.mContent.mURL && + NS_SUCCEEDED(mContent.mURL->Equals(aOther.mContent.mURL, &eq)) && + eq); + } + return mContent.mString == aOther.mContent.mString; + } + + PRBool operator!=(const nsStyleContentData& aOther) { + return !(*this == aOther); + } }; struct nsStyleCounterData { @@ -926,13 +968,15 @@ struct nsStyleContent: public nsStyleStruct { nsChangeHint CalcDifference(const nsStyleContent& aOther) const; PRUint32 ContentCount(void) const { return mContentCount; } // [reset] - nsresult GetContentAt(PRUint32 aIndex, nsStyleContentType& aType, nsString& aContent) const { - if (aIndex < mContentCount) { - aType = mContents[aIndex].mType; - aContent = mContents[aIndex].mContent; - return NS_OK; - } - return NS_ERROR_ILLEGAL_VALUE; + + const nsStyleContentData& ContentAt(PRUint32 aIndex) const { + NS_ASSERTION(aIndex < mContentCount, "out of range"); + return mContents[aIndex]; + } + + nsStyleContentData& ContentAt(PRUint32 aIndex) { + NS_ASSERTION(aIndex < mContentCount, "out of range"); + return mContents[aIndex]; } nsresult AllocateContents(PRUint32 aCount) { @@ -950,20 +994,6 @@ struct nsStyleContent: public nsStyleStruct { return NS_OK; } - nsresult SetContentAt(PRUint32 aIndex, nsStyleContentType aType, const nsString& aContent) { - if (aIndex < mContentCount) { - mContents[aIndex].mType = aType; - if (aType < eStyleContentType_OpenQuote) { - mContents[aIndex].mContent = aContent; - } - else { - mContents[aIndex].mContent.Truncate(); - } - return NS_OK; - } - return NS_ERROR_ILLEGAL_VALUE; - } - PRUint32 CounterIncrementCount(void) const { return mIncrementCount; } // [reset] nsresult GetCounterIncrementAt(PRUint32 aIndex, nsString& aCounter, PRInt32& aIncrement) const { if (aIndex < mIncrementCount) { @@ -1094,7 +1124,7 @@ struct nsStyleUserInterface: public nsStyleStruct { PRUint8 mUserFocus; // [inherited] (auto-select) PRUint8 mCursor; // [inherited] See nsStyleConsts.h NS_STYLE_CURSOR_* - nsString mCursorImage; // [inherited] url string + nsCOMPtr mCursorImage; // [inherited] url string }; struct nsStyleXUL : public nsStyleStruct { diff --git a/mozilla/layout/xul/base/src/nsImageBoxFrame.cpp b/mozilla/layout/xul/base/src/nsImageBoxFrame.cpp index 58e318c9934..c814ac0a04b 100644 --- a/mozilla/layout/xul/base/src/nsImageBoxFrame.cpp +++ b/mozilla/layout/xul/base/src/nsImageBoxFrame.cpp @@ -357,12 +357,17 @@ void nsImageBoxFrame::GetImageSource() { // get the new image src - mContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::src, mSrc); - - // if the new image is empty - if (mSrc.IsEmpty()) { - mUseSrcAttr = PR_FALSE; - + nsAutoString src; + mContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::src, src); + mUseSrcAttr = !src.IsEmpty(); + if (mUseSrcAttr) { + nsCOMPtr baseURI; + if (mContent) { + mContent->GetBaseURL(getter_AddRefs(baseURI)); + } + // XXX origin charset needed + NS_NewURI(getter_AddRefs(mURI), src, nsnull, baseURI); + } else { // Only get the list-style-image if we aren't being drawn // by a native theme. const nsStyleDisplay* disp = GetStyleDisplay(); @@ -371,14 +376,8 @@ nsImageBoxFrame::GetImageSource() return; // get the list-style-image - const nsStyleList* myList = GetStyleList(); - - if (!myList->mListStyleImage.IsEmpty()) { - mSrc = myList->mListStyleImage; - } + mURI = GetStyleList()->mListStyleImage; } - else - mUseSrcAttr = PR_TRUE; } void @@ -414,7 +413,7 @@ nsImageBoxFrame::UpdateImage(nsIPresContext* aPresContext, PRBool& aResize) aResize = PR_FALSE; // get the new image src - if (mSrc.IsEmpty()) { + if (!mURI) { mSizeFrozen = PR_TRUE; mHasImage = PR_FALSE; aResize = PR_TRUE; @@ -427,21 +426,7 @@ nsImageBoxFrame::UpdateImage(nsIPresContext* aPresContext, PRBool& aResize) return; } - nsCOMPtr baseURI; - if (mContent) { - mContent->GetBaseURL(getter_AddRefs(baseURI)); - } - nsCOMPtr srcURI; - nsresult rv = NS_NewURI(getter_AddRefs(srcURI), mSrc, nsnull, baseURI); - - if (NS_FAILED(rv)) { - if (mImageRequest) { - mImageRequest->Cancel(NS_ERROR_FAILURE); - mImageRequest = nsnull; - } - return; - } - + nsresult rv; if (mImageRequest) { nsCOMPtr requestURI; rv = mImageRequest->GetURI(getter_AddRefs(requestURI)); @@ -449,9 +434,8 @@ nsImageBoxFrame::UpdateImage(nsIPresContext* aPresContext, PRBool& aResize) if (NS_FAILED(rv) || !requestURI) return; PRBool eq; - requestURI->Equals(srcURI, &eq); // if the source uri and the current one are the same, return - if (eq) + if (NS_SUCCEEDED(requestURI->Equals(mURI, &eq)) && eq) return; } @@ -481,7 +465,7 @@ nsImageBoxFrame::UpdateImage(nsIPresContext* aPresContext, PRBool& aResize) } // XXX: initialDocumentURI is NULL! - il->LoadImage(srcURI, nsnull, documentURI, loadGroup, mListener, doc, + il->LoadImage(mURI, nsnull, documentURI, loadGroup, mListener, doc, mLoadFlags, nsnull, nsnull, getter_AddRefs(mImageRequest)); aResize = PR_TRUE; @@ -587,11 +571,13 @@ nsImageBoxFrame::DidSetStyleContext( nsIPresContext* aPresContext ) return NS_OK; // If list-style-image changes, we have a new image. - nsAutoString newSrc; - if (myList->mListStyleImage.Equals(mSrc)) + nsIURI *newURI = myList->mListStyleImage; + PRBool equal; + if (newURI == mURI || // handles null==null + (newURI && mURI && NS_SUCCEEDED(newURI->Equals(mURI, &equal)) && equal)) return NS_OK; - mSrc = myList->mListStyleImage; + mURI = newURI; PRBool aResize; UpdateImage(aPresContext, aResize); diff --git a/mozilla/layout/xul/base/src/nsImageBoxFrame.h b/mozilla/layout/xul/base/src/nsImageBoxFrame.h index b52847dd260..faa06453159 100644 --- a/mozilla/layout/xul/base/src/nsImageBoxFrame.h +++ b/mozilla/layout/xul/base/src/nsImageBoxFrame.h @@ -146,7 +146,7 @@ private: nsCOMPtr mImageRequest; nsCOMPtr mListener; - nsString mSrc; // The raw image source. + nsCOMPtr mURI; // The URI of the image. PRPackedBool mUseSrcAttr; // Whether or not the image src comes from an attribute. PRPackedBool mSizeFrozen; diff --git a/mozilla/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp b/mozilla/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp index 3ca032018c2..9e1bf4ed3bb 100644 --- a/mozilla/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp +++ b/mozilla/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp @@ -1878,23 +1878,22 @@ nsTreeBodyFrame::GetImage(PRInt32 aRowIndex, const PRUnichar* aColID, PRBool aUs { *aResult = nsnull; - const nsAString* imagePtr; nsAutoString imageSrc; mView->GetImageSrc(aRowIndex, aColID, imageSrc); if (!aUseContext && !imageSrc.IsEmpty()) { - imagePtr = &imageSrc; aAllowImageRegions = PR_FALSE; } else { // Obtain the URL from the style context. aAllowImageRegions = PR_TRUE; - const nsStyleList* myList = aStyleContext->GetStyleList(); - if (!myList->mListStyleImage.IsEmpty()) - imagePtr = &myList->mListStyleImage; - else + nsIURI* uri = aStyleContext->GetStyleList()->mListStyleImage; + if (!uri) return NS_OK; + nsCAutoString spec; + uri->GetSpec(spec); + CopyUTF8toUTF16(spec, imageSrc); } - nsStringKey key(*imagePtr); + nsStringKey key(imageSrc); if (mImageCache) { // Look the image up in our cache. @@ -1939,7 +1938,8 @@ nsTreeBodyFrame::GetImage(PRInt32 aRowIndex, const PRUnichar* aColID, PRBool aUs mContent->GetBaseURL(getter_AddRefs(baseURI)); nsCOMPtr srcURI; - NS_NewURI(getter_AddRefs(srcURI), *imagePtr, nsnull, baseURI); + // XXX origin charset needed + NS_NewURI(getter_AddRefs(srcURI), imageSrc, nsnull, baseURI); if (!srcURI) return NS_ERROR_FAILURE; nsCOMPtr imageRequest; @@ -3324,7 +3324,7 @@ nsTreeBodyFrame::ScrollInternal(PRInt32 aRow) nscoord rowHeightAsPixels = NSToCoordRound((float)mRowHeight*t2p); // See if we have a background image. If we do, then we cannot blit. - PRBool hasBackground = !GetStyleBackground()->mBackgroundImage.IsEmpty(); + PRBool hasBackground = GetStyleBackground()->mBackgroundImage != nsnull; PRInt32 absDelta = PR_ABS(delta); if (hasBackground || absDelta*mRowHeight >= mRect.height)