Changeset 80528 in webkit


Ignore:
Timestamp:
Mar 7, 2011 7:54:41 PM (13 years ago)
Author:
rniwa@webkit.org
Message:

2011-03-07 Ryosuke Niwa <rniwa@webkit.org>

Reviewed by Darin Adler.

selectionHasStyle and selectionStartHasStyle should use EditingStyle
https://bugs.webkit.org/show_bug.cgi?id=55902

selectionHasStyle now takes a property id and a value instead of a CSSMutableStyleDeclaration.

  • src/ContextMenuClientImpl.cpp: (WebKit::ContextMenuClientImpl::getCustomMenuFromDefaultItems): Calls selectionHasStyle.

2011-03-07 Ryosuke Niwa <rniwa@webkit.org>

Reviewed by Darin Adler.

selectionHasStyle and selectionStartHasStyle should use EditingStyle
https://bugs.webkit.org/show_bug.cgi?id=55902

selectionHasStyle now takes a property id and a value instead of a CSSMutableStyleDeclaration.

  • WebView/WebHTMLView.mm: Removed unused selectionHasStyle. (-[WebHTMLView validateUserInterfaceItemWithoutDelegate:]): Calls Editor::selectionHasStyle.

2011-03-07 Ryosuke Niwa <rniwa@webkit.org>

Reviewed by Darin Adler.

selectionHasStyle and selectionStartHasStyle should use EditingStyle
https://bugs.webkit.org/show_bug.cgi?id=55902

Deployed EditingStyle in selectionHasStyle and selectionStartHasStyle.
This allowed us to move triStateOfStyle from Editor.cpp to EditingStyle.cpp.

Also changed the argument lists of selectionHasStyle and selectionStartHasStyle
to take a property id and a value instead of a CSSMutableStyleDeclaration to cleanup
call sites of these two functions.

  • WebCore.exp.in: Updated the signature of selectionHasStyle. No longer exports selectionStartHasStyle because it's not called anywhere outside of WebCore.
  • WebCore.order: Ditto.
  • editing/EditingStyle.cpp: (WebCore::EditingStyle::EditingStyle): Added a new constructor that takes a property id and a property value. (WebCore::EditingStyle::triStateOfStyle): Moved from Editor.cpp.
  • editing/EditingStyle.h: (WebCore::EditingStyle::create): Added.
  • editing/Editor.cpp: (WebCore::Editor::selectionStartHasStyle): Takes a property id and a value instead of a CSSStyleDeclaration. (WebCore::Editor::selectionHasStyle): Ditto.
  • editing/Editor.h: Updated the signatures of selectionStartHasStyle and selectionHasStyle.
  • editing/EditorCommand.cpp: (WebCore::executeToggleStyle): Calls selectionStartHasStyle and selectionHasStyle. (WebCore::stateStyle): Ditto.
  • page/ContextMenuController.cpp: (WebCore::ContextMenuController::checkOrEnableIfNeeded): Ditto.
