Infobar material design refresh: layout
[chromium-blink-merge.git] / chrome / browser / ui / views / apps / glass_app_window_frame_view_win.cc
blobb45d2881e28e1b581c8b1b80aec8a2108b9b5d5d
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"
13 namespace {
15 const int kResizeAreaCornerSize = 16;
17 } // namespace
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
33 // for that.
34 // Also make sure the insets don't go below 1, as bad things happen when they
35 // do.
36 int caption_height = std::max(0,
37 gfx::win::GetSystemMetricsInDIP(SM_CYSMICON) +
38 gfx::win::GetSystemMetricsInDIP(SM_CYSIZEFRAME) - 1);
39 int frame_size =
40 std::max(1, gfx::win::GetSystemMetricsInDIP(SM_CXSIZEFRAME) - 1);
41 return gfx::Insets(
42 frame_size + caption_height, frame_size, frame_size, frame_size);
45 gfx::Rect GlassAppWindowFrameViewWin::GetBoundsForClientView() const {
46 if (widget_->IsFullscreen())
47 return bounds();
49 gfx::Insets insets = GetGlassInsets();
50 return gfx::Rect(insets.left(),
51 insets.top(),
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())
59 return bounds();
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
64 // here.
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())
74 return HTCLIENT;
76 if (!bounds().Contains(point))
77 return HTNOWHERE;
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()
83 : false;
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);
87 int frame_component =
88 GetHTComponentForFrame(point,
89 resize_border,
90 resize_border,
91 kResizeAreaCornerSize - resize_border,
92 kResizeAreaCornerSize - resize_border,
93 can_ever_resize);
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.
102 return HTCAPTION;
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)
115 .size();
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());
129 return min_size;
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());
141 return max_size;