Title: [180465] trunk/Source
Revision
180465
Author
[email protected]
Date
2015-02-20 16:09:48 -0800 (Fri, 20 Feb 2015)

Log Message

[WK2] Add support for font panel on OS X.
https://bugs.webkit.org/show_bug.cgi?id=141777

Reviewed by Tim Horton.

Source/WebCore:

This patch adds the necessary hooks to the Editor class to support
the font panel.

* editing/Editor.h:
* editing/mac/EditorMac.mm:
(WebCore::Editor::applyFontStyles):

Source/WebKit2:

This patch adds the necessary hooks to WKView to support
the font panel. It also includes refactoring of WebPage::editorState
and WebPageProxy::editorStateChanged to separate the different platform
specific tasks.

* Shared/EditorState.cpp:
(WebKit::EditorState::encode):
(WebKit::EditorState::decode):
* Shared/EditorState.h:
(WebKit::EditorState::EditorState):
* UIProcess/API/mac/WKView.mm:
(-[WKView _selectionChanged]):
(-[WKView changeFont:]):
* UIProcess/API/mac/WKViewInternal.h:
* UIProcess/PageClient.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::editorStateChanged): Deleted.
* UIProcess/WebPageProxy.h:
* UIProcess/efl/WebPageProxyEfl.cpp:
(WebKit::WebPageProxy::editorStateChanged):
* UIProcess/gtk/WebPageProxyGtk.cpp:
(WebKit::WebPageProxy::editorStateChanged):
* UIProcess/ios/WebPageProxyIOS.mm:
(WebKit::WebPageProxy::editorStateChanged):
* UIProcess/mac/PageClientImpl.h:
* UIProcess/mac/PageClientImpl.mm:
(WebKit::PageClientImpl::selectionDidChange):
* UIProcess/mac/WebPageProxyMac.mm:
(WebKit::WebPageProxy::setFont):
(WebKit::WebPageProxy::editorStateChanged):
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::editorState):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:
* WebProcess/WebPage/efl/WebPageEfl.cpp:
(WebKit::WebPage::platformEditorState):
* WebProcess/WebPage/gtk/WebPageGtk.cpp:
(WebKit::WebPage::platformEditorState):
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::platformEditorState):
* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::platformEditorState):
(WebKit::WebPage::setFont):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (180464 => 180465)


--- trunk/Source/WebCore/ChangeLog	2015-02-20 23:27:39 UTC (rev 180464)
+++ trunk/Source/WebCore/ChangeLog	2015-02-21 00:09:48 UTC (rev 180465)
@@ -1,3 +1,17 @@
+2015-02-20  Enrica Casucci  <[email protected]>
+
+        [WK2] Add support for font panel on OS X.
+        https://bugs.webkit.org/show_bug.cgi?id=141777
+
+        Reviewed by Tim Horton.
+
+        This patch adds the necessary hooks to the Editor class to support
+        the font panel.
+
+        * editing/Editor.h:
+        * editing/mac/EditorMac.mm:
+        (WebCore::Editor::applyFontStyles):
+
 2015-02-20  Zalan Bujtas  <[email protected]>
 
         Invalid assert in CompositeEditCommand::insertNodeAfter/insertNodeBefore

Modified: trunk/Source/WebCore/editing/Editor.h (180464 => 180465)


--- trunk/Source/WebCore/editing/Editor.h	2015-02-20 23:27:39 UTC (rev 180464)
+++ trunk/Source/WebCore/editing/Editor.h	2015-02-21 00:09:48 UTC (rev 180465)
@@ -432,6 +432,7 @@
     WEBCORE_EXPORT void readSelectionFromPasteboard(const String& pasteboardName, MailBlockquoteHandling = MailBlockquoteHandling::RespectBlockquote);
     WEBCORE_EXPORT void replaceNodeFromPasteboard(Node*, const String& pasteboardName);
     WEBCORE_EXPORT PassRefPtr<SharedBuffer> dataSelectionForPasteboard(const String& pasteboardName);
+    WEBCORE_EXPORT void applyFontStyles(const String& fontFamily, double fontSize, unsigned fontTraits);
 #endif // !PLATFORM(IOS)
     WEBCORE_EXPORT void replaceSelectionWithAttributedString(NSAttributedString *, MailBlockquoteHandling = MailBlockquoteHandling::RespectBlockquote);
 #endif

Modified: trunk/Source/WebCore/editing/mac/EditorMac.mm (180464 => 180465)


--- trunk/Source/WebCore/editing/mac/EditorMac.mm	2015-02-20 23:27:39 UTC (rev 180464)
+++ trunk/Source/WebCore/editing/mac/EditorMac.mm	2015-02-21 00:09:48 UTC (rev 180465)
@@ -27,6 +27,8 @@
 #import "Editor.h"
 
 #import "BlockExceptions.h"
+#import "CSSPrimitiveValueMappings.h"
+#import "CSSValuePool.h"
 #import "CachedResourceLoader.h"
 #import "ColorMac.h"
 #import "DOMRangeInternal.h"
