Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1001)

Side by Side Diff: win8/metro_driver/chrome_app_view_ash.cc

Issue 83233002: Enable basic IME functionality under Ash on Windows (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comment from ananta. Add text_service_delegate.h, which I forgot to upload. Style fixes. Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "win8/metro_driver/stdafx.h" 5 #include "win8/metro_driver/stdafx.h"
6 #include "win8/metro_driver/chrome_app_view_ash.h" 6 #include "win8/metro_driver/chrome_app_view_ash.h"
7 7
8 #include <corewindow.h> 8 #include <corewindow.h>
9 #include <shellapi.h> 9 #include <shellapi.h>
10 #include <windows.foundation.h> 10 #include <windows.foundation.h>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
15 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
16 #include "base/path_service.h" 16 #include "base/path_service.h"
17 #include "base/threading/thread.h" 17 #include "base/threading/thread.h"
18 #include "base/win/metro.h" 18 #include "base/win/metro.h"
19 #include "base/win/win_util.h" 19 #include "base/win/win_util.h"
20 #include "chrome/common/chrome_switches.h" 20 #include "chrome/common/chrome_switches.h"
21 #include "ipc/ipc_channel.h" 21 #include "ipc/ipc_channel.h"
22 #include "ipc/ipc_channel_proxy.h" 22 #include "ipc/ipc_channel_proxy.h"
23 #include "ipc/ipc_sender.h" 23 #include "ipc/ipc_sender.h"
24 #include "ui/events/gestures/gesture_sequence.h" 24 #include "ui/events/gestures/gesture_sequence.h"
25 #include "ui/metro_viewer/metro_viewer_messages.h" 25 #include "ui/metro_viewer/metro_viewer_messages.h"
26 #include "win8/metro_driver/file_picker_ash.h" 26 #include "win8/metro_driver/file_picker_ash.h"
27 #include "win8/metro_driver/ime/text_service.h"
27 #include "win8/metro_driver/metro_driver.h" 28 #include "win8/metro_driver/metro_driver.h"
28 #include "win8/metro_driver/winrt_utils.h" 29 #include "win8/metro_driver/winrt_utils.h"
29 #include "win8/viewer/metro_viewer_constants.h" 30 #include "win8/viewer/metro_viewer_constants.h"
30 31
31 typedef winfoundtn::ITypedEventHandler< 32 typedef winfoundtn::ITypedEventHandler<
32 winapp::Core::CoreApplicationView*, 33 winapp::Core::CoreApplicationView*,
33 winapp::Activation::IActivatedEventArgs*> ActivatedHandler; 34 winapp::Activation::IActivatedEventArgs*> ActivatedHandler;
34 35
35 typedef winfoundtn::ITypedEventHandler< 36 typedef winfoundtn::ITypedEventHandler<
36 winui::Core::CoreWindow*, 37 winui::Core::CoreWindow*,
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_OpenURLOnDesktop, 158 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_OpenURLOnDesktop,
158 OnOpenURLOnDesktop) 159 OnOpenURLOnDesktop)
159 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_SetCursor, OnSetCursor) 160 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_SetCursor, OnSetCursor)
160 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_DisplayFileOpen, 161 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_DisplayFileOpen,
161 OnDisplayFileOpenDialog) 162 OnDisplayFileOpenDialog)
162 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_DisplayFileSaveAs, 163 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_DisplayFileSaveAs,
163 OnDisplayFileSaveAsDialog) 164 OnDisplayFileSaveAsDialog)
164 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_DisplaySelectFolder, 165 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_DisplaySelectFolder,
165 OnDisplayFolderPicker) 166 OnDisplayFolderPicker)
166 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_SetCursorPos, OnSetCursorPos) 167 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_SetCursorPos, OnSetCursorPos)
168 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_ImeCancelComposition,
169 OnImeCancelComposition)
170 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_ImeTextInputClientUpdated,
171 OnImeTextInputClientChanged)
167 IPC_MESSAGE_UNHANDLED(__debugbreak()) 172 IPC_MESSAGE_UNHANDLED(__debugbreak())
168 IPC_END_MESSAGE_MAP() 173 IPC_END_MESSAGE_MAP()
169 return true; 174 return true;
170 } 175 }
171 176
172 virtual void OnChannelError() OVERRIDE { 177 virtual void OnChannelError() OVERRIDE {
173 DVLOG(1) << "Channel error. Exiting."; 178 DVLOG(1) << "Channel error. Exiting.";
174 MetroExit(app_view_->core_window_hwnd()); 179 MetroExit(app_view_->core_window_hwnd());
175 // In early Windows 8 versions the code above sometimes fails so we call 180 // In early Windows 8 versions the code above sometimes fails so we call
176 // it a second time with a NULL window which just calls Exit(). 181 // it a second time with a NULL window which just calls Exit().
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 239
235 void OnSetCursorPos(int x, int y) { 240 void OnSetCursorPos(int x, int y) {
236 VLOG(1) << "In IPC OnSetCursorPos: " << x << ", " << y; 241 VLOG(1) << "In IPC OnSetCursorPos: " << x << ", " << y;
237 ui_proxy_->PostTask( 242 ui_proxy_->PostTask(
238 FROM_HERE, 243 FROM_HERE,
239 base::Bind(&ChromeAppViewAsh::OnSetCursorPos, 244 base::Bind(&ChromeAppViewAsh::OnSetCursorPos,
240 base::Unretained(app_view_), 245 base::Unretained(app_view_),
241 x, y)); 246 x, y));
242 } 247 }
243 248
249 void OnImeCancelComposition() {
250 ui_proxy_->PostTask(
251 FROM_HERE,
252 base::Bind(&ChromeAppViewAsh::OnImeCancelComposition,
253 base::Unretained(app_view_)));
254 }
255
256 void OnImeTextInputClientChanged(
257 const std::vector<int32>& input_scopes,
258 const std::vector<metro_viewer::CharacterBounds>& character_bounds) {
259 ui_proxy_->PostTask(
260 FROM_HERE,
261 base::Bind(&ChromeAppViewAsh::OnImeUpdateTextInputClient,
262 base::Unretained(app_view_),
263 input_scopes,
264 character_bounds));
265 }
244 266
245 scoped_refptr<base::MessageLoopProxy> ui_proxy_; 267 scoped_refptr<base::MessageLoopProxy> ui_proxy_;
246 ChromeAppViewAsh* app_view_; 268 ChromeAppViewAsh* app_view_;
247 }; 269 };
248 270
249 bool WaitForChromeIPCConnection(const std::string& channel_name) { 271 bool WaitForChromeIPCConnection(const std::string& channel_name) {
250 int ms_elapsed = 0; 272 int ms_elapsed = 0;
251 while (!IPC::Channel::IsNamedServerInitialized(channel_name) && 273 while (!IPC::Channel::IsNamedServerInitialized(channel_name) &&
252 ms_elapsed < 10000) { 274 ms_elapsed < 10000) {
253 ms_elapsed += 500; 275 ms_elapsed += 500;
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 window_ = window; 487 window_ = window;
466 DVLOG(1) << __FUNCTION__; 488 DVLOG(1) << __FUNCTION__;
467 489
468 // Retrieve the native window handle via the interop layer. 490 // Retrieve the native window handle via the interop layer.
469 mswr::ComPtr<ICoreWindowInterop> interop; 491 mswr::ComPtr<ICoreWindowInterop> interop;
470 HRESULT hr = window->QueryInterface(interop.GetAddressOf()); 492 HRESULT hr = window->QueryInterface(interop.GetAddressOf());
471 CheckHR(hr); 493 CheckHR(hr);
472 hr = interop->get_WindowHandle(&core_window_hwnd_); 494 hr = interop->get_WindowHandle(&core_window_hwnd_);
473 CheckHR(hr); 495 CheckHR(hr);
474 496
497 text_service_ = metro_driver::CreateTextService(this, core_window_hwnd_);
498
475 hr = window_->add_SizeChanged(mswr::Callback<SizeChangedHandler>( 499 hr = window_->add_SizeChanged(mswr::Callback<SizeChangedHandler>(
476 this, &ChromeAppViewAsh::OnSizeChanged).Get(), 500 this, &ChromeAppViewAsh::OnSizeChanged).Get(),
477 &sizechange_token_); 501 &sizechange_token_);
478 CheckHR(hr); 502 CheckHR(hr);
479 503
480 // Register for pointer and keyboard notifications. We forward 504 // Register for pointer and keyboard notifications. We forward
481 // them to the browser process via IPC. 505 // them to the browser process via IPC.
482 hr = window_->add_PointerMoved(mswr::Callback<PointerEventHandler>( 506 hr = window_->add_PointerMoved(mswr::Callback<PointerEventHandler>(
483 this, &ChromeAppViewAsh::OnPointerMoved).Get(), 507 this, &ChromeAppViewAsh::OnPointerMoved).Get(),
484 &pointermoved_token_); 508 &pointermoved_token_);
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 ui_loop_.PostTask(FROM_HERE, base::Bind(&RunMessageLoop, dispatcher.Get())); 636 ui_loop_.PostTask(FROM_HERE, base::Bind(&RunMessageLoop, dispatcher.Get()));
613 ui_loop_.Run(); 637 ui_loop_.Run();
614 638
615 DVLOG(0) << "ProcessEvents done, hr=" << hr; 639 DVLOG(0) << "ProcessEvents done, hr=" << hr;
616 return hr; 640 return hr;
617 } 641 }
618 642
619 IFACEMETHODIMP 643 IFACEMETHODIMP
620 ChromeAppViewAsh::Uninitialize() { 644 ChromeAppViewAsh::Uninitialize() {
621 DVLOG(1) << __FUNCTION__; 645 DVLOG(1) << __FUNCTION__;
646 text_service_.reset();
622 window_ = nullptr; 647 window_ = nullptr;
623 view_ = nullptr; 648 view_ = nullptr;
624 core_window_hwnd_ = NULL; 649 core_window_hwnd_ = NULL;
625 return S_OK; 650 return S_OK;
626 } 651 }
627 652
628 // static 653 // static
629 HRESULT ChromeAppViewAsh::Unsnap() { 654 HRESULT ChromeAppViewAsh::Unsnap() {
630 mswr::ComPtr<winui::ViewManagement::IApplicationViewStatics> view_statics; 655 mswr::ComPtr<winui::ViewManagement::IApplicationViewStatics> view_statics;
631 HRESULT hr = winrt_utils::CreateActivationFactory( 656 HRESULT hr = winrt_utils::CreateActivationFactory(
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 DVLOG(1) << __FUNCTION__; 805 DVLOG(1) << __FUNCTION__;
781 DVLOG(1) << "Success: " << success; 806 DVLOG(1) << "Success: " << success;
782 if (ui_channel_) { 807 if (ui_channel_) {
783 ui_channel_->Send(new MetroViewerHostMsg_SelectFolderDone( 808 ui_channel_->Send(new MetroViewerHostMsg_SelectFolderDone(
784 success, 809 success,
785 base::FilePath(folder_picker->result()))); 810 base::FilePath(folder_picker->result())));
786 } 811 }
787 delete folder_picker; 812 delete folder_picker;
788 } 813 }
789 814
815 void ChromeAppViewAsh::OnImeCancelComposition() {
816 if (!text_service_)
ananta 2013/11/27 20:02:47 Can text_service_ be NULL here and in other Ime ha
yukawa 2013/11/28 06:06:20 Less likely but Yes. Currently metro_driver::Creat
ananta 2013/12/02 23:15:23 The LOG(ERROR) statements you have in the CreateTe
817 return;
818 text_service_->CancelComposition();
819 }
820
821 void ChromeAppViewAsh::OnImeUpdateTextInputClient(
822 const std::vector<int32>& input_scopes,
823 const std::vector<metro_viewer::CharacterBounds>& character_bounds) {
824 if (!text_service_)
825 return;
826 text_service_->OnDocumentChanged(input_scopes, character_bounds);
827 }
828
829 void ChromeAppViewAsh::OnCompositionChanged(
830 const string16& text,
831 int32 selection_start,
832 int32 selection_end,
833 const std::vector<metro_viewer::UnderlineInfo>& underlines) {
834 ui_channel_->Send(new MetroViewerHostMsg_ImeCompositionChanged(
835 text, selection_start, selection_end, underlines));
836 }
837
838 void ChromeAppViewAsh::OnTextCommitted(const string16& text) {
839 ui_channel_->Send(new MetroViewerHostMsg_ImeTextCommitted(text));
840 }
841
790 HRESULT ChromeAppViewAsh::OnActivate( 842 HRESULT ChromeAppViewAsh::OnActivate(
791 winapp::Core::ICoreApplicationView*, 843 winapp::Core::ICoreApplicationView*,
792 winapp::Activation::IActivatedEventArgs* args) { 844 winapp::Activation::IActivatedEventArgs* args) {
793 DVLOG(1) << __FUNCTION__; 845 DVLOG(1) << __FUNCTION__;
794 // Note: If doing more work in this function, you migth need to call 846 // Note: If doing more work in this function, you migth need to call
795 // get_PreviousExecutionState() and skip the work if the result is 847 // get_PreviousExecutionState() and skip the work if the result is
796 // ApplicationExecutionState_Running and globals.previous_state is too. 848 // ApplicationExecutionState_Running and globals.previous_state is too.
797 args->get_PreviousExecutionState(&globals.previous_state); 849 args->get_PreviousExecutionState(&globals.previous_state);
798 DVLOG(1) << "Previous Execution State: " << globals.previous_state; 850 DVLOG(1) << "Previous Execution State: " << globals.previous_state;
799 851
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
1026 winui::Core::CoreWindowActivationState state; 1078 winui::Core::CoreWindowActivationState state;
1027 HRESULT hr = args->get_WindowActivationState(&state); 1079 HRESULT hr = args->get_WindowActivationState(&state);
1028 if (FAILED(hr)) 1080 if (FAILED(hr))
1029 return hr; 1081 return hr;
1030 1082
1031 // Treat both full activation (Ash was reopened from the Start Screen or from 1083 // Treat both full activation (Ash was reopened from the Start Screen or from
1032 // any other Metro entry point in Windows) and pointer activation (user 1084 // any other Metro entry point in Windows) and pointer activation (user
1033 // clicked back in Ash after using another app on another monitor) the same. 1085 // clicked back in Ash after using another app on another monitor) the same.
1034 if (state == winui::Core::CoreWindowActivationState_CodeActivated || 1086 if (state == winui::Core::CoreWindowActivationState_CodeActivated ||
1035 state == winui::Core::CoreWindowActivationState_PointerActivated) { 1087 state == winui::Core::CoreWindowActivationState_PointerActivated) {
1088 if (text_service_)
1089 text_service_->OnWindowActivated();
1036 ui_channel_->Send(new MetroViewerHostMsg_WindowActivated()); 1090 ui_channel_->Send(new MetroViewerHostMsg_WindowActivated());
1037 } 1091 }
1038 return S_OK; 1092 return S_OK;
1039 } 1093 }
1040 1094
1041 HRESULT ChromeAppViewAsh::HandleSearchRequest( 1095 HRESULT ChromeAppViewAsh::HandleSearchRequest(
1042 winapp::Activation::IActivatedEventArgs* args) { 1096 winapp::Activation::IActivatedEventArgs* args) {
1043 mswr::ComPtr<winapp::Activation::ISearchActivatedEventArgs> search_args; 1097 mswr::ComPtr<winapp::Activation::ISearchActivatedEventArgs> search_args;
1044 CheckHR(args->QueryInterface( 1098 CheckHR(args->QueryInterface(
1045 winapp::Activation::IID_ISearchActivatedEventArgs, &search_args)); 1099 winapp::Activation::IID_ISearchActivatedEventArgs, &search_args));
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1136 mswr::ComPtr<winapp::Core::ICoreApplicationExit> app_exit; 1190 mswr::ComPtr<winapp::Core::ICoreApplicationExit> app_exit;
1137 CheckHR(core_app.As(&app_exit)); 1191 CheckHR(core_app.As(&app_exit));
1138 globals.app_exit = app_exit.Detach(); 1192 globals.app_exit = app_exit.Detach();
1139 } 1193 }
1140 1194
1141 IFACEMETHODIMP 1195 IFACEMETHODIMP
1142 ChromeAppViewFactory::CreateView(winapp::Core::IFrameworkView** view) { 1196 ChromeAppViewFactory::CreateView(winapp::Core::IFrameworkView** view) {
1143 *view = mswr::Make<ChromeAppViewAsh>().Detach(); 1197 *view = mswr::Make<ChromeAppViewAsh>().Detach();
1144 return (*view) ? S_OK : E_OUTOFMEMORY; 1198 return (*view) ? S_OK : E_OUTOFMEMORY;
1145 } 1199 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698