Title: [191570] releases/WebKitGTK/webkit-2.10
Revision
191570
Author
[email protected]
Date
2015-10-26 01:36:15 -0700 (Mon, 26 Oct 2015)

Log Message

Merge r191451 - REGRESSION (r181972): Scroll position changes to top of youtube page when switching tabs
https://bugs.webkit.org/show_bug.cgi?id=150428

Reviewed by Antti Koivisto.

Source/WebCore:

The bug was caused by updateFocusAppearance in WebPage::restoreSelectionInFocusedEditableElement
revealing the focused element which was added in r181972. Fixed the bug by adding an option to
suppress this behavior here.

* dom/Document.cpp:
(WebCore::Document::Document):
(WebCore::Document::updateFocusAppearanceSoon):
* dom/Document.h:
* dom/Element.cpp:
(WebCore::Element::focus):
(WebCore::Element::updateFocusAppearanceAfterAttachIfNeeded):
(WebCore::Element::updateFocusAppearance):
* dom/Element.h:
* history/CachedPage.cpp:
(WebCore::CachedPage::restore):
* html/HTMLAreaElement.cpp:
(WebCore::HTMLAreaElement::updateFocusAppearance):
* html/HTMLAreaElement.h:
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::updateFocusAppearance):
(WebCore::HTMLInputElement::runPostTypeUpdateTasks):
(WebCore::HTMLInputElement::didAttachRenderers):
* html/HTMLInputElement.h:
* html/HTMLTextAreaElement.cpp:
(WebCore::HTMLTextAreaElement::updateFocusAppearance):
* html/HTMLTextAreaElement.h:

Source/WebKit2:

Call updateFocusAppearance with RevealMode::DoNotReveal to avoid revealing the focused element.

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::restoreSelectionInFocusedEditableElement):

Tools:

Added a regression test using WebKit API test.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/mac/FirstResponderScrollingPosition.mm: Added.
(TestWebKitAPI::didFinishLoadForFrame):
(TestWebKitAPI::TEST):

Modified Paths

Added Paths

Diff

Modified: releases/WebKitGTK/webkit-2.10/Source/WebCore/ChangeLog (191569 => 191570)


--- releases/WebKitGTK/webkit-2.10/Source/WebCore/ChangeLog	2015-10-26 08:18:03 UTC (rev 191569)
+++ releases/WebKitGTK/webkit-2.10/Source/WebCore/ChangeLog	2015-10-26 08:36:15 UTC (rev 191570)
@@ -1,3 +1,37 @@
+2015-10-22  Ryosuke Niwa  <[email protected]>
+
+        REGRESSION (r181972): Scroll position changes to top of youtube page when switching tabs
+        https://bugs.webkit.org/show_bug.cgi?id=150428
+
+        Reviewed by Antti Koivisto.
+
+        The bug was caused by updateFocusAppearance in WebPage::restoreSelectionInFocusedEditableElement
+        revealing the focused element which was added in r181972. Fixed the bug by adding an option to
+        suppress this behavior here.
+
+        * dom/Document.cpp:
+        (WebCore::Document::Document):
+        (WebCore::Document::updateFocusAppearanceSoon):
+        * dom/Document.h:
+        * dom/Element.cpp:
+        (WebCore::Element::focus):
+        (WebCore::Element::updateFocusAppearanceAfterAttachIfNeeded):
+        (WebCore::Element::updateFocusAppearance):
+        * dom/Element.h:
+        * history/CachedPage.cpp:
+        (WebCore::CachedPage::restore):
+        * html/HTMLAreaElement.cpp:
+        (WebCore::HTMLAreaElement::updateFocusAppearance):
+        * html/HTMLAreaElement.h:
+        * html/HTMLInputElement.cpp:
+        (WebCore::HTMLInputElement::updateFocusAppearance):
+        (WebCore::HTMLInputElement::runPostTypeUpdateTasks):
+        (WebCore::HTMLInputElement::didAttachRenderers):
+        * html/HTMLInputElement.h:
+        * html/HTMLTextAreaElement.cpp:
+        (WebCore::HTMLTextAreaElement::updateFocusAppearance):
+        * html/HTMLTextAreaElement.h:
+
 2015-10-21  Dean Jackson  <[email protected]>
 
         Null dereference loading Blink layout test svg/filters/display-none-filter-primitive.html