@@ -681,4 +683,14 @@
     }
 }
 
+void Editor::applyFontStyles(const String& fontFamily, double fontSize, unsigned fontTraits)
+{
+    Ref<MutableStyleProperties> style = MutableStyleProperties::create();
+    style->setProperty(CSSPropertyFontFamily, cssValuePool().createFontFamilyValue(fontFamily));
+    style->setProperty(CSSPropertyFontStyle, (fontTraits & NSFontItalicTrait) ? CSSValueItalic : CSSValueNormal);
+    style->setProperty(CSSPropertyFontWeight, cssValuePool().createValue(fontTraits & NSFontBoldTrait ? FontWeightBold : FontWeightNormal));
+    style->setProperty(CSSPropertyFontSize, cssValuePool().createValue(fontSize, CSSPrimitiveValue::CSS_PX));
+    applyStyleToSelection(style.ptr(), EditActionSetFont);
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebKit2/ChangeLog (180464 => 180465)


--- trunk/Source/WebKit2/ChangeLog	2015-02-20 23:27:39 UTC (rev 180464)
+++ trunk/Source/WebKit2/ChangeLog	2015-02-21 00:09:48 UTC (rev 180465)
@@ -1,3 +1,54 @@
+2015-02-20  Enrica Casucci  <[email protected]>
+
+        [WK2] Add support for font panel on OS X.
+        https://bugs.webkit.org/show_bug.cgi?id=141777
+
+        Reviewed by Tim Horton.
+
+        This patch adds the necessary hooks to WKView to support
+        the font panel. It also includes refactoring of WebPage::editorState
+        and WebPageProxy::editorStateChanged to separate the different platform
+        specific tasks.
+
+        * Shared/EditorState.cpp:
+        (WebKit::EditorState::encode):
+        (WebKit::EditorState::decode):
+        * Shared/EditorState.h:
+        (WebKit::EditorState::EditorState):
+        * UIProcess/API/mac/WKView.mm:
+        (-[WKView _selectionChanged]):
+        (-[WKView changeFont:]):
+        * UIProcess/API/mac/WKViewInternal.h:
+        * UIProcess/PageClient.h:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::editorStateChanged): Deleted.
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/efl/WebPageProxyEfl.cpp:
+        (WebKit::WebPageProxy::editorStateChanged):
+        * UIProcess/gtk/WebPageProxyGtk.cpp:
+        (WebKit::WebPageProxy::editorStateChanged):
+        * UIProcess/ios/WebPageProxyIOS.mm:
+        (WebKit::WebPageProxy::editorStateChanged):
+        * UIProcess/mac/PageClientImpl.h:
+        * UIProcess/mac/PageClientImpl.mm:
+        (WebKit::PageClientImpl::selectionDidChange):
+        * UIProcess/mac/WebPageProxyMac.mm:
+        (WebKit::WebPageProxy::setFont):
+        (WebKit::WebPageProxy::editorStateChanged):
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::editorState):
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in:
+        * WebProcess/WebPage/efl/WebPageEfl.cpp:
+        (WebKit::WebPage::platformEditorState):
+        * WebProcess/WebPage/gtk/WebPageGtk.cpp:
+        (WebKit::WebPage::platformEditorState):
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::platformEditorState):
+        * WebProcess/WebPage/mac/WebPageMac.mm:
+        (WebKit::WebPage::platformEditorState):
+        (WebKit::WebPage::setFont):
+
 2015-02-20  Chris Dumez  <[email protected]>
 
         [WK2] Add more detailed diagnostic logging for measuring network cache efficacy

Modified: trunk/Source/WebKit2/Shared/EditorState.cpp (180464 => 180465)


--- trunk/Source/WebKit2/Shared/EditorState.cpp	2015-02-20 23:27:39 UTC (rev 180464)
+++ trunk/Source/WebKit2/Shared/EditorState.cpp	2015-02-21 00:09:48 UTC (rev 180465)
@@ -42,6 +42,12 @@
     encoder << isInPlugin;
     encoder << hasComposition;
 
+#if PLATFORM(MAC)
+    encoder << fontName;
+    encoder << fontSize;
+    encoder << selectionHasMultipleFonts;
+#endif
+
 #if PLATFORM(IOS)
     encoder << isReplaceAllowed;
     encoder << hasContent;
@@ -90,6 +96,17 @@
     if (!decoder.decode(result.hasComposition))
         return false;
 
+#if PLATFORM(MAC)
+    if (!decoder.decode(result.fontName))
+        return false;
+
+    if (!decoder.decode(result.fontSize))
+        return false;
+
+    if (!decoder.decode(result.selectionHasMultipleFonts))
+        return false;
+#endif
+
 #if PLATFORM(IOS)
     if (!decoder.decode(result.isReplaceAllowed))
         return false;

Modified: trunk/Source/WebKit2/Shared/EditorState.h (180464 => 180465)


