Inline NetLog IPv6 reachability events.
[chromium-blink-merge.git] / components / view_manager / event_dispatcher.cc
blob6cc8b8580eaf8ca531854026de3d1004bed3bd26
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.
5 #include "components/view_manager/event_dispatcher.h"
7 #include "components/view_manager/connection_manager.h"
8 #include "components/view_manager/server_view.h"
9 #include "components/view_manager/view_coordinate_conversions.h"
10 #include "components/view_manager/view_locator.h"
11 #include "ui/gfx/geometry/point.h"
12 #include "ui/gfx/geometry/point_f.h"
14 namespace view_manager {
16 EventDispatcher::EventDispatcher(ConnectionManager* connection_manager)
17 : connection_manager_(connection_manager) {
20 EventDispatcher::~EventDispatcher() {
23 void EventDispatcher::AddAccelerator(mojo::KeyboardCode keyboard_code,
24 mojo::EventFlags flags) {
25 accelerators_.insert(Accelerator(keyboard_code, flags));
28 void EventDispatcher::RemoveAccelerator(mojo::KeyboardCode keyboard_code,
29 mojo::EventFlags flags) {
30 accelerators_.erase(Accelerator(keyboard_code, flags));
33 void EventDispatcher::OnEvent(mojo::EventPtr event,
34 const OnEventCallback& callback) {
35 callback.Run();
37 if (event->pointer_data) {
38 const gfx::Point root_point(static_cast<int>(event->pointer_data->x),
39 static_cast<int>(event->pointer_data->y));
40 ServerView* target = connection_manager_->GetFocusedView();
42 if (event->action == mojo::EVENT_TYPE_POINTER_DOWN || !target) {
43 target = FindDeepestVisibleView(connection_manager_->root(), root_point);
44 CHECK(target);
45 connection_manager_->SetFocusedView(target);
47 const gfx::PointF local_point(ConvertPointFBetweenViews(
48 connection_manager_->root(), target,
49 gfx::PointF(event->pointer_data->x, event->pointer_data->y)));
50 event->pointer_data->x = local_point.x();
51 event->pointer_data->y = local_point.y();
52 connection_manager_->DispatchInputEventToView(target, event.Pass());
53 } else if (event->action == mojo::EVENT_TYPE_KEY_PRESSED &&
54 accelerators_.count(Accelerator(event->key_data->windows_key_code,
55 event->flags))) {
56 connection_manager_->wm_internal()->OnAccelerator(event.Pass());
57 } else {
58 ServerView* focused_view = connection_manager_->GetFocusedView();
59 if (focused_view)
60 connection_manager_->DispatchInputEventToView(focused_view, event.Pass());
64 } // namespace view_manager