OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/views/win/hwnd_message_handler.h" | 5 #include "ui/views/win/hwnd_message_handler.h" |
6 | 6 |
7 #include <dwmapi.h> | 7 #include <dwmapi.h> |
8 #include <shellapi.h> | 8 #include <shellapi.h> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 966 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
977 TrackMouseEvents(mouse_tracking_flags); | 977 TrackMouseEvents(mouse_tracking_flags); |
978 } | 978 } |
979 } | 979 } |
980 | 980 |
981 void HWNDMessageHandler::ClientAreaSizeChanged() { | 981 void HWNDMessageHandler::ClientAreaSizeChanged() { |
982 RECT r = {0, 0, 0, 0}; | 982 RECT r = {0, 0, 0, 0}; |
983 // In case of minimized window GetWindowRect can return normally unexpected | 983 // In case of minimized window GetWindowRect can return normally unexpected |
984 // coordinates. | 984 // coordinates. |
985 if (!IsMinimized()) { | 985 if (!IsMinimized()) { |
986 if (delegate_->WidgetSizeIsClientSize()) { | 986 if (delegate_->WidgetSizeIsClientSize()) { |
987 GetClientRect(hwnd(), &r); | 987 GetClientRect(hwnd(), &r); |
988 // This is needed due to a hack that works around a "feature" in | 988 // This is needed due to a hack that works around a "feature" in |
989 // Windows's handling of WM_NCCALCSIZE. See the comment near the end of | 989 // Windows's handling of WM_NCCALCSIZE. See the comment near the end of |
990 // GetClientAreaInsets for more details. | 990 // GetClientAreaInsets for more details. |
991 if (remove_standard_frame_) | 991 if (remove_standard_frame_ && !IsMaximized()) |
992 r.bottom += kClientAreaBottomInsetHack; | 992 r.bottom += kClientAreaBottomInsetHack; |
993 } else { | 993 } else { |
994 GetWindowRect(hwnd(), &r); | 994 GetWindowRect(hwnd(), &r); |
995 } | 995 } |
996 } | 996 } |
997 gfx::Size s(std::max(0, static_cast<int>(r.right - r.left)), | 997 gfx::Size s(std::max(0, static_cast<int>(r.right - r.left)), |
998 std::max(0, static_cast<int>(r.bottom - r.top))); | 998 std::max(0, static_cast<int>(r.bottom - r.top))); |
999 delegate_->HandleClientSizeChanged(s); | 999 delegate_->HandleClientSizeChanged(s); |
1000 if (use_layered_buffer_) { | 1000 if (use_layered_buffer_) { |
1001 layered_window_contents_.reset( | 1001 layered_window_contents_.reset( |
1002 new gfx::Canvas(s, ui::SCALE_FACTOR_100P, false)); | 1002 new gfx::Canvas(s, ui::SCALE_FACTOR_100P, false)); |
(...skipping 10 matching lines...) Expand all Loading... |
1013 // NativeWidgetWin::OnNCCalcSize() to be invoked. | 1013 // NativeWidgetWin::OnNCCalcSize() to be invoked. |
1014 if (!delegate_->IsWidgetWindow() || | 1014 if (!delegate_->IsWidgetWindow() || |
1015 (!delegate_->IsUsingCustomFrame() && !remove_standard_frame_)) { | 1015 (!delegate_->IsUsingCustomFrame() && !remove_standard_frame_)) { |
1016 return insets; | 1016 return insets; |
1017 } | 1017 } |
1018 | 1018 |
1019 if (IsMaximized()) { | 1019 if (IsMaximized()) { |
1020 // Windows automatically adds a standard width border to all sides when a | 1020 // Windows automatically adds a standard width border to all sides when a |
1021 // window is maximized. | 1021 // window is maximized. |
1022 int border_thickness = GetSystemMetrics(SM_CXSIZEFRAME); | 1022 int border_thickness = GetSystemMetrics(SM_CXSIZEFRAME); |
| 1023 if (remove_standard_frame_) |
| 1024 border_thickness -= 1; |
1023 return gfx::Insets(border_thickness, border_thickness, border_thickness, | 1025 return gfx::Insets(border_thickness, border_thickness, border_thickness, |
1024 border_thickness); | 1026 border_thickness); |
1025 } | 1027 } |
1026 | 1028 |
1027 // Returning empty insets for a window with the standard frame removed seems | 1029 // Returning empty insets for a window with the standard frame removed seems |
1028 // to cause Windows to treat the window specially, treating black as | 1030 // to cause Windows to treat the window specially, treating black as |
1029 // transparent and changing around some of the painting logic. I suspect it's | 1031 // transparent and changing around some of the painting logic. I suspect it's |
1030 // some sort of horrible backwards-compatability hack, but the upshot of it | 1032 // some sort of horrible backwards-compatability hack, but the upshot of it |
1031 // is that if the insets are empty then in certain conditions (it seems to | 1033 // is that if the insets are empty then in certain conditions (it seems to |
1032 // be subtly related to timing), the contents of windows with the standard | 1034 // be subtly related to timing), the contents of windows with the standard |
1033 // frame removed will flicker to transparent during resize. | 1035 // frame removed will flicker to transparent during resize. |
1034 // | 1036 // |
1035 // To work around this, we increase the size of the client area by 1px | 1037 // To work around this, we increase the size of the client area by 1px |
1036 // *beyond* the bottom of the window. This prevents Windows from having a | 1038 // *beyond* the bottom of the window. This prevents Windows from having a |
1037 // hissy fit and flashing the window incessantly during resizes, but it also | 1039 // hissy fit and flashing the window incessantly during resizes, but it also |
1038 // means that the client area is reported 1px larger than it really is, so | 1040 // means that the client area is reported 1px larger than it really is, so |
1039 // user code has to compensate by making its content shorter if it wants | 1041 // user code has to compensate by making its content shorter if it wants |
1040 // everything to appear inside the window. | 1042 // everything to appear inside the window. |
1041 if (remove_standard_frame_) | 1043 if (remove_standard_frame_) |
1042 return gfx::Insets(0, 0, kClientAreaBottomInsetHack, 0); | 1044 return gfx::Insets(0, 0, IsMaximized() ? 0 : kClientAreaBottomInsetHack, 0); |
1043 // This is weird, but highly essential. If we don't offset the bottom edge | 1045 // This is weird, but highly essential. If we don't offset the bottom edge |
1044 // of the client rect, the window client area and window area will match, | 1046 // of the client rect, the window client area and window area will match, |
1045 // and when returning to glass rendering mode from non-glass, the client | 1047 // and when returning to glass rendering mode from non-glass, the client |
1046 // area will not paint black as transparent. This is because (and I don't | 1048 // area will not paint black as transparent. This is because (and I don't |
1047 // know why) the client area goes from matching the window rect to being | 1049 // know why) the client area goes from matching the window rect to being |
1048 // something else. If the client area is not the window rect in both | 1050 // something else. If the client area is not the window rect in both |
1049 // modes, the blackness doesn't occur. Because of this, we need to tell | 1051 // modes, the blackness doesn't occur. Because of this, we need to tell |
1050 // the RootView to lay out to fit the window rect, rather than the client | 1052 // the RootView to lay out to fit the window rect, rather than the client |
1051 // rect when using the opaque frame. | 1053 // rect when using the opaque frame. |
1052 // Note: this is only required for non-fullscreen windows. Note that | 1054 // Note: this is only required for non-fullscreen windows. Note that |
(...skipping 1044 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2097 DwmExtendFrameIntoClientArea(hwnd(), &m); | 2099 DwmExtendFrameIntoClientArea(hwnd(), &m); |
2098 } | 2100 } |
2099 if (window_pos->flags & SWP_SHOWWINDOW) | 2101 if (window_pos->flags & SWP_SHOWWINDOW) |
2100 delegate_->HandleVisibilityChanged(true); | 2102 delegate_->HandleVisibilityChanged(true); |
2101 else if (window_pos->flags & SWP_HIDEWINDOW) | 2103 else if (window_pos->flags & SWP_HIDEWINDOW) |
2102 delegate_->HandleVisibilityChanged(false); | 2104 delegate_->HandleVisibilityChanged(false); |
2103 SetMsgHandled(FALSE); | 2105 SetMsgHandled(FALSE); |
2104 } | 2106 } |
2105 | 2107 |
2106 } // namespace views | 2108 } // namespace views |
OLD | NEW |