VisualViewport API should be updated upon opening of keyboard
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 16 Jan 2019 03:35:59 +0000 (03:35 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 16 Jan 2019 03:35:59 +0000 (03:35 +0000)
https://bugs.webkit.org/show_bug.cgi?id=193475

Reviewed by Simon Fraser.

Source/WebCore:

Added a function to update the visual viewport API and schedule a resize event to FrameView.

Test: fast/visual-viewport/ios/resize-event-for-keyboard.html

* page/FrameView.cpp:
(WebCore::FrameView::didUpdateViewportOverrideRects):
* page/FrameView.h:

Source/WebKit:

The bug was caused by the changes to unobscuredContentRectRespectingInputViewBounds not updating the visual viewport
unless it caused a layout to happen. Added a code to update the visual viewport in WebPage::updateVisibleContentRects.

Also fixed the bug that VisibleContentRectUpdateInfo::operator== was not checking differences in
unobscuredContentRectRespectingInputViewBounds which resulted in the visual viewport override not getting updated
while the keyboard is getting brought up.

* Shared/VisibleContentRectUpdateInfo.h:
(WebKit::operator==):
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::updateVisibleContentRects):

LayoutTests:

Added a regression test.

* fast/visual-viewport/ios/resize-event-for-keyboard-expected.txt: Added.
* fast/visual-viewport/ios/resize-event-for-keyboard.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/fast/visual-viewport/ios/resize-event-for-keyboard-expected.txt [new file with mode: 0644]
LayoutTests/fast/visual-viewport/ios/resize-event-for-keyboard.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/page/FrameView.cpp
Source/WebCore/page/FrameView.h
Source/WebKit/ChangeLog
Source/WebKit/Shared/VisibleContentRectUpdateInfo.h
Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm

index fb54e06..173660a 100644 (file)
@@ -1,3 +1,15 @@
+2019-01-15  Ryosuke Niwa  <rniwa@webkit.org>
+
+        VisualViewport API should be updated upon opening of keyboard
+        https://bugs.webkit.org/show_bug.cgi?id=193475
+
+        Reviewed by Simon Fraser.
+
+        Added a regression test.
+
+        * fast/visual-viewport/ios/resize-event-for-keyboard-expected.txt: Added.
+        * fast/visual-viewport/ios/resize-event-for-keyboard.html: Added.
+
 2019-01-15  Chris Dumez  <cdumez@apple.com>
 
         Unreviewed, rolling out r239993, r239995, r239997, and
diff --git a/LayoutTests/fast/visual-viewport/ios/resize-event-for-keyboard-expected.txt b/LayoutTests/fast/visual-viewport/ios/resize-event-for-keyboard-expected.txt
new file mode 100644 (file)
index 0000000..691ed83
--- /dev/null
@@ -0,0 +1,19 @@
+This tests "resize" event on window.visualViewport and height getting updated upon keyboard showing up on iOS
+To manually test, tap the text field below to show the software keyboard then dismiss it.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS resizeCount is 0
+PASS resizeCount is 1
+PASS originalWidth is window.visualViewport.width
+PASS window.visualViewport.height is not originalHeight
+PASS window.visualViewport.height < originalHeight is true
+PASS resizeCount is 2
+PASS originalWidth is window.visualViewport.width
+PASS window.visualViewport.height is originalHeight
+PASS window.visualViewport.height < originalHeight is false
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/visual-viewport/ios/resize-event-for-keyboard.html b/LayoutTests/fast/visual-viewport/ios/resize-event-for-keyboard.html
new file mode 100644 (file)
index 0000000..4f26730
--- /dev/null
@@ -0,0 +1,67 @@
+<!DOCTYPE html><!-- webkit-test-runner [ useFlexibleViewport=true ] -->
+<html>
+<head>
+<meta name="viewport" content="initial-scale=1, user-scalable=no">
+</head>
+<body onload="runTest()">
+<input type="text" onclick="didFocus()" placeholder="Tap here to open keyboard">
+<script src="../../../resources/ui-helper.js"></script>
+<script src="../../../resources/js-test.js"></script>
+<script>
+description('This tests "resize" event on window.visualViewport and height getting updated upon keyboard showing up on iOS<br>'
+    + 'To manually test, tap the text field below to show the software keyboard then dismiss it.');
+
+jsTestIsAsync = true;
+
+function didFocus() { }
+
+async function runTest() {
+    if (window.testRunner)
+        await UIHelper.ensurePresentationUpdate();
+
+    window.originalWidth = window.visualViewport.width;
+    window.originalHeight = window.visualViewport.height;
+    window.resizeCount = 0;
+    window.visualViewport.addEventListener('resize', () => {
+        resizeCount++;
+    });
+
+    shouldBe('resizeCount', '0');
+
+    const rect = document.querySelector('input').getBoundingClientRect();
+
+    if (window.testRunner) {
+        await UIHelper.activateAndWaitForInputSessionAt(rect.left + 5, rect.top + 5);
+        await UIHelper.ensurePresentationUpdate();
+    } else {
+        await new Promise((resolve) => {
+            window.didFocus = () => setTimeout(resolve, 500);
+        });
+    }
+
+    shouldBe('resizeCount', '1');
+    shouldBe('originalWidth', 'window.visualViewport.width');
+    shouldNotBe('window.visualViewport.height', 'originalHeight');
+    shouldBeTrue('window.visualViewport.height < originalHeight');
+
+    document.querySelector('input').blur();
+    if (window.testRunner) {
+        await UIHelper.waitForKeyboardToHide();
+        await UIHelper.ensurePresentationUpdate();
+    } else {
+        await new Promise((resolve) => {
+            setTimeout(resolve, 500);
+        });
+    }
+
+    shouldBe('resizeCount', '2');
+    shouldBe('originalWidth', 'window.visualViewport.width');
+    shouldBe('window.visualViewport.height', 'originalHeight');
+    shouldBeFalse('window.visualViewport.height < originalHeight');
+
+    finishJSTest();
+}
+
+</script>
+</body>
+</html>
index 2a9c60b..f58b0b2 100644 (file)
@@ -1,3 +1,18 @@
+2019-01-15  Ryosuke Niwa  <rniwa@webkit.org>
+
+        VisualViewport API should be updated upon opening of keyboard
+        https://bugs.webkit.org/show_bug.cgi?id=193475
+
+        Reviewed by Simon Fraser.
+
+        Added a function to update the visual viewport API and schedule a resize event to FrameView.
+
+        Test: fast/visual-viewport/ios/resize-event-for-keyboard.html
+
+        * page/FrameView.cpp:
+        (WebCore::FrameView::didUpdateViewportOverrideRects):
+        * page/FrameView.h:
+
 2019-01-15  Myles C. Maxfield  <mmaxfield@apple.com>
 
         Fix build after r240018
