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