Bug 757371 part 1 - Clean up nsHTMLEditRules::ReapplyCachedStyles; r=ehsan

This commit is contained in:
Aryeh Gregor committed 2012-05-22 13:15:09 +03:00
1 parent fca373b659
commit df79ea3ea8
4 files changed
+70 -30

No files matched your search

+23
View File
@@ -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,
+9 -1
View File
@@ -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,
+37 -28
View File
@@ -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
nsCOMPtr<nsISelection>selection;
nsresult res = mHTMLEditor->GetSelection(getter_AddRefs(selection));
NS_ENSURE_SUCCESS(res, res);
nsCOMPtr<nsIDOMNode> 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<nsTypedSelection> selection = mHTMLEditor->GetTypedSelection();
MOZ_ASSERT(selection);
if (!selection->GetRangeCount()) {
// Nothing to do
return NS_OK;
}
nsCOMPtr<nsIContent> 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;
}
+1 -1
View File
@@ -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);