Chromium Code Reviews| 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.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 namespace apps { | |
| 19 | |
| 20 const char GlassAppWindowFrameView::kViewClassName[] = | |
| 21 "browser/ui/views/extensions/GlassAppWindowFrameView"; | |
|
tapted
2014/04/03 19:40:24
should this be ui/views/apps/..?
benwells
2014/04/04 06:50:43
Done.
| |
| 22 | |
| 23 GlassAppWindowFrameView::GlassAppWindowFrameView(NativeAppWindow* window, | |
| 24 views::Widget* widget) | |
| 25 : window_(window), widget_(widget) {} | |
| 26 | |
| 27 GlassAppWindowFrameView::~GlassAppWindowFrameView() {} | |
| 28 | |
| 29 gfx::Insets GlassAppWindowFrameView::GetGlassInsets() const { | |
| 30 // If 1 is not subtraced, they are too big. There is possibly some reason | |
|
tapted
2014/04/03 19:40:24
nit: subtraced -> subtracted
benwells
2014/04/04 06:50:43
Done.
| |
| 31 // for that. | |
| 32 int caption_height = | |
| 33 GetSystemMetrics(SM_CYSMICON) + GetSystemMetrics(SM_CYSIZEFRAME) - 1; | |
| 34 int frame_size = GetSystemMetrics(SM_CXSIZEFRAME) - 1; | |
|
tapted
2014/04/03 19:40:24
Can GetSystemMetrics ever fail/ return 0?
benwells
2014/04/04 06:50:43
According to MSDN if it fails it will return 0. It
tapted
2014/04/04 16:15:19
cool - wild conjecture: maybe this is the explanat
| |
| 35 return gfx::Insets( | |
| 36 frame_size + caption_height, frame_size, frame_size, frame_size); | |
| 37 } | |
| 38 | |
| 39 gfx::Rect GlassAppWindowFrameView::GetBoundsForClientView() const { | |
| 40 if (widget_->IsFullscreen()) | |
| 41 return bounds(); | |
| 42 | |
| 43 gfx::Insets insets = GetGlassInsets(); | |
| 44 return gfx::Rect(insets.left(), | |
| 45 insets.top(), | |
| 46 std::max(0, width() - insets.left() - insets.right()), | |
| 47 std::max(0, height() - insets.top() - insets.bottom())); | |
| 48 } | |
| 49 | |
| 50 gfx::Rect GlassAppWindowFrameView::GetWindowBoundsForClientBounds( | |
| 51 const gfx::Rect& client_bounds) const { | |
| 52 gfx::Insets insets = GetGlassInsets(); | |
| 53 return gfx::Rect(client_bounds.x() - insets.left(), | |
| 54 client_bounds.y() - insets.top(), | |
| 55 client_bounds.width() + insets.left() + insets.right(), | |
| 56 client_bounds.height() + insets.top() + insets.bottom()); | |
| 57 } | |
| 58 | |
| 59 int GlassAppWindowFrameView::NonClientHitTest(const gfx::Point& point) { | |
| 60 if (widget_->IsFullscreen()) | |
| 61 return HTCLIENT; | |
|
tapted
2014/04/03 19:40:24
This API isn't too familiar to me, so this might b
benwells
2014/04/04 06:50:43
It should do. This function is only called if the
| |
| 62 | |
| 63 if (!bounds().Contains(point)) | |
| 64 return HTNOWHERE; | |
| 65 | |
| 66 // Check the frame first, as we allow a small area overlapping the contents | |
| 67 // to be used for resize handles. | |
| 68 bool can_ever_resize = widget_->widget_delegate() | |
| 69 ? widget_->widget_delegate()->CanResize() | |
| 70 : false; | |
| 71 // Don't allow overlapping resize handles when the window is maximized or | |
| 72 // fullscreen, as it can't be resized in those states. | |
| 73 int resize_border = GetSystemMetrics(SM_CXSIZEFRAME); | |
| 74 int frame_component = | |
| 75 GetHTComponentForFrame(point, | |
| 76 resize_border, | |
| 77 resize_border, | |
| 78 kResizeAreaCornerSize - resize_border, | |
| 79 kResizeAreaCornerSize - resize_border, | |
| 80 can_ever_resize); | |
| 81 if (frame_component != HTNOWHERE) | |
| 82 return frame_component; | |
| 83 | |
| 84 int client_component = widget_->client_view()->NonClientHitTest(point); | |
| 85 if (client_component != HTNOWHERE) | |
| 86 return client_component; | |
| 87 | |
| 88 // Caption is a safe default. | |
| 89 return HTCAPTION; | |
| 90 } | |
| 91 | |
| 92 void GlassAppWindowFrameView::GetWindowMask(const gfx::Size& size, | |
| 93 gfx::Path* window_mask) { | |
| 94 // We got nothing to say about no window mask. | |
| 95 } | |
| 96 | |
| 97 gfx::Size GlassAppWindowFrameView::GetPreferredSize() { | |
| 98 gfx::Size pref = widget_->client_view()->GetPreferredSize(); | |
| 99 gfx::Rect bounds(0, 0, pref.width(), pref.height()); | |
| 100 return widget_->non_client_view() | |
| 101 ->GetWindowBoundsForClientBounds(bounds) | |
| 102 .size(); | |
| 103 } | |
| 104 | |
| 105 const char* GlassAppWindowFrameView::GetClassName() const { | |
| 106 return kViewClassName; | |
| 107 } | |
| 108 | |
| 109 gfx::Size GlassAppWindowFrameView::GetMinimumSize() { | |
| 110 gfx::Size min_size = widget_->client_view()->GetMinimumSize(); | |
| 111 gfx::Rect client_bounds = GetBoundsForClientView(); | |
| 112 min_size.Enlarge(0, client_bounds.y()); | |
|
tapted
2014/04/03 19:40:24
why just the y? (should x always be 0?)
tapted
2014/04/04 16:15:19
there was one last question :). But I think I grok
| |
| 113 return min_size; | |
| 114 } | |
| 115 | |
| 116 gfx::Size GlassAppWindowFrameView::GetMaximumSize() { | |
| 117 gfx::Size max_size = widget_->client_view()->GetMaximumSize(); | |
| 118 | |
| 119 // Add to the client maximum size the height of any title bar and borders. | |
| 120 gfx::Size client_size = GetBoundsForClientView().size(); | |
| 121 if (max_size.width()) | |
| 122 max_size.Enlarge(width() - client_size.width(), 0); | |
| 123 if (max_size.height()) | |
| 124 max_size.Enlarge(0, height() - client_size.height()); | |
| 125 | |
| 126 return max_size; | |
| 127 } | |
| 128 | |
| 129 } // namespace apps | |
| OLD | NEW |