[ContentChangeObserver] Introduce ContentChangeObserver::MouseMovedScope
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 3 Mar 2019 02:50:52 +0000 (02:50 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 3 Mar 2019 02:50:52 +0000 (02:50 +0000)
https://bugs.webkit.org/show_bug.cgi?id=195252
<rdar://problem/48539446>

Reviewed by Simon Fraser.

Source/WebCore:

Scope the mouse-moved event to make the callsites less error-prone.

* page/ios/ContentChangeObserver.cpp:
(WebCore::ContentChangeObserver::startObservingMouseMoved):
(WebCore::ContentChangeObserver::stopObservingMouseMoved):
(WebCore::ContentChangeObserver::MouseMovedScope::MouseMovedScope):
(WebCore::ContentChangeObserver::MouseMovedScope::~MouseMovedScope):
(WebCore::ContentChangeObserver::startObservingContentChanges): Deleted.
(WebCore::ContentChangeObserver::stopObservingContentChanges): Deleted.
* page/ios/ContentChangeObserver.h:
* page/ios/EventHandlerIOS.mm:
(WebCore::EventHandler::mouseMoved):

Source/WebKit:

* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::handleSyntheticClick):

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

Source/WebCore/ChangeLog
Source/WebCore/page/ios/ContentChangeObserver.cpp
Source/WebCore/page/ios/ContentChangeObserver.h
Source/WebCore/page/ios/EventHandlerIOS.mm
Source/WebKit/ChangeLog
Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm

index 69ec099..64e301f 100644 (file)
@@ -1,5 +1,26 @@
 2019-03-02  Zalan Bujtas  <zalan@apple.com>
 
+        [ContentChangeObserver] Introduce ContentChangeObserver::MouseMovedScope
+        https://bugs.webkit.org/show_bug.cgi?id=195252
+        <rdar://problem/48539446>
+
+        Reviewed by Simon Fraser.
+
+        Scope the mouse-moved event to make the callsites less error-prone. 
+
+        * page/ios/ContentChangeObserver.cpp:
+        (WebCore::ContentChangeObserver::startObservingMouseMoved):
+        (WebCore::ContentChangeObserver::stopObservingMouseMoved):
+        (WebCore::ContentChangeObserver::MouseMovedScope::MouseMovedScope):
+        (WebCore::ContentChangeObserver::MouseMovedScope::~MouseMovedScope):
+        (WebCore::ContentChangeObserver::startObservingContentChanges): Deleted.
+        (WebCore::ContentChangeObserver::stopObservingContentChanges): Deleted.
+        * page/ios/ContentChangeObserver.h:
+        * page/ios/EventHandlerIOS.mm:
+        (WebCore::EventHandler::mouseMoved):
+
+2019-03-02  Zalan Bujtas  <zalan@apple.com>
+
         [ContentChangeObserver] Introduce ContentChangeObserver::adjustObservedState
         https://bugs.webkit.org/show_bug.cgi?id=195244
         <rdar://problem/48536737>
index af92dc2..dab2a21 100644 (file)
@@ -147,7 +147,7 @@ void ContentChangeObserver::contentVisibilityDidChange()
     adjustObservedState(Event::ContentVisibilityChanged);
 }
 
-void ContentChangeObserver::startObservingContentChanges()
+void ContentChangeObserver::startObservingMouseMoved()
 {
     ASSERT(!hasPendingStyleRecalc(m_page));
     clearObservedDOMTimers();
@@ -156,7 +156,7 @@ void ContentChangeObserver::startObservingContentChanges()
     adjustObservedState(Event::ContentObservationStarted);
 }
 
-void ContentChangeObserver::stopObservingContentChanges()
+void ContentChangeObserver::stopObservingMouseMoved()
 {
     stopObservingDOMTimerScheduling();
     m_isObservingContentChanges = false;
@@ -287,6 +287,19 @@ ContentChangeObserver::StyleChangeScope::~StyleChangeScope()
         m_contentChangeObserver->contentVisibilityDidChange();
 }
 
