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/window/window_win.h" | 5 #include "views/window/window_win.h" |
6 | 6 |
7 #include <dwmapi.h> | 7 #include <dwmapi.h> |
8 #include <shellapi.h> | 8 #include <shellapi.h> |
9 | 9 |
10 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
(...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
651 InitClass(); | 651 InitClass(); |
652 DCHECK(window_delegate_); | 652 DCHECK(window_delegate_); |
653 DCHECK(!window_delegate_->window_); | 653 DCHECK(!window_delegate_->window_); |
654 window_delegate_->window_ = this; | 654 window_delegate_->window_ = this; |
655 // Initialize these values to 0 so that subclasses can override the default | 655 // Initialize these values to 0 so that subclasses can override the default |
656 // behavior before calling Init. | 656 // behavior before calling Init. |
657 set_window_style(0); | 657 set_window_style(0); |
658 set_window_ex_style(0); | 658 set_window_ex_style(0); |
659 } | 659 } |
660 | 660 |
661 void WindowWin::Init(HWND parent, const gfx::Rect& bounds) { | 661 void WindowWin::Init(gfx::NativeView parent, const gfx::Rect& bounds) { |
662 // We need to save the parent window, since later calls to GetParent() will | 662 // We need to save the parent window, since later calls to GetParent() will |
663 // return NULL. | 663 // return NULL. |
664 owning_hwnd_ = parent; | 664 owning_hwnd_ = parent; |
665 // We call this after initializing our members since our implementations of | 665 // We call this after initializing our members since our implementations of |
666 // assorted WidgetWin functions may be called during initialization. | 666 // assorted WidgetWin functions may be called during initialization. |
667 is_modal_ = window_delegate_->IsModal(); | 667 is_modal_ = window_delegate_->IsModal(); |
668 if (is_modal_) | 668 if (is_modal_) |
669 BecomeModal(); | 669 BecomeModal(); |
670 | 670 |
671 if (window_style() == 0) | 671 if (window_style() == 0) |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
817 ScopedRedrawLock lock(this); | 817 ScopedRedrawLock lock(this); |
818 EnableMenuItem(menu, SC_RESTORE, is_minimized || is_maximized); | 818 EnableMenuItem(menu, SC_RESTORE, is_minimized || is_maximized); |
819 EnableMenuItem(menu, SC_MOVE, is_restored); | 819 EnableMenuItem(menu, SC_MOVE, is_restored); |
820 EnableMenuItem(menu, SC_SIZE, window_delegate_->CanResize() && is_restored); | 820 EnableMenuItem(menu, SC_SIZE, window_delegate_->CanResize() && is_restored); |
821 EnableMenuItem(menu, SC_MAXIMIZE, | 821 EnableMenuItem(menu, SC_MAXIMIZE, |
822 window_delegate_->CanMaximize() && !is_fullscreen && !is_maximized); | 822 window_delegate_->CanMaximize() && !is_fullscreen && !is_maximized); |
823 EnableMenuItem(menu, SC_MINIMIZE, | 823 EnableMenuItem(menu, SC_MINIMIZE, |
824 window_delegate_->CanMaximize() && !is_minimized); | 824 window_delegate_->CanMaximize() && !is_minimized); |
825 } | 825 } |
826 | 826 |
827 void WindowWin::OnMouseLeave() { | 827 LRESULT WindowWin::OnMouseLeave(UINT message, WPARAM w_param, LPARAM l_param) { |
828 // We only need to manually track WM_MOUSELEAVE messages between the client | 828 // We only need to manually track WM_MOUSELEAVE messages between the client |
829 // and non-client area when we're not using the native frame. | 829 // and non-client area when we're not using the native frame. |
830 if (non_client_view_->UseNativeFrame()) { | 830 if (non_client_view_->UseNativeFrame()) { |
831 SetMsgHandled(FALSE); | 831 SetMsgHandled(FALSE); |
832 return; | 832 return 0; |
833 } | 833 } |
834 | 834 |
835 bool process_mouse_exited = true; | 835 bool process_mouse_exited = true; |
836 POINT pt; | 836 POINT pt; |
837 if (GetCursorPos(&pt)) { | 837 if (GetCursorPos(&pt)) { |
838 LRESULT ht_component = | 838 LRESULT ht_component = |
839 ::SendMessage(GetNativeView(), WM_NCHITTEST, 0, MAKELPARAM(pt.x, pt.y)); | 839 ::SendMessage(GetNativeView(), WM_NCHITTEST, 0, MAKELPARAM(pt.x, pt.y)); |
840 if (ht_component != HTNOWHERE) { | 840 if (ht_component != HTNOWHERE) { |
841 // If the mouse moved into a part of the window's non-client area, then | 841 // If the mouse moved into a part of the window's non-client area, then |
842 // don't send a mouse exited event since the mouse is still within the | 842 // don't send a mouse exited event since the mouse is still within the |
843 // bounds of the ChromeView that's rendering the frame. Note that we do | 843 // bounds of the ChromeView that's rendering the frame. Note that we do |
844 // _NOT_ do this for windows with native frames, since in that case the | 844 // _NOT_ do this for windows with native frames, since in that case the |
845 // mouse really will have left the bounds of the RootView. | 845 // mouse really will have left the bounds of the RootView. |
846 process_mouse_exited = false; | 846 process_mouse_exited = false; |
847 } | 847 } |
848 } | 848 } |
849 | 849 |
850 if (process_mouse_exited) | 850 if (process_mouse_exited) |
851 ProcessMouseExited(); | 851 ProcessMouseExited(); |
| 852 return 0; |
852 } | 853 } |
853 | 854 |
854 LRESULT WindowWin::OnNCActivate(BOOL active) { | 855 LRESULT WindowWin::OnNCActivate(BOOL active) { |
855 is_active_ = !!active; | 856 is_active_ = !!active; |
856 | 857 |
857 // The frame may need to redraw as a result of the activation change. | 858 // The frame may need to redraw as a result of the activation change. |
858 // We can get WM_NCACTIVATE before we're actually visible. If we're not | 859 // We can get WM_NCACTIVATE before we're actually visible. If we're not |
859 // visible, no need to paint. | 860 // visible, no need to paint. |
860 if (IsVisible()) | 861 if (IsVisible()) |
861 non_client_view_->SchedulePaint(); | 862 non_client_view_->SchedulePaint(); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
968 // us. | 969 // us. |
969 return WidgetWin::OnNCHitTest(point); | 970 return WidgetWin::OnNCHitTest(point); |
970 } | 971 } |
971 | 972 |
972 void WindowWin::OnNCPaint(HRGN rgn) { | 973 void WindowWin::OnNCPaint(HRGN rgn) { |
973 // When using a custom frame, we want to avoid calling DefWindowProc() since | 974 // When using a custom frame, we want to avoid calling DefWindowProc() since |
974 // that may render artifacts. | 975 // that may render artifacts. |
975 SetMsgHandled(!non_client_view_->UseNativeFrame()); | 976 SetMsgHandled(!non_client_view_->UseNativeFrame()); |
976 } | 977 } |
977 | 978 |
978 void WindowWin::OnNCLButtonDown(UINT ht_component, const CPoint& point) { | 979 LRESULT WindowWin::OnNCLButtonDown(UINT message, |
| 980 WPARAM w_param, |
| 981 LPARAM l_param) { |
979 // When we're using a native frame, window controls work without us | 982 // When we're using a native frame, window controls work without us |
980 // interfering. | 983 // interfering. |
981 if (!non_client_view_->UseNativeFrame()) { | 984 if (!non_client_view_->UseNativeFrame()) { |
982 switch (ht_component) { | 985 switch (w_param) { |
983 case HTCLOSE: | 986 case HTCLOSE: |
984 case HTMINBUTTON: | 987 case HTMINBUTTON: |
985 case HTMAXBUTTON: { | 988 case HTMAXBUTTON: { |
986 // When the mouse is pressed down in these specific non-client areas, | 989 // When the mouse is pressed down in these specific non-client areas, |
987 // we need to tell the RootView to send the mouse pressed event (which | 990 // we need to tell the RootView to send the mouse pressed event (which |
988 // sets capture, allowing subsequent WM_LBUTTONUP (note, _not_ | 991 // sets capture, allowing subsequent WM_LBUTTONUP (note, _not_ |
989 // WM_NCLBUTTONUP) to fire so that the appropriate WM_SYSCOMMAND can be | 992 // WM_NCLBUTTONUP) to fire so that the appropriate WM_SYSCOMMAND can be |
990 // sent by the applicable button's ButtonListener. We _have_ to do this | 993 // sent by the applicable button's ButtonListener. We _have_ to do this |
991 // way rather than letting Windows just send the syscommand itself (as | 994 // way rather than letting Windows just send the syscommand itself (as |
992 // would happen if we never did this dance) because for some insane | 995 // would happen if we never did this dance) because for some insane |
993 // reason DefWindowProc for WM_NCLBUTTONDOWN also renders the pressed | 996 // reason DefWindowProc for WM_NCLBUTTONDOWN also renders the pressed |
994 // window control button appearance, in the Windows classic style, over | 997 // window control button appearance, in the Windows classic style, over |
995 // our view! Ick! By handling this message we prevent Windows from | 998 // our view! Ick! By handling this message we prevent Windows from |
996 // doing this undesirable thing, but that means we need to roll the | 999 // doing this undesirable thing, but that means we need to roll the |
997 // sys-command handling ourselves. | 1000 // sys-command handling ourselves. |
998 ProcessNCMousePress(point, MK_LBUTTON); | 1001 ProcessNCMousePress(message, w_param, l_param); |
999 return; | 1002 return 0; |
1000 } | 1003 } |
1001 } | 1004 } |
1002 } | 1005 } |
1003 | 1006 |
1004 WidgetWin::OnNCLButtonDown(ht_component, point); | 1007 WidgetWin::OnNCLButtonDown(message, w_param, l_param); |
1005 | 1008 |
1006 /* TODO(beng): Fix the standard non-client over-painting bug. This code | 1009 /* TODO(beng): Fix the standard non-client over-painting bug. This code |
1007 doesn't work but identifies the problem. | 1010 doesn't work but identifies the problem. |
1008 if (!IsMsgHandled()) { | 1011 if (!IsMsgHandled()) { |
1009 // WindowWin::OnNCLButtonDown set the message as unhandled. This normally | 1012 // WindowWin::OnNCLButtonDown set the message as unhandled. This normally |
1010 // means WidgetWin::ProcessWindowMessage will pass it to | 1013 // means WidgetWin::ProcessWindowMessage will pass it to |
1011 // DefWindowProc. Sadly, DefWindowProc for WM_NCLBUTTONDOWN does weird | 1014 // DefWindowProc. Sadly, DefWindowProc for WM_NCLBUTTONDOWN does weird |
1012 // non-client painting, so we need to call it directly here inside a | 1015 // non-client painting, so we need to call it directly here inside a |
1013 // scoped update lock. | 1016 // scoped update lock. |
1014 ScopedRedrawLock lock(this); | 1017 ScopedRedrawLock lock(this); |
1015 DefWindowProc(GetNativeView(), WM_NCLBUTTONDOWN, ht_component, | 1018 DefWindowProc(GetNativeView(), WM_NCLBUTTONDOWN, w_param, l_param); |
1016 MAKELPARAM(point.x, point.y)); | |
1017 SetMsgHandled(TRUE); | 1019 SetMsgHandled(TRUE); |
1018 } | 1020 } |
1019 */ | 1021 */ |
| 1022 return 0; |
1020 } | 1023 } |
1021 | 1024 |
1022 void WindowWin::OnNCRButtonDown(UINT ht_component, const CPoint& point) { | 1025 LRESULT WindowWin::OnNCRButtonDown(UINT message, |
1023 if (ht_component == HTCAPTION || ht_component == HTSYSMENU) { | 1026 WPARAM w_param, |
| 1027 LPARAM l_param) { |
| 1028 if (w_param == HTCAPTION || w_param == HTSYSMENU) { |
1024 is_right_mouse_pressed_on_caption_ = true; | 1029 is_right_mouse_pressed_on_caption_ = true; |
1025 // We SetCapture() to ensure we only show the menu when the button down and | 1030 // We SetCapture() to ensure we only show the menu when the button down and |
1026 // up are both on the caption. Note: this causes the button up to be | 1031 // up are both on the caption. Note: this causes the button up to be |
1027 // WM_RBUTTONUP instead of WM_NCRBUTTONUP. | 1032 // WM_RBUTTONUP instead of WM_NCRBUTTONUP. |
1028 SetCapture(); | 1033 SetCapture(); |
1029 } | 1034 } |
1030 | 1035 |
1031 WidgetWin::OnNCRButtonDown(ht_component, point); | 1036 WidgetWin::OnNCRButtonDown(message, w_param, l_param); |
| 1037 return 0; |
1032 } | 1038 } |
1033 | 1039 |
1034 void WindowWin::OnRButtonUp(UINT ht_component, const CPoint& point) { | 1040 LRESULT WindowWin::OnRButtonUp(UINT message, WPARAM w_param, LPARAM l_param) { |
1035 if (is_right_mouse_pressed_on_caption_) { | 1041 if (is_right_mouse_pressed_on_caption_) { |
1036 is_right_mouse_pressed_on_caption_ = false; | 1042 is_right_mouse_pressed_on_caption_ = false; |
1037 ReleaseCapture(); | 1043 ReleaseCapture(); |
1038 // |point| is in window coordinates, but WM_NCHITTEST and TrackPopupMenu() | 1044 // |point| is in window coordinates, but WM_NCHITTEST and TrackPopupMenu() |
1039 // expect screen coordinates. | 1045 // expect screen coordinates. |
1040 CPoint screen_point(point); | 1046 CPoint screen_point(GET_X_LPARAM(l_param), GET_Y_LPARAM(l_param)); |
1041 MapWindowPoints(GetNativeView(), HWND_DESKTOP, &screen_point, 1); | 1047 MapWindowPoints(GetNativeView(), HWND_DESKTOP, &screen_point, 1); |
1042 ht_component = SendMessage(GetNativeView(), WM_NCHITTEST, 0, | 1048 w_param = SendMessage(GetNativeView(), WM_NCHITTEST, 0, |
1043 MAKELPARAM(screen_point.x, screen_point.y)); | 1049 MAKELPARAM(screen_point.x, screen_point.y)); |
1044 if (ht_component == HTCAPTION || ht_component == HTSYSMENU) { | 1050 if (w_param == HTCAPTION || w_param == HTSYSMENU) { |
1045 UINT flags = TPM_LEFTBUTTON | TPM_RIGHTBUTTON | TPM_RETURNCMD; | 1051 UINT flags = TPM_LEFTBUTTON | TPM_RIGHTBUTTON | TPM_RETURNCMD; |
1046 if (base::i18n::IsRTL()) | 1052 if (base::i18n::IsRTL()) |
1047 flags |= TPM_RIGHTALIGN; | 1053 flags |= TPM_RIGHTALIGN; |
1048 HMENU system_menu = GetSystemMenu(GetNativeView(), FALSE); | 1054 HMENU system_menu = GetSystemMenu(GetNativeView(), FALSE); |
1049 int id = TrackPopupMenu(system_menu, flags, screen_point.x, | 1055 int id = TrackPopupMenu(system_menu, flags, screen_point.x, |
1050 screen_point.y, 0, GetNativeView(), NULL); | 1056 screen_point.y, 0, GetNativeView(), NULL); |
1051 ExecuteSystemMenuCommand(id); | 1057 ExecuteSystemMenuCommand(id); |
1052 return; | 1058 return 0; |
1053 } | 1059 } |
1054 } | 1060 } |
1055 | 1061 |
1056 WidgetWin::OnRButtonUp(ht_component, point); | 1062 WidgetWin::OnRButtonUp(message, w_param, l_param); |
| 1063 return 0; |
1057 } | 1064 } |
1058 | 1065 |
1059 LRESULT WindowWin::OnNCUAHDrawCaption(UINT msg, WPARAM w_param, | 1066 LRESULT WindowWin::OnNCUAHDrawCaption(UINT msg, WPARAM w_param, |
1060 LPARAM l_param) { | 1067 LPARAM l_param) { |
1061 // See comment in widget_win.h at the definition of WM_NCUAHDRAWCAPTION for | 1068 // See comment in widget_win.h at the definition of WM_NCUAHDRAWCAPTION for |
1062 // an explanation about why we need to handle this message. | 1069 // an explanation about why we need to handle this message. |
1063 SetMsgHandled(!non_client_view_->UseNativeFrame()); | 1070 SetMsgHandled(!non_client_view_->UseNativeFrame()); |
1064 return 0; | 1071 return 0; |
1065 } | 1072 } |
1066 | 1073 |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1468 VARIANT var; | 1475 VARIANT var; |
1469 AccessibilityTypes::State state = window_delegate_->accessible_state(); | 1476 AccessibilityTypes::State state = window_delegate_->accessible_state(); |
1470 if (state) { | 1477 if (state) { |
1471 var.lVal = ViewAccessibility::MSAAState(state); | 1478 var.lVal = ViewAccessibility::MSAAState(state); |
1472 hr = pAccPropServices->SetHwndProp(GetNativeView(), OBJID_CLIENT, | 1479 hr = pAccPropServices->SetHwndProp(GetNativeView(), OBJID_CLIENT, |
1473 CHILDID_SELF, PROPID_ACC_STATE, var); | 1480 CHILDID_SELF, PROPID_ACC_STATE, var); |
1474 } | 1481 } |
1475 } | 1482 } |
1476 } | 1483 } |
1477 | 1484 |
1478 void WindowWin::ProcessNCMousePress(const CPoint& point, int flags) { | 1485 // TODO(msw): ProcessNCMousePress could be made class/file private (or inlined i
n OnNCLButtonDown). |
1479 CPoint temp = point; | 1486 void WindowWin::ProcessNCMousePress(UINT message, |
1480 MapWindowPoints(HWND_DESKTOP, GetNativeView(), &temp, 1); | 1487 WPARAM w_param, |
1481 UINT message_flags = 0; | 1488 LPARAM l_param) { |
1482 if ((GetKeyState(VK_CONTROL) & 0x80) == 0x80) | 1489 // TODO(msw): Ensure point translation is correct. Move into ProcessMouseMoved
??? |
1483 message_flags |= MK_CONTROL; | 1490 CPoint point(GET_X_LPARAM(l_param), GET_Y_LPARAM(l_param)); |
1484 if ((GetKeyState(VK_SHIFT) & 0x80) == 0x80) | 1491 MapWindowPoints(HWND_DESKTOP, GetNativeView(), &point, 1); |
1485 message_flags |= MK_SHIFT; | 1492 l_param = MAKELPARAM(point.x, point.y); |
1486 message_flags |= flags; | 1493 // TODO(msw): Consolidate code with new Event processing? |
1487 ProcessMousePressed(temp, message_flags, false, false); | 1494 w_param |= ((GetKeyState(VK_CONTROL) & 0x80) == 0x80)? MK_CONTROL : 0; |
| 1495 w_param |= ((GetKeyState(VK_SHIFT) & 0x80) == 0x80)? MK_SHIFT : 0; |
| 1496 // TODO(msw): Why did this send non_client:=false to ProcessMousePressed??? |
| 1497 // Because this already did the xform? Can this be cleaned up? |
| 1498 DCHECK(message == WM_NCLBUTTONDOWN); |
| 1499 message = WM_LBUTTONDOWN; |
| 1500 ProcessMousePressed(message, w_param, l_param); |
1488 } | 1501 } |
1489 | 1502 |
1490 LRESULT WindowWin::CallDefaultNCActivateHandler(BOOL active) { | 1503 LRESULT WindowWin::CallDefaultNCActivateHandler(BOOL active) { |
1491 // The DefWindowProc handling for WM_NCACTIVATE renders the classic-look | 1504 // The DefWindowProc handling for WM_NCACTIVATE renders the classic-look |
1492 // window title bar directly, so we need to use a redraw lock here to prevent | 1505 // window title bar directly, so we need to use a redraw lock here to prevent |
1493 // it from doing so. | 1506 // it from doing so. |
1494 ScopedRedrawLock lock(this); | 1507 ScopedRedrawLock lock(this); |
1495 return DefWindowProc(GetNativeView(), WM_NCACTIVATE, active, 0); | 1508 return DefWindowProc(GetNativeView(), WM_NCACTIVATE, active, 0); |
1496 } | 1509 } |
1497 | 1510 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1542 Window::CloseSecondaryWidget(root_view->GetWidget()); | 1555 Window::CloseSecondaryWidget(root_view->GetWidget()); |
1543 return TRUE; | 1556 return TRUE; |
1544 } | 1557 } |
1545 } // namespace | 1558 } // namespace |
1546 | 1559 |
1547 void Window::CloseAllSecondaryWindows() { | 1560 void Window::CloseAllSecondaryWindows() { |
1548 EnumThreadWindows(GetCurrentThreadId(), WindowCallbackProc, 0); | 1561 EnumThreadWindows(GetCurrentThreadId(), WindowCallbackProc, 0); |
1549 } | 1562 } |
1550 | 1563 |
1551 } // namespace views | 1564 } // namespace views |
OLD | NEW |