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/aura_constants.h" |
14 #include "ui/aura/client/cursor_client.h" | 15 #include "ui/aura/client/cursor_client.h" |
15 #include "ui/aura/root_window.h" | 16 #include "ui/aura/root_window.h" |
| 17 #include "ui/aura/window_property.h" |
16 #include "ui/base/cursor/cursor_loader_win.h" | 18 #include "ui/base/cursor/cursor_loader_win.h" |
| 19 #include "ui/base/ime/composition_text.h" |
| 20 #include "ui/base/ime/input_method.h" |
| 21 #include "ui/base/ime/remote_input_method_win.h" |
| 22 #include "ui/base/ime/text_input_client.h" |
17 #include "ui/events/event_utils.h" | 23 #include "ui/events/event_utils.h" |
18 #include "ui/events/keycodes/keyboard_code_conversion_win.h" | 24 #include "ui/events/keycodes/keyboard_code_conversion_win.h" |
19 #include "ui/base/view_prop.h" | 25 #include "ui/base/view_prop.h" |
20 #include "ui/gfx/insets.h" | 26 #include "ui/gfx/insets.h" |
21 #include "ui/metro_viewer/metro_viewer_messages.h" | 27 #include "ui/metro_viewer/metro_viewer_messages.h" |
22 | 28 |
23 namespace aura { | 29 namespace aura { |
24 | 30 |
25 namespace { | 31 namespace { |
26 | 32 |
(...skipping 20 matching lines...) Expand all Loading... |
47 SetKeyState(keyboard_state, !!(flags & ui::EF_CAPS_LOCK_DOWN), VK_CAPITAL); | 53 SetKeyState(keyboard_state, !!(flags & ui::EF_CAPS_LOCK_DOWN), VK_CAPITAL); |
48 SetKeyState(keyboard_state, !!(flags & ui::EF_LEFT_MOUSE_BUTTON), VK_LBUTTON); | 54 SetKeyState(keyboard_state, !!(flags & ui::EF_LEFT_MOUSE_BUTTON), VK_LBUTTON); |
49 SetKeyState(keyboard_state, !!(flags & ui::EF_RIGHT_MOUSE_BUTTON), | 55 SetKeyState(keyboard_state, !!(flags & ui::EF_RIGHT_MOUSE_BUTTON), |
50 VK_RBUTTON); | 56 VK_RBUTTON); |
51 SetKeyState(keyboard_state, !!(flags & ui::EF_MIDDLE_MOUSE_BUTTON), | 57 SetKeyState(keyboard_state, !!(flags & ui::EF_MIDDLE_MOUSE_BUTTON), |
52 VK_MBUTTON); | 58 VK_MBUTTON); |
53 | 59 |
54 ::SetKeyboardState(keyboard_state); | 60 ::SetKeyboardState(keyboard_state); |
55 } | 61 } |
56 | 62 |
| 63 void FillCompositionText( |
| 64 const string16& text, |
| 65 int32 selection_start, |
| 66 int32 selection_end, |
| 67 const std::vector<metro_viewer::UnderlineInfo>& underlines, |
| 68 ui::CompositionText* composition_text) { |
| 69 composition_text->Clear(); |
| 70 composition_text->text = text; |
| 71 composition_text->selection.set_start(selection_start); |
| 72 composition_text->selection.set_end(selection_end); |
| 73 composition_text->underlines.resize(underlines.size()); |
| 74 for (size_t i = 0; i < underlines.size(); ++i) { |
| 75 composition_text->underlines[i].start_offset = underlines[i].start_offset; |
| 76 composition_text->underlines[i].end_offset = underlines[i].end_offset; |
| 77 composition_text->underlines[i].color = SK_ColorBLACK; |
| 78 composition_text->underlines[i].thick = underlines[i].thick; |
| 79 } |
| 80 } |
| 81 |
57 } // namespace | 82 } // namespace |
58 | 83 |
59 void HandleOpenFile(const base::string16& title, | 84 void HandleOpenFile(const base::string16& title, |
60 const base::FilePath& default_path, | 85 const base::FilePath& default_path, |
61 const base::string16& filter, | 86 const base::string16& filter, |
62 const OpenFileCompletion& on_success, | 87 const OpenFileCompletion& on_success, |
63 const FileSelectionCanceled& on_failure) { | 88 const FileSelectionCanceled& on_failure) { |
64 DCHECK(aura::RemoteRootWindowHostWin::Instance()); | 89 DCHECK(aura::RemoteRootWindowHostWin::Instance()); |
65 aura::RemoteRootWindowHostWin::Instance()->HandleOpenFile(title, | 90 aura::RemoteRootWindowHostWin::Instance()->HandleOpenFile(title, |
66 default_path, | 91 default_path, |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 | 170 |
146 void RemoteRootWindowHostWin::Connected(IPC::Sender* host, HWND remote_window) { | 171 void RemoteRootWindowHostWin::Connected(IPC::Sender* host, HWND remote_window) { |
147 CHECK(host_ == NULL); | 172 CHECK(host_ == NULL); |
148 host_ = host; | 173 host_ = host; |
149 remote_window_ = remote_window; | 174 remote_window_ = remote_window; |
150 } | 175 } |
151 | 176 |
152 void RemoteRootWindowHostWin::Disconnected() { | 177 void RemoteRootWindowHostWin::Disconnected() { |
153 // Don't CHECK here, Disconnected is called on a channel error which can | 178 // Don't CHECK here, Disconnected is called on a channel error which can |
154 // happen before we're successfully Connected. | 179 // happen before we're successfully Connected. |
| 180 ui::RemoteInputMethodPrivateWin* remote_input_method_private = |
| 181 GetRemoteInputMethodPrivate(); |
| 182 if (remote_input_method_private) |
| 183 remote_input_method_private->SetRemoteDelegate(NULL); |
155 host_ = NULL; | 184 host_ = NULL; |
156 remote_window_ = NULL; | 185 remote_window_ = NULL; |
157 } | 186 } |
158 | 187 |
159 bool RemoteRootWindowHostWin::OnMessageReceived(const IPC::Message& message) { | 188 bool RemoteRootWindowHostWin::OnMessageReceived(const IPC::Message& message) { |
160 bool handled = true; | 189 bool handled = true; |
161 IPC_BEGIN_MESSAGE_MAP(RemoteRootWindowHostWin, message) | 190 IPC_BEGIN_MESSAGE_MAP(RemoteRootWindowHostWin, message) |
162 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_MouseMoved, OnMouseMoved) | 191 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_MouseMoved, OnMouseMoved) |
163 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_MouseButton, OnMouseButton) | 192 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_MouseButton, OnMouseButton) |
164 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_KeyDown, OnKeyDown) | 193 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_KeyDown, OnKeyDown) |
(...skipping 12 matching lines...) Expand all Loading... |
177 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_FileOpenDone, | 206 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_FileOpenDone, |
178 OnFileOpenDone) | 207 OnFileOpenDone) |
179 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_MultiFileOpenDone, | 208 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_MultiFileOpenDone, |
180 OnMultiFileOpenDone) | 209 OnMultiFileOpenDone) |
181 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_SelectFolderDone, | 210 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_SelectFolderDone, |
182 OnSelectFolderDone) | 211 OnSelectFolderDone) |
183 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_SetCursorPosAck, | 212 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_SetCursorPosAck, |
184 OnSetCursorPosAck) | 213 OnSetCursorPosAck) |
185 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_ActivateDesktopDone, | 214 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_ActivateDesktopDone, |
186 OnDesktopActivated) | 215 OnDesktopActivated) |
| 216 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_ImeCompositionChanged, |
| 217 OnImeCompositionChanged) |
| 218 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_ImeTextCommitted, |
| 219 OnImeTextCommitted) |
187 IPC_MESSAGE_UNHANDLED(handled = false) | 220 IPC_MESSAGE_UNHANDLED(handled = false) |
188 IPC_END_MESSAGE_MAP() | 221 IPC_END_MESSAGE_MAP() |
189 return handled; | 222 return handled; |
190 } | 223 } |
191 | 224 |
192 void RemoteRootWindowHostWin::HandleOpenURLOnDesktop( | 225 void RemoteRootWindowHostWin::HandleOpenURLOnDesktop( |
193 const base::FilePath& shortcut, | 226 const base::FilePath& shortcut, |
194 const base::string16& url) { | 227 const base::string16& url) { |
195 if (!host_) | 228 if (!host_) |
196 return; | 229 return; |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 } | 344 } |
312 | 345 |
313 gfx::AcceleratedWidget RemoteRootWindowHostWin::GetAcceleratedWidget() { | 346 gfx::AcceleratedWidget RemoteRootWindowHostWin::GetAcceleratedWidget() { |
314 if (remote_window_) | 347 if (remote_window_) |
315 return remote_window_; | 348 return remote_window_; |
316 // Getting here should only happen for ash_unittests.exe and related code. | 349 // Getting here should only happen for ash_unittests.exe and related code. |
317 return ::GetDesktopWindow(); | 350 return ::GetDesktopWindow(); |
318 } | 351 } |
319 | 352 |
320 void RemoteRootWindowHostWin::Show() { | 353 void RemoteRootWindowHostWin::Show() { |
| 354 ui::RemoteInputMethodPrivateWin* remote_input_method_private = |
| 355 GetRemoteInputMethodPrivate(); |
| 356 if (remote_input_method_private) |
| 357 remote_input_method_private->SetRemoteDelegate(this); |
321 } | 358 } |
322 | 359 |
323 void RemoteRootWindowHostWin::Hide() { | 360 void RemoteRootWindowHostWin::Hide() { |
324 NOTIMPLEMENTED(); | 361 NOTIMPLEMENTED(); |
325 } | 362 } |
326 | 363 |
327 void RemoteRootWindowHostWin::ToggleFullScreen() { | 364 void RemoteRootWindowHostWin::ToggleFullScreen() { |
328 } | 365 } |
329 | 366 |
330 gfx::Rect RemoteRootWindowHostWin::GetBounds() const { | 367 gfx::Rect RemoteRootWindowHostWin::GetBounds() const { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 } | 452 } |
416 | 453 |
417 void RemoteRootWindowHostWin::OnDeviceScaleFactorChanged( | 454 void RemoteRootWindowHostWin::OnDeviceScaleFactorChanged( |
418 float device_scale_factor) { | 455 float device_scale_factor) { |
419 NOTIMPLEMENTED(); | 456 NOTIMPLEMENTED(); |
420 } | 457 } |
421 | 458 |
422 void RemoteRootWindowHostWin::PrepareForShutdown() { | 459 void RemoteRootWindowHostWin::PrepareForShutdown() { |
423 } | 460 } |
424 | 461 |
| 462 void RemoteRootWindowHostWin::CancelComposition() { |
| 463 host_->Send(new MetroViewerHostMsg_ImeCancelComposition); |
| 464 } |
| 465 |
| 466 void RemoteRootWindowHostWin::OnTextInputClientUpdated( |
| 467 const std::vector<int32>& input_scopes, |
| 468 const std::vector<gfx::Rect>& composition_character_bounds) { |
| 469 std::vector<metro_viewer::CharacterBounds> character_bounds; |
| 470 for (size_t i = 0; i < composition_character_bounds.size(); ++i) { |
| 471 const gfx::Rect& rect = composition_character_bounds[i]; |
| 472 metro_viewer::CharacterBounds bounds; |
| 473 bounds.left = rect.x(); |
| 474 bounds.top = rect.y(); |
| 475 bounds.right = rect.right(); |
| 476 bounds.bottom = rect.bottom(); |
| 477 character_bounds.push_back(bounds); |
| 478 } |
| 479 host_->Send(new MetroViewerHostMsg_ImeTextInputClientUpdated( |
| 480 input_scopes, character_bounds)); |
| 481 } |
| 482 |
425 void RemoteRootWindowHostWin::OnMouseMoved(int32 x, int32 y, int32 flags) { | 483 void RemoteRootWindowHostWin::OnMouseMoved(int32 x, int32 y, int32 flags) { |
426 if (ignore_mouse_moves_until_set_cursor_ack_) | 484 if (ignore_mouse_moves_until_set_cursor_ack_) |
427 return; | 485 return; |
428 | 486 |
429 gfx::Point location(x, y); | 487 gfx::Point location(x, y); |
430 ui::MouseEvent event(ui::ET_MOUSE_MOVED, location, location, flags); | 488 ui::MouseEvent event(ui::ET_MOUSE_MOVED, location, location, flags); |
431 delegate_->OnHostMouseEvent(&event); | 489 delegate_->OnHostMouseEvent(&event); |
432 } | 490 } |
433 | 491 |
434 void RemoteRootWindowHostWin::OnMouseButton( | 492 void RemoteRootWindowHostWin::OnMouseButton( |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 DCHECK(ignore_mouse_moves_until_set_cursor_ack_); | 632 DCHECK(ignore_mouse_moves_until_set_cursor_ack_); |
575 ignore_mouse_moves_until_set_cursor_ack_ = false; | 633 ignore_mouse_moves_until_set_cursor_ack_ = false; |
576 } | 634 } |
577 | 635 |
578 void RemoteRootWindowHostWin::OnDesktopActivated() { | 636 void RemoteRootWindowHostWin::OnDesktopActivated() { |
579 ActivateDesktopCompleted temp = activate_completed_callback_; | 637 ActivateDesktopCompleted temp = activate_completed_callback_; |
580 activate_completed_callback_.Reset(); | 638 activate_completed_callback_.Reset(); |
581 temp.Run(); | 639 temp.Run(); |
582 } | 640 } |
583 | 641 |
| 642 ui::RemoteInputMethodPrivateWin* |
| 643 RemoteRootWindowHostWin::GetRemoteInputMethodPrivate() { |
| 644 ui::InputMethod* input_method = GetAshWindow()->GetProperty( |
| 645 aura::client::kRootWindowInputMethodKey); |
| 646 return ui::RemoteInputMethodPrivateWin::Get(input_method); |
| 647 } |
| 648 |
| 649 void RemoteRootWindowHostWin::OnImeCompositionChanged( |
| 650 const string16& text, |
| 651 int32 selection_start, |
| 652 int32 selection_end, |
| 653 const std::vector<metro_viewer::UnderlineInfo>& underlines) { |
| 654 ui::RemoteInputMethodPrivateWin* remote_input_method_private = |
| 655 GetRemoteInputMethodPrivate(); |
| 656 if (!remote_input_method_private) |
| 657 return; |
| 658 ui::CompositionText composition_text; |
| 659 FillCompositionText( |
| 660 text, selection_start, selection_end, underlines, &composition_text); |
| 661 remote_input_method_private->OnCompositionChanged(composition_text); |
| 662 } |
| 663 |
| 664 void RemoteRootWindowHostWin::OnImeTextCommitted(const string16& text) { |
| 665 ui::RemoteInputMethodPrivateWin* remote_input_method_private = |
| 666 GetRemoteInputMethodPrivate(); |
| 667 if (!remote_input_method_private) |
| 668 return; |
| 669 remote_input_method_private->OnTextCommitted(text); |
| 670 } |
| 671 |
584 void RemoteRootWindowHostWin::DispatchKeyboardMessage(ui::EventType type, | 672 void RemoteRootWindowHostWin::DispatchKeyboardMessage(ui::EventType type, |
585 uint32 vkey, | 673 uint32 vkey, |
586 uint32 repeat_count, | 674 uint32 repeat_count, |
587 uint32 scan_code, | 675 uint32 scan_code, |
588 uint32 flags, | 676 uint32 flags, |
589 bool is_character) { | 677 bool is_character) { |
590 SetEventFlags(flags | mouse_event_flags()); | 678 SetEventFlags(flags | mouse_event_flags()); |
591 if (base::MessageLoop::current()->IsNested()) { | 679 if (base::MessageLoop::current()->IsNested()) { |
592 uint32 message = is_character ? WM_CHAR : | 680 uint32 message = is_character ? WM_CHAR : |
593 (type == ui::ET_KEY_PRESSED ? WM_KEYDOWN : WM_KEYUP); | 681 (type == ui::ET_KEY_PRESSED ? WM_KEYDOWN : WM_KEYUP); |
(...skipping 11 matching lines...) Expand all Loading... |
605 } | 693 } |
606 | 694 |
607 void RemoteRootWindowHostWin::SetEventFlags(uint32 flags) { | 695 void RemoteRootWindowHostWin::SetEventFlags(uint32 flags) { |
608 if (flags == event_flags_) | 696 if (flags == event_flags_) |
609 return; | 697 return; |
610 event_flags_ = flags; | 698 event_flags_ = flags; |
611 SetVirtualKeyStates(event_flags_); | 699 SetVirtualKeyStates(event_flags_); |
612 } | 700 } |
613 | 701 |
614 } // namespace aura | 702 } // namespace aura |
OLD | NEW |