Changeset 72573 in webkit


Ignore:
Timestamp:
Nov 22, 2010 4:25:10 PM (13 years ago)
Author:
rniwa@webkit.org
Message:

2010-11-22 Ryosuke Niwa <rniwa@webkit.org>

Reviewed by Tony Chang.

SelectionController::typingStyle() should return EditingStyle*
https://bugs.webkit.org/show_bug.cgi?id=49813

Changed the return value of SelectionController::typingStyle() to EditingStyle*.
Also added SelectionController::copyTypingStyle() to copy the typing style
as an instance of CSSMutableStyleDeclaration.

No tests are added since this is no behavioral change.

  • WebView/WebFrame.mm: (-[WebFrame _typingStyle]): Calls SelectionController::copyTypingStyle()

2010-11-22 Ryosuke Niwa <rniwa@webkit.org>

Reviewed by Tony Chang.

SelectionController::typingStyle() should return EditingStyle*
https://bugs.webkit.org/show_bug.cgi?id=49813

Changed the return type of SelectionController::typingStyle to EditingStyle*.

Extracted textDirection from Editor::textDirectionForSelection to hide the underlying
CSSMutableStyleDeclaration.

Also extracted the code to preserve unicode-bidi and direction CSS properties in
InsertTextCommand::input, and moved into EditingStyle::prepareToApplyAt. ShouldPreserveWritingDirection,
which is added to the argument list of EditingStyle::prepareToApplyAt, decides whether or not
these two properties are preserved.

Also added SelectionController::copyTypingStyle() to copy the typing style as an instance of
CSSMutableStyleDeclaration.

