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 have one of these operations in flight. |
palmer
2013/04/18 22:58:08
Only need one "have". :)
ananta
2013/04/19 00:23:24
Done.
| |
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.value(), |
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.value(), |
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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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(bool success, | |
457 const string16& folder) { | |
458 if (success) { | |
459 select_folder_completion_callback_.Run(base::FilePath(folder), 0, NULL); | |
460 } | |
461 select_folder_completion_callback_.Reset(); | |
462 } | |
463 | |
434 void RemoteRootWindowHostWin::DispatchKeyboardMessage(ui::EventType type, | 464 void RemoteRootWindowHostWin::DispatchKeyboardMessage(ui::EventType type, |
435 uint32 vkey, | 465 uint32 vkey, |
436 uint32 repeat_count, | 466 uint32 repeat_count, |
437 uint32 scan_code, | 467 uint32 scan_code, |
438 uint32 flags, | 468 uint32 flags, |
439 bool is_character) { | 469 bool is_character) { |
440 if (MessageLoop::current()->IsNested()) { | 470 if (MessageLoop::current()->IsNested()) { |
441 SetVirtualKeyStates(flags); | 471 SetVirtualKeyStates(flags); |
442 | 472 |
443 uint32 message = is_character ? WM_CHAR : | 473 uint32 message = is_character ? WM_CHAR : |
444 (type == ui::ET_KEY_PRESSED ? WM_KEYDOWN : WM_KEYUP); | 474 (type == ui::ET_KEY_PRESSED ? WM_KEYDOWN : WM_KEYUP); |
445 ::PostThreadMessage(::GetCurrentThreadId(), | 475 ::PostThreadMessage(::GetCurrentThreadId(), |
446 message, | 476 message, |
447 vkey, | 477 vkey, |
448 repeat_count | scan_code >> 15); | 478 repeat_count | scan_code >> 15); |
449 } else { | 479 } else { |
450 ui::KeyEvent event(type, | 480 ui::KeyEvent event(type, |
451 ui::KeyboardCodeForWindowsKeyCode(vkey), | 481 ui::KeyboardCodeForWindowsKeyCode(vkey), |
452 flags, | 482 flags, |
453 is_character); | 483 is_character); |
454 delegate_->OnHostKeyEvent(&event); | 484 delegate_->OnHostKeyEvent(&event); |
455 } | 485 } |
456 } | 486 } |
457 | 487 |
458 } // namespace aura | 488 } // namespace aura |
OLD | NEW |