OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/view_manager/event_dispatcher.h" | 5 #include "components/view_manager/event_dispatcher.h" |
6 | 6 |
7 #include "components/view_manager/connection_manager.h" | 7 #include "components/view_manager/connection_manager.h" |
8 #include "components/view_manager/server_view.h" | 8 #include "components/view_manager/server_view.h" |
9 #include "components/view_manager/view_coordinate_conversions.h" | 9 #include "components/view_manager/view_coordinate_conversions.h" |
10 #include "components/view_manager/view_locator.h" | 10 #include "components/view_manager/view_locator.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 void EventDispatcher::AddAccelerator(mojo::KeyboardCode keyboard_code, | 23 void EventDispatcher::AddAccelerator(mojo::KeyboardCode keyboard_code, |
24 mojo::EventFlags flags) { | 24 mojo::EventFlags flags) { |
25 accelerators_.insert(Accelerator(keyboard_code, flags)); | 25 accelerators_.insert(Accelerator(keyboard_code, flags)); |
26 } | 26 } |
27 | 27 |
28 void EventDispatcher::RemoveAccelerator(mojo::KeyboardCode keyboard_code, | 28 void EventDispatcher::RemoveAccelerator(mojo::KeyboardCode keyboard_code, |
29 mojo::EventFlags flags) { | 29 mojo::EventFlags flags) { |
30 accelerators_.erase(Accelerator(keyboard_code, flags)); | 30 accelerators_.erase(Accelerator(keyboard_code, flags)); |
31 } | 31 } |
32 | 32 |
33 void EventDispatcher::OnEvent(mojo::EventPtr event) { | 33 void EventDispatcher::OnEvent(mojo::EventPtr event, |
| 34 const OnEventCallback& callback) { |
| 35 callback.Run(); |
| 36 |
34 if (event->pointer_data) { | 37 if (event->pointer_data) { |
35 const gfx::Point root_point(static_cast<int>(event->pointer_data->x), | 38 const gfx::Point root_point(static_cast<int>(event->pointer_data->x), |
36 static_cast<int>(event->pointer_data->y)); | 39 static_cast<int>(event->pointer_data->y)); |
37 ServerView* target = connection_manager_->GetFocusedView(); | 40 ServerView* target = connection_manager_->GetFocusedView(); |
| 41 ; |
38 if (event->action == mojo::EVENT_TYPE_POINTER_DOWN || !target) { | 42 if (event->action == mojo::EVENT_TYPE_POINTER_DOWN || !target) { |
39 target = FindDeepestVisibleView(connection_manager_->root(), root_point); | 43 target = FindDeepestVisibleView(connection_manager_->root(), root_point); |
40 CHECK(target); | 44 CHECK(target); |
41 connection_manager_->SetFocusedView(target); | 45 connection_manager_->SetFocusedView(target); |
42 } | 46 } |
43 const gfx::PointF local_point(ConvertPointFBetweenViews( | 47 const gfx::PointF local_point(ConvertPointFBetweenViews( |
44 connection_manager_->root(), target, | 48 connection_manager_->root(), target, |
45 gfx::PointF(event->pointer_data->x, event->pointer_data->y))); | 49 gfx::PointF(event->pointer_data->x, event->pointer_data->y))); |
46 event->pointer_data->x = local_point.x(); | 50 event->pointer_data->x = local_point.x(); |
47 event->pointer_data->y = local_point.y(); | 51 event->pointer_data->y = local_point.y(); |
48 connection_manager_->DispatchInputEventToView(target, event.Pass()); | 52 connection_manager_->DispatchInputEventToView(target, event.Pass()); |
49 } else if (event->action == mojo::EVENT_TYPE_KEY_PRESSED && | 53 } else if (event->action == mojo::EVENT_TYPE_KEY_PRESSED && |
50 accelerators_.count(Accelerator(event->key_data->windows_key_code, | 54 accelerators_.count(Accelerator(event->key_data->windows_key_code, |
51 event->flags))) { | 55 event->flags))) { |
52 connection_manager_->view_manager_root_client()->OnAccelerator( | 56 connection_manager_->view_manager_root_client()->OnAccelerator( |
53 event.Pass()); | 57 event.Pass()); |
54 } else { | 58 } else { |
55 ServerView* focused_view = connection_manager_->GetFocusedView(); | 59 ServerView* focused_view = connection_manager_->GetFocusedView(); |
56 if (focused_view) | 60 if (focused_view) |
57 connection_manager_->DispatchInputEventToView(focused_view, event.Pass()); | 61 connection_manager_->DispatchInputEventToView(focused_view, event.Pass()); |
58 } | 62 } |
59 } | 63 } |
60 | 64 |
61 } // namespace view_manager | 65 } // namespace view_manager |
OLD | NEW |