diff options
author | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-06 22:45:41 +0000 |
---|---|---|
committer | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-06 22:45:41 +0000 |
commit | 4d8784a763ac72e5704ec6930fa23246a02321a8 (patch) | |
tree | 9c7b6672e8164a27d2424490459f0ad173a7de37 /ui/aura | |
parent | 3790cbd9434b76c65dc29c809c6138480cda2903 (diff) | |
download | chromium_src-4d8784a763ac72e5704ec6930fa23246a02321a8.zip chromium_src-4d8784a763ac72e5704ec6930fa23246a02321a8.tar.gz chromium_src-4d8784a763ac72e5704ec6930fa23246a02321a8.tar.bz2 |
events: Change how EventDispatcher works.
* Now that all events are dispatched using the same code-paths, the dispatch
code no longer needs to be template-ized. Remove the template code.
* EventDispatcher uses a delegate to determine if the event-target is still
alive.
* aura::RootWindow, FocusController etc. become EventDispatcherDelegate. Each
creates a dispatcher for each event-dispatch.
* All users of EventDispatcher (i.e. RootWindow, FocusController) need to let
the dispatcher know if it gets destroyed during an event-dispatch. After the
event dispatch, the user checks with the dispatcher first to determine if it
has been destroyed, and restores member variables as appropriate if it
wasn't.
These fix a number of issues where the event-dispatcher could be destroyed
during the dispatch and cause all sorts of badness.
BUG=164432
Review URL: https://codereview.chromium.org/11451027
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@171613 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/aura')
-rw-r--r-- | ui/aura/root_window.cc | 52 | ||||
-rw-r--r-- | ui/aura/root_window.h | 11 |
2 files changed, 18 insertions, 45 deletions
diff --git a/ui/aura/root_window.cc b/ui/aura/root_window.cc index db2594a..5c6f48d 100644 --- a/ui/aura/root_window.cc +++ b/ui/aura/root_window.cc @@ -261,7 +261,7 @@ bool RootWindow::DispatchGestureEvent(ui::GestureEvent* event) { if (target) { event->ConvertLocationToTarget(static_cast<Window*>(this), target); - ProcessGestureEvent(target, event); + ProcessEvent(target ? target : this, event); return event->handled(); } @@ -533,7 +533,7 @@ void RootWindow::UpdateCapture(Window* old_capture, ui::MouseEvent event(ui::ET_MOUSE_CAPTURE_CHANGED, gfx::Point(), gfx::Point(), 0); - ProcessMouseEvent(old_capture, &event); + ProcessEvent(old_capture, &event); old_capture->delegate()->OnCaptureLost(); } @@ -595,7 +595,7 @@ void RootWindow::HandleMouseMoved(const ui::MouseEvent& event, Window* target) { mouse_moved_handler_, ui::ET_MOUSE_EXITED, event.flags()); - ProcessMouseEvent(mouse_moved_handler_, &translated_event); + ProcessEvent(mouse_moved_handler_, &translated_event); } if (mouse_event_dispatch_target_ != target) { @@ -611,39 +611,15 @@ void RootWindow::HandleMouseMoved(const ui::MouseEvent& event, Window* target) { mouse_moved_handler_, ui::ET_MOUSE_ENTERED, event.flags()); - ProcessMouseEvent(mouse_moved_handler_, &translated_event); + ProcessEvent(mouse_moved_handler_, &translated_event); } } -void RootWindow::ProcessMouseEvent(Window* target, ui::MouseEvent* event) { - base::AutoReset<Window*> reset(&event_dispatch_target_, target); - ProcessEvent(target, event); -} - -void RootWindow::ProcessKeyEvent(Window* target, ui::KeyEvent* event) { - if (!target) - target = this; - base::AutoReset<Window*> reset(&event_dispatch_target_, target); - ProcessEvent(target, event); -} - -void RootWindow::ProcessScrollEvent(Window* target, ui::ScrollEvent* event) { - base::AutoReset<Window*> reset(&event_dispatch_target_, target); - ProcessEvent(target, event); -} - -void RootWindow::ProcessTouchEvent(Window* target, ui::TouchEvent* event) { - if (!target) - target = this; - base::AutoReset<Window*> reset(&event_dispatch_target_, target); - ProcessEvent(target, event); -} - -void RootWindow::ProcessGestureEvent(Window* target, ui::GestureEvent* event) { - if (!target) - target = this; - base::AutoReset<Window*> reset(&event_dispatch_target_, target); - ProcessEvent(target, event); +void RootWindow::ProcessEvent(Window* target, ui::Event* event) { + Window* old_target = event_dispatch_target_; + event_dispatch_target_ = target; + if (DispatchEvent(target, event)) + event_dispatch_target_ = old_target; } bool RootWindow::ProcessGestures(ui::GestureRecognizer::Gestures* gestures) { @@ -759,7 +735,7 @@ bool RootWindow::OnHostKeyEvent(ui::KeyEvent* event) { client::GetFocusClient(this)->FocusWindow(NULL, NULL); return false; } - ProcessKeyEvent(focused_window, event); + ProcessEvent(focused_window ? focused_window : this, event); return event->handled(); } @@ -803,7 +779,7 @@ bool RootWindow::OnHostScrollEvent(ui::ScrollEvent* event) { flags |= ui::EF_IS_NON_CLIENT; event->set_flags(flags); event->ConvertLocationToTarget(static_cast<Window*>(this), target); - ProcessScrollEvent(target, event); + ProcessEvent(target, event); return event->handled(); } return false; @@ -843,7 +819,7 @@ bool RootWindow::OnHostTouchEvent(ui::TouchEvent* event) { if (!target && !bounds().Contains(event->location())) { // If the initial touch is outside the root window, target the root. target = this; - ProcessTouchEvent(target, event); + ProcessEvent(target ? target : NULL, event); CHECK_EQ(ui::ER_UNHANDLED, event->result()); result = event->result(); } else { @@ -856,7 +832,7 @@ bool RootWindow::OnHostTouchEvent(ui::TouchEvent* event) { ui::TouchEvent translated_event( *event, static_cast<Window*>(this), target); - ProcessTouchEvent(target, &translated_event); + ProcessEvent(target ? target : NULL, &translated_event); handled = translated_event.handled(); result = translated_event.result(); } @@ -966,7 +942,7 @@ bool RootWindow::DispatchMouseEventToTarget(ui::MouseEvent* event, event->ConvertLocationToTarget(static_cast<Window*>(this), target); if (IsNonClientLocation(target, event->location())) event->set_flags(event->flags() | ui::EF_IS_NON_CLIENT); - ProcessMouseEvent(target, event); + ProcessEvent(target, event); return event->handled(); } return false; diff --git a/ui/aura/root_window.h b/ui/aura/root_window.h index a8c66df..0675566 100644 --- a/ui/aura/root_window.h +++ b/ui/aura/root_window.h @@ -55,7 +55,7 @@ class RootWindowObserver; class AURA_EXPORT RootWindow : public ui::CompositorDelegate, public ui::CompositorObserver, public Window, - public ui::EventDispatcher, + public ui::EventDispatcherDelegate, public ui::GestureEventHelper, public ui::LayerAnimationObserver, public aura::client::CaptureDelegate, @@ -280,11 +280,8 @@ class AURA_EXPORT RootWindow : public ui::CompositorDelegate, // sending exited and entered events as its value changes. void HandleMouseMoved(const ui::MouseEvent& event, Window* target); - void ProcessMouseEvent(Window* target, ui::MouseEvent* event); - void ProcessKeyEvent(Window* target, ui::KeyEvent* event); - void ProcessScrollEvent(Window* target, ui::ScrollEvent* event); - void ProcessTouchEvent(Window* target, ui::TouchEvent* event); - void ProcessGestureEvent(Window* target, ui::GestureEvent* event); + void ProcessEvent(Window* target, ui::Event* event); + bool ProcessGestures(ui::GestureRecognizer::Gestures* gestures); // Called when a Window is attached or detached from the RootWindow. @@ -303,7 +300,7 @@ class AURA_EXPORT RootWindow : public ui::CompositorDelegate, // |window| itself). void CleanupGestureRecognizerState(Window* window); - // Overridden from ui::EventDispatcher. + // Overridden from ui::EventDispatcherDelegate. virtual bool CanDispatchToTarget(EventTarget* target) OVERRIDE; // Overridden from ui::GestureEventHelper. |