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 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 const SaveFileCompletion& callback) { | 86 const SaveFileCompletion& callback) { |
87 DCHECK(aura::RemoteRootWindowHostWin::Instance()); | 87 DCHECK(aura::RemoteRootWindowHostWin::Instance()); |
88 aura::RemoteRootWindowHostWin::Instance()->HandleSaveFile(title, | 88 aura::RemoteRootWindowHostWin::Instance()->HandleSaveFile(title, |
89 default_path, | 89 default_path, |
90 filter, | 90 filter, |
91 filter_index, | 91 filter_index, |
92 default_extension, | 92 default_extension, |
93 callback); | 93 callback); |
94 } | 94 } |
95 | 95 |
| 96 void HandleSelectFolder(const string16& title, |
| 97 const SelectFolderCompletion& callback) { |
| 98 DCHECK(aura::RemoteRootWindowHostWin::Instance()); |
| 99 aura::RemoteRootWindowHostWin::Instance()->HandleSelectFolder(title, |
| 100 callback); |
| 101 } |
| 102 |
96 RemoteRootWindowHostWin* g_instance = NULL; | 103 RemoteRootWindowHostWin* g_instance = NULL; |
97 | 104 |
98 RemoteRootWindowHostWin* RemoteRootWindowHostWin::Instance() { | 105 RemoteRootWindowHostWin* RemoteRootWindowHostWin::Instance() { |
99 return g_instance; | 106 return g_instance; |
100 } | 107 } |
101 | 108 |
102 RemoteRootWindowHostWin* RemoteRootWindowHostWin::Create( | 109 RemoteRootWindowHostWin* RemoteRootWindowHostWin::Create( |
103 const gfx::Rect& bounds) { | 110 const gfx::Rect& bounds) { |
104 g_instance = new RemoteRootWindowHostWin(bounds); | 111 g_instance = new RemoteRootWindowHostWin(bounds); |
105 return g_instance; | 112 return g_instance; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_TouchUp, | 145 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_TouchUp, |
139 OnTouchUp) | 146 OnTouchUp) |
140 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_TouchMoved, | 147 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_TouchMoved, |
141 OnTouchMoved) | 148 OnTouchMoved) |
142 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_FileSaveAsDone, | 149 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_FileSaveAsDone, |
143 OnFileSaveAsDone) | 150 OnFileSaveAsDone) |
144 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_FileOpenDone, | 151 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_FileOpenDone, |
145 OnFileOpenDone) | 152 OnFileOpenDone) |
146 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_MultiFileOpenDone, | 153 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_MultiFileOpenDone, |
147 OnMultiFileOpenDone) | 154 OnMultiFileOpenDone) |
| 155 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_SelectFolderDone, |
| 156 OnSelectFolderDone) |
148 IPC_MESSAGE_UNHANDLED(handled = false) | 157 IPC_MESSAGE_UNHANDLED(handled = false) |
149 IPC_END_MESSAGE_MAP() | 158 IPC_END_MESSAGE_MAP() |
150 return handled; | 159 return handled; |
151 } | 160 } |
152 | 161 |
153 void RemoteRootWindowHostWin::HandleOpenFile( | 162 void RemoteRootWindowHostWin::HandleOpenFile( |
154 const string16& title, | 163 const string16& title, |
155 const base::FilePath& default_path, | 164 const base::FilePath& default_path, |
156 const string16& filter, | 165 const string16& filter, |
157 const OpenFileCompletion& callback) { | 166 const OpenFileCompletion& callback) { |
158 if (!host_) | 167 if (!host_) |
159 return; | 168 return; |
160 | 169 |
161 // Can only one of these operations in flight. | 170 // Can only have one of these operations in flight. |
162 DCHECK(file_open_completion_callback_.is_null()); | 171 DCHECK(file_open_completion_callback_.is_null()); |
163 file_open_completion_callback_ = callback; | 172 file_open_completion_callback_ = callback; |
164 | 173 |
165 host_->Send(new MetroViewerHostMsg_DisplayFileOpen(title, | 174 host_->Send(new MetroViewerHostMsg_DisplayFileOpen(title, |
166 filter, | 175 filter, |
167 default_path.value(), | 176 default_path, |
168 false)); | 177 false)); |
169 } | 178 } |
170 | 179 |
171 void RemoteRootWindowHostWin::HandleOpenMultipleFiles( | 180 void RemoteRootWindowHostWin::HandleOpenMultipleFiles( |
172 const string16& title, | 181 const string16& title, |
173 const base::FilePath& default_path, | 182 const base::FilePath& default_path, |
174 const string16& filter, | 183 const string16& filter, |
175 const OpenMultipleFilesCompletion& callback) { | 184 const OpenMultipleFilesCompletion& callback) { |
176 if (!host_) | 185 if (!host_) |
177 return; | 186 return; |
178 | 187 |
179 // Can only one of these operations in flight. | 188 // Can only have one of these operations in flight. |
180 DCHECK(multi_file_open_completion_callback_.is_null()); | 189 DCHECK(multi_file_open_completion_callback_.is_null()); |
181 multi_file_open_completion_callback_ = callback; | 190 multi_file_open_completion_callback_ = callback; |
182 | 191 |
183 host_->Send(new MetroViewerHostMsg_DisplayFileOpen(title, | 192 host_->Send(new MetroViewerHostMsg_DisplayFileOpen(title, |
184 filter, | 193 filter, |
185 default_path.value(), | 194 default_path, |
186 true)); | 195 true)); |
187 } | 196 } |
188 | 197 |
189 void RemoteRootWindowHostWin::HandleSaveFile( | 198 void RemoteRootWindowHostWin::HandleSaveFile( |
190 const string16& title, | 199 const string16& title, |
191 const base::FilePath& default_path, | 200 const base::FilePath& default_path, |
192 const string16& filter, | 201 const string16& filter, |
193 int filter_index, | 202 int filter_index, |
194 const string16& default_extension, | 203 const string16& default_extension, |
195 const SaveFileCompletion& callback) { | 204 const SaveFileCompletion& callback) { |
196 if (!host_) | 205 if (!host_) |
197 return; | 206 return; |
198 | 207 |
199 MetroViewerHostMsg_SaveAsDialogParams params; | 208 MetroViewerHostMsg_SaveAsDialogParams params; |
200 params.title = title; | 209 params.title = title; |
201 params.default_extension = default_extension; | 210 params.default_extension = default_extension; |
202 params.filter = filter; | 211 params.filter = filter; |
203 params.filter_index = filter_index; | 212 params.filter_index = filter_index; |
204 | 213 |
205 // Can only one of these operations in flight. | 214 // Can only have one of these operations in flight. |
206 DCHECK(file_saveas_completion_callback_.is_null()); | 215 DCHECK(file_saveas_completion_callback_.is_null()); |
207 file_saveas_completion_callback_ = callback; | 216 file_saveas_completion_callback_ = callback; |
208 | 217 |
209 host_->Send(new MetroViewerHostMsg_DisplayFileSaveAs(params)); | 218 host_->Send(new MetroViewerHostMsg_DisplayFileSaveAs(params)); |
210 } | 219 } |
211 | 220 |
| 221 void RemoteRootWindowHostWin::HandleSelectFolder( |
| 222 const string16& title, |
| 223 const SelectFolderCompletion& callback) { |
| 224 if (!host_) |
| 225 return; |
| 226 |
| 227 // Can only have one of these operations in flight. |
| 228 DCHECK(select_folder_completion_callback_.is_null()); |
| 229 select_folder_completion_callback_ = callback; |
| 230 |
| 231 host_->Send(new MetroViewerHostMsg_DisplaySelectFolder(title)); |
| 232 } |
| 233 |
212 void RemoteRootWindowHostWin::SetDelegate(RootWindowHostDelegate* delegate) { | 234 void RemoteRootWindowHostWin::SetDelegate(RootWindowHostDelegate* delegate) { |
213 delegate_ = delegate; | 235 delegate_ = delegate; |
214 } | 236 } |
215 | 237 |
216 RootWindow* RemoteRootWindowHostWin::GetRootWindow() { | 238 RootWindow* RemoteRootWindowHostWin::GetRootWindow() { |
217 return delegate_->AsRootWindow(); | 239 return delegate_->AsRootWindow(); |
218 } | 240 } |
219 | 241 |
220 gfx::AcceleratedWidget RemoteRootWindowHostWin::GetAcceleratedWidget() { | 242 gfx::AcceleratedWidget RemoteRootWindowHostWin::GetAcceleratedWidget() { |
221 // TODO(cpu): This is bad. Chrome's compositor needs a valid window | 243 // TODO(cpu): This is bad. Chrome's compositor needs a valid window |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 uint64 timestamp, | 419 uint64 timestamp, |
398 uint32 pointer_id) { | 420 uint32 pointer_id) { |
399 ui::TouchEvent event(ui::ET_TOUCH_MOVED, | 421 ui::TouchEvent event(ui::ET_TOUCH_MOVED, |
400 gfx::Point(x, y), | 422 gfx::Point(x, y), |
401 pointer_id, | 423 pointer_id, |
402 base::TimeDelta::FromMicroseconds(timestamp)); | 424 base::TimeDelta::FromMicroseconds(timestamp)); |
403 delegate_->OnHostTouchEvent(&event); | 425 delegate_->OnHostTouchEvent(&event); |
404 } | 426 } |
405 | 427 |
406 void RemoteRootWindowHostWin::OnFileSaveAsDone(bool success, | 428 void RemoteRootWindowHostWin::OnFileSaveAsDone(bool success, |
407 string16 filename, | 429 const base::FilePath& filename, |
408 int filter_index) { | 430 int filter_index) { |
409 if (success) { | 431 if (success) { |
410 file_saveas_completion_callback_.Run( | 432 file_saveas_completion_callback_.Run(filename, filter_index, NULL); |
411 base::FilePath(filename), filter_index, NULL); | |
412 } | 433 } |
413 file_saveas_completion_callback_.Reset(); | 434 file_saveas_completion_callback_.Reset(); |
414 } | 435 } |
415 | 436 |
416 | 437 |
417 void RemoteRootWindowHostWin::OnFileOpenDone(bool success, string16 filename) { | 438 void RemoteRootWindowHostWin::OnFileOpenDone(bool success, |
| 439 const base::FilePath& filename) { |
418 if (success) { | 440 if (success) { |
419 file_open_completion_callback_.Run( | 441 file_open_completion_callback_.Run( |
420 base::FilePath(filename), 0, NULL); | 442 base::FilePath(filename), 0, NULL); |
421 } | 443 } |
422 file_open_completion_callback_.Reset(); | 444 file_open_completion_callback_.Reset(); |
423 } | 445 } |
424 | 446 |
425 void RemoteRootWindowHostWin::OnMultiFileOpenDone( | 447 void RemoteRootWindowHostWin::OnMultiFileOpenDone( |
426 bool success, | 448 bool success, |
427 const std::vector<base::FilePath>& files) { | 449 const std::vector<base::FilePath>& files) { |
428 if (success) { | 450 if (success) { |
429 multi_file_open_completion_callback_.Run(files, NULL); | 451 multi_file_open_completion_callback_.Run(files, NULL); |
430 } | 452 } |
431 multi_file_open_completion_callback_.Reset(); | 453 multi_file_open_completion_callback_.Reset(); |
432 } | 454 } |
433 | 455 |
| 456 void RemoteRootWindowHostWin::OnSelectFolderDone( |
| 457 bool success, |
| 458 const base::FilePath& folder) { |
| 459 if (success) { |
| 460 select_folder_completion_callback_.Run(base::FilePath(folder), 0, NULL); |
| 461 } |
| 462 select_folder_completion_callback_.Reset(); |
| 463 } |
| 464 |
434 void RemoteRootWindowHostWin::DispatchKeyboardMessage(ui::EventType type, | 465 void RemoteRootWindowHostWin::DispatchKeyboardMessage(ui::EventType type, |
435 uint32 vkey, | 466 uint32 vkey, |
436 uint32 repeat_count, | 467 uint32 repeat_count, |
437 uint32 scan_code, | 468 uint32 scan_code, |
438 uint32 flags, | 469 uint32 flags, |
439 bool is_character) { | 470 bool is_character) { |
440 if (MessageLoop::current()->IsNested()) { | 471 if (MessageLoop::current()->IsNested()) { |
441 SetVirtualKeyStates(flags); | 472 SetVirtualKeyStates(flags); |
442 | 473 |
443 uint32 message = is_character ? WM_CHAR : | 474 uint32 message = is_character ? WM_CHAR : |
444 (type == ui::ET_KEY_PRESSED ? WM_KEYDOWN : WM_KEYUP); | 475 (type == ui::ET_KEY_PRESSED ? WM_KEYDOWN : WM_KEYUP); |
445 ::PostThreadMessage(::GetCurrentThreadId(), | 476 ::PostThreadMessage(::GetCurrentThreadId(), |
446 message, | 477 message, |
447 vkey, | 478 vkey, |
448 repeat_count | scan_code >> 15); | 479 repeat_count | scan_code >> 15); |
449 } else { | 480 } else { |
450 ui::KeyEvent event(type, | 481 ui::KeyEvent event(type, |
451 ui::KeyboardCodeForWindowsKeyCode(vkey), | 482 ui::KeyboardCodeForWindowsKeyCode(vkey), |
452 flags, | 483 flags, |
453 is_character); | 484 is_character); |
454 delegate_->OnHostKeyEvent(&event); | 485 delegate_->OnHostKeyEvent(&event); |
455 } | 486 } |
456 } | 487 } |
457 | 488 |
458 } // namespace aura | 489 } // namespace aura |
OLD | NEW |