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

Side by Side Diff: views/widget/native_widget_win.cc

Issue 7748036: Restoring a session should restore window minimization state on Windows (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 4 months 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 | Annotate | Revision Log
OLDNEW
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/native_widget_win.h" 5 #include "views/widget/native_widget_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/string_util.h" 10 #include "base/string_util.h"
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 return NULL; 630 return NULL;
631 } 631 }
632 632
633 void NativeWidgetWin::CenterWindow(const gfx::Size& size) { 633 void NativeWidgetWin::CenterWindow(const gfx::Size& size) {
634 HWND parent = GetParent(); 634 HWND parent = GetParent();
635 if (!IsWindow()) 635 if (!IsWindow())
636 parent = ::GetWindow(GetNativeView(), GW_OWNER); 636 parent = ::GetWindow(GetNativeView(), GW_OWNER);
637 ui::CenterAndSizeWindow(parent, GetNativeView(), size, false); 637 ui::CenterAndSizeWindow(parent, GetNativeView(), size, false);
638 } 638 }
639 639
640 void NativeWidgetWin::GetWindowBoundsAndMaximizedState(gfx::Rect* bounds, 640 void NativeWidgetWin::GetWindowBoundsAndShowState(
641 bool* maximized) const { 641 gfx::Rect* bounds,
642 ui::WindowShowState* show_state) const {
642 WINDOWPLACEMENT wp; 643 WINDOWPLACEMENT wp;
643 wp.length = sizeof(wp); 644 wp.length = sizeof(wp);
644 const bool succeeded = !!GetWindowPlacement(GetNativeView(), &wp); 645 const bool succeeded = !!GetWindowPlacement(GetNativeView(), &wp);
645 DCHECK(succeeded); 646 DCHECK(succeeded);
646 647
647 if (bounds != NULL) { 648 if (bounds != NULL) {
648 MONITORINFO mi; 649 MONITORINFO mi;
649 mi.cbSize = sizeof(mi); 650 mi.cbSize = sizeof(mi);
650 const bool succeeded = !!GetMonitorInfo( 651 const bool succeeded = !!GetMonitorInfo(
651 MonitorFromWindow(GetNativeView(), MONITOR_DEFAULTTONEAREST), &mi); 652 MonitorFromWindow(GetNativeView(), MONITOR_DEFAULTTONEAREST), &mi);
652 DCHECK(succeeded); 653 DCHECK(succeeded);
653 *bounds = gfx::Rect(wp.rcNormalPosition); 654 *bounds = gfx::Rect(wp.rcNormalPosition);
654 // Convert normal position from workarea coordinates to screen coordinates. 655 // Convert normal position from workarea coordinates to screen coordinates.
655 bounds->Offset(mi.rcWork.left - mi.rcMonitor.left, 656 bounds->Offset(mi.rcWork.left - mi.rcMonitor.left,
656 mi.rcWork.top - mi.rcMonitor.top); 657 mi.rcWork.top - mi.rcMonitor.top);
657 } 658 }
658 659
659 if (maximized != NULL) 660 if (show_state != NULL) {
660 *maximized = (wp.showCmd == SW_SHOWMAXIMIZED); 661 *show_state = ui::SHOW_STATE_NORMAL;
sky 2011/08/26 16:26:20 nit: put this as the last 'else' branch of the if.
dhollowa 2011/08/26 22:13:50 Done.
662 if (wp.showCmd == SW_SHOWMAXIMIZED)
663 *show_state = ui::SHOW_STATE_MAXIMIZED;
664 else if (wp.showCmd == SW_SHOWMINIMIZED)
665 *show_state = ui::SHOW_STATE_MINIMIZED;
666 }
661 } 667 }
662 668
663 void NativeWidgetWin::SetWindowTitle(const std::wstring& title) { 669 void NativeWidgetWin::SetWindowTitle(const std::wstring& title) {
664 SetWindowText(GetNativeView(), title.c_str()); 670 SetWindowText(GetNativeView(), title.c_str());
665 SetAccessibleName(title); 671 SetAccessibleName(title);
666 } 672 }
667 673
668 void NativeWidgetWin::SetWindowIcons(const SkBitmap& window_icon, 674 void NativeWidgetWin::SetWindowIcons(const SkBitmap& window_icon,
669 const SkBitmap& app_icon) { 675 const SkBitmap& app_icon) {
670 if (!window_icon.isNull()) { 676 if (!window_icon.isNull()) {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 return gfx::Rect(point.x, point.y, r.right - r.left, r.bottom - r.top); 760 return gfx::Rect(point.x, point.y, r.right - r.left, r.bottom - r.top);
755 } 761 }
756 762
757 gfx::Rect NativeWidgetWin::GetRestoredBounds() const { 763 gfx::Rect NativeWidgetWin::GetRestoredBounds() const {
758 // If we're in fullscreen mode, we've changed the normal bounds to the monitor 764 // If we're in fullscreen mode, we've changed the normal bounds to the monitor
759 // rect, so return the saved bounds instead. 765 // rect, so return the saved bounds instead.
760 if (IsFullscreen()) 766 if (IsFullscreen())
761 return gfx::Rect(saved_window_info_.window_rect); 767 return gfx::Rect(saved_window_info_.window_rect);
762 768
763 gfx::Rect bounds; 769 gfx::Rect bounds;
764 GetWindowBoundsAndMaximizedState(&bounds, NULL); 770 GetWindowBoundsAndShowState(&bounds, NULL);
765 return bounds; 771 return bounds;
766 } 772 }
767 773
768 void NativeWidgetWin::SetBounds(const gfx::Rect& bounds) { 774 void NativeWidgetWin::SetBounds(const gfx::Rect& bounds) {
769 LONG style = GetWindowLong(GWL_STYLE); 775 LONG style = GetWindowLong(GWL_STYLE);
770 if (style & WS_MAXIMIZE) 776 if (style & WS_MAXIMIZE)
771 SetWindowLong(GWL_STYLE, style & ~WS_MAXIMIZE); 777 SetWindowLong(GWL_STYLE, style & ~WS_MAXIMIZE);
772 SetWindowPos(NULL, bounds.x(), bounds.y(), bounds.width(), bounds.height(), 778 SetWindowPos(NULL, bounds.x(), bounds.y(), bounds.width(), bounds.height(),
773 SWP_NOACTIVATE | SWP_NOZORDER); 779 SWP_NOACTIVATE | SWP_NOZORDER);
774 } 780 }
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
861 // NOTE: Be careful not to activate any windows here (for example, calling 867 // NOTE: Be careful not to activate any windows here (for example, calling
862 // ShowWindow(SW_HIDE) will automatically activate another window). This 868 // ShowWindow(SW_HIDE) will automatically activate another window). This
863 // code can be called while a window is being deactivated, and activating 869 // code can be called while a window is being deactivated, and activating
864 // another window will screw up the activation that is already in progress. 870 // another window will screw up the activation that is already in progress.
865 SetWindowPos(NULL, 0, 0, 0, 0, 871 SetWindowPos(NULL, 0, 0, 0, 0,
866 SWP_HIDEWINDOW | SWP_NOACTIVATE | SWP_NOMOVE | 872 SWP_HIDEWINDOW | SWP_NOACTIVATE | SWP_NOMOVE |
867 SWP_NOREPOSITION | SWP_NOSIZE | SWP_NOZORDER); 873 SWP_NOREPOSITION | SWP_NOSIZE | SWP_NOZORDER);
868 } 874 }
869 } 875 }
870 876
871 void NativeWidgetWin::ShowMaximizedWithBounds( 877 void NativeWidgetWin::ShowMaximizedWithBounds(
sky 2011/08/26 16:26:20 Are you sure we don't need something similar for m
dhollowa 2011/08/26 22:13:50 Yes, my understanding is that with maximize the |S
872 const gfx::Rect& restored_bounds) { 878 const gfx::Rect& restored_bounds) {
873 WINDOWPLACEMENT placement = { 0 }; 879 WINDOWPLACEMENT placement = { 0 };
874 placement.length = sizeof(WINDOWPLACEMENT); 880 placement.length = sizeof(WINDOWPLACEMENT);
875 placement.showCmd = SW_SHOWMAXIMIZED; 881 placement.showCmd = SW_SHOWMAXIMIZED;
876 placement.rcNormalPosition = restored_bounds.ToRECT(); 882 placement.rcNormalPosition = restored_bounds.ToRECT();
877 SetWindowPlacement(hwnd(), &placement); 883 SetWindowPlacement(hwnd(), &placement);
878 } 884 }
879 885
880 void NativeWidgetWin::ShowWithState(ShowState state) { 886 void NativeWidgetWin::ShowWithWindowState(ui::WindowShowState show_state) {
881 DWORD native_show_state; 887 DWORD native_show_state;
882 switch (state) { 888 switch (show_state) {
883 case SHOW_INACTIVE: 889 case ui::SHOW_STATE_INACTIVE:
884 native_show_state = SW_SHOWNOACTIVATE; 890 native_show_state = SW_SHOWNOACTIVATE;
885 break; 891 break;
886 case SHOW_MAXIMIZED: 892 case ui::SHOW_STATE_MAXIMIZED:
887 native_show_state = SW_SHOWMAXIMIZED; 893 native_show_state = SW_SHOWMAXIMIZED;
888 break; 894 break;
895 case ui::SHOW_STATE_MINIMIZED:
896 native_show_state = SW_SHOWMINIMIZED;
897 break;
889 default: 898 default:
890 native_show_state = GetShowState(); 899 native_show_state = GetShowState();
891 break; 900 break;
892 } 901 }
893 Show(native_show_state); 902 Show(native_show_state);
894 } 903 }
895 904
896 bool NativeWidgetWin::IsVisible() const { 905 bool NativeWidgetWin::IsVisible() const {
897 return !!::IsWindowVisible(hwnd()); 906 return !!::IsWindowVisible(hwnd());
898 } 907 }
(...skipping 1267 matching lines...) Expand 10 before | Expand all | Expand 10 after
2166 // Set non-style attributes. 2175 // Set non-style attributes.
2167 ownership_ = params.ownership; 2176 ownership_ = params.ownership;
2168 2177
2169 DWORD style = WS_CLIPCHILDREN | WS_CLIPSIBLINGS; 2178 DWORD style = WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
2170 DWORD ex_style = 0; 2179 DWORD ex_style = 0;
2171 DWORD class_style = CS_DBLCLKS; 2180 DWORD class_style = CS_DBLCLKS;
2172 2181
2173 // Set type-independent style attributes. 2182 // Set type-independent style attributes.
2174 if (params.child) 2183 if (params.child)
2175 style |= WS_CHILD | WS_VISIBLE; 2184 style |= WS_CHILD | WS_VISIBLE;
2176 if (params.maximize) 2185 if (params.show_state == ui::SHOW_STATE_MAXIMIZED)
2177 style |= WS_MAXIMIZE; 2186 style |= WS_MAXIMIZE;
2187 if (params.show_state == ui::SHOW_STATE_MINIMIZED)
2188 style |= WS_MINIMIZE;
2178 if (!params.accept_events) 2189 if (!params.accept_events)
2179 ex_style |= WS_EX_TRANSPARENT; 2190 ex_style |= WS_EX_TRANSPARENT;
2180 if (!params.can_activate) 2191 if (!params.can_activate)
2181 ex_style |= WS_EX_NOACTIVATE; 2192 ex_style |= WS_EX_NOACTIVATE;
2182 if (params.keep_on_top) 2193 if (params.keep_on_top)
2183 ex_style |= WS_EX_TOPMOST; 2194 ex_style |= WS_EX_TOPMOST;
2184 if (params.mirror_origin_in_rtl) 2195 if (params.mirror_origin_in_rtl)
2185 ex_style |= l10n_util::GetExtendedTooltipStyles(); 2196 ex_style |= l10n_util::GetExtendedTooltipStyles();
2186 if (params.transparent) 2197 if (params.transparent)
2187 ex_style |= WS_EX_LAYERED; 2198 ex_style |= WS_EX_LAYERED;
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
2530 return (GetKeyState(VK_LBUTTON) & 0x80) || 2541 return (GetKeyState(VK_LBUTTON) & 0x80) ||
2531 (GetKeyState(VK_RBUTTON) & 0x80) || 2542 (GetKeyState(VK_RBUTTON) & 0x80) ||
2532 (GetKeyState(VK_MBUTTON) & 0x80) || 2543 (GetKeyState(VK_MBUTTON) & 0x80) ||
2533 (GetKeyState(VK_XBUTTON1) & 0x80) || 2544 (GetKeyState(VK_XBUTTON1) & 0x80) ||
2534 (GetKeyState(VK_XBUTTON2) & 0x80); 2545 (GetKeyState(VK_XBUTTON2) & 0x80);
2535 } 2546 }
2536 2547
2537 } // namespace internal 2548 } // namespace internal
2538 2549
2539 } // namespace views 2550 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698