| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "chrome/browser/ui/views/apps/glass_app_window_frame_view_win.h" | |
| 6 | |
| 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" | |
| 11 | |
| 12 namespace { | |
| 13 | |
| 14 const int kResizeAreaCornerSize = 16; | |
| 15 | |
| 16 } // namespace | |
| 17 | |
| 18 const char GlassAppWindowFrameViewWin::kViewClassName[] = | |
| 19 "ui/views/apps/GlassAppWindowFrameViewWin"; | |
| 20 | |
| 21 GlassAppWindowFrameViewWin::GlassAppWindowFrameViewWin( | |
| 22 apps::NativeAppWindow* window, | |
| 23 views::Widget* widget) | |
| 24 : window_(window), widget_(widget) {} | |
| 25 | |
| 26 GlassAppWindowFrameViewWin::~GlassAppWindowFrameViewWin() {} | |
| 27 | |
| 28 gfx::Insets GlassAppWindowFrameViewWin::GetGlassInsets() const { | |
| 29 // If 1 is not subtracted, they are too big. There is possibly some reason | |
| 30 // for that. | |
| 31 // Also make sure the insets don't go below 1, as bad things happen when they | |
| 32 // do. | |
| 33 int caption_height = std::max( | |
| 34 0, GetSystemMetrics(SM_CYSMICON) + GetSystemMetrics(SM_CYSIZEFRAME) - 1); | |
| 35 int frame_size = std::max(1, GetSystemMetrics(SM_CXSIZEFRAME) - 1); | |
| 36 return gfx::Insets( | |
| 37 frame_size + caption_height, frame_size, frame_size, frame_size); | |
| 38 } | |
| 39 | |
| 40 gfx::Rect GlassAppWindowFrameViewWin::GetBoundsForClientView() const { | |
| 41 if (widget_->IsFullscreen()) | |
| 42 return bounds(); | |
| 43 | |
| 44 gfx::Insets insets = GetGlassInsets(); | |
| 45 return gfx::Rect(insets.left(), | |
| 46 insets.top(), | |
| 47 std::max(0, width() - insets.left() - insets.right()), | |
| 48 std::max(0, height() - insets.top() - insets.bottom())); | |
| 49 } | |
| 50 | |
| 51 gfx::Rect GlassAppWindowFrameViewWin::GetWindowBoundsForClientBounds( | |
| 52 const gfx::Rect& client_bounds) const { | |
| 53 gfx::Insets insets = GetGlassInsets(); | |
| 54 return gfx::Rect(client_bounds.x() - insets.left(), | |
| 55 client_bounds.y() - insets.top(), | |
| 56 client_bounds.width() + insets.left() + insets.right(), | |
| 57 client_bounds.height() + insets.top() + insets.bottom()); | |
| 58 } | |
| 59 | |
| 60 int GlassAppWindowFrameViewWin::NonClientHitTest(const gfx::Point& point) { | |
| 61 if (widget_->IsFullscreen()) | |
| 62 return HTCLIENT; | |
| 63 | |
| 64 if (!bounds().Contains(point)) | |
| 65 return HTNOWHERE; | |
| 66 | |
| 67 // Check the frame first, as we allow a small area overlapping the contents | |
| 68 // to be used for resize handles. | |
| 69 bool can_ever_resize = widget_->widget_delegate() | |
| 70 ? widget_->widget_delegate()->CanResize() | |
| 71 : false; | |
| 72 // Don't allow overlapping resize handles when the window is maximized or | |
| 73 // fullscreen, as it can't be resized in those states. | |
| 74 int resize_border = GetSystemMetrics(SM_CXSIZEFRAME); | |
| 75 int frame_component = | |
| 76 GetHTComponentForFrame(point, | |
| 77 resize_border, | |
| 78 resize_border, | |
| 79 kResizeAreaCornerSize - resize_border, | |
| 80 kResizeAreaCornerSize - resize_border, | |
| 81 can_ever_resize); | |
| 82 if (frame_component != HTNOWHERE) | |
| 83 return frame_component; | |
| 84 | |
| 85 int client_component = widget_->client_view()->NonClientHitTest(point); | |
| 86 if (client_component != HTNOWHERE) | |
| 87 return client_component; | |
| 88 | |
| 89 // Caption is a safe default. | |
| 90 return HTCAPTION; | |
| 91 } | |
| 92 | |
| 93 void GlassAppWindowFrameViewWin::GetWindowMask(const gfx::Size& size, | |
| 94 gfx::Path* window_mask) { | |
| 95 // We got nothing to say about no window mask. | |
| 96 } | |
| 97 | |
| 98 gfx::Size GlassAppWindowFrameViewWin::GetPreferredSize() { | |
| 99 gfx::Size pref = widget_->client_view()->GetPreferredSize(); | |
| 100 gfx::Rect bounds(0, 0, pref.width(), pref.height()); | |
| 101 return widget_->non_client_view() | |
| 102 ->GetWindowBoundsForClientBounds(bounds) | |
| 103 .size(); | |
| 104 } | |
| 105 | |
| 106 const char* GlassAppWindowFrameViewWin::GetClassName() const { | |
| 107 return kViewClassName; | |
| 108 } | |
| 109 | |
| 110 gfx::Size GlassAppWindowFrameViewWin::GetMinimumSize() { | |
| 111 gfx::Size min_size = widget_->client_view()->GetMinimumSize(); | |
| 112 gfx::Rect client_bounds = GetBoundsForClientView(); | |
| 113 min_size.Enlarge(0, client_bounds.y()); | |
| 114 return min_size; | |
| 115 } | |
| 116 | |
| 117 gfx::Size GlassAppWindowFrameViewWin::GetMaximumSize() { | |
| 118 gfx::Size max_size = widget_->client_view()->GetMaximumSize(); | |
| 119 | |
| 120 // Add to the client maximum size the height of any title bar and borders. | |
| 121 gfx::Size client_size = GetBoundsForClientView().size(); | |
| 122 if (max_size.width()) | |
| 123 max_size.Enlarge(width() - client_size.width(), 0); | |
| 124 if (max_size.height()) | |
| 125 max_size.Enlarge(0, height() - client_size.height()); | |
| 126 | |
| 127 return max_size; | |
| 128 } | |
| OLD | NEW |