From 374693715eab720b40a4fcaacb8b58c8a7972e6d Mon Sep 17 00:00:00 2001 From: Ryan VanderMeulen Date: Wed, 6 Feb 2013 11:21:25 -0500 Subject: [PATCH] Backed out changeset 487d16b80087 (bug 812638) for mochitest orange. --- editor/libeditor/html/nsHTMLCSSUtils.cpp | 84 +++++++++++++++++-- editor/libeditor/html/nsHTMLCSSUtils.h | 13 ++- editor/libeditor/html/nsHTMLEditorStyle.cpp | 30 +++++-- .../lib/richtext/currentStatus.js | 5 -- .../lib/richtext2/currentStatus.js | 27 ------ .../libeditor/html/tests/test_bug480647.html | 35 +++++++- 6 files changed, 146 insertions(+), 48 deletions(-) diff --git a/editor/libeditor/html/nsHTMLCSSUtils.cpp b/editor/libeditor/html/nsHTMLCSSUtils.cpp index c044d4c731f5..2e08940b4668 100644 --- a/editor/libeditor/html/nsHTMLCSSUtils.cpp +++ b/editor/libeditor/html/nsHTMLCSSUtils.cpp @@ -183,6 +183,45 @@ void ProcessMarginRightValue(const nsAString * aInputString, nsAString & aOutput } } +static +void ProcessFontSizeValue(const nsAString* aInputString, nsAString& aOutputString, + const char* aDefaultValueString, + const char* aPrependString, const char* aAppendString) +{ + aOutputString.Truncate(); + if (aInputString) { + int32_t size = nsContentUtils::ParseLegacyFontSize(*aInputString); + switch (size) { + case 0: + // Didn't parse + return; + case 1: + aOutputString.AssignLiteral("x-small"); + return; + case 2: + aOutputString.AssignLiteral("small"); + return; + case 3: + aOutputString.AssignLiteral("medium"); + return; + case 4: + aOutputString.AssignLiteral("large"); + return; + case 5: + aOutputString.AssignLiteral("x-large"); + return; + case 6: + aOutputString.AssignLiteral("xx-large"); + return; + case 7: + // No corresponding CSS size + return; + default: + NS_NOTREACHED("Unexpected return value from ParseLegacyFontSize"); + } + } +} + const nsHTMLCSSUtils::CSSEquivTable boldEquivTable[] = { { nsHTMLCSSUtils::eCSSEditableProperty_font_weight, ProcessBValue, nullptr, nullptr, nullptr, true, false }, { nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 } @@ -218,6 +257,11 @@ const nsHTMLCSSUtils::CSSEquivTable fontFaceEquivTable[] = { { nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 } }; +const nsHTMLCSSUtils::CSSEquivTable fontSizeEquivTable[] = { + { nsHTMLCSSUtils::eCSSEditableProperty_font_size, ProcessFontSizeValue, nullptr, nullptr, nullptr, true, false }, + { nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 } +}; + const nsHTMLCSSUtils::CSSEquivTable bgcolorEquivTable[] = { { nsHTMLCSSUtils::eCSSEditableProperty_background_color, ProcessSameValue, nullptr, nullptr, nullptr, true, false }, { nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 } @@ -303,19 +347,21 @@ nsHTMLCSSUtils::~nsHTMLCSSUtils() bool nsHTMLCSSUtils::IsCSSEditableProperty(nsIDOMNode* aNode, nsIAtom* aProperty, - const nsAString* aAttribute) + const nsAString* aAttribute, + const nsAString* aValue) { NS_ASSERTION(aNode, "Shouldn't you pass aNode? - Bug 214025"); nsCOMPtr content = do_QueryInterface(aNode); NS_ENSURE_TRUE(content, false); - return IsCSSEditableProperty(content, aProperty, aAttribute); + return IsCSSEditableProperty(content, aProperty, aAttribute, aValue); } bool nsHTMLCSSUtils::IsCSSEditableProperty(nsIContent* aNode, nsIAtom* aProperty, - const nsAString* aAttribute) + const nsAString* aAttribute, + const nsAString* aValue) { MOZ_ASSERT(aNode); @@ -341,6 +387,16 @@ nsHTMLCSSUtils::IsCSSEditableProperty(nsIContent* aNode, return true; } + // FONT SIZE doesn't work if the value is 7 + if (nsEditProperty::font == aProperty && aAttribute && + aAttribute->EqualsLiteral("size")) { + if (!aValue || aValue->IsEmpty()) { + return true; + } + int32_t size = nsContentUtils::ParseLegacyFontSize(*aValue); + return size && size != 7; + } + // ALIGN attribute on elements supporting it if (aAttribute && (aAttribute->EqualsLiteral("align")) && (nsEditProperty::div == tagName @@ -852,6 +908,9 @@ nsHTMLCSSUtils::GenerateCSSDeclarationsFromHTMLStyle(dom::Element* aElement, } else if (nsEditProperty::font == aHTMLProperty && aAttribute->EqualsLiteral("face")) { equivTable = fontFaceEquivTable; + } else if (nsEditProperty::font == aHTMLProperty && + aAttribute->EqualsLiteral("size")) { + equivTable = fontSizeEquivTable; } else if (aAttribute->EqualsLiteral("bgcolor")) { equivTable = bgcolorEquivTable; } else if (aAttribute->EqualsLiteral("background")) { @@ -930,7 +989,8 @@ nsHTMLCSSUtils::SetCSSEquivalentToHTMLStyle(nsIDOMNode * aNode, { nsCOMPtr element = do_QueryInterface(aNode); *aCount = 0; - if (!element || !IsCSSEditableProperty(element, aHTMLProperty, aAttribute)) { + if (!element || !IsCSSEditableProperty(element, aHTMLProperty, + aAttribute, aValue)) { return NS_OK; } @@ -1006,7 +1066,8 @@ nsHTMLCSSUtils::GetCSSEquivalentToHTMLInlineStyleSet(nsINode* aNode, nsCOMPtr theElement = GetElementContainerOrSelf(aNode); NS_ENSURE_TRUE(theElement, NS_ERROR_NULL_POINTER); - if (!theElement || !IsCSSEditableProperty(theElement, aHTMLProperty, aAttribute)) { + if (!theElement || !IsCSSEditableProperty(theElement, aHTMLProperty, + aAttribute, &aValueString)) { return NS_OK; } @@ -1183,6 +1244,19 @@ nsHTMLCSSUtils::IsCSSEquivalentToHTMLInlineStyleSet(nsIDOMNode *aNode, !valueStringLower.EqualsLiteral("serif"); } return NS_OK; + } else if (nsEditProperty::font == aHTMLProperty && aHTMLAttribute && + aHTMLAttribute->EqualsLiteral("size")) { + if (htmlValueString.IsEmpty()) { + aIsSet = true; + } else { + int32_t size = nsContentUtils::ParseLegacyFontSize(htmlValueString); + aIsSet = (size == 1 && valueString.EqualsLiteral("x-small")) || + (size == 2 && valueString.EqualsLiteral("small")) || + (size == 3 && valueString.EqualsLiteral("medium")) || + (size == 4 && valueString.EqualsLiteral("large")) || + (size == 5 && valueString.EqualsLiteral("x-large")) || + (size == 6 && valueString.EqualsLiteral("xx-large")); + } } else if (aHTMLAttribute && aHTMLAttribute->EqualsLiteral("align")) { aIsSet = true; } else { diff --git a/editor/libeditor/html/nsHTMLCSSUtils.h b/editor/libeditor/html/nsHTMLCSSUtils.h index 7ce042c42606..a391d8b149a1 100644 --- a/editor/libeditor/html/nsHTMLCSSUtils.h +++ b/editor/libeditor/html/nsHTMLCSSUtils.h @@ -82,9 +82,18 @@ public: * @param aProperty [IN] an atom containing a HTML tag name * @param aAttribute [IN] a string containing the name of a HTML * attribute carried by the element above + * @param aValue [IN] an optional string containing the attribute's + * HTML value -- this matters for , + * since size=7 has no CSS equivalent. Make sure + * you pass the HTML value (e.g. "4"), not the + * CSS value (e.g. "large"). */ - bool IsCSSEditableProperty(nsIContent* aNode, nsIAtom* aProperty, const nsAString* aAttribute); - bool IsCSSEditableProperty(nsIDOMNode* aNode, nsIAtom* aProperty, const nsAString* aAttribute); + bool IsCSSEditableProperty(nsIContent* aNode, nsIAtom* aProperty, + const nsAString* aAttribute, + const nsAString* aValue = nullptr); + bool IsCSSEditableProperty(nsIDOMNode* aNode, nsIAtom* aProperty, + const nsAString* aAttribute, + const nsAString* aValue = nullptr); /** adds/remove a CSS declaration to the STYLE atrribute carried by a given element * diff --git a/editor/libeditor/html/nsHTMLEditorStyle.cpp b/editor/libeditor/html/nsHTMLEditorStyle.cpp index cd28228607e9..14f8776fc256 100644 --- a/editor/libeditor/html/nsHTMLEditorStyle.cpp +++ b/editor/libeditor/html/nsHTMLEditorStyle.cpp @@ -312,7 +312,8 @@ nsHTMLEditor::IsSimpleModifiableNode(nsIContent* aContent, // No luck so far. Now we check for a with a single style="" // attribute that sets only the style we're looking for, if this type of // style supports it - if (!mHTMLCSSUtils->IsCSSEditableProperty(element, aProperty, aAttribute) || + if (!mHTMLCSSUtils->IsCSSEditableProperty(element, aProperty, + aAttribute, aValue) || !element->IsHTML(nsGkAtoms::span) || element->GetAttrCount() != 1 || !element->HasAttr(kNameSpaceID_None, nsGkAtoms::style)) { return false; @@ -360,7 +361,8 @@ nsHTMLEditor::SetInlinePropertyOnTextNode( nsIDOMCharacterData *aTextNode, // don't need to do anything if property already set on node bool bHasProp; - if (mHTMLCSSUtils->IsCSSEditableProperty(node, aProperty, aAttribute)) { + if (mHTMLCSSUtils->IsCSSEditableProperty(node, aProperty, + aAttribute, aValue)) { // the HTML styles defined by aProperty/aAttribute has a CSS equivalence // in this implementation for node; let's check if it carries those css styles nsAutoString value(*aValue); @@ -469,7 +471,8 @@ nsHTMLEditor::SetInlinePropertyOnNodeImpl(nsIContent* aNode, } // don't need to do anything if property already set on node - if (mHTMLCSSUtils->IsCSSEditableProperty(aNode, aProperty, aAttribute)) { + if (mHTMLCSSUtils->IsCSSEditableProperty(aNode, aProperty, + aAttribute, aValue)) { if (mHTMLCSSUtils->IsCSSEquivalentToHTMLInlineStyleSet( aNode, aProperty, aAttribute, *aValue, nsHTMLCSSUtils::eComputed)) { return NS_OK; @@ -480,7 +483,8 @@ nsHTMLEditor::SetInlinePropertyOnNodeImpl(nsIContent* aNode, } bool useCSS = (IsCSSEnabled() && - mHTMLCSSUtils->IsCSSEditableProperty(aNode, aProperty, aAttribute)) || + mHTMLCSSUtils->IsCSSEditableProperty(aNode, aProperty, + aAttribute, aValue)) || // bgcolor is always done using CSS aAttribute->EqualsLiteral("bgcolor"); @@ -1153,7 +1157,11 @@ nsHTMLEditor::GetInlinePropertyBase(nsIAtom *aProperty, return NS_OK; } - if (mHTMLCSSUtils->IsCSSEditableProperty(collapsedNode, aProperty, aAttribute)) { + // Bug 747889: we don't support CSS for fontSize values + if ((aProperty != nsEditProperty::font || + !aAttribute->EqualsLiteral("size")) && + mHTMLCSSUtils->IsCSSEditableProperty(collapsedNode, aProperty, + aAttribute)) { mHTMLCSSUtils->IsCSSEquivalentToHTMLInlineStyleSet( collapsedNode, aProperty, aAttribute, isSet, tOutString, nsHTMLCSSUtils::eComputed); @@ -1237,7 +1245,11 @@ nsHTMLEditor::GetInlinePropertyBase(nsIAtom *aProperty, bool isSet = false; if (first) { - if (mHTMLCSSUtils->IsCSSEditableProperty(node, aProperty, aAttribute)){ + if (mHTMLCSSUtils->IsCSSEditableProperty(node, aProperty, + aAttribute) && + // Bug 747889: we don't support CSS for fontSize values + (aProperty != nsEditProperty::font || + !aAttribute->EqualsLiteral("size"))) { // the HTML styles defined by aProperty/aAttribute has a CSS // equivalence in this implementation for node; let's check if it // carries those css styles @@ -1256,7 +1268,11 @@ nsHTMLEditor::GetInlinePropertyBase(nsIAtom *aProperty, *outValue = firstValue; } } else { - if (mHTMLCSSUtils->IsCSSEditableProperty(node, aProperty, aAttribute)){ + if (mHTMLCSSUtils->IsCSSEditableProperty(node, aProperty, + aAttribute) && + // Bug 747889: we don't support CSS for fontSize values + (aProperty != nsEditProperty::font || + !aAttribute->EqualsLiteral("size"))) { // the HTML styles defined by aProperty/aAttribute has a CSS equivalence // in this implementation for node; let's check if it carries those css styles if (aValue) { diff --git a/editor/libeditor/html/tests/browserscope/lib/richtext/currentStatus.js b/editor/libeditor/html/tests/browserscope/lib/richtext/currentStatus.js index b30775d043d3..1db07455064e 100644 --- a/editor/libeditor/html/tests/browserscope/lib/richtext/currentStatus.js +++ b/editor/libeditor/html/tests/browserscope/lib/richtext/currentStatus.js @@ -19,7 +19,6 @@ var knownFailures = { }, 'a' : { 'createbookmark-0' : true, - 'fontsize-1' : true, 'subscript-1' : true, 'superscript-1' : true, }, @@ -35,10 +34,6 @@ var knownFailures = { 'fontsize-1' : true, 'fontsize-2' : true, }, - 'c': { - 'fontsize-1' : true, - 'fontsize-2' : true, - }, }; function isKnownFailure(type, test, param) { diff --git a/editor/libeditor/html/tests/browserscope/lib/richtext2/currentStatus.js b/editor/libeditor/html/tests/browserscope/lib/richtext2/currentStatus.js index 7dd092c52d0e..3fa3bedadc12 100644 --- a/editor/libeditor/html/tests/browserscope/lib/richtext2/currentStatus.js +++ b/editor/libeditor/html/tests/browserscope/lib/richtext2/currentStatus.js @@ -20,9 +20,6 @@ const knownFailures = { "AC-Proposed-SUP_TEXT-1_SI-dM": true, "AC-Proposed-SUP_TEXT-1_SI-body": true, "AC-Proposed-SUP_TEXT-1_SI-div": true, - "AC-Proposed-FS:2_TEXT-1_SI-dM": true, - "AC-Proposed-FS:2_TEXT-1_SI-body": true, - "AC-Proposed-FS:2_TEXT-1_SI-div": true, "AC-Proposed-FS:18px_TEXT-1_SI-dM": true, "AC-Proposed-FS:18px_TEXT-1_SI-body": true, "AC-Proposed-FS:18px_TEXT-1_SI-div": true, @@ -44,9 +41,6 @@ const knownFailures = { "C-Proposed-FS:1_SPAN.ass.s:fs:large-1_SW-dM": true, "C-Proposed-FS:1_SPAN.ass.s:fs:large-1_SW-body": true, "C-Proposed-FS:1_SPAN.ass.s:fs:large-1_SW-div": true, - "C-Proposed-FS:5_FONTsz:1.s:fs:xs-1_SW-dM": true, - "C-Proposed-FS:5_FONTsz:1.s:fs:xs-1_SW-body": true, - "C-Proposed-FS:5_FONTsz:1.s:fs:xs-1_SW-div": true, "C-Proposed-FS:larger_FONTsz:4-dM": true, "C-Proposed-FS:larger_FONTsz:4-body": true, "C-Proposed-FS:larger_FONTsz:4-div": true, @@ -83,18 +77,9 @@ const knownFailures = { "CC-Proposed-FN:c_FONTf:a-2_SL-dM": true, "CC-Proposed-FN:c_FONTf:a-2_SL-body": true, "CC-Proposed-FN:c_FONTf:a-2_SL-div": true, - "CC-Proposed-FS:1_SPANs:fs:l-1_SW-dM": true, - "CC-Proposed-FS:1_SPANs:fs:l-1_SW-body": true, - "CC-Proposed-FS:1_SPANs:fs:l-1_SW-div": true, "CC-Proposed-FS:18px_SPANs:fs:l-1_SW-dM": true, "CC-Proposed-FS:18px_SPANs:fs:l-1_SW-body": true, "CC-Proposed-FS:18px_SPANs:fs:l-1_SW-div": true, - "CC-Proposed-FS:4_SPANs:fs:l-1_SW-dM": true, - "CC-Proposed-FS:4_SPANs:fs:l-1_SW-body": true, - "CC-Proposed-FS:4_SPANs:fs:l-1_SW-div": true, - "CC-Proposed-FS:4_SPANs:fs:18px-1_SW-dM": true, - "CC-Proposed-FS:4_SPANs:fs:18px-1_SW-body": true, - "CC-Proposed-FS:4_SPANs:fs:18px-1_SW-div": true, "CC-Proposed-FS:larger_SPANs:fs:l-1_SI-dM": true, "CC-Proposed-FS:larger_SPANs:fs:l-1_SI-body": true, "CC-Proposed-FS:larger_SPANs:fs:l-1_SI-div": true, @@ -678,9 +663,6 @@ const knownFailures = { "C-Proposed-FS:1_SPAN.ass.s:fs:large-1_SW-dM": true, "C-Proposed-FS:1_SPAN.ass.s:fs:large-1_SW-body": true, "C-Proposed-FS:1_SPAN.ass.s:fs:large-1_SW-div": true, - "C-Proposed-FS:5_FONTsz:1.s:fs:xs-1_SW-dM": true, - "C-Proposed-FS:5_FONTsz:1.s:fs:xs-1_SW-body": true, - "C-Proposed-FS:5_FONTsz:1.s:fs:xs-1_SW-div": true, "C-Proposed-FS:2_FONTc:b.sz:6-1_SI-dM": true, "C-Proposed-FS:2_FONTc:b.sz:6-1_SI-body": true, "C-Proposed-FS:2_FONTc:b.sz:6-1_SI-div": true, @@ -726,18 +708,9 @@ const knownFailures = { "CC-Proposed-FN:c_FONTf:a-2_SL-dM": true, "CC-Proposed-FN:c_FONTf:a-2_SL-body": true, "CC-Proposed-FN:c_FONTf:a-2_SL-div": true, - "CC-Proposed-FS:1_SPANs:fs:l-1_SW-dM": true, - "CC-Proposed-FS:1_SPANs:fs:l-1_SW-body": true, - "CC-Proposed-FS:1_SPANs:fs:l-1_SW-div": true, "CC-Proposed-FS:18px_SPANs:fs:l-1_SW-dM": true, "CC-Proposed-FS:18px_SPANs:fs:l-1_SW-body": true, "CC-Proposed-FS:18px_SPANs:fs:l-1_SW-div": true, - "CC-Proposed-FS:4_SPANs:fs:l-1_SW-dM": true, - "CC-Proposed-FS:4_SPANs:fs:l-1_SW-body": true, - "CC-Proposed-FS:4_SPANs:fs:l-1_SW-div": true, - "CC-Proposed-FS:4_SPANs:fs:18px-1_SW-dM": true, - "CC-Proposed-FS:4_SPANs:fs:18px-1_SW-body": true, - "CC-Proposed-FS:4_SPANs:fs:18px-1_SW-div": true, "CC-Proposed-FS:larger_SPANs:fs:l-1_SI-dM": true, "CC-Proposed-FS:larger_SPANs:fs:l-1_SI-body": true, "CC-Proposed-FS:larger_SPANs:fs:l-1_SI-div": true, diff --git a/editor/libeditor/html/tests/test_bug480647.html b/editor/libeditor/html/tests/test_bug480647.html index 33f088a1b1a8..b38dd54bfe40 100644 --- a/editor/libeditor/html/tests/test_bug480647.html +++ b/editor/libeditor/html/tests/test_bug480647.html @@ -21,16 +21,47 @@ function parseFontSizeTodo(input, expected) { } function parseFontSizeInner(input, expected, fn) { + // First test non-CSS + document.execCommand("styleWithCSS", false, false); div.innerHTML = "foo"; getSelection().selectAllChildren(div); document.execCommand("fontSize", false, input); if (expected === null) { fn(div.innerHTML, "foo", - 'execCommand("fontSize", false, "' + input + '") should be no-op'); + 'execCommand("fontSize", false, "' + input + '") should be no-op ' + + '(non-CSS)'); } else { fn(div.innerHTML, 'foo', 'execCommand("fontSize", false, "' + input + '") should parse to ' + - expected); + expected + ' (non-CSS)'); + } + + // Now test CSS + document.execCommand("styleWithCSS", false, true); + div.innerHTML = "foo"; + getSelection().selectAllChildren(div); + document.execCommand("fontSize", false, input); + if (expected === null) { + fn(div.innerHTML, "foo", + 'execCommand("fontSize", false, "' + input + '") should be no-op ' + + '(CSS)'); + } else if (expected === 7) { + // No CSS support for + fn(div.innerHTML, 'foo', + 'execCommand("fontSize", false, "' + input + '") should parse to ' + + expected + ' (CSS)'); + } else { + var cssVal = { + 1: "x-small", + 2: "small", + 3: "medium", + 4: "large", + 5: "x-large", + 6: "xx-large", + }[expected]; + fn(div.innerHTML, 'foo', + 'execCommand("fontSize", false, "' + input + '") should parse to ' + + expected + ' (CSS)'); } }