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 "athena/main/athena_frame_view.h" 6 7 #include "base/strings/utf_string_conversions.h" 8 #include "third_party/skia/include/core/SkColor.h" 9 #include "ui/base/hit_test.h" 10 #include "ui/views/background.h" 11 #include "ui/views/controls/label.h" 12 #include "ui/views/view.h" 13 #include "ui/views/widget/widget.h" 14 #include "ui/views/widget/widget_delegate.h" 15 #include "ui/views/window/client_view.h" 16 17 namespace athena { 18 namespace { 19 20 // The height of the top border necessary to display the title without the icon. 21 const int kDefaultTitleHeight = 13; 22 23 // The default background color for athena's frame. This is placeholder. 24 const SkColor kDefaultTitleBackground = 0xFFcccccc; 25 26 } // namespace 27 28 // static 29 const char AthenaFrameView::kViewClassName[] = "AthenaFrameView"; 30 31 AthenaFrameView::AthenaFrameView(views::Widget* frame) : frame_(frame) { 32 set_background( 33 views::Background::CreateSolidBackground(kDefaultTitleBackground)); 34 UpdateWindowTitle(); 35 } 36 37 AthenaFrameView::~AthenaFrameView() { 38 } 39 40 gfx::Rect AthenaFrameView::GetBoundsForClientView() const { 41 gfx::Rect client_bounds = bounds(); 42 client_bounds.Inset(NonClientBorderInsets()); 43 return client_bounds; 44 } 45 46 gfx::Rect AthenaFrameView::GetWindowBoundsForClientBounds( 47 const gfx::Rect& client_bounds) const { 48 gfx::Rect window_bounds = client_bounds; 49 window_bounds.Inset(-NonClientBorderInsets()); 50 return window_bounds; 51 } 52 53 int AthenaFrameView::NonClientHitTest(const gfx::Point& point) { 54 if (!bounds().Contains(point)) 55 return HTNOWHERE; 56 int client_hit_test = frame_->client_view()->NonClientHitTest(point); 57 if (client_hit_test != HTNOWHERE) 58 return client_hit_test; 59 int window_hit_test = 60 GetHTComponentForFrame(point, 0, NonClientBorderThickness(), 0, 0, false); 61 return (window_hit_test == HTNOWHERE) ? HTCAPTION : client_hit_test; 62 } 63 64 gfx::Size AthenaFrameView::GetPreferredSize() const { 65 gfx::Size pref = frame_->client_view()->GetPreferredSize(); 66 gfx::Rect bounds(0, 0, pref.width(), pref.height()); 67 return frame_->non_client_view() 68 ->GetWindowBoundsForClientBounds(bounds) 69 .size(); 70 } 71 72 const char* AthenaFrameView::GetClassName() const { 73 return kViewClassName; 74 } 75 76 gfx::Insets AthenaFrameView::NonClientBorderInsets() const { 77 int border_thickness = NonClientBorderThickness(); 78 return gfx::Insets(NonClientTopBorderHeight(), 79 border_thickness, 80 border_thickness, 81 border_thickness); 82 } 83 84 int AthenaFrameView::NonClientBorderThickness() const { 85 return 0; 86 } 87 88 int AthenaFrameView::NonClientTopBorderHeight() const { 89 return kDefaultTitleHeight; 90 } 91 92 } // namespace athena 93