diff --git a/editor/libeditor/html/nsHTMLCSSUtils.cpp b/editor/libeditor/html/nsHTMLCSSUtils.cpp index f291137f9dda..3e17cfa181b4 100644 --- a/editor/libeditor/html/nsHTMLCSSUtils.cpp +++ b/editor/libeditor/html/nsHTMLCSSUtils.cpp @@ -1067,6 +1067,29 @@ nsHTMLCSSUtils::GetCSSEquivalentToHTMLInlineStyleSet(nsINode* aNode, // style equivalent to the HTML style aHTMLProperty/aHTMLAttribute/valueString? // The value of aStyleType controls the styles we retrieve: specified or // computed. The return value aIsSet is true if the CSS styles are set. +// +// The nsIContent variant returns aIsSet instead of using an out parameter, and +// does not modify aValue. +bool +nsHTMLCSSUtils::IsCSSEquivalentToHTMLInlineStyleSet(nsIContent* aContent, + nsIAtom* aProperty, + const nsAString* aAttribute, + const nsAString& aValue, + 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(), + aProperty, aAttribute, + isSet, value, aStyleType); + NS_ASSERTION(NS_SUCCEEDED(res), "IsCSSEquivalentToHTMLInlineStyleSet failed"); + NS_ENSURE_SUCCESS(res, false); + return isSet; +} + nsresult nsHTMLCSSUtils::IsCSSEquivalentToHTMLInlineStyleSet(nsIDOMNode *aNode, nsIAtom *aHTMLProperty, diff --git a/editor/libeditor/html/nsHTMLCSSUtils.h b/editor/libeditor/html/nsHTMLCSSUtils.h index 42d5acea89f2..97f6ce6a5107 100644 --- a/editor/libeditor/html/nsHTMLCSSUtils.h +++ b/editor/libeditor/html/nsHTMLCSSUtils.h @@ -185,8 +185,16 @@ public: * @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] SPECIFIED_STYLE_TYPE to query the specified style values - COMPUTED_STYLE_TYPE to query the computed style values + * COMPUTED_STYLE_TYPE to query the computed style values + * + * The nsIContent variant returns aIsSet instead of using an out parameter. */ + bool IsCSSEquivalentToHTMLInlineStyleSet(nsIContent* aContent, + nsIAtom* aProperty, + const nsAString* aAttribute, + const nsAString& aValue, + PRUint8 aStyleType); + nsresult IsCSSEquivalentToHTMLInlineStyleSet(nsIDOMNode * aNode, nsIAtom * aHTMLProperty, const nsAString * aAttribute, diff --git a/editor/libeditor/html/nsHTMLEditRules.cpp b/editor/libeditor/html/nsHTMLEditRules.cpp index ea350c48f806..6a5b0dc0699d 100644 --- a/editor/libeditor/html/nsHTMLEditRules.cpp +++ b/editor/libeditor/html/nsHTMLEditRules.cpp @@ -7212,51 +7212,60 @@ nsHTMLEditRules::CacheInlineStyles(nsIDOMNode *aNode) } -nsresult +nsresult nsHTMLEditRules::ReapplyCachedStyles() { - // The idea here is to examine our cached list of styles - // and see if any have been removed. If so, add typeinstate - // for them, so that they will be reinserted when new - // content is added. + // The idea here is to examine our cached list of styles and see if any have + // been removed. If so, add typeinstate for them, so that they will be + // reinserted when new content is added. // remember if we are in css mode bool useCSS = mHTMLEditor->IsCSSEnabled(); - // get selection point - nsCOMPtrselection; - nsresult res = mHTMLEditor->GetSelection(getter_AddRefs(selection)); - NS_ENSURE_SUCCESS(res, res); - nsCOMPtr selNode; - PRInt32 selOffset; - res = mHTMLEditor->GetStartNodeAndOffset(selection, getter_AddRefs(selNode), &selOffset); - NS_ENSURE_SUCCESS(res, res); + // get selection point; if it doesn't exist, we have nothing to do + nsRefPtr selection = mHTMLEditor->GetTypedSelection(); + MOZ_ASSERT(selection); + if (!selection->GetRangeCount()) { + // Nothing to do + return NS_OK; + } + nsCOMPtr selNode = + do_QueryInterface(selection->GetRangeAt(0)->GetStartParent()); + if (!selNode) { + // Nothing to do + return NS_OK; + } - for (PRInt32 j = 0; j < SIZE_STYLE_TABLE; ++j) - { - if (mCachedStyles[j].mPresent) - { + for (PRInt32 i = 0; i < SIZE_STYLE_TABLE; ++i) { + if (mCachedStyles[i].mPresent) { bool bFirst, bAny, bAll; bFirst = bAny = bAll = false; - + nsAutoString curValue; - if (useCSS) // check computed style first in css case - { - mHTMLEditor->mHTMLCSSUtils->IsCSSEquivalentToHTMLInlineStyleSet(selNode, mCachedStyles[j].tag, &(mCachedStyles[j].attr), - bAny, curValue, COMPUTED_STYLE_TYPE); + if (useCSS) { + // check computed style first in css case + bAny = mHTMLEditor->mHTMLCSSUtils->IsCSSEquivalentToHTMLInlineStyleSet( + selNode, mCachedStyles[i].tag, &(mCachedStyles[i].attr), curValue, + COMPUTED_STYLE_TYPE); } - if (!bAny) // then check typeinstate and html style - { - res = mHTMLEditor->GetInlinePropertyBase(mCachedStyles[j].tag, &(mCachedStyles[j].attr), &(mCachedStyles[j].value), - &bFirst, &bAny, &bAll, &curValue, false); + if (!bAny) { + // then check typeinstate and html style + nsresult res = mHTMLEditor->GetInlinePropertyBase(mCachedStyles[i].tag, + &(mCachedStyles[i].attr), + &(mCachedStyles[i].value), + &bFirst, &bAny, &bAll, + &curValue, false); NS_ENSURE_SUCCESS(res, res); } - // this style has disappeared through deletion. Add it onto our typeinstate: + // this style has disappeared through deletion. Add to our typeinstate: if (!bAny || IsStyleCachePreservingAction(mTheAction)) { - mHTMLEditor->mTypeInState->SetProp(mCachedStyles[j].tag, mCachedStyles[j].attr, mCachedStyles[j].value); + mHTMLEditor->mTypeInState->SetProp(mCachedStyles[i].tag, + mCachedStyles[i].attr, + mCachedStyles[i].value); } } } + return NS_OK; } diff --git a/editor/libeditor/html/nsHTMLEditRules.h b/editor/libeditor/html/nsHTMLEditRules.h index 236ad7ae7806..72a87d63800e 100644 --- a/editor/libeditor/html/nsHTMLEditRules.h +++ b/editor/libeditor/html/nsHTMLEditRules.h @@ -246,7 +246,7 @@ protected: nsresult PopListItem(nsIDOMNode *aListItem, bool *aOutOfList); nsresult RemoveListStructure(nsIDOMNode *aList); nsresult CacheInlineStyles(nsIDOMNode *aNode); - nsresult ReapplyCachedStyles(); + nsresult ReapplyCachedStyles(); nsresult ClearCachedStyles(); nsresult AdjustSpecialBreaks(bool aSafeToAskFrames = false); nsresult AdjustWhitespace(nsISelection *aSelection);