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 | |
37 if (event->pointer_data) { | 34 if (event->pointer_data) { |
38 const gfx::Point root_point(static_cast<int>(event->pointer_data->x), | 35 const gfx::Point root_point(static_cast<int>(event->pointer_data->x), |
39 static_cast<int>(event->pointer_data->y)); | 36 static_cast<int>(event->pointer_data->y)); |
40 ServerView* target = connection_manager_->GetFocusedView(); | 37 ServerView* target = connection_manager_->GetFocusedView(); |
41 ; | |
42 if (event->action == mojo::EVENT_TYPE_POINTER_DOWN || !target) { | 38 if (event->action == mojo::EVENT_TYPE_POINTER_DOWN || !target) { |
43 target = FindDeepestVisibleView(connection_manager_->root(), root_point); | 39 target = FindDeepestVisibleView(connection_manager_->root(), root_point); |
44 CHECK(target); | 40 CHECK(target); |
45 connection_manager_->SetFocusedView(target); | 41 connection_manager_->SetFocusedView(target); |
46 } | 42 } |
47 const gfx::PointF local_point(ConvertPointFBetweenViews( | 43 const gfx::PointF local_point(ConvertPointFBetweenViews( |
48 connection_manager_->root(), target, | 44 connection_manager_->root(), target, |
49 gfx::PointF(event->pointer_data->x, event->pointer_data->y))); | 45 gfx::PointF(event->pointer_data->x, event->pointer_data->y))); |
50 event->pointer_data->x = local_point.x(); | 46 event->pointer_data->x = local_point.x(); |
51 event->pointer_data->y = local_point.y(); | 47 event->pointer_data->y = local_point.y(); |
52 connection_manager_->DispatchInputEventToView(target, event.Pass()); | 48 connection_manager_->DispatchInputEventToView(target, event.Pass()); |
53 } else if (event->action == mojo::EVENT_TYPE_KEY_PRESSED && | 49 } else if (event->action == mojo::EVENT_TYPE_KEY_PRESSED && |
54 accelerators_.count(Accelerator(event->key_data->windows_key_code, | 50 accelerators_.count(Accelerator(event->key_data->windows_key_code, |
55 event->flags))) { | 51 event->flags))) { |
56 connection_manager_->view_manager_root_client()->OnAccelerator( | 52 connection_manager_->view_manager_root_client()->OnAccelerator( |
57 event.Pass()); | 53 event.Pass()); |
58 } else { | 54 } else { |
59 ServerView* focused_view = connection_manager_->GetFocusedView(); | 55 ServerView* focused_view = connection_manager_->GetFocusedView(); |
60 if (focused_view) | 56 if (focused_view) |
61 connection_manager_->DispatchInputEventToView(focused_view, event.Pass()); | 57 connection_manager_->DispatchInputEventToView(focused_view, event.Pass()); |
62 } | 58 } |
63 } | 59 } |
64 | 60 |
65 } // namespace view_manager | 61 } // namespace view_manager |
OLD | NEW |