Index: athena/activity/activity_frame_view.cc |
diff --git a/athena/activity/activity_frame_view.cc b/athena/activity/activity_frame_view.cc |
index 08aeb3d12fa6d651143d9389015a22162ee6e550..e75827c39df1a5c93e5e2204d215cc21369e803c 100644 |
--- a/athena/activity/activity_frame_view.cc |
+++ b/athena/activity/activity_frame_view.cc |
@@ -4,64 +4,94 @@ |
#include "athena/activity/activity_frame_view.h" |
-#include <algorithm> |
-#include <vector> |
- |
#include "athena/activity/public/activity_view_model.h" |
+#include "athena/wm/public/window_manager.h" |
+#include "third_party/skia/include/core/SkBitmap.h" |
#include "ui/base/hit_test.h" |
+#include "ui/gfx/canvas.h" |
+#include "ui/gfx/image/image_skia.h" |
#include "ui/views/background.h" |
-#include "ui/views/border.h" |
+#include "ui/views/controls/image_view.h" |
#include "ui/views/controls/label.h" |
#include "ui/views/view.h" |
#include "ui/views/widget/widget.h" |
#include "ui/views/widget/widget_delegate.h" |
+#include "ui/views/window/client_view.h" |
namespace athena { |
+namespace { |
+ |
+// The icon size. |
+const int kIconSize = 32; |
+ |
+// The distance between the icon and the title when the icon is visible. |
+const int kIconTitleSpacing = 5; |
+ |
+// The height of the top border necessary to display the title without the icon. |
+const int kDefaultTitleHeight = 25; |
+ |
+// The height of the top border in overview mode. |
+const int kOverviewTitleHeight = 55; |
+ |
+// The height of the top border for fullscreen and frameless activities in |
+// overview mode. |
+const int kOverviewShortTitleHeight = 30; |
+ |
+// The thickness of the left, right and bottom borders in overview mode. |
+const int kOverviewBorderThickness = 5; |
-//////////////////////////////////////////////////////////////////////////////// |
-// FrameViewAthena, public: |
+} // namespace |
// static |
const char ActivityFrameView::kViewClassName[] = "ActivityFrameView"; |
ActivityFrameView::ActivityFrameView(views::Widget* frame, |
ActivityViewModel* view_model) |
- : frame_(frame), view_model_(view_model), title_(new views::Label) { |
- title_->SetHorizontalAlignment(gfx::ALIGN_CENTER); |
+ : frame_(frame), |
+ view_model_(view_model), |
+ title_(new views::Label), |
+ icon_(new views::ImageView), |
+ in_overview_(false) { |
title_->SetEnabledColor(SkColorSetA(SK_ColorBLACK, 0xe5)); |
- title_->SetBorder(views::Border::CreateSolidSidedBorder(0, 0, 1, 0, |
- SkColorSetA(SK_ColorGRAY, 0x7f))); |
+ |
+ SkBitmap bitmap; |
+ bitmap.allocN32Pixels(kIconSize, kIconSize); |
+ bitmap.eraseARGB(255, 0, 255, 0); |
+ icon_->SetImage(gfx::ImageSkia::CreateFrom1xBitmap(bitmap)); |
+ |
AddChildView(title_); |
+ AddChildView(icon_); |
pkotwicz
2014/08/30 00:56:38
I still add |icon_| as a child right away but only
|
+ |
+ SkColor bgcolor = view_model_->GetRepresentativeColor(); |
+ set_background(views::Background::CreateSolidBackground(bgcolor)); |
UpdateWindowTitle(); |
+ |
+ WindowManager::GetInstance()->AddObserver(this); |
} |
ActivityFrameView::~ActivityFrameView() { |
+ WindowManager::GetInstance()->RemoveObserver(this); |
} |
-//////////////////////////////////////////////////////////////////////////////// |
-// ActivityFrameView, views::NonClientFrameView overrides: |
- |
gfx::Rect ActivityFrameView::GetBoundsForClientView() const { |
gfx::Rect client_bounds = bounds(); |
- if (view_model_->UsesFrame()) |
- client_bounds.Inset(0, NonClientTopBorderHeight(), 0, 0); |
+ client_bounds.Inset(NonClientBorderInsets()); |
return client_bounds; |
} |
gfx::Rect ActivityFrameView::GetWindowBoundsForClientBounds( |
const gfx::Rect& client_bounds) const { |
gfx::Rect window_bounds = client_bounds; |
- if (view_model_->UsesFrame()) |
- window_bounds.Inset(0, -NonClientTopBorderHeight(), 0, 0); |
+ window_bounds.Inset(-NonClientBorderInsets()); |
return window_bounds; |
} |
int ActivityFrameView::NonClientHitTest(const gfx::Point& point) { |
- if (frame_->IsFullscreen()) |
- return 0; |
- if (title_->bounds().Contains(point)) |
- return HTCAPTION; |
- return 0; |
+ if (!bounds().Contains(point)) |
+ return HTNOWHERE; |
+ int client_hit_test = frame_->client_view()->NonClientHitTest(point); |
+ return (client_hit_test == HTNOWHERE) ? |
+ HTCAPTION : client_hit_test; |
} |
void ActivityFrameView::GetWindowMask(const gfx::Size& size, |
@@ -79,14 +109,13 @@ void ActivityFrameView::UpdateWindowTitle() { |
return; |
SkColor bgcolor = view_model_->GetRepresentativeColor(); |
+ set_background(views::Background::CreateSolidBackground(bgcolor)); |
title_->set_background(views::Background::CreateSolidBackground(bgcolor)); |
title_->SetBackgroundColor(bgcolor); |
title_->SetText(frame_->widget_delegate()->GetWindowTitle()); |
+ Layout(); |
pkotwicz
2014/08/30 00:56:38
Yes, this is necessary. |title_| no longer takes u
|
} |
-//////////////////////////////////////////////////////////////////////////////// |
-// ActivityFrameView, views::View overrides: |
- |
gfx::Size ActivityFrameView::GetPreferredSize() const { |
gfx::Size pref = frame_->client_view()->GetPreferredSize(); |
gfx::Rect bounds(0, 0, pref.width(), pref.height()); |
@@ -100,15 +129,71 @@ const char* ActivityFrameView::GetClassName() const { |
} |
void ActivityFrameView::Layout() { |
- title_->SetBounds(0, 0, width(), NonClientTopBorderHeight()); |
+ if (frame_->IsFullscreen() || !view_model_->UsesFrame()) { |
+ title_->SetVisible(false); |
+ icon_->SetVisible(false); |
+ return; |
+ } |
+ |
+ title_->SetVisible(true); |
+ icon_->SetVisible(in_overview_); |
+ |
+ gfx::Size preferred_title_size = title_->GetPreferredSize(); |
+ int top_height = NonClientTopBorderHeight(); |
+ int title_x = 0; |
+ if (in_overview_) { |
+ int edge = (top_height - kIconSize) / 2; |
+ icon_->SetBounds(edge, edge, kIconSize, kIconSize); |
+ |
+ title_x = icon_->bounds().right() + kIconTitleSpacing; |
+ } else { |
+ title_x = (width() - preferred_title_size.width()) / 2; |
+ } |
+ |
+ title_->SetBounds(title_x, |
+ (top_height - preferred_title_size.height()) / 2, |
+ preferred_title_size.width(), |
+ preferred_title_size.height()); |
+} |
+ |
+void ActivityFrameView::OnPaintBackground(gfx::Canvas* canvas) { |
+ View::OnPaintBackground(canvas); |
+ |
+ gfx::Rect border_bounds = GetLocalBounds(); |
pkotwicz
2014/08/30 00:56:38
In the old code |title_| had a bottom border. This
|
+ border_bounds.Inset(NonClientBorderInsets()); |
+ border_bounds.Inset(-1, -1, 0, 0); |
+ canvas->DrawRect(border_bounds, SkColorSetA(SK_ColorGRAY, 0x7f)); |
+} |
+ |
+void ActivityFrameView::OnOverviewModeEnter() { |
+ in_overview_ = true; |
+ InvalidateLayout(); |
+ frame_->client_view()->InvalidateLayout(); |
+ frame_->GetRootView()->Layout(); |
+} |
+ |
+void ActivityFrameView::OnOverviewModeExit() { |
+ in_overview_ = false; |
+ InvalidateLayout(); |
+ frame_->client_view()->InvalidateLayout(); |
+ frame_->GetRootView()->Layout(); |
} |
-//////////////////////////////////////////////////////////////////////////////// |
-// ActivityFrameView, private: |
+void ActivityFrameView::OnActivityOrderHasChanged() { |
+} |
+ |
+gfx::Insets ActivityFrameView::NonClientBorderInsets() const { |
+ int edge_width = in_overview_ ? kOverviewBorderThickness : 0; |
+ return gfx::Insets(NonClientTopBorderHeight(), |
+ edge_width, |
+ edge_width, |
+ edge_width); |
+} |
int ActivityFrameView::NonClientTopBorderHeight() const { |
- const int kDefaultTitleHeight = 25; |
- return frame_->IsFullscreen() ? 0 : kDefaultTitleHeight; |
+ if (frame_->IsFullscreen() || !view_model_->UsesFrame()) |
+ return in_overview_ ? kOverviewShortTitleHeight : 0; |
+ return in_overview_ ? kOverviewTitleHeight : kDefaultTitleHeight; |
} |
-} // namespace ash |
+} // namespace athena |