Modified: releases/WebKitGTK/webkit-2.10/Source/WebCore/dom/Document.cpp (191569 => 191570)


--- releases/WebKitGTK/webkit-2.10/Source/WebCore/dom/Document.cpp	2015-10-26 08:18:03 UTC (rev 191569)
+++ releases/WebKitGTK/webkit-2.10/Source/WebCore/dom/Document.cpp	2015-10-26 08:36:15 UTC (rev 191570)
@@ -452,7 +452,7 @@
     , m_closeAfterStyleRecalc(false)
     , m_gotoAnchorNeededAfterStylesheetsLoad(false)
     , m_frameElementsShouldIgnoreScrolling(false)
-    , m_updateFocusAppearanceRestoresSelection(false)
+    , m_updateFocusAppearanceRestoresSelection(SelectionRestorationMode::SetDefault)
     , m_ignoreDestructiveWriteCount(0)
     , m_markers(std::make_unique<DocumentMarkerController>())
     , m_updateFocusAppearanceTimer(*this, &Document::updateFocusAppearanceTimerFired)
@@ -5063,9 +5063,9 @@
         m_pendingStateObject = stateObject;
 }
 
-void Document::updateFocusAppearanceSoon(bool restorePreviousSelection)
+void Document::updateFocusAppearanceSoon(SelectionRestorationMode mode)
 {
-    m_updateFocusAppearanceRestoresSelection = restorePreviousSelection;
+    m_updateFocusAppearanceRestoresSelection = mode;
     if (!m_updateFocusAppearanceTimer.isActive())
         m_updateFocusAppearanceTimer.startOneShot(0);
 }

Modified: releases/WebKitGTK/webkit-2.10/Source/WebCore/dom/Document.h (191569 => 191570)


--- releases/WebKitGTK/webkit-2.10/Source/WebCore/dom/Document.h	2015-10-26 08:18:03 UTC (rev 191569)
+++ releases/WebKitGTK/webkit-2.10/Source/WebCore/dom/Document.h	2015-10-26 08:36:15 UTC (rev 191570)
@@ -271,6 +271,16 @@
 
 enum DimensionsCheck { WidthDimensionsCheck = 1 << 0, HeightDimensionsCheck = 1 << 1, AllDimensionsCheck = 1 << 2 };
 
