Need SPI for clients to require a user action to get an editing controls
authorbdakin@apple.com <bdakin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 23 May 2016 22:06:57 +0000 (22:06 +0000)
committerbdakin@apple.com <bdakin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 23 May 2016 22:06:57 +0000 (22:06 +0000)
manager
https://bugs.webkit.org/show_bug.cgi?id=157992
-and corresponding-
rdar://problem/26379927

Reviewed by Tim Horton.

New SPI _setRequiresUserActionForEditingControlsManager. The SPI defaults to
False, which means that by default there is no user action requirement to
have an editing controls manager. The SPI is on WKViewPrivate and
WKWebViewConfigurationPrivate, and it’s implemented in WebViewImpl.
* UIProcess/API/Cocoa/WKViewPrivate.h:
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _initializeWithConfiguration:]):
* UIProcess/API/Cocoa/WKWebViewConfiguration.mm:
(-[WKWebViewConfiguration init]):
(-[WKWebViewConfiguration copyWithZone:]):
(-[WKWebViewConfiguration _requiresUserActionForEditingControlsManager]):
(-[WKWebViewConfiguration _setRequiresUserActionForEditingControlsManager:]):
* UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h:
* UIProcess/API/mac/WKView.mm:
(-[WKView _requiresUserActionForEditingControlsManager]):
(-[WKView _setRequiresUserActionForEditingControlsManager:]):
* UIProcess/Cocoa/WebViewImpl.h:
(WebKit::WebViewImpl::setRequiresUserActionForEditingControlsManager):
(WebKit::WebViewImpl::requiresUserActionForEditingControlsManager):

New message allows the WebProcess to tell the UI process whether the current
web page has had any selection changes based on user interaction.
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::setHasHadSelectionChangesFromUserInteraction):
* UIProcess/WebPageProxy.h:
(WebKit::WebPageProxy::hasHadSelectionChangesFromUserInteraction):
* UIProcess/WebPageProxy.messages.in:

m_userIsInteracting m_hasFocusedDueToUserInteraction used to be iOS only, but
now we want to track them for Mac as well.
* WebProcess/WebPage/WebPage.cpp:

Handling mouse events and key events will toggle m_userIsInteracting.
(WebKit::WebPage::mouseEvent):
(WebKit::WebPage::keyEvent):

m_userIsInteracting is no longer iOS-only.
(WebKit::WebPage::setInitialFocus):

Send a message to the UI process on page transition to re-set
hasHadSelectionChangesFromUserInteraction to false.
(WebKit::WebPage::didStartPageTransition):

Send a message to the UI process if this is the first selection change to
happen as a result of a user action.
(WebKit::WebPage::didChangeSelection):
* WebProcess/WebPage/WebPage.h:

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

12 files changed:
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/Cocoa/WKViewPrivate.h
Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit2/UIProcess/API/Cocoa/WKWebViewConfiguration.mm
Source/WebKit2/UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h
Source/WebKit2/UIProcess/API/mac/WKView.mm
Source/WebKit2/UIProcess/Cocoa/WebViewImpl.h
Source/WebKit2/UIProcess/WebPageProxy.cpp
Source/WebKit2/UIProcess/WebPageProxy.h
Source/WebKit2/UIProcess/WebPageProxy.messages.in
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.h

