From c86dfc36ed98e49e263513599de16389d5f15917 Mon Sep 17 00:00:00 2001 From: Ed Morley Date: Sun, 15 Jul 2012 11:42:31 +0100 Subject: [PATCH] Backout 6ceeca8b4b73 (bug 772332), ce5629b973e4, 1dcff1db63b4, 108d06ef7755 & 7bf6519b3f43 (bug 768756) for bustage --- content/smil/nsSMILCSSProperty.cpp | 15 +- dom/base/nsGlobalWindow.cpp | 8 +- editor/libeditor/html/Makefile.in | 3 - editor/libeditor/html/nsHTMLAbsPosition.cpp | 11 +- .../libeditor/html/nsHTMLAnonymousUtils.cpp | 11 +- editor/libeditor/html/nsHTMLCSSUtils.cpp | 136 ++++++++++-------- editor/libeditor/html/nsHTMLCSSUtils.h | 39 ++--- editor/libeditor/html/nsHTMLEditRules.cpp | 15 +- editor/libeditor/html/nsHTMLEditorStyle.cpp | 41 ++++-- layout/style/nsComputedDOMStyle.cpp | 106 ++++++++------ layout/style/nsComputedDOMStyle.h | 16 ++- 11 files changed, 232 insertions(+), 169 deletions(-) diff --git a/content/smil/nsSMILCSSProperty.cpp b/content/smil/nsSMILCSSProperty.cpp index 55b9aa131431..378038c9e2e6 100644 --- a/content/smil/nsSMILCSSProperty.cpp +++ b/content/smil/nsSMILCSSProperty.cpp @@ -17,7 +17,7 @@ using namespace mozilla::dom; // Helper function static bool -GetCSSComputedValue(Element* aElem, +GetCSSComputedValue(nsIContent* aElem, nsCSSProperty aPropID, nsAString& aResult) { @@ -40,11 +40,16 @@ GetCSSComputedValue(Element* aElem, return false; } - nsRefPtr computedStyle = - NS_NewComputedDOMStyle(aElem, EmptyString(), shell); + nsRefPtr computedStyle; + nsCOMPtr domElement(do_QueryInterface(aElem)); + nsresult rv = NS_NewComputedDOMStyle(domElement, EmptyString(), shell, + getter_AddRefs(computedStyle)); - computedStyle->GetPropertyValue(aPropID, aResult); - return true; + if (NS_SUCCEEDED(rv)) { + computedStyle->GetPropertyValue(aPropID, aResult); + return true; + } + return false; } // Class Methods diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 3dc2f0c5c47e..ef15a52c2952 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -8170,10 +8170,10 @@ nsGlobalWindow::GetComputedStyle(nsIDOMElement* aElt, return NS_OK; } - nsCOMPtr element = do_QueryInterface(aElt); - NS_ENSURE_TRUE(element, NS_ERROR_FAILURE); - nsRefPtr compStyle = - NS_NewComputedDOMStyle(element, aPseudoElt, presShell); + nsRefPtr compStyle; + nsresult rv = NS_NewComputedDOMStyle(aElt, aPseudoElt, presShell, + getter_AddRefs(compStyle)); + NS_ENSURE_SUCCESS(rv, rv); *aReturn = compStyle.forget().get(); diff --git a/editor/libeditor/html/Makefile.in b/editor/libeditor/html/Makefile.in index fede8c765932..65a557705045 100644 --- a/editor/libeditor/html/Makefile.in +++ b/editor/libeditor/html/Makefile.in @@ -48,8 +48,6 @@ CPPSRCS += nsHTMLEditorLog.cpp \ DEFINES += -DENABLE_EDITOR_API_LOG endif -DEFINES += -D_IMPL_NS_LAYOUT - # don't want the shared lib; force the creation of a static lib. FORCE_STATIC_LIB = 1 @@ -59,5 +57,4 @@ INCLUDES += -I$(topsrcdir)/editor/libeditor/base \ -I$(topsrcdir)/editor/libeditor/text \ -I$(topsrcdir)/editor/txmgr/src \ -I$(topsrcdir)/content/base/src \ - -I$(topsrcdir)/layout/style \ $(NULL) diff --git a/editor/libeditor/html/nsHTMLAbsPosition.cpp b/editor/libeditor/html/nsHTMLAbsPosition.cpp index fb3eebdba650..ca9a08ace7ea 100644 --- a/editor/libeditor/html/nsHTMLAbsPosition.cpp +++ b/editor/libeditor/html/nsHTMLAbsPosition.cpp @@ -12,7 +12,6 @@ #include "nsAlgorithm.h" #include "nsAutoPtr.h" #include "nsCOMPtr.h" -#include "nsComputedDOMStyle.h" #include "nsDebug.h" #include "nsEditProperty.h" #include "nsEditRules.h" @@ -657,9 +656,13 @@ nsHTMLEditor::CheckPositionedElementBGandFG(nsIDOMElement * aElement, bgColorStr); NS_ENSURE_SUCCESS(res, res); if (bgColorStr.EqualsLiteral("transparent")) { - nsRefPtr cssDecl = - mHTMLCSSUtils->GetComputedStyle(aElement); - NS_ENSURE_STATE(cssDecl); + nsCOMPtr window; + res = mHTMLCSSUtils->GetDefaultViewCSS(aElement, getter_AddRefs(window)); + NS_ENSURE_SUCCESS(res, res); + + nsCOMPtr cssDecl; + res = window->GetComputedStyle(aElement, EmptyString(), getter_AddRefs(cssDecl)); + NS_ENSURE_SUCCESS(res, res); // from these declarations, get the one we want and that one only nsCOMPtr colorCssValue; diff --git a/editor/libeditor/html/nsHTMLAnonymousUtils.cpp b/editor/libeditor/html/nsHTMLAnonymousUtils.cpp index c1023887c2e4..64a9f2ae5677 100644 --- a/editor/libeditor/html/nsHTMLAnonymousUtils.cpp +++ b/editor/libeditor/html/nsHTMLAnonymousUtils.cpp @@ -8,7 +8,6 @@ #include "nsAString.h" #include "nsAutoPtr.h" #include "nsCOMPtr.h" -#include "nsComputedDOMStyle.h" #include "nsContentUtils.h" #include "nsDebug.h" #include "nsEditProperty.h" @@ -421,10 +420,14 @@ nsHTMLEditor::GetPositionAndDimensions(nsIDOMElement * aElement, // Yes, it is absolutely positioned mResizedObjectIsAbsolutelyPositioned = true; + nsCOMPtr window; + res = mHTMLCSSUtils->GetDefaultViewCSS(aElement, getter_AddRefs(window)); + NS_ENSURE_TRUE(window, NS_ERROR_FAILURE); + + nsCOMPtr cssDecl; // Get the all the computed css styles attached to the element node - nsRefPtr cssDecl = - mHTMLCSSUtils->GetComputedStyle(aElement); - NS_ENSURE_STATE(cssDecl); + res = window->GetComputedStyle(aElement, EmptyString(), getter_AddRefs(cssDecl)); + NS_ENSURE_SUCCESS(res, res); aBorderLeft = GetCSSFloatValue(cssDecl, NS_LITERAL_STRING("border-left-width")); aBorderTop = GetCSSFloatValue(cssDecl, NS_LITERAL_STRING("border-top-width")); diff --git a/editor/libeditor/html/nsHTMLCSSUtils.cpp b/editor/libeditor/html/nsHTMLCSSUtils.cpp index a7d70d2476bf..2fe7a05b9d05 100644 --- a/editor/libeditor/html/nsHTMLCSSUtils.cpp +++ b/editor/libeditor/html/nsHTMLCSSUtils.cpp @@ -7,15 +7,12 @@ #include "EditTxn.h" #include "mozilla/Assertions.h" #include "mozilla/Preferences.h" -#include "mozilla/css/Declaration.h" -#include "mozilla/css/StyleRule.h" #include "mozilla/dom/Element.h" #include "mozilla/mozalloc.h" #include "nsAString.h" #include "nsAutoPtr.h" #include "nsCOMPtr.h" #include "nsColor.h" -#include "nsComputedDOMStyle.h" #include "nsContentUtils.h" #include "nsDebug.h" #include "nsDependentSubstring.h" @@ -573,85 +570,94 @@ nsresult nsHTMLCSSUtils::GetSpecifiedProperty(nsIDOMNode *aNode, nsIAtom *aProperty, nsAString & aValue) { - return GetCSSInlinePropertyBase(aNode, aProperty, aValue, eSpecified); + return GetCSSInlinePropertyBase(aNode, aProperty, aValue, nsnull, SPECIFIED_STYLE_TYPE); } nsresult nsHTMLCSSUtils::GetComputedProperty(nsIDOMNode *aNode, nsIAtom *aProperty, nsAString & aValue) { - return GetCSSInlinePropertyBase(aNode, aProperty, aValue, eComputed); -} + nsCOMPtr window; + nsresult res = GetDefaultViewCSS(aNode, getter_AddRefs(window)); + NS_ENSURE_SUCCESS(res, res); -nsresult -nsHTMLCSSUtils::GetCSSInlinePropertyBase(nsIDOMNode* aNode, nsIAtom* aProperty, - nsAString& aValue, - StyleType aStyleType) -{ - nsCOMPtr node = do_QueryInterface(aNode); - return GetCSSInlinePropertyBase(node, aProperty, aValue, aStyleType); + return GetCSSInlinePropertyBase(aNode, aProperty, aValue, window, COMPUTED_STYLE_TYPE); } nsresult nsHTMLCSSUtils::GetCSSInlinePropertyBase(nsINode* aNode, nsIAtom* aProperty, nsAString& aValue, - StyleType aStyleType) + nsIDOMWindow* aWindow, + PRUint8 aStyleType) { - MOZ_ASSERT(aNode && aProperty); - aValue.Truncate(); + nsCOMPtr node = do_QueryInterface(aNode); + return GetCSSInlinePropertyBase(node, aProperty, aValue, aWindow, aStyleType); +} - nsCOMPtr element = GetElementContainerOrSelf(aNode); +nsresult +nsHTMLCSSUtils::GetCSSInlinePropertyBase(nsIDOMNode *aNode, nsIAtom *aProperty, + nsAString& aValue, + nsIDOMWindow* aWindow, + PRUint8 aStyleType) +{ + aValue.Truncate(); + NS_ENSURE_TRUE(aProperty, NS_ERROR_NULL_POINTER); + + nsCOMPtr element = GetElementContainerOrSelf(aNode); NS_ENSURE_TRUE(element, NS_ERROR_NULL_POINTER); - if (aStyleType == eComputed) { - // Get the all the computed css styles attached to the element node - nsRefPtr cssDecl = GetComputedStyle(element); - NS_ENSURE_STATE(cssDecl); - - // from these declarations, get the one we want and that one only - MOZ_ALWAYS_TRUE(NS_SUCCEEDED( - cssDecl->GetPropertyValue(nsDependentAtomString(aProperty), aValue))); - - return NS_OK; + switch (aStyleType) { + case COMPUTED_STYLE_TYPE: + if (element && aWindow) { + nsAutoString value, propString; + nsCOMPtr cssDecl; + aProperty->ToString(propString); + // Get the all the computed css styles attached to the element node + nsresult res = aWindow->GetComputedStyle(element, EmptyString(), getter_AddRefs(cssDecl)); + if (NS_FAILED(res) || !cssDecl) + return res; + // from these declarations, get the one we want and that one only + res = cssDecl->GetPropertyValue(propString, value); + NS_ENSURE_SUCCESS(res, res); + aValue.Assign(value); + } + break; + case SPECIFIED_STYLE_TYPE: + if (element) { + nsCOMPtr cssDecl; + PRUint32 length; + nsresult res = GetInlineStyles(element, getter_AddRefs(cssDecl), &length); + if (NS_FAILED(res) || !cssDecl) return res; + nsAutoString value, propString; + aProperty->ToString(propString); + res = cssDecl->GetPropertyValue(propString, value); + NS_ENSURE_SUCCESS(res, res); + aValue.Assign(value); + } + break; } - - MOZ_ASSERT(aStyleType == eSpecified); - nsRefPtr rule = element->GetInlineStyleRule(); - if (!rule) { - return NS_OK; - } - nsCSSProperty prop = - nsCSSProps::LookupProperty(nsDependentAtomString(aProperty)); - MOZ_ASSERT(prop != eCSSProperty_UNKNOWN); - rule->GetDeclaration()->GetValue(prop, aValue); - return NS_OK; } -already_AddRefed -nsHTMLCSSUtils::GetComputedStyle(nsIDOMElement* aElement) +nsresult +nsHTMLCSSUtils::GetDefaultViewCSS(nsIDOMNode *aNode, nsIDOMWindow **aViewCSS) { - nsCOMPtr element = do_QueryInterface(aElement); - return GetComputedStyle(element); + nsCOMPtr node = do_QueryInterface(aNode); + NS_ENSURE_TRUE(node, NS_ERROR_NULL_POINTER); + return GetDefaultViewCSS(node, aViewCSS); } -already_AddRefed -nsHTMLCSSUtils::GetComputedStyle(dom::Element* aElement) +nsresult +nsHTMLCSSUtils::GetDefaultViewCSS(nsINode* aNode, nsIDOMWindow** aViewCSS) { - MOZ_ASSERT(aElement); + MOZ_ASSERT(aNode); + dom::Element* element = GetElementContainerOrSelf(aNode); + NS_ENSURE_TRUE(element, NS_ERROR_NULL_POINTER); - nsIDocument* doc = aElement->GetCurrentDoc(); - NS_ASSERTION(doc, "Trying to compute style of detached element"); - NS_ENSURE_TRUE(doc, nsnull); - - nsIPresShell* presShell = doc->GetShell(); - NS_ASSERTION(presShell, "Trying to compute style without PresShell"); - NS_ENSURE_TRUE(presShell, nsnull); - - nsRefPtr style = - NS_NewComputedDOMStyle(aElement, EmptyString(), presShell); - - return style.forget(); + nsCOMPtr window = element->OwnerDoc()->GetWindow(); + NS_ENSURE_TRUE(window, NS_ERROR_FAILURE); + window.forget(aViewCSS); + return NS_OK; } // remove the CSS style "aProperty : aPropertyValue" and possibly remove the whole node @@ -1060,7 +1066,7 @@ nsHTMLCSSUtils::GetCSSEquivalentToHTMLInlineStyleSet(nsINode* aNode, nsIAtom *aHTMLProperty, const nsAString *aAttribute, nsAString & aValueString, - StyleType aStyleType) + PRUint8 aStyleType) { aValueString.Truncate(); nsCOMPtr theElement = GetElementContainerOrSelf(aNode); @@ -1072,6 +1078,12 @@ nsHTMLCSSUtils::GetCSSEquivalentToHTMLInlineStyleSet(nsINode* aNode, } // Yes, the requested HTML style has a CSS equivalence in this implementation + // Retrieve the default ViewCSS if we are asked for computed styles + nsCOMPtr window; + if (COMPUTED_STYLE_TYPE == aStyleType) { + nsresult res = GetDefaultViewCSS(theElement, getter_AddRefs(window)); + NS_ENSURE_SUCCESS(res, res); + } nsTArray cssPropertyArray; nsTArray cssValueArray; // get the CSS equivalence with last param true indicating we want only the @@ -1083,7 +1095,7 @@ nsHTMLCSSUtils::GetCSSEquivalentToHTMLInlineStyleSet(nsINode* aNode, nsAutoString valueString; // retrieve the specified/computed value of the property nsresult res = GetCSSInlinePropertyBase(theElement, cssPropertyArray[index], - valueString, aStyleType); + valueString, window, aStyleType); NS_ENSURE_SUCCESS(res, res); // append the value to aValueString (possibly with a leading whitespace) if (index) { @@ -1106,9 +1118,11 @@ nsHTMLCSSUtils::IsCSSEquivalentToHTMLInlineStyleSet(nsIContent* aContent, nsIAtom* aProperty, const nsAString* aAttribute, const nsAString& aValue, - StyleType aStyleType) + PRUint8 aStyleType) { MOZ_ASSERT(aContent && aProperty); + MOZ_ASSERT(aStyleType == SPECIFIED_STYLE_TYPE || + aStyleType == COMPUTED_STYLE_TYPE); bool isSet; nsAutoString value(aValue); nsresult res = IsCSSEquivalentToHTMLInlineStyleSet(aContent->AsDOMNode(), @@ -1125,7 +1139,7 @@ nsHTMLCSSUtils::IsCSSEquivalentToHTMLInlineStyleSet(nsIDOMNode *aNode, const nsAString *aHTMLAttribute, bool& aIsSet, nsAString& valueString, - StyleType aStyleType) + PRUint8 aStyleType) { NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER); diff --git a/editor/libeditor/html/nsHTMLCSSUtils.h b/editor/libeditor/html/nsHTMLCSSUtils.h index 6213b7df28ba..1d806df43356 100644 --- a/editor/libeditor/html/nsHTMLCSSUtils.h +++ b/editor/libeditor/html/nsHTMLCSSUtils.h @@ -12,7 +12,6 @@ #include "prtypes.h" // for PRUint8, PRInt32, PRUint32 class ChangeCSSInlineStyleTxn; -class nsComputedDOMStyle; class nsIAtom; class nsIContent; class nsIDOMCSSStyleDeclaration; @@ -26,6 +25,9 @@ class Element; } // namespace dom } // namespace mozilla +#define SPECIFIED_STYLE_TYPE 1 +#define COMPUTED_STYLE_TYPE 2 + class nsHTMLEditor; class nsIDOMWindow; @@ -62,8 +64,6 @@ public: eCSSEditableProperty_width }; - enum StyleType { eSpecified, eComputed }; - struct CSSEquivTable { nsCSSEditableProperty cssProperty; @@ -176,13 +176,14 @@ public: * @param aHTMLProperty [IN] an atom containing an HTML property * @param aAttribute [IN] a pointer to an attribute name or nsnull if irrelevant * @param aValueString [OUT] the list of css values - * @param aStyleType [IN] eSpecified or eComputed + * @param aStyleType [IN] SPECIFIED_STYLE_TYPE to query the specified style values + COMPUTED_STYLE_TYPE to query the computed style values */ nsresult GetCSSEquivalentToHTMLInlineStyleSet(nsINode* aNode, nsIAtom * aHTMLProperty, const nsAString * aAttribute, nsAString & aValueString, - StyleType aStyleType); + PRUint8 aStyleType); /** Does the node aNode (or his parent if it is not an element node) carries * the CSS equivalent styles to the HTML style for this node ? @@ -192,7 +193,8 @@ public: * @param aAttribute [IN] a pointer to an attribute name or nsnull if irrelevant * @param aIsSet [OUT] a boolean being true if the css properties are set * @param aValueString [IN/OUT] the attribute value (in) the list of css values (out) - * @param aStyleType [IN] eSpecified or eComputed + * @param aStyleType [IN] SPECIFIED_STYLE_TYPE to query the specified style values + * COMPUTED_STYLE_TYPE to query the computed style values * * The nsIContent variant returns aIsSet instead of using an out parameter. */ @@ -200,14 +202,14 @@ public: nsIAtom* aProperty, const nsAString* aAttribute, const nsAString& aValue, - StyleType aStyleType); + PRUint8 aStyleType); nsresult IsCSSEquivalentToHTMLInlineStyleSet(nsIDOMNode * aNode, nsIAtom * aHTMLProperty, const nsAString * aAttribute, bool & aIsSet, nsAString & aValueString, - StyleType aStyleType); + PRUint8 aStyleType); /** Adds to the node the CSS inline styles equivalent to the HTML style * and return the number of CSS properties set by the call @@ -305,12 +307,13 @@ public: already_AddRefed GetElementContainerOrSelf(nsIDOMNode* aNode); /** - * Gets the computed style for a given element. Can return null. + * Gets the default Window for a given node. + * + * @param aNode the node we want the default Window for + * @param aWindow [OUT] the default Window */ - already_AddRefed - GetComputedStyle(nsIDOMElement* aElement); - already_AddRefed - GetComputedStyle(mozilla::dom::Element* aElement); + nsresult GetDefaultViewCSS(nsINode* aNode, nsIDOMWindow** aWindow); + nsresult GetDefaultViewCSS(nsIDOMNode* aNode, nsIDOMWindow** aWindow); private: @@ -380,12 +383,16 @@ private: * @param aNode [IN] a DOM node * @param aProperty [IN] a CSS property * @param aValue [OUT] the retrieved value for this property - * @param aStyleType [IN] eSpecified or eComputed + * @param aWindow [IN] the window we need in case we query computed styles + * @param aStyleType [IN] SPECIFIED_STYLE_TYPE to query the specified style values + * COMPUTED_STYLE_TYPE to query the computed style values */ nsresult GetCSSInlinePropertyBase(nsINode* aNode, nsIAtom* aProperty, - nsAString& aValue, StyleType aStyleType); + nsAString& aValue, nsIDOMWindow* aWindow, + PRUint8 aStyleType); nsresult GetCSSInlinePropertyBase(nsIDOMNode* aNode, nsIAtom* aProperty, - nsAString& aValue, StyleType aStyleType); + nsAString& aValue, nsIDOMWindow* aWindow, + PRUint8 aStyleType); private: diff --git a/editor/libeditor/html/nsHTMLEditRules.cpp b/editor/libeditor/html/nsHTMLEditRules.cpp index a867b1ded840..d81b24bcb9ab 100644 --- a/editor/libeditor/html/nsHTMLEditRules.cpp +++ b/editor/libeditor/html/nsHTMLEditRules.cpp @@ -836,7 +836,7 @@ nsHTMLEditRules::GetAlignment(bool *aMixed, nsIHTMLEditor::EAlignment *aAlign) // let's get the value(s) of text-align or margin-left/margin-right mHTMLEditor->mHTMLCSSUtils->GetCSSEquivalentToHTMLInlineStyleSet( blockParentContent, dummyProperty, &typeAttrName, value, - nsHTMLCSSUtils::eComputed); + COMPUTED_STYLE_TYPE); if (value.EqualsLiteral("center") || value.EqualsLiteral("-moz-center") || value.EqualsLiteral("auto auto")) @@ -2834,8 +2834,10 @@ nsHTMLEditRules::DeleteNonTableElements(nsINode* aNode) return mHTMLEditor->DeleteNode(aNode->AsDOMNode()); } - for (PRInt32 i = aNode->GetChildCount() - 1; i >= 0; --i) { - nsresult rv = DeleteNonTableElements(aNode->GetChildAt(i)); + for (nsCOMPtr child = aNode->GetLastChild(); + child; + child = child->GetPreviousSibling()) { + nsresult rv = DeleteNonTableElements(child); NS_ENSURE_SUCCESS(rv, rv); } return NS_OK; @@ -7164,9 +7166,8 @@ nsHTMLEditRules::CacheInlineStyles(nsIDOMNode *aNode) } else { - mHTMLEditor->mHTMLCSSUtils->IsCSSEquivalentToHTMLInlineStyleSet(aNode, - mCachedStyles[j].tag, &(mCachedStyles[j].attr), isSet, outValue, - nsHTMLCSSUtils::eComputed); + mHTMLEditor->mHTMLCSSUtils->IsCSSEquivalentToHTMLInlineStyleSet(aNode, mCachedStyles[j].tag, &(mCachedStyles[j].attr), + isSet, outValue, COMPUTED_STYLE_TYPE); } if (isSet) { @@ -7212,7 +7213,7 @@ nsHTMLEditRules::ReapplyCachedStyles() // check computed style first in css case bAny = mHTMLEditor->mHTMLCSSUtils->IsCSSEquivalentToHTMLInlineStyleSet( selNode, mCachedStyles[i].tag, &(mCachedStyles[i].attr), curValue, - nsHTMLCSSUtils::eComputed); + COMPUTED_STYLE_TYPE); } if (!bAny) { // then check typeinstate and html style diff --git a/editor/libeditor/html/nsHTMLEditorStyle.cpp b/editor/libeditor/html/nsHTMLEditorStyle.cpp index 65f8b5e5c66c..d8ba72ab9f42 100644 --- a/editor/libeditor/html/nsHTMLEditorStyle.cpp +++ b/editor/libeditor/html/nsHTMLEditorStyle.cpp @@ -357,7 +357,7 @@ nsHTMLEditor::SetInlinePropertyOnTextNode( nsIDOMCharacterData *aTextNode, nsAutoString value(*aValue); mHTMLCSSUtils->IsCSSEquivalentToHTMLInlineStyleSet(node, aProperty, aAttribute, bHasProp, value, - nsHTMLCSSUtils::eComputed); + COMPUTED_STYLE_TYPE); } else { IsTextPropertySetByContent(node, aProperty, aAttribute, aValue, bHasProp); } @@ -463,7 +463,7 @@ nsHTMLEditor::SetInlinePropertyOnNodeImpl(nsIContent* aNode, if (mHTMLCSSUtils->IsCSSEditableProperty(aNode, aProperty, aAttribute, aValue)) { if (mHTMLCSSUtils->IsCSSEquivalentToHTMLInlineStyleSet( - aNode, aProperty, aAttribute, *aValue, nsHTMLCSSUtils::eComputed)) { + aNode, aProperty, aAttribute, *aValue, COMPUTED_STYLE_TYPE)) { return NS_OK; } } else if (IsTextPropertySetByContent(aNode, aProperty, @@ -649,8 +649,9 @@ nsresult nsHTMLEditor::SplitStyleAbovePoint(nsCOMPtr *aNode, // the HTML style defined by aProperty/aAttribute has a CSS equivalence // in this implementation for the node tmp; let's check if it carries those css styles nsAutoString firstValue; - mHTMLCSSUtils->IsCSSEquivalentToHTMLInlineStyleSet(tmp, aProperty, - aAttribute, isSet, firstValue, nsHTMLCSSUtils::eSpecified); + mHTMLCSSUtils->IsCSSEquivalentToHTMLInlineStyleSet(tmp, aProperty, aAttribute, + isSet, firstValue, + SPECIFIED_STYLE_TYPE); } if ( (aProperty && NodeIsType(tmp, aProperty)) || // node is the correct inline prop (aProperty == nsEditProperty::href && nsHTMLEditUtils::IsLink(tmp)) || @@ -860,8 +861,9 @@ nsresult nsHTMLEditor::RemoveStyleInside(nsIDOMNode *aNode, // css styles nsAutoString propertyValue; bool isSet; - mHTMLCSSUtils->IsCSSEquivalentToHTMLInlineStyleSet(aNode, aProperty, - aAttribute, isSet, propertyValue, nsHTMLCSSUtils::eSpecified); + mHTMLCSSUtils->IsCSSEquivalentToHTMLInlineStyleSet(aNode, aProperty, aAttribute, + isSet, propertyValue, + SPECIFIED_STYLE_TYPE); if (isSet) { // yes, tmp has the corresponding css declarations in its style attribute // let's remove them @@ -1151,7 +1153,7 @@ nsHTMLEditor::GetInlinePropertyBase(nsIAtom *aProperty, aAttribute)) { mHTMLCSSUtils->IsCSSEquivalentToHTMLInlineStyleSet( collapsedNode, aProperty, aAttribute, isSet, tOutString, - nsHTMLCSSUtils::eComputed); + COMPUTED_STYLE_TYPE); if (outValue) { outValue->Assign(tOutString); } @@ -1243,8 +1245,9 @@ nsHTMLEditor::GetInlinePropertyBase(nsIAtom *aProperty, if (aValue) { firstValue.Assign(*aValue); } - mHTMLCSSUtils->IsCSSEquivalentToHTMLInlineStyleSet(node, aProperty, - aAttribute, isSet, firstValue, nsHTMLCSSUtils::eComputed); + mHTMLCSSUtils->IsCSSEquivalentToHTMLInlineStyleSet(node, aProperty, aAttribute, + isSet, firstValue, + COMPUTED_STYLE_TYPE); } else { IsTextPropertySetByContent(node, aProperty, aAttribute, aValue, isSet, &firstValue); @@ -1265,8 +1268,9 @@ nsHTMLEditor::GetInlinePropertyBase(nsIAtom *aProperty, if (aValue) { theValue.Assign(*aValue); } - mHTMLCSSUtils->IsCSSEquivalentToHTMLInlineStyleSet(node, aProperty, - aAttribute, isSet, theValue, nsHTMLCSSUtils::eComputed); + mHTMLCSSUtils->IsCSSEquivalentToHTMLInlineStyleSet(node, aProperty, aAttribute, + isSet, theValue, + COMPUTED_STYLE_TYPE); } else { IsTextPropertySetByContent(node, aProperty, aAttribute, aValue, isSet, &theValue); @@ -1431,8 +1435,11 @@ nsresult nsHTMLEditor::RemoveInlinePropertyImpl(nsIAtom *aProperty, const nsAStr nsAutoString cssValue; bool isSet = false; mHTMLCSSUtils->IsCSSEquivalentToHTMLInlineStyleSet(startNode, - aProperty, aAttribute, isSet , cssValue, - nsHTMLCSSUtils::eComputed); + aProperty, + aAttribute, + isSet , + cssValue, + COMPUTED_STYLE_TYPE); if (isSet) { // startNode's computed style indicates the CSS equivalence to the HTML style to // remove is applied; but we found no element in the ancestors of startNode @@ -1488,8 +1495,12 @@ nsresult nsHTMLEditor::RemoveInlinePropertyImpl(nsIAtom *aProperty, const nsAStr // in this implementation for node nsAutoString cssValue; bool isSet = false; - mHTMLCSSUtils->IsCSSEquivalentToHTMLInlineStyleSet(node, aProperty, - aAttribute, isSet , cssValue, nsHTMLCSSUtils::eComputed); + mHTMLCSSUtils->IsCSSEquivalentToHTMLInlineStyleSet(node, + aProperty, + aAttribute, + isSet , + cssValue, + COMPUTED_STYLE_TYPE); if (isSet) { // startNode's computed style indicates the CSS equivalence to the HTML style to // remove is applied; but we found no element in the ancestors of startNode diff --git a/layout/style/nsComputedDOMStyle.cpp b/layout/style/nsComputedDOMStyle.cpp index fd6a99cef3fa..e3d61501e677 100644 --- a/layout/style/nsComputedDOMStyle.cpp +++ b/layout/style/nsComputedDOMStyle.cpp @@ -60,9 +60,10 @@ using namespace mozilla::dom; static nsComputedDOMStyle *sCachedComputedDOMStyle; -already_AddRefed -NS_NewComputedDOMStyle(dom::Element* aElement, const nsAString& aPseudoElt, - nsIPresShell* aPresShell) +nsresult +NS_NewComputedDOMStyle(nsIDOMElement *aElement, const nsAString &aPseudoElt, + nsIPresShell *aPresShell, + nsComputedDOMStyle **aComputedStyle) { nsRefPtr computedStyle; if (sCachedComputedDOMStyle) { @@ -70,17 +71,23 @@ NS_NewComputedDOMStyle(dom::Element* aElement, const nsAString& aPseudoElt, // But before we use it, re-initialize the object. // Oh yeah baby, placement new! - computedStyle = new (sCachedComputedDOMStyle) - nsComputedDOMStyle(aElement, aPseudoElt, aPresShell); + computedStyle = new (sCachedComputedDOMStyle) nsComputedDOMStyle(); sCachedComputedDOMStyle = nsnull; } else { // No nsComputedDOMStyle cached, create a new one. - computedStyle = new nsComputedDOMStyle(aElement, aPseudoElt, aPresShell); + computedStyle = new nsComputedDOMStyle(); + NS_ENSURE_TRUE(computedStyle, NS_ERROR_OUT_OF_MEMORY); } - return computedStyle.forget(); + nsresult rv = computedStyle->Init(aElement, aPseudoElt, aPresShell); + NS_ENSURE_SUCCESS(rv, rv); + + *aComputedStyle = nsnull; + computedStyle.swap(*aComputedStyle); + + return NS_OK; } static nsIFrame* @@ -91,46 +98,11 @@ GetContainingBlockFor(nsIFrame* aFrame) { return aFrame->GetContainingBlock(); } -nsComputedDOMStyle::nsComputedDOMStyle(dom::Element* aElement, - const nsAString& aPseudoElt, - nsIPresShell* aPresShell) +nsComputedDOMStyle::nsComputedDOMStyle() : mDocumentWeak(nsnull), mOuterFrame(nsnull), mInnerFrame(nsnull), mPresShell(nsnull), mExposeVisitedStyle(false) { - MOZ_ASSERT(aElement && aPresShell); - - mDocumentWeak = do_GetWeakReference(aPresShell->GetDocument()); - - mContent = aElement; - - if (!DOMStringIsNull(aPseudoElt) && !aPseudoElt.IsEmpty() && - aPseudoElt.First() == PRUnichar(':')) { - // deal with two-colon forms of aPseudoElt - nsAString::const_iterator start, end; - aPseudoElt.BeginReading(start); - aPseudoElt.EndReading(end); - NS_ASSERTION(start != end, "aPseudoElt is not empty!"); - ++start; - bool haveTwoColons = true; - if (start == end || *start != PRUnichar(':')) { - --start; - haveTwoColons = false; - } - mPseudo = do_GetAtom(Substring(start, end)); - MOZ_ASSERT(mPseudo); - - // There aren't any non-CSS2 pseudo-elements with a single ':' - if (!haveTwoColons && - !nsCSSPseudoElements::IsCSS2PseudoElement(mPseudo)) { - // XXXbz I'd really rather we threw an exception or something, but - // the DOM spec sucks. - mPseudo = nsnull; - } - } - - nsPresContext *presCtx = aPresShell->GetPresContext(); - MOZ_ASSERT(presCtx); } @@ -196,6 +168,54 @@ NS_IMPL_CYCLE_COLLECTING_RELEASE_WITH_DESTROY(nsComputedDOMStyle, doDestroyComputedDOMStyle(this)) +NS_IMETHODIMP +nsComputedDOMStyle::Init(nsIDOMElement *aElement, + const nsAString& aPseudoElt, + nsIPresShell *aPresShell) +{ + NS_ENSURE_ARG_POINTER(aElement); + NS_ENSURE_ARG_POINTER(aPresShell); + + mDocumentWeak = do_GetWeakReference(aPresShell->GetDocument()); + + mContent = do_QueryInterface(aElement); + if (!mContent) { + // This should not happen, all our elements support nsIContent! + + return NS_ERROR_FAILURE; + } + + if (!DOMStringIsNull(aPseudoElt) && !aPseudoElt.IsEmpty() && + aPseudoElt.First() == PRUnichar(':')) { + // deal with two-colon forms of aPseudoElt + nsAString::const_iterator start, end; + aPseudoElt.BeginReading(start); + aPseudoElt.EndReading(end); + NS_ASSERTION(start != end, "aPseudoElt is not empty!"); + ++start; + bool haveTwoColons = true; + if (start == end || *start != PRUnichar(':')) { + --start; + haveTwoColons = false; + } + mPseudo = do_GetAtom(Substring(start, end)); + NS_ENSURE_TRUE(mPseudo, NS_ERROR_OUT_OF_MEMORY); + + // There aren't any non-CSS2 pseudo-elements with a single ':' + if (!haveTwoColons && + !nsCSSPseudoElements::IsCSS2PseudoElement(mPseudo)) { + // XXXbz I'd really rather we threw an exception or something, but + // the DOM spec sucks. + mPseudo = nsnull; + } + } + + nsPresContext *presCtx = aPresShell->GetPresContext(); + NS_ENSURE_TRUE(presCtx, NS_ERROR_FAILURE); + + return NS_OK; +} + NS_IMETHODIMP nsComputedDOMStyle::GetPropertyValue(const nsCSSProperty aPropID, nsAString& aValue) diff --git a/layout/style/nsComputedDOMStyle.h b/layout/style/nsComputedDOMStyle.h index adf0154e67be..947eac998d8f 100644 --- a/layout/style/nsComputedDOMStyle.h +++ b/layout/style/nsComputedDOMStyle.h @@ -32,13 +32,15 @@ public: NS_DECL_CYCLE_COLLECTION_SKIPPABLE_CLASS_AMBIGUOUS(nsComputedDOMStyle, nsICSSDeclaration) + NS_IMETHOD Init(nsIDOMElement *aElement, + const nsAString& aPseudoElt, + nsIPresShell *aPresShell); + NS_DECL_NSICSSDECLARATION NS_DECL_NSIDOMCSSSTYLEDECLARATION - nsComputedDOMStyle(mozilla::dom::Element* aElement, - const nsAString& aPseudoElt, - nsIPresShell* aPresShell); + nsComputedDOMStyle(); virtual ~nsComputedDOMStyle(); static void Shutdown(); @@ -509,10 +511,10 @@ private: #endif }; -already_AddRefed -NS_NewComputedDOMStyle(mozilla::dom::Element* aElement, - const nsAString& aPseudoElt, - nsIPresShell* aPresShell); +nsresult +NS_NewComputedDOMStyle(nsIDOMElement *aElement, const nsAString &aPseudoElt, + nsIPresShell *aPresShell, + nsComputedDOMStyle **aComputedStyle); #endif /* nsComputedDOMStyle_h__ */