Bug 812638: backs out bug 480647 (part 6) r=ehsan

This commit is contained in:
Jet Villegas 2013-02-06 06:57:26 -08:00
parent eac6d60297
commit 3ecf1b8786
6 changed files with 48 additions and 146 deletions

View File

@ -183,45 +183,6 @@ 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 }
@ -257,11 +218,6 @@ 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 }
@ -347,21 +303,19 @@ nsHTMLCSSUtils::~nsHTMLCSSUtils()
bool
nsHTMLCSSUtils::IsCSSEditableProperty(nsIDOMNode* aNode,
nsIAtom* aProperty,
const nsAString* aAttribute,
const nsAString* aValue)
const nsAString* aAttribute)
{
NS_ASSERTION(aNode, "Shouldn't you pass aNode? - Bug 214025");
nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
NS_ENSURE_TRUE(content, false);
return IsCSSEditableProperty(content, aProperty, aAttribute, aValue);
return IsCSSEditableProperty(content, aProperty, aAttribute);
}
bool
nsHTMLCSSUtils::IsCSSEditableProperty(nsIContent* aNode,
nsIAtom* aProperty,
const nsAString* aAttribute,
const nsAString* aValue)
const nsAString* aAttribute)
{
MOZ_ASSERT(aNode);
@ -387,16 +341,6 @@ 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
@ -908,9 +852,6 @@ 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")) {
@ -989,8 +930,7 @@ nsHTMLCSSUtils::SetCSSEquivalentToHTMLStyle(nsIDOMNode * aNode,
{
nsCOMPtr<dom::Element> element = do_QueryInterface(aNode);
*aCount = 0;
if (!element || !IsCSSEditableProperty(element, aHTMLProperty,
aAttribute, aValue)) {
if (!element || !IsCSSEditableProperty(element, aHTMLProperty, aAttribute)) {
return NS_OK;
}
@ -1066,8 +1006,7 @@ nsHTMLCSSUtils::GetCSSEquivalentToHTMLInlineStyleSet(nsINode* aNode,
nsCOMPtr<dom::Element> theElement = GetElementContainerOrSelf(aNode);
NS_ENSURE_TRUE(theElement, NS_ERROR_NULL_POINTER);
if (!theElement || !IsCSSEditableProperty(theElement, aHTMLProperty,
aAttribute, &aValueString)) {
if (!theElement || !IsCSSEditableProperty(theElement, aHTMLProperty, aAttribute)) {
return NS_OK;
}
@ -1244,19 +1183,6 @@ 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 {

View File

@ -82,18 +82,9 @@ 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 <font size>,
* 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,
const nsAString* aValue = nullptr);
bool IsCSSEditableProperty(nsIDOMNode* aNode, nsIAtom* aProperty,
const nsAString* aAttribute,
const nsAString* aValue = nullptr);
bool IsCSSEditableProperty(nsIContent* aNode, nsIAtom* aProperty, const nsAString* aAttribute);
bool IsCSSEditableProperty(nsIDOMNode* aNode, nsIAtom* aProperty, const nsAString* aAttribute);
/** adds/remove a CSS declaration to the STYLE atrribute carried by a given element
*

View File

@ -312,8 +312,7 @@ nsHTMLEditor::IsSimpleModifiableNode(nsIContent* aContent,
// No luck so far. Now we check for a <span> 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, aValue) ||
if (!mHTMLCSSUtils->IsCSSEditableProperty(element, aProperty, aAttribute) ||
!element->IsHTML(nsGkAtoms::span) || element->GetAttrCount() != 1 ||
!element->HasAttr(kNameSpaceID_None, nsGkAtoms::style)) {
return false;
@ -361,8 +360,7 @@ nsHTMLEditor::SetInlinePropertyOnTextNode( nsIDOMCharacterData *aTextNode,
// don't need to do anything if property already set on node
bool bHasProp;
if (mHTMLCSSUtils->IsCSSEditableProperty(node, aProperty,
aAttribute, aValue)) {
if (mHTMLCSSUtils->IsCSSEditableProperty(node, aProperty, aAttribute)) {
// 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);
@ -471,8 +469,7 @@ nsHTMLEditor::SetInlinePropertyOnNodeImpl(nsIContent* aNode,
}
// don't need to do anything if property already set on node
if (mHTMLCSSUtils->IsCSSEditableProperty(aNode, aProperty,
aAttribute, aValue)) {
if (mHTMLCSSUtils->IsCSSEditableProperty(aNode, aProperty, aAttribute)) {
if (mHTMLCSSUtils->IsCSSEquivalentToHTMLInlineStyleSet(
aNode, aProperty, aAttribute, *aValue, nsHTMLCSSUtils::eComputed)) {
return NS_OK;
@ -483,8 +480,7 @@ nsHTMLEditor::SetInlinePropertyOnNodeImpl(nsIContent* aNode,
}
bool useCSS = (IsCSSEnabled() &&
mHTMLCSSUtils->IsCSSEditableProperty(aNode, aProperty,
aAttribute, aValue)) ||
mHTMLCSSUtils->IsCSSEditableProperty(aNode, aProperty, aAttribute)) ||
// bgcolor is always done using CSS
aAttribute->EqualsLiteral("bgcolor");
@ -1157,11 +1153,7 @@ nsHTMLEditor::GetInlinePropertyBase(nsIAtom *aProperty,
return NS_OK;
}
// Bug 747889: we don't support CSS for fontSize values
if ((aProperty != nsEditProperty::font ||
!aAttribute->EqualsLiteral("size")) &&
mHTMLCSSUtils->IsCSSEditableProperty(collapsedNode, aProperty,
aAttribute)) {
if (mHTMLCSSUtils->IsCSSEditableProperty(collapsedNode, aProperty, aAttribute)) {
mHTMLCSSUtils->IsCSSEquivalentToHTMLInlineStyleSet(
collapsedNode, aProperty, aAttribute, isSet, tOutString,
nsHTMLCSSUtils::eComputed);
@ -1245,11 +1237,7 @@ nsHTMLEditor::GetInlinePropertyBase(nsIAtom *aProperty,
bool isSet = false;
if (first) {
if (mHTMLCSSUtils->IsCSSEditableProperty(node, aProperty,
aAttribute) &&
// Bug 747889: we don't support CSS for fontSize values
(aProperty != nsEditProperty::font ||
!aAttribute->EqualsLiteral("size"))) {
if (mHTMLCSSUtils->IsCSSEditableProperty(node, aProperty, aAttribute)){
// 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
@ -1268,11 +1256,7 @@ nsHTMLEditor::GetInlinePropertyBase(nsIAtom *aProperty,
*outValue = firstValue;
}
} else {
if (mHTMLCSSUtils->IsCSSEditableProperty(node, aProperty,
aAttribute) &&
// Bug 747889: we don't support CSS for fontSize values
(aProperty != nsEditProperty::font ||
!aAttribute->EqualsLiteral("size"))) {
if (mHTMLCSSUtils->IsCSSEditableProperty(node, aProperty, aAttribute)){
// 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) {

View File

@ -19,6 +19,7 @@ var knownFailures = {
},
'a' : {
'createbookmark-0' : true,
'fontsize-1' : true,
'subscript-1' : true,
'superscript-1' : true,
},
@ -34,6 +35,10 @@ var knownFailures = {
'fontsize-1' : true,
'fontsize-2' : true,
},
'c': {
'fontsize-1' : true,
'fontsize-2' : true,
},
};
function isKnownFailure(type, test, param) {

View File

@ -20,6 +20,9 @@ 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,
@ -41,6 +44,9 @@ 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,
@ -77,9 +83,18 @@ 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,
@ -663,6 +678,9 @@ 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,
@ -708,9 +726,18 @@ 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,

View File

@ -21,47 +21,16 @@ 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 ' +
'(non-CSS)');
'execCommand("fontSize", false, "' + input + '") should be no-op');
} else {
fn(div.innerHTML, '<font size="' + expected + '">foo</font>',
'execCommand("fontSize", false, "' + input + '") should parse to ' +
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 <font size=7>
fn(div.innerHTML, '<font size="' + expected + '">foo</font>',
'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, '<span style="font-size: ' + cssVal + ';">foo</span>',
'execCommand("fontSize", false, "' + input + '") should parse to ' +
expected + ' (CSS)');
expected);
}
}