Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(116)

Side by Side Diff: components/view_manager/event_dispatcher.cc

Issue 1344573002: Mandoline: Rename components/view_manager to components/mus (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/view_manager/event_dispatcher.h ('k') | components/view_manager/focus_controller.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "components/view_manager/event_dispatcher.h"
6
7 #include "components/view_manager/server_view.h"
8 #include "components/view_manager/view_coordinate_conversions.h"
9 #include "components/view_manager/view_locator.h"
10 #include "components/view_manager/view_tree_host_impl.h"
11 #include "ui/gfx/geometry/point.h"
12 #include "ui/gfx/geometry/point_f.h"
13
14 namespace view_manager {
15
16 EventDispatcher::EventDispatcher(ViewTreeHostImpl* view_tree_host)
17 : view_tree_host_(view_tree_host) {
18 }
19
20 EventDispatcher::~EventDispatcher() {
21 }
22
23 void EventDispatcher::AddAccelerator(uint32_t id,
24 mojo::KeyboardCode keyboard_code,
25 mojo::EventFlags flags) {
26 #if !defined(NDEBUG)
27 for (const auto& pair : accelerators_) {
28 DCHECK(pair.first != id);
29 DCHECK(pair.second.keyboard_code != keyboard_code ||
30 pair.second.flags != flags);
31 }
32 #endif
33 accelerators_.insert(Entry(id, Accelerator(keyboard_code, flags)));
34 }
35
36 void EventDispatcher::RemoveAccelerator(uint32_t id) {
37 auto it = accelerators_.find(id);
38 DCHECK(it != accelerators_.end());
39 accelerators_.erase(it);
40 }
41
42 void EventDispatcher::OnEvent(mojo::EventPtr event) {
43 if (event->action == mojo::EVENT_TYPE_KEY_PRESSED &&
44 !event->key_data->is_char) {
45 uint32_t accelerator = 0u;
46 if (FindAccelerator(*event, &accelerator)) {
47 view_tree_host_->OnAccelerator(accelerator, event.Pass());
48 return;
49 }
50 }
51
52 ServerView* target = FindEventTarget(event.get());
53 if (target) {
54 // Update focus on pointer-down.
55 if (event->action == mojo::EVENT_TYPE_POINTER_DOWN)
56 view_tree_host_->SetFocusedView(target);
57 view_tree_host_->DispatchInputEventToView(target, event.Pass());
58 }
59 }
60
61 bool EventDispatcher::FindAccelerator(const mojo::Event& event,
62 uint32_t* accelerator_id) {
63 DCHECK(event.key_data);
64 for (const auto& pair : accelerators_) {
65 if (pair.second.keyboard_code == event.key_data->windows_key_code &&
66 pair.second.flags == event.flags) {
67 *accelerator_id = pair.first;
68 return true;
69 }
70 }
71 return false;
72 }
73
74 ServerView* EventDispatcher::FindEventTarget(mojo::Event* event) {
75 ServerView* focused_view = view_tree_host_->GetFocusedView();
76 if (event->pointer_data) {
77 ServerView* root = view_tree_host_->root_view();
78 const gfx::Point root_point(static_cast<int>(event->pointer_data->x),
79 static_cast<int>(event->pointer_data->y));
80 ServerView* target = focused_view;
81 if (event->action == mojo::EVENT_TYPE_POINTER_DOWN || !target ||
82 !root->Contains(target)) {
83 target = FindDeepestVisibleView(root, root_point);
84 CHECK(target);
85 }
86 const gfx::PointF local_point(ConvertPointFBetweenViews(
87 root, target,
88 gfx::PointF(event->pointer_data->x, event->pointer_data->y)));
89 event->pointer_data->x = local_point.x();
90 event->pointer_data->y = local_point.y();
91 return target;
92 }
93
94 return focused_view;
95 }
96
97 } // namespace view_manager
OLDNEW
« no previous file with comments | « components/view_manager/event_dispatcher.h ('k') | components/view_manager/focus_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698