#include "ui/events/event.h"
#include "ui/events/event_handler.h"
#include "ui/events/event_utils.h"
-#include "ui/events/gestures/gesture_configuration.h"
+#include "ui/events/gesture_detection/gesture_configuration.h"
#include "ui/events/keycodes/keyboard_codes.h"
#include "ui/events/test/event_generator.h"
#include "ui/events/test/test_event_handler.h"
mouse_event_count_(0),
mouse_event_flags_(0x0) {
}
- virtual ~NonClientDelegate() {}
+ ~NonClientDelegate() override {}
int non_client_count() const { return non_client_count_; }
gfx::Point non_client_location() const { return non_client_location_; }
gfx::Point mouse_event_location() const { return mouse_event_location_; }
int mouse_event_flags() const { return mouse_event_flags_; }
- virtual int GetNonClientComponent(const gfx::Point& location) const OVERRIDE {
+ int GetNonClientComponent(const gfx::Point& location) const override {
NonClientDelegate* self = const_cast<NonClientDelegate*>(this);
self->non_client_count_++;
self->non_client_location_ = location;
return HTTOPLEFT;
}
- virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE {
+ void OnMouseEvent(ui::MouseEvent* event) override {
mouse_event_count_++;
mouse_event_location_ = event->location();
mouse_event_flags_ = event->flags();
class ConsumeKeyHandler : public ui::test::TestEventHandler {
public:
ConsumeKeyHandler() {}
- virtual ~ConsumeKeyHandler() {}
+ ~ConsumeKeyHandler() override {}
// Overridden from ui::EventHandler:
- virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE {
+ void OnKeyEvent(ui::KeyEvent* event) override {
ui::test::TestEventHandler::OnKeyEvent(event);
event->StopPropagation();
}
test::CreateTestWindowWithBounds(root_window_->bounds(), root_window_);
non_lock_window->set_id(kNonLockWindowId);
}
- virtual ~TestEventClient() {
- client::SetEventClient(root_window_, NULL);
- }
+ ~TestEventClient() override { client::SetEventClient(root_window_, NULL); }
// Starts/stops locking. Locking prevents windows other than those inside
// the lock container from receiving events, getting focus etc.
private:
// Overridden from client::EventClient:
- virtual bool CanProcessEventsWithinSubtree(
- const Window* window) const OVERRIDE {
+ bool CanProcessEventsWithinSubtree(const Window* window) const override {
return lock_ ?
window->Contains(GetLockWindow()) || GetLockWindow()->Contains(window) :
true;
}
- virtual ui::EventTarget* GetToplevelEventTarget() OVERRIDE {
- return NULL;
- }
+ ui::EventTarget* GetToplevelEventTarget() override { return NULL; }
Window* root_window_;
bool lock_;
w3->parent()->RemoveChild(w3.get());
}
-TEST_F(WindowEventDispatcherTest, IgnoreUnknownKeys) {
+TEST_F(WindowEventDispatcherTest, DontIgnoreUnknownKeys) {
ConsumeKeyHandler handler;
root_window()->AddPreTargetHandler(&handler);
ui::KeyEvent unknown_event(ui::ET_KEY_PRESSED, ui::VKEY_UNKNOWN, ui::EF_NONE);
DispatchEventUsingWindowDispatcher(&unknown_event);
- EXPECT_FALSE(unknown_event.handled());
- EXPECT_EQ(0, handler.num_key_events());
+ EXPECT_TRUE(unknown_event.handled());
+ EXPECT_EQ(1, handler.num_key_events());
handler.Reset();
ui::KeyEvent known_event(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE);
}
// ui::EventHandler overrides:
- virtual void OnEvent(ui::Event* event) OVERRIDE {
+ void OnEvent(ui::Event* event) override {
ui::EventHandler::OnEvent(event);
events_.push_back(event->type());
if (wait_until_event_ == event->type() && run_loop_) {
}
}
- virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE {
+ void OnMouseEvent(ui::MouseEvent* event) override {
mouse_locations_.push_back(event->location());
mouse_event_flags_.push_back(event->flags());
}
- virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE {
+ void OnTouchEvent(ui::TouchEvent* event) override {
touch_locations_.push_back(event->location());
}
- virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE {
+ void OnGestureEvent(ui::GestureEvent* event) override {
gesture_locations_.push_back(event->location());
}
EventTypesToString(recorder.events()));
recorder.Reset();
- // Check that we coalesce held MOUSE_DRAGGED events.
+ // Check that we coalesce held MOUSE_DRAGGED events. Note that here (and
+ // elsewhere in this test) we re-define each event prior to dispatch so that
+ // it has the correct state (phase, handled, target, etc.).
+ mouse_dragged_event = ui::MouseEvent(
+ ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0), gfx::Point(0, 0), 0, 0);
ui::MouseEvent mouse_dragged_event2(ui::ET_MOUSE_DRAGGED, gfx::Point(10, 10),
gfx::Point(10, 10), 0, 0);
DispatchEventUsingWindowDispatcher(&mouse_dragged_event);
DispatchEventUsingWindowDispatcher(&mouse_dragged_event2);
EXPECT_TRUE(recorder.events().empty());
+ mouse_pressed_event = ui::MouseEvent(
+ ui::ET_MOUSE_PRESSED, gfx::Point(0, 0), gfx::Point(0, 0), 0, 0);
DispatchEventUsingWindowDispatcher(&mouse_pressed_event);
EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED",
EventTypesToString(recorder.events()));
// Check that on ReleasePointerMoves, held events are not dispatched
// immediately, but posted instead.
+ mouse_dragged_event = ui::MouseEvent(
+ ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0), gfx::Point(0, 0), 0, 0);
DispatchEventUsingWindowDispatcher(&mouse_dragged_event);
host()->dispatcher()->ReleasePointerMoves();
EXPECT_TRUE(recorder.events().empty());
// However if another message comes in before the dispatch of the posted
// event, check that the posted event is dispatched before this new event.
host()->dispatcher()->HoldPointerMoves();
+ mouse_dragged_event = ui::MouseEvent(
+ ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0), gfx::Point(0, 0), 0, 0);
DispatchEventUsingWindowDispatcher(&mouse_dragged_event);
host()->dispatcher()->ReleasePointerMoves();
+ mouse_pressed_event = ui::MouseEvent(
+ ui::ET_MOUSE_PRESSED, gfx::Point(0, 0), gfx::Point(0, 0), 0, 0);
DispatchEventUsingWindowDispatcher(&mouse_pressed_event);
EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED",
EventTypesToString(recorder.events()));
// Check that if the other message is another MOUSE_DRAGGED, we still coalesce
// them.
host()->dispatcher()->HoldPointerMoves();
+ mouse_dragged_event = ui::MouseEvent(
+ ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0), gfx::Point(0, 0), 0, 0);
DispatchEventUsingWindowDispatcher(&mouse_dragged_event);
host()->dispatcher()->ReleasePointerMoves();
+ mouse_dragged_event2 = ui::MouseEvent(
+ ui::ET_MOUSE_DRAGGED, gfx::Point(10, 10), gfx::Point(10, 10), 0, 0);
DispatchEventUsingWindowDispatcher(&mouse_dragged_event2);
EXPECT_EQ("MOUSE_DRAGGED", EventTypesToString(recorder.events()));
recorder.Reset();
// Check that synthetic mouse move event has a right location when issued
// while holding pointer moves.
+ mouse_dragged_event = ui::MouseEvent(
+ ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0), gfx::Point(0, 0), 0, 0);
+ mouse_dragged_event2 = ui::MouseEvent(
+ ui::ET_MOUSE_DRAGGED, gfx::Point(10, 10), gfx::Point(10, 10), 0, 0);
ui::MouseEvent mouse_dragged_event3(ui::ET_MOUSE_DRAGGED, gfx::Point(28, 28),
gfx::Point(28, 28), 0, 0);
host()->dispatcher()->HoldPointerMoves();
: dispatcher_(dispatcher),
filter_(filter),
holding_moves_(false) {}
- virtual ~HoldPointerOnScrollHandler() {}
+ ~HoldPointerOnScrollHandler() override {}
private:
// ui::test::TestEventHandler:
- virtual void OnGestureEvent(ui::GestureEvent* gesture) OVERRIDE {
+ void OnGestureEvent(ui::GestureEvent* gesture) override {
if (!holding_moves_ && gesture->type() == ui::ET_GESTURE_SCROLL_UPDATE) {
holding_moves_ = true;
dispatcher_->HoldPointerMoves();
public:
DeletingEventFilter()
: delete_during_pre_handle_(false) {}
- virtual ~DeletingEventFilter() {}
+ ~DeletingEventFilter() override {}
void Reset(bool delete_during_pre_handle) {
delete_during_pre_handle_ = delete_during_pre_handle;
private:
// Overridden from ui::EventHandler:
- virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE {
+ void OnKeyEvent(ui::KeyEvent* event) override {
if (delete_during_pre_handle_)
delete event->target();
}
- virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE {
+ void OnMouseEvent(ui::MouseEvent* event) override {
if (delete_during_pre_handle_)
delete event->target();
}
: window_(NULL),
delete_during_handle_(false),
got_event_(false) {}
- virtual ~DeletingWindowDelegate() {}
+ ~DeletingWindowDelegate() override {}
void Reset(Window* window, bool delete_during_handle) {
window_ = window;
private:
// Overridden from WindowDelegate:
- virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE {
+ void OnKeyEvent(ui::KeyEvent* event) override {
if (delete_during_handle_)
delete window_;
got_event_ = true;
}
- virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE {
+ void OnMouseEvent(ui::MouseEvent* event) override {
if (delete_during_handle_)
delete window_;
got_event_ = true;
class DetachesParentOnTapDelegate : public test::TestWindowDelegate {
public:
DetachesParentOnTapDelegate() {}
- virtual ~DetachesParentOnTapDelegate() {}
+ ~DetachesParentOnTapDelegate() override {}
private:
- virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE {
+ void OnGestureEvent(ui::GestureEvent* event) override {
if (event->type() == ui::ET_GESTURE_TAP_DOWN) {
event->SetHandled();
return;
: generator_(generator),
tap_location_(tap_location),
gesture_end_count_(0) {}
- virtual ~NestedGestureDelegate() {}
+ ~NestedGestureDelegate() override {}
int gesture_end_count() const { return gesture_end_count_; }
private:
- virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE {
+ void OnGestureEvent(ui::GestureEvent* event) override {
switch (event->type()) {
case ui::ET_GESTURE_TAP_DOWN:
event->SetHandled();
reposted_(false),
done_cleanup_(false) {}
- virtual ~RepostGestureEventRecorder() {}
+ ~RepostGestureEventRecorder() override {}
- virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE {
+ void OnTouchEvent(ui::TouchEvent* event) override {
if (reposted_ && event->type() == ui::ET_TOUCH_PRESSED) {
done_cleanup_ = true;
Reset();
EventFilterRecorder::OnTouchEvent(event);
}
- virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE {
+ void OnGestureEvent(ui::GestureEvent* event) override {
EXPECT_EQ(done_cleanup_ ? repost_target_ : repost_source_, event->target());
if (event->type() == ui::ET_GESTURE_TAP_DOWN) {
if (!reposted_) {
// Ignore mouse events as they don't fire at all times. This causes
// the GestureRepostEventOrder test to fail randomly.
- virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE {}
+ void OnMouseEvent(ui::MouseEvent* event) override {}
private:
aura::Window* repost_source_;
class OnMouseExitDeletingEventFilter : public EventFilterRecorder {
public:
OnMouseExitDeletingEventFilter() : window_to_delete_(NULL) {}
- virtual ~OnMouseExitDeletingEventFilter() {}
+ ~OnMouseExitDeletingEventFilter() override {}
void set_window_to_delete(Window* window_to_delete) {
window_to_delete_ = window_to_delete;
private:
// Overridden from ui::EventHandler:
- virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE {
+ void OnMouseEvent(ui::MouseEvent* event) override {
EventFilterRecorder::OnMouseEvent(event);
if (window_to_delete_) {
delete window_to_delete_;
}
// WindowObserver:
- virtual void OnWindowDestroying(aura::Window* window) OVERRIDE {
+ void OnWindowDestroying(aura::Window* window) override {
*got_destroying_ = true;
*has_valid_root_ = (window->GetRootWindow() != NULL);
}
explicit DontResetHeldEventWindowDelegate(aura::Window* root)
: root_(root),
mouse_event_count_(0) {}
- virtual ~DontResetHeldEventWindowDelegate() {}
+ ~DontResetHeldEventWindowDelegate() override {}
int mouse_event_count() const { return mouse_event_count_; }
// TestWindowDelegate:
- virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE {
+ void OnMouseEvent(ui::MouseEvent* event) override {
if ((event->flags() & ui::EF_SHIFT_DOWN) != 0 &&
mouse_event_count_++ == 0) {
ui::MouseEvent mouse_event(ui::ET_MOUSE_PRESSED,
got_mouse_event_(false),
got_destroy_(false) {
}
- virtual ~DeleteHostFromHeldMouseEventDelegate() {}
+ ~DeleteHostFromHeldMouseEventDelegate() override {}
bool got_mouse_event() const { return got_mouse_event_; }
bool got_destroy() const { return got_destroy_; }
// TestWindowDelegate:
- virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE {
+ void OnMouseEvent(ui::MouseEvent* event) override {
if ((event->flags() & ui::EF_SHIFT_DOWN) != 0) {
got_mouse_event_ = true;
delete host_;
}
}
- virtual void OnWindowDestroyed(Window* window) OVERRIDE {
- got_destroy_ = true;
- }
+ void OnWindowDestroyed(Window* window) override { got_destroy_ = true; }
private:
WindowTreeHost* host_;
class CaptureWindowTracker : public test::TestWindowDelegate {
public:
CaptureWindowTracker() {}
- virtual ~CaptureWindowTracker() {}
+ ~CaptureWindowTracker() override {}
void CreateCaptureWindow(aura::Window* root_window) {
capture_window_.reset(test::CreateTestWindowWithDelegate(
capture_window_.reset();
}
- virtual void OnCaptureLost() OVERRIDE {
- capture_window_.reset();
- }
+ void OnCaptureLost() override { capture_window_.reset(); }
- virtual void OnWindowDestroyed(Window* window) OVERRIDE {
+ void OnWindowDestroyed(Window* window) override {
TestWindowDelegate::OnWindowDestroyed(window);
capture_window_.reset();
}
class ExitMessageLoopOnMousePress : public ui::test::TestEventHandler {
public:
ExitMessageLoopOnMousePress() {}
- virtual ~ExitMessageLoopOnMousePress() {}
+ ~ExitMessageLoopOnMousePress() override {}
protected:
- virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE {
+ void OnMouseEvent(ui::MouseEvent* event) override {
ui::test::TestEventHandler::OnMouseEvent(event);
if (event->type() == ui::ET_MOUSE_PRESSED)
base::MessageLoopForUI::current()->Quit();
: public WindowEventDispatcherTest {
public:
WindowEventDispatcherTestWithMessageLoop() {}
- virtual ~WindowEventDispatcherTestWithMessageLoop() {}
+ ~WindowEventDispatcherTestWithMessageLoop() override {}
void RunTest() {
// Reset any event the window may have received when bringing up the window
}
protected:
- virtual void SetUp() OVERRIDE {
+ void SetUp() override {
WindowEventDispatcherTest::SetUp();
window_.reset(CreateNormalWindow(1, root_window(), NULL));
window_->AddPreTargetHandler(&handler_);
}
- virtual void TearDown() OVERRIDE {
+ void TearDown() override {
window_.reset();
WindowEventDispatcherTest::TearDown();
}
class WindowEventDispatcherTestInHighDPI : public WindowEventDispatcherTest {
public:
WindowEventDispatcherTestInHighDPI() {}
- virtual ~WindowEventDispatcherTestInHighDPI() {}
+ ~WindowEventDispatcherTestInHighDPI() override {}
protected:
- virtual void SetUp() OVERRIDE {
+ void SetUp() override {
WindowEventDispatcherTest::SetUp();
test_screen()->SetDeviceScaleFactor(2.f);
}
class SelfDestructDelegate : public test::TestWindowDelegate {
public:
SelfDestructDelegate() {}
- virtual ~SelfDestructDelegate() {}
+ ~SelfDestructDelegate() override {}
- virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE {
- window_.reset();
- }
+ void OnMouseEvent(ui::MouseEvent* event) override { window_.reset(); }
void set_window(scoped_ptr<aura::Window> window) {
window_ = window.Pass();
Env::GetInstance()->last_mouse_location().ToString());
}
+// Tests that the window which has capture can get destroyed as a result of
+// ui::ET_MOUSE_CAPTURE_CHANGED event dispatched in
+// WindowEventDispatcher::UpdateCapture without causing a "use after free".
+TEST_F(WindowEventDispatcherTest, DestroyWindowOnCaptureChanged) {
+ SelfDestructDelegate delegate;
+ scoped_ptr<aura::Window> window_first(CreateTestWindowWithDelegate(
+ &delegate, 1, gfx::Rect(20, 10, 10, 20), root_window()));
+ Window* window_first_raw = window_first.get();
+ window_first->Show();
+ window_first->SetCapture();
+ delegate.set_window(window_first.Pass());
+ EXPECT_TRUE(delegate.has_window());
+
+ scoped_ptr<aura::Window> window_second(
+ test::CreateTestWindowWithId(2, root_window()));
+ window_second->Show();
+
+ client::CaptureDelegate* capture_delegate = host()->dispatcher();
+ capture_delegate->UpdateCapture(window_first_raw, window_second.get());
+ EXPECT_FALSE(delegate.has_window());
+}
+
class StaticFocusClient : public client::FocusClient {
public:
explicit StaticFocusClient(Window* focused)
: focused_(focused) {}
- virtual ~StaticFocusClient() {}
+ ~StaticFocusClient() override {}
private:
// client::FocusClient:
- virtual void AddObserver(client::FocusChangeObserver* observer) OVERRIDE {}
- virtual void RemoveObserver(client::FocusChangeObserver* observer) OVERRIDE {}
- virtual void FocusWindow(Window* window) OVERRIDE {}
- virtual void ResetFocusWithinActiveWindow(Window* window) OVERRIDE {}
- virtual Window* GetFocusedWindow() OVERRIDE { return focused_; }
+ void AddObserver(client::FocusChangeObserver* observer) override {}
+ void RemoveObserver(client::FocusChangeObserver* observer) override {}
+ void FocusWindow(Window* window) override {}
+ void ResetFocusWithinActiveWindow(Window* window) override {}
+ Window* GetFocusedWindow() override { return focused_; }
Window* focused_;
explicit DispatchEventHandler(Window* target)
: target_(target),
dispatched_(false) {}
- virtual ~DispatchEventHandler() {}
+ ~DispatchEventHandler() override {}
bool dispatched() const { return dispatched_; }
private:
// ui::EventHandler:
- virtual void OnMouseEvent(ui::MouseEvent* mouse) OVERRIDE {
+ void OnMouseEvent(ui::MouseEvent* mouse) override {
if (mouse->type() == ui::ET_MOUSE_MOVED) {
ui::MouseEvent move(ui::ET_MOUSE_MOVED, target_->bounds().CenterPoint(),
target_->bounds().CenterPoint(), ui::EF_NONE, ui::EF_NONE);
MoveWindowHandler(Window* window, Window* root_window)
: window_to_move_(window),
root_window_to_move_to_(root_window) {}
- virtual ~MoveWindowHandler() {}
+ ~MoveWindowHandler() override {}
private:
// ui::EventHandler:
- virtual void OnMouseEvent(ui::MouseEvent* mouse) OVERRIDE {
+ void OnMouseEvent(ui::MouseEvent* mouse) override {
if (mouse->type() == ui::ET_MOUSE_MOVED) {
root_window_to_move_to_->AddChild(window_to_move_);
}
class AlwaysMouseDownInputStateLookup : public InputStateLookup {
public:
AlwaysMouseDownInputStateLookup() {}
- virtual ~AlwaysMouseDownInputStateLookup() {}
+ ~AlwaysMouseDownInputStateLookup() override {}
private:
// InputStateLookup:
- virtual bool IsMouseButtonDown() const OVERRIDE { return true; }
+ bool IsMouseButtonDown() const override { return true; }
DISALLOW_COPY_AND_ASSIGN(AlwaysMouseDownInputStateLookup);
};
window_ = window;
}
private:
- virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE {
+ void OnTouchEvent(ui::TouchEvent* event) override {
// Convert touch event back to root window coordinates.
event->ConvertLocationToTarget(window_, window_->GetRootWindow());
dispatcher_->ProcessedTouchEvent(event, window_, ui::ER_UNHANDLED);