Changeset 67102 in webkit


Ignore:
Timestamp:
Sep 9, 2010 11:55:13 AM (14 years ago)
Author:
rniwa@webkit.org
Message:

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.
Location:
trunk
Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r67101 r67102  
     12010-09-09  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        queryCommandValue('FontSize') returns pixel values instead of IE font numbers
     6        https://bugs.webkit.org/show_bug.cgi?id=21033
     7
     8        Added a test to ensure queryCommandValue('fontSize') returns legacy font size
     9        for both variable width and fixed width fonts.
     10
     11        * editing/execCommand/query-font-size-expected.txt: Added.
     12        * editing/execCommand/query-font-size.html: Added.
     13        * fast/serializer: Added.
     14
    1152010-09-09  Tony Chang  <tony@chromium.org>
    216
  • trunk/WebCore/ChangeLog

    r67100 r67102  
     12010-09-09  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        QueryCommandValue('FontSize') returns pixel values instead of IE font numbers
     6        https://bugs.webkit.org/show_bug.cgi?id=21033
     7
     8        Modified selectionStartCSSPropertyValue to return legacy font size instead of pixel size.
     9        To implement the conversion between pixel font size and legacy font size,
     10        added legacyFontSize to CSSStyleSelector with a helper static function findNearestLegacyFontSize.
     11
     12        Fixed a bug in selectionComputedStyle where it obtains the style of the previous editing position
     13        even when the selection is a range. This change revealed a crash in executeToggleStyleInList,
     14        which was also fixed.
     15
     16        Test: editing/execCommand/query-font-size.html
     17
     18        * css/CSSComputedStyleDeclaration.cpp:
     19        (WebCore::CSSComputedStyleDeclaration::getFontSizeCSSValuePreferringKeyword): Corrected style.
     20        (WebCore::CSSComputedStyleDeclaration::useFixedFontDefaultSize): Added.
     21        * css/CSSComputedStyleDeclaration.h:
     22        * css/CSSStyleSelector.cpp:
     23        (WebCore::CSSStyleSelector::fontSizeForKeyword): Renamed fixed/monospace to shouldUseFixedDefaultSize.
     24        (WebCore::findNearestLegacyFontSize): Added, a helper for legacyFontSize.
     25        (WebCore::CSSStyleSelector::legacyFontSize): Added.
     26        * css/CSSStyleSelector.h:
     27        * editing/Editor.cpp:
     28        (WebCore::Editor::selectionStartCSSPropertyValue): Added a conversion from pixel to legacy font size.
     29        * editing/EditorCommand.cpp:
     30        (WebCore::executeToggleStyleInList): Crash fix.
     31        * page/Frame.cpp:
     32        (WebCore::Frame::selectionComputedStyle): See above.
     33
    1342010-09-09  Robert Hogan  <robert@webkit.org>
    235
  • trunk/WebCore/css/CSSComputedStyleDeclaration.cpp

    r67032 r67102  
    572572PassRefPtr<CSSValue> CSSComputedStyleDeclaration::getFontSizeCSSValuePreferringKeyword() const
    573573{
    574     Node* node = m_node.get();
    575     if (!node)
     574    if (!m_node)
    576575        return 0;
    577576
    578     node->document()->updateLayoutIgnorePendingStylesheets();
    579 
    580     RefPtr<RenderStyle> style = node->computedStyle(m_pseudoElementSpecifier);
     577    m_node->document()->updateLayoutIgnorePendingStylesheets();
     578
     579    RefPtr<RenderStyle> style = m_node->computedStyle(m_pseudoElementSpecifier);
    581580    if (!style)
    582581        return 0;
     
    586585
    587586    return CSSPrimitiveValue::create(style->fontDescription().computedPixelSize(), CSSPrimitiveValue::CSS_PX);
     587}
     588
     589bool CSSComputedStyleDeclaration::useFixedFontDefaultSize() const
     590{
     591    if (!m_node)
     592        return false;
     593
     594    RefPtr<RenderStyle> style = m_node->computedStyle(m_pseudoElementSpecifier);
     595    if (!style)
     596        return false;
     597
     598    return style->fontDescription().useFixedDefaultSize();
    588599}
    589600
  • trunk/WebCore/css/CSSComputedStyleDeclaration.h

    r63014 r67102  
    5959    PassRefPtr<CSSValue> getPropertyCSSValue(int propertyID, EUpdateLayout) const;
    6060    PassRefPtr<CSSValue> getFontSizeCSSValuePreferringKeyword() const;
     61    bool useFixedFontDefaultSize() const;
    6162#if ENABLE(SVG)
    6263    PassRefPtr<CSSValue> getSVGPropertyCSSValue(int propertyID, EUpdateLayout) const;
  • trunk/WebCore/css/CSSStyleSelector.cpp

    r67032 r67102  
    63126312static const float fontSizeFactors[totalKeywords] = { 0.60f, 0.75f, 0.89f, 1.0f, 1.2f, 1.5f, 2.0f, 3.0f };
    63136313
    6314 float CSSStyleSelector::fontSizeForKeyword(Document* document, int keyword, bool fixed)
     6314float CSSStyleSelector::fontSizeForKeyword(Document* document, int keyword, bool shouldUseFixedDefaultSize)
    63156315{
    63166316    Settings* settings = document->settings();
     
    63196319
    63206320    bool quirksMode = document->inQuirksMode();
    6321     int mediumSize = fixed ? settings->defaultFixedFontSize() : settings->defaultFontSize();
     6321    int mediumSize = shouldUseFixedDefaultSize ? settings->defaultFixedFontSize() : settings->defaultFontSize();
    63226322    if (mediumSize >= fontSizeTableMin && mediumSize <= fontSizeTableMax) {
    63236323        // Look up the entry in the table.
     
    63306330    float minLogicalSize = max(settings->minimumLogicalFontSize(), 1);
    63316331    return max(fontSizeFactors[keyword - CSSValueXxSmall]*mediumSize, minLogicalSize);
     6332}
     6333
     6334template<typename T>
     6335static int findNearestLegacyFontSize(int pixelFontSize, const T* table, int multiplier)
     6336{
     6337    // Ignore table[0] because xx-small does not correspond to any legacy font size.
     6338    for (int i = 1; i < totalKeywords - 1; i++) {
     6339        if (pixelFontSize * 2 < (table[i] + table[i + 1]) * multiplier)
     6340            return i;
     6341    }
     6342    return totalKeywords - 1;
     6343}
     6344
     6345int CSSStyleSelector::legacyFontSize(Document* document, int pixelFontSize, bool shouldUseFixedDefaultSize)
     6346{
     6347    Settings* settings = document->settings();
     6348    if (!settings)
     6349        return 1;
     6350
     6351    bool quirksMode = document->inQuirksMode();
     6352    int mediumSize = shouldUseFixedDefaultSize ? settings->defaultFixedFontSize() : settings->defaultFontSize();
     6353    if (mediumSize >= fontSizeTableMin && mediumSize <= fontSizeTableMax) {
     6354        int row = mediumSize - fontSizeTableMin;
     6355        return findNearestLegacyFontSize<int>(pixelFontSize, quirksMode ? quirksFontSizeTable[row] : strictFontSizeTable[row], 1);
     6356    }
     6357
     6358    return findNearestLegacyFontSize<float>(pixelFontSize, fontSizeFactors, mediumSize);
    63326359}
    63336360
  • trunk/WebCore/css/CSSStyleSelector.h

    r66339 r67102  
    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
    125128    private:
    126129        // Given a CSS keyword in the range (xx-small to -webkit-xxx-large), this function will return
    127130        // the correct font size scaled relative to the user's default (medium).
    128         static float fontSizeForKeyword(Document*, int keyword, bool monospace);
     131        static float fontSizeForKeyword(Document*, int keyword, bool shouldUseFixedDefaultSize);
    129132
    130133        // When the CSS keyword "larger" is used, this function will attempt to match within the keyword
  • trunk/WebCore/editing/Editor.cpp

    r67049 r67102  
    3434#include "CSSProperty.h"
    3535#include "CSSPropertyNames.h"
     36#include "CSSStyleSelector.h"
    3637#include "CSSValueKeywords.h"
    3738#include "CharacterNames.h"
     
    939940{
    940941    Node* nodeToRemove;
    941     RefPtr<CSSStyleDeclaration> selectionStyle = m_frame->selectionComputedStyle(nodeToRemove);
     942    RefPtr<CSSComputedStyleDeclaration> selectionStyle = m_frame->selectionComputedStyle(nodeToRemove);
    942943    if (!selectionStyle)
    943944        return String();
     
    964965            }
    965966        }
     967    }
     968
     969    if (propertyID == CSSPropertyFontSize) {
     970        RefPtr<CSSValue> value = selectionStyle->getPropertyCSSValue(CSSPropertyFontSize);
     971        ASSERT(value->isPrimitiveValue());
     972        int fontPixelSize = static_cast<CSSPrimitiveValue*>(value.get())->getIntValue(CSSPrimitiveValue::CSS_PX);
     973        int size = CSSStyleSelector::legacyFontSize(m_frame->document(), fontPixelSize, selectionStyle->useFixedFontDefaultSize());
     974        return String::number(size);
    966975    }
    967976
  • trunk/WebCore/editing/EditorCommand.cpp

    r66643 r67102  
    134134    Node* nodeToRemove = 0;
    135135    RefPtr<CSSComputedStyleDeclaration> selectionStyle = frame->selectionComputedStyle(nodeToRemove);
     136    if (!selectionStyle)
     137        return false;
     138
    136139    RefPtr<CSSValue> selectedCSSValue = selectionStyle->getPropertyCSSValue(propertyID);
    137140    String newStyle = "none";
  • trunk/WebCore/page/Frame.cpp

    r66963 r67102  
    746746    Position pos = range->editingStartPosition();
    747747
     748    // If the pos is at the end of a text node, then this node is not fully selected.
     749    // Move it to the next deep equivalent position to avoid removing the style from this node.
     750    // e.g. if pos was at Position("hello", 5) in <b>hello<div>world</div></b>, we want Position("world", 0) instead.
     751    // We only do this for range because caret at Position("hello", 5) in <b>hello</b>world should give you font-weight: bold.
     752    Node* posNode = pos.containerNode();
     753    if (selection()->isRange() && posNode && posNode->isTextNode() && pos.computeOffsetInContainerNode() == posNode->maxCharacterOffset())
     754        pos = nextVisuallyDistinctCandidate(pos);
     755
    748756    Element *elem = pos.element();
    749757    if (!elem)
Note: See TracChangeset for help on using the changeset viewer.