Changeset 67170 in webkit


Ignore:
Timestamp:
Sep 9, 2010 10:39:16 PM (14 years ago)
Author:
rniwa@webkit.org
Message:

2010-09-09 Ryosuke Niwa <rniwa@webkit.org>

Reviewed by Eric Seidel.

REGRESSION: applying new font size causes font-size outside selection to change
https://bugs.webkit.org/show_bug.cgi?id=45026

The regression was caused by removeImplicitlyStyledElement not converting font size to CSS value properly.
Namely, it was treating font size as a pixel value for font-size property. Fixed this by adding fontSizeToCSSValue
which uses HTMLFontElement::cssValueFromFontSizeNumber and deployed it in removeImplicitlyStyledElement

Also fixed a bug in StyleChange::extractTextStyles that it ignores font-size property when the values were
relative terms such as x-small and -webkit-xxx-large. And replaced the logic to convert from pixel font size
to legacy font size by CSSStyleSelector::legacyFontSize.

Test: editing/style/push-down-font-styles.html

  • editing/ApplyStyleCommand.cpp: (WebCore::StyleChange::extractTextStyles): Fixed a bug. See above. (WebCore::stringToCSSValue): Converts string to CSSValue. (WebCore::fontSizeToCSSValue): Converts font size number (String) to CSSPrimitiveValue. (WebCore::ApplyStyleCommand::removeImplicitlyStyledElement): Calls stringToCSSValue and fontSizeToCSSValue.
  • css/CSSStyleSelector.h: Made fontSizeForKeyword public.

2010-09-09 Ryosuke Niwa <rniwa@webkit.org>

Reviewed by Eric Seidel.

REGRESSION: applying new font size causes font-size outside selection to change
https://bugs.webkit.org/show_bug.cgi?id=45026

Added a test to apply font-size and font-family on various markups.

  • editing/deleting/delete-br-012-expected.txt: Conflicting font and span elements are merged into one font element.
  • editing/inserting/5994480-2-expected.txt: Removed redundant size attribute from font element.
  • editing/deleting/delete-select-all-001-expected.txt: Style spans are replaced by font elements.
  • editing/style/block-style-004-expected.txt: Ditto.
  • editing/style/block-style-005-expected.txt: Ditto.
  • editing/style/block-style-006-expected.txt: Ditto.
  • editing/style/fontsize-1-expected.txt: Ditto.
  • editing/execCommand/query-font-size-expected.txt: Ditto; also fixed the test not to add extraneous spans.
  • editing/style/push-down-font-styles-expected.txt: Added.
  • editing/style/push-down-font-styles.html: Added.
  • editing/style/script-tests/push-down-font-styles.js: Added. (testSingleToggle): (selectAll): (selectTest): (selectFirstWord): (selectSecondWord): (selectLastTwoWords):
  • platform/chromium-win/editing/inserting/5994480-2-expected.txt: Removed extraneous span.
