Changeset 236770 in webkit
- Timestamp:
- Oct 2, 2018 3:53:37 PM (6 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r236762 r236770 1 2018-10-02 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 [WebKit2] Format > Bold and Format > Italic don't toggle between bold and italic style 4 https://bugs.webkit.org/show_bug.cgi?id=179787 5 <rdar://problem/35593389> 6 7 Reviewed by Tim Horton. 8 9 Fixes the bug by relaxing our policy in WebViewImpl::updateFontManagerIfNeeded. Instead of updating only when 10 the font panel is visible, update when either the font panel is visible, or the selection is in a richly 11 editable area. In the latter case, an up-to-date NSFontManager state is needed in order for certain font 12 formatting menu items, such as bold and italic, to correctly toggle state. 13 14 Test: FontManagerTests.ToggleBoldAndItalicWithMenuItems 15 16 * UIProcess/Cocoa/WebViewImpl.h: 17 * UIProcess/Cocoa/WebViewImpl.mm: 18 (-[WKWindowVisibilityObserver observeValueForKeyPath:ofObject:change:context:]): 19 (WebKit::WebViewImpl::selectionDidChange): 20 (WebKit::WebViewImpl::updateFontManagerIfNeeded): 21 22 Rename updateFontPanelIfNeeded to updateFontManagerIfNeeded, to reflect the new behavior. 23 24 (WebKit::WebViewImpl::changeFontAttributesFromSender): 25 (WebKit::WebViewImpl::changeFontFromFontManager): 26 (WebKit::WebViewImpl::updateFontPanelIfNeeded): Deleted. 27 1 28 2018-10-02 Alex Christensen <achristensen@webkit.org> 2 29 -
trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.h
r236724 r236770 324 324 325 325 void didBecomeEditable(); 326 void updateFont PanelIfNeeded();326 void updateFontManagerIfNeeded(); 327 327 void changeFontFromFontManager(); 328 328 void changeFontAttributesFromSender(id); -
trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm
r236724 r236770 375 375 376 376 if ([keyPath isEqualToString:@"visible"] && [NSFontPanel sharedFontPanelExists] && object == [NSFontPanel sharedFontPanel]) { 377 _impl->updateFont PanelIfNeeded();377 _impl->updateFontManagerIfNeeded(); 378 378 return; 379 379 } … … 2737 2737 void WebViewImpl::selectionDidChange() 2738 2738 { 2739 updateFont PanelIfNeeded();2739 updateFontManagerIfNeeded(); 2740 2740 if (!m_isHandlingAcceptedCandidate) 2741 2741 m_softSpaceRange = NSMakeRange(NSNotFound, 0); … … 2788 2788 } 2789 2789 2790 void WebViewImpl::updateFontPanelIfNeeded() 2791 { 2792 const EditorState& editorState = m_page->editorState(); 2793 if (editorState.selectionIsNone || !editorState.isContentEditable) 2794 return; 2795 if ([NSFontPanel sharedFontPanelExists] && [[NSFontPanel sharedFontPanel] isVisible]) { 2796 m_page->fontAtSelection([](const String& fontName, double fontSize, bool selectionHasMultipleFonts, WebKit::CallbackBase::Error error) { 2797 NSFont *font = [NSFont fontWithName:fontName size:fontSize]; 2798 if (font) 2799 [[NSFontManager sharedFontManager] setSelectedFont:font isMultiple:selectionHasMultipleFonts]; 2800 }); 2801 } 2790 void WebViewImpl::updateFontManagerIfNeeded() 2791 { 2792 BOOL fontPanelIsVisible = NSFontPanel.sharedFontPanelExists && NSFontPanel.sharedFontPanel.visible; 2793 if (!fontPanelIsVisible && !m_page->editorState().isContentRichlyEditable) 2794 return; 2795 2796 m_page->fontAtSelection([](const String& fontName, double fontSize, bool selectionHasMultipleFonts, WebKit::CallbackBase::Error error) { 2797 if (NSFont *font = [NSFont fontWithName:fontName size:fontSize]) 2798 [NSFontManager.sharedFontManager setSelectedFont:font isMultiple:selectionHasMultipleFonts]; 2799 }); 2802 2800 } 2803 2801 … … 2846 2844 2847 2845 m_page->changeFontAttributes(WebCore::computedFontAttributeChanges(NSFontManager.sharedFontManager, sender)); 2848 updateFont PanelIfNeeded();2846 updateFontManagerIfNeeded(); 2849 2847 } 2850 2848 … … 2856 2854 2857 2855 m_page->changeFont(WebCore::computedFontChanges(NSFontManager.sharedFontManager)); 2858 updateFont PanelIfNeeded();2856 updateFontManagerIfNeeded(); 2859 2857 } 2860 2858 -
trunk/Tools/ChangeLog
r236764 r236770 1 2018-10-02 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 [WebKit2] Format > Bold and Format > Italic don't toggle between bold and italic style 4 https://bugs.webkit.org/show_bug.cgi?id=179787 5 <rdar://problem/35593389> 6 7 Reviewed by Tim Horton. 8 9 Add a test to verify that NSFontManager's selected font is updated when applying italic and bold styles using 10 menu items. 11 12 * TestWebKitAPI/Tests/mac/FontManagerTests.mm: 13 (webViewForFontManagerTesting): 14 (menuItemCellForFontAction): 15 (TestWebKitAPI::TEST): 16 1 17 2018-10-02 Chris Dumez <cdumez@apple.com> 2 18 -
trunk/Tools/TestWebKitAPI/Tests/mac/FontManagerTests.mm
r236724 r236770 121 121 "</body><script>document.body.addEventListener('input', event => lastInputEvent = event)</script>"]; 122 122 [webView stringByEvaluatingJavaScript:@"document.body.focus()"]; 123 [webView _setEditable:YES]; 123 124 fontManager.target = webView.get(); 124 125 return webView; 125 126 } 126 127 127 static RetainPtr<NSMenuItemCell> menuItemCellForFontAction(NS FontAction action)128 static RetainPtr<NSMenuItemCell> menuItemCellForFontAction(NSUInteger tag) 128 129 { 129 130 auto menuItem = adoptNS([[NSMenuItem alloc] init]); 130 131 auto menuItemCell = adoptNS([[NSMenuItemCell alloc] init]); 131 132 [menuItemCell setMenuItem:menuItem.get()]; 132 [menuItemCell setTag: action];133 [menuItemCell setTag:tag]; 133 134 return menuItemCell; 134 135 } 135 136 136 137 namespace TestWebKitAPI { 138 139 TEST(FontManagerTests, ToggleBoldAndItalicWithMenuItems) 140 { 141 NSFontManager *fontManager = NSFontManager.sharedFontManager; 142 auto webView = webViewForFontManagerTesting(fontManager); 143 144 [webView selectWord:nil]; 145 [fontManager addFontTrait:menuItemCellForFontAction(NSBoldFontMask).autorelease()]; 146 EXPECT_WK_STREQ("bold", [webView stylePropertyAtSelectionStart:@"font-weight"]); 147 EXPECT_WK_STREQ("bold", [webView stylePropertyAtSelectionEnd:@"font-weight"]); 148 EXPECT_WK_STREQ("Times-Bold", [fontManager selectedFont].fontName); 149 150 [fontManager addFontTrait:menuItemCellForFontAction(NSUnboldFontMask).autorelease()]; 151 EXPECT_WK_STREQ("normal", [webView stylePropertyAtSelectionStart:@"font-weight"]); 152 EXPECT_WK_STREQ("normal", [webView stylePropertyAtSelectionEnd:@"font-weight"]); 153 EXPECT_WK_STREQ("Times-Roman", [fontManager selectedFont].fontName); 154 155 [fontManager addFontTrait:menuItemCellForFontAction(NSItalicFontMask).autorelease()]; 156 EXPECT_WK_STREQ("italic", [webView stylePropertyAtSelectionStart:@"font-style"]); 157 EXPECT_WK_STREQ("italic", [webView stylePropertyAtSelectionEnd:@"font-style"]); 158 EXPECT_WK_STREQ("Times-Italic", [fontManager selectedFont].fontName); 159 160 [fontManager addFontTrait:menuItemCellForFontAction(NSUnitalicFontMask).autorelease()]; 161 EXPECT_WK_STREQ("normal", [webView stylePropertyAtSelectionStart:@"font-style"]); 162 EXPECT_WK_STREQ("normal", [webView stylePropertyAtSelectionEnd:@"font-style"]); 163 EXPECT_WK_STREQ("Times-Roman", [fontManager selectedFont].fontName); 164 } 137 165 138 166 TEST(FontManagerTests, ChangeFontSizeWithMenuItems)
Note: See TracChangeset
for help on using the changeset viewer.