Need to updateEditorState if an element change edit-ability without changing
authorbdakin@apple.com <bdakin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 2 Sep 2016 23:14:34 +0000 (23:14 +0000)
committerbdakin@apple.com <bdakin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 2 Sep 2016 23:14:34 +0000 (23:14 +0000)
selection
https://bugs.webkit.org/show_bug.cgi?id=161546
-and corresponding-
rdar://problem/27806012

Reviewed by Ryosuke Niwa.

Source/WebCore:

Call into the client in case edited state needs to be updated.
* editing/FrameSelection.cpp:
(WebCore::FrameSelection::updateAppearanceAfterLayout):
* loader/EmptyClients.h:
* page/EditorClient.h:

Source/WebKit/mac:

Every time WebEditorClient::respondToChangedSelection is called, we now save
whether the last state was contentEditable. That way in
updateEditorStateAfterLayoutIfNeeded() we can assess whether or not edit-ability
has changed.

* WebCoreSupport/WebEditorClient.h:
* WebCoreSupport/WebEditorClient.mm:
(WebEditorClient::respondToChangedSelection):
(WebEditorClient:: updateEditorStateAfterLayoutIfEditabilityChanged):

Source/WebKit2:

Every time WebPage::editorState() is called, we now save whether the last state
was contentEditable. That way in updateEditorStateAfterLayoutIfNeeded() we can
assess whether or not edit-ability has changed.

* WebProcess/WebCoreSupport/WebEditorClient.cpp:
(WebKit::WebEditorClient:: updateEditorStateAfterLayoutIfEditabilityChanged):
* WebProcess/WebCoreSupport/WebEditorClient.h:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::editorState):
(WebKit::WebPage:: updateEditorStateAfterLayoutIfEditabilityChanged):
(WebKit::WebPage::didStartPageTransition):
* WebProcess/WebPage/WebPage.h:

LayoutTests:

This patch seems to have fixed a bug!
* editing/secure-input/removed-password-input-expected.txt:

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

14 files changed:
LayoutTests/ChangeLog
LayoutTests/editing/secure-input/removed-password-input-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/editing/FrameSelection.cpp
Source/WebCore/loader/EmptyClients.h
Source/WebCore/page/EditorClient.h
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/WebCoreSupport/WebEditorClient.h
Source/WebKit/mac/WebCoreSupport/WebEditorClient.mm
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.cpp
Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.h
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.h

index c8fef97..61a5a25 100644 (file)
@@ -1,3 +1,16 @@
+2016-09-02  Beth Dakin  <bdakin@apple.com>
+
+        Need to updateEditorState if an element change edit-ability without changing 
+        selection
+        https://bugs.webkit.org/show_bug.cgi?id=161546
+        -and corresponding-
+        rdar://problem/27806012
+
+        Reviewed by Ryosuke Niwa.
+
+        This patch seems to have fixed a bug!
+        * editing/secure-input/removed-password-input-expected.txt:
+
 2016-09-02  Jonathan Bedard  <jbedard@apple.com>
 
         WebKitTestRunner needs layoutTestController.setDashboardCompatibilityMode
index fdcce2a..307b4d6 100644 (file)
@@ -7,7 +7,7 @@ A password input is focused:
 PASS testRunner.secureEventInputIsEnabled is true
 
 After deleting the input:
-FAIL testRunner.secureEventInputIsEnabled should be false. Was true.
+PASS testRunner.secureEventInputIsEnabled is false
 PASS successfullyParsed is true
 
 TEST COMPLETE
index 3c525bc..5ba8099 100644 (file)
@@ -1,3 +1,19 @@
+2016-09-02  Beth Dakin  <bdakin@apple.com>
+
+        Need to updateEditorState if an element change edit-ability without changing 
+        selection
+        https://bugs.webkit.org/show_bug.cgi?id=161546
+        -and corresponding-
+        rdar://problem/27806012
+
+        Reviewed by Ryosuke Niwa.
+
+        Call into the client in case edited state needs to be updated. 
+        * editing/FrameSelection.cpp:
+        (WebCore::FrameSelection::updateAppearanceAfterLayout):
+        * loader/EmptyClients.h:
+        * page/EditorClient.h:
+
 2016-09-02  Zalan Bujtas  <zalan@apple.com>
 
         ASSERTION FAILED: !m_committedWidth in WebCore::LineWidth::fitBelowFloats
