OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "ui/aura/remote_root_window_host_win.h" | 5 #include "ui/aura/remote_root_window_host_win.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "ipc/ipc_message.h" | 12 #include "ipc/ipc_message.h" |
13 #include "ipc/ipc_sender.h" | 13 #include "ipc/ipc_sender.h" |
14 #include "ui/aura/client/cursor_client.h" | 14 #include "ui/aura/client/cursor_client.h" |
15 #include "ui/aura/root_window.h" | 15 #include "ui/aura/root_window.h" |
16 #include "ui/base/cursor/cursor_loader_win.h" | 16 #include "ui/base/cursor/cursor_loader_win.h" |
17 #include "ui/events/event_utils.h" | 17 #include "ui/events/event_utils.h" |
18 #include "ui/events/keycodes/keyboard_code_conversion_win.h" | 18 #include "ui/events/keycodes/keyboard_code_conversion_win.h" |
19 #include "ui/base/view_prop.h" | 19 #include "ui/base/view_prop.h" |
20 #include "ui/gfx/insets.h" | 20 #include "ui/gfx/insets.h" |
21 #include "ui/metro_viewer/metro_viewer_messages.h" | 21 #include "ui/metro_viewer/metro_viewer_messages.h" |
22 | 22 |
23 namespace aura { | 23 namespace aura { |
24 | 24 |
25 namespace { | 25 namespace { |
26 | 26 |
27 const char* kWindowTreeHostWinKey = "__AURA_REMOTE_ROOT_WINDOW_HOST_WIN__"; | 27 const char* kRootWindowHostWinKey = "__AURA_REMOTE_ROOT_WINDOW_HOST_WIN__"; |
28 | 28 |
29 // Sets the keystate for the virtual key passed in to down or up. | 29 // Sets the keystate for the virtual key passed in to down or up. |
30 void SetKeyState(uint8* key_states, bool key_down, uint32 virtual_key_code) { | 30 void SetKeyState(uint8* key_states, bool key_down, uint32 virtual_key_code) { |
31 DCHECK(key_states); | 31 DCHECK(key_states); |
32 | 32 |
33 if (key_down) | 33 if (key_down) |
34 key_states[virtual_key_code] |= 0x80; | 34 key_states[virtual_key_code] |= 0x80; |
35 else | 35 else |
36 key_states[virtual_key_code] &= 0x7F; | 36 key_states[virtual_key_code] &= 0x7F; |
37 } | 37 } |
(...skipping 16 matching lines...) Expand all Loading... |
54 ::SetKeyboardState(keyboard_state); | 54 ::SetKeyboardState(keyboard_state); |
55 } | 55 } |
56 | 56 |
57 } // namespace | 57 } // namespace |
58 | 58 |
59 void HandleOpenFile(const base::string16& title, | 59 void HandleOpenFile(const base::string16& title, |
60 const base::FilePath& default_path, | 60 const base::FilePath& default_path, |
61 const base::string16& filter, | 61 const base::string16& filter, |
62 const OpenFileCompletion& on_success, | 62 const OpenFileCompletion& on_success, |
63 const FileSelectionCanceled& on_failure) { | 63 const FileSelectionCanceled& on_failure) { |
64 DCHECK(aura::RemoteWindowTreeHostWin::Instance()); | 64 DCHECK(aura::RemoteRootWindowHostWin::Instance()); |
65 aura::RemoteWindowTreeHostWin::Instance()->HandleOpenFile(title, | 65 aura::RemoteRootWindowHostWin::Instance()->HandleOpenFile(title, |
66 default_path, | 66 default_path, |
67 filter, | 67 filter, |
68 on_success, | 68 on_success, |
69 on_failure); | 69 on_failure); |
70 } | 70 } |
71 | 71 |
72 void HandleOpenMultipleFiles(const base::string16& title, | 72 void HandleOpenMultipleFiles(const base::string16& title, |
73 const base::FilePath& default_path, | 73 const base::FilePath& default_path, |
74 const base::string16& filter, | 74 const base::string16& filter, |
75 const OpenMultipleFilesCompletion& on_success, | 75 const OpenMultipleFilesCompletion& on_success, |
76 const FileSelectionCanceled& on_failure) { | 76 const FileSelectionCanceled& on_failure) { |
77 DCHECK(aura::RemoteWindowTreeHostWin::Instance()); | 77 DCHECK(aura::RemoteRootWindowHostWin::Instance()); |
78 aura::RemoteWindowTreeHostWin::Instance()->HandleOpenMultipleFiles( | 78 aura::RemoteRootWindowHostWin::Instance()->HandleOpenMultipleFiles( |
79 title, | 79 title, |
80 default_path, | 80 default_path, |
81 filter, | 81 filter, |
82 on_success, | 82 on_success, |
83 on_failure); | 83 on_failure); |
84 } | 84 } |
85 | 85 |
86 void HandleSaveFile(const base::string16& title, | 86 void HandleSaveFile(const base::string16& title, |
87 const base::FilePath& default_path, | 87 const base::FilePath& default_path, |
88 const base::string16& filter, | 88 const base::string16& filter, |
89 int filter_index, | 89 int filter_index, |
90 const base::string16& default_extension, | 90 const base::string16& default_extension, |
91 const SaveFileCompletion& on_success, | 91 const SaveFileCompletion& on_success, |
92 const FileSelectionCanceled& on_failure) { | 92 const FileSelectionCanceled& on_failure) { |
93 DCHECK(aura::RemoteWindowTreeHostWin::Instance()); | 93 DCHECK(aura::RemoteRootWindowHostWin::Instance()); |
94 aura::RemoteWindowTreeHostWin::Instance()->HandleSaveFile(title, | 94 aura::RemoteRootWindowHostWin::Instance()->HandleSaveFile(title, |
95 default_path, | 95 default_path, |
96 filter, | 96 filter, |
97 filter_index, | 97 filter_index, |
98 default_extension, | 98 default_extension, |
99 on_success, | 99 on_success, |
100 on_failure); | 100 on_failure); |
101 } | 101 } |
102 | 102 |
103 void HandleSelectFolder(const base::string16& title, | 103 void HandleSelectFolder(const base::string16& title, |
104 const SelectFolderCompletion& on_success, | 104 const SelectFolderCompletion& on_success, |
105 const FileSelectionCanceled& on_failure) { | 105 const FileSelectionCanceled& on_failure) { |
106 DCHECK(aura::RemoteWindowTreeHostWin::Instance()); | 106 DCHECK(aura::RemoteRootWindowHostWin::Instance()); |
107 aura::RemoteWindowTreeHostWin::Instance()->HandleSelectFolder(title, | 107 aura::RemoteRootWindowHostWin::Instance()->HandleSelectFolder(title, |
108 on_success, | 108 on_success, |
109 on_failure); | 109 on_failure); |
110 } | 110 } |
111 | 111 |
112 void HandleActivateDesktop(const base::FilePath& shortcut, | 112 void HandleActivateDesktop(const base::FilePath& shortcut, |
113 const ActivateDesktopCompleted& on_success) { | 113 const ActivateDesktopCompleted& on_success) { |
114 DCHECK(aura::RemoteWindowTreeHostWin::Instance()); | 114 DCHECK(aura::RemoteRootWindowHostWin::Instance()); |
115 aura::RemoteWindowTreeHostWin::Instance()->HandleActivateDesktop(shortcut, | 115 aura::RemoteRootWindowHostWin::Instance()->HandleActivateDesktop(shortcut, |
116 on_success); | 116 on_success); |
117 } | 117 } |
118 | 118 |
119 RemoteWindowTreeHostWin* g_instance = NULL; | 119 RemoteRootWindowHostWin* g_instance = NULL; |
120 | 120 |
121 RemoteWindowTreeHostWin* RemoteWindowTreeHostWin::Instance() { | 121 RemoteRootWindowHostWin* RemoteRootWindowHostWin::Instance() { |
122 if (g_instance) | 122 if (g_instance) |
123 return g_instance; | 123 return g_instance; |
124 return Create(gfx::Rect()); | 124 return Create(gfx::Rect()); |
125 } | 125 } |
126 | 126 |
127 RemoteWindowTreeHostWin* RemoteWindowTreeHostWin::Create( | 127 RemoteRootWindowHostWin* RemoteRootWindowHostWin::Create( |
128 const gfx::Rect& bounds) { | 128 const gfx::Rect& bounds) { |
129 g_instance = g_instance ? g_instance : new RemoteWindowTreeHostWin(bounds); | 129 g_instance = g_instance ? g_instance : new RemoteRootWindowHostWin(bounds); |
130 return g_instance; | 130 return g_instance; |
131 } | 131 } |
132 | 132 |
133 RemoteWindowTreeHostWin::RemoteWindowTreeHostWin(const gfx::Rect& bounds) | 133 RemoteRootWindowHostWin::RemoteRootWindowHostWin(const gfx::Rect& bounds) |
134 : remote_window_(NULL), | 134 : remote_window_(NULL), |
135 host_(NULL), | 135 host_(NULL), |
136 ignore_mouse_moves_until_set_cursor_ack_(false), | 136 ignore_mouse_moves_until_set_cursor_ack_(false), |
137 event_flags_(0) { | 137 event_flags_(0) { |
138 prop_.reset(new ui::ViewProp(NULL, kWindowTreeHostWinKey, this)); | 138 prop_.reset(new ui::ViewProp(NULL, kRootWindowHostWinKey, this)); |
139 CreateCompositor(GetAcceleratedWidget()); | 139 CreateCompositor(GetAcceleratedWidget()); |
140 } | 140 } |
141 | 141 |
142 RemoteWindowTreeHostWin::~RemoteWindowTreeHostWin() { | 142 RemoteRootWindowHostWin::~RemoteRootWindowHostWin() { |
143 g_instance = NULL; | 143 g_instance = NULL; |
144 } | 144 } |
145 | 145 |
146 void RemoteWindowTreeHostWin::Connected(IPC::Sender* host, HWND remote_window) { | 146 void RemoteRootWindowHostWin::Connected(IPC::Sender* host, HWND remote_window) { |
147 CHECK(host_ == NULL); | 147 CHECK(host_ == NULL); |
148 host_ = host; | 148 host_ = host; |
149 remote_window_ = remote_window; | 149 remote_window_ = remote_window; |
150 } | 150 } |
151 | 151 |
152 void RemoteWindowTreeHostWin::Disconnected() { | 152 void RemoteRootWindowHostWin::Disconnected() { |
153 // Don't CHECK here, Disconnected is called on a channel error which can | 153 // Don't CHECK here, Disconnected is called on a channel error which can |
154 // happen before we're successfully Connected. | 154 // happen before we're successfully Connected. |
155 host_ = NULL; | 155 host_ = NULL; |
156 remote_window_ = NULL; | 156 remote_window_ = NULL; |
157 } | 157 } |
158 | 158 |
159 bool RemoteWindowTreeHostWin::OnMessageReceived(const IPC::Message& message) { | 159 bool RemoteRootWindowHostWin::OnMessageReceived(const IPC::Message& message) { |
160 bool handled = true; | 160 bool handled = true; |
161 IPC_BEGIN_MESSAGE_MAP(RemoteWindowTreeHostWin, message) | 161 IPC_BEGIN_MESSAGE_MAP(RemoteRootWindowHostWin, message) |
162 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_MouseMoved, OnMouseMoved) | 162 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_MouseMoved, OnMouseMoved) |
163 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_MouseButton, OnMouseButton) | 163 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_MouseButton, OnMouseButton) |
164 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_KeyDown, OnKeyDown) | 164 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_KeyDown, OnKeyDown) |
165 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_KeyUp, OnKeyUp) | 165 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_KeyUp, OnKeyUp) |
166 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_Character, OnChar) | 166 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_Character, OnChar) |
167 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_WindowActivated, | 167 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_WindowActivated, |
168 OnWindowActivated) | 168 OnWindowActivated) |
169 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_TouchDown, | 169 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_TouchDown, |
170 OnTouchDown) | 170 OnTouchDown) |
171 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_TouchUp, | 171 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_TouchUp, |
(...skipping 12 matching lines...) Expand all Loading... |
184 OnSetCursorPosAck) | 184 OnSetCursorPosAck) |
185 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_WindowSizeChanged, | 185 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_WindowSizeChanged, |
186 OnWindowSizeChanged) | 186 OnWindowSizeChanged) |
187 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_ActivateDesktopDone, | 187 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_ActivateDesktopDone, |
188 OnDesktopActivated) | 188 OnDesktopActivated) |
189 IPC_MESSAGE_UNHANDLED(handled = false) | 189 IPC_MESSAGE_UNHANDLED(handled = false) |
190 IPC_END_MESSAGE_MAP() | 190 IPC_END_MESSAGE_MAP() |
191 return handled; | 191 return handled; |
192 } | 192 } |
193 | 193 |
194 void RemoteWindowTreeHostWin::HandleOpenURLOnDesktop( | 194 void RemoteRootWindowHostWin::HandleOpenURLOnDesktop( |
195 const base::FilePath& shortcut, | 195 const base::FilePath& shortcut, |
196 const base::string16& url) { | 196 const base::string16& url) { |
197 if (!host_) | 197 if (!host_) |
198 return; | 198 return; |
199 host_->Send(new MetroViewerHostMsg_OpenURLOnDesktop(shortcut, url)); | 199 host_->Send(new MetroViewerHostMsg_OpenURLOnDesktop(shortcut, url)); |
200 } | 200 } |
201 | 201 |
202 void RemoteWindowTreeHostWin::HandleActivateDesktop( | 202 void RemoteRootWindowHostWin::HandleActivateDesktop( |
203 const base::FilePath& shortcut, | 203 const base::FilePath& shortcut, |
204 const ActivateDesktopCompleted& on_success) { | 204 const ActivateDesktopCompleted& on_success) { |
205 if (!host_) | 205 if (!host_) |
206 return; | 206 return; |
207 DCHECK(activate_completed_callback_.is_null()); | 207 DCHECK(activate_completed_callback_.is_null()); |
208 activate_completed_callback_ = on_success; | 208 activate_completed_callback_ = on_success; |
209 host_->Send(new MetroViewerHostMsg_ActivateDesktop(shortcut)); | 209 host_->Send(new MetroViewerHostMsg_ActivateDesktop(shortcut)); |
210 } | 210 } |
211 | 211 |
212 void RemoteWindowTreeHostWin::HandleOpenFile( | 212 void RemoteRootWindowHostWin::HandleOpenFile( |
213 const base::string16& title, | 213 const base::string16& title, |
214 const base::FilePath& default_path, | 214 const base::FilePath& default_path, |
215 const base::string16& filter, | 215 const base::string16& filter, |
216 const OpenFileCompletion& on_success, | 216 const OpenFileCompletion& on_success, |
217 const FileSelectionCanceled& on_failure) { | 217 const FileSelectionCanceled& on_failure) { |
218 if (!host_) | 218 if (!host_) |
219 return; | 219 return; |
220 | 220 |
221 // Can only have one of these operations in flight. | 221 // Can only have one of these operations in flight. |
222 DCHECK(file_open_completion_callback_.is_null()); | 222 DCHECK(file_open_completion_callback_.is_null()); |
223 DCHECK(failure_callback_.is_null()); | 223 DCHECK(failure_callback_.is_null()); |
224 | 224 |
225 file_open_completion_callback_ = on_success; | 225 file_open_completion_callback_ = on_success; |
226 failure_callback_ = on_failure; | 226 failure_callback_ = on_failure; |
227 | 227 |
228 host_->Send(new MetroViewerHostMsg_DisplayFileOpen(title, | 228 host_->Send(new MetroViewerHostMsg_DisplayFileOpen(title, |
229 filter, | 229 filter, |
230 default_path, | 230 default_path, |
231 false)); | 231 false)); |
232 } | 232 } |
233 | 233 |
234 void RemoteWindowTreeHostWin::HandleOpenMultipleFiles( | 234 void RemoteRootWindowHostWin::HandleOpenMultipleFiles( |
235 const base::string16& title, | 235 const base::string16& title, |
236 const base::FilePath& default_path, | 236 const base::FilePath& default_path, |
237 const base::string16& filter, | 237 const base::string16& filter, |
238 const OpenMultipleFilesCompletion& on_success, | 238 const OpenMultipleFilesCompletion& on_success, |
239 const FileSelectionCanceled& on_failure) { | 239 const FileSelectionCanceled& on_failure) { |
240 if (!host_) | 240 if (!host_) |
241 return; | 241 return; |
242 | 242 |
243 // Can only have one of these operations in flight. | 243 // Can only have one of these operations in flight. |
244 DCHECK(multi_file_open_completion_callback_.is_null()); | 244 DCHECK(multi_file_open_completion_callback_.is_null()); |
245 DCHECK(failure_callback_.is_null()); | 245 DCHECK(failure_callback_.is_null()); |
246 multi_file_open_completion_callback_ = on_success; | 246 multi_file_open_completion_callback_ = on_success; |
247 failure_callback_ = on_failure; | 247 failure_callback_ = on_failure; |
248 | 248 |
249 host_->Send(new MetroViewerHostMsg_DisplayFileOpen(title, | 249 host_->Send(new MetroViewerHostMsg_DisplayFileOpen(title, |
250 filter, | 250 filter, |
251 default_path, | 251 default_path, |
252 true)); | 252 true)); |
253 } | 253 } |
254 | 254 |
255 void RemoteWindowTreeHostWin::HandleSaveFile( | 255 void RemoteRootWindowHostWin::HandleSaveFile( |
256 const base::string16& title, | 256 const base::string16& title, |
257 const base::FilePath& default_path, | 257 const base::FilePath& default_path, |
258 const base::string16& filter, | 258 const base::string16& filter, |
259 int filter_index, | 259 int filter_index, |
260 const base::string16& default_extension, | 260 const base::string16& default_extension, |
261 const SaveFileCompletion& on_success, | 261 const SaveFileCompletion& on_success, |
262 const FileSelectionCanceled& on_failure) { | 262 const FileSelectionCanceled& on_failure) { |
263 if (!host_) | 263 if (!host_) |
264 return; | 264 return; |
265 | 265 |
266 MetroViewerHostMsg_SaveAsDialogParams params; | 266 MetroViewerHostMsg_SaveAsDialogParams params; |
267 params.title = title; | 267 params.title = title; |
268 params.default_extension = default_extension; | 268 params.default_extension = default_extension; |
269 params.filter = filter; | 269 params.filter = filter; |
270 params.filter_index = filter_index; | 270 params.filter_index = filter_index; |
271 params.suggested_name = default_path; | 271 params.suggested_name = default_path; |
272 | 272 |
273 // Can only have one of these operations in flight. | 273 // Can only have one of these operations in flight. |
274 DCHECK(file_saveas_completion_callback_.is_null()); | 274 DCHECK(file_saveas_completion_callback_.is_null()); |
275 DCHECK(failure_callback_.is_null()); | 275 DCHECK(failure_callback_.is_null()); |
276 file_saveas_completion_callback_ = on_success; | 276 file_saveas_completion_callback_ = on_success; |
277 failure_callback_ = on_failure; | 277 failure_callback_ = on_failure; |
278 | 278 |
279 host_->Send(new MetroViewerHostMsg_DisplayFileSaveAs(params)); | 279 host_->Send(new MetroViewerHostMsg_DisplayFileSaveAs(params)); |
280 } | 280 } |
281 | 281 |
282 void RemoteWindowTreeHostWin::HandleSelectFolder( | 282 void RemoteRootWindowHostWin::HandleSelectFolder( |
283 const base::string16& title, | 283 const base::string16& title, |
284 const SelectFolderCompletion& on_success, | 284 const SelectFolderCompletion& on_success, |
285 const FileSelectionCanceled& on_failure) { | 285 const FileSelectionCanceled& on_failure) { |
286 if (!host_) | 286 if (!host_) |
287 return; | 287 return; |
288 | 288 |
289 // Can only have one of these operations in flight. | 289 // Can only have one of these operations in flight. |
290 DCHECK(select_folder_completion_callback_.is_null()); | 290 DCHECK(select_folder_completion_callback_.is_null()); |
291 DCHECK(failure_callback_.is_null()); | 291 DCHECK(failure_callback_.is_null()); |
292 select_folder_completion_callback_ = on_success; | 292 select_folder_completion_callback_ = on_success; |
293 failure_callback_ = on_failure; | 293 failure_callback_ = on_failure; |
294 | 294 |
295 host_->Send(new MetroViewerHostMsg_DisplaySelectFolder(title)); | 295 host_->Send(new MetroViewerHostMsg_DisplaySelectFolder(title)); |
296 } | 296 } |
297 | 297 |
298 bool RemoteWindowTreeHostWin::IsForegroundWindow() { | 298 bool RemoteRootWindowHostWin::IsForegroundWindow() { |
299 return ::GetForegroundWindow() == remote_window_; | 299 return ::GetForegroundWindow() == remote_window_; |
300 } | 300 } |
301 | 301 |
302 Window* RemoteWindowTreeHostWin::GetAshWindow() { | 302 Window* RemoteRootWindowHostWin::GetAshWindow() { |
303 return GetRootWindow()->window(); | 303 return GetRootWindow()->window(); |
304 } | 304 } |
305 | 305 |
306 RootWindow* RemoteWindowTreeHostWin::GetRootWindow() { | 306 RootWindow* RemoteRootWindowHostWin::GetRootWindow() { |
307 return delegate_->AsRootWindow(); | 307 return delegate_->AsRootWindow(); |
308 } | 308 } |
309 | 309 |
310 gfx::AcceleratedWidget RemoteWindowTreeHostWin::GetAcceleratedWidget() { | 310 gfx::AcceleratedWidget RemoteRootWindowHostWin::GetAcceleratedWidget() { |
311 if (remote_window_) | 311 if (remote_window_) |
312 return remote_window_; | 312 return remote_window_; |
313 // Getting here should only happen for ash_unittests.exe and related code. | 313 // Getting here should only happen for ash_unittests.exe and related code. |
314 return ::GetDesktopWindow(); | 314 return ::GetDesktopWindow(); |
315 } | 315 } |
316 | 316 |
317 void RemoteWindowTreeHostWin::Show() { | 317 void RemoteRootWindowHostWin::Show() { |
318 } | 318 } |
319 | 319 |
320 void RemoteWindowTreeHostWin::Hide() { | 320 void RemoteRootWindowHostWin::Hide() { |
321 NOTIMPLEMENTED(); | 321 NOTIMPLEMENTED(); |
322 } | 322 } |
323 | 323 |
324 void RemoteWindowTreeHostWin::ToggleFullScreen() { | 324 void RemoteRootWindowHostWin::ToggleFullScreen() { |
325 } | 325 } |
326 | 326 |
327 gfx::Rect RemoteWindowTreeHostWin::GetBounds() const { | 327 gfx::Rect RemoteRootWindowHostWin::GetBounds() const { |
328 gfx::Rect r(gfx::Point(0, 0), aura::WindowTreeHost::GetNativeScreenSize()); | 328 gfx::Rect r(gfx::Point(0, 0), aura::RootWindowHost::GetNativeScreenSize()); |
329 return r; | 329 return r; |
330 } | 330 } |
331 | 331 |
332 void RemoteWindowTreeHostWin::SetBounds(const gfx::Rect& bounds) { | 332 void RemoteRootWindowHostWin::SetBounds(const gfx::Rect& bounds) { |
333 NotifyHostResized(bounds.size()); | 333 NotifyHostResized(bounds.size()); |
334 } | 334 } |
335 | 335 |
336 gfx::Insets RemoteWindowTreeHostWin::GetInsets() const { | 336 gfx::Insets RemoteRootWindowHostWin::GetInsets() const { |
337 return gfx::Insets(); | 337 return gfx::Insets(); |
338 } | 338 } |
339 | 339 |
340 void RemoteWindowTreeHostWin::SetInsets(const gfx::Insets& insets) { | 340 void RemoteRootWindowHostWin::SetInsets(const gfx::Insets& insets) { |
341 } | 341 } |
342 | 342 |
343 gfx::Point RemoteWindowTreeHostWin::GetLocationOnNativeScreen() const { | 343 gfx::Point RemoteRootWindowHostWin::GetLocationOnNativeScreen() const { |
344 return gfx::Point(0, 0); | 344 return gfx::Point(0, 0); |
345 } | 345 } |
346 | 346 |
347 void RemoteWindowTreeHostWin::SetCursor(gfx::NativeCursor native_cursor) { | 347 void RemoteRootWindowHostWin::SetCursor(gfx::NativeCursor native_cursor) { |
348 if (!host_) | 348 if (!host_) |
349 return; | 349 return; |
350 host_->Send( | 350 host_->Send( |
351 new MetroViewerHostMsg_SetCursor(uint64(native_cursor.platform()))); | 351 new MetroViewerHostMsg_SetCursor(uint64(native_cursor.platform()))); |
352 } | 352 } |
353 | 353 |
354 void RemoteWindowTreeHostWin::SetCapture() { | 354 void RemoteRootWindowHostWin::SetCapture() { |
355 } | 355 } |
356 | 356 |
357 void RemoteWindowTreeHostWin::ReleaseCapture() { | 357 void RemoteRootWindowHostWin::ReleaseCapture() { |
358 } | 358 } |
359 | 359 |
360 bool RemoteWindowTreeHostWin::QueryMouseLocation(gfx::Point* location_return) { | 360 bool RemoteRootWindowHostWin::QueryMouseLocation(gfx::Point* location_return) { |
361 aura::client::CursorClient* cursor_client = | 361 aura::client::CursorClient* cursor_client = |
362 aura::client::GetCursorClient(GetRootWindow()->window()); | 362 aura::client::GetCursorClient(GetRootWindow()->window()); |
363 if (cursor_client && !cursor_client->IsMouseEventsEnabled()) { | 363 if (cursor_client && !cursor_client->IsMouseEventsEnabled()) { |
364 *location_return = gfx::Point(0, 0); | 364 *location_return = gfx::Point(0, 0); |
365 return false; | 365 return false; |
366 } | 366 } |
367 POINT pt; | 367 POINT pt; |
368 GetCursorPos(&pt); | 368 GetCursorPos(&pt); |
369 *location_return = | 369 *location_return = |
370 gfx::Point(static_cast<int>(pt.x), static_cast<int>(pt.y)); | 370 gfx::Point(static_cast<int>(pt.x), static_cast<int>(pt.y)); |
371 return true; | 371 return true; |
372 } | 372 } |
373 | 373 |
374 bool RemoteWindowTreeHostWin::ConfineCursorToRootWindow() { | 374 bool RemoteRootWindowHostWin::ConfineCursorToRootWindow() { |
375 return true; | 375 return true; |
376 } | 376 } |
377 | 377 |
378 void RemoteWindowTreeHostWin::UnConfineCursor() { | 378 void RemoteRootWindowHostWin::UnConfineCursor() { |
379 } | 379 } |
380 | 380 |
381 void RemoteWindowTreeHostWin::OnCursorVisibilityChanged(bool show) { | 381 void RemoteRootWindowHostWin::OnCursorVisibilityChanged(bool show) { |
382 NOTIMPLEMENTED(); | 382 NOTIMPLEMENTED(); |
383 } | 383 } |
384 | 384 |
385 void RemoteWindowTreeHostWin::MoveCursorTo(const gfx::Point& location) { | 385 void RemoteRootWindowHostWin::MoveCursorTo(const gfx::Point& location) { |
386 VLOG(1) << "In MoveCursorTo: " << location.x() << ", " << location.y(); | 386 VLOG(1) << "In MoveCursorTo: " << location.x() << ", " << location.y(); |
387 if (!host_) | 387 if (!host_) |
388 return; | 388 return; |
389 | 389 |
390 // This function can be called in cases like when the mouse cursor is | 390 // This function can be called in cases like when the mouse cursor is |
391 // restricted within a viewport (For e.g. LockCursor) which assumes that | 391 // restricted within a viewport (For e.g. LockCursor) which assumes that |
392 // subsequent mouse moves would be received starting with the new cursor | 392 // subsequent mouse moves would be received starting with the new cursor |
393 // coordinates. This is a challenge for Windows ASH for the reasons | 393 // coordinates. This is a challenge for Windows ASH for the reasons |
394 // outlined below. | 394 // outlined below. |
395 // Other cases which don't expect this behavior should continue to work | 395 // Other cases which don't expect this behavior should continue to work |
396 // without issues. | 396 // without issues. |
397 | 397 |
398 // The mouse events are received by the viewer process and sent to the | 398 // The mouse events are received by the viewer process and sent to the |
399 // browser. If we invoke the SetCursor API here we continue to receive | 399 // browser. If we invoke the SetCursor API here we continue to receive |
400 // mouse messages from the viewer which were posted before the SetCursor | 400 // mouse messages from the viewer which were posted before the SetCursor |
401 // API executes which messes up the state in the browser. To workaround | 401 // API executes which messes up the state in the browser. To workaround |
402 // this we invoke the SetCursor API in the viewer process and ignore | 402 // this we invoke the SetCursor API in the viewer process and ignore |
403 // mouse messages until we received an ACK from the viewer indicating that | 403 // mouse messages until we received an ACK from the viewer indicating that |
404 // the SetCursor operation completed. | 404 // the SetCursor operation completed. |
405 ignore_mouse_moves_until_set_cursor_ack_ = true; | 405 ignore_mouse_moves_until_set_cursor_ack_ = true; |
406 VLOG(1) << "In MoveCursorTo. Sending IPC"; | 406 VLOG(1) << "In MoveCursorTo. Sending IPC"; |
407 host_->Send(new MetroViewerHostMsg_SetCursorPos(location.x(), location.y())); | 407 host_->Send(new MetroViewerHostMsg_SetCursorPos(location.x(), location.y())); |
408 } | 408 } |
409 | 409 |
410 void RemoteWindowTreeHostWin::PostNativeEvent( | 410 void RemoteRootWindowHostWin::PostNativeEvent( |
411 const base::NativeEvent& native_event) { | 411 const base::NativeEvent& native_event) { |
412 } | 412 } |
413 | 413 |
414 void RemoteWindowTreeHostWin::OnDeviceScaleFactorChanged( | 414 void RemoteRootWindowHostWin::OnDeviceScaleFactorChanged( |
415 float device_scale_factor) { | 415 float device_scale_factor) { |
416 NOTIMPLEMENTED(); | 416 NOTIMPLEMENTED(); |
417 } | 417 } |
418 | 418 |
419 void RemoteWindowTreeHostWin::PrepareForShutdown() { | 419 void RemoteRootWindowHostWin::PrepareForShutdown() { |
420 } | 420 } |
421 | 421 |
422 void RemoteWindowTreeHostWin::OnMouseMoved(int32 x, int32 y, int32 flags) { | 422 void RemoteRootWindowHostWin::OnMouseMoved(int32 x, int32 y, int32 flags) { |
423 if (ignore_mouse_moves_until_set_cursor_ack_) | 423 if (ignore_mouse_moves_until_set_cursor_ack_) |
424 return; | 424 return; |
425 | 425 |
426 gfx::Point location(x, y); | 426 gfx::Point location(x, y); |
427 ui::MouseEvent event(ui::ET_MOUSE_MOVED, location, location, flags); | 427 ui::MouseEvent event(ui::ET_MOUSE_MOVED, location, location, flags); |
428 delegate_->OnHostMouseEvent(&event); | 428 delegate_->OnHostMouseEvent(&event); |
429 } | 429 } |
430 | 430 |
431 void RemoteWindowTreeHostWin::OnMouseButton( | 431 void RemoteRootWindowHostWin::OnMouseButton( |
432 int32 x, | 432 int32 x, |
433 int32 y, | 433 int32 y, |
434 int32 extra, | 434 int32 extra, |
435 ui::EventType type, | 435 ui::EventType type, |
436 ui::EventFlags flags) { | 436 ui::EventFlags flags) { |
437 gfx::Point location(x, y); | 437 gfx::Point location(x, y); |
438 ui::MouseEvent mouse_event(type, location, location, flags); | 438 ui::MouseEvent mouse_event(type, location, location, flags); |
439 | 439 |
440 SetEventFlags(flags | key_event_flags()); | 440 SetEventFlags(flags | key_event_flags()); |
441 if (type == ui::ET_MOUSEWHEEL) { | 441 if (type == ui::ET_MOUSEWHEEL) { |
(...skipping 13 matching lines...) Expand all Loading... |
455 } else { | 455 } else { |
456 mouse_event.SetClickCount(1); | 456 mouse_event.SetClickCount(1); |
457 } | 457 } |
458 last_mouse_click_event_ .reset(new ui::MouseEvent(mouse_event)); | 458 last_mouse_click_event_ .reset(new ui::MouseEvent(mouse_event)); |
459 delegate_->OnHostMouseEvent(&mouse_event); | 459 delegate_->OnHostMouseEvent(&mouse_event); |
460 } else { | 460 } else { |
461 delegate_->OnHostMouseEvent(&mouse_event); | 461 delegate_->OnHostMouseEvent(&mouse_event); |
462 } | 462 } |
463 } | 463 } |
464 | 464 |
465 void RemoteWindowTreeHostWin::OnKeyDown(uint32 vkey, | 465 void RemoteRootWindowHostWin::OnKeyDown(uint32 vkey, |
466 uint32 repeat_count, | 466 uint32 repeat_count, |
467 uint32 scan_code, | 467 uint32 scan_code, |
468 uint32 flags) { | 468 uint32 flags) { |
469 DispatchKeyboardMessage(ui::ET_KEY_PRESSED, vkey, repeat_count, scan_code, | 469 DispatchKeyboardMessage(ui::ET_KEY_PRESSED, vkey, repeat_count, scan_code, |
470 flags, false); | 470 flags, false); |
471 } | 471 } |
472 | 472 |
473 void RemoteWindowTreeHostWin::OnKeyUp(uint32 vkey, | 473 void RemoteRootWindowHostWin::OnKeyUp(uint32 vkey, |
474 uint32 repeat_count, | 474 uint32 repeat_count, |
475 uint32 scan_code, | 475 uint32 scan_code, |
476 uint32 flags) { | 476 uint32 flags) { |
477 DispatchKeyboardMessage(ui::ET_KEY_RELEASED, vkey, repeat_count, scan_code, | 477 DispatchKeyboardMessage(ui::ET_KEY_RELEASED, vkey, repeat_count, scan_code, |
478 flags, false); | 478 flags, false); |
479 } | 479 } |
480 | 480 |
481 void RemoteWindowTreeHostWin::OnChar(uint32 key_code, | 481 void RemoteRootWindowHostWin::OnChar(uint32 key_code, |
482 uint32 repeat_count, | 482 uint32 repeat_count, |
483 uint32 scan_code, | 483 uint32 scan_code, |
484 uint32 flags) { | 484 uint32 flags) { |
485 DispatchKeyboardMessage(ui::ET_KEY_PRESSED, key_code, repeat_count, | 485 DispatchKeyboardMessage(ui::ET_KEY_PRESSED, key_code, repeat_count, |
486 scan_code, flags, true); | 486 scan_code, flags, true); |
487 } | 487 } |
488 | 488 |
489 void RemoteWindowTreeHostWin::OnWindowActivated() { | 489 void RemoteRootWindowHostWin::OnWindowActivated() { |
490 delegate_->OnHostActivated(); | 490 delegate_->OnHostActivated(); |
491 } | 491 } |
492 | 492 |
493 void RemoteWindowTreeHostWin::OnTouchDown(int32 x, | 493 void RemoteRootWindowHostWin::OnTouchDown(int32 x, |
494 int32 y, | 494 int32 y, |
495 uint64 timestamp, | 495 uint64 timestamp, |
496 uint32 pointer_id) { | 496 uint32 pointer_id) { |
497 ui::TouchEvent event(ui::ET_TOUCH_PRESSED, | 497 ui::TouchEvent event(ui::ET_TOUCH_PRESSED, |
498 gfx::Point(x, y), | 498 gfx::Point(x, y), |
499 pointer_id, | 499 pointer_id, |
500 base::TimeDelta::FromMicroseconds(timestamp)); | 500 base::TimeDelta::FromMicroseconds(timestamp)); |
501 delegate_->OnHostTouchEvent(&event); | 501 delegate_->OnHostTouchEvent(&event); |
502 } | 502 } |
503 | 503 |
504 void RemoteWindowTreeHostWin::OnTouchUp(int32 x, | 504 void RemoteRootWindowHostWin::OnTouchUp(int32 x, |
505 int32 y, | 505 int32 y, |
506 uint64 timestamp, | 506 uint64 timestamp, |
507 uint32 pointer_id) { | 507 uint32 pointer_id) { |
508 ui::TouchEvent event(ui::ET_TOUCH_RELEASED, | 508 ui::TouchEvent event(ui::ET_TOUCH_RELEASED, |
509 gfx::Point(x, y), | 509 gfx::Point(x, y), |
510 pointer_id, | 510 pointer_id, |
511 base::TimeDelta::FromMicroseconds(timestamp)); | 511 base::TimeDelta::FromMicroseconds(timestamp)); |
512 delegate_->OnHostTouchEvent(&event); | 512 delegate_->OnHostTouchEvent(&event); |
513 } | 513 } |
514 | 514 |
515 void RemoteWindowTreeHostWin::OnTouchMoved(int32 x, | 515 void RemoteRootWindowHostWin::OnTouchMoved(int32 x, |
516 int32 y, | 516 int32 y, |
517 uint64 timestamp, | 517 uint64 timestamp, |
518 uint32 pointer_id) { | 518 uint32 pointer_id) { |
519 ui::TouchEvent event(ui::ET_TOUCH_MOVED, | 519 ui::TouchEvent event(ui::ET_TOUCH_MOVED, |
520 gfx::Point(x, y), | 520 gfx::Point(x, y), |
521 pointer_id, | 521 pointer_id, |
522 base::TimeDelta::FromMicroseconds(timestamp)); | 522 base::TimeDelta::FromMicroseconds(timestamp)); |
523 delegate_->OnHostTouchEvent(&event); | 523 delegate_->OnHostTouchEvent(&event); |
524 } | 524 } |
525 | 525 |
526 void RemoteWindowTreeHostWin::OnFileSaveAsDone(bool success, | 526 void RemoteRootWindowHostWin::OnFileSaveAsDone(bool success, |
527 const base::FilePath& filename, | 527 const base::FilePath& filename, |
528 int filter_index) { | 528 int filter_index) { |
529 if (success) | 529 if (success) |
530 file_saveas_completion_callback_.Run(filename, filter_index, NULL); | 530 file_saveas_completion_callback_.Run(filename, filter_index, NULL); |
531 else | 531 else |
532 failure_callback_.Run(NULL); | 532 failure_callback_.Run(NULL); |
533 file_saveas_completion_callback_.Reset(); | 533 file_saveas_completion_callback_.Reset(); |
534 failure_callback_.Reset(); | 534 failure_callback_.Reset(); |
535 } | 535 } |
536 | 536 |
537 | 537 |
538 void RemoteWindowTreeHostWin::OnFileOpenDone(bool success, | 538 void RemoteRootWindowHostWin::OnFileOpenDone(bool success, |
539 const base::FilePath& filename) { | 539 const base::FilePath& filename) { |
540 if (success) | 540 if (success) |
541 file_open_completion_callback_.Run(base::FilePath(filename), 0, NULL); | 541 file_open_completion_callback_.Run(base::FilePath(filename), 0, NULL); |
542 else | 542 else |
543 failure_callback_.Run(NULL); | 543 failure_callback_.Run(NULL); |
544 file_open_completion_callback_.Reset(); | 544 file_open_completion_callback_.Reset(); |
545 failure_callback_.Reset(); | 545 failure_callback_.Reset(); |
546 } | 546 } |
547 | 547 |
548 void RemoteWindowTreeHostWin::OnMultiFileOpenDone( | 548 void RemoteRootWindowHostWin::OnMultiFileOpenDone( |
549 bool success, | 549 bool success, |
550 const std::vector<base::FilePath>& files) { | 550 const std::vector<base::FilePath>& files) { |
551 if (success) | 551 if (success) |
552 multi_file_open_completion_callback_.Run(files, NULL); | 552 multi_file_open_completion_callback_.Run(files, NULL); |
553 else | 553 else |
554 failure_callback_.Run(NULL); | 554 failure_callback_.Run(NULL); |
555 multi_file_open_completion_callback_.Reset(); | 555 multi_file_open_completion_callback_.Reset(); |
556 failure_callback_.Reset(); | 556 failure_callback_.Reset(); |
557 } | 557 } |
558 | 558 |
559 void RemoteWindowTreeHostWin::OnSelectFolderDone( | 559 void RemoteRootWindowHostWin::OnSelectFolderDone( |
560 bool success, | 560 bool success, |
561 const base::FilePath& folder) { | 561 const base::FilePath& folder) { |
562 if (success) | 562 if (success) |
563 select_folder_completion_callback_.Run(base::FilePath(folder), 0, NULL); | 563 select_folder_completion_callback_.Run(base::FilePath(folder), 0, NULL); |
564 else | 564 else |
565 failure_callback_.Run(NULL); | 565 failure_callback_.Run(NULL); |
566 select_folder_completion_callback_.Reset(); | 566 select_folder_completion_callback_.Reset(); |
567 failure_callback_.Reset(); | 567 failure_callback_.Reset(); |
568 } | 568 } |
569 | 569 |
570 void RemoteWindowTreeHostWin::OnSetCursorPosAck() { | 570 void RemoteRootWindowHostWin::OnSetCursorPosAck() { |
571 DCHECK(ignore_mouse_moves_until_set_cursor_ack_); | 571 DCHECK(ignore_mouse_moves_until_set_cursor_ack_); |
572 ignore_mouse_moves_until_set_cursor_ack_ = false; | 572 ignore_mouse_moves_until_set_cursor_ack_ = false; |
573 } | 573 } |
574 | 574 |
575 void RemoteWindowTreeHostWin::OnWindowSizeChanged(uint32 width, uint32 height) { | 575 void RemoteRootWindowHostWin::OnWindowSizeChanged(uint32 width, uint32 height) { |
576 SetBounds(gfx::Rect(0, 0, width, height)); | 576 SetBounds(gfx::Rect(0, 0, width, height)); |
577 } | 577 } |
578 | 578 |
579 void RemoteWindowTreeHostWin::OnDesktopActivated() { | 579 void RemoteRootWindowHostWin::OnDesktopActivated() { |
580 ActivateDesktopCompleted temp = activate_completed_callback_; | 580 ActivateDesktopCompleted temp = activate_completed_callback_; |
581 activate_completed_callback_.Reset(); | 581 activate_completed_callback_.Reset(); |
582 temp.Run(); | 582 temp.Run(); |
583 } | 583 } |
584 | 584 |
585 void RemoteWindowTreeHostWin::DispatchKeyboardMessage(ui::EventType type, | 585 void RemoteRootWindowHostWin::DispatchKeyboardMessage(ui::EventType type, |
586 uint32 vkey, | 586 uint32 vkey, |
587 uint32 repeat_count, | 587 uint32 repeat_count, |
588 uint32 scan_code, | 588 uint32 scan_code, |
589 uint32 flags, | 589 uint32 flags, |
590 bool is_character) { | 590 bool is_character) { |
591 SetEventFlags(flags | mouse_event_flags()); | 591 SetEventFlags(flags | mouse_event_flags()); |
592 if (base::MessageLoop::current()->IsNested()) { | 592 if (base::MessageLoop::current()->IsNested()) { |
593 uint32 message = is_character ? WM_CHAR : | 593 uint32 message = is_character ? WM_CHAR : |
594 (type == ui::ET_KEY_PRESSED ? WM_KEYDOWN : WM_KEYUP); | 594 (type == ui::ET_KEY_PRESSED ? WM_KEYDOWN : WM_KEYUP); |
595 ::PostThreadMessage(::GetCurrentThreadId(), | 595 ::PostThreadMessage(::GetCurrentThreadId(), |
596 message, | 596 message, |
597 vkey, | 597 vkey, |
598 repeat_count | scan_code >> 15); | 598 repeat_count | scan_code >> 15); |
599 } else { | 599 } else { |
600 ui::KeyEvent event(type, | 600 ui::KeyEvent event(type, |
601 ui::KeyboardCodeForWindowsKeyCode(vkey), | 601 ui::KeyboardCodeForWindowsKeyCode(vkey), |
602 flags, | 602 flags, |
603 is_character); | 603 is_character); |
604 delegate_->OnHostKeyEvent(&event); | 604 delegate_->OnHostKeyEvent(&event); |
605 } | 605 } |
606 } | 606 } |
607 | 607 |
608 void RemoteWindowTreeHostWin::SetEventFlags(uint32 flags) { | 608 void RemoteRootWindowHostWin::SetEventFlags(uint32 flags) { |
609 if (flags == event_flags_) | 609 if (flags == event_flags_) |
610 return; | 610 return; |
611 event_flags_ = flags; | 611 event_flags_ = flags; |
612 SetVirtualKeyStates(event_flags_); | 612 SetVirtualKeyStates(event_flags_); |
613 } | 613 } |
614 | 614 |
615 } // namespace aura | 615 } // namespace aura |
OLD | NEW |