From 2f071d5ceb615597be5a0959b1337bf5b36a2de9 Mon Sep 17 00:00:00 2001 From: "dbaron%dbaron.org" Date: Sat, 13 Sep 2003 19:18:52 +0000 Subject: [PATCH] Don't create style rule DOM wrappers for inline style, since we are not supposed to, and ours crash when used on inline style. b=218222 r+sr=bzbarsky git-svn-id: svn://10.0.0.236/trunk@146845 18797224-902f-48f8-a5cc-f745e15eee43 --- .../html/content/src/nsGenericHTMLElement.cpp | 8 +++++ .../content/html/style/src/nsCSSStyleRule.cpp | 6 ++++ mozilla/content/html/style/src/nsICSSRule.h | 2 ++ mozilla/editor/idl/nsIHTMLEditor.idl | 7 ---- .../editor/libeditor/html/nsHTMLEditor.cpp | 36 ------------------- .../ui/dialogs/content/EdAECSSAttributes.js | 13 ++----- .../inspector/base/src/inDOMUtils.cpp | 3 +- mozilla/layout/style/nsCSSStyleRule.cpp | 6 ++++ mozilla/layout/style/nsICSSRule.h | 2 ++ 9 files changed, 28 insertions(+), 55 deletions(-) diff --git a/mozilla/content/html/content/src/nsGenericHTMLElement.cpp b/mozilla/content/html/content/src/nsGenericHTMLElement.cpp index e3a9436e001..c706b6de40f 100644 --- a/mozilla/content/html/content/src/nsGenericHTMLElement.cpp +++ b/mozilla/content/html/content/src/nsGenericHTMLElement.cpp @@ -504,6 +504,9 @@ nsGenericHTMLElement::GetStyle(nsIDOMCSSStyleDeclaration** aStyle) nsDOMSlots *slots = GetDOMSlots(); if (!slots->mStyle) { + // Just in case... + ReparseStyleAttribute(); + nsresult rv; if (!gCSSOMFactory) { rv = CallGetService(kCSSOMFactoryCID, &gCSSOMFactory); @@ -2307,6 +2310,11 @@ nsGenericHTMLElement::GetInlineStyleRule(nsIStyleRule** aStyleRule) if (mAttributes) { nsHTMLValue value; if (NS_CONTENT_ATTR_HAS_VALUE == mAttributes->GetAttribute(nsHTMLAtoms::style, value)) { + if (eHTMLUnit_String == value.GetUnit()) { + ReparseStyleAttribute(); + mAttributes->GetAttribute(nsHTMLAtoms::style, value); + // hopefully value.GetUnit() is now eHTMLUnit_ISupports + } if (eHTMLUnit_ISupports == value.GetUnit()) { nsCOMPtr supports = value.GetISupportsValue(); if (supports) diff --git a/mozilla/content/html/style/src/nsCSSStyleRule.cpp b/mozilla/content/html/style/src/nsCSSStyleRule.cpp index a36e60ba0e6..bfb0d500870 100644 --- a/mozilla/content/html/style/src/nsCSSStyleRule.cpp +++ b/mozilla/content/html/style/src/nsCSSStyleRule.cpp @@ -1407,6 +1407,12 @@ CSSStyleRuleImpl::Clone(nsICSSRule*& aClone) const NS_IMETHODIMP CSSStyleRuleImpl::GetDOMRule(nsIDOMCSSRule** aDOMRule) { + if (!mSheet) { + // inline style rules aren't supposed to have a DOM rule object, only + // a declaration. + *aDOMRule = nsnull; + return NS_OK; + } if (!mDOMRule) { mDOMRule = new DOMCSSStyleRuleImpl(this); if (!mDOMRule) { diff --git a/mozilla/content/html/style/src/nsICSSRule.h b/mozilla/content/html/style/src/nsICSSRule.h index 037d0fef34b..7c658ffca2e 100644 --- a/mozilla/content/html/style/src/nsICSSRule.h +++ b/mozilla/content/html/style/src/nsICSSRule.h @@ -71,6 +71,8 @@ public: NS_IMETHOD Clone(nsICSSRule*& aClone) const = 0; + // Note that this returns null for inline style rules since they aren't + // supposed to have a DOM rule representation (and our code wouldn't work). NS_IMETHOD GetDOMRule(nsIDOMCSSRule** aDOMRule) = 0; }; diff --git a/mozilla/editor/idl/nsIHTMLEditor.idl b/mozilla/editor/idl/nsIHTMLEditor.idl index e650277bea0..b4da1df2dd7 100644 --- a/mozilla/editor/idl/nsIHTMLEditor.idl +++ b/mozilla/editor/idl/nsIHTMLEditor.idl @@ -568,13 +568,6 @@ interface nsIHTMLEditor : nsISupports */ void removeInsertionListener(in nsIContentFilter inFilter); - /** - * parse a string containing CSS declarations and returns a DOM CSSStyleRule - * @return a DOM CSSStyleRule - * @param aString [IN] a string containing CSS declarations - */ - nsIDOMCSSStyleRule parseStyleAttrIntoCSSRule(in AString aString); - /** * Returns an anonymous nsDOMElement of type aTag, * child of aParentNode. If aIsCreatedHidden is true, the class diff --git a/mozilla/editor/libeditor/html/nsHTMLEditor.cpp b/mozilla/editor/libeditor/html/nsHTMLEditor.cpp index c20965fc979..09afab646bb 100644 --- a/mozilla/editor/libeditor/html/nsHTMLEditor.cpp +++ b/mozilla/editor/libeditor/html/nsHTMLEditor.cpp @@ -54,8 +54,6 @@ #include "nsHTMLURIRefObject.h" -#include "nsICSSParser.h" -#include "nsIDOMCSSStyleRule.h" #include "nsIDOMText.h" #include "nsITextContent.h" #include "nsIDOMNodeList.h" @@ -5927,40 +5925,6 @@ nsHTMLEditor::NodesSameType(nsIDOMNode *aNode1, nsIDOMNode *aNode2) return PR_FALSE; } -NS_IMETHODIMP -nsHTMLEditor::ParseStyleAttrIntoCSSRule(const nsAString& aString, - nsIDOMCSSStyleRule **_retval) -{ - nsCOMPtr domdoc; - nsEditor::GetDocument(getter_AddRefs(domdoc)); - if (!domdoc) - return NS_ERROR_UNEXPECTED; - - nsCOMPtr doc (do_QueryInterface(domdoc)); - if (!doc) - return NS_ERROR_UNEXPECTED; - nsCOMPtr docURL; - doc->GetBaseURL(getter_AddRefs(docURL)); - nsCOMPtr css = do_CreateInstance("@mozilla.org/content/css-parser;1"); - NS_ASSERTION(css, "can't get a css parser"); - if (!css) return NS_ERROR_NULL_POINTER; - - nsCOMPtr mRule; - css->ParseStyleAttribute(aString, docURL, getter_AddRefs(mRule)); - nsCOMPtr styleRule = do_QueryInterface(mRule); - if (!styleRule) { - return NS_ERROR_UNEXPECTED; - } - - nsCOMPtr domRule; - styleRule->GetDOMRule(getter_AddRefs(domRule)); - if (!domRule) { - return NS_ERROR_UNEXPECTED; - } - - return CallQueryInterface(domRule, _retval); -} - NS_IMETHODIMP nsHTMLEditor::CopyLastEditableChildStyles(nsIDOMNode * aPreviousBlock, nsIDOMNode * aNewBlock, nsIDOMNode **aOutBrNode) diff --git a/mozilla/editor/ui/dialogs/content/EdAECSSAttributes.js b/mozilla/editor/ui/dialogs/content/EdAECSSAttributes.js index 9ad2ebb0781..5569ae36133 100644 --- a/mozilla/editor/ui/dialogs/content/EdAECSSAttributes.js +++ b/mozilla/editor/ui/dialogs/content/EdAECSSAttributes.js @@ -27,22 +27,13 @@ // build attribute list in tree form from element attributes function BuildCSSAttributeTable() { - // we can't trust DOM 2 ElementCSSInlineStyle because gElement can be - // outside of the document's tree - var styleAttr = gElement.getAttribute("style"); - var styleRule; - try { - var editor = GetCurrentEditor(); - styleRule = editor.parseStyleAttrIntoCSSRule(styleAttr); - } catch(ex) {} - - if (styleRule == undefined) + var style = gElement.style; + if (style == undefined) { dump("Inline styles undefined\n"); return; } - var style = styleRule.style; var declLength = style.length; if (declLength == undefined || declLength == 0) diff --git a/mozilla/extensions/inspector/base/src/inDOMUtils.cpp b/mozilla/extensions/inspector/base/src/inDOMUtils.cpp index 33415d85a71..a71a5e0a4a8 100644 --- a/mozilla/extensions/inspector/base/src/inDOMUtils.cpp +++ b/mozilla/extensions/inspector/base/src/inDOMUtils.cpp @@ -178,7 +178,8 @@ inDOMUtils::GetCSSStyleRules(nsIDOMElement *aElement, cssRule = do_QueryInterface(srule); if (cssRule) { cssRule->GetDOMRule(getter_AddRefs(domRule)); - rules->InsertElementAt(domRule, 0); + if (domRule) + rules->InsertElementAt(domRule, 0); } } diff --git a/mozilla/layout/style/nsCSSStyleRule.cpp b/mozilla/layout/style/nsCSSStyleRule.cpp index a36e60ba0e6..bfb0d500870 100644 --- a/mozilla/layout/style/nsCSSStyleRule.cpp +++ b/mozilla/layout/style/nsCSSStyleRule.cpp @@ -1407,6 +1407,12 @@ CSSStyleRuleImpl::Clone(nsICSSRule*& aClone) const NS_IMETHODIMP CSSStyleRuleImpl::GetDOMRule(nsIDOMCSSRule** aDOMRule) { + if (!mSheet) { + // inline style rules aren't supposed to have a DOM rule object, only + // a declaration. + *aDOMRule = nsnull; + return NS_OK; + } if (!mDOMRule) { mDOMRule = new DOMCSSStyleRuleImpl(this); if (!mDOMRule) { diff --git a/mozilla/layout/style/nsICSSRule.h b/mozilla/layout/style/nsICSSRule.h index 037d0fef34b..7c658ffca2e 100644 --- a/mozilla/layout/style/nsICSSRule.h +++ b/mozilla/layout/style/nsICSSRule.h @@ -71,6 +71,8 @@ public: NS_IMETHOD Clone(nsICSSRule*& aClone) const = 0; + // Note that this returns null for inline style rules since they aren't + // supposed to have a DOM rule representation (and our code wouldn't work). NS_IMETHOD GetDOMRule(nsIDOMCSSRule** aDOMRule) = 0; };