Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(638)

Side by Side Diff: ui/views/win/hwnd_message_handler.cc

Issue 2484643003: Revert of Restore maximized window position after detaching display. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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_);
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
2254 // If the size of a background fullscreen window changes again, then we 2233 // If the size of a background fullscreen window changes again, then we
2255 // should reset the |background_fullscreen_hack_| flag. 2234 // should reset the |background_fullscreen_hack_| flag.
2256 if (background_fullscreen_hack_ && 2235 if (background_fullscreen_hack_ &&
2257 (!(window_pos->flags & SWP_NOSIZE) && 2236 (!(window_pos->flags & SWP_NOSIZE) &&
2258 (monitor_rect.height() - window_pos->cy != 1))) { 2237 (monitor_rect.height() - window_pos->cy != 1))) {
2259 background_fullscreen_hack_ = false; 2238 background_fullscreen_hack_ = false;
2260 } 2239 }
2261 const bool fullscreen_without_hack = 2240 if (monitor && (monitor == last_monitor_) &&
2262 IsFullscreen() && !background_fullscreen_hack_; 2241 ((IsFullscreen() && !background_fullscreen_hack_) ||
2263 2242 work_area_changed)) {
2264 if (incorrect_maximized_bounds ||
2265 (same_monitor && (fullscreen_without_hack || work_area_changed))) {
2266 // A rect for the monitor we're on changed. Normally Windows notifies 2243 // A rect for the monitor we're on changed. Normally Windows notifies
2267 // us about this (and thus we're reaching here due to the SetWindowPos() 2244 // us about this (and thus we're reaching here due to the SetWindowPos()
2268 // call in OnSettingChange() above), but with some software (e.g. 2245 // call in OnSettingChange() above), but with some software (e.g.
2269 // nVidia's nView desktop manager) the work area can change asynchronous 2246 // nVidia's nView desktop manager) the work area can change asynchronous
2270 // to any notification, and we're just sent a SetWindowPos() call with a 2247 // to any notification, and we're just sent a SetWindowPos() call with a
2271 // new (frequently incorrect) position/size. In either case, the best 2248 // new (frequently incorrect) position/size. In either case, the best
2272 // response is to throw away the existing position/size information in 2249 // response is to throw away the existing position/size information in
2273 // |window_pos| and recalculate it based on the new work rect. 2250 // |window_pos| and recalculate it based on the new work rect.
2274 gfx::Rect new_window_rect; 2251 gfx::Rect new_window_rect;
2275 if (IsFullscreen()) { 2252 if (IsFullscreen()) {
2276 new_window_rect = monitor_rect; 2253 new_window_rect = monitor_rect;
2277 } else if (IsMaximized()) { 2254 } else if (IsMaximized()) {
2278 new_window_rect = expected_maximized_bounds; 2255 new_window_rect = work_area;
2256 int border_thickness = GetSystemMetrics(SM_CXSIZEFRAME);
2257 new_window_rect.Inset(-border_thickness, -border_thickness);
2279 } else { 2258 } else {
2280 new_window_rect = gfx::Rect(window_rect); 2259 new_window_rect = gfx::Rect(window_rect);
2281 new_window_rect.AdjustToFit(work_area); 2260 new_window_rect.AdjustToFit(work_area);
2282 } 2261 }
2283 window_pos->x = new_window_rect.x(); 2262 window_pos->x = new_window_rect.x();
2284 window_pos->y = new_window_rect.y(); 2263 window_pos->y = new_window_rect.y();
2285 window_pos->cx = new_window_rect.width(); 2264 window_pos->cx = new_window_rect.width();
2286 window_pos->cy = new_window_rect.height(); 2265 window_pos->cy = new_window_rect.height();
2287 // WARNING! Don't set SWP_FRAMECHANGED here, it breaks moving the child 2266 // WARNING! Don't set SWP_FRAMECHANGED here, it breaks moving the child
2288 // HWNDs for some reason. 2267 // HWNDs for some reason.
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
2731 MONITORINFO monitor_info = {sizeof(monitor_info)}; 2710 MONITORINFO monitor_info = {sizeof(monitor_info)};
2732 GetMonitorInfo(MonitorFromWindow(hwnd(), MONITOR_DEFAULTTOPRIMARY), 2711 GetMonitorInfo(MonitorFromWindow(hwnd(), MONITOR_DEFAULTTOPRIMARY),
2733 &monitor_info); 2712 &monitor_info);
2734 gfx::Rect shrunk_rect(monitor_info.rcMonitor); 2713 gfx::Rect shrunk_rect(monitor_info.rcMonitor);
2735 shrunk_rect.set_height(shrunk_rect.height() - 1); 2714 shrunk_rect.set_height(shrunk_rect.height() - 1);
2736 background_fullscreen_hack_ = true; 2715 background_fullscreen_hack_ = true;
2737 SetBoundsInternal(shrunk_rect, false); 2716 SetBoundsInternal(shrunk_rect, false);
2738 } 2717 }
2739 2718
2740 } // namespace views 2719 } // namespace views
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698