OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "athena/activity/activity_frame_view.h" | 5 #include "athena/activity/activity_frame_view.h" |
6 | 6 |
7 #include "athena/activity/public/activity_view_model.h" | 7 #include "athena/activity/public/activity_view_model.h" |
8 #include "athena/wm/public/window_manager.h" | 8 #include "athena/wm/public/window_manager.h" |
9 #include "third_party/skia/include/core/SkBitmap.h" | |
10 #include "ui/base/hit_test.h" | 9 #include "ui/base/hit_test.h" |
11 #include "ui/gfx/canvas.h" | 10 #include "ui/gfx/canvas.h" |
12 #include "ui/gfx/image/image_skia.h" | 11 #include "ui/gfx/image/image_skia.h" |
13 #include "ui/views/background.h" | 12 #include "ui/views/background.h" |
14 #include "ui/views/controls/image_view.h" | 13 #include "ui/views/controls/image_view.h" |
15 #include "ui/views/controls/label.h" | 14 #include "ui/views/controls/label.h" |
16 #include "ui/views/view.h" | 15 #include "ui/views/view.h" |
17 #include "ui/views/widget/widget.h" | 16 #include "ui/views/widget/widget.h" |
18 #include "ui/views/widget/widget_delegate.h" | 17 #include "ui/views/widget/widget_delegate.h" |
19 #include "ui/views/window/client_view.h" | 18 #include "ui/views/window/client_view.h" |
20 | 19 |
21 namespace athena { | 20 namespace athena { |
22 namespace { | 21 namespace { |
23 | 22 |
24 // The icon size. | 23 // The icon size. |
25 const int kIconSize = 32; | 24 const int kIconSize = 32; |
26 | 25 |
27 // The distance between the icon and the title when the icon is visible. | 26 // The distance between the icon and the title when the icon is visible. |
28 const int kIconTitleSpacing = 5; | 27 const int kIconTitleSpacing = 10; |
29 | 28 |
30 // The height of the top border necessary to display the title without the icon. | 29 // The height of the top border necessary to display the title without the icon. |
31 const int kDefaultTitleHeight = 25; | 30 const int kDefaultTitleHeight = 25; |
32 | 31 |
33 // The height of the top border in overview mode. | 32 // The height of the top border in overview mode. |
34 const int kOverviewTitleHeight = 55; | 33 const int kOverviewTitleHeight = 55; |
35 | 34 |
36 // The height of the top border for fullscreen and frameless activities in | 35 // The height of the top border for fullscreen and frameless activities in |
37 // overview mode. | 36 // overview mode. |
38 const int kOverviewShortTitleHeight = 30; | 37 const int kOverviewShortTitleHeight = 30; |
39 | 38 |
40 // The thickness of the left, right and bottom borders in overview mode. | 39 // The thickness of the left, right and bottom borders in overview mode. |
41 const int kOverviewBorderThickness = 5; | 40 const int kOverviewBorderThickness = 5; |
42 | 41 |
43 } // namespace | 42 } // namespace |
44 | 43 |
45 // static | 44 // static |
46 const char ActivityFrameView::kViewClassName[] = "ActivityFrameView"; | 45 const char ActivityFrameView::kViewClassName[] = "ActivityFrameView"; |
47 | 46 |
48 ActivityFrameView::ActivityFrameView(views::Widget* frame, | 47 ActivityFrameView::ActivityFrameView(views::Widget* frame, |
49 ActivityViewModel* view_model) | 48 ActivityViewModel* view_model) |
50 : frame_(frame), | 49 : frame_(frame), |
51 view_model_(view_model), | 50 view_model_(view_model), |
52 title_(new views::Label), | 51 title_(new views::Label), |
53 icon_(new views::ImageView), | 52 icon_(new views::ImageView), |
54 in_overview_(false) { | 53 in_overview_(false) { |
55 title_->SetEnabledColor(SkColorSetA(SK_ColorBLACK, 0xe5)); | 54 title_->SetEnabledColor(SkColorSetA(SK_ColorBLACK, 0xe5)); |
56 | 55 |
57 SkBitmap bitmap; | |
58 bitmap.allocN32Pixels(kIconSize, kIconSize); | |
59 bitmap.eraseARGB(255, 0, 255, 0); | |
60 icon_->SetImage(gfx::ImageSkia::CreateFrom1xBitmap(bitmap)); | |
61 | |
62 AddChildView(title_); | 56 AddChildView(title_); |
63 AddChildView(icon_); | 57 AddChildView(icon_); |
64 | 58 |
65 SkColor bgcolor = view_model_->GetRepresentativeColor(); | |
66 set_background(views::Background::CreateSolidBackground(bgcolor)); | |
67 UpdateWindowTitle(); | 59 UpdateWindowTitle(); |
| 60 UpdateWindowIcon(); |
68 | 61 |
69 WindowManager::GetInstance()->AddObserver(this); | 62 WindowManager::GetInstance()->AddObserver(this); |
70 } | 63 } |
71 | 64 |
72 ActivityFrameView::~ActivityFrameView() { | 65 ActivityFrameView::~ActivityFrameView() { |
73 WindowManager::GetInstance()->RemoveObserver(this); | 66 WindowManager::GetInstance()->RemoveObserver(this); |
74 } | 67 } |
75 | 68 |
76 gfx::Rect ActivityFrameView::GetBoundsForClientView() const { | 69 gfx::Rect ActivityFrameView::GetBoundsForClientView() const { |
77 gfx::Rect client_bounds = bounds(); | 70 gfx::Rect client_bounds = bounds(); |
(...skipping 20 matching lines...) Expand all Loading... |
98 } | 91 } |
99 | 92 |
100 void ActivityFrameView::GetWindowMask(const gfx::Size& size, | 93 void ActivityFrameView::GetWindowMask(const gfx::Size& size, |
101 gfx::Path* window_mask) { | 94 gfx::Path* window_mask) { |
102 } | 95 } |
103 | 96 |
104 void ActivityFrameView::ResetWindowControls() { | 97 void ActivityFrameView::ResetWindowControls() { |
105 } | 98 } |
106 | 99 |
107 void ActivityFrameView::UpdateWindowIcon() { | 100 void ActivityFrameView::UpdateWindowIcon() { |
108 if (!view_model_->UsesFrame()) | 101 // The activity has a frame in overview mode regardless of the value of |
109 return; | 102 // ActivityViewModel::UsesFrame(). |
110 | |
111 SkColor bgcolor = view_model_->GetRepresentativeColor(); | 103 SkColor bgcolor = view_model_->GetRepresentativeColor(); |
112 set_background(views::Background::CreateSolidBackground(bgcolor)); | 104 set_background(views::Background::CreateSolidBackground(bgcolor)); |
113 title_->SetBackgroundColor(bgcolor); | 105 |
| 106 if (view_model_->UsesFrame()) |
| 107 icon_->SetImage(view_model_->GetIcon()); |
114 SchedulePaint(); | 108 SchedulePaint(); |
115 } | 109 } |
116 | 110 |
117 void ActivityFrameView::UpdateWindowTitle() { | 111 void ActivityFrameView::UpdateWindowTitle() { |
118 if (!view_model_->UsesFrame()) | 112 if (!view_model_->UsesFrame()) |
119 return; | 113 return; |
120 title_->SetText(frame_->widget_delegate()->GetWindowTitle()); | 114 title_->SetText(frame_->widget_delegate()->GetWindowTitle()); |
121 Layout(); | 115 Layout(); |
122 } | 116 } |
123 | 117 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 return in_overview_ ? kOverviewBorderThickness : 0; | 201 return in_overview_ ? kOverviewBorderThickness : 0; |
208 } | 202 } |
209 | 203 |
210 int ActivityFrameView::NonClientTopBorderHeight() const { | 204 int ActivityFrameView::NonClientTopBorderHeight() const { |
211 if (frame_->IsFullscreen() || !view_model_->UsesFrame()) | 205 if (frame_->IsFullscreen() || !view_model_->UsesFrame()) |
212 return in_overview_ ? kOverviewShortTitleHeight : 0; | 206 return in_overview_ ? kOverviewShortTitleHeight : 0; |
213 return in_overview_ ? kOverviewTitleHeight : kDefaultTitleHeight; | 207 return in_overview_ ? kOverviewTitleHeight : kDefaultTitleHeight; |
214 } | 208 } |
215 | 209 |
216 } // namespace athena | 210 } // namespace athena |
OLD | NEW |