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

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: GetSavedWindowPlacement consolidation, Test, and All case. Created 9 years, 3 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::GetWindowPlacement(
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 if (wp.showCmd == SW_SHOWMAXIMIZED)
662 *show_state = ui::SHOW_STATE_MAXIMIZED;
663 else if (wp.showCmd == SW_SHOWMINIMIZED)
664 *show_state = ui::SHOW_STATE_MINIMIZED;
665 else
666 *show_state = ui::SHOW_STATE_NORMAL;
667 }
661 } 668 }
662 669
663 void NativeWidgetWin::SetWindowTitle(const std::wstring& title) { 670 void NativeWidgetWin::SetWindowTitle(const std::wstring& title) {
664 SetWindowText(GetNativeView(), title.c_str()); 671 SetWindowText(GetNativeView(), title.c_str());
665 SetAccessibleName(title); 672 SetAccessibleName(title);
666 } 673 }
667 674
668 void NativeWidgetWin::SetWindowIcons(const SkBitmap& window_icon, 675 void NativeWidgetWin::SetWindowIcons(const SkBitmap& window_icon,
669 const SkBitmap& app_icon) { 676 const SkBitmap& app_icon) {
670 if (!window_icon.isNull()) { 677 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); 761 return gfx::Rect(point.x, point.y, r.right - r.left, r.bottom - r.top);
755 } 762 }
756 763
757 gfx::Rect NativeWidgetWin::GetRestoredBounds() const { 764 gfx::Rect NativeWidgetWin::GetRestoredBounds() const {
758 // If we're in fullscreen mode, we've changed the normal bounds to the monitor 765 // If we're in fullscreen mode, we've changed the normal bounds to the monitor
759 // rect, so return the saved bounds instead. 766 // rect, so return the saved bounds instead.
760 if (IsFullscreen()) 767 if (IsFullscreen())
761 return gfx::Rect(saved_window_info_.window_rect); 768 return gfx::Rect(saved_window_info_.window_rect);
762 769
763 gfx::Rect bounds; 770 gfx::Rect bounds;
764 GetWindowBoundsAndMaximizedState(&bounds, NULL); 771 GetWindowPlacement(&bounds, NULL);
765 return bounds; 772 return bounds;
766 } 773 }
767 774
768 void NativeWidgetWin::SetBounds(const gfx::Rect& bounds) { 775 void NativeWidgetWin::SetBounds(const gfx::Rect& bounds) {
769 LONG style = GetWindowLong(GWL_STYLE); 776 LONG style = GetWindowLong(GWL_STYLE);
770 if (style & WS_MAXIMIZE) 777 if (style & WS_MAXIMIZE)
771 SetWindowLong(GWL_STYLE, style & ~WS_MAXIMIZE); 778 SetWindowLong(GWL_STYLE, style & ~WS_MAXIMIZE);
772 SetWindowPos(NULL, bounds.x(), bounds.y(), bounds.width(), bounds.height(), 779 SetWindowPos(NULL, bounds.x(), bounds.y(), bounds.width(), bounds.height(),
773 SWP_NOACTIVATE | SWP_NOZORDER); 780 SWP_NOACTIVATE | SWP_NOZORDER);
774 } 781 }
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
870 877
871 void NativeWidgetWin::ShowMaximizedWithBounds( 878 void NativeWidgetWin::ShowMaximizedWithBounds(
872 const gfx::Rect& restored_bounds) { 879 const gfx::Rect& restored_bounds) {
873 WINDOWPLACEMENT placement = { 0 }; 880 WINDOWPLACEMENT placement = { 0 };
874 placement.length = sizeof(WINDOWPLACEMENT); 881 placement.length = sizeof(WINDOWPLACEMENT);
875 placement.showCmd = SW_SHOWMAXIMIZED; 882 placement.showCmd = SW_SHOWMAXIMIZED;
876 placement.rcNormalPosition = restored_bounds.ToRECT(); 883 placement.rcNormalPosition = restored_bounds.ToRECT();
877 SetWindowPlacement(hwnd(), &placement); 884 SetWindowPlacement(hwnd(), &placement);
878 } 885 }
879 886
880 void NativeWidgetWin::ShowWithState(ShowState state) { 887 void NativeWidgetWin::ShowWithWindowState(ui::WindowShowState show_state) {
881 DWORD native_show_state; 888 DWORD native_show_state;
882 switch (state) { 889 switch (show_state) {
883 case SHOW_INACTIVE: 890 case ui::SHOW_STATE_INACTIVE:
884 native_show_state = SW_SHOWNOACTIVATE; 891 native_show_state = SW_SHOWNOACTIVATE;
885 break; 892 break;
886 case SHOW_MAXIMIZED: 893 case ui::SHOW_STATE_MAXIMIZED:
887 native_show_state = SW_SHOWMAXIMIZED; 894 native_show_state = SW_SHOWMAXIMIZED;
888 break; 895 break;
896 case ui::SHOW_STATE_MINIMIZED:
897 native_show_state = SW_SHOWMINIMIZED;
898 break;
889 default: 899 default:
890 native_show_state = GetShowState(); 900 native_show_state = GetShowState();
891 break; 901 break;
892 } 902 }
893 Show(native_show_state); 903 Show(native_show_state);
894 } 904 }
895 905
896 bool NativeWidgetWin::IsVisible() const { 906 bool NativeWidgetWin::IsVisible() const {
897 return !!::IsWindowVisible(hwnd()); 907 return !!::IsWindowVisible(hwnd());
898 } 908 }
(...skipping 1267 matching lines...) Expand 10 before | Expand all | Expand 10 after
2166 // Set non-style attributes. 2176 // Set non-style attributes.
2167 ownership_ = params.ownership; 2177 ownership_ = params.ownership;
2168 2178
2169 DWORD style = WS_CLIPCHILDREN | WS_CLIPSIBLINGS; 2179 DWORD style = WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
2170 DWORD ex_style = 0; 2180 DWORD ex_style = 0;
2171 DWORD class_style = CS_DBLCLKS; 2181 DWORD class_style = CS_DBLCLKS;
2172 2182
2173 // Set type-independent style attributes. 2183 // Set type-independent style attributes.
2174 if (params.child) 2184 if (params.child)
2175 style |= WS_CHILD | WS_VISIBLE; 2185 style |= WS_CHILD | WS_VISIBLE;
2176 if (params.maximize) 2186 if (params.show_state == ui::SHOW_STATE_MAXIMIZED)
2177 style |= WS_MAXIMIZE; 2187 style |= WS_MAXIMIZE;
2188 if (params.show_state == ui::SHOW_STATE_MINIMIZED)
2189 style |= WS_MINIMIZE;
2178 if (!params.accept_events) 2190 if (!params.accept_events)
2179 ex_style |= WS_EX_TRANSPARENT; 2191 ex_style |= WS_EX_TRANSPARENT;
2180 if (!params.can_activate) 2192 if (!params.can_activate)
2181 ex_style |= WS_EX_NOACTIVATE; 2193 ex_style |= WS_EX_NOACTIVATE;
2182 if (params.keep_on_top) 2194 if (params.keep_on_top)
2183 ex_style |= WS_EX_TOPMOST; 2195 ex_style |= WS_EX_TOPMOST;
2184 if (params.mirror_origin_in_rtl) 2196 if (params.mirror_origin_in_rtl)
2185 ex_style |= l10n_util::GetExtendedTooltipStyles(); 2197 ex_style |= l10n_util::GetExtendedTooltipStyles();
2186 if (params.transparent) 2198 if (params.transparent)
2187 ex_style |= WS_EX_LAYERED; 2199 ex_style |= WS_EX_LAYERED;
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
2530 return (GetKeyState(VK_LBUTTON) & 0x80) || 2542 return (GetKeyState(VK_LBUTTON) & 0x80) ||
2531 (GetKeyState(VK_RBUTTON) & 0x80) || 2543 (GetKeyState(VK_RBUTTON) & 0x80) ||
2532 (GetKeyState(VK_MBUTTON) & 0x80) || 2544 (GetKeyState(VK_MBUTTON) & 0x80) ||
2533 (GetKeyState(VK_XBUTTON1) & 0x80) || 2545 (GetKeyState(VK_XBUTTON1) & 0x80) ||
2534 (GetKeyState(VK_XBUTTON2) & 0x80); 2546 (GetKeyState(VK_XBUTTON2) & 0x80);
2535 } 2547 }
2536 2548
2537 } // namespace internal 2549 } // namespace internal
2538 2550
2539 } // namespace views 2551 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698