Diff
Modified: trunk/Source/WebCore/ChangeLog (191450 => 191451)
--- trunk/Source/WebCore/ChangeLog 2015-10-22 10:50:09 UTC (rev 191450)
+++ trunk/Source/WebCore/ChangeLog 2015-10-22 11:37:46 UTC (rev 191451)
@@ -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-22 Joonghun Park <[email protected]>
[EFL] Fix build break since r191439
Modified: trunk/Source/WebCore/dom/Document.cpp (191450 => 191451)
--- trunk/Source/WebCore/dom/Document.cpp 2015-10-22 10:50:09 UTC (rev 191450)
+++ trunk/Source/WebCore/dom/Document.cpp 2015-10-22 11:37:46 UTC (rev 191451)
@@ -455,7 +455,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>(*this))
, m_updateFocusAppearanceTimer(*this, &Document::updateFocusAppearanceTimerFired)
@@ -5079,9 +5079,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: trunk/Source/WebCore/dom/Document.h (191450 => 191451)
--- trunk/Source/WebCore/dom/Document.h 2015-10-22 10:50:09 UTC (rev 191450)
+++ trunk/Source/WebCore/dom/Document.h 2015-10-22 11:37:46 UTC (rev 191451)
@@ -274,6 +274,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,
@@ -966,7 +976,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
@@ -1492,7 +1502,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: trunk/Source/WebCore/dom/Element.cpp (191450 => 191451)
--- trunk/Source/WebCore/dom/Element.cpp 2015-10-22 10:50:09 UTC (rev 191450)
+++ trunk/Source/WebCore/dom/Element.cpp 2015-10-22 11:37:46 UTC (rev 191451)
@@ -2219,7 +2219,7 @@
if (isFormControl)
view->setProhibitsScrolling(true);
#endif
- updateFocusAppearance(restorePreviousSelection);
+ updateFocusAppearance(restorePreviousSelection ? SelectionRestorationMode::Restore : SelectionRestorationMode::SetDefault);
#if PLATFORM(IOS)
if (isFormControl)
view->setProhibitsScrolling(false);
@@ -2234,11 +2234,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();
@@ -2254,9 +2254,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: trunk/Source/WebCore/dom/Element.h (191450 => 191451)
--- trunk/Source/WebCore/dom/Element.h 2015-10-22 10:50:09 UTC (rev 191450)
+++ trunk/Source/WebCore/dom/Element.h 2015-10-22 11:37:46 UTC (rev 191451)
@@ -327,7 +327,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: trunk/Source/WebCore/history/CachedPage.cpp (191450 => 191451)
--- trunk/Source/WebCore/history/CachedPage.cpp 2015-10-22 10:50:09 UTC (rev 191450)
+++ trunk/Source/WebCore/history/CachedPage.cpp 2015-10-22 11:37:46 UTC (rev 191451)
@@ -92,7 +92,7 @@
frameView->setProhibitsScrolling(true);
}
#endif
- element->updateFocusAppearance(true);
+ element->updateFocusAppearance(SelectionRestorationMode::Restore);
#if PLATFORM(IOS)
if (frameView)
frameView->setProhibitsScrolling(hadProhibitsScrolling);
Modified: trunk/Source/WebCore/html/HTMLAreaElement.cpp (191450 => 191451)
--- trunk/Source/WebCore/html/HTMLAreaElement.cpp 2015-10-22 10:50:09 UTC (rev 191450)
+++ trunk/Source/WebCore/html/HTMLAreaElement.cpp 2015-10-22 11:37:46 UTC (rev 191451)
@@ -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: trunk/Source/WebCore/html/HTMLAreaElement.h (191450 => 191451)
--- trunk/Source/WebCore/html/HTMLAreaElement.h 2015-10-22 10:50:09 UTC (rev 191450)
+++ trunk/Source/WebCore/html/HTMLAreaElement.h 2015-10-22 11:37:46 UTC (rev 191451)
@@ -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: trunk/Source/WebCore/html/HTMLInputElement.cpp (191450 => 191451)
--- trunk/Source/WebCore/html/HTMLInputElement.cpp 2015-10-22 10:50:09 UTC (rev 191450)
+++ trunk/Source/WebCore/html/HTMLInputElement.cpp 2015-10-22 11:37:46 UTC (rev 191451)
@@ -402,17 +402,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()
@@ -528,7 +528,7 @@
setNeedsStyleRecalc(ReconstructRenderTree);
if (document().focusedElement() == this)
- updateFocusAppearance(true);
+ updateFocusAppearance(SelectionRestorationMode::Restore, SelectionRevealMode::Reveal);
setChangedSinceLastFormControlChangeEvent(false);
@@ -785,7 +785,7 @@
m_inputType->attach();
if (document().focusedElement() == this)
- document().updateFocusAppearanceSoon(true /* restore selection */);
+ document().updateFocusAppearanceSoon(SelectionRestorationMode::Restore);
}
void HTMLInputElement::didDetachRenderers()
Modified: trunk/Source/WebCore/html/HTMLInputElement.h (191450 => 191451)
--- trunk/Source/WebCore/html/HTMLInputElement.h 2015-10-22 10:50:09 UTC (rev 191450)
+++ trunk/Source/WebCore/html/HTMLInputElement.h 2015-10-22 11:37:46 UTC (rev 191451)
@@ -343,7 +343,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: trunk/Source/WebCore/html/HTMLTextAreaElement.cpp (191450 => 191451)
--- trunk/Source/WebCore/html/HTMLTextAreaElement.cpp 2015-10-22 10:50:09 UTC (rev 191450)
+++ trunk/Source/WebCore/html/HTMLTextAreaElement.cpp 2015-10-22 11:37:46 UTC (rev 191451)
@@ -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: trunk/Source/WebCore/html/HTMLTextAreaElement.h (191450 => 191451)
--- trunk/Source/WebCore/html/HTMLTextAreaElement.h 2015-10-22 10:50:09 UTC (rev 191450)
+++ trunk/Source/WebCore/html/HTMLTextAreaElement.h 2015-10-22 11:37:46 UTC (rev 191451)
@@ -108,7 +108,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: trunk/Source/WebKit2/ChangeLog (191450 => 191451)
--- trunk/Source/WebKit2/ChangeLog 2015-10-22 10:50:09 UTC (rev 191450)
+++ trunk/Source/WebKit2/ChangeLog 2015-10-22 11:37:46 UTC (rev 191451)
@@ -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-22 Carlos Garcia Campos <[email protected]>
Unreviewed. Fix a crash in GTk+ after r191402.
Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp (191450 => 191451)
--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp 2015-10-22 10:50:09 UTC (rev 191450)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp 2015-10-22 11:37:46 UTC (rev 191451)
@@ -3444,7 +3444,7 @@
if (auto document = frame.document()) {
if (auto element = document->focusedElement())
- element->updateFocusAppearance(true /* restoreSelection */);
+ element->updateFocusAppearance(SelectionRestorationMode::Restore, SelectionRevealMode::DoNotReveal);
}
}
Modified: trunk/Tools/ChangeLog (191450 => 191451)
--- trunk/Tools/ChangeLog 2015-10-22 10:50:09 UTC (rev 191450)
+++ trunk/Tools/ChangeLog 2015-10-22 11:37:46 UTC (rev 191451)
@@ -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-22 Carlos Garcia Campos <[email protected]>
Unreviewed. Fix GTK+ build after r191423.
Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (191450 => 191451)
--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2015-10-22 10:50:09 UTC (rev 191450)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2015-10-22 11:37:46 UTC (rev 191451)
@@ -265,6 +265,7 @@
93F7E86F14DC8E5C00C84A99 /* NewFirstVisuallyNonEmptyLayoutFrames_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93F7E86E14DC8E5B00C84A99 /* NewFirstVisuallyNonEmptyLayoutFrames_Bundle.cpp */; };
9B26FCCA159D16DE00CC3765 /* HTMLFormCollectionNamedItem.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9B26FCB4159D15E700CC3765 /* HTMLFormCollectionNamedItem.html */; };
9B4F8FA7159D52DD002D9F94 /* HTMLCollectionNamedItem.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9B4F8FA6159D52CA002D9F94 /* HTMLCollectionNamedItem.html */; };
+ 9B7916501BD89D0D00D50B8F /* FirstResponderScrollingPosition.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9B79164F1BD89D0D00D50B8F /* FirstResponderScrollingPosition.mm */; settings = {ASSET_TAGS = (); }; };
A13EBBAA1B87428D00097110 /* WebProcessPlugIn.mm in Sources */ = {isa = PBXBuildFile; fileRef = A13EBBA91B87428D00097110 /* WebProcessPlugIn.mm */; };
A13EBBAB1B87434600097110 /* PlatformUtilitiesCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0F139E721A423A2B00F590F5 /* PlatformUtilitiesCocoa.mm */; };
A13EBBB01B87436F00097110 /* BundleParametersPlugIn.mm in Sources */ = {isa = PBXBuildFile; fileRef = A13EBBAE1B87436F00097110 /* BundleParametersPlugIn.mm */; };
@@ -638,6 +639,7 @@
9B26FCB4159D15E700CC3765 /* HTMLFormCollectionNamedItem.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = HTMLFormCollectionNamedItem.html; sourceTree = "<group>"; };
9B4F8FA3159D52B1002D9F94 /* HTMLCollectionNamedItem.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = HTMLCollectionNamedItem.mm; sourceTree = "<group>"; };
9B4F8FA6159D52CA002D9F94 /* HTMLCollectionNamedItem.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = HTMLCollectionNamedItem.html; sourceTree = "<group>"; };
+ 9B79164F1BD89D0D00D50B8F /* FirstResponderScrollingPosition.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FirstResponderScrollingPosition.mm; sourceTree = "<group>"; };
A13EBB491B87339E00097110 /* TestWebKitAPI.wkbundle */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = TestWebKitAPI.wkbundle; sourceTree = BUILT_PRODUCTS_DIR; };
A13EBB521B87346600097110 /* WebProcessPlugIn.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = WebProcessPlugIn.xcconfig; sourceTree = "<group>"; };
A13EBB541B8734E000097110 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@@ -1313,6 +1315,7 @@
7A99D9931AD4A29D00373141 /* MenuTypesForMouseEvents.mm */,
E19DB9781B32137C00DB38D4 /* NavigatorLanguage.mm */,
A57A34EF16AF677200C2501F /* PageVisibilityStateWithWindowChanges.mm */,
+ 9B79164F1BD89D0D00D50B8F /* FirstResponderScrollingPosition.mm */,
00BC16851680FE810065F1E5 /* PublicSuffix.mm */,
37C784DE197C8F2E0010A496 /* RenderedImageFromDOMNode.mm */,
3722C8681461E03E00C45D00 /* RenderedImageFromDOMRange.mm */,
@@ -1752,6 +1755,7 @@
A1C4FB6E1BACCE50003742D0 /* QuickLook.mm in Sources */,
7A5623111AD5AF3E0096B920 /* MenuTypesForMouseEvents.cpp in Sources */,
51CB4AD81B3A079C00C1B1C6 /* ModalAlertsSPI.cpp in Sources */,
+ 9B7916501BD89D0D00D50B8F /* FirstResponderScrollingPosition.mm in Sources */,
1CF0D3791BBF2F3D00B4EF54 /* WKRetainPtr.cpp in Sources */,
26F6E1F01ADC749B00DE696B /* DFAMinimizer.cpp in Sources */,
260BA5791B1D2E7B004FA07C /* DFACombiner.cpp in Sources */,
Added: trunk/Tools/TestWebKitAPI/Tests/mac/FirstResponderScrollingPosition.mm (0 => 191451)
--- trunk/Tools/TestWebKitAPI/Tests/mac/FirstResponderScrollingPosition.mm (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/mac/FirstResponderScrollingPosition.mm 2015-10-22 11:37:46 UTC (rev 191451)
@@ -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