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

Side by Side Diff: views/widget/widget_win.cc

Issue 6675005: Integrate the new input method API for Views into Chromium. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add some DCHECKs. Created 9 years, 9 months 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 | Annotate | Revision Log
« views/widget/widget_gtk.cc ('K') | « views/widget/widget_win.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "views/widget/widget_win.h" 5 #include "views/widget/widget_win.h"
6 6
7 #include <dwmapi.h> 7 #include <dwmapi.h>
8 8
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/win/windows_version.h" 10 #include "base/win/windows_version.h"
11 #include "ui/base/dragdrop/drag_drop_types.h" 11 #include "ui/base/dragdrop/drag_drop_types.h"
12 #include "ui/base/dragdrop/drag_source.h" 12 #include "ui/base/dragdrop/drag_source.h"
13 #include "ui/base/dragdrop/os_exchange_data.h" 13 #include "ui/base/dragdrop/os_exchange_data.h"
14 #include "ui/base/dragdrop/os_exchange_data_provider_win.h" 14 #include "ui/base/dragdrop/os_exchange_data_provider_win.h"
15 #include "ui/base/keycodes/keyboard_code_conversion_win.h" 15 #include "ui/base/keycodes/keyboard_code_conversion_win.h"
16 #include "ui/base/l10n/l10n_util_win.h" 16 #include "ui/base/l10n/l10n_util_win.h"
17 #include "ui/base/system_monitor/system_monitor.h" 17 #include "ui/base/system_monitor/system_monitor.h"
18 #include "ui/base/theme_provider.h" 18 #include "ui/base/theme_provider.h"
19 #include "ui/base/view_prop.h" 19 #include "ui/base/view_prop.h"
20 #include "ui/base/win/hwnd_util.h" 20 #include "ui/base/win/hwnd_util.h"
21 #include "ui/gfx/canvas_skia.h" 21 #include "ui/gfx/canvas_skia.h"
22 #include "ui/gfx/native_theme_win.h" 22 #include "ui/gfx/native_theme_win.h"
23 #include "ui/gfx/path.h" 23 #include "ui/gfx/path.h"
24 #include "views/accessibility/native_view_accessibility_win.h" 24 #include "views/accessibility/native_view_accessibility_win.h"
25 #include "views/controls/native_control_win.h" 25 #include "views/controls/native_control_win.h"
26 #include "views/focus/accelerator_handler.h" 26 #include "views/focus/accelerator_handler.h"
27 #include "views/focus/focus_util_win.h" 27 #include "views/focus/focus_util_win.h"
28 #include "views/focus/view_storage.h" 28 #include "views/focus/view_storage.h"
29 #include "views/ime/input_method_win.h"
29 #include "views/views_delegate.h" 30 #include "views/views_delegate.h"
30 #include "views/widget/aero_tooltip_manager.h" 31 #include "views/widget/aero_tooltip_manager.h"
31 #include "views/widget/child_window_message_processor.h" 32 #include "views/widget/child_window_message_processor.h"
32 #include "views/widget/drop_target_win.h" 33 #include "views/widget/drop_target_win.h"
33 #include "views/widget/native_widget_delegate.h" 34 #include "views/widget/native_widget_delegate.h"
34 #include "views/widget/root_view.h" 35 #include "views/widget/root_view.h"
35 #include "views/widget/widget_delegate.h" 36 #include "views/widget/widget_delegate.h"
36 #include "views/window/window_win.h" 37 #include "views/window/window_win.h"
37 38
38 #pragma comment(lib, "dwmapi.lib") 39 #pragma comment(lib, "dwmapi.lib")
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 layered_alpha_(255), 139 layered_alpha_(255),
139 ALLOW_THIS_IN_INITIALIZER_LIST(paint_layered_window_factory_(this)), 140 ALLOW_THIS_IN_INITIALIZER_LIST(paint_layered_window_factory_(this)),
140 delete_on_destroy_(true), 141 delete_on_destroy_(true),
141 can_update_layered_window_(true), 142 can_update_layered_window_(true),
142 last_mouse_event_was_move_(false), 143 last_mouse_event_was_move_(false),
143 is_mouse_down_(false), 144 is_mouse_down_(false),
144 is_window_(false), 145 is_window_(false),
145 restore_focus_when_enabled_(false), 146 restore_focus_when_enabled_(false),
146 accessibility_view_events_index_(-1), 147 accessibility_view_events_index_(-1),
147 accessibility_view_events_(kMaxAccessibilityViewEvents), 148 accessibility_view_events_(kMaxAccessibilityViewEvents),
148 previous_cursor_(NULL) { 149 previous_cursor_(NULL),
150 is_input_method_win_(false) {
149 set_native_widget(this); 151 set_native_widget(this);
150 } 152 }
151 153
152 WidgetWin::~WidgetWin() { 154 WidgetWin::~WidgetWin() {
153 DestroyRootView(); 155 DestroyRootView();
154 } 156 }
155 157
156 void WidgetWin::SetCreateParams(const CreateParams& params) { 158 void WidgetWin::SetCreateParams(const CreateParams& params) {
157 // Set non-style attributes. 159 // Set non-style attributes.
158 set_delete_on_destroy(params.delete_on_destroy); 160 set_delete_on_destroy(params.delete_on_destroy);
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 } 327 }
326 328
327 void WidgetWin::ReleaseNativeCapture() { 329 void WidgetWin::ReleaseNativeCapture() {
328 ReleaseCapture(); 330 ReleaseCapture();
329 } 331 }
330 332
331 bool WidgetWin::HasNativeCapture() const { 333 bool WidgetWin::HasNativeCapture() const {
332 return GetCapture() == hwnd(); 334 return GetCapture() == hwnd();
333 } 335 }
334 336
337 InputMethod* WidgetWin::GetInputMethodNative() {
338 return input_method_.get();
339 }
340
341 void WidgetWin::ReplaceInputMethod(InputMethod* input_method) {
342 input_method_.reset(input_method);
343 if (input_method) {
344 input_method->set_delegate(this);
345 input_method->Init(GetWidget());
346 }
347 is_input_method_win_ = false;
348 }
349
335 gfx::Rect WidgetWin::GetWindowScreenBounds() const { 350 gfx::Rect WidgetWin::GetWindowScreenBounds() const {
336 RECT r; 351 RECT r;
337 GetWindowRect(&r); 352 GetWindowRect(&r);
338 return gfx::Rect(r); 353 return gfx::Rect(r);
339 } 354 }
340 355
341 gfx::Rect WidgetWin::GetClientAreaScreenBounds() const { 356 gfx::Rect WidgetWin::GetClientAreaScreenBounds() const {
342 RECT r; 357 RECT r;
343 GetClientRect(&r); 358 GetClientRect(&r);
344 POINT point = { r.left, r.top }; 359 POINT point = { r.left, r.top };
(...skipping 30 matching lines...) Expand all
375 // we don't destroy the window before the callback returned (as the caller 390 // we don't destroy the window before the callback returned (as the caller
376 // may delete ourselves on destroy and the ATL callback would still 391 // may delete ourselves on destroy and the ATL callback would still
377 // dereference us when the callback returns). 392 // dereference us when the callback returns).
378 MessageLoop::current()->PostTask(FROM_HERE, 393 MessageLoop::current()->PostTask(FROM_HERE,
379 close_widget_factory_.NewRunnableMethod( 394 close_widget_factory_.NewRunnableMethod(
380 &WidgetWin::CloseNow)); 395 &WidgetWin::CloseNow));
381 } 396 }
382 } 397 }
383 398
384 void WidgetWin::CloseNow() { 399 void WidgetWin::CloseNow() {
400 // Destroys the input method before closing the window so that it can be
401 // detached from the widget correctly.
402 input_method_.reset();
403 is_input_method_win_ = false;
404
385 // We may already have been destroyed if the selection resulted in a tab 405 // We may already have been destroyed if the selection resulted in a tab
386 // switch which will have reactivated the browser window and closed us, so 406 // switch which will have reactivated the browser window and closed us, so
387 // we need to check to see if we're still a window before trying to destroy 407 // we need to check to see if we're still a window before trying to destroy
388 // ourself. 408 // ourself.
389 if (IsWindow()) 409 if (IsWindow())
390 DestroyWindow(hwnd()); 410 DestroyWindow(hwnd());
391 } 411 }
392 412
393 void WidgetWin::Show() { 413 void WidgetWin::Show() {
394 if (IsWindow()) 414 if (IsWindow())
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 // Bug 964884: detach the IME attached to this window. 634 // Bug 964884: detach the IME attached to this window.
615 // We should attach IMEs only when we need to input CJK strings. 635 // We should attach IMEs only when we need to input CJK strings.
616 ImmAssociateContextEx(hwnd(), NULL, 0); 636 ImmAssociateContextEx(hwnd(), NULL, 0);
617 637
618 // We need to allow the delegate to size its contents since the window may not 638 // We need to allow the delegate to size its contents since the window may not
619 // receive a size notification when its initial bounds are specified at window 639 // receive a size notification when its initial bounds are specified at window
620 // creation time. 640 // creation time.
621 ClientAreaSizeChanged(); 641 ClientAreaSizeChanged();
622 642
623 delegate_->OnNativeWidgetCreated(); 643 delegate_->OnNativeWidgetCreated();
644
645 // delegate_->OnNativeWidgetCreated() creates the focus manager for top-level
646 // widget. Only top-level widget should have an input method.
647 if (delegate_->HasFocusManager()) {
648 input_method_.reset(new InputMethodWin(this));
649 input_method_->Init(GetWidget());
650 is_input_method_win_ = true;
651 }
624 return 0; 652 return 0;
625 } 653 }
626 654
627 void WidgetWin::OnDestroy() { 655 void WidgetWin::OnDestroy() {
628 if (drop_target_.get()) { 656 if (drop_target_.get()) {
629 RevokeDragDrop(hwnd()); 657 RevokeDragDrop(hwnd());
630 drop_target_ = NULL; 658 drop_target_ = NULL;
631 } 659 }
632 660
633 props_.reset(); 661 props_.reset();
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 } 721 }
694 722
695 void WidgetWin::OnGetMinMaxInfo(MINMAXINFO* minmax_info) { 723 void WidgetWin::OnGetMinMaxInfo(MINMAXINFO* minmax_info) {
696 SetMsgHandled(FALSE); 724 SetMsgHandled(FALSE);
697 } 725 }
698 726
699 void WidgetWin::OnHScroll(int scroll_type, short position, HWND scrollbar) { 727 void WidgetWin::OnHScroll(int scroll_type, short position, HWND scrollbar) {
700 SetMsgHandled(FALSE); 728 SetMsgHandled(FALSE);
701 } 729 }
702 730
731 LRESULT WidgetWin::OnImeMessages(UINT message, WPARAM w_param, LPARAM l_param) {
732 if (!is_input_method_win_) {
733 SetMsgHandled(FALSE);
734 return 0;
735 }
736
737 InputMethodWin* ime = static_cast<InputMethodWin*>(input_method_.get());
738 BOOL handled = FALSE;
739 LRESULT result = 0;
740 switch (message) {
741 case WM_IME_SETCONTEXT:
742 result = ime->OnImeSetContext(message, w_param, l_param, &handled);
743 break;
744 case WM_IME_STARTCOMPOSITION:
745 result = ime->OnImeStartComposition(message, w_param, l_param, &handled);
746 break;
747 case WM_IME_COMPOSITION:
748 result = ime->OnImeComposition(message, w_param, l_param, &handled);
749 break;
750 case WM_IME_ENDCOMPOSITION:
751 result = ime->OnImeEndComposition(message, w_param, l_param, &handled);
752 break;
753 case WM_CHAR:
754 case WM_SYSCHAR:
755 result = ime->OnChar(message, w_param, l_param, &handled);
756 break;
757 case WM_DEADCHAR:
758 case WM_SYSDEADCHAR:
759 result = ime->OnDeadChar(message, w_param, l_param, &handled);
760 break;
761 default:
762 NOTREACHED() << "Unknown IME message:" << message;
763 break;
764 }
765
766 SetMsgHandled(handled);
767 return result;
768 }
769
703 void WidgetWin::OnInitMenu(HMENU menu) { 770 void WidgetWin::OnInitMenu(HMENU menu) {
704 SetMsgHandled(FALSE); 771 SetMsgHandled(FALSE);
705 } 772 }
706 773
707 void WidgetWin::OnInitMenuPopup(HMENU menu, 774 void WidgetWin::OnInitMenuPopup(HMENU menu,
708 UINT position, 775 UINT position,
709 BOOL is_system_menu) { 776 BOOL is_system_menu) {
710 SetMsgHandled(FALSE); 777 SetMsgHandled(FALSE);
711 } 778 }
712 779
780 void WidgetWin::OnInputLangChange(DWORD character_set, HKL input_language_id) {
781 if (is_input_method_win_) {
782 static_cast<InputMethodWin*>(input_method_.get())->OnInputLangChange(
783 character_set, input_language_id);
784 }
785 }
786
713 LRESULT WidgetWin::OnKeyDown(UINT message, WPARAM w_param, LPARAM l_param) { 787 LRESULT WidgetWin::OnKeyDown(UINT message, WPARAM w_param, LPARAM l_param) {
714 RootView* root_view = GetFocusedViewRootView();
715 if (!root_view)
716 root_view = GetRootView();
717
718 MSG msg; 788 MSG msg;
719 MakeMSG(&msg, message, w_param, l_param); 789 MakeMSG(&msg, message, w_param, l_param);
720 SetMsgHandled(root_view->ProcessKeyEvent(KeyEvent(msg))); 790 KeyEvent key(msg);
791 if (input_method_.get())
792 input_method_->DispatchKeyEvent(key);
793 else
794 DispatchKeyEventPostIME(key);
721 return 0; 795 return 0;
722 } 796 }
723 797
724 LRESULT WidgetWin::OnKeyUp(UINT message, WPARAM w_param, LPARAM l_param) { 798 LRESULT WidgetWin::OnKeyUp(UINT message, WPARAM w_param, LPARAM l_param) {
725 RootView* root_view = GetFocusedViewRootView();
726 if (!root_view)
727 root_view = GetRootView();
728
729 MSG msg; 799 MSG msg;
730 MakeMSG(&msg, message, w_param, l_param); 800 MakeMSG(&msg, message, w_param, l_param);
731 SetMsgHandled(root_view->ProcessKeyEvent(KeyEvent(msg))); 801 KeyEvent key(msg);
802 if (input_method_.get())
803 input_method_->DispatchKeyEvent(key);
804 else
805 DispatchKeyEventPostIME(key);
732 return 0; 806 return 0;
733 } 807 }
734 808
735 void WidgetWin::OnKillFocus(HWND focused_window) { 809 void WidgetWin::OnKillFocus(HWND focused_window) {
736 delegate_->OnNativeBlur(focused_window); 810 delegate_->OnNativeBlur(focused_window);
811 if (is_input_method_win_)
812 static_cast<InputMethodWin*>(input_method_.get())->OnKillFocus();
737 SetMsgHandled(FALSE); 813 SetMsgHandled(FALSE);
738 } 814 }
739 815
740 LRESULT WidgetWin::OnMouseActivate(UINT message, 816 LRESULT WidgetWin::OnMouseActivate(UINT message,
741 WPARAM w_param, 817 WPARAM w_param,
742 LPARAM l_param) { 818 LPARAM l_param) {
743 SetMsgHandled(FALSE); 819 SetMsgHandled(FALSE);
744 return MA_ACTIVATE; 820 return MA_ACTIVATE;
745 } 821 }
746 822
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 980
905 LRESULT WidgetWin::OnReflectedMessage(UINT msg, 981 LRESULT WidgetWin::OnReflectedMessage(UINT msg,
906 WPARAM w_param, 982 WPARAM w_param,
907 LPARAM l_param) { 983 LPARAM l_param) {
908 SetMsgHandled(FALSE); 984 SetMsgHandled(FALSE);
909 return 0; 985 return 0;
910 } 986 }
911 987
912 void WidgetWin::OnSetFocus(HWND focused_window) { 988 void WidgetWin::OnSetFocus(HWND focused_window) {
913 delegate_->OnNativeFocus(focused_window); 989 delegate_->OnNativeFocus(focused_window);
990 if (is_input_method_win_)
991 static_cast<InputMethodWin*>(input_method_.get())->OnSetFocus();
914 SetMsgHandled(FALSE); 992 SetMsgHandled(FALSE);
915 } 993 }
916 994
917 LRESULT WidgetWin::OnSetIcon(UINT size_type, HICON new_icon) { 995 LRESULT WidgetWin::OnSetIcon(UINT size_type, HICON new_icon) {
918 SetMsgHandled(FALSE); 996 SetMsgHandled(FALSE);
919 return 0; 997 return 0;
920 } 998 }
921 999
922 LRESULT WidgetWin::OnSetText(const wchar_t* text) { 1000 LRESULT WidgetWin::OnSetText(const wchar_t* text) {
923 SetMsgHandled(FALSE); 1001 SetMsgHandled(FALSE);
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
1186 layered_window_contents_.reset( 1264 layered_window_contents_.reset(
1187 new gfx::CanvasSkia(s.width(), s.height(), false)); 1265 new gfx::CanvasSkia(s.width(), s.height(), false));
1188 } 1266 }
1189 } 1267 }
1190 1268
1191 gfx::AcceleratedWidget WidgetWin::GetAcceleratedWidget() { 1269 gfx::AcceleratedWidget WidgetWin::GetAcceleratedWidget() {
1192 // TODO(beng): 1270 // TODO(beng):
1193 return gfx::kNullAcceleratedWidget; 1271 return gfx::kNullAcceleratedWidget;
1194 } 1272 }
1195 1273
1274 void WidgetWin::DispatchKeyEventPostIME(const KeyEvent& key) {
1275 RootView* root_view = GetFocusedViewRootView();
1276 if (!root_view)
1277 root_view = GetRootView();
1278
1279 SetMsgHandled(root_view->ProcessKeyEvent(key));
1280 }
1281
1196 //////////////////////////////////////////////////////////////////////////////// 1282 ////////////////////////////////////////////////////////////////////////////////
1197 // Widget, public: 1283 // Widget, public:
1198 1284
1199 // static 1285 // static
1200 Widget* Widget::CreatePopupWidget(const CreateParams& params) { 1286 Widget* Widget::CreatePopupWidget(const CreateParams& params) {
1201 WidgetWin* popup = new WidgetWin; 1287 WidgetWin* popup = new WidgetWin;
1202 popup->SetCreateParams(params); 1288 popup->SetCreateParams(params);
1203 return popup; 1289 return popup;
1204 } 1290 }
1205 1291
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1258 return; 1344 return;
1259 1345
1260 NativeWidget* native_widget = GetNativeWidgetForNativeView(native_view); 1346 NativeWidget* native_widget = GetNativeWidgetForNativeView(native_view);
1261 if (native_widget) 1347 if (native_widget)
1262 children->insert(native_widget); 1348 children->insert(native_widget);
1263 EnumChildWindows(native_view, EnumerateChildWindowsForNativeWidgets, 1349 EnumChildWindows(native_view, EnumerateChildWindowsForNativeWidgets,
1264 reinterpret_cast<LPARAM>(children)); 1350 reinterpret_cast<LPARAM>(children));
1265 } 1351 }
1266 1352
1267 } // namespace views 1353 } // namespace views
OLDNEW
« views/widget/widget_gtk.cc ('K') | « views/widget/widget_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698