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 @@
#include "ui/events/blink/did_overscroll_params.h"
#include "ui/events/blink/web_input_event.h"
#include "ui/events/event.h"
#include "ui/events/event_observer.h"
#include "ui/events/event_utils.h"
#include "ui/events/gesture_detection/gesture_configuration.h"
#include "ui/events/gestures/gesture_recognizer.h"
......@@ -194,45 +195,41 @@ class WinScreenKeyboardObserver
// We need to watch for mouse events outside a Web Popup or its parent
// and dismiss the popup for certain events.
class RenderWidgetHostViewAura::EventFilterForPopupExit
: public ui::EventHandler {
class RenderWidgetHostViewAura::EventObserverForPopupExit
: public ui::EventObserver {
public:
explicit EventFilterForPopupExit(RenderWidgetHostViewAura* rwhva)
explicit EventObserverForPopupExit(RenderWidgetHostViewAura* rwhva)
: rwhva_(rwhva) {
DCHECK(rwhva_);
aura::Env::GetInstance()->AddPreTargetHandler(this);
aura::Env* env = aura::Env::GetInstance();
env->AddEventObserver(this, env,
{ui::ET_MOUSE_PRESSED, ui::ET_TOUCH_PRESSED});
}
~EventFilterForPopupExit() override {
aura::Env::GetInstance()->RemovePreTargetHandler(this);
~EventObserverForPopupExit() override {
aura::Env::GetInstance()->RemoveEventObserver(this);
}
// Overridden from ui::EventHandler
void OnMouseEvent(ui::MouseEvent* event) override {
rwhva_->ApplyEventFilterForPopupExit(event);
}
void OnTouchEvent(ui::TouchEvent* event) override {
rwhva_->ApplyEventFilterForPopupExit(event);
// ui::EventObserver:
void OnEvent(const ui::Event& event) override {
rwhva_->ApplyEventObserverForPopupExit(*event.AsLocatedEvent());
}
private:
RenderWidgetHostViewAura* rwhva_;
DISALLOW_COPY_AND_ASSIGN(EventFilterForPopupExit);
DISALLOW_COPY_AND_ASSIGN(EventObserverForPopupExit);
};
void RenderWidgetHostViewAura::ApplyEventFilterForPopupExit(
ui::LocatedEvent* event) {
if (in_shutdown_ || is_fullscreen_ || !event->target())
return;
void RenderWidgetHostViewAura::ApplyEventObserverForPopupExit(
const ui::LocatedEvent& event) {
DCHECK(event.type() == ui::ET_MOUSE_PRESSED ||
event.type() == ui::ET_TOUCH_PRESSED);
if (event->type() != ui::ET_MOUSE_PRESSED &&
event->type() != ui::ET_TOUCH_PRESSED) {
if (in_shutdown_ || is_fullscreen_)
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_ &&
(!popup_parent_host_view_ ||
target != popup_parent_host_view_->window_)) {
......@@ -466,7 +463,8 @@ void RenderWidgetHostViewAura::InitAsPopup(
if (NeedsMouseCapture())
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();
}
......@@ -1953,7 +1951,7 @@ RenderWidgetHostViewAura::~RenderWidgetHostViewAura() {
popup_child_host_view_->popup_parent_host_view_ == this);
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)
// The LegacyRenderWidgetHostHWND window should have been destroyed in
......
......@@ -532,7 +532,7 @@ class CONTENT_EXPORT RenderWidgetHostViewAura
// Dismisses a Web Popup on a mouse or touch press outside the popup and its
// parent.
void ApplyEventFilterForPopupExit(ui::LocatedEvent* event);
void ApplyEventObserverForPopupExit(const ui::LocatedEvent& event);
// Converts |rect| from screen coordinate to window coordinate.
gfx::Rect ConvertRectFromScreen(const gfx::Rect& rect) const;
......@@ -586,9 +586,8 @@ class CONTENT_EXPORT RenderWidgetHostViewAura
// Our child popup host. NULL if we do not have a child popup.
RenderWidgetHostViewAura* popup_child_host_view_;
class EventFilterForPopupExit;
friend class EventFilterForPopupExit;
std::unique_ptr<ui::EventHandler> event_filter_for_popup_exit_;
class EventObserverForPopupExit;
std::unique_ptr<EventObserverForPopupExit> event_observer_for_popup_exit_;
// True when content is being loaded. Used to show an hourglass cursor.
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