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 "extensions/browser/app_window/native_app_window.h"
8 #include "ui/base/hit_test.h"
9 #include "ui/gfx/win/dpi.h"
10 #include "ui/views/widget/widget.h"
11 #include "ui/views/widget/widget_delegate.h"
15 const int kResizeAreaCornerSize
= 16;
19 const char GlassAppWindowFrameViewWin::kViewClassName
[] =
20 "ui/views/apps/GlassAppWindowFrameViewWin";
22 GlassAppWindowFrameViewWin::GlassAppWindowFrameViewWin(
23 extensions::NativeAppWindow
* window
,
24 views::Widget
* widget
)
25 : window_(window
), widget_(widget
) {
28 GlassAppWindowFrameViewWin::~GlassAppWindowFrameViewWin() {
31 gfx::Insets
GlassAppWindowFrameViewWin::GetGlassInsets() const {
32 // If 1 is not subtracted, they are too big. There is possibly some reason
34 // Also make sure the insets don't go below 1, as bad things happen when they
36 int caption_height
= std::max(0,
37 gfx::win::GetSystemMetricsInDIP(SM_CYSMICON
) +
38 gfx::win::GetSystemMetricsInDIP(SM_CYSIZEFRAME
) - 1);
40 std::max(1, gfx::win::GetSystemMetricsInDIP(SM_CXSIZEFRAME
) - 1);
42 frame_size
+ caption_height
, frame_size
, frame_size
, frame_size
);
45 gfx::Rect
GlassAppWindowFrameViewWin::GetBoundsForClientView() const {
46 if (widget_
->IsFullscreen())
49 gfx::Insets insets
= GetGlassInsets();
50 return gfx::Rect(insets
.left(),
52 std::max(0, width() - insets
.left() - insets
.right()),
53 std::max(0, height() - insets
.top() - insets
.bottom()));
56 gfx::Rect
GlassAppWindowFrameViewWin::GetWindowBoundsForClientBounds(
57 const gfx::Rect
& client_bounds
) const {
58 if (widget_
->IsFullscreen())
61 gfx::Insets insets
= GetGlassInsets();
62 // Our bounds are not the same as the window's due to the offset added by
63 // AppWindowDesktopWindowTreeHostWin::GetClientAreaInsets. So account for it
65 insets
+= gfx::Insets(0, 0, 1, 1);
66 return gfx::Rect(client_bounds
.x() - insets
.left(),
67 client_bounds
.y() - insets
.top(),
68 client_bounds
.width() + insets
.left() + insets
.right(),
69 client_bounds
.height() + insets
.top() + insets
.bottom());
72 int GlassAppWindowFrameViewWin::NonClientHitTest(const gfx::Point
& point
) {
73 if (widget_
->IsFullscreen())
76 if (!bounds().Contains(point
))
79 // Check the frame first, as we allow a small area overlapping the contents
80 // to be used for resize handles.
81 bool can_ever_resize
= widget_
->widget_delegate()
82 ? widget_
->widget_delegate()->CanResize()
84 // Don't allow overlapping resize handles when the window is maximized or
85 // fullscreen, as it can't be resized in those states.
86 int resize_border
= gfx::win::GetSystemMetricsInDIP(SM_CXSIZEFRAME
);
88 GetHTComponentForFrame(point
,
91 kResizeAreaCornerSize
- resize_border
,
92 kResizeAreaCornerSize
- resize_border
,
94 if (frame_component
!= HTNOWHERE
)
95 return frame_component
;
97 int client_component
= widget_
->client_view()->NonClientHitTest(point
);
98 if (client_component
!= HTNOWHERE
)
99 return client_component
;
101 // Caption is a safe default.
105 void GlassAppWindowFrameViewWin::GetWindowMask(const gfx::Size
& size
,
106 gfx::Path
* window_mask
) {
107 // We got nothing to say about no window mask.
110 gfx::Size
GlassAppWindowFrameViewWin::GetPreferredSize() const {
111 gfx::Size pref
= widget_
->client_view()->GetPreferredSize();
112 gfx::Rect
bounds(0, 0, pref
.width(), pref
.height());
113 return widget_
->non_client_view()
114 ->GetWindowBoundsForClientBounds(bounds
)
118 const char* GlassAppWindowFrameViewWin::GetClassName() const {
119 return kViewClassName
;
122 gfx::Size
GlassAppWindowFrameViewWin::GetMinimumSize() const {
123 gfx::Size min_size
= widget_
->client_view()->GetMinimumSize();
125 gfx::Insets insets
= GetGlassInsets();
126 min_size
.Enlarge(insets
.left() + insets
.right(),
127 insets
.top() + insets
.bottom());
132 gfx::Size
GlassAppWindowFrameViewWin::GetMaximumSize() const {
133 gfx::Size max_size
= widget_
->client_view()->GetMaximumSize();
135 gfx::Insets insets
= GetGlassInsets();
136 if (max_size
.width())
137 max_size
.Enlarge(insets
.left() + insets
.right(), 0);
138 if (max_size
.height())
139 max_size
.Enlarge(0, insets
.top() + insets
.bottom());