| 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 <algorithm> | |
| 8 #include <vector> | |
| 9 | |
| 10 #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" |
| 9 #include "third_party/skia/include/core/SkBitmap.h" |
| 11 #include "ui/base/hit_test.h" | 10 #include "ui/base/hit_test.h" |
| 11 #include "ui/gfx/canvas.h" |
| 12 #include "ui/gfx/image/image_skia.h" |
| 12 #include "ui/views/background.h" | 13 #include "ui/views/background.h" |
| 13 #include "ui/views/border.h" | 14 #include "ui/views/controls/image_view.h" |
| 14 #include "ui/views/controls/label.h" | 15 #include "ui/views/controls/label.h" |
| 15 #include "ui/views/view.h" | 16 #include "ui/views/view.h" |
| 16 #include "ui/views/widget/widget.h" | 17 #include "ui/views/widget/widget.h" |
| 17 #include "ui/views/widget/widget_delegate.h" | 18 #include "ui/views/widget/widget_delegate.h" |
| 19 #include "ui/views/window/client_view.h" |
| 18 | 20 |
| 19 namespace athena { | 21 namespace athena { |
| 22 namespace { |
| 20 | 23 |
| 21 //////////////////////////////////////////////////////////////////////////////// | 24 // The icon size. |
| 22 // FrameViewAthena, public: | 25 const int kIconSize = 32; |
| 26 |
| 27 // The distance between the icon and the title when the icon is visible. |
| 28 const int kIconTitleSpacing = 5; |
| 29 |
| 30 // The height of the top border necessary to display the title without the icon. |
| 31 const int kDefaultTitleHeight = 25; |
| 32 |
| 33 // The height of the top border in overview mode. |
| 34 const int kOverviewTitleHeight = 55; |
| 35 |
| 36 // The height of the top border for fullscreen and frameless activities in |
| 37 // overview mode. |
| 38 const int kOverviewShortTitleHeight = 30; |
| 39 |
| 40 // The thickness of the left, right and bottom borders in overview mode. |
| 41 const int kOverviewBorderThickness = 5; |
| 42 |
| 43 } // namespace |
| 23 | 44 |
| 24 // static | 45 // static |
| 25 const char ActivityFrameView::kViewClassName[] = "ActivityFrameView"; | 46 const char ActivityFrameView::kViewClassName[] = "ActivityFrameView"; |
| 26 | 47 |
| 27 ActivityFrameView::ActivityFrameView(views::Widget* frame, | 48 ActivityFrameView::ActivityFrameView(views::Widget* frame, |
| 28 ActivityViewModel* view_model) | 49 ActivityViewModel* view_model) |
| 29 : frame_(frame), view_model_(view_model), title_(new views::Label) { | 50 : frame_(frame), |
| 30 title_->SetHorizontalAlignment(gfx::ALIGN_CENTER); | 51 view_model_(view_model), |
| 52 title_(new views::Label), |
| 53 icon_(new views::ImageView), |
| 54 in_overview_(false) { |
| 31 title_->SetEnabledColor(SkColorSetA(SK_ColorBLACK, 0xe5)); | 55 title_->SetEnabledColor(SkColorSetA(SK_ColorBLACK, 0xe5)); |
| 32 title_->SetBorder(views::Border::CreateSolidSidedBorder(0, 0, 1, 0, | 56 |
| 33 SkColorSetA(SK_ColorGRAY, 0x7f))); | 57 SkBitmap bitmap; |
| 58 bitmap.allocN32Pixels(kIconSize, kIconSize); |
| 59 bitmap.eraseARGB(255, 0, 255, 0); |
| 60 icon_->SetImage(gfx::ImageSkia::CreateFrom1xBitmap(bitmap)); |
| 61 |
| 34 AddChildView(title_); | 62 AddChildView(title_); |
| 63 AddChildView(icon_); |
| 64 |
| 65 SkColor bgcolor = view_model_->GetRepresentativeColor(); |
| 66 set_background(views::Background::CreateSolidBackground(bgcolor)); |
| 35 UpdateWindowTitle(); | 67 UpdateWindowTitle(); |
| 68 |
| 69 WindowManager::GetInstance()->AddObserver(this); |
| 36 } | 70 } |
| 37 | 71 |
| 38 ActivityFrameView::~ActivityFrameView() { | 72 ActivityFrameView::~ActivityFrameView() { |
| 73 WindowManager::GetInstance()->RemoveObserver(this); |
| 39 } | 74 } |
| 40 | 75 |
| 41 //////////////////////////////////////////////////////////////////////////////// | |
| 42 // ActivityFrameView, views::NonClientFrameView overrides: | |
| 43 | |
| 44 gfx::Rect ActivityFrameView::GetBoundsForClientView() const { | 76 gfx::Rect ActivityFrameView::GetBoundsForClientView() const { |
| 45 gfx::Rect client_bounds = bounds(); | 77 gfx::Rect client_bounds = bounds(); |
| 46 if (view_model_->UsesFrame()) | 78 client_bounds.Inset(NonClientBorderInsets()); |
| 47 client_bounds.Inset(0, NonClientTopBorderHeight(), 0, 0); | |
| 48 return client_bounds; | 79 return client_bounds; |
| 49 } | 80 } |
| 50 | 81 |
| 51 gfx::Rect ActivityFrameView::GetWindowBoundsForClientBounds( | 82 gfx::Rect ActivityFrameView::GetWindowBoundsForClientBounds( |
| 52 const gfx::Rect& client_bounds) const { | 83 const gfx::Rect& client_bounds) const { |
| 53 gfx::Rect window_bounds = client_bounds; | 84 gfx::Rect window_bounds = client_bounds; |
| 54 if (view_model_->UsesFrame()) | 85 window_bounds.Inset(-NonClientBorderInsets()); |
| 55 window_bounds.Inset(0, -NonClientTopBorderHeight(), 0, 0); | |
| 56 return window_bounds; | 86 return window_bounds; |
| 57 } | 87 } |
| 58 | 88 |
| 59 int ActivityFrameView::NonClientHitTest(const gfx::Point& point) { | 89 int ActivityFrameView::NonClientHitTest(const gfx::Point& point) { |
| 60 if (frame_->IsFullscreen()) | 90 if (!bounds().Contains(point)) |
| 61 return 0; | 91 return HTNOWHERE; |
| 62 if (title_->bounds().Contains(point)) | 92 int client_hit_test = frame_->client_view()->NonClientHitTest(point); |
| 63 return HTCAPTION; | 93 if (client_hit_test != HTNOWHERE) |
| 64 return 0; | 94 return client_hit_test; |
| 95 int window_hit_test = |
| 96 GetHTComponentForFrame(point, 0, NonClientBorderThickness(), 0, 0, false); |
| 97 return (window_hit_test == HTNOWHERE) ? HTCAPTION : client_hit_test; |
| 65 } | 98 } |
| 66 | 99 |
| 67 void ActivityFrameView::GetWindowMask(const gfx::Size& size, | 100 void ActivityFrameView::GetWindowMask(const gfx::Size& size, |
| 68 gfx::Path* window_mask) { | 101 gfx::Path* window_mask) { |
| 69 } | 102 } |
| 70 | 103 |
| 71 void ActivityFrameView::ResetWindowControls() { | 104 void ActivityFrameView::ResetWindowControls() { |
| 72 } | 105 } |
| 73 | 106 |
| 74 void ActivityFrameView::UpdateWindowIcon() { | 107 void ActivityFrameView::UpdateWindowIcon() { |
| 75 if (!view_model_->UsesFrame()) | 108 if (!view_model_->UsesFrame()) |
| 76 return; | 109 return; |
| 77 | 110 |
| 78 SkColor bgcolor = view_model_->GetRepresentativeColor(); | 111 SkColor bgcolor = view_model_->GetRepresentativeColor(); |
| 79 set_background(views::Background::CreateSolidBackground(bgcolor)); | 112 set_background(views::Background::CreateSolidBackground(bgcolor)); |
| 80 title_->SetBackgroundColor(bgcolor); | 113 title_->SetBackgroundColor(bgcolor); |
| 81 SchedulePaint(); | 114 SchedulePaint(); |
| 82 } | 115 } |
| 83 | 116 |
| 84 void ActivityFrameView::UpdateWindowTitle() { | 117 void ActivityFrameView::UpdateWindowTitle() { |
| 85 if (!view_model_->UsesFrame()) | 118 if (!view_model_->UsesFrame()) |
| 86 return; | 119 return; |
| 87 title_->SetText(frame_->widget_delegate()->GetWindowTitle()); | 120 title_->SetText(frame_->widget_delegate()->GetWindowTitle()); |
| 121 Layout(); |
| 88 } | 122 } |
| 89 | 123 |
| 90 //////////////////////////////////////////////////////////////////////////////// | |
| 91 // ActivityFrameView, views::View overrides: | |
| 92 | |
| 93 gfx::Size ActivityFrameView::GetPreferredSize() const { | 124 gfx::Size ActivityFrameView::GetPreferredSize() const { |
| 94 gfx::Size pref = frame_->client_view()->GetPreferredSize(); | 125 gfx::Size pref = frame_->client_view()->GetPreferredSize(); |
| 95 gfx::Rect bounds(0, 0, pref.width(), pref.height()); | 126 gfx::Rect bounds(0, 0, pref.width(), pref.height()); |
| 96 return frame_->non_client_view() | 127 return frame_->non_client_view() |
| 97 ->GetWindowBoundsForClientBounds(bounds) | 128 ->GetWindowBoundsForClientBounds(bounds) |
| 98 .size(); | 129 .size(); |
| 99 } | 130 } |
| 100 | 131 |
| 101 const char* ActivityFrameView::GetClassName() const { | 132 const char* ActivityFrameView::GetClassName() const { |
| 102 return kViewClassName; | 133 return kViewClassName; |
| 103 } | 134 } |
| 104 | 135 |
| 105 void ActivityFrameView::Layout() { | 136 void ActivityFrameView::Layout() { |
| 106 title_->SetBounds(0, 0, width(), NonClientTopBorderHeight()); | 137 if (frame_->IsFullscreen() || !view_model_->UsesFrame()) { |
| 138 title_->SetVisible(false); |
| 139 icon_->SetVisible(false); |
| 140 return; |
| 141 } |
| 142 |
| 143 title_->SetVisible(true); |
| 144 icon_->SetVisible(in_overview_); |
| 145 |
| 146 gfx::Size preferred_title_size = title_->GetPreferredSize(); |
| 147 int top_height = NonClientTopBorderHeight(); |
| 148 int title_x = 0; |
| 149 if (in_overview_) { |
| 150 int edge = (top_height - kIconSize) / 2; |
| 151 icon_->SetBounds(edge, edge, kIconSize, kIconSize); |
| 152 |
| 153 title_x = icon_->bounds().right() + kIconTitleSpacing; |
| 154 } else { |
| 155 title_x = (width() - preferred_title_size.width()) / 2; |
| 156 } |
| 157 |
| 158 title_->SetBounds(title_x, |
| 159 (top_height - preferred_title_size.height()) / 2, |
| 160 preferred_title_size.width(), |
| 161 preferred_title_size.height()); |
| 107 } | 162 } |
| 108 | 163 |
| 109 //////////////////////////////////////////////////////////////////////////////// | 164 void ActivityFrameView::OnPaintBackground(gfx::Canvas* canvas) { |
| 110 // ActivityFrameView, private: | 165 View::OnPaintBackground(canvas); |
| 166 |
| 167 // Paint a border around the client view. |
| 168 gfx::Rect border_bounds = GetLocalBounds(); |
| 169 border_bounds.Inset(NonClientBorderInsets()); |
| 170 border_bounds.Inset(-1, -1, 0, 0); |
| 171 canvas->DrawRect(border_bounds, SkColorSetA(SK_ColorGRAY, 0x7f)); |
| 172 } |
| 173 |
| 174 void ActivityFrameView::OnOverviewModeEnter() { |
| 175 view_model_->PrepareContentsForOverview(); |
| 176 in_overview_ = true; |
| 177 InvalidateLayout(); |
| 178 frame_->client_view()->InvalidateLayout(); |
| 179 frame_->GetRootView()->Layout(); |
| 180 SchedulePaint(); |
| 181 } |
| 182 |
| 183 void ActivityFrameView::OnOverviewModeExit() { |
| 184 in_overview_ = false; |
| 185 InvalidateLayout(); |
| 186 frame_->client_view()->InvalidateLayout(); |
| 187 frame_->GetRootView()->Layout(); |
| 188 SchedulePaint(); |
| 189 view_model_->ResetContentsView(); |
| 190 } |
| 191 |
| 192 void ActivityFrameView::OnSplitViewModeEnter() { |
| 193 } |
| 194 |
| 195 void ActivityFrameView::OnSplitViewModeExit() { |
| 196 } |
| 197 |
| 198 gfx::Insets ActivityFrameView::NonClientBorderInsets() const { |
| 199 int border_thickness = NonClientBorderThickness(); |
| 200 return gfx::Insets(NonClientTopBorderHeight(), |
| 201 border_thickness, |
| 202 border_thickness, |
| 203 border_thickness); |
| 204 } |
| 205 |
| 206 int ActivityFrameView::NonClientBorderThickness() const { |
| 207 return in_overview_ ? kOverviewBorderThickness : 0; |
| 208 } |
| 111 | 209 |
| 112 int ActivityFrameView::NonClientTopBorderHeight() const { | 210 int ActivityFrameView::NonClientTopBorderHeight() const { |
| 113 const int kDefaultTitleHeight = 25; | 211 if (frame_->IsFullscreen() || !view_model_->UsesFrame()) |
| 114 return frame_->IsFullscreen() ? 0 : kDefaultTitleHeight; | 212 return in_overview_ ? kOverviewShortTitleHeight : 0; |
| 213 return in_overview_ ? kOverviewTitleHeight : kDefaultTitleHeight; |
| 115 } | 214 } |
| 116 | 215 |
| 117 } // namespace ash | 216 } // namespace athena |
| OLD | NEW |