index 1f05206..66c6dee 100644 (file)
@@ -1,3 +1,61 @@
+2016-05-23  Beth Dakin  <bdakin@apple.com>
+
+        Need SPI for clients to require a user action to get an editing controls 
+        manager
+        https://bugs.webkit.org/show_bug.cgi?id=157992
+        -and corresponding-
+        rdar://problem/26379927
+
+        Reviewed by Tim Horton.
+
+        New SPI _setRequiresUserActionForEditingControlsManager. The SPI defaults to 
+        False, which means that by default there is no user action requirement to 
+        have an editing controls manager. The SPI is on WKViewPrivate and 
+        WKWebViewConfigurationPrivate, and it’s implemented in WebViewImpl.
+        * UIProcess/API/Cocoa/WKViewPrivate.h:
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _initializeWithConfiguration:]):
+        * UIProcess/API/Cocoa/WKWebViewConfiguration.mm:
+        (-[WKWebViewConfiguration init]):
+        (-[WKWebViewConfiguration copyWithZone:]):
+        (-[WKWebViewConfiguration _requiresUserActionForEditingControlsManager]):
+        (-[WKWebViewConfiguration _setRequiresUserActionForEditingControlsManager:]):
+        * UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h:
+        * UIProcess/API/mac/WKView.mm:
+        (-[WKView _requiresUserActionForEditingControlsManager]):
+        (-[WKView _setRequiresUserActionForEditingControlsManager:]):
+        * UIProcess/Cocoa/WebViewImpl.h:
+        (WebKit::WebViewImpl::setRequiresUserActionForEditingControlsManager):
+        (WebKit::WebViewImpl::requiresUserActionForEditingControlsManager):
+
+        New message allows the WebProcess to tell the UI process whether the current 
+        web page has had any selection changes based on user interaction.
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::setHasHadSelectionChangesFromUserInteraction):
+        * UIProcess/WebPageProxy.h:
+        (WebKit::WebPageProxy::hasHadSelectionChangesFromUserInteraction):
+        * UIProcess/WebPageProxy.messages.in:
+
+        m_userIsInteracting m_hasFocusedDueToUserInteraction used to be iOS only, but 
+        now we want to track them for Mac as well.
+        * WebProcess/WebPage/WebPage.cpp:
+
+        Handling mouse events and key events will toggle m_userIsInteracting.
+        (WebKit::WebPage::mouseEvent):
+        (WebKit::WebPage::keyEvent):
+
+        m_userIsInteracting is no longer iOS-only.
+        (WebKit::WebPage::setInitialFocus):
+
+        Send a message to the UI process on page transition to re-set 
+        hasHadSelectionChangesFromUserInteraction to false.
+        (WebKit::WebPage::didStartPageTransition):
+
+        Send a message to the UI process if this is the first selection change to 
+        happen as a result of a user action.
+        (WebKit::WebPage::didChangeSelection):
+        * WebProcess/WebPage/WebPage.h:
+
 2016-05-23  Alex Christensen  <achristensen@webkit.org>
 
         Add logging for NSURLSession calls
index 6c91cae..493bfb0 100644 (file)
@@ -87,6 +87,8 @@
 @property (strong, nonatomic, setter=_setInspectorAttachmentView:) NSView *_inspectorAttachmentView WK_AVAILABLE(10_11, NA);
 #endif
 
+@property (nonatomic, readwrite, setter=_setRequiresUserActionForEditingControlsManager:) BOOL _requiresUserActionForEditingControlsManager;
+
 - (NSView*)fullScreenPlaceholderView;
 - (NSWindow*)createFullScreenWindow;
 