+enum class SelectionRestorationMode {
+    Restore,
+    SetDefault,
+};
+
+enum class SelectionRevealMode {
+    Reveal,
+    DoNotReveal
+};
+
 enum class HttpEquivPolicy {
     Enabled,
     DisabledBySettings,
@@ -951,7 +961,7 @@
     bool hasNodesWithPlaceholderStyle() const { return m_hasNodesWithPlaceholderStyle; }
     void setHasNodesWithPlaceholderStyle() { m_hasNodesWithPlaceholderStyle = true; }
 
-    void updateFocusAppearanceSoon(bool restorePreviousSelection);
+    void updateFocusAppearanceSoon(SelectionRestorationMode);
     void cancelFocusAppearanceUpdate();
 
     // Extension for manipulating canvas drawing contexts for use in CSS
@@ -1474,7 +1484,7 @@
     bool m_isDNSPrefetchEnabled;
     bool m_haveExplicitlyDisabledDNSPrefetch;
     bool m_frameElementsShouldIgnoreScrolling;
-    bool m_updateFocusAppearanceRestoresSelection;
+    SelectionRestorationMode m_updateFocusAppearanceRestoresSelection;
 
     // http://www.whatwg.org/specs/web-apps/current-work/#ignore-destructive-writes-counter
     unsigned m_ignoreDestructiveWriteCount;

Modified: releases/WebKitGTK/webkit-2.10/Source/WebCore/dom/Element.cpp (191569 => 191570)


--- releases/WebKitGTK/webkit-2.10/Source/WebCore/dom/Element.cpp	2015-10-26 08:18:03 UTC (rev 191569)
+++ releases/WebKitGTK/webkit-2.10/Source/WebCore/dom/Element.cpp	2015-10-26 08:36:15 UTC (rev 191570)
@@ -2142,7 +2142,7 @@
     if (isFormControl)
         view->setProhibitsScrolling(true);
 #endif
-    updateFocusAppearance(restorePreviousSelection);
+    updateFocusAppearance(restorePreviousSelection ? SelectionRestorationMode::Restore : SelectionRestorationMode::SetDefault);
 #if PLATFORM(IOS)
     if (isFormControl)
         view->setProhibitsScrolling(false);
@@ -2157,11 +2157,11 @@
     if (!data->needsFocusAppearanceUpdateSoonAfterAttach())
         return;
     if (isFocusable() && document().focusedElement() == this)
-        document().updateFocusAppearanceSoon(false /* don't restore selection */);
+        document().updateFocusAppearanceSoon(SelectionRestorationMode::SetDefault);
     data->setNeedsFocusAppearanceUpdateSoonAfterAttach(false);
 }
 
-void Element::updateFocusAppearance(bool /*restorePreviousSelection*/)
+void Element::updateFocusAppearance(SelectionRestorationMode, SelectionRevealMode revealMode)
 {
     if (isRootEditableElement()) {
         Frame* frame = document().frame();
@@ -2177,9 +2177,10 @@
         
         if (frame->selection().shouldChangeSelection(newSelection)) {
             frame->selection().setSelection(newSelection, FrameSelection::defaultSetSelectionOptions(), Element::defaultFocusTextStateChangeIntent());
-            frame->selection().revealSelection();
+            if (revealMode == SelectionRevealMode::Reveal)
+                frame->selection().revealSelection();
         }
-    } else if (renderer() && !renderer()->isWidget())
+    } else if (renderer() && !renderer()->isWidget() && revealMode == SelectionRevealMode::Reveal)
         renderer()->scrollRectToVisible(renderer()->anchorRect());
 }
 

Modified: releases/WebKitGTK/webkit-2.10/Source/WebCore/dom/Element.h (191569 => 191570)


--- releases/WebKitGTK/webkit-2.10/Source/WebCore/dom/Element.h	2015-10-26 08:18:03 UTC (rev 191569)
+++ releases/WebKitGTK/webkit-2.10/Source/WebCore/dom/Element.h	2015-10-26 08:36:15 UTC (rev 191570)
@@ -323,7 +323,7 @@
     static AXTextStateChangeIntent defaultFocusTextStateChangeIntent() { return AXTextStateChangeIntent(AXTextStateChangeTypeSelectionMove, AXTextSelection { AXTextSelectionDirectionDiscontiguous, AXTextSelectionGranularityUnknown, true }); }
     void updateFocusAppearanceAfterAttachIfNeeded();
     virtual void focus(bool restorePreviousSelection = true, FocusDirection = FocusDirectionNone);
-    virtual void updateFocusAppearance(bool restorePreviousSelection);
+    virtual void updateFocusAppearance(SelectionRestorationMode, SelectionRevealMode = SelectionRevealMode::Reveal);
     virtual void blur();
 
     String innerHTML() const;

Modified: releases/WebKitGTK/webkit-2.10/Source/WebCore/history/CachedPage.cpp (191569 => 191570)


