1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/views/apps/glass_app_window_frame_view_win.h"
7 #include "apps/ui/native_app_window.h"
8 #include "ui/base/hit_test.h"
9 #include "ui/views/widget/widget.h"
10 #include "ui/views/widget/widget_delegate.h"
14 const int kResizeAreaCornerSize
= 16;
18 const char GlassAppWindowFrameViewWin::kViewClassName
[] =
19 "ui/views/apps/GlassAppWindowFrameViewWin";
21 GlassAppWindowFrameViewWin::GlassAppWindowFrameViewWin(
22 apps::NativeAppWindow
* window
,
23 views::Widget
* widget
)
24 : window_(window
), widget_(widget
) {
27 GlassAppWindowFrameViewWin::~GlassAppWindowFrameViewWin() {
30 gfx::Insets
GlassAppWindowFrameViewWin::GetGlassInsets() const {
31 // If 1 is not subtracted, they are too big. There is possibly some reason
33 // Also make sure the insets don't go below 1, as bad things happen when they
35 int caption_height
= std::max(
36 0, GetSystemMetrics(SM_CYSMICON
) + GetSystemMetrics(SM_CYSIZEFRAME
) - 1);
37 int frame_size
= std::max(1, GetSystemMetrics(SM_CXSIZEFRAME
) - 1);
39 frame_size
+ caption_height
, frame_size
, frame_size
, frame_size
);
42 gfx::Rect
GlassAppWindowFrameViewWin::GetBoundsForClientView() const {
43 if (widget_
->IsFullscreen())
46 gfx::Insets insets
= GetGlassInsets();
47 return gfx::Rect(insets
.left(),
49 std::max(0, width() - insets
.left() - insets
.right()),
50 std::max(0, height() - insets
.top() - insets
.bottom()));
53 gfx::Rect
GlassAppWindowFrameViewWin::GetWindowBoundsForClientBounds(
54 const gfx::Rect
& client_bounds
) const {
55 gfx::Insets insets
= GetGlassInsets();
56 return gfx::Rect(client_bounds
.x() - insets
.left(),
57 client_bounds
.y() - insets
.top(),
58 client_bounds
.width() + insets
.left() + insets
.right(),
59 client_bounds
.height() + insets
.top() + insets
.bottom());
62 int GlassAppWindowFrameViewWin::NonClientHitTest(const gfx::Point
& point
) {
63 if (widget_
->IsFullscreen())
66 if (!bounds().Contains(point
))
69 // Check the frame first, as we allow a small area overlapping the contents
70 // to be used for resize handles.
71 bool can_ever_resize
= widget_
->widget_delegate()
72 ? widget_
->widget_delegate()->CanResize()
74 // Don't allow overlapping resize handles when the window is maximized or
75 // fullscreen, as it can't be resized in those states.
76 int resize_border
= GetSystemMetrics(SM_CXSIZEFRAME
);
78 GetHTComponentForFrame(point
,
81 kResizeAreaCornerSize
- resize_border
,
82 kResizeAreaCornerSize
- resize_border
,
84 if (frame_component
!= HTNOWHERE
)
85 return frame_component
;
87 int client_component
= widget_
->client_view()->NonClientHitTest(point
);
88 if (client_component
!= HTNOWHERE
)
89 return client_component
;
91 // Caption is a safe default.
95 void GlassAppWindowFrameViewWin::GetWindowMask(const gfx::Size
& size
,
96 gfx::Path
* window_mask
) {
97 // We got nothing to say about no window mask.
100 gfx::Size
GlassAppWindowFrameViewWin::GetPreferredSize() const {
101 gfx::Size pref
= widget_
->client_view()->GetPreferredSize();
102 gfx::Rect
bounds(0, 0, pref
.width(), pref
.height());
103 return widget_
->non_client_view()
104 ->GetWindowBoundsForClientBounds(bounds
)
108 const char* GlassAppWindowFrameViewWin::GetClassName() const {
109 return kViewClassName
;
112 gfx::Size
GlassAppWindowFrameViewWin::GetMinimumSize() const {
113 gfx::Size min_size
= widget_
->client_view()->GetMinimumSize();
114 gfx::Rect client_bounds
= GetBoundsForClientView();
115 min_size
.Enlarge(0, client_bounds
.y());
119 gfx::Size
GlassAppWindowFrameViewWin::GetMaximumSize() {
120 gfx::Size max_size
= widget_
->client_view()->GetMaximumSize();
122 // Add to the client maximum size the height of any title bar and borders.
123 gfx::Size client_size
= GetBoundsForClientView().size();
124 if (max_size
.width())
125 max_size
.Enlarge(width() - client_size
.width(), 0);
126 if (max_size
.height())
127 max_size
.Enlarge(0, height() - client_size
.height());