index f0da905..f4e55f6 100644 (file)
@@ -536,6 +536,7 @@ static uint32_t convertSystemLayoutDirection(NSUserInterfaceLayoutDirection dire
     _page = &_impl->page();
 
     _impl->setAutomaticallyAdjustsContentInsets(true);
+    _impl->setRequiresUserActionForEditingControlsManager([configuration _requiresUserActionForEditingControlsManager]);
 #endif
 
     _page->setBackgroundExtendsBeyondPage(true);
index 9ddc014..ea0aace 100644 (file)
@@ -120,6 +120,7 @@ private:
     BOOL _showsURLsInToolTips;
     BOOL _serviceControlsEnabled;
     BOOL _imageControlsEnabled;
+    BOOL _requiresUserActionForEditingControlsManager;
 #endif
 
 #if USE(APPLE_INTERNAL_SDK)
@@ -168,6 +169,7 @@ private:
     _showsURLsInToolTips = NO;
     _serviceControlsEnabled = NO;
     _imageControlsEnabled = NO;
+    _requiresUserActionForEditingControlsManager = NO;
 #endif
 
 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
@@ -290,6 +292,7 @@ private:
     configuration->_showsURLsInToolTips = self->_showsURLsInToolTips;
     configuration->_serviceControlsEnabled = self->_serviceControlsEnabled;
     configuration->_imageControlsEnabled = self->_imageControlsEnabled;
+    configuration->_requiresUserActionForEditingControlsManager = self->_requiresUserActionForEditingControlsManager;
 #endif
 #if ENABLE(DATA_DETECTION) && PLATFORM(IOS)
     configuration->_dataDetectorTypes = self->_dataDetectorTypes;
@@ -676,6 +679,17 @@ static NSString *defaultApplicationNameForUserAgent()
 {
     _imageControlsEnabled = imageControlsEnabled;
 }
+
+- (BOOL)_requiresUserActionForEditingControlsManager
+{
+    return _requiresUserActionForEditingControlsManager;
+}
+
+- (void)_setRequiresUserActionForEditingControlsManager:(BOOL)requiresUserAction
+{
+    _requiresUserActionForEditingControlsManager = requiresUserAction;
+}
+
 #endif // PLATFORM(MAC)
 
 #if USE(APPLE_INTERNAL_SDK)
index 6482ef0..7623746 100644 (file)
@@ -63,6 +63,7 @@
 @property (nonatomic, setter=_setShowsURLsInToolTips:) BOOL _showsURLsInToolTips WK_AVAILABLE(WK_MAC_TBA, NA);
 @property (nonatomic, setter=_setServiceControlsEnabled:) BOOL _serviceControlsEnabled WK_AVAILABLE(WK_MAC_TBA, NA);
 @property (nonatomic, setter=_setImageControlsEnabled:) BOOL _imageControlsEnabled WK_AVAILABLE(WK_MAC_TBA, NA);
+@property (nonatomic, readwrite, setter=_setRequiresUserActionForEditingControlsManager:) BOOL _requiresUserActionForEditingControlsManager WK_AVAILABLE(WK_MAC_TBA, NA);
 #endif
 
 @property (nonatomic, strong, setter=_setVisitedLinkProvider:) _WKVisitedLinkProvider *_visitedLinkProvider WK_DEPRECATED(10_10, WK_MAC_TBA, 8_0, WK_IOS_TBA, "Please use _visitedLinkStore instead");
index cdfa150..f6c783e 100644 (file)
@@ -1107,6 +1107,16 @@ Some other editing-related methods still unimplemented:
 }
 #endif
 
+- (BOOL)_requiresUserActionForEditingControlsManager
+{
+    return _data->_impl->requiresUserActionForEditingControlsManager();
+}
+
+- (void)_setRequiresUserActionForEditingControlsManager:(BOOL)requiresUserAction
+{
+    _data->_impl->setRequiresUserActionForEditingControlsManager(requiresUserAction);
+}
+
 - (NSView *)fullScreenPlaceholderView
 {
     return _data->_impl->fullScreenPlaceholderView();
index 008dfa4..f166667 100644 (file)
@@ -478,6 +478,9 @@ public:
 
     bool windowIsFrontWindowUnderMouse(NSEvent *);
 
+    void setRequiresUserActionForEditingControlsManager(bool requiresUserActionForEditingControlsManager) { m_requiresUserActionForEditingControlsManager = requiresUserActionForEditingControlsManager; }
+    bool requiresUserActionForEditingControlsManager() const { return m_requiresUserActionForEditingControlsManager; }
+
 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200 
     void handleAcceptedCandidate(NSTextCheckingResult *acceptedCandidate);
 #if USE(APPLE_INTERNAL_SDK)
@@ -635,6 +638,7 @@ private:
 #endif
     NSRange m_softSpaceRange { NSNotFound, 0 };
     bool m_isHandlingAcceptedCandidate { false };
+    bool m_requiresUserActionForEditingControlsManager { false };
 };
     
 } // namespace WebKit
index 7772c2a..5795b25 100644 (file)
@@ -4076,6 +4076,11 @@ void WebPageProxy::setAllowsMediaDocumentInlinePlayback(bool allows)
 }
 #endif
 