--- trunk/Source/WebKit2/Shared/EditorState.h	2015-02-20 23:27:39 UTC (rev 180464)
+++ trunk/Source/WebKit2/Shared/EditorState.h	2015-02-21 00:09:48 UTC (rev 180465)
@@ -53,6 +53,10 @@
         , isInPasswordField(false)
         , isInPlugin(false)
         , hasComposition(false)
+#if PLATFORM(MAC)
+        , selectionHasMultipleFonts(false)
+        , fontSize(0)
+#endif
 #if PLATFORM(IOS)
         , isReplaceAllowed(false)
         , hasContent(false)
@@ -75,6 +79,12 @@
     bool isInPlugin;
     bool hasComposition;
 
+#if PLATFORM(MAC)
+    bool selectionHasMultipleFonts;
+    String fontName;
+    double fontSize;
+#endif
+
 #if PLATFORM(IOS)
     bool isReplaceAllowed;
     bool hasContent;

Modified: trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm (180464 => 180465)


--- trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm	2015-02-20 23:27:39 UTC (rev 180464)
+++ trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm	2015-02-21 00:09:48 UTC (rev 180465)
@@ -737,6 +737,26 @@
     return _data->_page->readSelectionFromPasteboard([pasteboard name]);
 }
 
+// Font panel support.
+
+- (void)_selectionChanged
+{
+    const EditorState& editorState = _data->_page->editorState();
+    if (editorState.selectionIsNone || !editorState.isContentEditable)
+        return;
+    NSFont *font = [NSFont fontWithName:editorState.fontName size:editorState.fontSize];
+    [[NSFontManager sharedFontManager] setSelectedFont:font isMultiple:editorState.selectionHasMultipleFonts];
+}
+
+- (void)changeFont:(id)sender
+{
+    NSFontManager *fontManager = [NSFontManager sharedFontManager];
+    NSFont *font = [fontManager convertFont:[fontManager selectedFont]];
+    if (!font)
+        return;
+    _data->_page->setFont([font familyName], [font pointSize], [[font fontDescriptor] symbolicTraits]);
+}
+
 /*
 
 When possible, editing-related methods should be implemented in WebCore with the
@@ -745,7 +765,6 @@
 
 Editing-related methods still unimplemented that are implemented in WebKit1:
 
-- (void)changeFont:(id)sender;
 - (void)complete:(id)sender;
 - (void)copyFont:(id)sender;
 - (void)makeBaseWritingDirectionLeftToRight:(id)sender;

Modified: trunk/Source/WebKit2/UIProcess/API/mac/WKViewInternal.h (180464 => 180465)


--- trunk/Source/WebKit2/UIProcess/API/mac/WKViewInternal.h	2015-02-20 23:27:39 UTC (rev 180464)
+++ trunk/Source/WebKit2/UIProcess/API/mac/WKViewInternal.h	2015-02-21 00:09:48 UTC (rev 180465)
@@ -87,6 +87,7 @@
 - (NSRect)_convertToUserSpace:(NSRect)rect;
 - (void)_setTextIndicator:(PassRefPtr<WebCore::TextIndicator>)textIndicator fadeOut:(BOOL)fadeOut;
 - (void)_setTextIndicatorAnimationProgress:(float)progress;
+- (void)_selectionChanged;
 
 - (void)_setAcceleratedCompositingModeRootLayer:(CALayer *)rootLayer;
 - (CALayer *)_acceleratedCompositingModeRootLayer;

Modified: trunk/Source/WebKit2/UIProcess/PageClient.h (180464 => 180465)


--- trunk/Source/WebKit2/UIProcess/PageClient.h	2015-02-20 23:27:39 UTC (rev 180464)
+++ trunk/Source/WebKit2/UIProcess/PageClient.h	2015-02-21 00:09:48 UTC (rev 180465)
@@ -181,6 +181,7 @@
     virtual LayerOrView *acceleratedCompositingRootLayer() const = 0;
     virtual PassRefPtr<ViewSnapshot> takeViewSnapshot() = 0;
     virtual void wheelEventWasNotHandledByWebCore(const NativeWebWheelEvent&) = 0;
+    virtual void selectionDidChange() = 0;
 #endif
 
 #if PLATFORM(MAC) && !USE(ASYNC_NSTEXTINPUTCLIENT)
@@ -268,7 +269,6 @@
     virtual void startAssistingNode(const AssistedNodeInformation&, bool userIsInteracting, bool blurPreviousNode, API::Object* userData) = 0;
     virtual void stopAssistingNode() = 0;
     virtual bool isAssistingNode() = 0;
-    virtual void selectionDidChange() = 0;
     virtual bool interpretKeyEvent(const NativeWebKeyboardEvent&, bool isCharEvent) = 0;
     virtual void positionInformationDidChange(const InteractionInformationAtPosition&) = 0;
     virtual void saveImageToLibrary(PassRefPtr<WebCore::SharedBuffer>) = 0;

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp (180464 => 180465)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp	2015-02-20 23:27:39 UTC (rev 180464)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp	2015-02-21 00:09:48 UTC (rev 180465)
@@ -3758,50 +3758,6 @@
     count = m_backForwardList->forwardListCount();
 }
 
-void WebPageProxy::editorStateChanged(const EditorState& editorState)
-{
-#if PLATFORM(COCOA)
-    bool couldChangeSecureInputState = m_editorState.isInPasswordField != editorState.isInPasswordField || m_editorState.selectionIsNone;
-#endif
-#if PLATFORM(MAC) && !USE(ASYNC_NSTEXTINPUTCLIENT)
-    bool closedComposition = !editorState.shouldIgnoreCompositionSelectionChange && !editorState.hasComposition && (m_editorState.hasComposition || m_temporarilyClosedComposition);
-    m_temporarilyClosedComposition = editorState.shouldIgnoreCompositionSelectionChange && (m_temporarilyClosedComposition || m_editorState.hasComposition) && !editorState.hasComposition;
-    bool editabilityChanged = m_editorState.isContentEditable != editorState.isContentEditable;
-#endif
-
-    m_editorState = editorState;
-
-#if PLATFORM(COCOA)
-    // Selection being none is a temporary state when editing. Flipping secure input state too quickly was causing trouble (not fully understood).
-    if (couldChangeSecureInputState && !editorState.selectionIsNone)
-        m_pageClient.updateSecureInputState();
-#endif
-
-    if (editorState.shouldIgnoreCompositionSelectionChange)
-        return;
-
-#if PLATFORM(MAC) && !USE(ASYNC_NSTEXTINPUTCLIENT)
-    if (closedComposition)
-        m_pageClient.notifyInputContextAboutDiscardedComposition();
-    if (editabilityChanged) {
-        // This is only needed in sync code path, because AppKit automatically refreshes input context for async clients (<rdar://problem/18604360>).
-        m_pageClient.notifyApplicationAboutInputContextChange();
-    }
-    if (editorState.hasComposition) {
-        // Abandon the current inline input session if selection changed for any other reason but an input method changing the composition.
-        // FIXME: This logic should be in WebCore, no need to round-trip to UI process to cancel the composition.
-        cancelComposition();
-        m_pageClient.notifyInputContextAboutDiscardedComposition();
-    }
-#elif PLATFORM(IOS)
-    // We always need to notify the client on iOS to make sure the selection is redrawn,
-    // even during composition to support phrase boundary gesture.
-    notifyRevealedSelection();
-#elif PLATFORM(EFL) || PLATFORM(GTK)
-    m_pageClient.updateTextInputState();
-#endif
-}
-
 void WebPageProxy::compositionWasCanceled(const EditorState& editorState)
 {
 #if PLATFORM(COCOA)

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.h (180464 => 180465)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2015-02-20 23:27:39 UTC (rev 180464)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2015-02-21 00:09:48 UTC (rev 180465)
@@ -538,6 +538,7 @@
 #if PLATFORM(MAC)
     void insertDictatedTextAsync(const String& text, const EditingRange& replacementRange, const Vector<WebCore::TextAlternativeWithRange>& dictationAlternatives, bool registerUndoGroup);
     void attributedSubstringForCharacterRangeAsync(const EditingRange&, std::function<void (const AttributedString&, const EditingRange&, CallbackBase::Error)>);
+    void setFont(const String& fontFamily, double fontSize, uint64_t fontTraits);
 
 #if !USE(ASYNC_NSTEXTINPUTCLIENT)
     bool insertText(const String& text, const EditingRange& replacementRange);

Modified: trunk/Source/WebKit2/UIProcess/efl/WebPageProxyEfl.cpp (180464 => 180465)


--- trunk/Source/WebKit2/UIProcess/efl/WebPageProxyEfl.cpp	2015-02-20 23:27:39 UTC (rev 180464)
+++ trunk/Source/WebKit2/UIProcess/efl/WebPageProxyEfl.cpp	2015-02-21 00:09:48 UTC (rev 180465)
@@ -83,6 +83,15 @@
     notImplemented();
 }
 
+void WebPageProxy::editorStateChanged(const EditorState& editorState)
+{
+    m_editorState = editorState;
+    
+    if (editorState.shouldIgnoreCompositionSelectionChange)
+        return;
+    m_pageClient.updateTextInputState();
+}
+
 void WebPageProxy::setThemePath(const String& themePath)
 {
     if (!isValid())

Modified: trunk/Source/WebKit2/UIProcess/gtk/WebPageProxyGtk.cpp (180464 => 180465)


--- trunk/Source/WebKit2/UIProcess/gtk/WebPageProxyGtk.cpp	2015-02-20 23:27:39 UTC (rev 180464)
+++ trunk/Source/WebKit2/UIProcess/gtk/WebPageProxyGtk.cpp	2015-02-21 00:09:48 UTC (rev 180465)
@@ -76,6 +76,15 @@
     notImplemented();
 }
 
+void WebPageProxy::editorStateChanged(const EditorState& editorState)
+{
+    m_editorState = editorState;
+    
+    if (editorState.shouldIgnoreCompositionSelectionChange)
+        return;
+    m_pageClient.updateTextInputState();
+}
+
 #if PLUGIN_ARCHITECTURE(X11)
 typedef HashMap<uint64_t, GtkWidget* > PluginWindowMap;
 static PluginWindowMap& pluginWindowMap()

Modified: trunk/Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm (180464 => 180465)


--- trunk/Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm	2015-02-20 23:27:39 UTC (rev 180464)
+++ trunk/Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm	2015-02-21 00:09:48 UTC (rev 180465)
@@ -884,6 +884,24 @@
     process().send(Messages::WebPage::ContentSizeCategoryDidChange(contentSizeCategory), m_pageID);
 }
 
+void WebPageProxy::editorStateChanged(const EditorState& editorState)
+{
+    bool couldChangeSecureInputState = m_editorState.isInPasswordField != editorState.isInPasswordField || m_editorState.selectionIsNone;
+    
+    m_editorState = editorState;
+    
+    // Selection being none is a temporary state when editing. Flipping secure input state too quickly was causing trouble (not fully understood).
+    if (couldChangeSecureInputState && !editorState.selectionIsNone)
+        m_pageClient.updateSecureInputState();
+    
+    if (editorState.shouldIgnoreCompositionSelectionChange)
+        return;
+    
+    // We always need to notify the client on iOS to make sure the selection is redrawn,
+    // even during composition to support phrase boundary gesture.
+    notifyRevealedSelection();
+}
+
 #if USE(QUICK_LOOK)
     
 void WebPageProxy::didStartLoadForQuickLookDocumentInMainFrame(const String& fileName, const String& uti)

Modified: trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.h (180464 => 180465)


--- trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.h	2015-02-20 23:27:39 UTC (rev 180464)
+++ trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.h	2015-02-21 00:09:48 UTC (rev 180465)
@@ -98,6 +98,7 @@
     virtual void updateSecureInputState() override;
     virtual void resetSecureInputState() override;
     virtual void notifyInputContextAboutDiscardedComposition() override;
+    virtual void selectionDidChange();
 #if PLATFORM(MAC) && !USE(ASYNC_NSTEXTINPUTCLIENT)
     virtual void notifyApplicationAboutInputContextChange() override;
 #endif

Modified: trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.mm (180464 => 180465)


--- trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.mm	2015-02-20 23:27:39 UTC (rev 180464)
+++ trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.mm	2015-02-21 00:09:48 UTC (rev 180465)
@@ -531,6 +531,11 @@
     return [m_wkView _takeViewSnapshot];
 }
 
+void PageClientImpl::selectionDidChange()
+{
+    [m_wkView _selectionChanged];
+}
+
 void PageClientImpl::wheelEventWasNotHandledByWebCore(const NativeWebWheelEvent& event)
 {
     [m_wkView _wheelEventWasNotHandledByWebCore:event.nativeEvent()];

Modified: trunk/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm (180464 => 180465)


--- trunk/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm	2015-02-20 23:27:39 UTC (rev 180464)
+++ trunk/Source/WebKit2/UIProcess/mac/WebPageProxyMac.mm	2015-02-21 00:09:48 UTC (rev 180465)
@@ -665,7 +665,51 @@
 {
     return applicationIsAppleMail();
 }
+
+void WebPageProxy::setFont(const String& fontFamily, double fontSize, uint64_t fontTraits)
+{
+    if (!isValid())
+        return;
+
+    process().send(Messages::WebPage::SetFont(fontFamily, fontSize, fontTraits), m_pageID);
+}
+
+void WebPageProxy::editorStateChanged(const EditorState& editorState)
+{
+    bool couldChangeSecureInputState = m_editorState.isInPasswordField != editorState.isInPasswordField || m_editorState.selectionIsNone;
+#if !USE(ASYNC_NSTEXTINPUTCLIENT)
+    bool closedComposition = !editorState.shouldIgnoreCompositionSelectionChange && !editorState.hasComposition && (m_editorState.hasComposition || m_temporarilyClosedComposition);
+    m_temporarilyClosedComposition = editorState.shouldIgnoreCompositionSelectionChange && (m_temporarilyClosedComposition || m_editorState.hasComposition) && !editorState.hasComposition;
+    bool editabilityChanged = m_editorState.isContentEditable != editorState.isContentEditable;
+#endif
     
+    m_editorState = editorState;
+    
+    // Selection being none is a temporary state when editing. Flipping secure input state too quickly was causing trouble (not fully understood).
+    if (couldChangeSecureInputState && !editorState.selectionIsNone)
+        m_pageClient.updateSecureInputState();
+    
+    if (editorState.shouldIgnoreCompositionSelectionChange)
+        return;
+    
+    m_pageClient.selectionDidChange();
+
+#if !USE(ASYNC_NSTEXTINPUTCLIENT)
+    if (closedComposition)
+        m_pageClient.notifyInputContextAboutDiscardedComposition();
+    if (editabilityChanged) {
+        // This is only needed in sync code path, because AppKit automatically refreshes input context for async clients (<rdar://problem/18604360>).
+        m_pageClient.notifyApplicationAboutInputContextChange();
+    }
+    if (editorState.hasComposition) {
+        // Abandon the current inline input session if selection changed for any other reason but an input method changing the composition.
+        // FIXME: This logic should be in WebCore, no need to round-trip to UI process to cancel the composition.
+        cancelComposition();
+        m_pageClient.notifyInputContextAboutDiscardedComposition();
+    }
+#endif
+}
+    
 } // namespace WebKit
 
 #endif // PLATFORM(MAC)

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp (180464 => 180465)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp	2015-02-20 23:27:39 UTC (rev 180464)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp	2015-02-21 00:09:48 UTC (rev 180465)
@@ -764,77 +764,9 @@
     result.isInPasswordField = selection.isInPasswordField();
     result.hasComposition = frame.editor().hasComposition();
     result.shouldIgnoreCompositionSelectionChange = frame.editor().ignoreCompositionSelectionChange();
+    
+    platformEditorState(frame, result);
 
-#if PLATFORM(IOS)
-    if (frame.editor().hasComposition()) {
-        RefPtr<Range> compositionRange = frame.editor().compositionRange();
-        Vector<WebCore::SelectionRect> compositionRects;
-        compositionRange->collectSelectionRects(compositionRects);
-        if (compositionRects.size())
-            result.firstMarkedRect = compositionRects[0].rect();
-        if (compositionRects.size() > 1)
-            result.lastMarkedRect = compositionRects.last().rect();
-        else
-            result.lastMarkedRect = result.firstMarkedRect;
-        result.markedText = plainTextReplacingNoBreakSpace(compositionRange.get());
-    }
-    FrameView* view = frame.view();
-    if (selection.isCaret()) {
-        result.caretRectAtStart = view->contentsToRootView(frame.selection().absoluteCaretBounds());
-        result.caretRectAtEnd = result.caretRectAtStart;
-        // FIXME: The following check should take into account writing direction.
-        result.isReplaceAllowed = result.isContentEditable && atBoundaryOfGranularity(selection.start(), WordGranularity, DirectionForward);
-        result.wordAtSelection = plainTextReplacingNoBreakSpace(wordRangeFromPosition(selection.start()).get());
-        if (selection.isContentEditable()) {
-            charactersAroundPosition(selection.start(), result.characterAfterSelection, result.characterBeforeSelection, result.twoCharacterBeforeSelection);
-            Node* root = selection.rootEditableElement();
-            result.hasContent = root && root->hasChildNodes() && !isEndOfEditableOrNonEditableContent(firstPositionInNode(root));
-        }
-    } else if (selection.isRange()) {
-        result.caretRectAtStart = view->contentsToRootView(VisiblePosition(selection.start()).absoluteCaretBounds());
-        result.caretRectAtEnd = view->contentsToRootView(VisiblePosition(selection.end()).absoluteCaretBounds());
-        RefPtr<Range> selectedRange = selection.toNormalizedRange();
-        selectedRange->collectSelectionRects(result.selectionRects);
-        convertSelectionRectsToRootView(view, result.selectionRects);
-        String selectedText = plainTextReplacingNoBreakSpace(selectedRange.get(), TextIteratorDefaultBehavior, true);
-        // FIXME: We should disallow replace when the string contains only CJ characters.
-        result.isReplaceAllowed = result.isContentEditable && !result.isInPasswordField && !selectedText.containsOnlyWhitespace();
-        result.selectedTextLength = selectedText.length();
-        const int maxSelectedTextLength = 200;
-        if (selectedText.length() <= maxSelectedTextLength)
-            result.wordAtSelection = selectedText;
-    }
-    if (!selection.isNone()) {
-        Node* nodeToRemove;
-        if (RenderStyle* style = Editor::styleForSelectionStart(&frame, nodeToRemove)) {
-            CTFontRef font = style->fontCascade().primaryFont().getCTFont();
-            CTFontSymbolicTraits traits = font ? CTFontGetSymbolicTraits(font) : 0;
-            
-            if (traits & kCTFontTraitBold)
-                result.typingAttributes |= AttributeBold;
-            if (traits & kCTFontTraitItalic)
-                result.typingAttributes |= AttributeItalics;
-
-            RefPtr<EditingStyle> typingStyle = frame.selection().typingStyle();
-            if (typingStyle && typingStyle->style()) {
-                String value = typingStyle->style()->getPropertyValue(CSSPropertyWebkitTextDecorationsInEffect);
-                if (value.contains("underline"))
-                    result.typingAttributes |= AttributeUnderline;
-            } else {
-                if (style->textDecorationsInEffect() & TextDecorationUnderline)
-                    result.typingAttributes |= AttributeUnderline;
-            }
-
-            if (nodeToRemove)
-                nodeToRemove->remove(ASSERT_NO_EXCEPTION);
-        }
-    }
-#endif
-
-#if PLATFORM(GTK)
-    result.cursorRect = frame.selection().absoluteCaretBounds();
-#endif
-
     return result;
 }
 

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h (180464 => 180465)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h	2015-02-20 23:27:39 UTC (rev 180464)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h	2015-02-21 00:09:48 UTC (rev 180465)
@@ -872,6 +872,7 @@
 
     void platformInitialize();
     void platformDetach();
+    void platformEditorState(WebCore::Frame&, EditorState& result) const;
 
     void didReceiveWebPageMessage(IPC::Connection&, IPC::MessageDecoder&);
     void didReceiveSyncWebPageMessage(IPC::Connection&, IPC::MessageDecoder&, std::unique_ptr<IPC::MessageEncoder>&);
@@ -1082,6 +1083,7 @@
     PassRefPtr<WebCore::Range> lookupTextAtLocation(WebCore::FloatPoint, NSDictionary **options);
     void selectLastActionMenuRange();
     void focusAndSelectLastActionMenuHitTestResult();
+    void setFont(const String& fontFamily, double fontSize, uint64_t fontTraits);
 
     void dataDetectorsDidPresentUI(WebCore::PageOverlay::PageOverlayID);
     void dataDetectorsDidChangeUI(WebCore::PageOverlay::PageOverlayID);

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in (180464 => 180465)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in	2015-02-20 23:27:39 UTC (rev 180464)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in	2015-02-21 00:09:48 UTC (rev 180465)
@@ -166,6 +166,7 @@
 
 #if PLATFORM(MAC)
     PerformDictionaryLookupOfCurrentSelection()
+    SetFont(String fontFamily, double fontSize, uint64_t fontTraits)
 #endif
 
     PreferencesDidChange(struct WebKit::WebPreferencesStore store)

Modified: trunk/Source/WebKit2/WebProcess/WebPage/efl/WebPageEfl.cpp (180464 => 180465)


--- trunk/Source/WebKit2/WebProcess/WebPage/efl/WebPageEfl.cpp	2015-02-20 23:27:39 UTC (rev 180464)
+++ trunk/Source/WebKit2/WebProcess/WebPage/efl/WebPageEfl.cpp	2015-02-21 00:09:48 UTC (rev 180465)
@@ -82,6 +82,10 @@
     notImplemented();
 }
 
+void WebPage::platformEditorState(Frame&, EditorState&) const
+{
+}
+
 bool WebPage::performDefaultBehaviorForKeyEvent(const WebKeyboardEvent& keyboardEvent)
 {
     if (keyboardEvent.type() != WebEvent::KeyDown && keyboardEvent.type() != WebEvent::RawKeyDown)

Modified: trunk/Source/WebKit2/WebProcess/WebPage/gtk/WebPageGtk.cpp (180464 => 180465)


--- trunk/Source/WebKit2/WebProcess/WebPage/gtk/WebPageGtk.cpp	2015-02-20 23:27:39 UTC (rev 180464)
+++ trunk/Source/WebKit2/WebProcess/WebPage/gtk/WebPageGtk.cpp	2015-02-21 00:09:48 UTC (rev 180465)
@@ -28,6 +28,7 @@
 #include "config.h"
 #include "WebPage.h"
 
+#include "EditorState.h"
 #include "NotImplemented.h"
 #include "WebEvent.h"
 #include "WebPageAccessibilityObject.h"
@@ -67,6 +68,11 @@
 {
 }
 
+void WebPage::platformEditorState(Frame& frame, EditorState& result) const
+{
+    result.cursorRect = frame.selection().absoluteCaretBounds();
+}
+
 #if HAVE(ACCESSIBILITY)
 void WebPage::updateAccessibilityTree()
 {

Modified: trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm (180464 => 180465)


--- trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm	2015-02-20 23:27:39 UTC (rev 180464)
+++ trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm	2015-02-21 00:09:48 UTC (rev 180465)
@@ -86,6 +86,7 @@
 #import <WebCore/RenderThemeIOS.h>
 #import <WebCore/RenderView.h>
 #import <WebCore/SharedBuffer.h>
+#import <WebCore/StyleProperties.h>
 #import <WebCore/TextIterator.h>
 #import <WebCore/VisibleUnits.h>
 #import <WebCore/WKContentObservation.h>
@@ -127,6 +128,74 @@
     notImplemented();
 }
 
+void WebPage::platformEditorState(Frame& frame, EditorState& result) const
+{
+    const VisibleSelection& selection = frame.selection().selection();
+    if (frame.editor().hasComposition()) {
+        RefPtr<Range> compositionRange = frame.editor().compositionRange();
+        Vector<WebCore::SelectionRect> compositionRects;
+        compositionRange->collectSelectionRects(compositionRects);
+        if (compositionRects.size())
+            result.firstMarkedRect = compositionRects[0].rect();
+        if (compositionRects.size() > 1)
+            result.lastMarkedRect = compositionRects.last().rect();
+        else
+            result.lastMarkedRect = result.firstMarkedRect;
+        result.markedText = plainTextReplacingNoBreakSpace(compositionRange.get());
+    }
+    FrameView* view = frame.view();
+    if (selection.isCaret()) {
+        result.caretRectAtStart = view->contentsToRootView(frame.selection().absoluteCaretBounds());
+        result.caretRectAtEnd = result.caretRectAtStart;
+        // FIXME: The following check should take into account writing direction.
+        result.isReplaceAllowed = result.isContentEditable && atBoundaryOfGranularity(selection.start(), WordGranularity, DirectionForward);
+        result.wordAtSelection = plainTextReplacingNoBreakSpace(wordRangeFromPosition(selection.start()).get());
+        if (selection.isContentEditable()) {
+            charactersAroundPosition(selection.start(), result.characterAfterSelection, result.characterBeforeSelection, result.twoCharacterBeforeSelection);
+            Node* root = selection.rootEditableElement();
+            result.hasContent = root && root->hasChildNodes() && !isEndOfEditableOrNonEditableContent(firstPositionInNode(root));
+        }
+    } else if (selection.isRange()) {
+        result.caretRectAtStart = view->contentsToRootView(VisiblePosition(selection.start()).absoluteCaretBounds());
+        result.caretRectAtEnd = view->contentsToRootView(VisiblePosition(selection.end()).absoluteCaretBounds());
+        RefPtr<Range> selectedRange = selection.toNormalizedRange();
+        selectedRange->collectSelectionRects(result.selectionRects);
+        convertSelectionRectsToRootView(view, result.selectionRects);
+        String selectedText = plainTextReplacingNoBreakSpace(selectedRange.get(), TextIteratorDefaultBehavior, true);
+        // FIXME: We should disallow replace when the string contains only CJ characters.
+        result.isReplaceAllowed = result.isContentEditable && !result.isInPasswordField && !selectedText.containsOnlyWhitespace();
+        result.selectedTextLength = selectedText.length();
+        const int maxSelectedTextLength = 200;
+        if (selectedText.length() <= maxSelectedTextLength)
+            result.wordAtSelection = selectedText;
+    }
+    if (!selection.isNone()) {
+        Node* nodeToRemove;
+        if (RenderStyle* style = Editor::styleForSelectionStart(&frame, nodeToRemove)) {
+            CTFontRef font = style->fontCascade().primaryFont().getCTFont();
+            CTFontSymbolicTraits traits = font ? CTFontGetSymbolicTraits(font) : 0;
+            
+            if (traits & kCTFontTraitBold)
+                result.typingAttributes |= AttributeBold;
+            if (traits & kCTFontTraitItalic)
+                result.typingAttributes |= AttributeItalics;
+            
+            RefPtr<EditingStyle> typingStyle = frame.selection().typingStyle();
+            if (typingStyle && typingStyle->style()) {
+                String value = typingStyle->style()->getPropertyValue(CSSPropertyWebkitTextDecorationsInEffect);
+                if (value.contains("underline"))
+                    result.typingAttributes |= AttributeUnderline;
+            } else {
+                if (style->textDecorationsInEffect() & TextDecorationUnderline)
+                    result.typingAttributes |= AttributeUnderline;
+            }
+            
+            if (nodeToRemove)
+                nodeToRemove->remove(ASSERT_NO_EXCEPTION);
+        }
+    }
+}
+
 FloatSize WebPage::screenSize() const
 {
     return m_screenSize;

Modified: trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm (180464 => 180465)


--- trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm	2015-02-20 23:27:39 UTC (rev 180464)
+++ trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm	2015-02-21 00:09:48 UTC (rev 180465)
@@ -117,7 +117,20 @@
 {
     [m_mockAccessibilityElement setWebPage:nullptr];
 }
+
+void WebPage::platformEditorState(Frame& frame, EditorState& result) const
+{
+    if (frame.selection().selection().isNone())
+        return;
     
+    const Font* font = frame.editor().fontForSelection(result.selectionHasMultipleFonts);
+    NSFont *nsFont = font ? font->getNSFont() : nil;
+    if (nsFont) {
+        result.fontName = nsFont.fontName;
+        result.fontSize = nsFont.pointSize;
+    }
+}
+
 NSObject *WebPage::accessibilityObjectForMainFramePlugin()
 {
     if (!m_page)
@@ -1159,6 +1172,12 @@
     }
 }
 
+void WebPage::setFont(const String& fontFamily, double fontSize, uint64_t fontTraits)
+{
+    Frame& frame = m_page->focusController().focusedOrMainFrame();
+    frame.editor().applyFontStyles(fontFamily, fontSize, fontTraits);
+}
+
 } // namespace WebKit
 
 #endif // PLATFORM(MAC)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to