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

Move HandleKeyEvent into WebFrameWidgetBase

Collapse common implementation of HandleKeyEvent into one. There is a
path that checks for embeds that support keyboard focus and a tab
character, ensure this code is kept. fast/plugins/keypress-event.html
tests that condition.

BUG=1097816

Change-Id: Ic9c88a6c0a768f26980bb97645f853f651caf9ab
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2536151
Commit-Queue: Dave Tapuska <dtapuska@chromium.org>
Reviewed-by: default avatardanakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#827426}
parent e3b19166
......@@ -51,6 +51,7 @@
#include "third_party/blink/renderer/core/layout/hit_test_location.h"
#include "third_party/blink/renderer/core/layout/hit_test_request.h"
#include "third_party/blink/renderer/core/layout/layout_box.h"
#include "third_party/blink/renderer/core/layout/layout_embedded_content.h"
#include "third_party/blink/renderer/core/layout/layout_object.h"
#include "third_party/blink/renderer/core/loader/interactive_detector.h"
#include "third_party/blink/renderer/core/page/context_menu_controller.h"
......@@ -69,6 +70,7 @@
#include "third_party/blink/renderer/platform/graphics/animation_worklet_mutator_dispatcher_impl.h"
#include "third_party/blink/renderer/platform/graphics/compositor_mutator_client.h"
#include "third_party/blink/renderer/platform/graphics/paint_worklet_paint_dispatcher.h"
#include "third_party/blink/renderer/platform/keyboard_codes.h"
#include "third_party/blink/renderer/platform/scheduler/public/post_cross_thread_task.h"
#include "third_party/blink/renderer/platform/widget/input/main_thread_event_queue.h"
#include "third_party/blink/renderer/platform/widget/input/widget_input_handler_manager.h"
......@@ -508,6 +510,86 @@ void WebFrameWidgetBase::SetActive(bool active) {
View()->SetIsActive(active);
}
WebInputEventResult WebFrameWidgetBase::HandleKeyEvent(
const WebKeyboardEvent& event) {
DCHECK((event.GetType() == WebInputEvent::Type::kRawKeyDown) ||
(event.GetType() == WebInputEvent::Type::kKeyDown) ||
(event.GetType() == WebInputEvent::Type::kKeyUp));
// Please refer to the comments explaining the m_suppressNextKeypressEvent
// member.
// The m_suppressNextKeypressEvent is set if the KeyDown is handled by
// Webkit. A keyDown event is typically associated with a keyPress(char)
// event and a keyUp event. We reset this flag here as this is a new keyDown
// event.
suppress_next_keypress_event_ = false;
// If there is a popup open, it should be the one processing the event,
// not the page.
scoped_refptr<WebPagePopupImpl> page_popup = View()->GetPagePopup();
if (page_popup) {
page_popup->HandleKeyEvent(event);
if (event.GetType() == WebInputEvent::Type::kRawKeyDown) {
suppress_next_keypress_event_ = true;
}
return WebInputEventResult::kHandledSystem;
}
auto* frame = DynamicTo<LocalFrame>(FocusedCoreFrame());
if (!frame)
return WebInputEventResult::kNotHandled;
WebInputEventResult result = frame->GetEventHandler().KeyEvent(event);
if (result != WebInputEventResult::kNotHandled) {
if (WebInputEvent::Type::kRawKeyDown == event.GetType()) {
// Suppress the next keypress event unless the focused node is a plugin
// node. (Flash needs these keypress events to handle non-US keyboards.)
Element* element = FocusedElement();
if (element && element->GetLayoutObject() &&
element->GetLayoutObject()->IsEmbeddedObject()) {
if (event.windows_key_code == VKEY_TAB) {
// If the plugin supports keyboard focus then we should not send a tab
// keypress event.
WebPluginContainerImpl* plugin_view =
To<LayoutEmbeddedContent>(element->GetLayoutObject())->Plugin();
if (plugin_view && plugin_view->SupportsKeyboardFocus()) {
suppress_next_keypress_event_ = true;
}
}
} else {
suppress_next_keypress_event_ = true;
}
}
return result;
}
#if !defined(OS_MAC)
const WebInputEvent::Type kContextMenuKeyTriggeringEventType =
#if defined(OS_WIN)
WebInputEvent::Type::kKeyUp;
#else
WebInputEvent::Type::kRawKeyDown;
#endif
const WebInputEvent::Type kShiftF10TriggeringEventType =
WebInputEvent::Type::kRawKeyDown;
bool is_unmodified_menu_key =
!(event.GetModifiers() & WebInputEvent::kInputModifiers) &&
event.windows_key_code == VKEY_APPS;
bool is_shift_f10 = (event.GetModifiers() & WebInputEvent::kInputModifiers) ==
WebInputEvent::kShiftKey &&
event.windows_key_code == VKEY_F10;
if ((is_unmodified_menu_key &&
event.GetType() == kContextMenuKeyTriggeringEventType) ||
(is_shift_f10 && event.GetType() == kShiftF10TriggeringEventType)) {
View()->SendContextMenuEvent();
return WebInputEventResult::kHandledSystem;
}
#endif // !defined(OS_MAC)
return WebInputEventResult::kNotHandled;
}
void WebFrameWidgetBase::HandleMouseDown(LocalFrame& main_frame,
const WebMouseEvent& event) {
WebViewImpl* view_impl = View();
......@@ -2923,6 +3005,18 @@ Frame* WebFrameWidgetBase::FocusedCoreFrame() const {
: nullptr;
}
Element* WebFrameWidgetBase::FocusedElement() const {
LocalFrame* frame = GetPage()->GetFocusController().FocusedFrame();
if (!frame)
return nullptr;
Document* document = frame->GetDocument();
if (!document)
return nullptr;
return document->FocusedElement();
}
HitTestResult WebFrameWidgetBase::HitTestResultForRootFramePos(
const FloatPoint& pos_in_root_frame) {
FloatPoint doc_point =
......
......@@ -695,6 +695,10 @@ class CORE_EXPORT WebFrameWidgetBase
Frame* FocusedCoreFrame() const;
// Returns the currently focused `Element` in any `LocalFrame` owned by the
// associated `WebView`.
Element* FocusedElement() const;
// Perform a hit test for a point relative to the root frame of the page.
HitTestResult HitTestResultForRootFramePos(
const FloatPoint& pos_in_root_frame);
......@@ -732,14 +736,9 @@ class CORE_EXPORT WebFrameWidgetBase
// base class.
Member<HTMLPlugInElement> mouse_capture_element_;
// keyPress events to be suppressed if the associated keyDown event was
// handled.
// TODO(dtapuska): Move to private once all input handling is moved to
// base class.
bool suppress_next_keypress_event_ = false;
private:
// PageWidgetEventHandler methods:
WebInputEventResult HandleKeyEvent(const WebKeyboardEvent&) override;
void HandleMouseDown(LocalFrame&, const WebMouseEvent&) override;
WebInputEventResult HandleMouseUp(LocalFrame&, const WebMouseEvent&) override;
WebInputEventResult HandleMouseWheel(LocalFrame&,
......@@ -828,6 +827,10 @@ class CORE_EXPORT WebFrameWidgetBase
// WidgetScreenRect, WindowScreenRect, and the widget's size.
Member<ScreenMetricsEmulator> device_emulator_;
// keyPress events to be suppressed if the associated keyDown event was
// handled.
bool suppress_next_keypress_event_ = false;
friend class WebViewImpl;
friend class ReportTimeSwapPromise;
};
......
......@@ -83,7 +83,6 @@
#include "third_party/blink/renderer/core/probe/core_probes.h"
#include "third_party/blink/renderer/platform/graphics/color.h"
#include "third_party/blink/renderer/platform/heap/heap.h"
#include "third_party/blink/renderer/platform/keyboard_codes.h"
#include "third_party/blink/renderer/platform/scheduler/main_thread/frame_scheduler_impl.h"
#include "third_party/blink/renderer/platform/widget/widget_base.h"
......@@ -556,87 +555,6 @@ LocalFrameView* WebFrameWidgetImpl::GetLocalFrameViewForAnimationScrolling() {
return LocalRootImpl()->GetFrame()->View();
}
WebInputEventResult WebFrameWidgetImpl::HandleKeyEvent(
const WebKeyboardEvent& event) {
DCHECK((event.GetType() == WebInputEvent::Type::kRawKeyDown) ||
(event.GetType() == WebInputEvent::Type::kKeyDown) ||
(event.GetType() == WebInputEvent::Type::kKeyUp));
// Please refer to the comments explaining the m_suppressNextKeypressEvent
// member.
// The m_suppressNextKeypressEvent is set if the KeyDown is handled by
// Webkit. A keyDown event is typically associated with a keyPress(char)
// event and a keyUp event. We reset this flag here as this is a new keyDown
// event.
suppress_next_keypress_event_ = false;
// If there is a popup open, it should be the one processing the event,
// not the page.
scoped_refptr<WebPagePopupImpl> page_popup = View()->GetPagePopup();
if (page_popup) {
page_popup->HandleKeyEvent(event);
if (event.GetType() == WebInputEvent::Type::kRawKeyDown) {
suppress_next_keypress_event_ = true;
}
return WebInputEventResult::kHandledSystem;
}
auto* frame = DynamicTo<LocalFrame>(FocusedCoreFrame());
if (!frame)
return WebInputEventResult::kNotHandled;
WebInputEventResult result = frame->GetEventHandler().KeyEvent(event);
if (result != WebInputEventResult::kNotHandled) {
if (WebInputEvent::Type::kRawKeyDown == event.GetType()) {
// Suppress the next keypress event unless the focused node is a plugin
// node. (Flash needs these keypress events to handle non-US keyboards.)
Element* element = FocusedElement();
if (!element || !element->GetLayoutObject() ||
!element->GetLayoutObject()->IsEmbeddedObject())
suppress_next_keypress_event_ = true;
}
return result;
}
#if !defined(OS_MAC)
const WebInputEvent::Type kContextMenuKeyTriggeringEventType =
#if defined(OS_WIN)
WebInputEvent::Type::kKeyUp;
#else
WebInputEvent::Type::kRawKeyDown;
#endif
const WebInputEvent::Type kShiftF10TriggeringEventType =
WebInputEvent::Type::kRawKeyDown;
bool is_unmodified_menu_key =
!(event.GetModifiers() & WebInputEvent::kInputModifiers) &&
event.windows_key_code == VKEY_APPS;
bool is_shift_f10 = (event.GetModifiers() & WebInputEvent::kInputModifiers) ==
WebInputEvent::kShiftKey &&
event.windows_key_code == VKEY_F10;
if ((is_unmodified_menu_key &&
event.GetType() == kContextMenuKeyTriggeringEventType) ||
(is_shift_f10 && event.GetType() == kShiftF10TriggeringEventType)) {
View()->SendContextMenuEvent();
return WebInputEventResult::kHandledSystem;
}
#endif // !defined(OS_MAC)
return WebInputEventResult::kNotHandled;
}
Element* WebFrameWidgetImpl::FocusedElement() const {
LocalFrame* frame = GetPage()->GetFocusController().FocusedFrame();
if (!frame)
return nullptr;
Document* document = frame->GetDocument();
if (!document)
return nullptr;
return document->FocusedElement();
}
PaintLayerCompositor* WebFrameWidgetImpl::Compositor() const {
LocalFrame* frame = LocalRootImpl()->GetFrame();
if (!frame || !frame->GetDocument() || !frame->GetDocument()->GetLayoutView())
......
......@@ -112,9 +112,6 @@ class WebFrameWidgetImpl final : public WebFrameWidgetBase {
void ResetZoomLevelForTesting() override;
void SetDeviceScaleFactorForTesting(float factor) override;
// Returns the currently focused Element or null if no element has focus.
Element* FocusedElement() const;
PaintLayerCompositor* Compositor() const;
// WebFrameWidgetBase overrides:
......@@ -150,7 +147,6 @@ class WebFrameWidgetImpl final : public WebFrameWidgetBase {
// PageWidgetEventHandler functions
void HandleMouseLeave(LocalFrame&, const WebMouseEvent&) override;
WebInputEventResult HandleGestureEvent(const WebGestureEvent&) override;
WebInputEventResult HandleKeyEvent(const WebKeyboardEvent&) override;
LocalFrameView* GetLocalFrameViewForAnimationScrolling() override;
......
......@@ -25,7 +25,6 @@
#include "third_party/blink/renderer/core/html/html_plugin_element.h"
#include "third_party/blink/renderer/core/input/context_menu_allowed_scope.h"
#include "third_party/blink/renderer/core/input/event_handler.h"
#include "third_party/blink/renderer/core/layout/layout_embedded_content.h"
#include "third_party/blink/renderer/core/loader/interactive_detector.h"
#include "third_party/blink/renderer/core/page/context_menu_controller.h"
#include "third_party/blink/renderer/core/page/focus_controller.h"
......@@ -180,92 +179,6 @@ void WebViewFrameWidget::ZoomToFindInPageRect(
web_view_->ZoomToFindInPageRect(rect_in_root_frame);
}
WebInputEventResult WebViewFrameWidget::HandleKeyEvent(
const WebKeyboardEvent& event) {
DCHECK((event.GetType() == WebInputEvent::Type::kRawKeyDown) ||
(event.GetType() == WebInputEvent::Type::kKeyDown) ||
(event.GetType() == WebInputEvent::Type::kKeyUp));
TRACE_EVENT2("input", "WebViewFrameWidget::HandleKeyEvent", "type",
WebInputEvent::GetName(event.GetType()), "text",
String(event.text).Utf8());
// Please refer to the comments explaining |suppress_next_keypress_event_|.
//
// |suppress_next_keypress_event_| is set if the KeyDown is handled by
// Webkit. A keyDown event is typically associated with a keyPress(char)
// event and a keyUp event. We reset this flag here as this is a new keyDown
// event.
suppress_next_keypress_event_ = false;
// If there is a popup, it should be the one processing the event, not the
// page.
scoped_refptr<WebPagePopupImpl> page_popup = View()->GetPagePopup();
if (page_popup) {
page_popup->HandleKeyEvent(event);
// We need to ignore the next Char event after this otherwise pressing
// enter when selecting an item in the popup will go to the page.
if (WebInputEvent::Type::kRawKeyDown == event.GetType())
suppress_next_keypress_event_ = true;
return WebInputEventResult::kHandledSystem;
}
Frame* focused_frame = web_view_->FocusedCoreFrame();
auto* focused_local_frame = DynamicTo<LocalFrame>(focused_frame);
if (!focused_local_frame)
return WebInputEventResult::kNotHandled;
WebInputEventResult result =
focused_local_frame->GetEventHandler().KeyEvent(event);
if (result != WebInputEventResult::kNotHandled) {
if (WebInputEvent::Type::kRawKeyDown == event.GetType()) {
// Suppress the next keypress event unless the focused node is a plugin
// node. (Flash needs these keypress events to handle non-US keyboards.)
Element* element = web_view_->FocusedElement();
if (element && element->GetLayoutObject() &&
element->GetLayoutObject()->IsEmbeddedObject()) {
if (event.windows_key_code == VKEY_TAB) {
// If the plugin supports keyboard focus then we should not send a tab
// keypress event.
WebPluginContainerImpl* plugin_view =
To<LayoutEmbeddedContent>(element->GetLayoutObject())->Plugin();
if (plugin_view && plugin_view->SupportsKeyboardFocus()) {
suppress_next_keypress_event_ = true;
}
}
} else {
suppress_next_keypress_event_ = true;
}
}
return result;
}
#if !defined(OS_MAC)
const WebInputEvent::Type kContextMenuKeyTriggeringEventType =
#if defined(OS_WIN)
WebInputEvent::Type::kKeyUp;
#else
WebInputEvent::Type::kRawKeyDown;
#endif
const WebInputEvent::Type kShiftF10TriggeringEventType =
WebInputEvent::Type::kRawKeyDown;
bool is_unmodified_menu_key =
!(event.GetModifiers() & WebInputEvent::kInputModifiers) &&
event.windows_key_code == VKEY_APPS;
bool is_shift_f10 = (event.GetModifiers() & WebInputEvent::kInputModifiers) ==
WebInputEvent::kShiftKey &&
event.windows_key_code == VKEY_F10;
if ((is_unmodified_menu_key &&
event.GetType() == kContextMenuKeyTriggeringEventType) ||
(is_shift_f10 && event.GetType() == kShiftF10TriggeringEventType)) {
View()->SendContextMenuEvent();
return WebInputEventResult::kHandledSystem;
}
#endif // !defined(OS_MAC)
return WebInputEventResult::kNotHandled;
}
void WebViewFrameWidget::HandleMouseLeave(LocalFrame& main_frame,
const WebMouseEvent& event) {
web_view_->SetMouseOverURL(WebURL());
......
......@@ -121,7 +121,6 @@ class CORE_EXPORT WebViewFrameWidget : public WebFrameWidgetBase {
// PageWidgetEventHandler overrides:
void HandleMouseLeave(LocalFrame&, const WebMouseEvent&) override;
WebInputEventResult HandleGestureEvent(const WebGestureEvent&) override;
WebInputEventResult HandleKeyEvent(const WebKeyboardEvent&) override;
LocalFrameView* GetLocalFrameViewForAnimationScrolling() override;
void SetWindowRectSynchronously(const gfx::Rect& new_window_rect);
......
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