--- releases/WebKitGTK/webkit-2.10/Source/WebCore/history/CachedPage.cpp	2015-10-26 08:18:03 UTC (rev 191569)
+++ releases/WebKitGTK/webkit-2.10/Source/WebCore/history/CachedPage.cpp	2015-10-26 08:36:15 UTC (rev 191570)
@@ -92,7 +92,7 @@
             frameView->setProhibitsScrolling(true);
         }
 #endif
-        element->updateFocusAppearance(true);
+        element->updateFocusAppearance(SelectionRestorationMode::Restore);
 #if PLATFORM(IOS)
         if (frameView)
             frameView->setProhibitsScrolling(hadProhibitsScrolling);

Modified: releases/WebKitGTK/webkit-2.10/Source/WebCore/html/HTMLAreaElement.cpp (191569 => 191570)


--- releases/WebKitGTK/webkit-2.10/Source/WebCore/html/HTMLAreaElement.cpp	2015-10-26 08:18:03 UTC (rev 191569)
+++ releases/WebKitGTK/webkit-2.10/Source/WebCore/html/HTMLAreaElement.cpp	2015-10-26 08:36:15 UTC (rev 191570)
@@ -224,7 +224,7 @@
     downcast<RenderImage>(*renderer).areaElementFocusChanged(this);
 }
     
-void HTMLAreaElement::updateFocusAppearance(bool restorePreviousSelection)
+void HTMLAreaElement::updateFocusAppearance(SelectionRestorationMode restorationMode, SelectionRevealMode revealMode)
 {
     if (!isFocusable())
         return;
@@ -233,7 +233,7 @@
     if (!imageElement)
         return;
 
-    imageElement->updateFocusAppearance(restorePreviousSelection);
+    imageElement->updateFocusAppearance(restorationMode, revealMode);
 }
     
 bool HTMLAreaElement::supportsFocus() const

Modified: releases/WebKitGTK/webkit-2.10/Source/WebCore/html/HTMLAreaElement.h (191569 => 191570)


--- releases/WebKitGTK/webkit-2.10/Source/WebCore/html/HTMLAreaElement.h	2015-10-26 08:18:03 UTC (rev 191569)
+++ releases/WebKitGTK/webkit-2.10/Source/WebCore/html/HTMLAreaElement.h	2015-10-26 08:36:15 UTC (rev 191570)
@@ -57,7 +57,7 @@
     virtual bool isKeyboardFocusable(KeyboardEvent*) const override;
     virtual bool isMouseFocusable() const override;
     virtual bool isFocusable() const override;
-    virtual void updateFocusAppearance(bool /*restorePreviousSelection*/) override;
+    virtual void updateFocusAppearance(SelectionRestorationMode, SelectionRevealMode) override;
     virtual void setFocus(bool) override;
 
     enum Shape { Default, Poly, Rect, Circle, Unknown };

Modified: releases/WebKitGTK/webkit-2.10/Source/WebCore/html/HTMLInputElement.cpp (191569 => 191570)


--- releases/WebKitGTK/webkit-2.10/Source/WebCore/html/HTMLInputElement.cpp	2015-10-26 08:18:03 UTC (rev 191569)
+++ releases/WebKitGTK/webkit-2.10/Source/WebCore/html/HTMLInputElement.cpp	2015-10-26 08:36:15 UTC (rev 191570)
@@ -403,17 +403,17 @@
     return HTMLTextFormControlElement::isMouseFocusable();
 }
 
-void HTMLInputElement::updateFocusAppearance(bool restorePreviousSelection)
+void HTMLInputElement::updateFocusAppearance(SelectionRestorationMode restorationMode, SelectionRevealMode revealMode)
 {
     if (isTextField()) {
-        if (!restorePreviousSelection || !hasCachedSelection())
+        if (restorationMode == SelectionRestorationMode::SetDefault || !hasCachedSelection())
             select(Element::defaultFocusTextStateChangeIntent());
         else
             restoreCachedSelection();
-        if (document().frame())
+        if (document().frame() && revealMode == SelectionRevealMode::Reveal)
             document().frame()->selection().revealSelection();
     } else
-        HTMLTextFormControlElement::updateFocusAppearance(restorePreviousSelection);
+        HTMLTextFormControlElement::updateFocusAppearance(restorationMode, revealMode);
 }
 
 void HTMLInputElement::endEditing()
@@ -529,7 +529,7 @@
         setNeedsStyleRecalc(ReconstructRenderTree);
 
     if (document().focusedElement() == this)
-        updateFocusAppearance(true);
+        updateFocusAppearance(SelectionRestorationMode::Restore, SelectionRevealMode::Reveal);
 
     if (ShadowRoot* shadowRoot = shadowRootOfParentForDistribution(this))
         shadowRoot->invalidateDistribution();
@@ -789,7 +789,7 @@
     m_inputType->attach();
 
     if (document().focusedElement() == this)
-        document().updateFocusAppearanceSoon(true /* restore selection */);
+        document().updateFocusAppearanceSoon(SelectionRestorationMode::Restore);
 }
 
 void HTMLInputElement::didDetachRenderers()

Modified: releases/WebKitGTK/webkit-2.10/Source/WebCore/html/HTMLInputElement.h (191569 => 191570)


--- releases/WebKitGTK/webkit-2.10/Source/WebCore/html/HTMLInputElement.h	2015-10-26 08:18:03 UTC (rev 191569)
+++ releases/WebKitGTK/webkit-2.10/Source/WebCore/html/HTMLInputElement.h	2015-10-26 08:36:15 UTC (rev 191570)
@@ -344,7 +344,7 @@
     virtual bool isMouseFocusable() const override final;
     virtual bool isEnumeratable() const override final;
     virtual bool supportLabels() const override final;
-    virtual void updateFocusAppearance(bool restorePreviousSelection) override final;
+    virtual void updateFocusAppearance(SelectionRestorationMode, SelectionRevealMode) override final;
     virtual bool shouldUseInputMethod() override final;
 
     virtual bool isTextFormControl() const override final { return isTextField(); }

Modified: releases/WebKitGTK/webkit-2.10/Source/WebCore/html/HTMLTextAreaElement.cpp (191569 => 191570)


--- releases/WebKitGTK/webkit-2.10/Source/WebCore/html/HTMLTextAreaElement.cpp	2015-10-26 08:18:03 UTC (rev 191569)
+++ releases/WebKitGTK/webkit-2.10/Source/WebCore/html/HTMLTextAreaElement.cpp	2015-10-26 08:36:15 UTC (rev 191570)
@@ -251,9 +251,9 @@
     return isFocusable();
 }
 
