diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-26 17:41:33 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-26 17:41:33 +0000 |
commit | ea2a867a13715447e88d4f03133dffa2484751a9 (patch) | |
tree | 5dbdc1839b6ed0248ef9ad21cc7b7907e06a3754 /ui | |
parent | 91ae1ceb0ba057c98c492465db70f9fb2d2a7456 (diff) | |
download | chromium_src-ea2a867a13715447e88d4f03133dffa2484751a9.zip chromium_src-ea2a867a13715447e88d4f03133dffa2484751a9.tar.gz chromium_src-ea2a867a13715447e88d4f03133dffa2484751a9.tar.bz2 |
Rework EventFilter.
. EventFilters become optional.
. The Desktop window has a default handler.
. When processing events, Desktop::Process*Event walks up the hierarchy from the target, generating a list of EventFilters to notify about the event, then reverse walks this list notifying.
BUG=none
TEST=unittests
Review URL: http://codereview.chromium.org/8396021
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@107376 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r-- | ui/aura/aura.gyp | 1 | ||||
-rw-r--r-- | ui/aura/desktop.cc | 130 | ||||
-rw-r--r-- | ui/aura/desktop.h | 6 | ||||
-rw-r--r-- | ui/aura/event_filter.cc | 49 | ||||
-rw-r--r-- | ui/aura/event_filter.h | 47 | ||||
-rw-r--r-- | ui/aura/event_filter_unittest.cc | 212 | ||||
-rw-r--r-- | ui/aura/toplevel_window_event_filter.cc | 18 | ||||
-rw-r--r-- | ui/aura/toplevel_window_event_filter.h | 7 | ||||
-rw-r--r-- | ui/aura/window.cc | 26 | ||||
-rw-r--r-- | ui/aura/window.h | 10 | ||||
-rw-r--r-- | ui/aura_shell/default_container_event_filter.cc | 6 | ||||
-rw-r--r-- | ui/aura_shell/default_container_event_filter.h | 4 |
12 files changed, 397 insertions, 119 deletions
diff --git a/ui/aura/aura.gyp b/ui/aura/aura.gyp index 92e6e7f..a1d8704 100644 --- a/ui/aura/aura.gyp +++ b/ui/aura/aura.gyp @@ -128,6 +128,7 @@ 'test/test_suite.h', 'test/test_window_delegate.cc', 'test/test_window_delegate.h', + 'event_filter_unittest.cc', 'toplevel_window_event_filter_unittest.cc', 'window_unittest.cc', '<(SHARED_INTERMEDIATE_DIR)/ui/gfx/gfx_resources.rc', diff --git a/ui/aura/desktop.cc b/ui/aura/desktop.cc index 2b3d759..ae14d46 100644 --- a/ui/aura/desktop.cc +++ b/ui/aura/desktop.cc @@ -18,6 +18,7 @@ #include "ui/aura/desktop_host.h" #include "ui/aura/desktop_observer.h" #include "ui/aura/event.h" +#include "ui/aura/event_filter.h" #include "ui/aura/focus_manager.h" #include "ui/aura/screen_aura.h" #include "ui/aura/toplevel_window_container.h" @@ -66,6 +67,78 @@ class DefaultDesktopDelegate : public DesktopDelegate { DISALLOW_COPY_AND_ASSIGN(DefaultDesktopDelegate); }; +class DesktopEventFilter : public EventFilter { + public: + explicit DesktopEventFilter(Window* owner) : EventFilter(owner) {} + virtual ~DesktopEventFilter() {} + + // Overridden from EventFilter: + virtual bool PreHandleKeyEvent(Window* target, KeyEvent* event) OVERRIDE { + return false; + } + virtual bool PreHandleMouseEvent(Window* target, MouseEvent* event) OVERRIDE { + switch (event->type()) { + case ui::ET_MOUSE_PRESSED: + ActivateIfNecessary(target, event); + break; + case ui::ET_MOUSE_MOVED: + Desktop::GetInstance()->SetCursor(target->GetCursor(event->location())); + break; + default: + break; + } + return false; + } + virtual ui::TouchStatus PreHandleTouchEvent(Window* target, + TouchEvent* event) OVERRIDE { + if (event->type() == ui::ET_TOUCH_PRESSED) + ActivateIfNecessary(target, event); + return ui::TOUCH_STATUS_UNKNOWN; + } + + private: + // If necessary, activates |window| and changes focus. + void ActivateIfNecessary(Window* window, Event* event) { + // TODO(beng): some windows (e.g. disabled ones, tooltips, etc) may not be + // focusable. + + Window* active_window = Desktop::GetInstance()->active_window(); + Window* toplevel_window = window; + while (toplevel_window && toplevel_window != active_window && + toplevel_window->parent() && + !toplevel_window->parent()->AsToplevelWindowContainer()) { + toplevel_window = toplevel_window->parent(); + } + if (toplevel_window == active_window) { + // |window| is a descendant of the active window, no need to activate. + window->GetFocusManager()->SetFocusedWindow(window); + return; + } + if (!toplevel_window) { + // |window| is not in a top level window. + return; + } + if (!toplevel_window->delegate() || + !toplevel_window->delegate()->ShouldActivate(event)) + return; + + Desktop::GetInstance()->SetActiveWindow(toplevel_window, window); + } + + DISALLOW_COPY_AND_ASSIGN(DesktopEventFilter); +}; + +typedef std::vector<EventFilter*> EventFilters; + +void GetEventFiltersToNotify(Window* target, EventFilters* filters) { + Window* window = target->parent(); + while (window) { + if (window->event_filter()) + filters->push_back(window->event_filter()); + window = window->parent(); + } +} + } // namespace Desktop* Desktop::instance_ = NULL; @@ -89,6 +162,7 @@ Desktop::Desktop() gfx::Screen::SetInstance(screen_); host_->SetDesktop(this); last_mouse_location_ = host_->QueryMouseLocation(); + SetEventFilter(new DesktopEventFilter(this)); if (ui::Compositor::compositor_factory()) { compositor_ = (*ui::Compositor::compositor_factory())(this); @@ -178,7 +252,7 @@ bool Desktop::DispatchMouseEvent(MouseEvent* event) { } if (target && target->delegate()) { MouseEvent translated_event(*event, this, target); - return target->OnMouseEvent(&translated_event); + return ProcessMouseEvent(target, &translated_event); } return false; } @@ -215,7 +289,7 @@ bool Desktop::DispatchKeyEvent(KeyEvent* event) { if (focused_window_) { KeyEvent translated_event(*event); - return focused_window_->OnKeyEvent(&translated_event); + return ProcessKeyEvent(focused_window_, &translated_event); } return false; } @@ -229,7 +303,7 @@ bool Desktop::DispatchTouchEvent(TouchEvent* event) { target = GetEventHandlerForPoint(event->location()); if (target) { TouchEvent translated_event(*event, this, target); - ui::TouchStatus status = target->OnTouchEvent(&translated_event); + ui::TouchStatus status = ProcessTouchEvent(target, &translated_event); if (status == ui::TOUCH_STATUS_START) touch_event_handler_ = target; else if (status == ui::TOUCH_STATUS_END || @@ -380,15 +454,61 @@ void Desktop::HandleMouseMoved(const MouseEvent& event, Window* target) { if (mouse_moved_handler_ && mouse_moved_handler_->delegate()) { MouseEvent translated_event(event, this, mouse_moved_handler_, ui::ET_MOUSE_EXITED); - mouse_moved_handler_->OnMouseEvent(&translated_event); + ProcessMouseEvent(mouse_moved_handler_, &translated_event); } mouse_moved_handler_ = target; // Send an entered event. if (mouse_moved_handler_ && mouse_moved_handler_->delegate()) { MouseEvent translated_event(event, this, mouse_moved_handler_, ui::ET_MOUSE_ENTERED); - mouse_moved_handler_->OnMouseEvent(&translated_event); + ProcessMouseEvent(mouse_moved_handler_, &translated_event); + } +} + +bool Desktop::ProcessMouseEvent(Window* target, MouseEvent* event) { + if (!target->IsVisible()) + return false; + + EventFilters filters; + GetEventFiltersToNotify(target, &filters); + for (EventFilters::const_reverse_iterator it = filters.rbegin(); + it != filters.rend(); ++it) { + if ((*it)->PreHandleMouseEvent(target, event)) + return true; } + + return target->delegate()->OnMouseEvent(event); +} + +bool Desktop::ProcessKeyEvent(Window* target, KeyEvent* event) { + if (!target->IsVisible()) + return false; + + EventFilters filters; + GetEventFiltersToNotify(target, &filters); + for (EventFilters::const_reverse_iterator it = filters.rbegin(); + it != filters.rend(); ++it) { + if ((*it)->PreHandleKeyEvent(target, event)) + return true; + } + + return target->delegate()->OnKeyEvent(event); +} + +ui::TouchStatus Desktop::ProcessTouchEvent(Window* target, TouchEvent* event) { + if (!target->IsVisible()) + return ui::TOUCH_STATUS_UNKNOWN; + + EventFilters filters; + GetEventFiltersToNotify(target, &filters); + for (EventFilters::const_reverse_iterator it = filters.rbegin(); + it != filters.rend(); ++it) { + ui::TouchStatus status = (*it)->PreHandleTouchEvent(target, event); + if (status != ui::TOUCH_STATUS_UNKNOWN) + return status; + } + + return target->delegate()->OnTouchEvent(event); } void Desktop::ScheduleDraw() { diff --git a/ui/aura/desktop.h b/ui/aura/desktop.h index ffeed27..ec3521d 100644 --- a/ui/aura/desktop.h +++ b/ui/aura/desktop.h @@ -125,7 +125,7 @@ class AURA_EXPORT Desktop : public ui::CompositorDelegate, // If |window| has mouse capture, the current capture window is set to NULL. void ReleaseCapture(Window* window); - // Overrridden from Window: + // Overridden from Window: virtual void SetTransform(const ui::Transform& transform) OVERRIDE; private: @@ -133,6 +133,10 @@ class AURA_EXPORT Desktop : public ui::CompositorDelegate, // sending exited and entered events as its value changes. void HandleMouseMoved(const MouseEvent& event, Window* target); + bool ProcessMouseEvent(Window* target, MouseEvent* event); + bool ProcessKeyEvent(Window* target, KeyEvent* event); + ui::TouchStatus ProcessTouchEvent(Window* target, TouchEvent* event); + // Overridden from ui::CompositorDelegate virtual void ScheduleDraw(); diff --git a/ui/aura/event_filter.cc b/ui/aura/event_filter.cc index 2f2f177..2f67a11 100644 --- a/ui/aura/event_filter.cc +++ b/ui/aura/event_filter.cc @@ -18,53 +18,4 @@ EventFilter::EventFilter(Window* owner) : owner_(owner) { EventFilter::~EventFilter() { } -bool EventFilter::OnMouseEvent(Window* target, MouseEvent* event) { - switch (event->type()) { - case ui::ET_MOUSE_PRESSED: - ActivateIfNecessary(target, event); - break; - case ui::ET_MOUSE_MOVED: - Desktop::GetInstance()->SetCursor(target->GetCursor(event->location())); - break; - default: - break; - } - return false; -} - -ui::TouchStatus EventFilter::OnTouchEvent(Window* target, TouchEvent* event) { - if (event->type() == ui::ET_TOUCH_PRESSED) - ActivateIfNecessary(target, event); - return ui::TOUCH_STATUS_UNKNOWN; -} - -void EventFilter::ActivateIfNecessary( - Window* window, - Event* event) { - // TODO(beng): some windows (e.g. disabled ones, tooltips, etc) may not be - // focusable. - - Window* active_window = Desktop::GetInstance()->active_window(); - Window* toplevel_window = window; - while (toplevel_window && toplevel_window != active_window && - toplevel_window->parent() && - !toplevel_window->parent()->AsToplevelWindowContainer()) { - toplevel_window = toplevel_window->parent(); - } - if (toplevel_window == active_window) { - // |window| is a descendant of the active window, no need to activate. - window->GetFocusManager()->SetFocusedWindow(window); - return; - } - if (!toplevel_window) { - // |window| is not in a top level window. - return; - } - if (!toplevel_window->delegate() || - !toplevel_window->delegate()->ShouldActivate(event)) - return; - - Desktop::GetInstance()->SetActiveWindow(toplevel_window, window); -} - } // namespace aura diff --git a/ui/aura/event_filter.h b/ui/aura/event_filter.h index 3a94104..da2c2d1 100644 --- a/ui/aura/event_filter.h +++ b/ui/aura/event_filter.h @@ -7,37 +7,56 @@ #pragma once #include "base/basictypes.h" +#include "ui/aura/aura_export.h" #include "ui/base/events.h" namespace aura { -class Event; +class KeyEvent; class MouseEvent; class TouchEvent; class Window; -// An object that filters events sent to an owner window, potentially performing -// adjustments to the window's position, size and z-index. -class EventFilter { +// An object that filters events sent to an owner window. The filter can stop +// further processing of events. +// +// When the Desktop receives an event, it determines the "target window" for +// the event, this is typically the visible window whose bounds most tightly +// enclose the event coordinates, in the case of mouse events, or the focused +// window, in the case of key events. +// +// The Desktop then walks up the hierarchy from the target to its own window, +// collecting a list of EventFilters. This list is notified in reverse order +// (i.e. descending, from the Desktop's own event filter). Each filter gets a +// chance to prevent further processing of the event and/or take other actions. +class AURA_EXPORT EventFilter { public: explicit EventFilter(Window* owner); virtual ~EventFilter(); - // Try to handle |event| (before the owner's delegate gets a chance to). - // Returns true if the event was handled by the WindowManager and should not - // be forwarded to the owner's delegate. - // Default implementation for ET_MOUSE_PRESSED and ET_TOUCH_PRESSED focuses - // the window. - virtual bool OnMouseEvent(Window* target, MouseEvent* event); - virtual ui::TouchStatus OnTouchEvent(Window* target, TouchEvent* event); + // Parameters: a |target| Window and the |event|. The target window is the + // window the event was targeted at. If |event| is a LocatedEvent, its + // coordinates are relative to |target|. + + // For all PreHandle*() functions that return a bool, return true if the + // filter consumes the event and further processing (by the target, for + // example) is not performed. Return false if the filter does not consume the + // event and further processing is performed. Note that in this case the + // filter may still perform some action, the return value simply indicates + // that further processing can occur. + + virtual bool PreHandleKeyEvent(Window* target, KeyEvent* event) = 0; + virtual bool PreHandleMouseEvent(Window* target, MouseEvent* event) = 0; + + // Returns a value other than ui::TOUCH_STATUS_UNKNOWN if the event is + // consumed. + virtual ui::TouchStatus PreHandleTouchEvent(Window* target, + TouchEvent* event) = 0; protected: Window* owner() { return owner_; } private: - // If necessary, activates |window| and changes focus. - void ActivateIfNecessary(Window* window, Event* event); - Window* owner_; DISALLOW_COPY_AND_ASSIGN(EventFilter); diff --git a/ui/aura/event_filter_unittest.cc b/ui/aura/event_filter_unittest.cc new file mode 100644 index 0000000..498dc97 --- /dev/null +++ b/ui/aura/event_filter_unittest.cc @@ -0,0 +1,212 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/aura/event_filter.h" + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "ui/aura/desktop.h" +#include "ui/aura/event.h" +#include "ui/aura/test/aura_test_base.h" +#include "ui/aura/test/event_generator.h" +#include "ui/aura/test/test_desktop_delegate.h" +#include "ui/aura/test/test_window_delegate.h" + +#if defined(OS_WIN) +// Windows headers define macros for these function names which screw with us. +#if defined(CreateWindow) +#undef CreateWindow +#endif +#endif + +namespace aura { +namespace test { + +typedef AuraTestBase EventFilterTest; + +class TestEventFilterWindowDelegate : public TestWindowDelegate { + public: + TestEventFilterWindowDelegate() + : key_event_count_(0), + mouse_event_count_(0), + touch_event_count_(0) {} + virtual ~TestEventFilterWindowDelegate() {} + + void ResetCounts() { + key_event_count_ = 0; + mouse_event_count_ = 0; + touch_event_count_ = 0; + } + + int key_event_count() const { return key_event_count_; } + int mouse_event_count() const { return mouse_event_count_; } + int touch_event_count() const { return touch_event_count_; } + + // Overridden from TestWindowDelegate: + virtual bool OnKeyEvent(KeyEvent* event) OVERRIDE { + ++key_event_count_; + return true; + } + virtual bool OnMouseEvent(MouseEvent* event) OVERRIDE { + ++mouse_event_count_; + return true; + } + virtual ui::TouchStatus OnTouchEvent(TouchEvent* event) OVERRIDE { + ++touch_event_count_; + return ui::TOUCH_STATUS_UNKNOWN; + } + + private: + int key_event_count_; + int mouse_event_count_; + int touch_event_count_; + + DISALLOW_COPY_AND_ASSIGN(TestEventFilterWindowDelegate); +}; + +Window* CreateWindow(int id, Window* parent, WindowDelegate* delegate) { + Window* window = new Window(delegate ? delegate : new TestWindowDelegate); + window->set_id(id); + window->Init(); + window->SetParent(parent); + window->SetBounds(gfx::Rect(0, 0, 100, 100)); + window->Show(); + return window; +} + +class TestEventFilter : public EventFilter { + public: + explicit TestEventFilter(Window* owner) + : EventFilter(owner), + key_event_count_(0), + mouse_event_count_(0), + touch_event_count_(0), + consumes_key_events_(false), + consumes_mouse_events_(false), + consumes_touch_events_(false) { + } + virtual ~TestEventFilter() {} + + void ResetCounts() { + key_event_count_ = 0; + mouse_event_count_ = 0; + touch_event_count_ = 0; + } + + int key_event_count() const { return key_event_count_; } + int mouse_event_count() const { return mouse_event_count_; } + int touch_event_count() const { return touch_event_count_; } + + void set_consumes_key_events(bool consumes_key_events) { + consumes_key_events_ = consumes_key_events; + } + void set_consumes_mouse_events(bool consumes_mouse_events) { + consumes_mouse_events_ = consumes_mouse_events; + } + void set_consumes_touch_events(bool consumes_touch_events) { + consumes_touch_events_ = consumes_touch_events; + } + + // Overridden from EventFilter: + virtual bool PreHandleKeyEvent(Window* target, KeyEvent* event) OVERRIDE { + ++key_event_count_; + return consumes_key_events_; + } + virtual bool PreHandleMouseEvent(Window* target, MouseEvent* event) OVERRIDE { + ++mouse_event_count_; + return consumes_mouse_events_; + } + virtual ui::TouchStatus PreHandleTouchEvent(Window* target, + TouchEvent* event) OVERRIDE { + ++touch_event_count_; + // TODO(sadrul): ! + return ui::TOUCH_STATUS_UNKNOWN; + } + + private: + int key_event_count_; + int mouse_event_count_; + int touch_event_count_; + + bool consumes_key_events_; + bool consumes_mouse_events_; + bool consumes_touch_events_; + + DISALLOW_COPY_AND_ASSIGN(TestEventFilter); +}; + +// Creates this hierarchy: +// +// Desktop Window (EF) +// +- w1 (EF) +// +- w11 +// +- w111 (EF) +// +- w1111 <-- target window +TEST_F(EventFilterTest, Basic) { + scoped_ptr<Window> w1(CreateWindow(1, Desktop::GetInstance(), NULL)); + scoped_ptr<Window> w11(CreateWindow(11, w1.get(), NULL)); + scoped_ptr<Window> w111(CreateWindow(111, w11.get(), NULL)); + TestEventFilterWindowDelegate* d1111 = new TestEventFilterWindowDelegate; + scoped_ptr<Window> w1111(CreateWindow(1111, w111.get(), d1111)); + + TestEventFilter* desktop_filter = new TestEventFilter(Desktop::GetInstance()); + TestEventFilter* w1_filter = new TestEventFilter(w1.get()); + TestEventFilter* w111_filter = new TestEventFilter(w111.get()); + Desktop::GetInstance()->SetEventFilter(desktop_filter); + w1->SetEventFilter(w1_filter); + w111->SetEventFilter(w111_filter); + + w1111->GetFocusManager()->SetFocusedWindow(w1111.get()); + + // To start with, no one is going to consume any events. All three filters + // and the w1111's delegate should receive the event. + EventGenerator generator(w1111.get()); + generator.PressLeftButton(); + KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_A, 0); + Desktop::GetInstance()->DispatchKeyEvent(&key_event); + + // TODO(sadrul): TouchEvent! + EXPECT_EQ(1, desktop_filter->key_event_count()); + EXPECT_EQ(1, w1_filter->key_event_count()); + EXPECT_EQ(1, w111_filter->key_event_count()); + EXPECT_EQ(1, d1111->key_event_count()); + EXPECT_EQ(1, desktop_filter->mouse_event_count()); + EXPECT_EQ(1, w1_filter->mouse_event_count()); + EXPECT_EQ(1, w111_filter->mouse_event_count()); + EXPECT_EQ(1, d1111->mouse_event_count()); + EXPECT_EQ(0, desktop_filter->touch_event_count()); + EXPECT_EQ(0, w1_filter->touch_event_count()); + EXPECT_EQ(0, w111_filter->touch_event_count()); + EXPECT_EQ(0, d1111->touch_event_count()); + + d1111->ResetCounts(); + desktop_filter->ResetCounts(); + w1_filter->ResetCounts(); + w111_filter->ResetCounts(); + + // Now make w1's EF consume the event. + w1_filter->set_consumes_key_events(true); + w1_filter->set_consumes_mouse_events(true); + + generator.ReleaseLeftButton(); + Desktop::GetInstance()->DispatchKeyEvent(&key_event); + + // TODO(sadrul): TouchEvent! + EXPECT_EQ(1, desktop_filter->key_event_count()); + EXPECT_EQ(1, w1_filter->key_event_count()); + EXPECT_EQ(0, w111_filter->key_event_count()); + EXPECT_EQ(0, d1111->key_event_count()); + EXPECT_EQ(1, desktop_filter->mouse_event_count()); + EXPECT_EQ(1, w1_filter->mouse_event_count()); + EXPECT_EQ(0, w111_filter->mouse_event_count()); + EXPECT_EQ(0, d1111->mouse_event_count()); + EXPECT_EQ(0, desktop_filter->touch_event_count()); + EXPECT_EQ(0, w1_filter->touch_event_count()); + EXPECT_EQ(0, w111_filter->touch_event_count()); + EXPECT_EQ(0, d1111->touch_event_count()); +} + +} // namespace test +} // namespace aura + diff --git a/ui/aura/toplevel_window_event_filter.cc b/ui/aura/toplevel_window_event_filter.cc index 707e3a7..a492072 100644 --- a/ui/aura/toplevel_window_event_filter.cc +++ b/ui/aura/toplevel_window_event_filter.cc @@ -122,12 +122,15 @@ ToplevelWindowEventFilter::ToplevelWindowEventFilter(Window* owner) ToplevelWindowEventFilter::~ToplevelWindowEventFilter() { } -bool ToplevelWindowEventFilter::OnMouseEvent(Window* target, - MouseEvent* event) { +bool ToplevelWindowEventFilter::PreHandleKeyEvent(Window* target, + KeyEvent* event) { + return false; +} + +bool ToplevelWindowEventFilter::PreHandleMouseEvent(Window* target, + MouseEvent* event) { // Process EventFilters implementation first so that it processes // activation/focus first. - EventFilter::OnMouseEvent(target, event); - switch (event->type()) { case ui::ET_MOUSE_MOVED: UpdateWindowComponentForEvent(target, event); @@ -161,12 +164,13 @@ bool ToplevelWindowEventFilter::OnMouseEvent(Window* target, return false; } -ui::TouchStatus ToplevelWindowEventFilter::OnTouchEvent(Window* target, - TouchEvent* event) { +ui::TouchStatus ToplevelWindowEventFilter::PreHandleTouchEvent( + Window* target, + TouchEvent* event) { // Process EventFilters implementation first so that it processes // activation/focus first. // TODO(sad): Allow moving/resizing/maximizing etc. from touch? - return EventFilter::OnTouchEvent(target, event); + return ui::TOUCH_STATUS_UNKNOWN; } void ToplevelWindowEventFilter::MoveWindowToFront(Window* target) { diff --git a/ui/aura/toplevel_window_event_filter.h b/ui/aura/toplevel_window_event_filter.h index 2a85c4f..ff19a17 100644 --- a/ui/aura/toplevel_window_event_filter.h +++ b/ui/aura/toplevel_window_event_filter.h @@ -23,9 +23,10 @@ class AURA_EXPORT ToplevelWindowEventFilter : public EventFilter { virtual ~ToplevelWindowEventFilter(); // Overridden from EventFilter: - virtual bool OnMouseEvent(Window* target, MouseEvent* event) OVERRIDE; - virtual ui::TouchStatus OnTouchEvent(Window* target, - TouchEvent* event) OVERRIDE; + virtual bool PreHandleKeyEvent(Window* target, KeyEvent* event) OVERRIDE; + virtual bool PreHandleMouseEvent(Window* target, MouseEvent* event) OVERRIDE; + virtual ui::TouchStatus PreHandleTouchEvent(Window* target, + TouchEvent* event) OVERRIDE; protected: // Returns the |window_component_|. See the variable definition below for diff --git a/ui/aura/window.cc b/ui/aura/window.cc index 258d9d8..da87e96 100644 --- a/ui/aura/window.cc +++ b/ui/aura/window.cc @@ -306,32 +306,6 @@ void Window::SetEventFilter(EventFilter* event_filter) { event_filter_.reset(event_filter); } -bool Window::OnMouseEvent(MouseEvent* event) { - if (!parent_ || !IsVisible()) - return false; - if (!parent_->event_filter_.get()) - parent_->SetEventFilter(new EventFilter(parent_)); - return parent_->event_filter_->OnMouseEvent(this, event) || - delegate_->OnMouseEvent(event); -} - -bool Window::OnKeyEvent(KeyEvent* event) { - return IsVisible() && delegate_->OnKeyEvent(event); -} - -ui::TouchStatus Window::OnTouchEvent(TouchEvent* event) { - if (!parent_ || !IsVisible()) - return ui::TOUCH_STATUS_UNKNOWN; - - if (!parent_->event_filter_.get()) - parent_->SetEventFilter(new EventFilter(parent_)); - - ui::TouchStatus status = parent_->event_filter_->OnTouchEvent(this, event); - if (status == ui::TOUCH_STATUS_UNKNOWN && delegate_) - status = delegate_->OnTouchEvent(event); - return status; -} - void Window::AddObserver(WindowObserver* observer) { observers_.AddObserver(observer); } diff --git a/ui/aura/window.h b/ui/aura/window.h index 3e13090..8b236e2 100644 --- a/ui/aura/window.h +++ b/ui/aura/window.h @@ -191,15 +191,7 @@ class AURA_EXPORT Window : public ui::LayerDelegate { // Window takes ownership of the EventFilter. void SetEventFilter(EventFilter* event_filter); - - // Handles a mouse event. Returns true if handled. - bool OnMouseEvent(MouseEvent* event); - - // Handles a key event. Returns true if handled. - bool OnKeyEvent(KeyEvent* event); - - // Handles a touch event. - ui::TouchStatus OnTouchEvent(TouchEvent* event); + EventFilter* event_filter() { return event_filter_.get(); } // Add/remove observer. void AddObserver(WindowObserver* observer); diff --git a/ui/aura_shell/default_container_event_filter.cc b/ui/aura_shell/default_container_event_filter.cc index c54e391..9547148 100644 --- a/ui/aura_shell/default_container_event_filter.cc +++ b/ui/aura_shell/default_container_event_filter.cc @@ -20,8 +20,8 @@ DefaultContainerEventFilter::DefaultContainerEventFilter(aura::Window* owner) DefaultContainerEventFilter::~DefaultContainerEventFilter() { } -bool DefaultContainerEventFilter::OnMouseEvent(aura::Window* target, - aura::MouseEvent* event) { +bool DefaultContainerEventFilter::PreHandleMouseEvent(aura::Window* target, + aura::MouseEvent* event) { DefaultContainerLayoutManager* layout_manager = static_cast<DefaultContainerLayoutManager*>(owner()->layout_manager()); DCHECK(layout_manager); @@ -30,7 +30,7 @@ bool DefaultContainerEventFilter::OnMouseEvent(aura::Window* target, if (event->type() == ui::ET_MOUSE_DRAGGED && drag_state_ == DRAG_NONE) layout_manager->PrepareForMoveOrResize(target, event); - bool handled = ToplevelWindowEventFilter::OnMouseEvent(target, event); + bool handled = ToplevelWindowEventFilter::PreHandleMouseEvent(target, event); switch (event->type()) { case ui::ET_MOUSE_DRAGGED: diff --git a/ui/aura_shell/default_container_event_filter.h b/ui/aura_shell/default_container_event_filter.h index 8371087..0e9205a 100644 --- a/ui/aura_shell/default_container_event_filter.h +++ b/ui/aura_shell/default_container_event_filter.h @@ -17,8 +17,8 @@ class DefaultContainerEventFilter : public aura::ToplevelWindowEventFilter { virtual ~DefaultContainerEventFilter(); // Overridden from aura::ToplevelWindowEventFilter: - virtual bool OnMouseEvent(aura::Window* target, - aura::MouseEvent* event) OVERRIDE; + virtual bool PreHandleMouseEvent(aura::Window* target, + aura::MouseEvent* event) OVERRIDE; private: enum DragState { |