Toggling underline on font panel removes strike through
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 6 May 2015 16:42:33 +0000 (16:42 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 6 May 2015 16:42:33 +0000 (16:42 +0000)
https://bugs.webkit.org/show_bug.cgi?id=144670
<rdar://problem/3790443>

Reviewed by Darin Adler.

Source/WebCore:

* editing/EditingStyle.cpp:
(WebCore::EditingStyle::EditingStyle): Added a variant that takes CSSStyleDeclaration.
* editing/EditingStyle.h:
(WebCore::EditingStyle::create): Ditto.
* editing/Editor.cpp:
(WebCore::Editor::applyStyleToSelection): Takes Ref<EditingStyle>&& instead of RefPtr<EditingStyle>&&.
* editing/Editor.h:
* editing/EditorCommand.cpp:
(WebCore::applyCommandToFrame): Ditto.
(WebCore::executeStrikethrough):
(WebCore::executeUnderline):

Source/WebKit/mac:

Use setStrikeThroughChange and setUnderlineChange added in r183770 to toggle underline and strike through.

* WebView/WebHTMLView.mm:
(-[WebHTMLView _applyEditingStyleToSelection:withUndoAction:]):
(-[WebHTMLView _styleForAttributeChange:]):
(-[WebHTMLView changeAttributes:]):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@183871 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/editing/EditingStyle.cpp
Source/WebCore/editing/EditingStyle.h
Source/WebCore/editing/Editor.cpp
Source/WebCore/editing/Editor.h
Source/WebCore/editing/EditorCommand.cpp
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/WebView/WebHTMLView.mm

index 1ead13223b97727577fa1a554bcfeaba00c5c0ef..7725f76c155d9b732f1f10766d5b98abeb184154 100644 (file)
@@ -1,3 +1,23 @@
+2015-05-06  Ryosuke Niwa  <rniwa@webkit.org>
+
+        Toggling underline on font panel removes strike through
+        https://bugs.webkit.org/show_bug.cgi?id=144670
+        <rdar://problem/3790443>
+
+        Reviewed by Darin Adler.
+
+        * editing/EditingStyle.cpp:
+        (WebCore::EditingStyle::EditingStyle): Added a variant that takes CSSStyleDeclaration.
+        * editing/EditingStyle.h:
+        (WebCore::EditingStyle::create): Ditto.
+        * editing/Editor.cpp:
+        (WebCore::Editor::applyStyleToSelection): Takes Ref<EditingStyle>&& instead of RefPtr<EditingStyle>&&.
+        * editing/Editor.h:
+        * editing/EditorCommand.cpp:
+        (WebCore::applyCommandToFrame): Ditto.
+        (WebCore::executeStrikethrough):
+        (WebCore::executeUnderline):
+
 2015-05-06  Jessie Berlin  <jberlin@webkit.org>
 
         More build fixing.
index 68b141cf651c90569e78044358a33d4a80f3f14b..f2b0104019d2ddf93ea2773721c000f8cd320f3a 100644 (file)
@@ -348,6 +348,14 @@ EditingStyle::EditingStyle(const Position& position, PropertiesToInclude propert
     init(position.deprecatedNode(), propertiesToInclude);
 }
 
+EditingStyle::EditingStyle(const CSSStyleDeclaration* style)
+    : EditingStyle()
+{
+    if (style)
+        m_mutableStyle = style->copyProperties();
+    extractFontSizeDelta();
+}
+
 EditingStyle::EditingStyle(const StyleProperties* style)
     : EditingStyle()
 {
index 9b35f309ad9cfe05a6cf2c71a171cc89f9eb2241..4ea980a94084d9367dca44b7e5700f5341258b3c 100644 (file)
@@ -94,6 +94,11 @@ public:
         return adoptRef(*new EditingStyle(style));
     }
 
+    static Ref<EditingStyle> create(const CSSStyleDeclaration* style)
+    {
+        return adoptRef(*new EditingStyle(style));
+    }
+
     static Ref<EditingStyle> create(CSSPropertyID propertyID, const String& value)
     {
         return adoptRef(*new EditingStyle(propertyID, value));
@@ -167,6 +172,7 @@ private:
     EditingStyle();
     EditingStyle(Node*, PropertiesToInclude);
     EditingStyle(const Position&, PropertiesToInclude);
+    WEBCORE_EXPORT explicit EditingStyle(const CSSStyleDeclaration*);
     explicit EditingStyle(const StyleProperties*);
     EditingStyle(CSSPropertyID, const String& value);
     EditingStyle(CSSPropertyID, CSSValueID);
index 3c6104c20bb2105aa9cf311d28ad66161c3444a4..1ac7b87f550a80d910e077063a82f049383f607b 100644 (file)
@@ -941,9 +941,9 @@ void Editor::applyStyleToSelection(StyleProperties* style, EditAction editingAct
     applyStyle(style, editingAction);
 }
 
-void Editor::applyStyleToSelection(RefPtr<EditingStyle>&& style, EditAction editingAction)
+void Editor::applyStyleToSelection(Ref<EditingStyle>&& style, EditAction editingAction)
 {
-    if (!style || style->isEmpty() || !canEditRichly())
+    if (style->isEmpty() || !canEditRichly())
         return;
 
     // FIXME: This is wrong for text decorations since m_mutableStyle is empty.
index 90976fa8bab779f30f623c5e65979f8215e21e0f..18ce29e428aa044b4f9fa8cf3ec38d1b1cd5e0b0 100644 (file)
@@ -186,7 +186,7 @@ public:
     void applyStyle(RefPtr<EditingStyle>&&, EditAction);
     void applyParagraphStyle(StyleProperties*, EditAction = EditActionUnspecified);
     WEBCORE_EXPORT void applyStyleToSelection(StyleProperties*, EditAction);
-    void applyStyleToSelection(RefPtr<EditingStyle>&&, EditAction);
+    WEBCORE_EXPORT void applyStyleToSelection(Ref<EditingStyle>&&, EditAction);
     void applyParagraphStyleToSelection(StyleProperties*, EditAction);
 
     void appliedEditing(PassRefPtr<CompositeEditCommand>);
index 330622d54d195e7d3f7f6d2e0ece87a209e18114..be269a5ef7eb223cb2b0de2359598fcbe972e89c 100644 (file)
@@ -98,7 +98,7 @@ static Frame* targetFrame(Frame& frame, Event* event)
     return node->document().frame();
 }
 
-static bool applyCommandToFrame(Frame& frame, EditorCommandSource source, EditAction action, RefPtr<EditingStyle>&& style)
+static bool applyCommandToFrame(Frame& frame, EditorCommandSource source, EditAction action, Ref<EditingStyle>&& style)
 {
     // FIXME: We don't call shouldApplyStyle when the source is DOM; is there a good reason for that?
     switch (source) {
@@ -1034,7 +1034,7 @@ static TextDecorationChange textDecorationChangeForToggling(Editor& editor, CSSP
 
 static bool executeStrikethrough(Frame& frame, Event*, EditorCommandSource source, const String&)
 {
-    RefPtr<EditingStyle> style = EditingStyle::create();
+    Ref<EditingStyle> style = EditingStyle::create();
     style->setStrikeThroughChange(textDecorationChangeForToggling(frame.editor(), CSSPropertyWebkitTextDecorationsInEffect, "line-through"));
     // FIXME: Needs a new EditAction!
     return applyCommandToFrame(frame, source, EditActionUnderline, WTF::move(style));
@@ -1101,7 +1101,7 @@ static bool executeTranspose(Frame& frame, Event*, EditorCommandSource, const St
 
 static bool executeUnderline(Frame& frame, Event*, EditorCommandSource source, const String&)
 {
-    RefPtr<EditingStyle> style = EditingStyle::create();
+    Ref<EditingStyle> style = EditingStyle::create();
     TextDecorationChange change = textDecorationChangeForToggling(frame.editor(), CSSPropertyWebkitTextDecorationsInEffect, "underline");
     style->setUnderlineChange(change);
     return applyCommandToFrame(frame, source, EditActionUnderline, WTF::move(style));
index 529ff9a8839ee9355a420c8ff92eaf097d46b6aa..2ba553fccf8f2e916a3be11327d5619831acf438 100644 (file)
@@ -1,3 +1,18 @@
+2015-05-06  Ryosuke Niwa  <rniwa@webkit.org>
+
+        Toggling underline on font panel removes strike through
+        https://bugs.webkit.org/show_bug.cgi?id=144670
+        <rdar://problem/3790443>
+
+        Reviewed by Darin Adler.
+
+        Use setStrikeThroughChange and setUnderlineChange added in r183770 to toggle underline and strike through.
+
+        * WebView/WebHTMLView.mm:
+        (-[WebHTMLView _applyEditingStyleToSelection:withUndoAction:]):
+        (-[WebHTMLView _styleForAttributeChange:]):
+        (-[WebHTMLView changeAttributes:]):
+
 2015-05-04  Ryosuke Niwa  <rniwa@webkit.org>
 
         Toggling underline or strike through affects each other
index 1c488f6f5e45084b7f089bff89c4100cce976c55..2ebe7c60bb8f79899a0269f785d1add52f50dacd 100644 (file)
@@ -4795,6 +4795,12 @@ static PassRefPtr<KeyboardEvent> currentKeyboardEvent(Frame* coreFrame)
     }
 }
 
+- (void)_applyEditingStyleToSelection:(Ref<EditingStyle>&&)editingStyle withUndoAction:(EditAction)undoAction
+{
+    if (Frame* coreFrame = core([self _frame]))
+        coreFrame->editor().applyStyleToSelection(WTF::move(editingStyle), undoAction);
+}
+
 #if !PLATFORM(IOS)
 - (BOOL)_handleStyleKeyEquivalent:(NSEvent *)event
 {
@@ -4985,7 +4991,7 @@ static NSString *fontNameForDescription(NSString *familyName, BOOL italic, BOOL
     [self _applyStyleToSelection:[self _styleFromFontManagerOperation] withUndoAction:EditActionSetFont];
 }
 
-- (DOMCSSStyleDeclaration *)_styleForAttributeChange:(id)sender
+- (Ref<EditingStyle>)_styleForAttributeChange:(id)sender
 {
     DOMCSSStyleDeclaration *style = [self _emptyStyle];
 
@@ -5032,19 +5038,8 @@ static NSString *fontNameForDescription(NSString *familyName, BOOL italic, BOOL
     else if ([b objectForKey:NSShadowAttributeName] == nil)
         [style setTextShadow:@"none"];
 
-    int sa = [[a objectForKey:NSStrikethroughStyleAttributeName] intValue];
-    int sb = [[b objectForKey:NSStrikethroughStyleAttributeName] intValue];
-    if (sa == sb) {
-        if (sa == NSUnderlineStyleNone)
-            [style setProperty:@"-webkit-text-decorations-in-effect" value:@"none" priority:@""];
-            // we really mean "no line-through" rather than "none"
-        else
-            [style setProperty:@"-webkit-text-decorations-in-effect" value:@"line-through" priority:@""];
-            // we really mean "add line-through" rather than "line-through"
-    }
-
-    sa = [[a objectForKey:NSSuperscriptAttributeName] intValue];
-    sb = [[b objectForKey:NSSuperscriptAttributeName] intValue];
+    int sa = [[a objectForKey:NSSuperscriptAttributeName] intValue];
+    int sb = [[b objectForKey:NSSuperscriptAttributeName] intValue];
     if (sa == sb) {
         if (sa > 0)
             [style setVerticalAlign:@"super"];
@@ -5053,26 +5048,31 @@ static NSString *fontNameForDescription(NSString *familyName, BOOL italic, BOOL
         else
             [style setVerticalAlign:@"baseline"];
     }
+    
+    auto editingStyle = EditingStyle::create(core(style));
+
+    int strikeThroughA = [[a objectForKey:NSStrikethroughStyleAttributeName] intValue];
+    int strikeThroughB = [[b objectForKey:NSStrikethroughStyleAttributeName] intValue];
+    if (strikeThroughA == strikeThroughB) {
+        bool shouldRemoveStrikeThrough = strikeThroughA == NSUnderlineStyleNone;
+        editingStyle->setStrikeThroughChange(shouldRemoveStrikeThrough ? TextDecorationChange::Remove : TextDecorationChange::Add);
+    }
 
     int ua = [[a objectForKey:NSUnderlineStyleAttributeName] intValue];
     int ub = [[b objectForKey:NSUnderlineStyleAttributeName] intValue];
     if (ua == ub) {
-        if (ua == NSUnderlineStyleNone)
-            [style setProperty:@"-webkit-text-decorations-in-effect" value:@"none" priority:@""];
-            // we really mean "no underline" rather than "none"
-        else
-            [style setProperty:@"-webkit-text-decorations-in-effect" value:@"underline" priority:@""];
-            // we really mean "add underline" rather than "underline"
+        bool shouldRemoveUnderline = ua == NSUnderlineStyleNone;
+        editingStyle->setUnderlineChange(shouldRemoveUnderline ? TextDecorationChange::Remove : TextDecorationChange::Add);
     }
 
-    return style;
+    return editingStyle;
 }
 
 - (void)changeAttributes:(id)sender
 {
     COMMAND_PROLOGUE
 
-    [self _applyStyleToSelection:[self _styleForAttributeChange:sender] withUndoAction:EditActionChangeAttributes];
+    [self _applyEditingStyleToSelection:[self _styleForAttributeChange:sender] withUndoAction:EditActionChangeAttributes];
 }
 
 - (DOMCSSStyleDeclaration *)_styleFromColorPanelWithSelector:(SEL)selector