+void WebPageProxy::setHasHadSelectionChangesFromUserInteraction(bool hasHadUserSelectionChanges)
+{
+    m_hasHadSelectionChangesFromUserInteraction = hasHadUserSelectionChanges;
+}
+
 // BackForwardList
 
 void WebPageProxy::backForwardAddItem(uint64_t itemID)
index afff84c..1f9dc04 100644 (file)
@@ -1108,6 +1108,8 @@ public:
 
     UserInterfaceLayoutDirection userInterfaceLayoutDirection();
 
+    bool hasHadSelectionChangesFromUserInteraction() const { return m_hasHadSelectionChangesFromUserInteraction; }
+
 private:
     WebPageProxy(PageClient&, WebProcessProxy&, uint64_t pageID, Ref<API::PageConfiguration>&&);
     void platformInitialize();
@@ -1265,6 +1267,7 @@ private:
 
     void editorStateChanged(const EditorState&);
     void compositionWasCanceled(const EditorState&);
+    void setHasHadSelectionChangesFromUserInteraction(bool);
 
     // Back/Forward list management
     void backForwardAddItem(uint64_t itemID);
@@ -1807,6 +1810,8 @@ private:
 
     bool m_isResourceCachingDisabled { false };
 
+    bool m_hasHadSelectionChangesFromUserInteraction { false };
+
 #if ENABLE(MEDIA_SESSION)
     bool m_hasMediaSessionWithActiveMediaElements { false };
 #endif