-void HTMLTextAreaElement::updateFocusAppearance(bool restorePreviousSelection)
+void HTMLTextAreaElement::updateFocusAppearance(SelectionRestorationMode restorationMode, SelectionRevealMode revealMode)
 {
-    if (!restorePreviousSelection || !hasCachedSelection()) {
+    if (restorationMode == SelectionRestorationMode::SetDefault || !hasCachedSelection()) {
         // If this is the first focus, set a caret at the beginning of the text.  
         // This matches some browsers' behavior; see bug 11746 Comment #15.
         // http://bugs.webkit.org/show_bug.cgi?id=11746#c15
@@ -261,7 +261,7 @@
     } else
         restoreCachedSelection(Element::defaultFocusTextStateChangeIntent());
 
-    if (document().frame())
+    if (document().frame() && revealMode == SelectionRevealMode::Reveal)
         document().frame()->selection().revealSelection();
 }
 

Modified: releases/WebKitGTK/webkit-2.10/Source/WebCore/html/HTMLTextAreaElement.h (191569 => 191570)


--- releases/WebKitGTK/webkit-2.10/Source/WebCore/html/HTMLTextAreaElement.h	2015-10-26 08:18:03 UTC (rev 191569)
+++ releases/WebKitGTK/webkit-2.10/Source/WebCore/html/HTMLTextAreaElement.h	2015-10-26 08:36:15 UTC (rev 191570)
@@ -107,7 +107,7 @@
     virtual bool hasCustomFocusLogic() const override;
     virtual bool isMouseFocusable() const override;
     virtual bool isKeyboardFocusable(KeyboardEvent*) const override;
-    virtual void updateFocusAppearance(bool restorePreviousSelection) override;
+    virtual void updateFocusAppearance(SelectionRestorationMode, SelectionRevealMode) override;
 
     virtual void accessKeyAction(bool sendMouseEvents) override;
 

Modified: releases/WebKitGTK/webkit-2.10/Source/WebKit2/ChangeLog (191569 => 191570)


--- releases/WebKitGTK/webkit-2.10/Source/WebKit2/ChangeLog	2015-10-26 08:18:03 UTC (rev 191569)
+++ releases/WebKitGTK/webkit-2.10/Source/WebKit2/ChangeLog	2015-10-26 08:36:15 UTC (rev 191570)
@@ -1,3 +1,15 @@
+2015-10-22  Ryosuke Niwa  <[email protected]>
+
+        REGRESSION (r181972): Scroll position changes to top of youtube page when switching tabs
+        https://bugs.webkit.org/show_bug.cgi?id=150428
+
+        Reviewed by Antti Koivisto.
+
+        Call updateFocusAppearance with RevealMode::DoNotReveal to avoid revealing the focused element.
+
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::restoreSelectionInFocusedEditableElement):
+
 2015-10-21  Carlos Garcia Campos  <[email protected]>
 
         NetworkProcess: DNS prefetch happens in the Web Process

Modified: releases/WebKitGTK/webkit-2.10/Source/WebKit2/WebProcess/WebPage/WebPage.cpp (191569 => 191570)


--- releases/WebKitGTK/webkit-2.10/Source/WebKit2/WebProcess/WebPage/WebPage.cpp	2015-10-26 08:18:03 UTC (rev 191569)
+++ releases/WebKitGTK/webkit-2.10/Source/WebKit2/WebProcess/WebPage/WebPage.cpp	2015-10-26 08:36:15 UTC (rev 191570)
@@ -3486,7 +3486,7 @@
 
     if (auto document = frame.document()) {
         if (auto element = document->focusedElement())
-            element->updateFocusAppearance(true /* restoreSelection */);
+            element->updateFocusAppearance(SelectionRestorationMode::Restore, SelectionRevealMode::DoNotReveal);
     }
 }
 

Modified: releases/WebKitGTK/webkit-2.10/Tools/ChangeLog (191569 => 191570)


--- releases/WebKitGTK/webkit-2.10/Tools/ChangeLog	2015-10-26 08:18:03 UTC (rev 191569)
+++ releases/WebKitGTK/webkit-2.10/Tools/ChangeLog	2015-10-26 08:36:15 UTC (rev 191570)
@@ -1,3 +1,17 @@
+2015-10-22  Ryosuke Niwa  <[email protected]>
+
+        REGRESSION (r181972): Scroll position changes to top of youtube page when switching tabs
+        https://bugs.webkit.org/show_bug.cgi?id=150428
+
+        Reviewed by Antti Koivisto.
+
+        Added a regression test using WebKit API test.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/mac/FirstResponderScrollingPosition.mm: Added.
+        (TestWebKitAPI::didFinishLoadForFrame):
+        (TestWebKitAPI::TEST):
+
 2015-10-14  Carlos Garcia Campos  <[email protected]>
 
         [GTK] Missing return value on TestWebExtensions.cpp:193

Added: releases/WebKitGTK/webkit-2.10/Tools/TestWebKitAPI/Tests/mac/FirstResponderScrollingPosition.mm (0 => 191570)


