Commit 19c4174f authored by James Cook's avatar James Cook Committed by Commit Bot

Convert <select> popup observer to ui::EventObserver

This is needed for it to observe clicks outside the browser window
(e.g. on the desktop) under SingleProcessMash on Chrome OS.

Bug: 896948
Test: existing content_unittests
Change-Id: I8cdfa78f934255bde7e23a3964990e418717eb54
Reviewed-on: https://chromium-review.googlesource.com/c/1292810Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Commit-Queue: James Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#601710}
parent 42a63522
...@@ -88,6 +88,7 @@ ...@@ -88,6 +88,7 @@
#include "ui/events/blink/did_overscroll_params.h" #include "ui/events/blink/did_overscroll_params.h"
#include "ui/events/blink/web_input_event.h" #include "ui/events/blink/web_input_event.h"
#include "ui/events/event.h" #include "ui/events/event.h"
#include "ui/events/event_observer.h"
#include "ui/events/event_utils.h" #include "ui/events/event_utils.h"
#include "ui/events/gesture_detection/gesture_configuration.h" #include "ui/events/gesture_detection/gesture_configuration.h"
#include "ui/events/gestures/gesture_recognizer.h" #include "ui/events/gestures/gesture_recognizer.h"
...@@ -194,45 +195,41 @@ class WinScreenKeyboardObserver ...@@ -194,45 +195,41 @@ class WinScreenKeyboardObserver
// We need to watch for mouse events outside a Web Popup or its parent // We need to watch for mouse events outside a Web Popup or its parent
// and dismiss the popup for certain events. // and dismiss the popup for certain events.
class RenderWidgetHostViewAura::EventFilterForPopupExit class RenderWidgetHostViewAura::EventObserverForPopupExit
: public ui::EventHandler { : public ui::EventObserver {
public: public:
explicit EventFilterForPopupExit(RenderWidgetHostViewAura* rwhva) explicit EventObserverForPopupExit(RenderWidgetHostViewAura* rwhva)
: rwhva_(rwhva) { : rwhva_(rwhva) {
DCHECK(rwhva_); aura::Env* env = aura::Env::GetInstance();
aura::Env::GetInstance()->AddPreTargetHandler(this); env->AddEventObserver(this, env,
{ui::ET_MOUSE_PRESSED, ui::ET_TOUCH_PRESSED});
} }
~EventFilterForPopupExit() override { ~EventObserverForPopupExit() override {
aura::Env::GetInstance()->RemovePreTargetHandler(this); aura::Env::GetInstance()->RemoveEventObserver(this);
} }
// Overridden from ui::EventHandler // ui::EventObserver:
void OnMouseEvent(ui::MouseEvent* event) override { void OnEvent(const ui::Event& event) override {
rwhva_->ApplyEventFilterForPopupExit(event); rwhva_->ApplyEventObserverForPopupExit(*event.AsLocatedEvent());
}
void OnTouchEvent(ui::TouchEvent* event) override {
rwhva_->ApplyEventFilterForPopupExit(event);
} }
private: private:
RenderWidgetHostViewAura* rwhva_; RenderWidgetHostViewAura* rwhva_;
DISALLOW_COPY_AND_ASSIGN(EventFilterForPopupExit); DISALLOW_COPY_AND_ASSIGN(EventObserverForPopupExit);
}; };
void RenderWidgetHostViewAura::ApplyEventFilterForPopupExit( void RenderWidgetHostViewAura::ApplyEventObserverForPopupExit(
ui::LocatedEvent* event) { const ui::LocatedEvent& event) {
if (in_shutdown_ || is_fullscreen_ || !event->target()) DCHECK(event.type() == ui::ET_MOUSE_PRESSED ||
return; event.type() == ui::ET_TOUCH_PRESSED);
if (event->type() != ui::ET_MOUSE_PRESSED && if (in_shutdown_ || is_fullscreen_)
event->type() != ui::ET_TOUCH_PRESSED) {
return; return;
}
aura::Window* target = static_cast<aura::Window*>(event->target()); // |target| may be null.
aura::Window* target = static_cast<aura::Window*>(event.target());
if (target != window_ && if (target != window_ &&
(!popup_parent_host_view_ || (!popup_parent_host_view_ ||
target != popup_parent_host_view_->window_)) { target != popup_parent_host_view_->window_)) {
...@@ -466,7 +463,8 @@ void RenderWidgetHostViewAura::InitAsPopup( ...@@ -466,7 +463,8 @@ void RenderWidgetHostViewAura::InitAsPopup(
if (NeedsMouseCapture()) if (NeedsMouseCapture())
window_->SetCapture(); window_->SetCapture();
event_filter_for_popup_exit_.reset(new EventFilterForPopupExit(this)); event_observer_for_popup_exit_ =
std::make_unique<EventObserverForPopupExit>(this);
device_scale_factor_ = GetDeviceScaleFactor(); device_scale_factor_ = GetDeviceScaleFactor();
} }
...@@ -1953,7 +1951,7 @@ RenderWidgetHostViewAura::~RenderWidgetHostViewAura() { ...@@ -1953,7 +1951,7 @@ RenderWidgetHostViewAura::~RenderWidgetHostViewAura() {
popup_child_host_view_->popup_parent_host_view_ == this); popup_child_host_view_->popup_parent_host_view_ == this);
popup_child_host_view_->popup_parent_host_view_ = nullptr; popup_child_host_view_->popup_parent_host_view_ = nullptr;
} }
event_filter_for_popup_exit_.reset(); event_observer_for_popup_exit_.reset();
#if defined(OS_WIN) #if defined(OS_WIN)
// The LegacyRenderWidgetHostHWND window should have been destroyed in // The LegacyRenderWidgetHostHWND window should have been destroyed in
......
...@@ -532,7 +532,7 @@ class CONTENT_EXPORT RenderWidgetHostViewAura ...@@ -532,7 +532,7 @@ class CONTENT_EXPORT RenderWidgetHostViewAura
// Dismisses a Web Popup on a mouse or touch press outside the popup and its // Dismisses a Web Popup on a mouse or touch press outside the popup and its
// parent. // parent.
void ApplyEventFilterForPopupExit(ui::LocatedEvent* event); void ApplyEventObserverForPopupExit(const ui::LocatedEvent& event);
// Converts |rect| from screen coordinate to window coordinate. // Converts |rect| from screen coordinate to window coordinate.
gfx::Rect ConvertRectFromScreen(const gfx::Rect& rect) const; gfx::Rect ConvertRectFromScreen(const gfx::Rect& rect) const;
...@@ -586,9 +586,8 @@ class CONTENT_EXPORT RenderWidgetHostViewAura ...@@ -586,9 +586,8 @@ class CONTENT_EXPORT RenderWidgetHostViewAura
// Our child popup host. NULL if we do not have a child popup. // Our child popup host. NULL if we do not have a child popup.
RenderWidgetHostViewAura* popup_child_host_view_; RenderWidgetHostViewAura* popup_child_host_view_;
class EventFilterForPopupExit; class EventObserverForPopupExit;
friend class EventFilterForPopupExit; std::unique_ptr<EventObserverForPopupExit> event_observer_for_popup_exit_;
std::unique_ptr<ui::EventHandler> event_filter_for_popup_exit_;
// True when content is being loaded. Used to show an hourglass cursor. // True when content is being loaded. Used to show an hourglass cursor.
bool is_loading_; bool is_loading_;
......
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