index 8764a26..96cb9e8 100644 (file)
@@ -233,6 +233,7 @@ messages -> WebPageProxy {
     # Editor notifications
     EditorStateChanged(struct WebKit::EditorState editorState)
     CompositionWasCanceled(struct WebKit::EditorState editorState)
+    SetHasHadSelectionChangesFromUserInteraction(bool hasHadUserSelectionChanges)
 
     # Find messages
     DidCountStringMatches(String string, uint32_t matchCount)
index 71f4925..df63407 100644 (file)
@@ -341,6 +341,7 @@ WebPage::WebPage(uint64_t pageID, const WebPageCreationParameters& parameters)
     , m_hasWheelEventHandlers(false)
     , m_cachedPageCount(0)
     , m_autoSizingShouldExpandToViewHeight(false)
+    , m_userIsInteracting(false)
 #if ENABLE(CONTEXT_MENUS)
     , m_isShowingContextMenu(false)
 #endif
@@ -350,7 +351,6 @@ WebPage::WebPage(uint64_t pageID, const WebPageCreationParameters& parameters)
     , m_scaleWasSetByUIProcess(false)
     , m_userHasChangedPageScaleFactor(false)
     , m_hasStablePageScaleFactor(true)
-    , m_userIsInteracting(false)
     , m_hasPendingBlurNotification(false)
     , m_useTestingViewportConfiguration(false)
     , m_isInStableState(true)
@@ -2173,6 +2173,8 @@ static bool handleMouseEvent(const WebMouseEvent& mouseEvent, WebPage* page, boo
 
 void WebPage::mouseEvent(const WebMouseEvent& mouseEvent)
 {
+    m_userIsInteracting = true;
+
     m_page->pageThrottler().didReceiveUserInput();
 
     bool shouldHandleEvent = true;
@@ -2189,6 +2191,7 @@ void WebPage::mouseEvent(const WebMouseEvent& mouseEvent)
 
     if (!shouldHandleEvent) {
         send(Messages::WebPageProxy::DidReceiveEvent(static_cast<uint32_t>(mouseEvent.type()), false));
+        m_userIsInteracting = false;
         return;
     }
 
@@ -2214,6 +2217,7 @@ void WebPage::mouseEvent(const WebMouseEvent& mouseEvent)
     }
 
     send(Messages::WebPageProxy::DidReceiveEvent(static_cast<uint32_t>(mouseEvent.type()), handled));
+    m_userIsInteracting = false;
 }
 
 static bool handleWheelEvent(const WebWheelEvent& wheelEvent, Page* page)
@@ -2249,6 +2253,8 @@ static bool handleKeyEvent(const WebKeyboardEvent& keyboardEvent, Page* page)
 
 void WebPage::keyEvent(const WebKeyboardEvent& keyboardEvent)
 {
+    m_userIsInteracting = true;
+
     m_page->pageThrottler().didReceiveUserInput();
 
     CurrentEvent currentEvent(keyboardEvent);
@@ -2259,6 +2265,8 @@ void WebPage::keyEvent(const WebKeyboardEvent& keyboardEvent)
         handled = performDefaultBehaviorForKeyEvent(keyboardEvent);
 
     send(Messages::WebPageProxy::DidReceiveEvent(static_cast<uint32_t>(keyboardEvent.type()), handled));
+
+    m_userIsInteracting = false;
 }
 
 void WebPage::validateCommand(const String& commandName, uint64_t callbackID)
@@ -2461,9 +2469,7 @@ void WebPage::setInitialFocus(bool forward, bool isKeyboardEventValid, const Web
     if (!m_page)
         return;
 
-#if PLATFORM(IOS)
     TemporaryChange<bool> userIsInteractingChange { m_userIsInteracting, true };
-#endif
 
     Frame& frame = m_page->focusController().focusedOrMainFrame();
     frame.document()->setFocusedElement(0);
@@ -2558,8 +2564,14 @@ void WebPage::didReceivePolicyDecision(uint64_t frameID, uint64_t listenerID, ui
 void WebPage::didStartPageTransition()
 {
     m_drawingArea->setLayerTreeStateIsFrozen(true);
-#if PLATFORM(IOS)
+
+#if PLATFORM(MAC)
+    bool hasPreviouslyFocusedDueToUserInteraction = m_hasFocusedDueToUserInteraction;
+#endif
     m_hasFocusedDueToUserInteraction = false;
+#if PLATFORM(MAC)
+    if (hasPreviouslyFocusedDueToUserInteraction)
+        send(Messages::WebPageProxy::SetHasHadSelectionChangesFromUserInteraction(m_hasFocusedDueToUserInteraction));
 #endif
 }
 
@@ -4697,6 +4709,11 @@ void WebPage::didChangeSelection()
     m_isEditorStateMissingPostLayoutData = editorState.isMissingPostLayoutData;
 
 #if PLATFORM(MAC)
+    bool hasPreviouslyFocusedDueToUserInteraction = m_hasFocusedDueToUserInteraction;
+    m_hasFocusedDueToUserInteraction |= m_userIsInteracting;
+    if (!hasPreviouslyFocusedDueToUserInteraction && m_hasFocusedDueToUserInteraction)
+        send(Messages::WebPageProxy::SetHasHadSelectionChangesFromUserInteraction(m_hasFocusedDueToUserInteraction));
+
     // Abandon the current inline input session if selection changed for any other reason but an input method direct action.
     // FIXME: This logic should be in WebCore.
     // FIXME: Many changes that affect composition node do not go through didChangeSelection(). We need to do something when DOM manipulation affects the composition, because otherwise input method's idea about it will be different from Editor's.
index 2fa3f20..b92c774 100644 (file)
@@ -1376,6 +1376,9 @@ private:
     WebCore::IntSize m_minimumLayoutSize;
     bool m_autoSizingShouldExpandToViewHeight;
 
+    bool m_userIsInteracting;
+    bool m_hasFocusedDueToUserInteraction { false };
+
 #if ENABLE(CONTEXT_MENUS)
     bool m_isShowingContextMenu;
 #endif
@@ -1400,8 +1403,6 @@ private:
     bool m_scaleWasSetByUIProcess;
     bool m_userHasChangedPageScaleFactor;
     bool m_hasStablePageScaleFactor;
-    bool m_userIsInteracting;
-    bool m_hasFocusedDueToUserInteraction { false };
     bool m_hasPendingBlurNotification;
     bool m_useTestingViewportConfiguration;
     bool m_isInStableState;