Commit 3e345e0a authored by Dave Tapuska's avatar Dave Tapuska Committed by Commit Bot

Collapse the remaining HandleGestureEvent code into base.

The View implementation had a few more things that the frame left as
a todo. Talking with wjmaclean@ it seems that the view implementation
should just be used for this code as it handles things like long
press gestures which were added after the frame code was written.

BUG=1097816

Change-Id: Ic912c5d6fe9fda4183b25006c4b7631b37dade3a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2551791
Commit-Queue: Dave Tapuska <dtapuska@chromium.org>
Reviewed-by: default avatarJames MacLean <wjmaclean@chromium.org>
Reviewed-by: default avatardanakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#830684}
parent e29fd37b
......@@ -865,7 +865,75 @@ WebInputEventResult WebFrameWidgetBase::HandleGestureEvent(
}
}
event_result = HandleGestureEventScaled(scaled_event, targeted_event);
switch (scaled_event.GetType()) {
case WebInputEvent::Type::kGestureTap: {
{
ContextMenuAllowedScope scope;
event_result =
frame->GetEventHandler().HandleGestureEvent(targeted_event);
}
if (web_view->GetPagePopup() && last_hidden_page_popup_ &&
web_view->GetPagePopup()->HasSamePopupClient(
last_hidden_page_popup_.get())) {
// The tap triggered a page popup that is the same as the one we just
// closed. It needs to be closed.
web_view->CancelPagePopup();
}
// Don't have this value persist outside of a single tap gesture, plus
// we're done with it now.
last_hidden_page_popup_ = nullptr;
break;
}
case WebInputEvent::Type::kGestureTwoFingerTap:
case WebInputEvent::Type::kGestureLongPress:
case WebInputEvent::Type::kGestureLongTap:
if (scaled_event.GetType() == WebInputEvent::Type::kGestureLongTap) {
if (LocalFrame* inner_frame =
targeted_event.GetHitTestResult().InnerNodeFrame()) {
if (!inner_frame->GetEventHandler().LongTapShouldInvokeContextMenu())
break;
} else if (!frame->GetEventHandler().LongTapShouldInvokeContextMenu()) {
break;
}
}
GetPage()->GetContextMenuController().ClearContextMenu();
{
ContextMenuAllowedScope scope;
event_result =
frame->GetEventHandler().HandleGestureEvent(targeted_event);
}
break;
case WebInputEvent::Type::kGestureTapDown:
// Touch pinch zoom and scroll on the page (outside of a popup) must hide
// the popup. In case of a touch scroll or pinch zoom, this function is
// called with GestureTapDown rather than a GSB/GSU/GSE or GPB/GPU/GPE.
// When we close a popup because of a GestureTapDown, we also save it so
// we can prevent the following GestureTap from immediately reopening the
// same popup.
// This value should not persist outside of a gesture, so is cleared by
// GestureTap (where it is used) and by GestureCancel.
last_hidden_page_popup_ = web_view->GetPagePopup();
web_view->CancelPagePopup();
event_result =
frame->GetEventHandler().HandleGestureEvent(targeted_event);
break;
case WebInputEvent::Type::kGestureTapCancel:
// Don't have this value persist outside of a single tap gesture.
last_hidden_page_popup_ = nullptr;
event_result =
frame->GetEventHandler().HandleGestureEvent(targeted_event);
break;
case WebInputEvent::Type::kGestureShowPress:
case WebInputEvent::Type::kGestureTapUnconfirmed:
event_result =
frame->GetEventHandler().HandleGestureEvent(targeted_event);
break;
default:
NOTREACHED();
}
DidHandleGestureEvent(event);
return event_result;
}
......
......@@ -25,6 +25,7 @@
#include "third_party/blink/public/web/web_meaningful_layout.h"
#include "third_party/blink/renderer/core/clipboard/data_object.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/exported/web_page_popup_impl.h"
#include "third_party/blink/renderer/core/page/event_with_hit_test_results.h"
#include "third_party/blink/renderer/core/page/page_widget_delegate.h"
#include "third_party/blink/renderer/platform/graphics/apply_viewport_changes.h"
......@@ -740,13 +741,6 @@ class CORE_EXPORT WebFrameWidgetBase
// Returns the current state of synchronous resize mode for testing.
bool SynchronousResizeModeForTestingEnabled();
// Handle a gesture event that has already been scaled.
// This is temporary to help with reviews of collapsing the complicated
// HandleGestureEvent into one implementation.
virtual WebInputEventResult HandleGestureEventScaled(
const WebGestureEvent&,
const GestureEventWithHitTestResults&) = 0;
// A copy of the web drop data object we received from the browser.
Member<DataObject> current_drag_data_;
......@@ -961,6 +955,11 @@ class CORE_EXPORT WebFrameWidgetBase
// Whether this widget is for a child local root, or otherwise a main frame.
const bool is_for_child_local_root_;
// This stores the last hidden page popup. If a GestureTap attempts to open
// the popup that is closed by its previous GestureTapDown, the popup remains
// closed.
scoped_refptr<WebPagePopupImpl> last_hidden_page_popup_;
SelfKeepAlive<WebFrameWidgetBase> self_keep_alive_;
friend class WebViewImpl;
......
......@@ -209,41 +209,4 @@ WebFrameWidgetImpl::WebFrameWidgetImpl(
WebFrameWidgetImpl::~WebFrameWidgetImpl() = default;
// WebWidget ------------------------------------------------------------------
WebInputEventResult WebFrameWidgetImpl::HandleGestureEventScaled(
const WebGestureEvent& scaled_event,
const GestureEventWithHitTestResults&) {
base::Optional<ContextMenuAllowedScope> maybe_context_menu_scope;
switch (scaled_event.GetType()) {
case WebInputEvent::Type::kGestureTap:
case WebInputEvent::Type::kGestureTapUnconfirmed:
case WebInputEvent::Type::kGestureTapDown:
// Touch pinch zoom and scroll on the page (outside of a popup) must hide
// the popup. In case of a touch scroll or pinch zoom, this function is
// called with GestureTapDown rather than a GSB/GSU/GSE or GPB/GPU/GPE.
// WebViewImpl takes additional steps to avoid the following GestureTap
// from re-opening the popup being closed here, but since GestureTap will
// unconditionally close the current popup here, it is not used/needed.
// TODO(wjmaclean): We should maybe mirror what WebViewImpl does, the
// HandleGestureEvent() needs to happen inside or before the GestureTap
// case to do so.
View()->CancelPagePopup();
break;
case WebInputEvent::Type::kGestureTapCancel:
case WebInputEvent::Type::kGestureShowPress:
break;
case WebInputEvent::Type::kGestureTwoFingerTap:
case WebInputEvent::Type::kGestureLongPress:
case WebInputEvent::Type::kGestureLongTap:
GetPage()->GetContextMenuController().ClearContextMenu();
maybe_context_menu_scope.emplace();
break;
default:
NOTREACHED();
}
LocalFrame* frame = LocalRootImpl()->GetFrame();
return frame->GetEventHandler().HandleGestureEvent(scaled_event);
}
} // namespace blink
......@@ -79,11 +79,6 @@ class WebFrameWidgetImpl final : public WebFrameWidgetBase {
private:
friend class WebFrameWidget; // For WebFrameWidget::create.
// WebFrameWidgetBase overrides:
WebInputEventResult HandleGestureEventScaled(
const WebGestureEvent&,
const GestureEventWithHitTestResults&) override;
};
} // namespace blink
......
......@@ -69,113 +69,4 @@ WebViewFrameWidget::WebViewFrameWidget(
WebViewFrameWidget::~WebViewFrameWidget() = default;
WebInputEventResult WebViewFrameWidget::HandleGestureEventScaled(
const WebGestureEvent& scaled_event,
const GestureEventWithHitTestResults& targeted_event) {
WebViewImpl* web_view = View();
if (!web_view->MainFrameImpl())
return WebInputEventResult::kNotHandled;
WebInputEventResult event_result = WebInputEventResult::kNotHandled;
switch (scaled_event.GetType()) {
case WebInputEvent::Type::kGestureTap: {
{
ContextMenuAllowedScope scope;
event_result = web_view->MainFrameImpl()
->GetFrame()
->GetEventHandler()
.HandleGestureEvent(targeted_event);
}
if (web_view->GetPagePopup() && last_hidden_page_popup_ &&
web_view->GetPagePopup()->HasSamePopupClient(
last_hidden_page_popup_.get())) {
// The tap triggered a page popup that is the same as the one we just
// closed. It needs to be closed.
web_view->CancelPagePopup();
}
// Don't have this value persist outside of a single tap gesture, plus
// we're done with it now.
last_hidden_page_popup_ = nullptr;
break;
}
case WebInputEvent::Type::kGestureTwoFingerTap:
case WebInputEvent::Type::kGestureLongPress:
case WebInputEvent::Type::kGestureLongTap: {
if (!web_view->MainFrameImpl() ||
!web_view->MainFrameImpl()->GetFrameView())
break;
if (scaled_event.GetType() == WebInputEvent::Type::kGestureLongTap) {
if (LocalFrame* inner_frame =
targeted_event.GetHitTestResult().InnerNodeFrame()) {
if (!inner_frame->GetEventHandler().LongTapShouldInvokeContextMenu())
break;
} else if (!web_view->MainFrameImpl()
->GetFrame()
->GetEventHandler()
.LongTapShouldInvokeContextMenu()) {
break;
}
}
GetPage()->GetContextMenuController().ClearContextMenu();
{
ContextMenuAllowedScope scope;
event_result = web_view->MainFrameImpl()
->GetFrame()
->GetEventHandler()
.HandleGestureEvent(targeted_event);
}
break;
}
case WebInputEvent::Type::kGestureTapDown: {
// Touch pinch zoom and scroll on the page (outside of a popup) must hide
// the popup. In case of a touch scroll or pinch zoom, this function is
// called with GestureTapDown rather than a GSB/GSU/GSE or GPB/GPU/GPE.
// When we close a popup because of a GestureTapDown, we also save it so
// we can prevent the following GestureTap from immediately reopening the
// same popup.
// This value should not persist outside of a gesture, so is cleared by
// GestureTap (where it is used) and by GestureCancel.
last_hidden_page_popup_ = web_view->GetPagePopup();
web_view->CancelPagePopup();
event_result = web_view->MainFrameImpl()
->GetFrame()
->GetEventHandler()
.HandleGestureEvent(targeted_event);
break;
}
case WebInputEvent::Type::kGestureTapCancel: {
// Don't have this value persist outside of a single tap gesture.
last_hidden_page_popup_ = nullptr;
event_result = web_view->MainFrameImpl()
->GetFrame()
->GetEventHandler()
.HandleGestureEvent(targeted_event);
break;
}
case WebInputEvent::Type::kGestureShowPress: {
event_result = web_view->MainFrameImpl()
->GetFrame()
->GetEventHandler()
.HandleGestureEvent(targeted_event);
break;
}
case WebInputEvent::Type::kGestureTapUnconfirmed: {
event_result = web_view->MainFrameImpl()
->GetFrame()
->GetEventHandler()
.HandleGestureEvent(targeted_event);
break;
}
default: {
NOTREACHED();
}
}
return event_result;
}
} // namespace blink
......@@ -10,7 +10,6 @@
#include "base/single_thread_task_runner.h"
#include "base/types/pass_key.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/exported/web_page_popup_impl.h"
#include "third_party/blink/renderer/core/frame/web_frame_widget_base.h"
#include "third_party/blink/renderer/core/frame/web_local_frame_impl.h"
#include "third_party/blink/renderer/platform/graphics/apply_viewport_changes.h"
......@@ -60,16 +59,6 @@ class CORE_EXPORT WebViewFrameWidget : public WebFrameWidgetBase {
~WebViewFrameWidget() override;
private:
// WebFrameWidgetBase overrides:
WebInputEventResult HandleGestureEventScaled(
const WebGestureEvent&,
const GestureEventWithHitTestResults&) override;
// This stores the last hidden page popup. If a GestureTap attempts to open
// the popup that is closed by its previous GestureTapDown, the popup remains
// closed.
scoped_refptr<WebPagePopupImpl> last_hidden_page_popup_;
DISALLOW_COPY_AND_ASSIGN(WebViewFrameWidget);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment