mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-26 04:09:50 +00:00
Bug 833889 - Part 1. Remove CSS properties even if it is default value. r=masayuki
When selected nodes are <span style="font-weight: normal;">A</span>, toggle bold inserts new span element into parent node like <span style="font-weight: bold;"><span style="font-weight: normal;">A</span><span>. So bold isn't applied correctly. IsCSSEquivalentToHTMLInlineStyleSet might return false even if style is applied. Because it returns true that style isn't default value. Since "font-weight: normal" is default property, it isn't removed. So when style is already applied even if it is default value, we should remove it. MozReview-Commit-ID: LgImkHRp9Ff --HG-- extra : rebase_source : dd4d894495754a81abaf5a2aede1132056920beb extra : histedit_source : 72d196cd9f90296eb00b97c1538704c714cc871c
This commit is contained in:
parent
4e078cff7a
commit
d2b6ed15ad
@ -1243,6 +1243,44 @@ CSSEditUtils::IsCSSEquivalentToHTMLInlineStyleSet(
|
||||
return isSet;
|
||||
}
|
||||
|
||||
bool
|
||||
CSSEditUtils::HaveCSSEquivalentStyles(
|
||||
nsINode& aNode,
|
||||
nsIAtom* aHTMLProperty,
|
||||
nsIAtom* aHTMLAttribute,
|
||||
StyleType aStyleType)
|
||||
{
|
||||
nsAutoString valueString;
|
||||
nsCOMPtr<nsINode> node = &aNode;
|
||||
do {
|
||||
// get the value of the CSS equivalent styles
|
||||
nsresult rv =
|
||||
GetCSSEquivalentToHTMLInlineStyleSet(node, aHTMLProperty, aHTMLAttribute,
|
||||
valueString, aStyleType);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!valueString.IsEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (nsGkAtoms::u != aHTMLProperty && nsGkAtoms::strike != aHTMLProperty) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// unfortunately, the value of the text-decoration property is not
|
||||
// inherited.
|
||||
// that means that we have to look at ancestors of node to see if they
|
||||
// are underlined
|
||||
|
||||
// set to null if it's not a dom element
|
||||
node = node->GetParentElement();
|
||||
} while (node);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
CSSEditUtils::SetCSSEnabled(bool aIsCSSPrefChecked)
|
||||
{
|
||||
|
@ -213,7 +213,7 @@ public:
|
||||
* values (out).
|
||||
* @param aStyleType [IN] eSpecified or eComputed.
|
||||
* @return A boolean being true if the css properties are
|
||||
* set.
|
||||
* not same as initial value.
|
||||
*/
|
||||
bool IsCSSEquivalentToHTMLInlineStyleSet(nsINode* aContent,
|
||||
nsIAtom* aProperty,
|
||||
@ -239,6 +239,29 @@ public:
|
||||
nsAString& aValue,
|
||||
StyleType aStyleType);
|
||||
|
||||
/**
|
||||
* This is a kind of IsCSSEquivalentToHTMLInlineStyleSet.
|
||||
* IsCSSEquivalentToHTMLInlineStyleSet returns whether the properties
|
||||
* aren't same as initial value. But this method returns whether the
|
||||
* properties aren't set.
|
||||
* If node is <span style="font-weight: normal"/>,
|
||||
* - IsCSSEquivalentToHTMLInlineStyleSet returns false.
|
||||
* - HaveCSSEquivalentStyles returns true.
|
||||
*
|
||||
* @param aNode [IN] A DOM node.
|
||||
* @param aHTMLProperty [IN] An atom containing an HTML property.
|
||||
* @param aAttribute [IN] An atom to an attribute name or nullptr
|
||||
* if irrelevant.
|
||||
* @param aStyleType [IN] eSpecified or eComputed.
|
||||
* @return A boolean being true if the css properties are
|
||||
* not set.
|
||||
*/
|
||||
|
||||
bool HaveCSSEquivalentStyles(nsINode& aNode,
|
||||
nsIAtom* aProperty,
|
||||
nsIAtom* aAttribute,
|
||||
StyleType 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.
|
||||
|
@ -778,22 +778,25 @@ HTMLEditor::RemoveStyleInside(nsIContent& aNode,
|
||||
// the HTML style defined by aProperty/aAttribute has a CSS equivalence in
|
||||
// this implementation for the node aNode; let's check if it carries those
|
||||
// css styles
|
||||
nsCOMPtr<nsIAtom> attribute =
|
||||
aAttribute ? NS_Atomize(*aAttribute) : nullptr;
|
||||
nsAutoString propertyValue;
|
||||
bool isSet = mCSSEditUtils->IsCSSEquivalentToHTMLInlineStyleSet(&aNode,
|
||||
aProperty, attribute, propertyValue, CSSEditUtils::eSpecified);
|
||||
if (isSet && aNode.IsElement()) {
|
||||
// yes, tmp has the corresponding css declarations in its style attribute
|
||||
// let's remove them
|
||||
mCSSEditUtils->RemoveCSSEquivalentToHTMLStyle(aNode.AsElement(),
|
||||
aProperty,
|
||||
attribute,
|
||||
&propertyValue,
|
||||
false);
|
||||
// remove the node if it is a span or font, if its style attribute is
|
||||
// empty or absent, and if it does not have a class nor an id
|
||||
RemoveElementIfNoStyleOrIdOrClass(*aNode.AsElement());
|
||||
if (aNode.IsElement()) {
|
||||
nsCOMPtr<nsIAtom> attribute =
|
||||
aAttribute ? NS_Atomize(*aAttribute) : nullptr;
|
||||
bool hasAttribute =
|
||||
mCSSEditUtils->HaveCSSEquivalentStyles(
|
||||
aNode, aProperty, attribute, CSSEditUtils::eSpecified);
|
||||
if (hasAttribute) {
|
||||
// yes, tmp has the corresponding css declarations in its style
|
||||
// attribute
|
||||
// let's remove them
|
||||
mCSSEditUtils->RemoveCSSEquivalentToHTMLStyle(aNode.AsElement(),
|
||||
aProperty,
|
||||
attribute,
|
||||
nullptr,
|
||||
false);
|
||||
// remove the node if it is a span or font, if its style attribute is
|
||||
// empty or absent, and if it does not have a class nor an id
|
||||
RemoveElementIfNoStyleOrIdOrClass(*aNode.AsElement());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user