Changeset 79398 in webkit


Ignore:
Timestamp:
Feb 22, 2011, 9:35:44 PM (14 years ago)
Author:
rniwa@webkit.org
Message:

2011-02-22 Ryosuke Niwa <rniwa@webkit.org>

Reviewed by Darin Adler.

Make Editor::selectionComputedStyle return EditingStyle
https://bugs.webkit.org/show_bug.cgi?id=54933

Renamed selectionComputedStyle to selectionStartStyle and changed the return type to EditingStyle.
It also no longer takes a boolean shouldUseFixedFontDefaultSize.

Also added EditingStyle::mergeTypingStyle which replaced old editingStyleIncludingTypingStyle. This function
doesn't extract inheritable properties prior to merge because this turned out be a bug, which was revealed
by an existing layout test only after the code was shared with selectionStartStyle.

No tests are added since this is a refactoring.

  • editing/CompositeEditCommand.cpp: (WebCore::CompositeEditCommand::moveParagraphs): Calls EditingStyle::create and EditingStyle::mergeTypingStyle. (WebCore::CompositeEditCommand::breakOutOfEmptyListItem): Ditto.
  • editing/EditingStyle.cpp: Removed editingStyleIncludingTypingStyle. (WebCore::EditingStyle::mergeTypingStyle): Added.
  • editing/EditingStyle.h: (WebCore::EditingStyle::shouldUseFixedDefaultFontSize): Added.
  • editing/Editor.cpp: (WebCore::Editor::selectionStartHasStyle): Calls selectionStartStyle. (WebCore::Editor::selectionHasStyle): Ditto. (WebCore::Editor::selectionStartCSSPropertyValue): Ditto. (WebCore::Editor::selectionStartStyle): Renamed from selectionComputedStyle; returns EditingStyle.
  • editing/Editor.h:
  • editing/EditorCommand.cpp: (WebCore::executeToggleStyleInList): Calls selectionStartStyle.
  • editing/InsertLineBreakCommand.cpp:
  • editing/InsertParagraphSeparatorCommand.cpp: (WebCore::InsertParagraphSeparatorCommand::calculateStyleBeforeInsertion): Calls EditingStyle::create and EditingStyle::mergeTypingStyle.
  • editing/ReplaceSelectionCommand.cpp: (WebCore::ReplaceSelectionCommand::doApply): Ditto.
