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