index 6e11049..ab446eb 100644 (file)
@@ -2382,6 +2382,9 @@ void FrameSelection::setShouldShowBlockCursor(bool shouldShowBlockCursor)
 
 void FrameSelection::updateAppearanceAfterLayout()
 {
+    if (auto* client = m_frame->editor().client())
+        client->updateEditorStateAfterLayoutIfEditabilityChanged();
+
     setCaretRectNeedsUpdate();
     updateAndRevealSelection(AXTextStateChangeIntent());
     updateDataDetectorsForSelection();
index bfc50e3..db0805b 100644 (file)
@@ -466,6 +466,7 @@ public:
     void respondToChangedContents() override { }
     void respondToChangedSelection(Frame*) override { }
     void didChangeSelectionAndUpdateLayout() override { }
+    void updateEditorStateAfterLayoutIfEditabilityChanged() override { }
     void discardedComposition(Frame*) override { }
     void didEndEditing() override { }
     void willWriteSelectionToPasteboard(Range*) override { }
index 60280ae..4f6a985 100644 (file)
@@ -91,6 +91,7 @@ public:
     virtual void respondToChangedContents() = 0;
     virtual void respondToChangedSelection(Frame*) = 0;
     virtual void didChangeSelectionAndUpdateLayout() = 0;
+    virtual void updateEditorStateAfterLayoutIfEditabilityChanged() = 0;
     virtual void didEndEditing() = 0;
     virtual void willWriteSelectionToPasteboard(Range*) = 0;
     virtual void didWriteSelectionToPasteboard() = 0;
index 511d838..909fd8b 100644 (file)
@@ -1,3 +1,23 @@
+2016-09-02  Beth Dakin  <bdakin@apple.com>
+
+        Need to updateEditorState if an element change edit-ability without changing 
+        selection
+        https://bugs.webkit.org/show_bug.cgi?id=161546
+        -and corresponding-
+        rdar://problem/27806012
+
+        Reviewed by Ryosuke Niwa.
+
+        Every time WebEditorClient::respondToChangedSelection is called, we now save 
+        whether the last state was contentEditable. That way in 
+        updateEditorStateAfterLayoutIfNeeded() we can assess whether or not edit-ability 
+        has changed. 
+
+        * WebCoreSupport/WebEditorClient.h:
+        * WebCoreSupport/WebEditorClient.mm:
+        (WebEditorClient::respondToChangedSelection):
+        (WebEditorClient:: updateEditorStateAfterLayoutIfEditabilityChanged):
+
 2016-09-02  Joseph Pecoraro  <pecoraro@apple.com>
 
         [Mac] RetainPtr misuse, AnimationController leaks
index 0657182..07a5edc 100644 (file)
@@ -111,6 +111,7 @@ private:
     void respondToChangedContents() final;
     void respondToChangedSelection(WebCore::Frame*) final;
     void didChangeSelectionAndUpdateLayout() final { }
+    void updateEditorStateAfterLayoutIfEditabilityChanged() final;
     void discardedComposition(WebCore::Frame*) final;
 
     void registerUndoStep(PassRefPtr<WebCore::UndoStep>) final;
@@ -192,6 +193,9 @@ private:
     NSInteger m_lastCandidateRequestSequenceNumber;
 #endif
 
+    enum class EditorStateIsContentEditable { No, Yes, Unset };
+    EditorStateIsContentEditable m_lastEditorStateWasContentEditable { EditorStateIsContentEditable::Unset };
+
     WeakPtrFactory<WebEditorClient> m_weakPtrFactory;
 };
 
index 0f6fb9c..5739f08 100644 (file)
@@ -345,6 +345,7 @@ void WebEditorClient::respondToChangedSelection(Frame* frame)
     if ([documentView isKindOfClass:[WebHTMLView class]]) {
         [(WebHTMLView *)documentView _selectionChanged];
         [m_webView updateWebViewAdditions];
+        m_lastEditorStateWasContentEditable = [(WebHTMLView *)documentView _isEditable] ? EditorStateIsContentEditable::Yes : EditorStateIsContentEditable::No;
     }
 
 #if !PLATFORM(IOS)
@@ -628,6 +629,26 @@ void WebEditorClient::registerUndoOrRedoStep(PassRefPtr<UndoStep> step, bool isR
     m_haveUndoRedoOperations = YES;
 }
 
+void WebEditorClient::updateEditorStateAfterLayoutIfEditabilityChanged()
+{
+    // FIXME: We should update EditorStateIsContentEditable to track whether the state is richly
+    // editable or plainttext-only.
+    if (m_lastEditorStateWasContentEditable == EditorStateIsContentEditable::Unset)
+        return;
+
+    Frame* frame = core([m_webView _selectedOrMainFrame]);
+    if (!frame)
+        return;
+
+    NSView<WebDocumentView> *documentView = [[kit(frame) frameView] documentView];
+    if (![documentView isKindOfClass:[WebHTMLView class]])
+        return;
+
+    EditorStateIsContentEditable editorStateIsContentEditable = [(WebHTMLView *)documentView _isEditable] ? EditorStateIsContentEditable::Yes : EditorStateIsContentEditable::No;
+    if (m_lastEditorStateWasContentEditable != editorStateIsContentEditable)
+        [m_webView updateWebViewAdditions];
+}
+
 void WebEditorClient::registerUndoStep(PassRefPtr<UndoStep> cmd)
 {
     registerUndoOrRedoStep(cmd, false);
index cc373e3..e193742 100644 (file)
@@ -1,3 +1,26 @@
+2016-09-02  Beth Dakin  <bdakin@apple.com>
+
+        Need to updateEditorState if an element change edit-ability without changing 
+        selection
+        https://bugs.webkit.org/show_bug.cgi?id=161546
+        -and corresponding-
+        rdar://problem/27806012
+
+        Reviewed by Ryosuke Niwa.
+
+        Every time WebPage::editorState() is called, we now save whether the last state 
+        was contentEditable. That way in updateEditorStateAfterLayoutIfNeeded() we can 
+        assess whether or not edit-ability has changed. 
+
+        * WebProcess/WebCoreSupport/WebEditorClient.cpp:
+        (WebKit::WebEditorClient:: updateEditorStateAfterLayoutIfEditabilityChanged):
+        * WebProcess/WebCoreSupport/WebEditorClient.h:
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::editorState):
+        (WebKit::WebPage:: updateEditorStateAfterLayoutIfEditabilityChanged):
+        (WebKit::WebPage::didStartPageTransition):
+        * WebProcess/WebPage/WebPage.h:
+
 2016-09-02  Jonathan Bedard  <jbedard@apple.com>
 
         WebKitTestRunner needs layoutTestController.setDashboardCompatibilityMode