+ContentChangeObserver::MouseMovedScope::MouseMovedScope(Page* page)
+    : m_contentChangeObserver(page ? &page->contentChangeObserver() : nullptr)
+{
+    if (m_contentChangeObserver)
+        m_contentChangeObserver->startObservingMouseMoved();
+}
+
+ContentChangeObserver::MouseMovedScope::~MouseMovedScope()
+{
+    if (m_contentChangeObserver)
+        m_contentChangeObserver->stopObservingMouseMoved();
+}
+
 ContentChangeObserver::StyleRecalcScope::StyleRecalcScope(Page* page)
     : m_contentChangeObserver(page ? &page->contentChangeObserver() : nullptr)
 {
index 5172ee0..73ae578 100644 (file)
@@ -38,8 +38,6 @@ class ContentChangeObserver {
 public:
     ContentChangeObserver(Page&);
 
-    WEBCORE_EXPORT void startObservingContentChanges();
-    WEBCORE_EXPORT void stopObservingContentChanges();
     WEBCORE_EXPORT WKContentChange observedContentChange() const;
 
     void didInstallDOMTimer(const DOMTimer&, Seconds timeout, bool singleShot);
@@ -62,6 +60,14 @@ public:
         Visibility m_previousImplicitVisibility;
     };
 
+    class MouseMovedScope {
+    public:
+        WEBCORE_EXPORT MouseMovedScope(Page*);
+        WEBCORE_EXPORT ~MouseMovedScope();
+    private:
+        ContentChangeObserver* m_contentChangeObserver { nullptr };
+    };
+
     class StyleRecalcScope {
     public:
         StyleRecalcScope(Page*);
@@ -80,6 +86,9 @@ public:
     };
 
 private:
+    void startObservingMouseMoved();
+    void stopObservingMouseMoved();
+
     void startObservingDOMTimerScheduling() { m_isObservingDOMTimerScheduling = true; }
     void stopObservingDOMTimerScheduling() { m_isObservingDOMTimerScheduling = false; }
 
index de989ce..4f7003b 100644 (file)
@@ -494,16 +494,13 @@ void EventHandler::mouseMoved(WebEvent *event)
     auto& document = *m_frame.document();
     // Ensure we start mouse move event dispatching on a clear tree.
     document.updateStyleIfNeeded();
-
-    auto& contentChangeObserver = document.page()->contentChangeObserver();
-    contentChangeObserver.startObservingContentChanges();
-
     CurrentEventScope scope(event);
-    event.wasHandled = mouseMoved(currentPlatformMouseEvent());
-
-    // Run style recalc to be able to capture content changes as the result of the mouse move event.
-    document.updateStyleIfNeeded();
-    contentChangeObserver.stopObservingContentChanges();
+    {
+        ContentChangeObserver::MouseMovedScope observingScope(document.page());
+        event.wasHandled = mouseMoved(currentPlatformMouseEvent());
+        // Run style recalc to be able to capture content changes as the result of the mouse move event.
+        document.updateStyleIfNeeded();
+    }
 
     END_BLOCK_OBJC_EXCEPTIONS;
 }
index e3cea15..c111656 100644 (file)
@@ -1,3 +1,14 @@
+2019-03-02  Zalan Bujtas  <zalan@apple.com>
+
+        [ContentChangeObserver] Introduce ContentChangeObserver::MouseMovedScope
+        https://bugs.webkit.org/show_bug.cgi?id=195252
+        <rdar://problem/48539446>
+
+        Reviewed by Simon Fraser.
+
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::handleSyntheticClick):
+
 2019-03-02  Tim Horton  <timothy_horton@apple.com>
 
         Move EditingRange <-> Range methods to EditingRange instead of WebPage
index d6d14b1..bbce20f 100644 (file)
@@ -541,18 +541,17 @@ void WebPage::handleSyntheticClick(Node* nodeRespondingToClick, const WebCore::F
     auto& mainframe = m_page->mainFrame();
     auto& contentChangeObserver = m_page->contentChangeObserver();
 
-    LOG_WITH_STREAM(ContentObservation, stream << "handleSyntheticClick: node(" << nodeRespondingToClick << ") " << location);
-    contentChangeObserver.startObservingContentChanges();
-
     // FIXME: Pass caps lock state.
     bool shiftKey = modifiers.contains(WebEvent::Modifier::ShiftKey);
     bool ctrlKey = modifiers.contains(WebEvent::Modifier::ControlKey);
     bool altKey = modifiers.contains(WebEvent::Modifier::AltKey);
     bool metaKey = modifiers.contains(WebEvent::Modifier::MetaKey);
-    mainframe.eventHandler().mouseMoved(PlatformMouseEvent(roundedAdjustedPoint, roundedAdjustedPoint, NoButton, PlatformEvent::MouseMoved, 0, shiftKey, ctrlKey, altKey, metaKey, WallTime::now(), WebCore::ForceAtClick, WebCore::NoTap));
-    mainframe.document()->updateStyleIfNeeded();
-
-    contentChangeObserver.stopObservingContentChanges();
+    {
+        LOG_WITH_STREAM(ContentObservation, stream << "handleSyntheticClick: node(" << nodeRespondingToClick << ") " << location);
+        ContentChangeObserver::MouseMovedScope observingScope(m_page.get());
+        mainframe.eventHandler().mouseMoved(PlatformMouseEvent(roundedAdjustedPoint, roundedAdjustedPoint, NoButton, PlatformEvent::MouseMoved, 0, shiftKey, ctrlKey, altKey, metaKey, WallTime::now(), WebCore::ForceAtClick, WebCore::NoTap));
+        mainframe.document()->updateStyleIfNeeded();
+    }
 
     m_pendingSyntheticClickNode = nullptr;
     m_pendingSyntheticClickLocation = FloatPoint();