index f067d08..8dd924d 100644 (file)
@@ -2797,6 +2797,15 @@ void FrameView::updateTiledBackingAdaptiveSizing()
 
 #if PLATFORM(IOS_FAMILY)
 
+void FrameView::didUpdateViewportOverrideRects()
+{
+    if (!frame().settings().visualViewportAPIEnabled())
+        return;
+
+    if (auto* window = frame().window())
+        window->visualViewport().update();
+}
+
 void FrameView::unobscuredContentSizeChanged()
 {
     updateTiledBackingAdaptiveSizing();
index 529f6cc..4429846 100644 (file)
@@ -590,6 +590,10 @@ public:
     void updateTiledBackingAdaptiveSizing();
     TiledBacking::Scrollability computeScrollability() const;
 
+#if PLATFORM(IOS_FAMILY)
+    WEBCORE_EXPORT void didUpdateViewportOverrideRects();
+#endif
+
     void addPaintPendingMilestones(OptionSet<LayoutMilestone>);
     void firePaintRelatedMilestonesIfNeeded();
     void fireLayoutRelatedMilestonesIfNeeded();
index 36e06dc..33aa832 100644 (file)
@@ -1,3 +1,22 @@
+2019-01-15  Ryosuke Niwa  <rniwa@webkit.org>
+
+        VisualViewport API should be updated upon opening of keyboard
+        https://bugs.webkit.org/show_bug.cgi?id=193475
+
+        Reviewed by Simon Fraser.
+
+        The bug was caused by the changes to unobscuredContentRectRespectingInputViewBounds not updating the visual viewport
+        unless it caused a layout to happen. Added a code to update the visual viewport in WebPage::updateVisibleContentRects.
+
+        Also fixed the bug that VisibleContentRectUpdateInfo::operator== was not checking differences in
+        unobscuredContentRectRespectingInputViewBounds which resulted in the visual viewport override not getting updated
+        while the keyboard is getting brought up.
+
+        * Shared/VisibleContentRectUpdateInfo.h:
+        (WebKit::operator==):
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::updateVisibleContentRects):
+
 2019-01-15  Megan Gardner  <megan_gardner@apple.com>
 
         Add Reveal support in iOSMac
index 5f07c2b..91c1822 100644 (file)
@@ -121,6 +121,7 @@ inline bool operator==(const VisibleContentRectUpdateInfo& a, const VisibleConte
     return a.scale() == b.scale()
         && a.exposedContentRect() == b.exposedContentRect()
         && a.unobscuredContentRect() == b.unobscuredContentRect()
+        && a.unobscuredContentRectRespectingInputViewBounds() == b.unobscuredContentRectRespectingInputViewBounds()
         && a.customFixedPositionRect() == b.customFixedPositionRect()
         && a.obscuredInsets() == b.obscuredInsets()
         && a.unobscuredSafeAreaInsets() == b.unobscuredSafeAreaInsets()
index c74a636..06696c0 100644 (file)
@@ -3041,6 +3041,8 @@ void WebPage::updateVisibleContentRects(const VisibleContentRectUpdateInfo& visi
                 frameView.frame().selection().setCaretRectNeedsUpdate();
                 sendPartialEditorStateAndSchedulePostLayoutUpdate();
             }
+
+            frameView.didUpdateViewportOverrideRects();
         } else
             frameView.setCustomFixedPositionLayoutRect(enclosingIntRect(visibleContentRectUpdateInfo.customFixedPositionRect()));
     }