Location:
trunk
Files:
3 added
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r67169 r67170  
     12010-09-09  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Reviewed by Eric Seidel.
     4
     5        REGRESSION: applying new font size causes font-size outside selection to change
     6        https://bugs.webkit.org/show_bug.cgi?id=45026
     7
     8        Added a test to apply font-size and font-family on various markups.
     9
     10        * editing/deleting/delete-br-012-expected.txt: Conflicting font and span elements are merged into one font element.
     11        * editing/inserting/5994480-2-expected.txt: Removed redundant size attribute from font element.
     12        * editing/deleting/delete-select-all-001-expected.txt: Style spans are replaced by font elements.
     13        * editing/style/block-style-004-expected.txt: Ditto.
     14        * editing/style/block-style-005-expected.txt: Ditto.
     15        * editing/style/block-style-006-expected.txt: Ditto.
     16        * editing/style/fontsize-1-expected.txt: Ditto.
     17        * editing/execCommand/query-font-size-expected.txt: Ditto; also fixed the test not to add extraneous spans.
     18        * editing/style/push-down-font-styles-expected.txt: Added.
     19        * editing/style/push-down-font-styles.html: Added.
     20        * editing/style/script-tests/push-down-font-styles.js: Added.
     21        (testSingleToggle):
     22        (selectAll):
     23        (selectTest):
     24        (selectFirstWord):
     25        (selectSecondWord):
     26        (selectLastTwoWords):
     27        * platform/chromium-win/editing/inserting/5994480-2-expected.txt: Removed extraneous span.
     28
    1292010-09-09  James Kozianski  <koz@chromium.org>
    230
  • trunk/LayoutTests/editing/deleting/delete-br-012-expected.txt

    r67154 r67170  
    1818|   <font>
    1919|     class="Apple-style-span"
    20 |     size="6"
    21 |     <span>
    22 |       class="Apple-style-span"
    23 |       style="font-size: 24px;"
    24 |       <#selection-caret>
    25 |       <br>
     20|     size="5"
     21|     <#selection-caret>
     22|     <br>
    2623|   "
    2724"
  • trunk/LayoutTests/editing/deleting/delete-select-all-001-expected.txt

    r67154 r67170  
    11
    2 execDeleteCommand: <span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-size: medium;"><br></span>
     2execDeleteCommand: <font class="Apple-style-span" size="3"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"><br></span></font>
  • trunk/LayoutTests/editing/execCommand/query-font-size-expected.txt

    r67154 r67170  
    11test    html    queryCommandValue result
    2 execCommand('FontSize', -2)     <span class="Apple-style-span" style="font-size: x-small;">test</span>  1
    3 execCommand('FontSize', -1)     <span class="Apple-style-span" style="font-size: small;">test</span>    2
    4 execCommand('FontSize', 0)      <span>test</span>       3
    5 execCommand('FontSize', 1)      <span class="Apple-style-span" style="font-size: x-small;">test</span>  1
    6 execCommand('FontSize', 2)      <span class="Apple-style-span" style="font-size: small;">test</span>    2
    7 execCommand('FontSize', 3)      <span>test</span>       3
    8 execCommand('FontSize', 4)      <span class="Apple-style-span" style="font-size: large;">test</span>    4
    9 execCommand('FontSize', 5)      <span class="Apple-style-span" style="font-size: x-large;">test</span>  5
    10 execCommand('FontSize', 6)      <span class="Apple-style-span" style="font-size: xx-large;">test</span> 6
    11 execCommand('FontSize', 7)      <span class="Apple-style-span" style="font-size: -webkit-xxx-large;">test</span>        7
    12 execCommand('FontSize', '8px')  <span class="Apple-style-span" style="font-size: -webkit-xxx-large;">test</span>        7
    13 execCommand('FontSize', '2px')  <span class="Apple-style-span" style="font-size: small;">test</span>    2
     2execCommand('FontSize', -2)     <font class="Apple-style-span" size="1">test</font>     1
     3execCommand('FontSize', -1)     <font class="Apple-style-span" size="2">test</font>     2
     4execCommand('FontSize', 0)      test    3
     5execCommand('FontSize', 1)      <font class="Apple-style-span" size="1">test</font>     1
     6execCommand('FontSize', 2)      <font class="Apple-style-span" size="2">test</font>     2
     7execCommand('FontSize', 3)      test    3
     8execCommand('FontSize', 4)      <font class="Apple-style-span" size="4">test</font>     4
     9execCommand('FontSize', 5)      <font class="Apple-style-span" size="5">test</font>     5
     10execCommand('FontSize', 6)      <font class="Apple-style-span" size="6">test</font>     6
     11execCommand('FontSize', 7)      <font class="Apple-style-span" size="7">test</font>     7
     12execCommand('FontSize', '8px')  <font class="Apple-style-span" size="7">test</font>     7
     13execCommand('FontSize', '2px')  <font class="Apple-style-span" size="2">test</font>     2
    1414manual CSS font-size: 3px       <span style="font-size: 3px">test</span>        1
    1515manual CSS font-size: 0.2em     <span style="font-size: 0.2em">test</span>      1
     
    2020manual CSS font-size: 10px      <span style="font-size: 10px">test</span>       1
    2121monospace tests to ensure the bug 19161 does not affect queryCommandValue's values
    22 execCommand('FontSize', -2)     <span class="Apple-style-span" style="font-size: x-small;"><font class="Apple-style-span" face="monospace">test</font></span>   1
    23 execCommand('FontSize', -1)     <span class="Apple-style-span" style="font-size: small;"><font class="Apple-style-span" face="monospace">test</font></span>     2
    24 execCommand('FontSize', 0)      <span><font class="Apple-style-span" face="monospace">test</font></span>        3
    25 execCommand('FontSize', 1)      <span class="Apple-style-span" style="font-size: x-small;"><font class="Apple-style-span" face="monospace">test</font></span>   1
    26 execCommand('FontSize', 2)      <span class="Apple-style-span" style="font-size: small;"><font class="Apple-style-span" face="monospace">test</font></span>     2
    27 execCommand('FontSize', 3)      <span><font class="Apple-style-span" face="monospace">test</font></span>        3
    28 execCommand('FontSize', 4)      <span class="Apple-style-span" style="font-size: large;"><font class="Apple-style-span" face="monospace">test</font></span>     4
    29 execCommand('FontSize', 5)      <span class="Apple-style-span" style="font-size: x-large;"><font class="Apple-style-span" face="monospace">test</font></span>   5
    30 execCommand('FontSize', 6)      <span class="Apple-style-span" style="font-size: xx-large;"><font class="Apple-style-span" face="monospace">test</font></span>  6
    31 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
     22execCommand('FontSize', -2)     <font class="Apple-style-span" size="1"><font class="Apple-style-span" face="monospace">test</font></font>      1
     23execCommand('FontSize', -1)     <font class="Apple-style-span" size="2"><font class="Apple-style-span" face="monospace">test</font></font>      2
     24execCommand('FontSize', 0)      <font class="Apple-style-span" face="monospace">test</font>     3
     25execCommand('FontSize', 1)      <font class="Apple-style-span" size="1"><font class="Apple-style-span" face="monospace">test</font></font>      1
     26execCommand('FontSize', 2)      <font class="Apple-style-span" size="2"><font class="Apple-style-span" face="monospace">test</font></font>      2
     27execCommand('FontSize', 3)      <font class="Apple-style-span" face="monospace">test</font>     3
     28execCommand('FontSize', 4)      <font class="Apple-style-span" size="4"><font class="Apple-style-span" face="monospace">test</font></font>      4
     29execCommand('FontSize', 5)      <font class="Apple-style-span" size="5"><font class="Apple-style-span" face="monospace">test</font></font>      5
     30execCommand('FontSize', 6)      <font class="Apple-style-span" size="6"><font class="Apple-style-span" face="monospace">test</font></font>      6
     31execCommand('FontSize', 7)      <font class="Apple-style-span" size="7"><font class="Apple-style-span" face="monospace">test</font></font>      7
  • trunk/LayoutTests/editing/execCommand/query-font-size.html

    r67154 r67170  
    4444}
    4545
    46 function wrapInSpanIfNeeded(shouldBeSpan)
    47 {
    48     // Sometimes the result of the ExecCommand will not have a wrapping <span>
    49     if (!shouldBeSpan.localName || shouldBeSpan.localName.toLowerCase() != "span") {
    50         shouldBeSpan = document.createElement("span");
    51         shouldBeSpan.appendChild(editableDiv.firstChild);
    52         editableDiv.appendChild(shouldBeSpan);
    53     }
    54     return shouldBeSpan;
    55 }
    56 
    5746function reportSizeForSpan(span, comment)
    5847{
     
    6857    editableDiv.innerHTML = "test";
    6958    var sizedContent = setFontSizeOnContent(size);
    70     sizedContent = wrapInSpanIfNeeded(sizedContent);
    7159    if (fontFamily)
    7260        sizedContent = setFontFamilyOnContent(fontFamily);
  • trunk/LayoutTests/editing/inserting/5994480-2-expected.txt

    r67154 r67170  
    1 <font class="Apple-style-span" face="'Lucida Grande'" size="3"><span class="Apple-style-span" style="font-size: 11px;"><br></span></font>
     1<font class="Apple-style-span" face="'Lucida Grande'"><span class="Apple-style-span" style="font-size: 11px;"><br></span></font>
  • trunk/LayoutTests/editing/style/block-style-004-expected.txt

    r67154 r67170  
    77execInsertParagraphCommand: <div id="test" class="editing">x</div><div id="test" class="editing"><br></div><div id="test" class="editing"><br></div>
    88execTypeCharacterCommand: <div id="test" class="editing">x</div><div id="test" class="editing"><br></div><div id="test" class="editing">x</div>
    9 execFontSizeCommand: <div id="test" class="editing"><span class="Apple-style-span" style="font-size: -webkit-xxx-large;">x</span></div><div id="test" class="editing"><span class="Apple-style-span" style="font-size: -webkit-xxx-large;"><br></span></div><div id="test" class="editing"><span class="Apple-style-span" style="font-size: -webkit-xxx-large;">x</span></div>
    10 execInsertParagraphCommand: <div id="test" class="editing"><span class="Apple-style-span" style="font-size: -webkit-xxx-large;">x</span></div><div id="test" class="editing"><span class="Apple-style-span" style="font-size: -webkit-xxx-large;"><br></span></div><div id="test" class="editing"><span class="Apple-style-span" style="font-size: -webkit-xxx-large;"><br></span></div><div id="test" class="editing"><span class="Apple-style-span" style="font-size: -webkit-xxx-large;">x</span></div>
     9execFontSizeCommand: <div id="test" class="editing"><font class="Apple-style-span" size="7">x</font></div><div id="test" class="editing"><font class="Apple-style-span" size="7"><br></font></div><div id="test" class="editing"><font class="Apple-style-span" size="7">x</font></div>
     10execInsertParagraphCommand: <div id="test" class="editing"><font class="Apple-style-span" size="7">x</font></div><div id="test" class="editing"><font class="Apple-style-span" size="7"><br></font></div><div id="test" class="editing"><font class="Apple-style-span" size="7"><br></font></div><div id="test" class="editing"><font class="Apple-style-span" size="7">x</font></div>
  • trunk/LayoutTests/editing/style/block-style-005-expected.txt

    r67154 r67170  
    66execInsertParagraphCommand: <div id="test" class="editing">x</div><div id="test" class="editing"><br></div><div id="test" class="editing"><br></div>
    77execTypeCharacterCommand: <div id="test" class="editing">x</div><div id="test" class="editing"><br></div><div id="test" class="editing">x</div>
    8 execFontSizeCommand: <div id="test" class="editing"><span class="Apple-style-span" style="font-size: -webkit-xxx-large;">x</span></div><div id="test" class="editing"><span class="Apple-style-span" style="font-size: -webkit-xxx-large;"><br></span></div><div id="test" class="editing"><span class="Apple-style-span" style="font-size: -webkit-xxx-large;">x</span></div>
    9 execDeleteCommand: <div id="test" class="editing"><span class="Apple-style-span" style="font-size: -webkit-xxx-large;">x</span></div><div id="test" class="editing"><span class="Apple-style-span" style="font-size: -webkit-xxx-large;"><br></span></div><div id="test" class="editing"><span class="Apple-style-span" style="font-size: -webkit-xxx-large;"><br></span></div>
     8execFontSizeCommand: <div id="test" class="editing"><font class="Apple-style-span" size="7">x</font></div><div id="test" class="editing"><font class="Apple-style-span" size="7"><br></font></div><div id="test" class="editing"><font class="Apple-style-span" size="7">x</font></div>
     9execDeleteCommand: <div id="test" class="editing"><font class="Apple-style-span" size="7">x</font></div><div id="test" class="editing"><font class="Apple-style-span" size="7"><br></font></div><div id="test" class="editing"><font class="Apple-style-span" size="7"><br></font></div>
  • trunk/LayoutTests/editing/style/block-style-006-expected.txt

    r67154 r67170  
    77execInsertParagraphCommand: <div id="test" class="editing">x</div><div id="test" class="editing"><br></div><div id="test" class="editing"><br></div>
    88execTypeCharacterCommand: <div id="test" class="editing">x</div><div id="test" class="editing"><br></div><div id="test" class="editing">x</div>
    9 execFontSizeCommand: <div id="test" class="editing"><span class="Apple-style-span" style="font-size: -webkit-xxx-large;">x</span></div><div id="test" class="editing"><span class="Apple-style-span" style="font-size: -webkit-xxx-large;"><br></span></div><div id="test" class="editing"><span class="Apple-style-span" style="font-size: -webkit-xxx-large;">x</span></div>
    10 execInsertParagraphCommand: <div id="test" class="editing"><span class="Apple-style-span" style="font-size: -webkit-xxx-large;">x</span></div><div id="test" class="editing"><span class="Apple-style-span" style="font-size: -webkit-xxx-large;"><br></span></div><div id="test" class="editing"><span class="Apple-style-span" style="font-size: -webkit-xxx-large;"><br></span></div><div id="test" class="editing"><span class="Apple-style-span" style="font-size: -webkit-xxx-large;">x</span></div>
     9execFontSizeCommand: <div id="test" class="editing"><font class="Apple-style-span" size="7">x</font></div><div id="test" class="editing"><font class="Apple-style-span" size="7"><br></font></div><div id="test" class="editing"><font class="Apple-style-span" size="7">x</font></div>
     10execInsertParagraphCommand: <div id="test" class="editing"><font class="Apple-style-span" size="7">x</font></div><div id="test" class="editing"><font class="Apple-style-span" size="7"><br></font></div><div id="test" class="editing"><font class="Apple-style-span" size="7"><br></font></div><div id="test" class="editing"><font class="Apple-style-span" size="7">x</font></div>
  • trunk/LayoutTests/editing/style/fontsize-1-expected.txt

    r67154 r67170  
    88
    99type small:
    10 | <span>
     10| <font>
    1111|   class="Apple-style-span"
    12 |   style="font-size: small;"
     12|   size="2"
    1313|   "small<#selection-caret>"
    1414
    1515fontsize 4:
    16 | <span>
     16| <font>
    1717|   class="Apple-style-span"
    18 |   style="font-size: small;"
     18|   size="2"
    1919|   "small<#selection-caret>"
    2020
    2121type medium:
    22 | <span>
     22| <font>
    2323|   class="Apple-style-span"
    24 |   style="font-size: small;"
     24|   size="2"
    2525|   "small"
    26 | <span>
     26| <font>
    2727|   class="Apple-style-span"
    28 |   style="font-size: large;"
     28|   size="4"
    2929|   "medium<#selection-caret>"
    3030
    3131fontsize 6:
    32 | <span>
     32| <font>
    3333|   class="Apple-style-span"
    34 |   style="font-size: small;"
     34|   size="2"
    3535|   "small"
    36 | <span>
     36| <font>
    3737|   class="Apple-style-span"
    38 |   style="font-size: large;"
     38|   size="4"
    3939|   "medium<#selection-caret>"
    4040
    4141type large:
    42 | <span>
     42| <font>
    4343|   class="Apple-style-span"
    44 |   style="font-size: small;"
     44|   size="2"
    4545|   "small"
    46 | <span>
     46| <font>
    4747|   class="Apple-style-span"
    48 |   style="font-size: large;"
     48|   size="4"
    4949|   "medium"
    50 | <span>
     50| <font>
    5151|   class="Apple-style-span"
    52 |   style="font-size: xx-large;"
     52|   size="6"
    5353|   "large<#selection-caret>"
    5454
  • trunk/LayoutTests/platform/chromium-win/editing/inserting/5994480-2-expected.txt

    r56271 r67170  
    1 <font class="Apple-style-span" face="Arial" size="3"><span class="Apple-style-span" style="font-size: 13px;"><br></span></font>
     1<font class="Apple-style-span" face="Arial" size="2"><br></font>
  • trunk/WebCore/ChangeLog

    r67168 r67170  
     12010-09-09  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Reviewed by Eric Seidel.
     4
     5        REGRESSION: applying new font size causes font-size outside selection to change
     6        https://bugs.webkit.org/show_bug.cgi?id=45026
     7
     8        The regression was caused by removeImplicitlyStyledElement not converting font size to CSS value properly.
     9        Namely, it was treating font size as a pixel value for font-size property.  Fixed this by adding fontSizeToCSSValue
     10        which uses HTMLFontElement::cssValueFromFontSizeNumber and deployed it in removeImplicitlyStyledElement
     11
     12        Also fixed a bug in StyleChange::extractTextStyles that it ignores font-size property when the values were
     13        relative terms such as x-small and -webkit-xxx-large. And replaced the logic to convert from pixel font size
     14        to legacy font size by CSSStyleSelector::legacyFontSize.
     15
     16        Test: editing/style/push-down-font-styles.html
     17
     18        * editing/ApplyStyleCommand.cpp:
     19        (WebCore::StyleChange::extractTextStyles): Fixed a bug. See above.
     20        (WebCore::stringToCSSValue): Converts string to CSSValue.
     21        (WebCore::fontSizeToCSSValue): Converts font size number (String) to CSSPrimitiveValue.
     22        (WebCore::ApplyStyleCommand::removeImplicitlyStyledElement): Calls stringToCSSValue and fontSizeToCSSValue.
     23        * css/CSSStyleSelector.h: Made fontSizeForKeyword public.
     24
    1252010-09-09  Kent Tamura  <tkent@chromium.org>
    226
  • trunk/WebCore/css/CSSStyleSelector.h

    r67154 r67170  
    123123        PassRefPtr<CSSRuleList> pseudoStyleRulesForElement(Element*, PseudoId, bool authorOnly);
    124124
    125         // Given a font size in pixel, this function will return legacy font size between 1 and 7.
    126         static int legacyFontSize(Document*, int pixelFontSize, bool shouldUseFixedDefaultSize);
    127 
    128     private:
    129125        // Given a CSS keyword in the range (xx-small to -webkit-xxx-large), this function will return
    130126        // the correct font size scaled relative to the user's default (medium).
    131127        static float fontSizeForKeyword(Document*, int keyword, bool shouldUseFixedDefaultSize);
     128
     129        // Given a font size in pixel, this function will return legacy font size between 1 and 7.
     130        static int legacyFontSize(Document*, int pixelFontSize, bool shouldUseFixedDefaultSize);
     131
     132    private:
    132133
    133134        // When the CSS keyword "larger" is used, this function will attempt to match within the keyword
  • trunk/WebCore/editing/ApplyStyleCommand.cpp

    r67154 r67170  
    3232#include "CSSProperty.h"
    3333#include "CSSPropertyNames.h"
     34#include "CSSStyleSelector.h"
    3435#include "CSSValueKeywords.h"
    3536#include "Document.h"
     
    3738#include "Frame.h"
    3839#include "HTMLElement.h"
     40#include "HTMLFontElement.h"
    3941#include "HTMLInterchange.h"
    4042#include "HTMLNames.h"
     
    111113    void init(PassRefPtr<CSSStyleDeclaration>, const Position&);
    112114    void reconcileTextDecorationProperties(CSSMutableStyleDeclaration*);
    113     void extractTextStyles(CSSMutableStyleDeclaration*);
     115    void extractTextStyles(Document*, CSSMutableStyleDeclaration*, bool shouldUseFixedFontDefautlSize);
    114116
    115117    String m_cssStyle;
     
    148150    reconcileTextDecorationProperties(mutableStyle.get());
    149151    if (!document->frame()->editor()->shouldStyleWithCSS())
    150         extractTextStyles(mutableStyle.get());
     152        extractTextStyles(document, mutableStyle.get(), computedStyle->useFixedFontDefaultSize());
    151153
    152154    // Changing the whitespace style in a tab span would collapse the tab into a space.
     
    203205}
    204206
    205 void StyleChange::extractTextStyles(CSSMutableStyleDeclaration* style)
     207void StyleChange::extractTextStyles(Document* document, CSSMutableStyleDeclaration* style, bool shouldUseFixedFontDefautlSize)
    206208{
    207209    ASSERT(style);
     
    260262        else {
    261263            CSSPrimitiveValue* value = static_cast<CSSPrimitiveValue*>(fontSize.get());
    262 
    263             // Only accept absolute scale
    264264            if (value->primitiveType() >= CSSPrimitiveValue::CSS_PX && value->primitiveType() <= CSSPrimitiveValue::CSS_PC) {
    265                 float number = value->getFloatValue(CSSPrimitiveValue::CSS_PX);
    266                 if (number <= 9)
    267                     m_applyFontSize = "1";
    268                 else if (number <= 10)
    269                     m_applyFontSize = "2";
    270                 else if (number <= 13)
    271                     m_applyFontSize = "3";
    272                 else if (number <= 16)
    273                     m_applyFontSize = "4";
    274                 else if (number <= 18)
    275                     m_applyFontSize = "5";
    276                 else if (number <= 24)
    277                     m_applyFontSize = "6";
    278                 else
    279                     m_applyFontSize = "7";
     265                int pixelFontSize = value->getFloatValue(CSSPrimitiveValue::CSS_PX);
     266                int legacyFontSize = CSSStyleSelector::legacyFontSize(document, pixelFontSize, shouldUseFixedFontDefautlSize);
     267                // Use legacy font size only if pixel value matches exactly to that of legacy font size.
     268                if (CSSStyleSelector::fontSizeForKeyword(document, legacyFontSize - 1 + CSSValueXSmall, shouldUseFixedFontDefautlSize) == pixelFontSize) {
     269                    m_applyFontSize = String::number(legacyFontSize);
     270                    style->removeProperty(CSSPropertyFontSize);
     271                }
     272            } else if (CSSValueXSmall <= value->getIdent() && value->getIdent() <= CSSValueWebkitXxxLarge) {
     273                m_applyFontSize = String::number(value->getIdent() - CSSValueXSmall + 1);
     274                style->removeProperty(CSSPropertyFontSize);
    280275            }
    281             // Huge quirk in Microsoft Entourage is that they understand CSS font-size, but also write
    282             // out legacy 1-7 values in font tags (I guess for mailers that are not CSS-savvy at all,
    283             // like Eudora). Yes, they write out *both*. We need to write out both as well.
    284276        }
    285277    }
     
    11591151    const QualifiedName* element;
    11601152    const QualifiedName* attribute;
     1153    PassRefPtr<CSSValue> (*attributeToCSSValue)(int propertyID, const String&);
    11611154    EPushDownType pushDownType;
    11621155};
    11631156
     1157static PassRefPtr<CSSValue> stringToCSSValue(int propertyID, const String& value)
     1158{
     1159    RefPtr<CSSMutableStyleDeclaration> dummyStyle;
     1160    dummyStyle = CSSMutableStyleDeclaration::create();
     1161    dummyStyle->setProperty(propertyID, value);
     1162    return dummyStyle->getPropertyCSSValue(propertyID);
     1163}
     1164
     1165static PassRefPtr<CSSValue> fontSizeToCSSValue(int propertyID, const String& value)
     1166{
     1167    UNUSED_PARAM(propertyID);
     1168    ASSERT(propertyID == CSSPropertyFontSize);
     1169    int size;
     1170    if (!HTMLFontElement::cssValueFromFontSizeNumber(value, size))
     1171        return 0;
     1172    return CSSPrimitiveValue::createIdentifier(size);
     1173}
     1174
    11641175static const HTMLEquivalent HTMLEquivalents[] = {
    1165     { CSSPropertyFontWeight, false, CSSValueBold, &bTag, 0, ShouldBePushedDown },
    1166     { CSSPropertyFontWeight, false, CSSValueBold, &strongTag, 0, ShouldBePushedDown },
    1167     { CSSPropertyVerticalAlign, false, CSSValueSub, &subTag, 0, ShouldBePushedDown },
    1168     { CSSPropertyVerticalAlign, false, CSSValueSuper, &supTag, 0, ShouldBePushedDown },
    1169     { CSSPropertyFontStyle, false, CSSValueItalic, &iTag, 0, ShouldBePushedDown },
    1170     { CSSPropertyFontStyle, false, CSSValueItalic, &emTag, 0, ShouldBePushedDown },
     1176    { CSSPropertyFontWeight, false, CSSValueBold, &bTag, 0, 0, ShouldBePushedDown },
     1177    { CSSPropertyFontWeight, false, CSSValueBold, &strongTag, 0, 0, ShouldBePushedDown },
     1178    { CSSPropertyVerticalAlign, false, CSSValueSub, &subTag, 0, 0, ShouldBePushedDown },
     1179    { CSSPropertyVerticalAlign, false, CSSValueSuper, &supTag, 0, 0, ShouldBePushedDown },
     1180    { CSSPropertyFontStyle, false, CSSValueItalic, &iTag, 0, 0, ShouldBePushedDown },
     1181    { CSSPropertyFontStyle, false, CSSValueItalic, &emTag, 0, 0, ShouldBePushedDown },
    11711182
    11721183    // text-decorations should be CSSValueList
    1173     { CSSPropertyTextDecoration, true, CSSValueUnderline, &uTag, 0, ShouldBePushedDown },
    1174     { CSSPropertyTextDecoration, true, CSSValueLineThrough, &sTag, 0, ShouldBePushedDown },
    1175     { CSSPropertyTextDecoration, true, CSSValueLineThrough, &strikeTag, 0, ShouldBePushedDown },
    1176     { CSSPropertyWebkitTextDecorationsInEffect, true, CSSValueUnderline, &uTag, 0, ShouldBePushedDown },
    1177     { CSSPropertyWebkitTextDecorationsInEffect, true, CSSValueLineThrough, &sTag, 0, ShouldBePushedDown },
    1178     { CSSPropertyWebkitTextDecorationsInEffect, true, CSSValueLineThrough, &strikeTag, 0, ShouldBePushedDown },
     1184    { CSSPropertyTextDecoration, true, CSSValueUnderline, &uTag, 0, 0, ShouldBePushedDown },
     1185    { CSSPropertyTextDecoration, true, CSSValueLineThrough, &sTag, 0, 0, ShouldBePushedDown },
     1186    { CSSPropertyTextDecoration, true, CSSValueLineThrough, &strikeTag, 0, 0, ShouldBePushedDown },
     1187    { CSSPropertyWebkitTextDecorationsInEffect, true, CSSValueUnderline, &uTag, 0, 0, ShouldBePushedDown },
     1188    { CSSPropertyWebkitTextDecorationsInEffect, true, CSSValueLineThrough, &sTag, 0, 0, ShouldBePushedDown },
     1189    { CSSPropertyWebkitTextDecorationsInEffect, true, CSSValueLineThrough, &strikeTag, 0, 0, ShouldBePushedDown },
    11791190
    11801191    // FIXME: font attributes should only be removed if values were different
    1181     { CSSPropertyColor, false, CSSValueInvalid, &fontTag, &colorAttr, ShouldBePushedDown },
    1182     { CSSPropertyFontFamily, false, CSSValueInvalid, &fontTag, &faceAttr, ShouldBePushedDown },
    1183     { CSSPropertyFontSize, false, CSSValueInvalid, &fontTag, &sizeAttr, ShouldBePushedDown },
     1192    { CSSPropertyColor, false, CSSValueInvalid, &fontTag, &colorAttr, stringToCSSValue, ShouldBePushedDown },
     1193    { CSSPropertyFontFamily, false, CSSValueInvalid, &fontTag, &faceAttr, stringToCSSValue, ShouldBePushedDown },
     1194    { CSSPropertyFontSize, false, CSSValueInvalid, &fontTag, &sizeAttr, fontSizeToCSSValue, ShouldBePushedDown },
    11841195
    11851196    // unicode-bidi and direction are pushed down separately so don't push down with other styles.
    1186     { CSSPropertyUnicodeBidi, false, CSSValueInvalid, 0, &dirAttr, ShouldNotBePushedDown },
    1187     { CSSPropertyDirection, false, CSSValueInvalid, 0, &dirAttr, ShouldNotBePushedDown },
     1197    { CSSPropertyDirection, false, CSSValueInvalid, 0, &dirAttr, stringToCSSValue, ShouldNotBePushedDown },
     1198    { CSSPropertyUnicodeBidi, false, CSSValueInvalid, 0, &dirAttr, stringToCSSValue, ShouldNotBePushedDown },
    11881199};
    11891200
     
    12041215        if (!styleValue)
    12051216            continue;
    1206         RefPtr<CSSPrimitiveValue> mapValue = CSSPrimitiveValue::createIdentifier(equivalent.primitiveId);
     1217        RefPtr<CSSValue> mapValue;
     1218        if (equivalent.attribute)
     1219            mapValue = equivalent.attributeToCSSValue(equivalent.propertyID, element->getAttribute(*equivalent.attribute));
     1220        else
     1221            mapValue = CSSPrimitiveValue::createIdentifier(equivalent.primitiveId).get();
    12071222
    12081223        if (equivalent.isValueList && styleValue->isValueList() && static_cast<CSSValueList*>(styleValue.get())->hasValue(mapValue.get()))
    12091224            continue; // If CSS value assumes CSSValueList, then only skip if the value was present in style to apply.
    1210         else if (styleValue->cssText() == mapValue->cssText())
     1225        else if (mapValue && styleValue->cssText() == mapValue->cssText())
    12111226            continue; // If CSS value is primitive, then skip if they are equal.
    12121227
    1213         if (extractedStyle) {
    1214             if (equivalent.primitiveId == CSSValueInvalid)
    1215                 extractedStyle->setProperty(equivalent.propertyID, element->getAttribute(*equivalent.attribute));
    1216             else
    1217                 extractedStyle->setProperty(equivalent.propertyID, mapValue->cssText());
    1218         }
     1228        if (extractedStyle)
     1229            extractedStyle->setProperty(equivalent.propertyID, mapValue->cssText());
    12191230
    12201231        if (mode == RemoveNone)
Note: See TracChangeset for help on using the changeset viewer.