| 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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 active_mouse_tracking_flags_(0), | 138 active_mouse_tracking_flags_(0), |
| 137 use_layered_buffer_(false), | 139 use_layered_buffer_(false), |
| 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 is_window_(false), | 144 is_window_(false), |
| 143 restore_focus_when_enabled_(false), | 145 restore_focus_when_enabled_(false), |
| 144 accessibility_view_events_index_(-1), | 146 accessibility_view_events_index_(-1), |
| 145 accessibility_view_events_(kMaxAccessibilityViewEvents), | 147 accessibility_view_events_(kMaxAccessibilityViewEvents), |
| 146 previous_cursor_(NULL) { | 148 previous_cursor_(NULL), |
| 149 is_input_method_win_(false) { |
| 147 set_native_widget(this); | 150 set_native_widget(this); |
| 148 } | 151 } |
| 149 | 152 |
| 150 WidgetWin::~WidgetWin() { | 153 WidgetWin::~WidgetWin() { |
| 154 // We need to delete the input method before calling DestroyRootView(), |
| 155 // because it'll set focus_manager_ to NULL. |
| 156 input_method_.reset(); |
| 151 DestroyRootView(); | 157 DestroyRootView(); |
| 152 } | 158 } |
| 153 | 159 |
| 154 void WidgetWin::SetCreateParams(const CreateParams& params) { | 160 void WidgetWin::SetCreateParams(const CreateParams& params) { |
| 155 // Set non-style attributes. | 161 // Set non-style attributes. |
| 156 set_delete_on_destroy(params.delete_on_destroy); | 162 set_delete_on_destroy(params.delete_on_destroy); |
| 157 | 163 |
| 158 DWORD style = WS_CLIPCHILDREN | WS_CLIPSIBLINGS; | 164 DWORD style = WS_CLIPCHILDREN | WS_CLIPSIBLINGS; |
| 159 DWORD ex_style = 0; | 165 DWORD ex_style = 0; |
| 160 DWORD class_style = CS_DBLCLKS; | 166 DWORD class_style = CS_DBLCLKS; |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 } | 332 } |
| 327 | 333 |
| 328 void WidgetWin::ReleaseMouseCapture() { | 334 void WidgetWin::ReleaseMouseCapture() { |
| 329 ReleaseCapture(); | 335 ReleaseCapture(); |
| 330 } | 336 } |
| 331 | 337 |
| 332 bool WidgetWin::HasMouseCapture() const { | 338 bool WidgetWin::HasMouseCapture() const { |
| 333 return GetCapture() == hwnd(); | 339 return GetCapture() == hwnd(); |
| 334 } | 340 } |
| 335 | 341 |
| 342 InputMethod* WidgetWin::GetInputMethodNative() { |
| 343 return input_method_.get(); |
| 344 } |
| 345 |
| 346 void WidgetWin::ReplaceInputMethod(InputMethod* input_method) { |
| 347 input_method_.reset(input_method); |
| 348 if (input_method) { |
| 349 input_method->set_delegate(this); |
| 350 input_method->Init(GetWidget()); |
| 351 } |
| 352 is_input_method_win_ = false; |
| 353 } |
| 354 |
| 336 gfx::Rect WidgetWin::GetWindowScreenBounds() const { | 355 gfx::Rect WidgetWin::GetWindowScreenBounds() const { |
| 337 RECT r; | 356 RECT r; |
| 338 GetWindowRect(&r); | 357 GetWindowRect(&r); |
| 339 return gfx::Rect(r); | 358 return gfx::Rect(r); |
| 340 } | 359 } |
| 341 | 360 |
| 342 gfx::Rect WidgetWin::GetClientAreaScreenBounds() const { | 361 gfx::Rect WidgetWin::GetClientAreaScreenBounds() const { |
| 343 RECT r; | 362 RECT r; |
| 344 GetClientRect(&r); | 363 GetClientRect(&r); |
| 345 POINT point = { r.left, r.top }; | 364 POINT point = { r.left, r.top }; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 376 // we don't destroy the window before the callback returned (as the caller | 395 // we don't destroy the window before the callback returned (as the caller |
| 377 // may delete ourselves on destroy and the ATL callback would still | 396 // may delete ourselves on destroy and the ATL callback would still |
| 378 // dereference us when the callback returns). | 397 // dereference us when the callback returns). |
| 379 MessageLoop::current()->PostTask(FROM_HERE, | 398 MessageLoop::current()->PostTask(FROM_HERE, |
| 380 close_widget_factory_.NewRunnableMethod( | 399 close_widget_factory_.NewRunnableMethod( |
| 381 &WidgetWin::CloseNow)); | 400 &WidgetWin::CloseNow)); |
| 382 } | 401 } |
| 383 } | 402 } |
| 384 | 403 |
| 385 void WidgetWin::CloseNow() { | 404 void WidgetWin::CloseNow() { |
| 405 // Destroys the input method before closing the window so that it can be |
| 406 // detached from the widget correctly. |
| 407 input_method_.reset(); |
| 408 is_input_method_win_ = false; |
| 409 |
| 386 // We may already have been destroyed if the selection resulted in a tab | 410 // We may already have been destroyed if the selection resulted in a tab |
| 387 // switch which will have reactivated the browser window and closed us, so | 411 // switch which will have reactivated the browser window and closed us, so |
| 388 // we need to check to see if we're still a window before trying to destroy | 412 // we need to check to see if we're still a window before trying to destroy |
| 389 // ourself. | 413 // ourself. |
| 390 if (IsWindow()) | 414 if (IsWindow()) |
| 391 DestroyWindow(hwnd()); | 415 DestroyWindow(hwnd()); |
| 392 } | 416 } |
| 393 | 417 |
| 394 void WidgetWin::Show() { | 418 void WidgetWin::Show() { |
| 395 if (IsWindow()) | 419 if (IsWindow()) |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 // Bug 964884: detach the IME attached to this window. | 637 // Bug 964884: detach the IME attached to this window. |
| 614 // We should attach IMEs only when we need to input CJK strings. | 638 // We should attach IMEs only when we need to input CJK strings. |
| 615 ImmAssociateContextEx(hwnd(), NULL, 0); | 639 ImmAssociateContextEx(hwnd(), NULL, 0); |
| 616 | 640 |
| 617 // We need to allow the delegate to size its contents since the window may not | 641 // We need to allow the delegate to size its contents since the window may not |
| 618 // receive a size notification when its initial bounds are specified at window | 642 // receive a size notification when its initial bounds are specified at window |
| 619 // creation time. | 643 // creation time. |
| 620 ClientAreaSizeChanged(); | 644 ClientAreaSizeChanged(); |
| 621 | 645 |
| 622 delegate_->OnNativeWidgetCreated(); | 646 delegate_->OnNativeWidgetCreated(); |
| 647 |
| 648 // delegate_->OnNativeWidgetCreated() creates the focus manager for top-level |
| 649 // widget. Only top-level widget should have an input method. |
| 650 if (delegate_->HasFocusManager() && |
| 651 NativeTextfieldViews::IsTextfieldViewsEnabled()) { |
| 652 input_method_.reset(new InputMethodWin(this)); |
| 653 input_method_->Init(GetWidget()); |
| 654 is_input_method_win_ = true; |
| 655 } |
| 623 return 0; | 656 return 0; |
| 624 } | 657 } |
| 625 | 658 |
| 626 void WidgetWin::OnDestroy() { | 659 void WidgetWin::OnDestroy() { |
| 627 if (drop_target_.get()) { | 660 if (drop_target_.get()) { |
| 628 RevokeDragDrop(hwnd()); | 661 RevokeDragDrop(hwnd()); |
| 629 drop_target_ = NULL; | 662 drop_target_ = NULL; |
| 630 } | 663 } |
| 631 | 664 |
| 632 props_.reset(); | 665 props_.reset(); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 } | 725 } |
| 693 | 726 |
| 694 void WidgetWin::OnGetMinMaxInfo(MINMAXINFO* minmax_info) { | 727 void WidgetWin::OnGetMinMaxInfo(MINMAXINFO* minmax_info) { |
| 695 SetMsgHandled(FALSE); | 728 SetMsgHandled(FALSE); |
| 696 } | 729 } |
| 697 | 730 |
| 698 void WidgetWin::OnHScroll(int scroll_type, short position, HWND scrollbar) { | 731 void WidgetWin::OnHScroll(int scroll_type, short position, HWND scrollbar) { |
| 699 SetMsgHandled(FALSE); | 732 SetMsgHandled(FALSE); |
| 700 } | 733 } |
| 701 | 734 |
| 735 LRESULT WidgetWin::OnImeMessages(UINT message, WPARAM w_param, LPARAM l_param) { |
| 736 if (!is_input_method_win_) { |
| 737 SetMsgHandled(FALSE); |
| 738 return 0; |
| 739 } |
| 740 |
| 741 InputMethodWin* ime = static_cast<InputMethodWin*>(input_method_.get()); |
| 742 BOOL handled = FALSE; |
| 743 LRESULT result = 0; |
| 744 switch (message) { |
| 745 case WM_IME_SETCONTEXT: |
| 746 result = ime->OnImeSetContext(message, w_param, l_param, &handled); |
| 747 break; |
| 748 case WM_IME_STARTCOMPOSITION: |
| 749 result = ime->OnImeStartComposition(message, w_param, l_param, &handled); |
| 750 break; |
| 751 case WM_IME_COMPOSITION: |
| 752 result = ime->OnImeComposition(message, w_param, l_param, &handled); |
| 753 break; |
| 754 case WM_IME_ENDCOMPOSITION: |
| 755 result = ime->OnImeEndComposition(message, w_param, l_param, &handled); |
| 756 break; |
| 757 case WM_CHAR: |
| 758 case WM_SYSCHAR: |
| 759 result = ime->OnChar(message, w_param, l_param, &handled); |
| 760 break; |
| 761 case WM_DEADCHAR: |
| 762 case WM_SYSDEADCHAR: |
| 763 result = ime->OnDeadChar(message, w_param, l_param, &handled); |
| 764 break; |
| 765 default: |
| 766 NOTREACHED() << "Unknown IME message:" << message; |
| 767 break; |
| 768 } |
| 769 |
| 770 SetMsgHandled(handled); |
| 771 return result; |
| 772 } |
| 773 |
| 702 void WidgetWin::OnInitMenu(HMENU menu) { | 774 void WidgetWin::OnInitMenu(HMENU menu) { |
| 703 SetMsgHandled(FALSE); | 775 SetMsgHandled(FALSE); |
| 704 } | 776 } |
| 705 | 777 |
| 706 void WidgetWin::OnInitMenuPopup(HMENU menu, | 778 void WidgetWin::OnInitMenuPopup(HMENU menu, |
| 707 UINT position, | 779 UINT position, |
| 708 BOOL is_system_menu) { | 780 BOOL is_system_menu) { |
| 709 SetMsgHandled(FALSE); | 781 SetMsgHandled(FALSE); |
| 710 } | 782 } |
| 711 | 783 |
| 784 void WidgetWin::OnInputLangChange(DWORD character_set, HKL input_language_id) { |
| 785 if (is_input_method_win_) { |
| 786 static_cast<InputMethodWin*>(input_method_.get())->OnInputLangChange( |
| 787 character_set, input_language_id); |
| 788 } |
| 789 } |
| 790 |
| 712 LRESULT WidgetWin::OnKeyDown(UINT message, WPARAM w_param, LPARAM l_param) { | 791 LRESULT WidgetWin::OnKeyDown(UINT message, WPARAM w_param, LPARAM l_param) { |
| 713 RootView* root_view = GetFocusedViewRootView(); | |
| 714 if (!root_view) | |
| 715 root_view = GetRootView(); | |
| 716 | |
| 717 MSG msg = { hwnd(), message, w_param, l_param }; | 792 MSG msg = { hwnd(), message, w_param, l_param }; |
| 718 SetMsgHandled(root_view->ProcessKeyEvent(KeyEvent(msg))); | 793 KeyEvent key(msg); |
| 794 if (input_method_.get()) |
| 795 input_method_->DispatchKeyEvent(key); |
| 796 else |
| 797 DispatchKeyEventPostIME(key); |
| 719 return 0; | 798 return 0; |
| 720 } | 799 } |
| 721 | 800 |
| 722 LRESULT WidgetWin::OnKeyUp(UINT message, WPARAM w_param, LPARAM l_param) { | 801 LRESULT WidgetWin::OnKeyUp(UINT message, WPARAM w_param, LPARAM l_param) { |
| 723 RootView* root_view = GetFocusedViewRootView(); | |
| 724 if (!root_view) | |
| 725 root_view = GetRootView(); | |
| 726 | |
| 727 MSG msg = { hwnd(), message, w_param, l_param }; | 802 MSG msg = { hwnd(), message, w_param, l_param }; |
| 728 SetMsgHandled(root_view->ProcessKeyEvent(KeyEvent(msg))); | 803 KeyEvent key(msg); |
| 804 if (input_method_.get()) |
| 805 input_method_->DispatchKeyEvent(key); |
| 806 else |
| 807 DispatchKeyEventPostIME(key); |
| 729 return 0; | 808 return 0; |
| 730 } | 809 } |
| 731 | 810 |
| 732 void WidgetWin::OnKillFocus(HWND focused_window) { | 811 void WidgetWin::OnKillFocus(HWND focused_window) { |
| 733 delegate_->OnNativeBlur(focused_window); | 812 delegate_->OnNativeBlur(focused_window); |
| 813 if (input_method_.get()) |
| 814 input_method_->OnBlur(); |
| 734 SetMsgHandled(FALSE); | 815 SetMsgHandled(FALSE); |
| 735 } | 816 } |
| 736 | 817 |
| 737 LRESULT WidgetWin::OnMouseActivate(UINT message, | 818 LRESULT WidgetWin::OnMouseActivate(UINT message, |
| 738 WPARAM w_param, | 819 WPARAM w_param, |
| 739 LPARAM l_param) { | 820 LPARAM l_param) { |
| 740 if (GetWindowLong(GWL_EXSTYLE) & WS_EX_NOACTIVATE) | 821 if (GetWindowLong(GWL_EXSTYLE) & WS_EX_NOACTIVATE) |
| 741 return MA_NOACTIVATE; | 822 return MA_NOACTIVATE; |
| 742 SetMsgHandled(FALSE); | 823 SetMsgHandled(FALSE); |
| 743 return MA_ACTIVATE; | 824 return MA_ACTIVATE; |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 856 | 937 |
| 857 LRESULT WidgetWin::OnReflectedMessage(UINT msg, | 938 LRESULT WidgetWin::OnReflectedMessage(UINT msg, |
| 858 WPARAM w_param, | 939 WPARAM w_param, |
| 859 LPARAM l_param) { | 940 LPARAM l_param) { |
| 860 SetMsgHandled(FALSE); | 941 SetMsgHandled(FALSE); |
| 861 return 0; | 942 return 0; |
| 862 } | 943 } |
| 863 | 944 |
| 864 void WidgetWin::OnSetFocus(HWND focused_window) { | 945 void WidgetWin::OnSetFocus(HWND focused_window) { |
| 865 delegate_->OnNativeFocus(focused_window); | 946 delegate_->OnNativeFocus(focused_window); |
| 947 if (input_method_.get()) |
| 948 input_method_->OnFocus(); |
| 866 SetMsgHandled(FALSE); | 949 SetMsgHandled(FALSE); |
| 867 } | 950 } |
| 868 | 951 |
| 869 LRESULT WidgetWin::OnSetIcon(UINT size_type, HICON new_icon) { | 952 LRESULT WidgetWin::OnSetIcon(UINT size_type, HICON new_icon) { |
| 870 SetMsgHandled(FALSE); | 953 SetMsgHandled(FALSE); |
| 871 return 0; | 954 return 0; |
| 872 } | 955 } |
| 873 | 956 |
| 874 LRESULT WidgetWin::OnSetText(const wchar_t* text) { | 957 LRESULT WidgetWin::OnSetText(const wchar_t* text) { |
| 875 SetMsgHandled(FALSE); | 958 SetMsgHandled(FALSE); |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1050 layered_window_contents_.reset( | 1133 layered_window_contents_.reset( |
| 1051 new gfx::CanvasSkia(s.width(), s.height(), false)); | 1134 new gfx::CanvasSkia(s.width(), s.height(), false)); |
| 1052 } | 1135 } |
| 1053 } | 1136 } |
| 1054 | 1137 |
| 1055 gfx::AcceleratedWidget WidgetWin::GetAcceleratedWidget() { | 1138 gfx::AcceleratedWidget WidgetWin::GetAcceleratedWidget() { |
| 1056 // TODO(beng): | 1139 // TODO(beng): |
| 1057 return gfx::kNullAcceleratedWidget; | 1140 return gfx::kNullAcceleratedWidget; |
| 1058 } | 1141 } |
| 1059 | 1142 |
| 1143 void WidgetWin::DispatchKeyEventPostIME(const KeyEvent& key) { |
| 1144 RootView* root_view = GetFocusedViewRootView(); |
| 1145 if (!root_view) |
| 1146 root_view = GetRootView(); |
| 1147 |
| 1148 SetMsgHandled(root_view->ProcessKeyEvent(key)); |
| 1149 } |
| 1150 |
| 1060 //////////////////////////////////////////////////////////////////////////////// | 1151 //////////////////////////////////////////////////////////////////////////////// |
| 1061 // Widget, public: | 1152 // Widget, public: |
| 1062 | 1153 |
| 1063 // static | 1154 // static |
| 1064 Widget* Widget::CreateWidget(const CreateParams& params) { | 1155 Widget* Widget::CreateWidget(const CreateParams& params) { |
| 1065 WidgetWin* widget = new WidgetWin; | 1156 WidgetWin* widget = new WidgetWin; |
| 1066 widget->SetCreateParams(params); | 1157 widget->SetCreateParams(params); |
| 1067 return widget; | 1158 return widget; |
| 1068 } | 1159 } |
| 1069 | 1160 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1176 | 1267 |
| 1177 // And now, notify them that they have a brand new parent. | 1268 // And now, notify them that they have a brand new parent. |
| 1178 for (NativeWidgets::iterator it = widgets.begin(); | 1269 for (NativeWidgets::iterator it = widgets.begin(); |
| 1179 it != widgets.end(); ++it) { | 1270 it != widgets.end(); ++it) { |
| 1180 (*it)->GetWidget()->NotifyNativeViewHierarchyChanged(true, | 1271 (*it)->GetWidget()->NotifyNativeViewHierarchyChanged(true, |
| 1181 new_parent); | 1272 new_parent); |
| 1182 } | 1273 } |
| 1183 } | 1274 } |
| 1184 | 1275 |
| 1185 } // namespace views | 1276 } // namespace views |
| OLD | NEW |