--- releases/WebKitGTK/webkit-2.10/Tools/TestWebKitAPI/Tests/mac/FirstResponderScrollingPosition.mm	                        (rev 0)
+++ releases/WebKitGTK/webkit-2.10/Tools/TestWebKitAPI/Tests/mac/FirstResponderScrollingPosition.mm	2015-10-26 08:36:15 UTC (rev 191570)
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2011, 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "_javascript_Test.h"
+#import "PlatformUtilities.h"
+#import "PlatformWebView.h"
+#import <WebKit/WKRetainPtr.h>
+#import <WebKit/WKPage.h>
+#import <WebKit/WKPreferencesPrivate.h>
+#import <wtf/RetainPtr.h>
+
+namespace TestWebKitAPI {
+    
+static bool didFinishLoad;
+
+static void didFinishLoadForFrame(WKPageRef, WKFrameRef, WKTypeRef, const void*)
+{
+    didFinishLoad = true;
+}
+
+TEST(WebKit2, FirstResponderScrollingPosition)
+{
+    WKRetainPtr<WKContextRef> context(AdoptWK, Util::createContextWithInjectedBundle());
+
+    // Turn off threaded scrolling; synchronously waiting for the main thread scroll position to
+    // update using WKPageForceRepaint would be better, but for some reason the test still fails occasionally.
+    WKRetainPtr<WKPageGroupRef> pageGroup(AdoptWK, WKPageGroupCreateWithIdentifier(Util::toWK("NoThreadedScrollingPageGroup").get()));
+    WKPreferencesRef preferences = WKPageGroupGetPreferences(pageGroup.get());
+    WKPreferencesSetThreadedScrollingEnabled(preferences, false);
+
+    RetainPtr<NSWindow> window = adoptNS([[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 800, 600)
+        styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO]);
+    [window.get() makeKeyAndOrderFront:nil];
+    EXPECT_TRUE([window.get() isVisible]);
+
+    PlatformWebView webView(context.get(), pageGroup.get());
+
+    WKPageLoaderClientV0 loaderClient;
+    memset(&loaderClient, 0, sizeof(loaderClient));
+    loaderClient.base.version = 0;
+    loaderClient.didFinishLoadForFrame = didFinishLoadForFrame;
+    WKPageSetPageLoaderClient(webView.page(), &loaderClient.base);
+    
+    [window.get().contentView addSubview:webView.platformView()];
+    [window.get() makeFirstResponder:webView.platformView()];
+
+    WKRetainPtr<WKURLRef> url(AdoptWK, Util::createURLForResource("simple-tall", "html"));
+    WKPageLoadURL(webView.page(), url.get());
+    Util::run(&didFinishLoad);
+    didFinishLoad = false;
+
+    EXPECT_JS_EQ(webView.page(), "var input = document.createElement('input');"
+        "document.body.insertBefore(input, document.body.firstChild);"
+        "input.focus(); false", "false");
+    EXPECT_JS_EQ(webView.page(), "window.scrollY", "0");
+
+    ASSERT_TRUE([webView.platformView() respondsToSelector:@selector(scrollLineDown:)]);
+    [webView.platformView() scrollLineDown:nil];
+
+    EXPECT_JS_EQ(webView.page(), "window.scrollY", "40");
+
+    PlatformWebView newWebView(context.get(), pageGroup.get());
+    WKPageSetPageLoaderClient(newWebView.page(), &loaderClient.base);
+
+    [window.get().contentView addSubview:newWebView.platformView()];
+    [window.get() makeFirstResponder:newWebView.platformView()];
+
+    WKPageLoadURL(newWebView.page(), url.get());
+    Util::run(&didFinishLoad);
+
+    EXPECT_JS_EQ(webView.page(), "window.scrollY", "40");
+    EXPECT_JS_EQ(newWebView.page(), "window.scrollY", "0");
+
+    [window.get() makeFirstResponder:webView.platformView()];
+
+    EXPECT_JS_EQ(webView.page(), "window.scrollY", "40");
+    EXPECT_JS_EQ(newWebView.page(), "window.scrollY", "0");
+}
+    
+} // namespace TestWebKitAPI
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to