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

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: Rebase 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/focus/focus_manager.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/controls/textfield/native_textfield_views.h"
26 #include "views/focus/accelerator_handler.h" 27 #include "views/focus/accelerator_handler.h"
27 #include "views/focus/focus_util_win.h" 28 #include "views/focus/focus_util_win.h"
28 #include "views/focus/view_storage.h" 29 #include "views/focus/view_storage.h"
30 #include "views/ime/input_method_win.h"
29 #include "views/views_delegate.h" 31 #include "views/views_delegate.h"
30 #include "views/widget/aero_tooltip_manager.h" 32 #include "views/widget/aero_tooltip_manager.h"
31 #include "views/widget/child_window_message_processor.h" 33 #include "views/widget/child_window_message_processor.h"
32 #include "views/widget/drop_target_win.h" 34 #include "views/widget/drop_target_win.h"
33 #include "views/widget/native_widget_delegate.h" 35 #include "views/widget/native_widget_delegate.h"
34 #include "views/widget/root_view.h" 36 #include "views/widget/root_view.h"
35 #include "views/widget/widget_delegate.h" 37 #include "views/widget/widget_delegate.h"
36 #include "views/window/window_win.h" 38 #include "views/window/window_win.h"
37 39
38 #pragma comment(lib, "dwmapi.lib") 40 #pragma comment(lib, "dwmapi.lib")
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 layered_alpha_(255), 140 layered_alpha_(255),
139 ALLOW_THIS_IN_INITIALIZER_LIST(paint_layered_window_factory_(this)), 141 ALLOW_THIS_IN_INITIALIZER_LIST(paint_layered_window_factory_(this)),
140 delete_on_destroy_(true), 142 delete_on_destroy_(true),
141 can_update_layered_window_(true), 143 can_update_layered_window_(true),
142 last_mouse_event_was_move_(false), 144 last_mouse_event_was_move_(false),
143 is_mouse_down_(false), 145 is_mouse_down_(false),
144 is_window_(false), 146 is_window_(false),
145 restore_focus_when_enabled_(false), 147 restore_focus_when_enabled_(false),
146 accessibility_view_events_index_(-1), 148 accessibility_view_events_index_(-1),
147 accessibility_view_events_(kMaxAccessibilityViewEvents), 149 accessibility_view_events_(kMaxAccessibilityViewEvents),
148 previous_cursor_(NULL) { 150 previous_cursor_(NULL),
151 is_input_method_win_(false) {
149 set_native_widget(this); 152 set_native_widget(this);
150 } 153 }
151 154
152 WidgetWin::~WidgetWin() { 155 WidgetWin::~WidgetWin() {
156 // We need to delete the input method before calling DestroyRootView(),
157 // because it'll set focus_manager_ to NULL.
158 input_method_.reset();
153 DestroyRootView(); 159 DestroyRootView();
154 } 160 }
155 161
156 void WidgetWin::SetCreateParams(const CreateParams& params) { 162 void WidgetWin::SetCreateParams(const CreateParams& params) {
157 // Set non-style attributes. 163 // Set non-style attributes.
158 set_delete_on_destroy(params.delete_on_destroy); 164 set_delete_on_destroy(params.delete_on_destroy);
159 165
160 DWORD style = WS_CLIPCHILDREN | WS_CLIPSIBLINGS; 166 DWORD style = WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
161 DWORD ex_style = 0; 167 DWORD ex_style = 0;
162 DWORD class_style = CS_DBLCLKS; 168 DWORD class_style = CS_DBLCLKS;
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 } 333 }
328 334
329 void WidgetWin::ReleaseNativeCapture() { 335 void WidgetWin::ReleaseNativeCapture() {
330 ReleaseCapture(); 336 ReleaseCapture();
331 } 337 }
332 338
333 bool WidgetWin::HasNativeCapture() const { 339 bool WidgetWin::HasNativeCapture() const {
334 return GetCapture() == hwnd(); 340 return GetCapture() == hwnd();
335 } 341 }
336 342
343 InputMethod* WidgetWin::GetInputMethodNative() {
344 return input_method_.get();
345 }
346
347 void WidgetWin::ReplaceInputMethod(InputMethod* input_method) {
348 input_method_.reset(input_method);
349 if (input_method) {
350 input_method->set_delegate(this);
351 input_method->Init(GetWidget());
352 }
353 is_input_method_win_ = false;
354 }
355
337 gfx::Rect WidgetWin::GetWindowScreenBounds() const { 356 gfx::Rect WidgetWin::GetWindowScreenBounds() const {
338 RECT r; 357 RECT r;
339 GetWindowRect(&r); 358 GetWindowRect(&r);
340 return gfx::Rect(r); 359 return gfx::Rect(r);
341 } 360 }
342 361
343 gfx::Rect WidgetWin::GetClientAreaScreenBounds() const { 362 gfx::Rect WidgetWin::GetClientAreaScreenBounds() const {
344 RECT r; 363 RECT r;
345 GetClientRect(&r); 364 GetClientRect(&r);
346 POINT point = { r.left, r.top }; 365 POINT point = { r.left, r.top };
(...skipping 30 matching lines...) Expand all
377 // we don't destroy the window before the callback returned (as the caller 396 // we don't destroy the window before the callback returned (as the caller
378 // may delete ourselves on destroy and the ATL callback would still 397 // may delete ourselves on destroy and the ATL callback would still
379 // dereference us when the callback returns). 398 // dereference us when the callback returns).
380 MessageLoop::current()->PostTask(FROM_HERE, 399 MessageLoop::current()->PostTask(FROM_HERE,
381 close_widget_factory_.NewRunnableMethod( 400 close_widget_factory_.NewRunnableMethod(
382 &WidgetWin::CloseNow)); 401 &WidgetWin::CloseNow));
383 } 402 }
384 } 403 }
385 404
386 void WidgetWin::CloseNow() { 405 void WidgetWin::CloseNow() {
406 // Destroys the input method before closing the window so that it can be
407 // detached from the widget correctly.
408 input_method_.reset();
409 is_input_method_win_ = false;
410
387 // We may already have been destroyed if the selection resulted in a tab 411 // We may already have been destroyed if the selection resulted in a tab
388 // switch which will have reactivated the browser window and closed us, so 412 // switch which will have reactivated the browser window and closed us, so
389 // we need to check to see if we're still a window before trying to destroy 413 // we need to check to see if we're still a window before trying to destroy
390 // ourself. 414 // ourself.
391 if (IsWindow()) 415 if (IsWindow())
392 DestroyWindow(hwnd()); 416 DestroyWindow(hwnd());
393 } 417 }
394 418
395 void WidgetWin::Show() { 419 void WidgetWin::Show() {
396 if (IsWindow()) 420 if (IsWindow())
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 // Bug 964884: detach the IME attached to this window. 640 // Bug 964884: detach the IME attached to this window.
617 // We should attach IMEs only when we need to input CJK strings. 641 // We should attach IMEs only when we need to input CJK strings.
618 ImmAssociateContextEx(hwnd(), NULL, 0); 642 ImmAssociateContextEx(hwnd(), NULL, 0);
619 643
620 // We need to allow the delegate to size its contents since the window may not 644 // We need to allow the delegate to size its contents since the window may not
621 // receive a size notification when its initial bounds are specified at window 645 // receive a size notification when its initial bounds are specified at window
622 // creation time. 646 // creation time.
623 ClientAreaSizeChanged(); 647 ClientAreaSizeChanged();
624 648
625 delegate_->OnNativeWidgetCreated(); 649 delegate_->OnNativeWidgetCreated();
650
651 // delegate_->OnNativeWidgetCreated() creates the focus manager for top-level
652 // widget. Only top-level widget should have an input method.
653 if (delegate_->HasFocusManager() &&
654 NativeTextfieldViews::IsTextfieldViewsEnabled()) {
655 input_method_.reset(new InputMethodWin(this));
656 input_method_->Init(GetWidget());
657 is_input_method_win_ = true;
658 }
626 return 0; 659 return 0;
627 } 660 }
628 661
629 void WidgetWin::OnDestroy() { 662 void WidgetWin::OnDestroy() {
630 if (drop_target_.get()) { 663 if (drop_target_.get()) {
631 RevokeDragDrop(hwnd()); 664 RevokeDragDrop(hwnd());
632 drop_target_ = NULL; 665 drop_target_ = NULL;
633 } 666 }
634 667
635 props_.reset(); 668 props_.reset();
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 } 728 }
696 729
697 void WidgetWin::OnGetMinMaxInfo(MINMAXINFO* minmax_info) { 730 void WidgetWin::OnGetMinMaxInfo(MINMAXINFO* minmax_info) {
698 SetMsgHandled(FALSE); 731 SetMsgHandled(FALSE);
699 } 732 }
700 733
701 void WidgetWin::OnHScroll(int scroll_type, short position, HWND scrollbar) { 734 void WidgetWin::OnHScroll(int scroll_type, short position, HWND scrollbar) {
702 SetMsgHandled(FALSE); 735 SetMsgHandled(FALSE);
703 } 736 }
704 737
738 LRESULT WidgetWin::OnImeMessages(UINT message, WPARAM w_param, LPARAM l_param) {
739 if (!is_input_method_win_) {
740 SetMsgHandled(FALSE);
741 return 0;
742 }
743
744 InputMethodWin* ime = static_cast<InputMethodWin*>(input_method_.get());
745 BOOL handled = FALSE;
746 LRESULT result = 0;
747 switch (message) {
748 case WM_IME_SETCONTEXT:
749 result = ime->OnImeSetContext(message, w_param, l_param, &handled);
750 break;
751 case WM_IME_STARTCOMPOSITION:
752 result = ime->OnImeStartComposition(message, w_param, l_param, &handled);
753 break;
754 case WM_IME_COMPOSITION:
755 result = ime->OnImeComposition(message, w_param, l_param, &handled);
756 break;
757 case WM_IME_ENDCOMPOSITION:
758 result = ime->OnImeEndComposition(message, w_param, l_param, &handled);
759 break;
760 case WM_CHAR:
761 case WM_SYSCHAR:
762 result = ime->OnChar(message, w_param, l_param, &handled);
763 break;
764 case WM_DEADCHAR:
765 case WM_SYSDEADCHAR:
766 result = ime->OnDeadChar(message, w_param, l_param, &handled);
767 break;
768 default:
769 NOTREACHED() << "Unknown IME message:" << message;
770 break;
771 }
772
773 SetMsgHandled(handled);
774 return result;
775 }
776
705 void WidgetWin::OnInitMenu(HMENU menu) { 777 void WidgetWin::OnInitMenu(HMENU menu) {
706 SetMsgHandled(FALSE); 778 SetMsgHandled(FALSE);
707 } 779 }
708 780
709 void WidgetWin::OnInitMenuPopup(HMENU menu, 781 void WidgetWin::OnInitMenuPopup(HMENU menu,
710 UINT position, 782 UINT position,
711 BOOL is_system_menu) { 783 BOOL is_system_menu) {
712 SetMsgHandled(FALSE); 784 SetMsgHandled(FALSE);
713 } 785 }
714 786
787 void WidgetWin::OnInputLangChange(DWORD character_set, HKL input_language_id) {
788 if (is_input_method_win_) {
789 static_cast<InputMethodWin*>(input_method_.get())->OnInputLangChange(
790 character_set, input_language_id);
791 }
792 }
793
715 LRESULT WidgetWin::OnKeyDown(UINT message, WPARAM w_param, LPARAM l_param) { 794 LRESULT WidgetWin::OnKeyDown(UINT message, WPARAM w_param, LPARAM l_param) {
716 RootView* root_view = GetFocusedViewRootView();
717 if (!root_view)
718 root_view = GetRootView();
719
720 MSG msg; 795 MSG msg;
721 MakeMSG(&msg, message, w_param, l_param); 796 MakeMSG(&msg, message, w_param, l_param);
722 SetMsgHandled(root_view->ProcessKeyEvent(KeyEvent(msg))); 797 KeyEvent key(msg);
798 if (input_method_.get())
799 input_method_->DispatchKeyEvent(key);
800 else
801 DispatchKeyEventPostIME(key);
723 return 0; 802 return 0;
724 } 803 }
725 804
726 LRESULT WidgetWin::OnKeyUp(UINT message, WPARAM w_param, LPARAM l_param) { 805 LRESULT WidgetWin::OnKeyUp(UINT message, WPARAM w_param, LPARAM l_param) {
727 RootView* root_view = GetFocusedViewRootView();
728 if (!root_view)
729 root_view = GetRootView();
730
731 MSG msg; 806 MSG msg;
732 MakeMSG(&msg, message, w_param, l_param); 807 MakeMSG(&msg, message, w_param, l_param);
733 SetMsgHandled(root_view->ProcessKeyEvent(KeyEvent(msg))); 808 KeyEvent key(msg);
809 if (input_method_.get())
810 input_method_->DispatchKeyEvent(key);
811 else
812 DispatchKeyEventPostIME(key);
734 return 0; 813 return 0;
735 } 814 }
736 815
737 void WidgetWin::OnKillFocus(HWND focused_window) { 816 void WidgetWin::OnKillFocus(HWND focused_window) {
738 delegate_->OnNativeBlur(focused_window); 817 delegate_->OnNativeBlur(focused_window);
818 if (input_method_.get())
819 input_method_->OnFocusOut();
739 SetMsgHandled(FALSE); 820 SetMsgHandled(FALSE);
740 } 821 }
741 822
742 LRESULT WidgetWin::OnMouseActivate(UINT message, 823 LRESULT WidgetWin::OnMouseActivate(UINT message,
743 WPARAM w_param, 824 WPARAM w_param,
744 LPARAM l_param) { 825 LPARAM l_param) {
745 if (GetWindowLong(GWL_EXSTYLE) & WS_EX_NOACTIVATE) 826 if (GetWindowLong(GWL_EXSTYLE) & WS_EX_NOACTIVATE)
746 return MA_NOACTIVATE; 827 return MA_NOACTIVATE;
747 SetMsgHandled(FALSE); 828 SetMsgHandled(FALSE);
748 return MA_ACTIVATE; 829 return MA_ACTIVATE;
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
908 989
909 LRESULT WidgetWin::OnReflectedMessage(UINT msg, 990 LRESULT WidgetWin::OnReflectedMessage(UINT msg,
910 WPARAM w_param, 991 WPARAM w_param,
911 LPARAM l_param) { 992 LPARAM l_param) {
912 SetMsgHandled(FALSE); 993 SetMsgHandled(FALSE);
913 return 0; 994 return 0;
914 } 995 }
915 996
916 void WidgetWin::OnSetFocus(HWND focused_window) { 997 void WidgetWin::OnSetFocus(HWND focused_window) {
917 delegate_->OnNativeFocus(focused_window); 998 delegate_->OnNativeFocus(focused_window);
999 if (input_method_.get())
1000 input_method_->OnFocusIn();
918 SetMsgHandled(FALSE); 1001 SetMsgHandled(FALSE);
919 } 1002 }
920 1003
921 LRESULT WidgetWin::OnSetIcon(UINT size_type, HICON new_icon) { 1004 LRESULT WidgetWin::OnSetIcon(UINT size_type, HICON new_icon) {
922 SetMsgHandled(FALSE); 1005 SetMsgHandled(FALSE);
923 return 0; 1006 return 0;
924 } 1007 }
925 1008
926 LRESULT WidgetWin::OnSetText(const wchar_t* text) { 1009 LRESULT WidgetWin::OnSetText(const wchar_t* text) {
927 SetMsgHandled(FALSE); 1010 SetMsgHandled(FALSE);
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
1190 layered_window_contents_.reset( 1273 layered_window_contents_.reset(
1191 new gfx::CanvasSkia(s.width(), s.height(), false)); 1274 new gfx::CanvasSkia(s.width(), s.height(), false));
1192 } 1275 }
1193 } 1276 }
1194 1277
1195 gfx::AcceleratedWidget WidgetWin::GetAcceleratedWidget() { 1278 gfx::AcceleratedWidget WidgetWin::GetAcceleratedWidget() {
1196 // TODO(beng): 1279 // TODO(beng):
1197 return gfx::kNullAcceleratedWidget; 1280 return gfx::kNullAcceleratedWidget;
1198 } 1281 }
1199 1282
1283 void WidgetWin::DispatchKeyEventPostIME(const KeyEvent& key) {
1284 RootView* root_view = GetFocusedViewRootView();
1285 if (!root_view)
1286 root_view = GetRootView();
1287
1288 SetMsgHandled(root_view->ProcessKeyEvent(key));
1289 }
1290
1200 //////////////////////////////////////////////////////////////////////////////// 1291 ////////////////////////////////////////////////////////////////////////////////
1201 // Widget, public: 1292 // Widget, public:
1202 1293
1203 // static 1294 // static
1204 Widget* Widget::CreatePopupWidget(const CreateParams& params) { 1295 Widget* Widget::CreatePopupWidget(const CreateParams& params) {
1205 WidgetWin* popup = new WidgetWin; 1296 WidgetWin* popup = new WidgetWin;
1206 popup->SetCreateParams(params); 1297 popup->SetCreateParams(params);
1207 return popup; 1298 return popup;
1208 } 1299 }
1209 1300
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1284 return; 1375 return;
1285 1376
1286 NativeWidget* native_widget = GetNativeWidgetForNativeView(native_view); 1377 NativeWidget* native_widget = GetNativeWidgetForNativeView(native_view);
1287 if (native_widget) 1378 if (native_widget)
1288 children->insert(native_widget); 1379 children->insert(native_widget);
1289 EnumChildWindows(native_view, EnumerateChildWindowsForNativeWidgets, 1380 EnumChildWindows(native_view, EnumerateChildWindowsForNativeWidgets,
1290 reinterpret_cast<LPARAM>(children)); 1381 reinterpret_cast<LPARAM>(children));
1291 } 1382 }
1292 1383
1293 } // namespace views 1384 } // namespace views
OLDNEW
« views/focus/focus_manager.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