Location:
trunk/Source/WebCore
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r79397 r79398  
     12011-02-22  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        Make Editor::selectionComputedStyle return EditingStyle
     6        https://bugs.webkit.org/show_bug.cgi?id=54933
     7
     8        Renamed selectionComputedStyle to selectionStartStyle and changed the return type to EditingStyle.
     9        It also no longer takes a boolean shouldUseFixedFontDefaultSize.
     10
     11        Also added EditingStyle::mergeTypingStyle which replaced old editingStyleIncludingTypingStyle. This function
     12        doesn't extract inheritable properties prior to merge because this turned out be a bug, which was revealed
     13        by an existing layout test only after the code was shared with selectionStartStyle.
     14
     15        No tests are added since this is a refactoring.
     16
     17        * editing/CompositeEditCommand.cpp:
     18        (WebCore::CompositeEditCommand::moveParagraphs): Calls EditingStyle::create and EditingStyle::mergeTypingStyle.
     19        (WebCore::CompositeEditCommand::breakOutOfEmptyListItem): Ditto.
     20        * editing/EditingStyle.cpp: Removed editingStyleIncludingTypingStyle.
     21        (WebCore::EditingStyle::mergeTypingStyle): Added.
     22        * editing/EditingStyle.h:
     23        (WebCore::EditingStyle::shouldUseFixedDefaultFontSize): Added.
     24        * editing/Editor.cpp:
     25        (WebCore::Editor::selectionStartHasStyle): Calls selectionStartStyle.
     26        (WebCore::Editor::selectionHasStyle): Ditto.
     27        (WebCore::Editor::selectionStartCSSPropertyValue): Ditto.
     28        (WebCore::Editor::selectionStartStyle): Renamed from selectionComputedStyle; returns EditingStyle.
     29        * editing/Editor.h:
     30        * editing/EditorCommand.cpp:
     31        (WebCore::executeToggleStyleInList): Calls selectionStartStyle.
     32        * editing/InsertLineBreakCommand.cpp:
     33        * editing/InsertParagraphSeparatorCommand.cpp:
     34        (WebCore::InsertParagraphSeparatorCommand::calculateStyleBeforeInsertion): Calls EditingStyle::create and
     35        EditingStyle::mergeTypingStyle.
     36        * editing/ReplaceSelectionCommand.cpp:
     37        (WebCore::ReplaceSelectionCommand::doApply): Ditto.
     38
    1392011-02-22  Robert Hogan  <robert@webkit.org>
    240
  • trunk/Source/WebCore/editing/CompositeEditCommand.cpp

    r79196 r79398  
    968968    RefPtr<EditingStyle> styleInEmptyParagraph;
    969969    if (startOfParagraphToMove == endOfParagraphToMove && preserveStyle) {
    970         styleInEmptyParagraph = editingStyleIncludingTypingStyle(startOfParagraphToMove.deepEquivalent());
     970        styleInEmptyParagraph = EditingStyle::create(startOfParagraphToMove.deepEquivalent());
     971        styleInEmptyParagraph->mergeTypingStyle(document());
    971972        // The moved paragraph should assume the block style of the destination.
    972973        styleInEmptyParagraph->removeBlockProperties();
     
    10371038        return false;
    10381039
    1039     RefPtr<EditingStyle> style = editingStyleIncludingTypingStyle(endingSelection().start());
     1040    RefPtr<EditingStyle> style = EditingStyle::create(endingSelection().start());
     1041    style->mergeTypingStyle(document());
    10401042
    10411043    ContainerNode* listNode = emptyListItem->parentNode();
  • trunk/Source/WebCore/editing/EditingStyle.cpp

    r79382 r79398  
    403403}
    404404
    405 PassRefPtr<EditingStyle> editingStyleIncludingTypingStyle(const Position& position)
    406 {
    407     RefPtr<EditingStyle> editingStyle = EditingStyle::create(position);
    408     RefPtr<EditingStyle> typingStyle = position.anchorNode()->document()->frame()->selection()->typingStyle();
    409     if (typingStyle && typingStyle->style())
    410         editingStyle->style()->merge(copyEditingProperties(typingStyle->style()).get());
    411     return editingStyle;
     405void EditingStyle::mergeTypingStyle(Document* document)
     406{
     407    ASSERT(document);
     408
     409    RefPtr<EditingStyle> typingStyle = document->frame()->selection()->typingStyle();
     410    if (!typingStyle || !typingStyle->style() || typingStyle == this)
     411        return;
     412
     413    if (m_mutableStyle)
     414        m_mutableStyle->merge(typingStyle->style(), true);
     415    else
     416        m_mutableStyle = typingStyle->style()->copy();
    412417}
    413418   
  • trunk/Source/WebCore/editing/EditingStyle.h

    r79382 r79398  
    4343class CSSComputedStyleDeclaration;
    4444class CSSMutableStyleDeclaration;
     45class Document;
    4546class Node;
    4647class Position;
     
    9798    }
    9899    void prepareToApplyAt(const Position&, ShouldPreserveWritingDirection = DoNotPreserveWritingDirection);
     100    void mergeTypingStyle(Document*);
    99101
    100102    float fontSizeDelta() const { return m_fontSizeDelta; }
    101103    bool hasFontSizeDelta() const { return m_fontSizeDelta != NoFontDelta; }
     104    bool shouldUseFixedDefaultFontSize() const { return m_shouldUseFixedDefaultFontSize; }
    102105
    103106private:
     
    117120};
    118121
    119 PassRefPtr<EditingStyle> editingStyleIncludingTypingStyle(const Position&);
    120    
    121122} // namespace WebCore
    122123
  • trunk/Source/WebCore/editing/Editor.cpp

    r79196 r79398  
    986986bool Editor::selectionStartHasStyle(CSSStyleDeclaration* style) const
    987987{
    988     bool shouldUseFixedFontDefaultSize;
    989     RefPtr<CSSMutableStyleDeclaration> selectionStyle = selectionComputedStyle(shouldUseFixedFontDefaultSize);
    990     if (!selectionStyle)
    991         return false;
    992     return triStateOfStyle(style, selectionStyle.get()) == TrueTriState;
     988    RefPtr<EditingStyle> selectionStyle = selectionStartStyle();
     989    if (!selectionStyle || !selectionStyle->style())
     990        return false;
     991    return triStateOfStyle(style, selectionStyle->style()) == TrueTriState;
    993992}
    994993
    995994TriState Editor::selectionHasStyle(CSSStyleDeclaration* style) const
    996995{
     996    if (!m_frame->selection()->isCaretOrRange())
     997        return FalseTriState;
     998
     999    if (m_frame->selection()->isCaret()) {
     1000        RefPtr<EditingStyle> selectionStyle = selectionStartStyle();
     1001        if (!selectionStyle || !selectionStyle->style())
     1002            return FalseTriState;
     1003        return triStateOfStyle(style, selectionStyle->style());
     1004    }
     1005
    9971006    TriState state = FalseTriState;
    998 
    999     if (!m_frame->selection()->isRange()) {
    1000         bool shouldUseFixedFontDefaultSize;
    1001         RefPtr<CSSMutableStyleDeclaration> selectionStyle = selectionComputedStyle(shouldUseFixedFontDefaultSize);
    1002         if (!selectionStyle)
    1003             return FalseTriState;
    1004         state = triStateOfStyle(style, selectionStyle.get());
    1005     } else {
    1006         for (Node* node = m_frame->selection()->start().deprecatedNode(); node; node = node->traverseNextNode()) {
    1007             RefPtr<CSSComputedStyleDeclaration> nodeStyle = computedStyle(node);
    1008             if (nodeStyle) {
    1009                 TriState nodeState = triStateOfStyle(style, nodeStyle.get(), !node->isTextNode());
    1010                 if (node == m_frame->selection()->start().deprecatedNode())
    1011                     state = nodeState;
    1012                 else if (state != nodeState && node->isTextNode()) {
    1013                     state = MixedTriState;
    1014                     break;
    1015                 }
     1007    for (Node* node = m_frame->selection()->start().deprecatedNode(); node; node = node->traverseNextNode()) {
     1008        RefPtr<CSSComputedStyleDeclaration> nodeStyle = computedStyle(node);
     1009        if (nodeStyle) {
     1010            TriState nodeState = triStateOfStyle(style, nodeStyle.get(), !node->isTextNode());
     1011            if (node == m_frame->selection()->start().deprecatedNode())
     1012                state = nodeState;
     1013            else if (state != nodeState && node->isTextNode()) {
     1014                state = MixedTriState;
     1015                break;
    10161016            }
    1017             if (node == m_frame->selection()->end().deprecatedNode())
    1018                 break;
    10191017        }
     1018        if (node == m_frame->selection()->end().deprecatedNode())
     1019            break;
    10201020    }
    10211021
     
    10411041String Editor::selectionStartCSSPropertyValue(int propertyID)
    10421042{
    1043     bool shouldUseFixedFontDefaultSize = false;
    1044     RefPtr<CSSMutableStyleDeclaration> selectionStyle = selectionComputedStyle(shouldUseFixedFontDefaultSize);
    1045     if (!selectionStyle)
     1043    RefPtr<EditingStyle> selectionStyle = selectionStartStyle();
     1044    if (!selectionStyle->style())
    10461045        return String();
    10471046
    1048     String value = selectionStyle->getPropertyValue(propertyID);
     1047    String value = selectionStyle->style()->getPropertyValue(propertyID);
    10491048
    10501049    // If background color is transparent, traverse parent nodes until we hit a different value or document root
    10511050    // Also, if the selection is a range, ignore the background color at the start of selection,
    10521051    // and find the background color of the common ancestor.
    1053     if (propertyID == CSSPropertyBackgroundColor && (m_frame->selection()->isRange() || hasTransparentBackgroundColor(selectionStyle.get()))) {
     1052    if (propertyID == CSSPropertyBackgroundColor && (m_frame->selection()->isRange() || hasTransparentBackgroundColor(selectionStyle->style()))) {
    10541053        RefPtr<Range> range(m_frame->selection()->toNormalizedRange());
    10551054        ExceptionCode ec = 0;
    10561055        for (Node* ancestor = range->commonAncestorContainer(ec); ancestor; ancestor = ancestor->parentNode()) {
    1057             selectionStyle = computedStyle(ancestor)->copy();
    1058             if (!hasTransparentBackgroundColor(selectionStyle.get())) {
    1059                 value = selectionStyle->getPropertyValue(CSSPropertyBackgroundColor);
    1060                 break;
    1061             }
     1056            RefPtr<CSSComputedStyleDeclaration> ancestorStyle = computedStyle(ancestor);
     1057            if (!hasTransparentBackgroundColor(ancestorStyle.get()))
     1058                return ancestorStyle->getPropertyValue(CSSPropertyBackgroundColor);
    10621059        }
    10631060    }
    10641061
    10651062    if (propertyID == CSSPropertyFontSize) {
    1066         RefPtr<CSSValue> cssValue = selectionStyle->getPropertyCSSValue(CSSPropertyFontSize);
     1063        RefPtr<CSSValue> cssValue = selectionStyle->style()->getPropertyCSSValue(CSSPropertyFontSize);
    10671064        if (cssValue->isPrimitiveValue()) {
    10681065            value = String::number(legacyFontSizeFromCSSValue(m_frame->document(), static_cast<CSSPrimitiveValue*>(cssValue.get()),
    1069                 shouldUseFixedFontDefaultSize, AlwaysUseLegacyFontSize));
     1066                selectionStyle->shouldUseFixedDefaultFontSize(), AlwaysUseLegacyFontSize));
    10701067        }
    10711068    }
     
    31773174}
    31783175
    3179 PassRefPtr<CSSMutableStyleDeclaration> Editor::selectionComputedStyle(bool& shouldUseFixedFontDefaultSize) const
     3176PassRefPtr<EditingStyle> Editor::selectionStartStyle() const
    31803177{
    31813178    if (m_frame->selection()->isNone())
     
    31973194        return 0;
    31983195
    3199     RefPtr<Element> styleElement = element;
    3200     RefPtr<CSSComputedStyleDeclaration> style = computedStyle(styleElement.release());
    3201     RefPtr<CSSMutableStyleDeclaration> mutableStyle = style->copy();
    3202     shouldUseFixedFontDefaultSize = style->useFixedFontDefaultSize();
    3203 
    3204     if (!m_frame->selection()->typingStyle())
    3205         return mutableStyle;
    3206 
    3207     RefPtr<EditingStyle> typingStyle = m_frame->selection()->typingStyle()->copy();
    3208     typingStyle->prepareToApplyAt(position);
    3209     mutableStyle->merge(typingStyle->style());
    3210 
    3211     return mutableStyle;
     3196    RefPtr<EditingStyle> style = EditingStyle::create(element, EditingStyle::AllProperties);
     3197    style->mergeTypingStyle(m_frame->document());
     3198    return style;
    32123199}
    32133200
  • trunk/Source/WebCore/editing/Editor.h

    r78632 r79398  
    366366    void setMarkedTextMatchesAreHighlighted(bool);
    367367
    368     PassRefPtr<CSSMutableStyleDeclaration> selectionComputedStyle(bool& shouldUseFixedFontDefaultSize) const;
     368    PassRefPtr<EditingStyle> selectionStartStyle() const;
    369369
    370370    void textFieldDidBeginEditing(Element*);
  • trunk/Source/WebCore/editing/EditorCommand.cpp

    r78632 r79398  
    133133{
    134134    ExceptionCode ec = 0;
    135     bool shouldUseFixedFontDefaultSize;
    136     RefPtr<CSSMutableStyleDeclaration> selectionStyle = frame->editor()->selectionComputedStyle(shouldUseFixedFontDefaultSize);
    137     if (!selectionStyle)
    138         return false;
    139 
    140     RefPtr<CSSValue> selectedCSSValue = selectionStyle->getPropertyCSSValue(propertyID);
     135    RefPtr<EditingStyle> selectionStyle = frame->editor()->selectionStartStyle();
     136    if (!selectionStyle || !selectionStyle->style())
     137        return false;
     138
     139    RefPtr<CSSValue> selectedCSSValue = selectionStyle->style()->getPropertyCSSValue(propertyID);
    141140    String newStyle = "none";
    142141    if (selectedCSSValue->isValueList()) {
  • trunk/Source/WebCore/editing/InsertLineBreakCommand.cpp

    r79196 r79398  
    2727#include "InsertLineBreakCommand.h"
    2828
    29 #include "CSSMutableStyleDeclaration.h"
    3029#include "Document.h"
    3130#include "Frame.h"
  • trunk/Source/WebCore/editing/InsertParagraphSeparatorCommand.cpp

    r79196 r79398  
    7979    if (!isStartOfParagraph(visiblePos) && !isEndOfParagraph(visiblePos))
    8080        return;
    81    
    82     m_style = editingStyleIncludingTypingStyle(pos);
     81
     82    ASSERT(pos.isNotNull());
     83    m_style = EditingStyle::create(pos);
     84    m_style->mergeTypingStyle(pos.anchorNode()->document());
    8385}
    8486
  • trunk/Source/WebCore/editing/ReplaceSelectionCommand.cpp

    r79196 r79398  
    798798        m_matchStyle = false;
    799799   
    800     if (m_matchStyle)
    801         m_insertionStyle = editingStyleIncludingTypingStyle(selection.start());
     800    if (m_matchStyle) {
     801        m_insertionStyle = EditingStyle::create(selection.start());
     802        m_insertionStyle->mergeTypingStyle(document());
     803    }
    802804
    803805    VisiblePosition visibleStart = selection.visibleStart();
Note: See TracChangeset for help on using the changeset viewer.