| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/aura/window_event_dispatcher.h" | 5 #include "ui/aura/window_event_dispatcher.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/debug/trace_event.h" | 11 #include "base/debug/trace_event.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "ui/aura/client/capture_client.h" | 14 #include "ui/aura/client/capture_client.h" |
| 15 #include "ui/aura/client/cursor_client.h" | 15 #include "ui/aura/client/cursor_client.h" |
| 16 #include "ui/aura/client/event_client.h" | 16 #include "ui/aura/client/event_client.h" |
| 17 #include "ui/aura/client/focus_client.h" | 17 #include "ui/aura/client/focus_client.h" |
| 18 #include "ui/aura/client/screen_position_client.h" | 18 #include "ui/aura/client/screen_position_client.h" |
| 19 #include "ui/aura/env.h" | 19 #include "ui/aura/env.h" |
| 20 #include "ui/aura/root_window_observer.h" | 20 #include "ui/aura/root_window_observer.h" |
| 21 #include "ui/aura/window.h" | 21 #include "ui/aura/window.h" |
| 22 #include "ui/aura/window_delegate.h" | 22 #include "ui/aura/window_delegate.h" |
| 23 #include "ui/aura/window_targeter.h" | 23 #include "ui/aura/window_targeter.h" |
| 24 #include "ui/aura/window_tracker.h" | 24 #include "ui/aura/window_tracker.h" |
| 25 #include "ui/aura/window_tree_host.h" | 25 #include "ui/aura/window_tree_host.h" |
| 26 #include "ui/base/hit_test.h" | 26 #include "ui/base/hit_test.h" |
| 27 #include "ui/base/view_prop.h" | |
| 28 #include "ui/compositor/dip_util.h" | 27 #include "ui/compositor/dip_util.h" |
| 29 #include "ui/compositor/layer.h" | 28 #include "ui/compositor/layer.h" |
| 30 #include "ui/compositor/layer_animator.h" | 29 #include "ui/compositor/layer_animator.h" |
| 31 #include "ui/events/event.h" | 30 #include "ui/events/event.h" |
| 32 #include "ui/events/gestures/gesture_recognizer.h" | 31 #include "ui/events/gestures/gesture_recognizer.h" |
| 33 #include "ui/events/gestures/gesture_types.h" | 32 #include "ui/events/gestures/gesture_types.h" |
| 34 #include "ui/gfx/screen.h" | 33 #include "ui/gfx/screen.h" |
| 35 | 34 |
| 36 using std::vector; | 35 using std::vector; |
| 37 | 36 |
| 38 typedef ui::EventDispatchDetails DispatchDetails; | 37 typedef ui::EventDispatchDetails DispatchDetails; |
| 39 | 38 |
| 40 namespace aura { | 39 namespace aura { |
| 41 | 40 |
| 42 namespace { | 41 namespace { |
| 43 | 42 |
| 44 const char kRootWindowForAcceleratedWidget[] = | |
| 45 "__AURA_ROOT_WINDOW_ACCELERATED_WIDGET__"; | |
| 46 | |
| 47 // Returns true if |target| has a non-client (frame) component at |location|, | 43 // Returns true if |target| has a non-client (frame) component at |location|, |
| 48 // in window coordinates. | 44 // in window coordinates. |
| 49 bool IsNonClientLocation(Window* target, const gfx::Point& location) { | 45 bool IsNonClientLocation(Window* target, const gfx::Point& location) { |
| 50 if (!target->delegate()) | 46 if (!target->delegate()) |
| 51 return false; | 47 return false; |
| 52 int hit_test_code = target->delegate()->GetNonClientComponent(location); | 48 int hit_test_code = target->delegate()->GetNonClientComponent(location); |
| 53 return hit_test_code != HTCLIENT && hit_test_code != HTNOWHERE; | 49 return hit_test_code != HTCLIENT && hit_test_code != HTNOWHERE; |
| 54 } | 50 } |
| 55 | 51 |
| 56 Window* ConsumerToWindow(ui::GestureConsumer* consumer) { | 52 Window* ConsumerToWindow(ui::GestureConsumer* consumer) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 79 return true; | 75 return true; |
| 80 return false; | 76 return false; |
| 81 } | 77 } |
| 82 | 78 |
| 83 } // namespace | 79 } // namespace |
| 84 | 80 |
| 85 //////////////////////////////////////////////////////////////////////////////// | 81 //////////////////////////////////////////////////////////////////////////////// |
| 86 // WindowEventDispatcher, public: | 82 // WindowEventDispatcher, public: |
| 87 | 83 |
| 88 WindowEventDispatcher::WindowEventDispatcher(WindowTreeHost* host) | 84 WindowEventDispatcher::WindowEventDispatcher(WindowTreeHost* host) |
| 89 : window_(new Window(NULL)), | 85 : host_(host), |
| 90 host_(host), | |
| 91 touch_ids_down_(0), | 86 touch_ids_down_(0), |
| 92 mouse_pressed_handler_(NULL), | 87 mouse_pressed_handler_(NULL), |
| 93 mouse_moved_handler_(NULL), | 88 mouse_moved_handler_(NULL), |
| 94 event_dispatch_target_(NULL), | 89 event_dispatch_target_(NULL), |
| 95 old_dispatch_target_(NULL), | 90 old_dispatch_target_(NULL), |
| 96 synthesize_mouse_move_(false), | 91 synthesize_mouse_move_(false), |
| 97 move_hold_count_(0), | 92 move_hold_count_(0), |
| 98 dispatching_held_event_(false), | 93 dispatching_held_event_(false), |
| 99 repost_event_factory_(this), | 94 repost_event_factory_(this), |
| 100 held_event_factory_(this) { | 95 held_event_factory_(this) { |
| 101 window()->Init(WINDOW_LAYER_NOT_DRAWN); | |
| 102 window()->set_dispatcher(this); | |
| 103 window()->SetName("RootWindow"); | |
| 104 window()->SetEventTargeter( | |
| 105 scoped_ptr<ui::EventTargeter>(new WindowTargeter())); | |
| 106 | |
| 107 prop_.reset(new ui::ViewProp(host_->GetAcceleratedWidget(), | |
| 108 kRootWindowForAcceleratedWidget, | |
| 109 this)); | |
| 110 ui::GestureRecognizer::Get()->AddGestureEventHelper(this); | 96 ui::GestureRecognizer::Get()->AddGestureEventHelper(this); |
| 111 } | 97 } |
| 112 | 98 |
| 113 WindowEventDispatcher::~WindowEventDispatcher() { | 99 WindowEventDispatcher::~WindowEventDispatcher() { |
| 114 TRACE_EVENT0("shutdown", "WindowEventDispatcher::Destructor"); | 100 TRACE_EVENT0("shutdown", "WindowEventDispatcher::Destructor"); |
| 115 | |
| 116 ui::GestureRecognizer::Get()->RemoveGestureEventHelper(this); | 101 ui::GestureRecognizer::Get()->RemoveGestureEventHelper(this); |
| 117 | |
| 118 // An observer may have been added by an animation on the | |
| 119 // WindowEventDispatcher. | |
| 120 window()->layer()->GetAnimator()->RemoveObserver(this); | |
| 121 | |
| 122 // Destroy child windows while we're still valid. This is also done by | |
| 123 // ~Window, but by that time any calls to virtual methods overriden here (such | |
| 124 // as GetRootWindow()) result in Window's implementation. By destroying here | |
| 125 // we ensure GetRootWindow() still returns this. | |
| 126 window()->RemoveOrDestroyChildren(); | |
| 127 window()->set_dispatcher(NULL); | |
| 128 } | |
| 129 | |
| 130 // static | |
| 131 WindowEventDispatcher* WindowEventDispatcher::GetForAcceleratedWidget( | |
| 132 gfx::AcceleratedWidget widget) { | |
| 133 return reinterpret_cast<WindowEventDispatcher*>( | |
| 134 ui::ViewProp::GetValue(widget, kRootWindowForAcceleratedWidget)); | |
| 135 } | 102 } |
| 136 | 103 |
| 137 void WindowEventDispatcher::PrepareForShutdown() { | 104 void WindowEventDispatcher::PrepareForShutdown() { |
| 138 host_->PrepareForShutdown(); | 105 host_->PrepareForShutdown(); |
| 139 // discard synthesize event request as well. | 106 // discard synthesize event request as well. |
| 140 synthesize_mouse_move_ = false; | 107 synthesize_mouse_move_ = false; |
| 141 } | 108 } |
| 142 | 109 |
| 143 void WindowEventDispatcher::RepostEvent(const ui::LocatedEvent& event) { | 110 void WindowEventDispatcher::RepostEvent(const ui::LocatedEvent& event) { |
| 144 DCHECK(event.type() == ui::ET_MOUSE_PRESSED || | 111 DCHECK(event.type() == ui::ET_MOUSE_PRESSED || |
| (...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 911 break; | 878 break; |
| 912 | 879 |
| 913 default: | 880 default: |
| 914 NOTREACHED(); | 881 NOTREACHED(); |
| 915 break; | 882 break; |
| 916 } | 883 } |
| 917 PreDispatchLocatedEvent(target, event); | 884 PreDispatchLocatedEvent(target, event); |
| 918 } | 885 } |
| 919 | 886 |
| 920 } // namespace aura | 887 } // namespace aura |
| OLD | NEW |