| 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/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 Loading... |
| 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() { |
| 155 // We need to delete the input method before calling DestroyRootView(), |
| 156 // because it'll set focus_manager_ to NULL. |
| 157 input_method_.reset(); |
| 153 DestroyRootView(); | 158 DestroyRootView(); |
| 154 } | 159 } |
| 155 | 160 |
| 156 void WidgetWin::SetCreateParams(const CreateParams& params) { | 161 void WidgetWin::SetCreateParams(const CreateParams& params) { |
| 157 // Set non-style attributes. | 162 // Set non-style attributes. |
| 158 set_delete_on_destroy(params.delete_on_destroy); | 163 set_delete_on_destroy(params.delete_on_destroy); |
| 159 | 164 |
| 160 DWORD style = 0; | 165 DWORD style = 0; |
| 161 DWORD ex_style = 0; | 166 DWORD ex_style = 0; |
| 162 DWORD class_style = CS_DBLCLKS; | 167 DWORD class_style = CS_DBLCLKS; |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 } | 330 } |
| 326 | 331 |
| 327 void WidgetWin::ReleaseNativeCapture() { | 332 void WidgetWin::ReleaseNativeCapture() { |
| 328 ReleaseCapture(); | 333 ReleaseCapture(); |
| 329 } | 334 } |
| 330 | 335 |
| 331 bool WidgetWin::HasNativeCapture() const { | 336 bool WidgetWin::HasNativeCapture() const { |
| 332 return GetCapture() == hwnd(); | 337 return GetCapture() == hwnd(); |
| 333 } | 338 } |
| 334 | 339 |
| 340 InputMethod* WidgetWin::GetInputMethodNative() { |
| 341 return input_method_.get(); |
| 342 } |
| 343 |
| 344 void WidgetWin::ReplaceInputMethod(InputMethod* input_method) { |
| 345 input_method_.reset(input_method); |
| 346 if (input_method) { |
| 347 input_method->set_delegate(this); |
| 348 input_method->Init(GetWidget()); |
| 349 } |
| 350 is_input_method_win_ = false; |
| 351 } |
| 352 |
| 335 gfx::Rect WidgetWin::GetWindowScreenBounds() const { | 353 gfx::Rect WidgetWin::GetWindowScreenBounds() const { |
| 336 RECT r; | 354 RECT r; |
| 337 GetWindowRect(&r); | 355 GetWindowRect(&r); |
| 338 return gfx::Rect(r); | 356 return gfx::Rect(r); |
| 339 } | 357 } |
| 340 | 358 |
| 341 gfx::Rect WidgetWin::GetClientAreaScreenBounds() const { | 359 gfx::Rect WidgetWin::GetClientAreaScreenBounds() const { |
| 342 RECT r; | 360 RECT r; |
| 343 GetClientRect(&r); | 361 GetClientRect(&r); |
| 344 POINT point = { r.left, r.top }; | 362 POINT point = { r.left, r.top }; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 375 // we don't destroy the window before the callback returned (as the caller | 393 // 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 | 394 // may delete ourselves on destroy and the ATL callback would still |
| 377 // dereference us when the callback returns). | 395 // dereference us when the callback returns). |
| 378 MessageLoop::current()->PostTask(FROM_HERE, | 396 MessageLoop::current()->PostTask(FROM_HERE, |
| 379 close_widget_factory_.NewRunnableMethod( | 397 close_widget_factory_.NewRunnableMethod( |
| 380 &WidgetWin::CloseNow)); | 398 &WidgetWin::CloseNow)); |
| 381 } | 399 } |
| 382 } | 400 } |
| 383 | 401 |
| 384 void WidgetWin::CloseNow() { | 402 void WidgetWin::CloseNow() { |
| 403 // Destroys the input method before closing the window so that it can be |
| 404 // detached from the widget correctly. |
| 405 input_method_.reset(); |
| 406 is_input_method_win_ = false; |
| 407 |
| 385 // We may already have been destroyed if the selection resulted in a tab | 408 // 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 | 409 // 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 | 410 // we need to check to see if we're still a window before trying to destroy |
| 388 // ourself. | 411 // ourself. |
| 389 if (IsWindow()) | 412 if (IsWindow()) |
| 390 DestroyWindow(hwnd()); | 413 DestroyWindow(hwnd()); |
| 391 } | 414 } |
| 392 | 415 |
| 393 void WidgetWin::Show() { | 416 void WidgetWin::Show() { |
| 394 if (IsWindow()) | 417 if (IsWindow()) |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 614 // Bug 964884: detach the IME attached to this window. | 637 // Bug 964884: detach the IME attached to this window. |
| 615 // 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. |
| 616 ImmAssociateContextEx(hwnd(), NULL, 0); | 639 ImmAssociateContextEx(hwnd(), NULL, 0); |
| 617 | 640 |
| 618 // 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 |
| 619 // 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 |
| 620 // creation time. | 643 // creation time. |
| 621 ClientAreaSizeChanged(); | 644 ClientAreaSizeChanged(); |
| 622 | 645 |
| 623 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 input_method_.reset(new InputMethodWin(this)); |
| 652 input_method_->Init(GetWidget()); |
| 653 is_input_method_win_ = true; |
| 654 } |
| 624 return 0; | 655 return 0; |
| 625 } | 656 } |
| 626 | 657 |
| 627 void WidgetWin::OnDestroy() { | 658 void WidgetWin::OnDestroy() { |
| 628 if (drop_target_.get()) { | 659 if (drop_target_.get()) { |
| 629 RevokeDragDrop(hwnd()); | 660 RevokeDragDrop(hwnd()); |
| 630 drop_target_ = NULL; | 661 drop_target_ = NULL; |
| 631 } | 662 } |
| 632 | 663 |
| 633 props_.reset(); | 664 props_.reset(); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 } | 724 } |
| 694 | 725 |
| 695 void WidgetWin::OnGetMinMaxInfo(MINMAXINFO* minmax_info) { | 726 void WidgetWin::OnGetMinMaxInfo(MINMAXINFO* minmax_info) { |
| 696 SetMsgHandled(FALSE); | 727 SetMsgHandled(FALSE); |
| 697 } | 728 } |
| 698 | 729 |
| 699 void WidgetWin::OnHScroll(int scroll_type, short position, HWND scrollbar) { | 730 void WidgetWin::OnHScroll(int scroll_type, short position, HWND scrollbar) { |
| 700 SetMsgHandled(FALSE); | 731 SetMsgHandled(FALSE); |
| 701 } | 732 } |
| 702 | 733 |
| 734 LRESULT WidgetWin::OnImeMessages(UINT message, WPARAM w_param, LPARAM l_param) { |
| 735 if (!is_input_method_win_) { |
| 736 SetMsgHandled(FALSE); |
| 737 return 0; |
| 738 } |
| 739 |
| 740 InputMethodWin* ime = static_cast<InputMethodWin*>(input_method_.get()); |
| 741 BOOL handled = FALSE; |
| 742 LRESULT result = 0; |
| 743 switch (message) { |
| 744 case WM_IME_SETCONTEXT: |
| 745 result = ime->OnImeSetContext(message, w_param, l_param, &handled); |
| 746 break; |
| 747 case WM_IME_STARTCOMPOSITION: |
| 748 result = ime->OnImeStartComposition(message, w_param, l_param, &handled); |
| 749 break; |
| 750 case WM_IME_COMPOSITION: |
| 751 result = ime->OnImeComposition(message, w_param, l_param, &handled); |
| 752 break; |
| 753 case WM_IME_ENDCOMPOSITION: |
| 754 result = ime->OnImeEndComposition(message, w_param, l_param, &handled); |
| 755 break; |
| 756 case WM_CHAR: |
| 757 case WM_SYSCHAR: |
| 758 result = ime->OnChar(message, w_param, l_param, &handled); |
| 759 break; |
| 760 case WM_DEADCHAR: |
| 761 case WM_SYSDEADCHAR: |
| 762 result = ime->OnDeadChar(message, w_param, l_param, &handled); |
| 763 break; |
| 764 default: |
| 765 NOTREACHED() << "Unknown IME message:" << message; |
| 766 break; |
| 767 } |
| 768 |
| 769 SetMsgHandled(handled); |
| 770 return result; |
| 771 } |
| 772 |
| 703 void WidgetWin::OnInitMenu(HMENU menu) { | 773 void WidgetWin::OnInitMenu(HMENU menu) { |
| 704 SetMsgHandled(FALSE); | 774 SetMsgHandled(FALSE); |
| 705 } | 775 } |
| 706 | 776 |
| 707 void WidgetWin::OnInitMenuPopup(HMENU menu, | 777 void WidgetWin::OnInitMenuPopup(HMENU menu, |
| 708 UINT position, | 778 UINT position, |
| 709 BOOL is_system_menu) { | 779 BOOL is_system_menu) { |
| 710 SetMsgHandled(FALSE); | 780 SetMsgHandled(FALSE); |
| 711 } | 781 } |
| 712 | 782 |
| 783 void WidgetWin::OnInputLangChange(DWORD character_set, HKL input_language_id) { |
| 784 if (is_input_method_win_) { |
| 785 static_cast<InputMethodWin*>(input_method_.get())->OnInputLangChange( |
| 786 character_set, input_language_id); |
| 787 } |
| 788 } |
| 789 |
| 713 LRESULT WidgetWin::OnKeyDown(UINT message, WPARAM w_param, LPARAM l_param) { | 790 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; | 791 MSG msg; |
| 719 MakeMSG(&msg, message, w_param, l_param); | 792 MakeMSG(&msg, message, w_param, l_param); |
| 720 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); |
| 721 return 0; | 798 return 0; |
| 722 } | 799 } |
| 723 | 800 |
| 724 LRESULT WidgetWin::OnKeyUp(UINT message, WPARAM w_param, LPARAM l_param) { | 801 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; | 802 MSG msg; |
| 730 MakeMSG(&msg, message, w_param, l_param); | 803 MakeMSG(&msg, message, w_param, l_param); |
| 731 SetMsgHandled(root_view->ProcessKeyEvent(KeyEvent(msg))); | 804 KeyEvent key(msg); |
| 805 if (input_method_.get()) |
| 806 input_method_->DispatchKeyEvent(key); |
| 807 else |
| 808 DispatchKeyEventPostIME(key); |
| 732 return 0; | 809 return 0; |
| 733 } | 810 } |
| 734 | 811 |
| 735 void WidgetWin::OnKillFocus(HWND focused_window) { | 812 void WidgetWin::OnKillFocus(HWND focused_window) { |
| 736 delegate_->OnNativeBlur(focused_window); | 813 delegate_->OnNativeBlur(focused_window); |
| 814 if (is_input_method_win_) |
| 815 static_cast<InputMethodWin*>(input_method_.get())->OnKillFocus(); |
| 737 SetMsgHandled(FALSE); | 816 SetMsgHandled(FALSE); |
| 738 } | 817 } |
| 739 | 818 |
| 740 LRESULT WidgetWin::OnMouseActivate(UINT message, | 819 LRESULT WidgetWin::OnMouseActivate(UINT message, |
| 741 WPARAM w_param, | 820 WPARAM w_param, |
| 742 LPARAM l_param) { | 821 LPARAM l_param) { |
| 743 SetMsgHandled(FALSE); | 822 SetMsgHandled(FALSE); |
| 744 return MA_ACTIVATE; | 823 return MA_ACTIVATE; |
| 745 } | 824 } |
| 746 | 825 |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 904 | 983 |
| 905 LRESULT WidgetWin::OnReflectedMessage(UINT msg, | 984 LRESULT WidgetWin::OnReflectedMessage(UINT msg, |
| 906 WPARAM w_param, | 985 WPARAM w_param, |
| 907 LPARAM l_param) { | 986 LPARAM l_param) { |
| 908 SetMsgHandled(FALSE); | 987 SetMsgHandled(FALSE); |
| 909 return 0; | 988 return 0; |
| 910 } | 989 } |
| 911 | 990 |
| 912 void WidgetWin::OnSetFocus(HWND focused_window) { | 991 void WidgetWin::OnSetFocus(HWND focused_window) { |
| 913 delegate_->OnNativeFocus(focused_window); | 992 delegate_->OnNativeFocus(focused_window); |
| 993 if (is_input_method_win_) |
| 994 static_cast<InputMethodWin*>(input_method_.get())->OnSetFocus(); |
| 914 SetMsgHandled(FALSE); | 995 SetMsgHandled(FALSE); |
| 915 } | 996 } |
| 916 | 997 |
| 917 LRESULT WidgetWin::OnSetIcon(UINT size_type, HICON new_icon) { | 998 LRESULT WidgetWin::OnSetIcon(UINT size_type, HICON new_icon) { |
| 918 SetMsgHandled(FALSE); | 999 SetMsgHandled(FALSE); |
| 919 return 0; | 1000 return 0; |
| 920 } | 1001 } |
| 921 | 1002 |
| 922 LRESULT WidgetWin::OnSetText(const wchar_t* text) { | 1003 LRESULT WidgetWin::OnSetText(const wchar_t* text) { |
| 923 SetMsgHandled(FALSE); | 1004 SetMsgHandled(FALSE); |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1186 layered_window_contents_.reset( | 1267 layered_window_contents_.reset( |
| 1187 new gfx::CanvasSkia(s.width(), s.height(), false)); | 1268 new gfx::CanvasSkia(s.width(), s.height(), false)); |
| 1188 } | 1269 } |
| 1189 } | 1270 } |
| 1190 | 1271 |
| 1191 gfx::AcceleratedWidget WidgetWin::GetAcceleratedWidget() { | 1272 gfx::AcceleratedWidget WidgetWin::GetAcceleratedWidget() { |
| 1192 // TODO(beng): | 1273 // TODO(beng): |
| 1193 return gfx::kNullAcceleratedWidget; | 1274 return gfx::kNullAcceleratedWidget; |
| 1194 } | 1275 } |
| 1195 | 1276 |
| 1277 void WidgetWin::DispatchKeyEventPostIME(const KeyEvent& key) { |
| 1278 RootView* root_view = GetFocusedViewRootView(); |
| 1279 if (!root_view) |
| 1280 root_view = GetRootView(); |
| 1281 |
| 1282 SetMsgHandled(root_view->ProcessKeyEvent(key)); |
| 1283 } |
| 1284 |
| 1196 //////////////////////////////////////////////////////////////////////////////// | 1285 //////////////////////////////////////////////////////////////////////////////// |
| 1197 // Widget, public: | 1286 // Widget, public: |
| 1198 | 1287 |
| 1199 // static | 1288 // static |
| 1200 Widget* Widget::CreatePopupWidget(const CreateParams& params) { | 1289 Widget* Widget::CreatePopupWidget(const CreateParams& params) { |
| 1201 WidgetWin* popup = new WidgetWin; | 1290 WidgetWin* popup = new WidgetWin; |
| 1202 popup->SetCreateParams(params); | 1291 popup->SetCreateParams(params); |
| 1203 return popup; | 1292 return popup; |
| 1204 } | 1293 } |
| 1205 | 1294 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1280 return; | 1369 return; |
| 1281 | 1370 |
| 1282 NativeWidget* native_widget = GetNativeWidgetForNativeView(native_view); | 1371 NativeWidget* native_widget = GetNativeWidgetForNativeView(native_view); |
| 1283 if (native_widget) | 1372 if (native_widget) |
| 1284 children->insert(native_widget); | 1373 children->insert(native_widget); |
| 1285 EnumChildWindows(native_view, EnumerateChildWindowsForNativeWidgets, | 1374 EnumChildWindows(native_view, EnumerateChildWindowsForNativeWidgets, |
| 1286 reinterpret_cast<LPARAM>(children)); | 1375 reinterpret_cast<LPARAM>(children)); |
| 1287 } | 1376 } |
| 1288 | 1377 |
| 1289 } // namespace views | 1378 } // namespace views |
| OLD | NEW |