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

Side by Side Diff: ui/aura/test/event_generator.cc

Issue 406413004: Cleanups for aura/test/event_generator.h (resolve TODOs) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase at r285842 Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « ui/aura/test/event_generator.h ('k') | ui/aura/test/event_generator_delegate_aura.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 (c) 2012 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 "ui/aura/test/event_generator.h"
6
7 #include "ui/aura/client/screen_position_client.h"
8 #include "ui/aura/window_event_dispatcher.h"
9 #include "ui/aura/window_tree_host.h"
10
11 namespace aura {
12 namespace test {
13 namespace {
14
15 class DefaultEventGeneratorDelegate : public EventGeneratorDelegateAura {
16 public:
17 explicit DefaultEventGeneratorDelegate(Window* root_window)
18 : root_window_(root_window) {}
19 virtual ~DefaultEventGeneratorDelegate() {}
20
21 // EventGeneratorDelegateAura overrides:
22 virtual WindowTreeHost* GetHostAt(const gfx::Point& point) const OVERRIDE {
23 return root_window_->GetHost();
24 }
25
26 virtual client::ScreenPositionClient* GetScreenPositionClient(
27 const aura::Window* window) const OVERRIDE {
28 return NULL;
29 }
30
31 private:
32 Window* root_window_;
33
34 DISALLOW_COPY_AND_ASSIGN(DefaultEventGeneratorDelegate);
35 };
36
37 const Window* WindowFromTarget(const ui::EventTarget* event_target) {
38 return static_cast<const Window*>(event_target);
39 }
40
41 } // namespace
42
43 EventGeneratorDelegateAura::EventGeneratorDelegateAura() {
44 }
45
46 EventGeneratorDelegateAura::~EventGeneratorDelegateAura() {
47 }
48
49 ui::EventTarget* EventGeneratorDelegateAura::GetTargetAt(
50 const gfx::Point& location) {
51 return GetHostAt(location)->window();
52 }
53
54 ui::EventSource* EventGeneratorDelegateAura::GetEventSource(
55 ui::EventTarget* target) {
56 return static_cast<Window*>(target)->GetHost()->GetEventSource();
57 }
58
59 gfx::Point EventGeneratorDelegateAura::CenterOfTarget(
60 const ui::EventTarget* target) const {
61 gfx::Point center =
62 gfx::Rect(WindowFromTarget(target)->bounds().size()).CenterPoint();
63 ConvertPointFromTarget(target, &center);
64 return center;
65 }
66
67 gfx::Point EventGeneratorDelegateAura::CenterOfWindow(
68 gfx::NativeWindow window) const {
69 return CenterOfTarget(window);
70 }
71
72 void EventGeneratorDelegateAura::ConvertPointFromTarget(
73 const ui::EventTarget* event_target,
74 gfx::Point* point) const {
75 DCHECK(point);
76 const Window* target = WindowFromTarget(event_target);
77 aura::client::ScreenPositionClient* client = GetScreenPositionClient(target);
78 if (client)
79 client->ConvertPointToScreen(target, point);
80 else
81 aura::Window::ConvertPointToTarget(target, target->GetRootWindow(), point);
82 }
83
84 void EventGeneratorDelegateAura::ConvertPointToTarget(
85 const ui::EventTarget* event_target,
86 gfx::Point* point) const {
87 DCHECK(point);
88 const Window* target = WindowFromTarget(event_target);
89 aura::client::ScreenPositionClient* client = GetScreenPositionClient(target);
90 if (client)
91 client->ConvertPointFromScreen(target, point);
92 else
93 aura::Window::ConvertPointToTarget(target->GetRootWindow(), target, point);
94 }
95
96 void EventGeneratorDelegateAura::ConvertPointFromHost(
97 const ui::EventTarget* hosted_target,
98 gfx::Point* point) const {
99 const Window* window = WindowFromTarget(hosted_target);
100 window->GetHost()->ConvertPointFromHost(point);
101 }
102
103 } // namespace test
104 } // namespace aura
105
106 namespace ui {
107 namespace test {
108
109 // static
110 EventGeneratorDelegate* EventGenerator::CreateDefaultPlatformDelegate(
111 EventGenerator* owner,
112 gfx::NativeWindow root_window,
113 gfx::NativeWindow window) {
114 return new aura::test::DefaultEventGeneratorDelegate(root_window);
115 }
116
117 } // namespace test
118 } // namespace ui
OLDNEW
« no previous file with comments | « ui/aura/test/event_generator.h ('k') | ui/aura/test/event_generator_delegate_aura.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698