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 "athena/activity/activity_frame_view.h"
10 #include "athena/activity/public/activity_view_model.h"
11 #include "ui/base/hit_test.h"
12 #include "ui/views/background.h"
13 #include "ui/views/border.h"
14 #include "ui/views/controls/label.h"
15 #include "ui/views/view.h"
16 #include "ui/views/widget/widget.h"
17 #include "ui/views/widget/widget_delegate.h"
21 ////////////////////////////////////////////////////////////////////////////////
22 // FrameViewAthena, public:
25 const char ActivityFrameView::kViewClassName
[] = "ActivityFrameView";
27 ActivityFrameView::ActivityFrameView(views::Widget
* frame
,
28 ActivityViewModel
* view_model
)
29 : frame_(frame
), view_model_(view_model
), title_(new views::Label
) {
30 title_
->SetHorizontalAlignment(gfx::ALIGN_CENTER
);
31 title_
->SetEnabledColor(SkColorSetA(SK_ColorBLACK
, 0xe5));
32 title_
->SetBorder(views::Border::CreateSolidSidedBorder(0, 0, 1, 0,
33 SkColorSetA(SK_ColorGRAY
, 0x7f)));
38 ActivityFrameView::~ActivityFrameView() {
41 ////////////////////////////////////////////////////////////////////////////////
42 // ActivityFrameView, views::NonClientFrameView overrides:
44 gfx::Rect
ActivityFrameView::GetBoundsForClientView() const {
45 gfx::Rect client_bounds
= bounds();
46 if (view_model_
->UsesFrame())
47 client_bounds
.Inset(0, NonClientTopBorderHeight(), 0, 0);
51 gfx::Rect
ActivityFrameView::GetWindowBoundsForClientBounds(
52 const gfx::Rect
& client_bounds
) const {
53 gfx::Rect window_bounds
= client_bounds
;
54 if (view_model_
->UsesFrame())
55 window_bounds
.Inset(0, -NonClientTopBorderHeight(), 0, 0);
59 int ActivityFrameView::NonClientHitTest(const gfx::Point
& point
) {
60 if (frame_
->IsFullscreen())
62 if (title_
->bounds().Contains(point
))
67 void ActivityFrameView::GetWindowMask(const gfx::Size
& size
,
68 gfx::Path
* window_mask
) {
71 void ActivityFrameView::ResetWindowControls() {
74 void ActivityFrameView::UpdateWindowIcon() {
77 void ActivityFrameView::UpdateWindowTitle() {
78 if (!view_model_
->UsesFrame())
81 SkColor bgcolor
= view_model_
->GetRepresentativeColor();
82 title_
->set_background(views::Background::CreateSolidBackground(bgcolor
));
83 title_
->SetBackgroundColor(bgcolor
);
84 title_
->SetText(frame_
->widget_delegate()->GetWindowTitle());
87 ////////////////////////////////////////////////////////////////////////////////
88 // ActivityFrameView, views::View overrides:
90 gfx::Size
ActivityFrameView::GetPreferredSize() const {
91 gfx::Size pref
= frame_
->client_view()->GetPreferredSize();
92 gfx::Rect
bounds(0, 0, pref
.width(), pref
.height());
93 return frame_
->non_client_view()
94 ->GetWindowBoundsForClientBounds(bounds
)
98 const char* ActivityFrameView::GetClassName() const {
99 return kViewClassName
;
102 void ActivityFrameView::Layout() {
103 title_
->SetBounds(0, 0, width(), NonClientTopBorderHeight());
106 ////////////////////////////////////////////////////////////////////////////////
107 // ActivityFrameView, private:
109 int ActivityFrameView::NonClientTopBorderHeight() const {
110 const int kDefaultTitleHeight
= 25;
111 return frame_
->IsFullscreen() ? 0 : kDefaultTitleHeight
;