No new tests are added since this is a refactoring.

  • editing/EditingStyle.cpp: (WebCore::EditingStyle::textDirection): Extracted from Editor::textDirectionForSelection. (WebCore::EditingStyle::removeStyleConflictingWithStyleOfNode): Added a missing null check. (WebCore::EditingStyle::prepareToApplyAt): See above. (WebCore::editingStyleIncludingTypingStyle): Calls SelectionController::typingStyle.
  • editing/EditingStyle.h: Moved WritingDirection from Editor.h
  • editing/Editor.cpp: (WebCore::Editor::textDirectionForSelection): Calls EditingStyle::textDirection. (WebCore::Editor::computeAndSetTypingStyle): Calls SelectionController::typingStyle. (WebCore::Editor::selectionComputedStyle): Ditto. (WebCore::Editor::styleForSelectionStart): Ditto.
  • editing/Editor.h:
  • editing/InsertLineBreakCommand.cpp: (WebCore::InsertLineBreakCommand::doApply): Ditto.
  • editing/InsertTextCommand.cpp: (WebCore::InsertTextCommand::input): Calls EditingStyle::prepareToApplyAt with PreserveWritingDirection.
  • editing/SelectionController.h: (WebCore::SelectionController::typingStyle): Returns EditingStyle* rather than CSSMutableStyleDeclaration*. (WebCore::SelectionController::copyTypingStyle): Added.
Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r72572 r72573  
     12010-11-22  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Reviewed by Tony Chang.
     4
     5        SelectionController::typingStyle() should return EditingStyle*
     6        https://bugs.webkit.org/show_bug.cgi?id=49813
     7
     8        Changed the return type of SelectionController::typingStyle to EditingStyle*.
     9
     10        Extracted textDirection from Editor::textDirectionForSelection to hide the underlying
     11        CSSMutableStyleDeclaration.
     12
     13        Also extracted the code to preserve unicode-bidi and direction CSS properties in
     14        InsertTextCommand::input, and moved into EditingStyle::prepareToApplyAt. ShouldPreserveWritingDirection,
     15        which is added to the argument list of EditingStyle::prepareToApplyAt, decides whether or not
     16        these two properties are preserved.
     17
     18        Also added SelectionController::copyTypingStyle() to copy the typing style as an instance of
     19        CSSMutableStyleDeclaration.
     20
     21        No new tests are added since this is a refactoring.
     22
     23        * editing/EditingStyle.cpp:
     24        (WebCore::EditingStyle::textDirection): Extracted from Editor::textDirectionForSelection.
     25        (WebCore::EditingStyle::removeStyleConflictingWithStyleOfNode): Added a missing null check.
     26        (WebCore::EditingStyle::prepareToApplyAt): See above.
     27        (WebCore::editingStyleIncludingTypingStyle): Calls SelectionController::typingStyle.
     28        * editing/EditingStyle.h: Moved WritingDirection from Editor.h
     29        * editing/Editor.cpp:
     30        (WebCore::Editor::textDirectionForSelection): Calls EditingStyle::textDirection.
     31        (WebCore::Editor::computeAndSetTypingStyle): Calls SelectionController::typingStyle.
     32        (WebCore::Editor::selectionComputedStyle): Ditto.
     33        (WebCore::Editor::styleForSelectionStart): Ditto.
     34        * editing/Editor.h:
     35        * editing/InsertLineBreakCommand.cpp:
     36        (WebCore::InsertLineBreakCommand::doApply): Ditto.
     37        * editing/InsertTextCommand.cpp:
     38        (WebCore::InsertTextCommand::input): Calls EditingStyle::prepareToApplyAt with PreserveWritingDirection.
     39        * editing/SelectionController.h:
     40        (WebCore::SelectionController::typingStyle): Returns EditingStyle* rather than CSSMutableStyleDeclaration*.
     41        (WebCore::SelectionController::copyTypingStyle): Added.
     42
    1432010-11-22  Patrick Gansterer  <paroga@webkit.org>
    244
  • trunk/WebCore/editing/EditingStyle.cpp

    r72500 r72573  
    3131#include "CSSComputedStyleDeclaration.h"
    3232#include "CSSMutableStyleDeclaration.h"
     33#include "CSSValueKeywords.h"
    3334#include "Frame.h"
    3435#include "RenderStyle.h"
     
    142143}
    143144
     145bool EditingStyle::textDirection(WritingDirection& writingDirection) const
     146{
     147    RefPtr<CSSValue> unicodeBidi = m_mutableStyle->getPropertyCSSValue(CSSPropertyUnicodeBidi);
     148    if (!unicodeBidi)
     149        return false;
     150
     151    ASSERT(unicodeBidi->isPrimitiveValue());
     152    int unicodeBidiValue = static_cast<CSSPrimitiveValue*>(unicodeBidi.get())->getIdent();
     153    if (unicodeBidiValue == CSSValueEmbed) {
     154        RefPtr<CSSValue> direction = m_mutableStyle->getPropertyCSSValue(CSSPropertyDirection);
     155        ASSERT(!direction || direction->isPrimitiveValue());
     156        if (!direction)
     157            return false;
     158
     159        writingDirection = static_cast<CSSPrimitiveValue*>(direction.get())->getIdent() == CSSValueLtr ? LeftToRightWritingDirection : RightToLeftWritingDirection;
     160
     161        return true;
     162    }
     163
     164    if (unicodeBidiValue == CSSValueNormal) {
     165        writingDirection = NaturalWritingDirection;
     166        return true;
     167    }
     168
     169    return false;
     170}
     171
    144172void EditingStyle::setStyle(PassRefPtr<CSSMutableStyleDeclaration> style)
    145173{
     
    176204void EditingStyle::removeStyleConflictingWithStyleOfNode(Node* node)
    177205{
    178     if (!node || !node->parentNode())
     206    if (!node || !node->parentNode() || !m_mutableStyle)
    179207        return;
    180208    RefPtr<CSSMutableStyleDeclaration> parentStyle = editingStyleFromComputedStyle(computedStyle(node->parentNode()));
     
    193221}
    194222
    195 void EditingStyle::prepareToApplyAt(const Position& position)
    196 {
     223void EditingStyle::prepareToApplyAt(const Position& position, ShouldPreserveWritingDirection shouldPreserveWritingDirection)
     224{
     225    if (!m_mutableStyle)
     226        return;
     227
    197228    // ReplaceSelectionCommand::handleStyleSpans() requires that this function only removes the editing style.
    198229    // If this function was modified in the future to delete all redundant properties, then add a boolean value to indicate
    199230    // which one of editingStyleAtPosition or computedStyle is called.
    200231    RefPtr<EditingStyle> style = EditingStyle::create(position);
     232
     233    RefPtr<CSSValue> unicodeBidi;
     234    RefPtr<CSSValue> direction;
     235    if (shouldPreserveWritingDirection == PreserveWritingDirection) {
     236        unicodeBidi = m_mutableStyle->getPropertyCSSValue(CSSPropertyUnicodeBidi);
     237        direction = m_mutableStyle->getPropertyCSSValue(CSSPropertyDirection);
     238    }
     239
    201240    style->m_mutableStyle->diff(m_mutableStyle.get());
    202241
     
    208247        m_mutableStyle->removeProperty(CSSPropertyBackgroundColor, ec);
    209248    }
     249
     250    if (unicodeBidi) {
     251        ASSERT(unicodeBidi->isPrimitiveValue());
     252        m_mutableStyle->setProperty(CSSPropertyUnicodeBidi, static_cast<CSSPrimitiveValue*>(unicodeBidi.get())->getIdent());
     253        if (direction) {
     254            ASSERT(direction->isPrimitiveValue());
     255            m_mutableStyle->setProperty(CSSPropertyDirection, static_cast<CSSPrimitiveValue*>(direction.get())->getIdent());
     256        }
     257    }
    210258}
    211259
     
    213261{
    214262    RefPtr<EditingStyle> editingStyle = EditingStyle::create(position);
    215     RefPtr<CSSMutableStyleDeclaration> typingStyle = position.node()->document()->frame()->selection()->typingStyle();
    216     if (typingStyle)
    217         editingStyle->style()->merge(copyEditingProperties(typingStyle.get()).get());
     263    RefPtr<EditingStyle> typingStyle = position.node()->document()->frame()->selection()->typingStyle();
     264    if (typingStyle && typingStyle->style())
     265        editingStyle->style()->merge(copyEditingProperties(typingStyle->style()).get());
    218266    return editingStyle;
    219267}
  • trunk/WebCore/editing/EditingStyle.h

    r71556 r72573  
    4141class CSSComputedStyleDeclaration;
    4242
     43enum WritingDirection { NaturalWritingDirection, LeftToRightWritingDirection, RightToLeftWritingDirection };
     44
    4345class EditingStyle : public RefCounted<EditingStyle> {
    4446public:
     47   
     48    enum ShouldPreserveWritingDirection { PreserveWritingDirection, DoNotPreserveWritingDirection };
    4549
    4650    static PassRefPtr<EditingStyle> create()
     
    6569
    6670    CSSMutableStyleDeclaration* style() { return m_mutableStyle.get(); }
     71    bool textDirection(WritingDirection&) const;
    6772    bool isEmpty() const;
    6873    void setStyle(PassRefPtr<CSSMutableStyleDeclaration>);
     
    7277    void removeStyleConflictingWithStyleOfNode(Node* node);
    7378    void removeNonEditingProperties();
    74     void prepareToApplyAt(const Position&);
     79    void prepareToApplyAt(const Position&, ShouldPreserveWritingDirection = DoNotPreserveWritingDirection);
    7580
    7681private:
  • trunk/WebCore/editing/Editor.cpp

    r72500 r72573  
    617617
    618618    if (m_frame->selection()->isCaret()) {
    619         RefPtr<CSSMutableStyleDeclaration> typingStyle = m_frame->selection()->typingStyle();
    620         if (typingStyle) {
    621             RefPtr<CSSValue> unicodeBidi = typingStyle->getPropertyCSSValue(CSSPropertyUnicodeBidi);
    622             if (unicodeBidi) {
    623                 ASSERT(unicodeBidi->isPrimitiveValue());
    624                 int unicodeBidiValue = static_cast<CSSPrimitiveValue*>(unicodeBidi.get())->getIdent();
    625                 if (unicodeBidiValue == CSSValueEmbed) {
    626                     RefPtr<CSSValue> direction = typingStyle->getPropertyCSSValue(CSSPropertyDirection);
    627                     ASSERT(!direction || direction->isPrimitiveValue());
    628                     if (direction) {
    629                         hasNestedOrMultipleEmbeddings = false;
    630                         return static_cast<CSSPrimitiveValue*>(direction.get())->getIdent() == CSSValueLtr ? LeftToRightWritingDirection : RightToLeftWritingDirection;
    631                     }
    632                 } else if (unicodeBidiValue == CSSValueNormal) {
    633                     hasNestedOrMultipleEmbeddings = false;
    634                     return NaturalWritingDirection;
    635                 }
    636             }
     619        RefPtr<EditingStyle> typingStyle = m_frame->selection()->typingStyle();
     620        WritingDirection direction;
     621        if (typingStyle && typingStyle->textDirection(direction)) {
     622            hasNestedOrMultipleEmbeddings = false;
     623            return direction;
    637624        }
    638625        node = m_frame->selection()->selection().visibleStart().deepEquivalent().node();
     
    30283015    // Calculate the current typing style.
    30293016    RefPtr<CSSMutableStyleDeclaration> mutableStyle = style->makeMutable();
    3030     if (m_frame->selection()->typingStyle()) {
    3031         m_frame->selection()->typingStyle()->merge(mutableStyle.get());
    3032         mutableStyle = m_frame->selection()->typingStyle();
     3017    RefPtr<EditingStyle> typingStyle = m_frame->selection()->typingStyle();
     3018    if (typingStyle && typingStyle->style()) {
     3019        typingStyle->style()->merge(mutableStyle.get());
     3020        mutableStyle = typingStyle->style();
    30333021    }
    30343022
     
    30903078        return mutableStyle;
    30913079
    3092     RefPtr<EditingStyle> typingStyle = EditingStyle::create(m_frame->selection()->typingStyle());
     3080    RefPtr<EditingStyle> typingStyle = m_frame->selection()->typingStyle();
    30933081    typingStyle->removeNonEditingProperties();
    30943082    typingStyle->prepareToApplyAt(position);
     
    31743162        return 0;
    31753163
    3176     if (!m_frame->selection()->typingStyle())
     3164    RefPtr<EditingStyle> typingStyle = m_frame->selection()->typingStyle();
     3165    if (!typingStyle || !typingStyle->style())
    31773166        return position.node()->renderer()->style();
    31783167
     
    31803169
    31813170    ExceptionCode ec = 0;
    3182     String styleText = m_frame->selection()->typingStyle()->cssText() + " display: inline";
     3171    String styleText = typingStyle->style()->cssText() + " display: inline";
    31833172    styleElement->setAttribute(styleAttr, styleText.impl(), ec);
    31843173    ASSERT(!ec);
  • trunk/WebCore/editing/Editor.h

    r72469 r72573  
    7171enum TriState { FalseTriState, TrueTriState, MixedTriState };
    7272enum EditorCommandSource { CommandFromMenuOrKeyBinding, CommandFromDOM, CommandFromDOMWithUserInterface };
    73 enum WritingDirection { NaturalWritingDirection, LeftToRightWritingDirection, RightToLeftWritingDirection };
    7473
    7574class Editor {
  • trunk/WebCore/editing/InsertLineBreakCommand.cpp

    r71469 r72573  
    165165
    166166    // Handle the case where there is a typing style.
    167    
    168     RefPtr<CSSMutableStyleDeclaration> typingStyle = document()->frame()->selection()->typingStyle();
    169    
    170     if (typingStyle && typingStyle->length() > 0) {
     167
     168    RefPtr<EditingStyle> typingStyle = document()->frame()->selection()->typingStyle();
     169
     170    if (typingStyle && !typingStyle->isEmpty()) {
    171171        // Apply the typing style to the inserted line break, so that if the selection
    172172        // leaves and then comes back, new input will have the right style.
    173173        // FIXME: We shouldn't always apply the typing style to the line break here,
    174174        // see <rdar://problem/5794462>.
    175         applyStyle(typingStyle.get(), firstDeepEditingPositionForNode(nodeToInsert.get()), lastDeepEditingPositionForNode(nodeToInsert.get()));
     175        applyStyle(typingStyle->style(), firstDeepEditingPositionForNode(nodeToInsert.get()), lastDeepEditingPositionForNode(nodeToInsert.get()));
    176176        // Even though this applyStyle operates on a Range, it still sets an endingSelection().
    177177        // It tries to set a VisibleSelection around the content it operated on. So, that VisibleSelection
  • trunk/WebCore/editing/InsertTextCommand.cpp

    r71469 r72573  
    191191
    192192    // Handle the case where there is a typing style.
    193     RefPtr<CSSMutableStyleDeclaration> typingStyle = document()->frame()->selection()->typingStyle();
    194     RefPtr<CSSComputedStyleDeclaration> endingStyle = endPosition.computedStyle();
    195     RefPtr<CSSValue> unicodeBidi;
    196     RefPtr<CSSValue> direction;
    197     if (typingStyle) {
    198         unicodeBidi = typingStyle->getPropertyCSSValue(CSSPropertyUnicodeBidi);
    199         direction = typingStyle->getPropertyCSSValue(CSSPropertyDirection);
    200     }
    201     endingStyle->diff(typingStyle.get());
    202     if (typingStyle && unicodeBidi) {
    203         ASSERT(unicodeBidi->isPrimitiveValue());
    204         typingStyle->setProperty(CSSPropertyUnicodeBidi, static_cast<CSSPrimitiveValue*>(unicodeBidi.get())->getIdent());
    205         if (direction) {
    206             ASSERT(direction->isPrimitiveValue());
    207             typingStyle->setProperty(CSSPropertyDirection, static_cast<CSSPrimitiveValue*>(direction.get())->getIdent());
    208         }
    209     }
    210 
    211     if (typingStyle && typingStyle->length())
    212         applyStyle(typingStyle.get());
     193    if (RefPtr<EditingStyle> typingStyle = document()->frame()->selection()->typingStyle()) {
     194        typingStyle->prepareToApplyAt(endPosition, EditingStyle::PreserveWritingDirection);
     195        if (!typingStyle->isEmpty())
     196            applyStyle(typingStyle->style());
     197    }
    213198
    214199    if (!selectInsertedText)
  • trunk/WebCore/editing/SelectionController.h

    r71469 r72573  
    161161    void paintDragCaret(GraphicsContext*, int tx, int ty, const IntRect& clipRect) const;
    162162
    163     CSSMutableStyleDeclaration* typingStyle() const;
     163    EditingStyle* typingStyle() const;
     164    PassRefPtr<CSSMutableStyleDeclaration> copyTypingStyle() const;
    164165    void setTypingStyle(PassRefPtr<EditingStyle>);
    165166    void clearTypingStyle();
     
    234235};
    235236
    236 inline CSSMutableStyleDeclaration* SelectionController::typingStyle() const
    237 {
    238     return m_typingStyle ? m_typingStyle->style() : 0;
     237inline EditingStyle* SelectionController::typingStyle() const
     238{
     239    return m_typingStyle.get();
     240}
     241
     242inline PassRefPtr<CSSMutableStyleDeclaration> SelectionController::copyTypingStyle() const
     243{
     244    if (!m_typingStyle || !m_typingStyle->style())
     245        return 0;
     246    return m_typingStyle->style()->copy();
    239247}
    240248
  • trunk/WebKit/mac/ChangeLog

    r72443 r72573  
     12010-11-22  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Reviewed by Tony Chang.
     4
     5        SelectionController::typingStyle() should return EditingStyle*
     6        https://bugs.webkit.org/show_bug.cgi?id=49813
     7
     8        Changed the return value of SelectionController::typingStyle() to EditingStyle*.
     9        Also added SelectionController::copyTypingStyle() to copy the typing style
     10        as an instance of CSSMutableStyleDeclaration.
     11
     12        No tests are added since this is no behavioral change.
     13
     14        * WebView/WebFrame.mm:
     15        (-[WebFrame _typingStyle]): Calls SelectionController::copyTypingStyle()
     16
    1172010-11-19  Michael Saboff  <msaboff@apple.com>
    218
  • trunk/WebKit/mac/WebView/WebFrame.mm

    r71451 r72573  
    902902- (DOMCSSStyleDeclaration *)_typingStyle
    903903{
    904     if (!_private->coreFrame || !_private->coreFrame->selection()->typingStyle())
    905         return nil;
    906     return kit(_private->coreFrame->selection()->typingStyle()->copy().get());
     904    if (!_private->coreFrame)
     905        return nil;
     906    RefPtr<CSSMutableStyleDeclaration> typingStyle = _private->coreFrame->selection()->copyTypingStyle();
     907    if (!typingStyle)
     908        return nil;
     909    return kit(typingStyle.get());
    907910}
    908911
Note: See TracChangeset for help on using the changeset viewer.