Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
2010-09-09 Ryosuke Niwa <rniwa@webkit.org>
Reviewed by Darin Adler. QueryCommandValue('FontSize') returns pixel values instead of IE font numbers https://bugs.webkit.org/show_bug.cgi?id=21033 Modified selectionStartCSSPropertyValue to return legacy font size instead of pixel size. To implement the conversion between pixel font size and legacy font size, added legacyFontSize to CSSStyleSelector with a helper static function findNearestLegacyFontSize. Fixed a bug in selectionComputedStyle where it obtains the style of the previous editing position even when the selection is a range. This change revealed a crash in executeToggleStyleInList, which was also fixed. Test: editing/execCommand/query-font-size.html * css/CSSComputedStyleDeclaration.cpp: (WebCore::CSSComputedStyleDeclaration::getFontSizeCSSValuePreferringKeyword): Corrected style. (WebCore::CSSComputedStyleDeclaration::useFixedFontDefaultSize): Added. * css/CSSComputedStyleDeclaration.h: * css/CSSStyleSelector.cpp: (WebCore::CSSStyleSelector::fontSizeForKeyword): Renamed fixed/monospace to shouldUseFixedDefaultSize. (WebCore::findNearestLegacyFontSize): Added, a helper for legacyFontSize. (WebCore::CSSStyleSelector::legacyFontSize): Added. * css/CSSStyleSelector.h: * editing/Editor.cpp: (WebCore::Editor::selectionStartCSSPropertyValue): Added a conversion from pixel to legacy font size. * editing/EditorCommand.cpp: (WebCore::executeToggleStyleInList): Crash fix. * page/Frame.cpp: (WebCore::Frame::selectionComputedStyle): See above. 2010-09-09 Ryosuke Niwa <rniwa@webkit.org> Reviewed by Darin Adler. queryCommandValue('FontSize') returns pixel values instead of IE font numbers https://bugs.webkit.org/show_bug.cgi?id=21033 Added a test to ensure queryCommandValue('fontSize') returns legacy font size for both variable width and fixed width fonts. * editing/execCommand/query-font-size-expected.txt: Added. * editing/execCommand/query-font-size.html: Added. * fast/serializer: Added. Canonical link: https://commits.webkit.org/57844@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@67102 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information
Showing
with
274 additions
and 8 deletions.
- +14 −0 LayoutTests/ChangeLog
- +31 −0 LayoutTests/editing/execCommand/query-font-size-expected.txt
- +126 −0 LayoutTests/editing/execCommand/query-font-size.html
- +33 −0 WebCore/ChangeLog
- +15 −4 WebCore/css/CSSComputedStyleDeclaration.cpp
- +1 −0 WebCore/css/CSSComputedStyleDeclaration.h
- +29 −2 WebCore/css/CSSStyleSelector.cpp
- +4 −1 WebCore/css/CSSStyleSelector.h
- +10 −1 WebCore/editing/Editor.cpp
- +3 −0 WebCore/editing/EditorCommand.cpp
- +8 −0 WebCore/page/Frame.cpp
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,31 @@ | ||
test html queryCommandValue result getComputedStyle result | ||
execCommand('FontSize', -2) <span class="Apple-style-span" style="font-size: x-small;">test</span> 1 10px | ||
execCommand('FontSize', -1) <span class="Apple-style-span" style="font-size: small;">test</span> 2 13px | ||
execCommand('FontSize', 0) <span>test</span> 3 16px | ||
execCommand('FontSize', 1) <span class="Apple-style-span" style="font-size: x-small;">test</span> 1 10px | ||
execCommand('FontSize', 2) <span class="Apple-style-span" style="font-size: small;">test</span> 2 13px | ||
execCommand('FontSize', 3) <span>test</span> 3 16px | ||
execCommand('FontSize', 4) <span class="Apple-style-span" style="font-size: large;">test</span> 4 18px | ||
execCommand('FontSize', 5) <span class="Apple-style-span" style="font-size: x-large;">test</span> 5 24px | ||
execCommand('FontSize', 6) <span class="Apple-style-span" style="font-size: xx-large;">test</span> 6 32px | ||
execCommand('FontSize', 7) <span class="Apple-style-span" style="font-size: -webkit-xxx-large;">test</span> 7 48px | ||
execCommand('FontSize', '8px') <span class="Apple-style-span" style="font-size: -webkit-xxx-large;">test</span> 7 48px | ||
execCommand('FontSize', '2px') <span class="Apple-style-span" style="font-size: small;">test</span> 2 13px | ||
manual CSS font-size: 3px <span style="font-size: 3px">test</span> 1 3px | ||
manual CSS font-size: 0.2em <span style="font-size: 0.2em">test</span> 1 9px | ||
manual CSS font-size: 17px <span style="font-size: 17px">test</span> 4 17px | ||
manual CSS font-size: 31px <span style="font-size: 31px">test</span> 6 31px | ||
manual CSS font-size: 50px <span style="font-size: 50px">test</span> 7 50px | ||
manual CSS font-size: 5em <span style="font-size: 5em">test</span> 7 80px | ||
manual CSS font-size: 10px <span style="font-size: 10px">test</span> 1 10px | ||
monospace tests to show bug 19161 | ||
execCommand('FontSize', -2) <span class="Apple-style-span" style="font-size: x-small;"><font class="Apple-style-span" face="monospace">test</font></span> 1 10px | ||
execCommand('FontSize', -1) <span class="Apple-style-span" style="font-size: small;"><font class="Apple-style-span" face="monospace">test</font></span> 2 13px | ||
execCommand('FontSize', 0) <span><font class="Apple-style-span" face="monospace">test</font></span> 3 16px | ||
execCommand('FontSize', 1) <span class="Apple-style-span" style="font-size: x-small;"><font class="Apple-style-span" face="monospace">test</font></span> 1 10px | ||
execCommand('FontSize', 2) <span class="Apple-style-span" style="font-size: small;"><font class="Apple-style-span" face="monospace">test</font></span> 2 13px | ||
execCommand('FontSize', 3) <span><font class="Apple-style-span" face="monospace">test</font></span> 3 16px | ||
execCommand('FontSize', 4) <span class="Apple-style-span" style="font-size: large;"><font class="Apple-style-span" face="monospace">test</font></span> 4 18px | ||
execCommand('FontSize', 5) <span class="Apple-style-span" style="font-size: x-large;"><font class="Apple-style-span" face="monospace">test</font></span> 5 24px | ||
execCommand('FontSize', 6) <span class="Apple-style-span" style="font-size: xx-large;"><font class="Apple-style-span" face="monospace">test</font></span> 6 32px | ||
execCommand('FontSize', 7) <span class="Apple-style-span" style="font-size: -webkit-xxx-large;"><font class="Apple-style-span" face="monospace">test</font></span> 7 48px |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,126 @@ | ||
<body> | ||
<script> | ||
|
||
function addRow(table) | ||
{ | ||
var tableRow = document.createElement("tr"); | ||
table.appendChild(tableRow); | ||
return tableRow; | ||
} | ||
|
||
function addCellWithNodeContents(tableRow, contents) | ||
{ | ||
var tableCell = document.createElement("td"); | ||
tableCell.appendChild(contents); | ||
tableRow.appendChild(tableCell); | ||
return tableCell; | ||
} | ||
|
||
function addCellWithTextContents(tableRow, contents) | ||
{ | ||
return addCellWithNodeContents(tableRow, document.createTextNode(contents)); | ||
} | ||
|
||
function addHeaderWithTextContents(tableRow, contents) | ||
{ | ||
var tableCell = document.createElement("th"); | ||
tableCell.appendChild(document.createTextNode(contents)); | ||
tableRow.appendChild(tableCell); | ||
return tableCell; | ||
} | ||
|
||
function setFontSizeOnContent(size) | ||
{ | ||
window.getSelection().selectAllChildren(editableDiv); | ||
document.execCommand("FontSize", false, size); | ||
return editableDiv.firstChild; | ||
} | ||
|
||
function setFontFamilyOnContent(fontFamily) | ||
{ | ||
window.getSelection().selectAllChildren(editableDiv); | ||
document.execCommand("FontName", false, fontFamily); | ||
return editableDiv.firstChild; | ||
} | ||
|
||
function wrapInSpanIfNeeded(shouldBeSpan) | ||
{ | ||
// Sometimes the result of the ExecCommand will not have a wrapping <span> | ||
if (!shouldBeSpan.localName || shouldBeSpan.localName.toLowerCase() != "span") { | ||
shouldBeSpan = document.createElement("span"); | ||
shouldBeSpan.appendChild(editableDiv.firstChild); | ||
editableDiv.appendChild(shouldBeSpan); | ||
} | ||
return shouldBeSpan; | ||
} | ||
|
||
function reportSizeForSpan(span, comment) | ||
{ | ||
var tableRow = addRow(table); | ||
addCellWithTextContents(tableRow, comment); | ||
addCellWithTextContents(tableRow, span.parentNode.innerHTML); // sill FF has no outerHTML | ||
|
||
window.getSelection().selectAllChildren(span.parentNode); | ||
addCellWithTextContents(tableRow, "" + document.queryCommandValue("FontSize")); | ||
addCellWithTextContents(tableRow, "" + window.getComputedStyle(span, null).fontSize); | ||
} | ||
|
||
function testExecCommandFontSize(size, fontFamily) | ||
{ | ||
editableDiv.innerHTML = "test"; | ||
var sizedContent = setFontSizeOnContent(size); | ||
sizedContent = wrapInSpanIfNeeded(sizedContent); | ||
if (fontFamily) | ||
sizedContent = setFontFamilyOnContent(fontFamily); | ||
var sizeString = (typeof(size) == "string") ? ("'" + size + "'") : size; | ||
reportSizeForSpan(sizedContent, "execCommand('FontSize', " + sizeString + ")"); | ||
} | ||
|
||
function testManualFontSize(size) | ||
{ | ||
editableDiv.innerHTML = "<span style='font-size: " + size + "'>test</span>"; | ||
reportSizeForSpan(editableDiv.firstChild, "manual CSS font-size: " + size); | ||
} | ||
|
||
if (window.layoutTestController) | ||
window.layoutTestController.dumpAsText(); | ||
|
||
var editableDiv = document.createElement("div"); | ||
editableDiv.contentEditable = true; | ||
document.body.appendChild(editableDiv); | ||
|
||
var table = document.createElement("table"); | ||
table.border = "1px"; | ||
table.width = "100%"; | ||
document.body.appendChild(table); | ||
|
||
var tableRow = addRow(table); | ||
addHeaderWithTextContents(tableRow, "test"); | ||
addHeaderWithTextContents(tableRow, "html"); | ||
addHeaderWithTextContents(tableRow, "queryCommandValue result"); | ||
addHeaderWithTextContents(tableRow, "getComputedStyle result"); | ||
|
||
for (var size = -2; size < 8; size++) { | ||
testExecCommandFontSize(size); | ||
} | ||
testExecCommandFontSize("8px"); | ||
testExecCommandFontSize("2px"); | ||
|
||
testManualFontSize("3px"); | ||
testManualFontSize("0.2em"); | ||
testManualFontSize("17px"); | ||
testManualFontSize("31px"); | ||
testManualFontSize("50px"); | ||
testManualFontSize("5em"); | ||
testManualFontSize("10px"); | ||
|
||
tableRow = addRow(table); | ||
addHeaderWithTextContents(tableRow, "monospace tests to show bug 19161"); | ||
|
||
for (var size = -2; size < 8; size++) { | ||
testExecCommandFontSize(size, 'monospace'); | ||
} | ||
|
||
document.body.removeChild(editableDiv); | ||
|
||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters