glass_app_window_frame_view_win.cc revision 116680a4aac90f2aa7413d9095a592090648e557
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/gfx/win/dpi.h" 10#include "ui/views/widget/widget.h" 11#include "ui/views/widget/widget_delegate.h" 12 13namespace { 14 15const int kResizeAreaCornerSize = 16; 16 17} // namespace 18 19const char GlassAppWindowFrameViewWin::kViewClassName[] = 20 "ui/views/apps/GlassAppWindowFrameViewWin"; 21 22GlassAppWindowFrameViewWin::GlassAppWindowFrameViewWin( 23 apps::NativeAppWindow* window, 24 views::Widget* widget) 25 : window_(window), widget_(widget) { 26} 27 28GlassAppWindowFrameViewWin::~GlassAppWindowFrameViewWin() { 29} 30 31gfx::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); 43} 44 45gfx::Rect GlassAppWindowFrameViewWin::GetBoundsForClientView() const { 46 if (widget_->IsFullscreen()) 47 return bounds(); 48 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())); 54} 55 56gfx::Rect GlassAppWindowFrameViewWin::GetWindowBoundsForClientBounds( 57 const gfx::Rect& client_bounds) const { 58 gfx::Insets insets = GetGlassInsets(); 59 return gfx::Rect(client_bounds.x() - insets.left(), 60 client_bounds.y() - insets.top(), 61 client_bounds.width() + insets.left() + insets.right(), 62 client_bounds.height() + insets.top() + insets.bottom()); 63} 64 65int GlassAppWindowFrameViewWin::NonClientHitTest(const gfx::Point& point) { 66 if (widget_->IsFullscreen()) 67 return HTCLIENT; 68 69 if (!bounds().Contains(point)) 70 return HTNOWHERE; 71 72 // Check the frame first, as we allow a small area overlapping the contents 73 // to be used for resize handles. 74 bool can_ever_resize = widget_->widget_delegate() 75 ? widget_->widget_delegate()->CanResize() 76 : false; 77 // Don't allow overlapping resize handles when the window is maximized or 78 // fullscreen, as it can't be resized in those states. 79 int resize_border = gfx::win::GetSystemMetricsInDIP(SM_CXSIZEFRAME); 80 int frame_component = 81 GetHTComponentForFrame(point, 82 resize_border, 83 resize_border, 84 kResizeAreaCornerSize - resize_border, 85 kResizeAreaCornerSize - resize_border, 86 can_ever_resize); 87 if (frame_component != HTNOWHERE) 88 return frame_component; 89 90 int client_component = widget_->client_view()->NonClientHitTest(point); 91 if (client_component != HTNOWHERE) 92 return client_component; 93 94 // Caption is a safe default. 95 return HTCAPTION; 96} 97 98void GlassAppWindowFrameViewWin::GetWindowMask(const gfx::Size& size, 99 gfx::Path* window_mask) { 100 // We got nothing to say about no window mask. 101} 102 103gfx::Size GlassAppWindowFrameViewWin::GetPreferredSize() const { 104 gfx::Size pref = widget_->client_view()->GetPreferredSize(); 105 gfx::Rect bounds(0, 0, pref.width(), pref.height()); 106 return widget_->non_client_view() 107 ->GetWindowBoundsForClientBounds(bounds) 108 .size(); 109} 110 111const char* GlassAppWindowFrameViewWin::GetClassName() const { 112 return kViewClassName; 113} 114 115gfx::Size GlassAppWindowFrameViewWin::GetMinimumSize() const { 116 gfx::Size min_size = widget_->client_view()->GetMinimumSize(); 117 gfx::Rect client_bounds = GetBoundsForClientView(); 118 min_size.Enlarge(0, client_bounds.y()); 119 return min_size; 120} 121 122gfx::Size GlassAppWindowFrameViewWin::GetMaximumSize() const { 123 gfx::Size max_size = widget_->client_view()->GetMaximumSize(); 124 125 // Add to the client maximum size the height of any title bar and borders. 126 gfx::Size client_size = GetBoundsForClientView().size(); 127 if (max_size.width()) 128 max_size.Enlarge(width() - client_size.width(), 0); 129 if (max_size.height()) 130 max_size.Enlarge(0, height() - client_size.height()); 131 132 return max_size; 133} 134