Chromium Code Reviews| 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 gfx::Point native_screen_location = root_location; | |
| 108 host_->ConvertPointToNativeScreen(&native_screen_location); | |
| 106 | 109 |
| 107 if (button_down_mask_) | 110 if (button_down_mask_) |
| 108 PostMouseEvent(ui::ET_MOUSE_DRAGGED, root_location, 0, 0); | 111 PostMouseEvent(ui::ET_MOUSE_DRAGGED, host_location, |
| 112 native_screen_location, 0, 0); | |
| 109 else | 113 else |
| 110 PostMouseEvent(ui::ET_MOUSE_MOVED, root_location, 0, 0); | 114 PostMouseEvent(ui::ET_MOUSE_MOVED, host_location, native_screen_location, |
| 115 0, 0); | |
| 111 | 116 |
| 112 RunClosureAfterAllPendingUIEvents(closure); | 117 RunClosureAfterAllPendingUIEvents(closure); |
| 113 return true; | 118 return true; |
| 114 } | 119 } |
| 115 virtual bool SendMouseEvents(ui_controls::MouseButton type, | 120 virtual bool SendMouseEvents(ui_controls::MouseButton type, |
| 116 int state) override { | 121 int state) override { |
| 117 return SendMouseEventsNotifyWhenDone(type, state, base::Closure()); | 122 return SendMouseEventsNotifyWhenDone(type, state, base::Closure()); |
| 118 } | 123 } |
| 119 virtual bool SendMouseEventsNotifyWhenDone( | 124 virtual bool SendMouseEventsNotifyWhenDone( |
| 120 ui_controls::MouseButton type, | 125 ui_controls::MouseButton type, |
| 121 int state, | 126 int state, |
| 122 const base::Closure& closure) override { | 127 const base::Closure& closure) override { |
| 123 gfx::Point loc = aura::Env::GetInstance()->last_mouse_location(); | 128 gfx::Point root_location = aura::Env::GetInstance()->last_mouse_location(); |
| 124 aura::client::ScreenPositionClient* screen_position_client = | 129 aura::client::ScreenPositionClient* screen_position_client = |
| 125 aura::client::GetScreenPositionClient(host_->window()); | 130 aura::client::GetScreenPositionClient(host_->window()); |
| 126 if (screen_position_client) { | 131 if (screen_position_client) { |
| 127 screen_position_client->ConvertPointFromScreen(host_->window(), &loc); | 132 screen_position_client->ConvertPointFromScreen(host_->window(), |
| 133 &root_location); | |
| 128 } | 134 } |
| 135 | |
| 136 gfx::Point host_location = root_location; | |
| 137 host_->ConvertPointToHost(&host_location); | |
| 138 | |
| 139 gfx::Point native_screen_location = root_location; | |
| 140 host_->ConvertPointToNativeScreen(&native_screen_location); | |
| 141 | |
| 129 int flag = 0; | 142 int flag = 0; |
| 130 | 143 |
| 131 switch (type) { | 144 switch (type) { |
| 132 case ui_controls::LEFT: | 145 case ui_controls::LEFT: |
| 133 flag = ui::EF_LEFT_MOUSE_BUTTON; | 146 flag = ui::EF_LEFT_MOUSE_BUTTON; |
| 134 break; | 147 break; |
| 135 case ui_controls::MIDDLE: | 148 case ui_controls::MIDDLE: |
| 136 flag = ui::EF_MIDDLE_MOUSE_BUTTON; | 149 flag = ui::EF_MIDDLE_MOUSE_BUTTON; |
| 137 break; | 150 break; |
| 138 case ui_controls::RIGHT: | 151 case ui_controls::RIGHT: |
| 139 flag = ui::EF_RIGHT_MOUSE_BUTTON; | 152 flag = ui::EF_RIGHT_MOUSE_BUTTON; |
| 140 break; | 153 break; |
| 141 default: | 154 default: |
| 142 NOTREACHED(); | 155 NOTREACHED(); |
| 143 break; | 156 break; |
| 144 } | 157 } |
| 145 | 158 |
| 146 if (state & ui_controls::DOWN) { | 159 if (state & ui_controls::DOWN) { |
| 147 button_down_mask_ |= flag; | 160 button_down_mask_ |= flag; |
| 148 PostMouseEvent(ui::ET_MOUSE_PRESSED, loc, button_down_mask_ | flag, flag); | 161 PostMouseEvent(ui::ET_MOUSE_PRESSED, host_location, |
| 162 native_screen_location, button_down_mask_ | flag, flag); | |
| 149 } | 163 } |
| 150 if (state & ui_controls::UP) { | 164 if (state & ui_controls::UP) { |
| 151 button_down_mask_ &= ~flag; | 165 button_down_mask_ &= ~flag; |
| 152 PostMouseEvent( | 166 PostMouseEvent(ui::ET_MOUSE_RELEASED, host_location, |
| 153 ui::ET_MOUSE_RELEASED, loc, button_down_mask_ | flag, flag); | 167 native_screen_location, button_down_mask_ | flag, flag); |
| 154 } | 168 } |
| 155 | 169 |
| 156 RunClosureAfterAllPendingUIEvents(closure); | 170 RunClosureAfterAllPendingUIEvents(closure); |
| 157 return true; | 171 return true; |
| 158 } | 172 } |
| 159 virtual bool SendMouseClick(ui_controls::MouseButton type) override { | 173 virtual bool SendMouseClick(ui_controls::MouseButton type) override { |
| 160 return SendMouseEvents(type, ui_controls::UP | ui_controls::DOWN); | 174 return SendMouseEvents(type, ui_controls::UP | ui_controls::DOWN); |
| 161 } | 175 } |
| 162 virtual void RunClosureAfterAllPendingUIEvents( | 176 virtual void RunClosureAfterAllPendingUIEvents( |
| 163 const base::Closure& closure) override { | 177 const base::Closure& closure) override { |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 188 ui::KeyboardCode key_code, | 202 ui::KeyboardCode key_code, |
| 189 int flags) { | 203 int flags) { |
| 190 // Do not rewrite injected events. See crbug.com/136465. | 204 // Do not rewrite injected events. See crbug.com/136465. |
| 191 flags |= ui::EF_FINAL; | 205 flags |= ui::EF_FINAL; |
| 192 | 206 |
| 193 ui::KeyEvent key_event(type, key_code, flags); | 207 ui::KeyEvent key_event(type, key_code, flags); |
| 194 SendEventToProcessor(&key_event); | 208 SendEventToProcessor(&key_event); |
| 195 } | 209 } |
| 196 | 210 |
| 197 void PostMouseEvent(ui::EventType type, | 211 void PostMouseEvent(ui::EventType type, |
| 198 const gfx::PointF& location, | 212 const gfx::PointF& host_location, |
| 213 const gfx::PointF& native_screen_location, | |
| 199 int flags, | 214 int flags, |
| 200 int changed_button_flags) { | 215 int changed_button_flags) { |
| 201 base::MessageLoop::current()->PostTask( | 216 base::MessageLoop::current()->PostTask( |
| 202 FROM_HERE, | 217 FROM_HERE, |
| 203 base::Bind(&UIControlsOzone::PostMouseEventTask, | 218 base::Bind(&UIControlsOzone::PostMouseEventTask, base::Unretained(this), |
| 204 base::Unretained(this), | 219 type, host_location, native_screen_location, flags, |
| 205 type, | |
| 206 location, | |
| 207 flags, | |
| 208 changed_button_flags)); | 220 changed_button_flags)); |
| 209 } | 221 } |
| 210 | 222 |
| 211 void PostMouseEventTask(ui::EventType type, | 223 void PostMouseEventTask(ui::EventType type, |
| 212 const gfx::PointF& location, | 224 const gfx::PointF& host_location, |
| 225 const gfx::PointF& native_screen_location, | |
| 213 int flags, | 226 int flags, |
| 214 int changed_button_flags) { | 227 int changed_button_flags) { |
| 215 ui::MouseEvent mouse_event( | 228 ui::MouseEvent mouse_event(type, host_location, native_screen_location, |
|
sadrul
2014/12/03 21:33:56
Confusing as it is, this is actually not right. Lo
| |
| 216 type, location, location, flags, changed_button_flags); | 229 flags, changed_button_flags); |
| 217 | 230 |
| 218 // This hack is necessary to set the repeat count for clicks. | 231 // This hack is necessary to set the repeat count for clicks. |
| 219 ui::MouseEvent mouse_event2(&mouse_event); | 232 ui::MouseEvent mouse_event2(&mouse_event); |
| 220 | 233 |
| 221 SendEventToProcessor(&mouse_event2); | 234 SendEventToProcessor(&mouse_event2); |
| 222 } | 235 } |
| 223 | 236 |
| 224 WindowTreeHost* host_; | 237 WindowTreeHost* host_; |
| 225 | 238 |
| 226 // Mask of the mouse buttons currently down. | 239 // Mask of the mouse buttons currently down. |
| 227 unsigned button_down_mask_ = 0; | 240 unsigned button_down_mask_ = 0; |
| 228 | 241 |
| 229 DISALLOW_COPY_AND_ASSIGN(UIControlsOzone); | 242 DISALLOW_COPY_AND_ASSIGN(UIControlsOzone); |
| 230 }; | 243 }; |
| 231 | 244 |
| 232 } // namespace | 245 } // namespace |
| 233 | 246 |
| 234 ui_controls::UIControlsAura* CreateUIControlsAura(WindowTreeHost* host) { | 247 ui_controls::UIControlsAura* CreateUIControlsAura(WindowTreeHost* host) { |
| 235 return new UIControlsOzone(host); | 248 return new UIControlsOzone(host); |
| 236 } | 249 } |
| 237 | 250 |
| 238 } // namespace test | 251 } // namespace test |
| 239 } // namespace aura | 252 } // namespace aura |
| OLD | NEW |