OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/logging.h" | 6 #include "base/logging.h" |
7 #include "ui/aura/client/screen_position_client.h" | 7 #include "ui/aura/client/screen_position_client.h" |
8 #include "ui/aura/env.h" | 8 #include "ui/aura/env.h" |
9 #include "ui/aura/test/aura_test_utils.h" | 9 #include "ui/aura/test/aura_test_utils.h" |
10 #include "ui/aura/test/ui_controls_factory_aura.h" | 10 #include "ui/aura/test/ui_controls_factory_aura.h" |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 long screen_x, | 93 long screen_x, |
94 long screen_y, | 94 long screen_y, |
95 const base::Closure& closure) override { | 95 const base::Closure& closure) override { |
96 gfx::Point root_location(screen_x, screen_y); | 96 gfx::Point root_location(screen_x, screen_y); |
97 aura::client::ScreenPositionClient* screen_position_client = | 97 aura::client::ScreenPositionClient* screen_position_client = |
98 aura::client::GetScreenPositionClient(host_->window()); | 98 aura::client::GetScreenPositionClient(host_->window()); |
99 if (screen_position_client) { | 99 if (screen_position_client) { |
100 screen_position_client->ConvertPointFromScreen(host_->window(), | 100 screen_position_client->ConvertPointFromScreen(host_->window(), |
101 &root_location); | 101 &root_location); |
102 } | 102 } |
103 gfx::Point root_current_location = | 103 |
104 QueryLatestMousePositionRequestInHost(host_); | 104 gfx::Point host_location = root_location; |
105 host_->ConvertPointFromHost(&root_current_location); | 105 host_->ConvertPointToHost(&host_location); |
| 106 |
| 107 ui::EventType event_type; |
106 | 108 |
107 if (button_down_mask_) | 109 if (button_down_mask_) |
108 PostMouseEvent(ui::ET_MOUSE_DRAGGED, root_location, 0, 0); | 110 event_type = ui::ET_MOUSE_DRAGGED; |
109 else | 111 else |
110 PostMouseEvent(ui::ET_MOUSE_MOVED, root_location, 0, 0); | 112 event_type = ui::ET_MOUSE_MOVED; |
| 113 |
| 114 PostMouseEvent(event_type, host_location, 0, 0); |
111 | 115 |
112 RunClosureAfterAllPendingUIEvents(closure); | 116 RunClosureAfterAllPendingUIEvents(closure); |
113 return true; | 117 return true; |
114 } | 118 } |
115 virtual bool SendMouseEvents(ui_controls::MouseButton type, | 119 virtual bool SendMouseEvents(ui_controls::MouseButton type, |
116 int state) override { | 120 int state) override { |
117 return SendMouseEventsNotifyWhenDone(type, state, base::Closure()); | 121 return SendMouseEventsNotifyWhenDone(type, state, base::Closure()); |
118 } | 122 } |
119 virtual bool SendMouseEventsNotifyWhenDone( | 123 virtual bool SendMouseEventsNotifyWhenDone( |
120 ui_controls::MouseButton type, | 124 ui_controls::MouseButton type, |
121 int state, | 125 int state, |
122 const base::Closure& closure) override { | 126 const base::Closure& closure) override { |
123 gfx::Point loc = aura::Env::GetInstance()->last_mouse_location(); | 127 gfx::Point root_location = aura::Env::GetInstance()->last_mouse_location(); |
124 aura::client::ScreenPositionClient* screen_position_client = | 128 aura::client::ScreenPositionClient* screen_position_client = |
125 aura::client::GetScreenPositionClient(host_->window()); | 129 aura::client::GetScreenPositionClient(host_->window()); |
126 if (screen_position_client) { | 130 if (screen_position_client) { |
127 screen_position_client->ConvertPointFromScreen(host_->window(), &loc); | 131 screen_position_client->ConvertPointFromScreen(host_->window(), |
| 132 &root_location); |
128 } | 133 } |
| 134 |
| 135 gfx::Point host_location = root_location; |
| 136 host_->ConvertPointToHost(&host_location); |
| 137 |
129 int flag = 0; | 138 int flag = 0; |
130 | 139 |
131 switch (type) { | 140 switch (type) { |
132 case ui_controls::LEFT: | 141 case ui_controls::LEFT: |
133 flag = ui::EF_LEFT_MOUSE_BUTTON; | 142 flag = ui::EF_LEFT_MOUSE_BUTTON; |
134 break; | 143 break; |
135 case ui_controls::MIDDLE: | 144 case ui_controls::MIDDLE: |
136 flag = ui::EF_MIDDLE_MOUSE_BUTTON; | 145 flag = ui::EF_MIDDLE_MOUSE_BUTTON; |
137 break; | 146 break; |
138 case ui_controls::RIGHT: | 147 case ui_controls::RIGHT: |
139 flag = ui::EF_RIGHT_MOUSE_BUTTON; | 148 flag = ui::EF_RIGHT_MOUSE_BUTTON; |
140 break; | 149 break; |
141 default: | 150 default: |
142 NOTREACHED(); | 151 NOTREACHED(); |
143 break; | 152 break; |
144 } | 153 } |
145 | 154 |
146 if (state & ui_controls::DOWN) { | 155 if (state & ui_controls::DOWN) { |
147 button_down_mask_ |= flag; | 156 button_down_mask_ |= flag; |
148 PostMouseEvent(ui::ET_MOUSE_PRESSED, loc, button_down_mask_ | flag, flag); | 157 PostMouseEvent(ui::ET_MOUSE_PRESSED, host_location, |
| 158 button_down_mask_ | flag, flag); |
149 } | 159 } |
150 if (state & ui_controls::UP) { | 160 if (state & ui_controls::UP) { |
151 button_down_mask_ &= ~flag; | 161 button_down_mask_ &= ~flag; |
152 PostMouseEvent( | 162 PostMouseEvent(ui::ET_MOUSE_RELEASED, host_location, |
153 ui::ET_MOUSE_RELEASED, loc, button_down_mask_ | flag, flag); | 163 button_down_mask_ | flag, flag); |
154 } | 164 } |
155 | 165 |
156 RunClosureAfterAllPendingUIEvents(closure); | 166 RunClosureAfterAllPendingUIEvents(closure); |
157 return true; | 167 return true; |
158 } | 168 } |
159 virtual bool SendMouseClick(ui_controls::MouseButton type) override { | 169 virtual bool SendMouseClick(ui_controls::MouseButton type) override { |
160 return SendMouseEvents(type, ui_controls::UP | ui_controls::DOWN); | 170 return SendMouseEvents(type, ui_controls::UP | ui_controls::DOWN); |
161 } | 171 } |
162 virtual void RunClosureAfterAllPendingUIEvents( | 172 virtual void RunClosureAfterAllPendingUIEvents( |
163 const base::Closure& closure) override { | 173 const base::Closure& closure) override { |
(...skipping 24 matching lines...) Expand all Loading... |
188 ui::KeyboardCode key_code, | 198 ui::KeyboardCode key_code, |
189 int flags) { | 199 int flags) { |
190 // Do not rewrite injected events. See crbug.com/136465. | 200 // Do not rewrite injected events. See crbug.com/136465. |
191 flags |= ui::EF_FINAL; | 201 flags |= ui::EF_FINAL; |
192 | 202 |
193 ui::KeyEvent key_event(type, key_code, flags); | 203 ui::KeyEvent key_event(type, key_code, flags); |
194 SendEventToProcessor(&key_event); | 204 SendEventToProcessor(&key_event); |
195 } | 205 } |
196 | 206 |
197 void PostMouseEvent(ui::EventType type, | 207 void PostMouseEvent(ui::EventType type, |
198 const gfx::PointF& location, | 208 const gfx::PointF& host_location, |
199 int flags, | 209 int flags, |
200 int changed_button_flags) { | 210 int changed_button_flags) { |
201 base::MessageLoop::current()->PostTask( | 211 base::MessageLoop::current()->PostTask( |
202 FROM_HERE, | 212 FROM_HERE, |
203 base::Bind(&UIControlsOzone::PostMouseEventTask, | 213 base::Bind(&UIControlsOzone::PostMouseEventTask, base::Unretained(this), |
204 base::Unretained(this), | 214 type, host_location, flags, changed_button_flags)); |
205 type, | |
206 location, | |
207 flags, | |
208 changed_button_flags)); | |
209 } | 215 } |
210 | 216 |
211 void PostMouseEventTask(ui::EventType type, | 217 void PostMouseEventTask(ui::EventType type, |
212 const gfx::PointF& location, | 218 const gfx::PointF& host_location, |
213 int flags, | 219 int flags, |
214 int changed_button_flags) { | 220 int changed_button_flags) { |
215 ui::MouseEvent mouse_event( | 221 ui::MouseEvent mouse_event(type, host_location, host_location, flags, |
216 type, location, location, flags, changed_button_flags); | 222 changed_button_flags); |
217 | 223 |
218 // This hack is necessary to set the repeat count for clicks. | 224 // This hack is necessary to set the repeat count for clicks. |
219 ui::MouseEvent mouse_event2(&mouse_event); | 225 ui::MouseEvent mouse_event2(&mouse_event); |
220 | 226 |
221 SendEventToProcessor(&mouse_event2); | 227 SendEventToProcessor(&mouse_event2); |
222 } | 228 } |
223 | 229 |
224 WindowTreeHost* host_; | 230 WindowTreeHost* host_; |
225 | 231 |
226 // Mask of the mouse buttons currently down. | 232 // Mask of the mouse buttons currently down. |
227 unsigned button_down_mask_ = 0; | 233 unsigned button_down_mask_ = 0; |
228 | 234 |
229 DISALLOW_COPY_AND_ASSIGN(UIControlsOzone); | 235 DISALLOW_COPY_AND_ASSIGN(UIControlsOzone); |
230 }; | 236 }; |
231 | 237 |
232 } // namespace | 238 } // namespace |
233 | 239 |
234 ui_controls::UIControlsAura* CreateUIControlsAura(WindowTreeHost* host) { | 240 ui_controls::UIControlsAura* CreateUIControlsAura(WindowTreeHost* host) { |
235 return new UIControlsOzone(host); | 241 return new UIControlsOzone(host); |
236 } | 242 } |
237 | 243 |
238 } // namespace test | 244 } // namespace test |
239 } // namespace aura | 245 } // namespace aura |
OLD | NEW |