Chromium Code Reviews| 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 <oleacc.h> | 8 #include <oleacc.h> |
| 9 #include <shellapi.h> | 9 #include <shellapi.h> |
| 10 #include <tchar.h> | 10 #include <tchar.h> |
| (...skipping 2212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2223 window_pos->flags &= ~(SWP_SHOWWINDOW | SWP_HIDEWINDOW); | 2223 window_pos->flags &= ~(SWP_SHOWWINDOW | SWP_HIDEWINDOW); |
| 2224 } | 2224 } |
| 2225 } else if (!GetParent(hwnd())) { | 2225 } else if (!GetParent(hwnd())) { |
| 2226 RECT window_rect; | 2226 RECT window_rect; |
| 2227 HMONITOR monitor; | 2227 HMONITOR monitor; |
| 2228 gfx::Rect monitor_rect, work_area; | 2228 gfx::Rect monitor_rect, work_area; |
| 2229 if (GetWindowRect(hwnd(), &window_rect) && | 2229 if (GetWindowRect(hwnd(), &window_rect) && |
| 2230 GetMonitorAndRects(window_rect, &monitor, &monitor_rect, &work_area)) { | 2230 GetMonitorAndRects(window_rect, &monitor, &monitor_rect, &work_area)) { |
| 2231 bool work_area_changed = (monitor_rect == last_monitor_rect_) && | 2231 bool work_area_changed = (monitor_rect == last_monitor_rect_) && |
| 2232 (work_area != last_work_area_); | 2232 (work_area != last_work_area_); |
| 2233 const bool same_monitor = monitor && (monitor == last_monitor_); | |
|
ananta
2016/10/06 19:59:57
If a monitor is attached or detached, do we get a
atimoxin
2016/10/07 15:27:22
Yes, we get this message, but we get it before the
| |
| 2234 | |
| 2235 gfx::Rect expected_maximized_bounds = work_area; | |
| 2236 if (IsMaximized()) { | |
| 2237 // Windows automatically adds a standard width border to all sides when | |
| 2238 // window is maximized. We should take this into account. | |
| 2239 gfx::Insets client_area_insets; | |
| 2240 if (GetClientAreaInsets(&client_area_insets)) | |
| 2241 expected_maximized_bounds.Inset(client_area_insets.Scale(-1)); | |
| 2242 } | |
| 2243 // Sometimes Windows incorrectly changes bounds of maximized windows after | |
| 2244 // attaching or detaching additional displays. In this case user can see | |
| 2245 // non-client area of the window (that should be hidden in normal case). | |
| 2246 // We should restore window position if problem occurs. | |
| 2247 const bool incorrect_maximized_bounds = | |
| 2248 IsMaximized() && | |
| 2249 (expected_maximized_bounds.x() != window_pos->x || | |
| 2250 expected_maximized_bounds.y() != window_pos->y || | |
| 2251 expected_maximized_bounds.width() != window_pos->cx || | |
| 2252 expected_maximized_bounds.height() != window_pos->cy); | |
| 2253 | |
| 2233 // If the size of a background fullscreen window changes again, then we | 2254 // If the size of a background fullscreen window changes again, then we |
| 2234 // should reset the |background_fullscreen_hack_| flag. | 2255 // should reset the |background_fullscreen_hack_| flag. |
| 2235 if (background_fullscreen_hack_ && | 2256 if (background_fullscreen_hack_ && |
| 2236 (!(window_pos->flags & SWP_NOSIZE) && | 2257 (!(window_pos->flags & SWP_NOSIZE) && |
| 2237 (monitor_rect.height() - window_pos->cy != 1))) { | 2258 (monitor_rect.height() - window_pos->cy != 1))) { |
| 2238 background_fullscreen_hack_ = false; | 2259 background_fullscreen_hack_ = false; |
| 2239 } | 2260 } |
| 2240 if (monitor && (monitor == last_monitor_) && | 2261 const bool fullscreen_without_hack = |
| 2241 ((IsFullscreen() && !background_fullscreen_hack_) || | 2262 IsFullscreen() && !background_fullscreen_hack_; |
| 2242 work_area_changed)) { | 2263 |
| 2264 if (incorrect_maximized_bounds || | |
| 2265 (same_monitor && (fullscreen_without_hack || work_area_changed))) { | |
| 2243 // A rect for the monitor we're on changed. Normally Windows notifies | 2266 // A rect for the monitor we're on changed. Normally Windows notifies |
| 2244 // us about this (and thus we're reaching here due to the SetWindowPos() | 2267 // us about this (and thus we're reaching here due to the SetWindowPos() |
| 2245 // call in OnSettingChange() above), but with some software (e.g. | 2268 // call in OnSettingChange() above), but with some software (e.g. |
| 2246 // nVidia's nView desktop manager) the work area can change asynchronous | 2269 // nVidia's nView desktop manager) the work area can change asynchronous |
| 2247 // to any notification, and we're just sent a SetWindowPos() call with a | 2270 // to any notification, and we're just sent a SetWindowPos() call with a |
| 2248 // new (frequently incorrect) position/size. In either case, the best | 2271 // new (frequently incorrect) position/size. In either case, the best |
| 2249 // response is to throw away the existing position/size information in | 2272 // response is to throw away the existing position/size information in |
| 2250 // |window_pos| and recalculate it based on the new work rect. | 2273 // |window_pos| and recalculate it based on the new work rect. |
| 2251 gfx::Rect new_window_rect; | 2274 gfx::Rect new_window_rect; |
| 2252 if (IsFullscreen()) { | 2275 if (IsFullscreen()) { |
| 2253 new_window_rect = monitor_rect; | 2276 new_window_rect = monitor_rect; |
| 2254 } else if (IsMaximized()) { | 2277 } else if (IsMaximized()) { |
| 2255 new_window_rect = work_area; | 2278 new_window_rect = expected_maximized_bounds; |
| 2256 int border_thickness = GetSystemMetrics(SM_CXSIZEFRAME); | |
| 2257 new_window_rect.Inset(-border_thickness, -border_thickness); | |
| 2258 } else { | 2279 } else { |
| 2259 new_window_rect = gfx::Rect(window_rect); | 2280 new_window_rect = gfx::Rect(window_rect); |
| 2260 new_window_rect.AdjustToFit(work_area); | 2281 new_window_rect.AdjustToFit(work_area); |
| 2261 } | 2282 } |
| 2262 window_pos->x = new_window_rect.x(); | 2283 window_pos->x = new_window_rect.x(); |
| 2263 window_pos->y = new_window_rect.y(); | 2284 window_pos->y = new_window_rect.y(); |
| 2264 window_pos->cx = new_window_rect.width(); | 2285 window_pos->cx = new_window_rect.width(); |
| 2265 window_pos->cy = new_window_rect.height(); | 2286 window_pos->cy = new_window_rect.height(); |
| 2266 // WARNING! Don't set SWP_FRAMECHANGED here, it breaks moving the child | 2287 // WARNING! Don't set SWP_FRAMECHANGED here, it breaks moving the child |
| 2267 // HWNDs for some reason. | 2288 // HWNDs for some reason. |
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2710 MONITORINFO monitor_info = {sizeof(monitor_info)}; | 2731 MONITORINFO monitor_info = {sizeof(monitor_info)}; |
| 2711 GetMonitorInfo(MonitorFromWindow(hwnd(), MONITOR_DEFAULTTOPRIMARY), | 2732 GetMonitorInfo(MonitorFromWindow(hwnd(), MONITOR_DEFAULTTOPRIMARY), |
| 2712 &monitor_info); | 2733 &monitor_info); |
| 2713 gfx::Rect shrunk_rect(monitor_info.rcMonitor); | 2734 gfx::Rect shrunk_rect(monitor_info.rcMonitor); |
| 2714 shrunk_rect.set_height(shrunk_rect.height() - 1); | 2735 shrunk_rect.set_height(shrunk_rect.height() - 1); |
| 2715 background_fullscreen_hack_ = true; | 2736 background_fullscreen_hack_ = true; |
| 2716 SetBoundsInternal(shrunk_rect, false); | 2737 SetBoundsInternal(shrunk_rect, false); |
| 2717 } | 2738 } |
| 2718 | 2739 |
| 2719 } // namespace views | 2740 } // namespace views |
| OLD | NEW |