Location:
trunk/Source
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r80526 r80528  
     12011-03-07  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        selectionHasStyle and selectionStartHasStyle should use EditingStyle
     6        https://bugs.webkit.org/show_bug.cgi?id=55902
     7
     8        Deployed EditingStyle in selectionHasStyle and selectionStartHasStyle.
     9        This allowed us to move triStateOfStyle from Editor.cpp to EditingStyle.cpp.
     10
     11        Also changed the argument lists of selectionHasStyle and selectionStartHasStyle
     12        to take a property id and a value instead of a CSSMutableStyleDeclaration to cleanup
     13        call sites of these two functions.
     14
     15        * WebCore.exp.in: Updated the signature of selectionHasStyle. No longer exports
     16        selectionStartHasStyle because it's not called anywhere outside of WebCore.
     17        * WebCore.order: Ditto.
     18        * editing/EditingStyle.cpp:
     19        (WebCore::EditingStyle::EditingStyle): Added a new constructor that takes a property id
     20        and a property value.
     21        (WebCore::EditingStyle::triStateOfStyle): Moved from Editor.cpp.
     22        * editing/EditingStyle.h:
     23        (WebCore::EditingStyle::create): Added.
     24        * editing/Editor.cpp:
     25        (WebCore::Editor::selectionStartHasStyle): Takes a property id and a value instead of
     26        a CSSStyleDeclaration.
     27        (WebCore::Editor::selectionHasStyle): Ditto.
     28        * editing/Editor.h: Updated the signatures of selectionStartHasStyle and selectionHasStyle.
     29        * editing/EditorCommand.cpp:
     30        (WebCore::executeToggleStyle): Calls selectionStartHasStyle and selectionHasStyle.
     31        (WebCore::stateStyle): Ditto.
     32        * page/ContextMenuController.cpp:
     33        (WebCore::ContextMenuController::checkOrEnableIfNeeded): Ditto.
     34
    1352011-03-07  Alexey Proskuryakov  <ap@apple.com>
    236
  • trunk/Source/WebCore/WebCore.exp.in

    r80512 r80528  
    11961196__ZNK7WebCore6Editor16fontForSelectionERb
    11971197__ZNK7WebCore6Editor17firstRectForRangeEPNS_5RangeE
    1198 __ZNK7WebCore6Editor17selectionHasStyleEPNS_19CSSStyleDeclarationE
     1198__ZNK7WebCore6Editor17selectionHasStyleEiRKN3WTF6StringE
    11991199__ZNK7WebCore6Editor17shouldDeleteRangeEPNS_5RangeE
    1200 __ZNK7WebCore6Editor22selectionStartHasStyleEPNS_19CSSStyleDeclarationE
    12011200__ZNK7WebCore6Editor23getCompositionSelectionERjS1_
    12021201__ZNK7WebCore6Editor30applyEditingStyleToBodyElementEv
  • trunk/Source/WebCore/WebCore.order

    r80367 r80528  
    1293312933__ZN7WebCoreL9stateBoldEPNS_5FrameEPNS_5EventE
    1293412934__ZN7WebCoreL10stateStyleEPNS_5FrameEiPKc
    12935 __ZNK7WebCore6Editor17selectionHasStyleEPNS_19CSSStyleDeclarationE
     12935__ZNK7WebCore6Editor17selectionHasStyleEiRKN3WTF6StringE
    1293612936__ZNK7WebCore5Frame22selectionComputedStyleERPNS_4NodeE
    1293712937__ZN7WebCoreL11stateItalicEPNS_5FrameEPNS_5EventE
     
    1764217642__ZN7WebCoreL17executeToggleBoldEPNS_5FrameEPNS_5EventENS_19EditorCommandSourceERKNS_6StringE
    1764317643__ZN7WebCoreL18executeToggleStyleEPNS_5FrameENS_19EditorCommandSourceENS_10EditActionEiPKcS5_
    17644 __ZNK7WebCore6Editor22selectionStartHasStyleEPNS_19CSSStyleDeclarationE
    1764517644__ZN7WebCoreL30triStateOfStyleInComputedStyleEPNS_19CSSStyleDeclarationEPNS_27CSSComputedStyleDeclarationEb
    1764617645__ZN7WebCoreL14executeOutdentEPNS_5FrameEPNS_5EventENS_19EditorCommandSourceERKNS_6StringE
  • trunk/Source/WebCore/editing/EditingStyle.cpp

    r80060 r80528  
    287287}
    288288
     289EditingStyle::EditingStyle(int propertyID, const String& value)
     290    : m_mutableStyle(0)
     291    , m_shouldUseFixedDefaultFontSize(false)
     292    , m_fontSizeDelta(NoFontDelta)
     293{
     294    setProperty(propertyID, value);
     295}
     296
    289297EditingStyle::~EditingStyle()
    290298{
     
    506514}
    507515
     516// CSS properties that create a visual difference only when applied to text.
     517static const int textOnlyProperties[] = {
     518    CSSPropertyTextDecoration,
     519    CSSPropertyWebkitTextDecorationsInEffect,
     520    CSSPropertyFontStyle,
     521    CSSPropertyFontWeight,
     522    CSSPropertyColor,
     523};
     524
     525TriState EditingStyle::triStateOfStyle(CSSStyleDeclaration* styleToCompare, ShouldIgnoreTextOnlyProperties shouldIgnoreTextOnlyProperties) const
     526{
     527    RefPtr<CSSMutableStyleDeclaration> difference = getPropertiesNotIn(m_mutableStyle.get(), styleToCompare);
     528
     529    if (shouldIgnoreTextOnlyProperties == IgnoreTextOnlyProperties)
     530        difference->removePropertiesInSet(textOnlyProperties, WTF_ARRAY_LENGTH(textOnlyProperties));
     531
     532    if (!difference->length())
     533        return TrueTriState;
     534    if (difference->length() == m_mutableStyle->length())
     535        return FalseTriState;
     536
     537    return MixedTriState;
     538}
     539
    508540bool EditingStyle::conflictsWithInlineStyleOfElement(StyledElement* element, EditingStyle* extractedStyle, Vector<CSSPropertyID>* conflictingProperties) const
    509541{
  • trunk/Source/WebCore/editing/EditingStyle.h

    r80213 r80528  
    5252class StyledElement;
    5353
     54enum TriState { FalseTriState, TrueTriState, MixedTriState };
     55
    5456class EditingStyle : public RefCounted<EditingStyle> {
    5557public:
     
    8082    }
    8183
     84    static PassRefPtr<EditingStyle> create(int propertyID, const String& value)
     85    {
     86        return adoptRef(new EditingStyle(propertyID, value));
     87    }
     88
    8289    ~EditingStyle();
    8390
     
    96103    void removeNonEditingProperties();
    97104    void collapseTextDecorationProperties();
     105    enum ShouldIgnoreTextOnlyProperties { IgnoreTextOnlyProperties, DoNotIgnoreTextOnlyProperties };
     106    TriState triStateOfStyle(CSSStyleDeclaration*, ShouldIgnoreTextOnlyProperties = DoNotIgnoreTextOnlyProperties) const;
    98107    bool conflictsWithInlineStyleOfElement(StyledElement* element) const { return conflictsWithInlineStyleOfElement(element, 0, 0); }
    99108    bool conflictsWithInlineStyleOfElement(StyledElement* element, EditingStyle* extractedStyle, Vector<CSSPropertyID>& conflictingProperties) const
     
    118127    EditingStyle(const Position&);
    119128    EditingStyle(const CSSStyleDeclaration*);
     129    EditingStyle(int propertyID, const String& value);
    120130    void init(Node*, PropertiesToInclude);
    121131    void removeTextFillAndStrokeColorsIfNeeded(RenderStyle*);
  • trunk/Source/WebCore/editing/Editor.cpp

    r80408 r80528  
    946946}
    947947
    948 // CSS properties that only has a visual difference when applied to text.
    949 static const int textOnlyProperties[] = {
    950     CSSPropertyTextDecoration,
    951     CSSPropertyWebkitTextDecorationsInEffect,
    952     CSSPropertyFontStyle,
    953     CSSPropertyFontWeight,
    954     CSSPropertyColor,
    955 };
    956 
    957 static TriState triStateOfStyle(CSSStyleDeclaration* desiredStyle, CSSStyleDeclaration* styleToCompare, bool ignoreTextOnlyProperties = false)
    958 {
    959     RefPtr<CSSMutableStyleDeclaration> diff = getPropertiesNotIn(desiredStyle, styleToCompare);
    960 
    961     if (ignoreTextOnlyProperties)
    962         diff->removePropertiesInSet(textOnlyProperties, WTF_ARRAY_LENGTH(textOnlyProperties));
    963 
    964     if (!diff->length())
    965         return TrueTriState;
    966     if (diff->length() == desiredStyle->length())
    967         return FalseTriState;
    968     return MixedTriState;
    969 }
    970 
    971 bool Editor::selectionStartHasStyle(CSSStyleDeclaration* style) const
    972 {
     948bool Editor::selectionStartHasStyle(int propertyID, const String& value) const
     949{
     950    RefPtr<EditingStyle> style = EditingStyle::create(propertyID, value);
    973951    RefPtr<EditingStyle> selectionStyle = selectionStartStyle();
    974952    if (!selectionStyle || !selectionStyle->style())
    975953        return false;
    976     return triStateOfStyle(style, selectionStyle->style()) == TrueTriState;
    977 }
    978 
    979 TriState Editor::selectionHasStyle(CSSStyleDeclaration* style) const
    980 {
     954    return style->triStateOfStyle(selectionStyle->style()) == TrueTriState;
     955}
     956
     957TriState Editor::selectionHasStyle(int propertyID, const String& value) const
     958{
     959    RefPtr<EditingStyle> style = EditingStyle::create(propertyID, value);
    981960    if (!m_frame->selection()->isCaretOrRange())
    982961        return FalseTriState;
     
    986965        if (!selectionStyle || !selectionStyle->style())
    987966            return FalseTriState;
    988         return triStateOfStyle(style, selectionStyle->style());
     967        return style->triStateOfStyle(selectionStyle->style());
    989968    }
    990969
     
    993972        RefPtr<CSSComputedStyleDeclaration> nodeStyle = computedStyle(node);
    994973        if (nodeStyle) {
    995             TriState nodeState = triStateOfStyle(style, nodeStyle.get(), !node->isTextNode());
     974            TriState nodeState = style->triStateOfStyle(nodeStyle.get(), node->isTextNode() ? EditingStyle::DoNotIgnoreTextOnlyProperties : EditingStyle::IgnoreTextOnlyProperties);
    996975            if (node == m_frame->selection()->start().deprecatedNode())
    997976                state = nodeState;
  • trunk/Source/WebCore/editing/Editor.h

    r80408 r80528  
    7777};
    7878
    79 enum TriState { FalseTriState, TrueTriState, MixedTriState };
    8079enum EditorCommandSource { CommandFromMenuOrKeyBinding, CommandFromDOM, CommandFromDOMWithUserInterface };
    8180
     
    134133    void respondToChangedContents(const VisibleSelection& endingSelection);
    135134
    136     TriState selectionHasStyle(CSSStyleDeclaration*) const;
     135    bool selectionStartHasStyle(int propertyID, const String& value) const;
     136    TriState selectionHasStyle(int propertyID, const String& value) const;
    137137    String selectionStartCSSPropertyValue(int propertyID);
    138138    const SimpleFontData* fontForSelection(bool&) const;
     
    170170    void reappliedEditing(PassRefPtr<EditCommand>);
    171171    void unappliedSpellCorrection(const VisibleSelection& selectionOfCorrected, const String& corrected, const String& correction);
    172 
    173     bool selectionStartHasStyle(CSSStyleDeclaration*) const;
    174172
    175173    void setShouldStyleWithCSS(bool flag) { m_shouldStyleWithCSS = flag; }
  • trunk/Source/WebCore/editing/EditorCommand.cpp

    r80023 r80528  
    157157static bool executeToggleStyle(Frame* frame, EditorCommandSource source, EditAction action, int propertyID, const char* offValue, const char* onValue)
    158158{
    159     RefPtr<CSSMutableStyleDeclaration> style = CSSMutableStyleDeclaration::create();
    160     style->setProperty(propertyID, onValue); // We need to add this style to pass it to selectionStartHasStyle / selectionHasStyle
    161 
    162159    // Style is considered present when
    163160    // Mac: present at the beginning of selection
     
    166163    bool styleIsPresent;
    167164    if (frame->editor()->behavior().shouldToggleStyleBasedOnStartOfSelection())
    168         styleIsPresent = frame->editor()->selectionStartHasStyle(style.get());
     165        styleIsPresent = frame->editor()->selectionStartHasStyle(propertyID, onValue);
    169166    else
    170         styleIsPresent = frame->editor()->selectionHasStyle(style.get()) == TrueTriState;
    171 
    172     style->setProperty(propertyID, styleIsPresent ? offValue : onValue);
    173     return applyCommandToFrame(frame, source, action, style.get());
     167        styleIsPresent = frame->editor()->selectionHasStyle(propertyID, onValue) == TrueTriState;
     168
     169    RefPtr<EditingStyle> style = EditingStyle::create(propertyID, styleIsPresent ? offValue : onValue);
     170    return applyCommandToFrame(frame, source, action, style->style());
    174171}
    175172
     
    228225static TriState stateStyle(Frame* frame, int propertyID, const char* desiredValue)
    229226{
    230     RefPtr<CSSMutableStyleDeclaration> style = CSSMutableStyleDeclaration::create();
    231     style->setProperty(propertyID, desiredValue);
    232 
    233227    if (frame->editor()->behavior().shouldToggleStyleBasedOnStartOfSelection())
    234         return frame->editor()->selectionStartHasStyle(style.get()) ? TrueTriState : FalseTriState;
    235     return frame->editor()->selectionHasStyle(style.get());
     228        return frame->editor()->selectionStartHasStyle(propertyID, desiredValue) ? TrueTriState : FalseTriState;
     229    return frame->editor()->selectionHasStyle(propertyID, desiredValue);
    236230}
    237231
  • trunk/Source/WebCore/page/ContextMenuController.cpp

    r80344 r80528  
    10111011        case ContextMenuItemTagLeftToRight:
    10121012        case ContextMenuItemTagRightToLeft: {
    1013             ExceptionCode ec = 0;
    1014             RefPtr<CSSStyleDeclaration> style = frame->document()->createCSSStyleDeclaration();
    10151013            String direction = item.action() == ContextMenuItemTagLeftToRight ? "ltr" : "rtl";
    1016             style->setProperty(CSSPropertyDirection, direction, false, ec);
    1017             shouldCheck = frame->editor()->selectionHasStyle(style.get()) != FalseTriState;
     1014            shouldCheck = frame->editor()->selectionHasStyle(CSSPropertyDirection, direction) != FalseTriState;
    10181015            shouldEnable = true;
    10191016            break;
     
    10611058#endif
    10621059        case ContextMenuItemTagUnderline: {
    1063             ExceptionCode ec = 0;
    1064             RefPtr<CSSStyleDeclaration> style = frame->document()->createCSSStyleDeclaration();
    1065             style->setProperty(CSSPropertyWebkitTextDecorationsInEffect, "underline", false, ec);
    1066             shouldCheck = frame->editor()->selectionHasStyle(style.get()) != FalseTriState;
     1060            shouldCheck = frame->editor()->selectionHasStyle(CSSPropertyWebkitTextDecorationsInEffect, "underline") != FalseTriState;
    10671061            shouldEnable = frame->editor()->canEditRichly();
    10681062            break;
     
    10791073            break;
    10801074        case ContextMenuItemTagItalic: {
    1081             ExceptionCode ec = 0;
    1082             RefPtr<CSSStyleDeclaration> style = frame->document()->createCSSStyleDeclaration();
    1083             style->setProperty(CSSPropertyFontStyle, "italic", false, ec);
    1084             shouldCheck = frame->editor()->selectionHasStyle(style.get()) != FalseTriState;
     1075            shouldCheck = frame->editor()->selectionHasStyle(CSSPropertyFontStyle, "italic") != FalseTriState;
    10851076            shouldEnable = frame->editor()->canEditRichly();
    10861077            break;
    10871078        }
    10881079        case ContextMenuItemTagBold: {
    1089             ExceptionCode ec = 0;
    1090             RefPtr<CSSStyleDeclaration> style = frame->document()->createCSSStyleDeclaration();
    1091             style->setProperty(CSSPropertyFontWeight, "bold", false, ec);
    1092             shouldCheck = frame->editor()->selectionHasStyle(style.get()) != FalseTriState;
     1080            shouldCheck = frame->editor()->selectionHasStyle(CSSPropertyFontWeight, "bold") != FalseTriState;
    10931081            shouldEnable = frame->editor()->canEditRichly();
    10941082            break;
  • trunk/Source/WebKit/chromium/ChangeLog

    r80493 r80528  
     12011-03-07  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        selectionHasStyle and selectionStartHasStyle should use EditingStyle
     6        https://bugs.webkit.org/show_bug.cgi?id=55902
     7
     8        selectionHasStyle now takes a property id and a value instead of a CSSMutableStyleDeclaration.
     9
     10        * src/ContextMenuClientImpl.cpp:
     11        (WebKit::ContextMenuClientImpl::getCustomMenuFromDefaultItems): Calls selectionHasStyle.
     12
    1132011-03-07  Daniel Cheng  <dcheng@chromium.org>
    214
  • trunk/Source/WebKit/chromium/src/ContextMenuClientImpl.cpp

    r79843 r80528  
    263263
    264264#if OS(DARWIN)
    265     ExceptionCode ec = 0;
    266     RefPtr<CSSStyleDeclaration> style = selectedFrame->document()->createCSSStyleDeclaration();
    267     style->setProperty(CSSPropertyDirection, "ltr", false, ec);
    268     if (selectedFrame->editor()->selectionHasStyle(style.get()) != FalseTriState)
     265    if (selectedFrame->editor()->selectionHasStyle(CSSPropertyDirection, 'ltr') != FalseTriState)
    269266        data.writingDirectionLeftToRight |= WebContextMenuData::CheckableMenuItemChecked;
    270     style->setProperty(CSSPropertyDirection, "rtl", false, ec);
    271     if (selectedFrame->editor()->selectionHasStyle(style.get()) != FalseTriState)
     267    if (selectedFrame->editor()->selectionHasStyle(CSSPropertyDirection, 'rtl') != FalseTriState)
    272268        data.writingDirectionRightToLeft |= WebContextMenuData::CheckableMenuItemChecked;
    273269#endif // OS(DARWIN)
  • trunk/Source/WebKit/mac/ChangeLog

    r80506 r80528  
     12011-03-07  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        selectionHasStyle and selectionStartHasStyle should use EditingStyle
     6        https://bugs.webkit.org/show_bug.cgi?id=55902
     7
     8        selectionHasStyle now takes a property id and a value instead of a CSSMutableStyleDeclaration.
     9
     10        * WebView/WebHTMLView.mm: Removed unused selectionHasStyle.
     11        (-[WebHTMLView validateUserInterfaceItemWithoutDelegate:]): Calls Editor::selectionHasStyle.
     12
    1132011-03-07  Dan Bernstein  <mitz@apple.com>
    214
  • trunk/Source/WebKit/mac/WebView/WebHTMLView.mm

    r80153 r80528  
    26442644}
    26452645
    2646 - (NSCellStateValue)selectionHasStyle:(CSSStyleDeclaration*)style
    2647 {
    2648     Frame* coreFrame = core([self _frame]);
    2649     if (!coreFrame)
    2650         return NSOffState;
    2651     return kit(coreFrame->editor()->selectionHasStyle(style));
    2652 }
    2653 
    26542646- (BOOL)validateUserInterfaceItemWithoutDelegate:(id <NSValidatedUserInterfaceItem>)item
    26552647{
     
    27072699        NSMenuItem *menuItem = (NSMenuItem *)item;
    27082700        if ([menuItem isKindOfClass:[NSMenuItem class]]) {
    2709             RefPtr<CSSStyleDeclaration> style = CSSMutableStyleDeclaration::create();
    2710             ExceptionCode ec;
    2711             style->setProperty("direction", writingDirection == NSWritingDirectionLeftToRight ? "LTR" : "RTL", ec);
    2712             [menuItem setState:frame->editor()->selectionHasStyle(style.get())];
     2701            String direction = writingDirection == NSWritingDirectionLeftToRight ? "ltr" : "rtl";
     2702            [menuItem setState:frame->editor()->selectionHasStyle(CSSPropertyDirection, direction)];
    27132703        }
    27142704        return [self _canEdit];
     
    27252715        NSMenuItem *menuItem = (NSMenuItem *)item;
    27262716        if ([menuItem isKindOfClass:[NSMenuItem class]]) {
    2727             RefPtr<CSSStyleDeclaration> style = CSSMutableStyleDeclaration::create();
    2728             ExceptionCode ec;
    2729             style->setProperty("direction", "RTL", ec);
    27302717            // Take control of the title of the menu item instead of just checking/unchecking it because
    27312718            // a check would be ambiguous.
    2732             [menuItem setTitle:frame->editor()->selectionHasStyle(style.get())
     2719            [menuItem setTitle:frame->editor()->selectionHasStyle(CSSPropertyDirection, "rtl")
    27332720                ? UI_STRING_INTERNAL("Left to Right", "Left to Right context menu item")
    27342721                : UI_STRING_INTERNAL("Right to Left", "Right to Left context menu item")];
Note: See TracChangeset for help on using the changeset viewer.