index 42fc248..4c95e9f 100644 (file)
@@ -201,6 +201,11 @@ void WebEditorClient::didChangeSelectionAndUpdateLayout()
     m_page->sendPostLayoutEditorStateIfNeeded();
 }
 
+void WebEditorClient::updateEditorStateAfterLayoutIfEditabilityChanged()
+{
+    m_page->updateEditorStateAfterLayoutIfEditabilityChanged();
+}
+
 void WebEditorClient::discardedComposition(Frame*)
 {
     m_page->discardedComposition();
index 1421731..0f1a852 100644 (file)
@@ -63,6 +63,7 @@ private:
     void respondToChangedContents() final;
     void respondToChangedSelection(WebCore::Frame*) final;
     void didChangeSelectionAndUpdateLayout() final;
+    void updateEditorStateAfterLayoutIfEditabilityChanged() final;
     void discardedComposition(WebCore::Frame*) final;
     void didEndEditing() final;
     void willWriteSelectionToPasteboard(WebCore::Range*) final;
index 1a93d4a..578430d 100644 (file)
@@ -900,9 +900,24 @@ EditorState WebPage::editorState(IncludePostLayoutDataHint shouldIncludePostLayo
 
     platformEditorState(frame, result, shouldIncludePostLayoutData);
 
+    m_lastEditorStateWasContentEditable = result.isContentEditable ? EditorStateIsContentEditable::Yes : EditorStateIsContentEditable::No;
+
     return result;
 }
 
+void WebPage::updateEditorStateAfterLayoutIfEditabilityChanged()
+{
+    // FIXME: We should update EditorStateIsContentEditable to track whether the state is richly
+    // editable or plainttext-only.
+    if (m_lastEditorStateWasContentEditable == EditorStateIsContentEditable::Unset)
+        return;
+
+    Frame& frame = m_page->focusController().focusedOrMainFrame();
+    EditorStateIsContentEditable editorStateIsContentEditable = frame.selection().selection().isContentEditable() ? EditorStateIsContentEditable::Yes : EditorStateIsContentEditable::No;
+    if (m_lastEditorStateWasContentEditable != editorStateIsContentEditable)
+        send(Messages::WebPageProxy::EditorStateChanged(editorState()));
+}
+
 String WebPage::renderTreeExternalRepresentation() const
 {
     return externalRepresentation(m_mainFrame->coreFrame(), RenderAsTextBehaviorNormal);
@@ -2610,6 +2625,7 @@ void WebPage::didStartPageTransition()
 #endif
     m_hasEverFocusedElementDueToUserInteractionSincePageTransition = false;
     m_isAssistingNodeDueToUserInteraction = false;
+    m_lastEditorStateWasContentEditable = EditorStateIsContentEditable::Unset;
 #if PLATFORM(MAC)
     if (hasPreviouslyFocusedDueToUserInteraction)
         send(Messages::WebPageProxy::SetHasHadSelectionChangesFromUserInteraction(m_hasEverFocusedElementDueToUserInteractionSincePageTransition));
index 10a0f4f..0c76f65 100644 (file)
@@ -365,6 +365,7 @@ public:
     enum class IncludePostLayoutDataHint { No, Yes };
     EditorState editorState(IncludePostLayoutDataHint = IncludePostLayoutDataHint::Yes) const;
     void sendPostLayoutEditorStateIfNeeded();
+    void updateEditorStateAfterLayoutIfEditabilityChanged();
 
     String renderTreeExternalRepresentation() const;
     String renderTreeExternalRepresentationForPrinting() const;
@@ -1478,6 +1479,9 @@ private:
     bool m_shouldDispatchFakeMouseMoveEvents;
     bool m_isEditorStateMissingPostLayoutData { false };
 
+    enum class EditorStateIsContentEditable { No, Yes, Unset };
+    mutable EditorStateIsContentEditable m_lastEditorStateWasContentEditable { EditorStateIsContentEditable::Unset };
+
 #if PLATFORM(GTK)
     bool m_inputMethodEnabled { false };
 #endif