Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1010)

Unified Diff: athena/home/athena_start_page_view.cc

Issue 473623002: Redesign the home card bottom state. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: athena/home/athena_start_page_view.cc
diff --git a/athena/home/athena_start_page_view.cc b/athena/home/athena_start_page_view.cc
new file mode 100644
index 0000000000000000000000000000000000000000..14bab7d77e47c09db75301e447c3d6a73ecb17ee
--- /dev/null
+++ b/athena/home/athena_start_page_view.cc
@@ -0,0 +1,164 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "athena/home/athena_start_page_view.h"
+
+#include "third_party/skia/include/core/SkPaint.h"
+#include "third_party/skia/include/core/SkPath.h"
+#include "ui/app_list/app_list_item.h"
+#include "ui/app_list/app_list_item_list.h"
+#include "ui/app_list/app_list_model.h"
+#include "ui/app_list/app_list_view_delegate.h"
+#include "ui/app_list/views/search_box_view.h"
+#include "ui/gfx/canvas.h"
+#include "ui/views/background.h"
+#include "ui/views/border.h"
+#include "ui/views/layout/box_layout.h"
+#include "ui/views/layout/fill_layout.h"
+#include "ui/views/painter.h"
+#include "ui/views/shadow_border.h"
+
+namespace {
+
+const size_t kMaxIconNum = 3;
+const int kIconSize = 50;
+const int kIconMargin = 25;
+
+// The preferred height for VISIBLE_BOTTOM state.
+const int kPreferredHeightBottom = 100;
+
+class PlaceHolderButton : public views::ImageButton,
+ public views::ButtonListener {
+ public:
+ PlaceHolderButton()
+ : ImageButton(this) {
+ gfx::Canvas canvas(gfx::Size(kIconSize, kIconSize), 1.0f, true);
+ SkPaint paint;
+ paint.setStyle(SkPaint::kFill_Style);
+ paint.setColor(SkColorSetRGB(86, 119, 252));
+ paint.setFlags(SkPaint::kAntiAlias_Flag);
+ canvas.DrawCircle(
+ gfx::Point(kIconSize / 2, kIconSize / 2), kIconSize / 2, paint);
+
+ scoped_ptr<gfx::ImageSkia> image(
+ new gfx::ImageSkia(canvas.ExtractImageRep()));
+ SetImage(STATE_NORMAL, image.get());
+ }
+
+ private:
+ // views::ButtonListener:
+ virtual void ButtonPressed(views::Button* sender,
+ const ui::Event& event) OVERRIDE {
+ // Do nothing: remove these place holders.
+ }
+
+ DISALLOW_COPY_AND_ASSIGN(PlaceHolderButton);
+};
+
+class AppIconButton : public views::ImageButton,
+ public views::ButtonListener {
+ public:
+ explicit AppIconButton(app_list::AppListItem* item)
+ : ImageButton(this),
+ item_(item) {
+ // TODO(mukai): icon should be resized.
+ SetImage(STATE_NORMAL, &item->icon());
+ }
+
+ private:
+ // views::ButtonListener:
+ virtual void ButtonPressed(views::Button* sender,
+ const ui::Event& event) OVERRIDE {
+ DCHECK_EQ(sender, this);
+ item_->Activate(event.flags());
+ }
+
+ app_list::AppListItem* item_;
+
+ DISALLOW_COPY_AND_ASSIGN(AppIconButton);
+};
+
+// This class draws the background and border of the search box.
+class BorderedSearchBoxBackground : public views::Background {
+ public:
+ BorderedSearchBoxBackground() {}
+ virtual ~BorderedSearchBoxBackground() {}
+
+ private:
+ static const int kBorderWidth = 1;
+ static const int kCornerRadius = 1;
+
+ // views::Background:
+ virtual void Paint(gfx::Canvas* canvas, views::View* view) const OVERRIDE {
+ SkPath path;
+ gfx::Rect bounds = view->GetContentsBounds();
+ bounds.Inset(1, 1);
+ path.addRoundRect(SkRect::MakeXYWH(bounds.x(), bounds.y(),
+ bounds.width(), bounds.height()),
+ kCornerRadius, kCornerRadius, SkPath::kCW_Direction);
+ SkPaint background_paint;
+ background_paint.setStyle(SkPaint::kFill_Style);
+ background_paint.setColor(SK_ColorWHITE);
+ canvas->DrawPath(path, background_paint);
+
+ SkPaint border_paint;
+ border_paint.setStyle(SkPaint::kStroke_Style);
+ border_paint.setColor(SK_ColorGRAY);
+ border_paint.setStrokeWidth(SkIntToScalar(kBorderWidth));
+ canvas->DrawPath(path, border_paint);
sadrul 2014/08/13 22:01:13 This is a tiny bit unfortunate: because we have vi
Jun Mukai 2014/08/13 23:18:23 split this into two classes, renamed to be more ge
+ }
+
+ DISALLOW_COPY_AND_ASSIGN(BorderedSearchBoxBackground);
+};
+
+} // namespace
+
+namespace athena {
+
+AthenaStartPageView::AthenaStartPageView(
+ app_list::AppListViewDelegate* view_delegate) {
+ app_list::AppListItemList* top_level =
+ view_delegate->GetModel()->top_level_item_list();
+
+ views::View* container = new views::View();
+ AddChildView(container);
+
+ views::BoxLayout* box_layout = new views::BoxLayout(
+ views::BoxLayout::kHorizontal, kIconMargin, kIconMargin, kIconMargin);
+ box_layout->set_main_axis_alignment(
+ views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER);
+ box_layout->set_cross_axis_alignment(
+ views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER);
+ container->SetLayoutManager(box_layout);
+ for (size_t i = 0; i < std::min(top_level->item_count(), kMaxIconNum); ++i)
+ container->AddChildView(new AppIconButton(top_level->item_at(i)));
+
+ views::View* search_box_container = new views::View();
+ search_box_container->set_background(new BorderedSearchBoxBackground());
+ search_box_container->SetLayoutManager(new views::FillLayout());
+ search_box_container->AddChildView(
+ new app_list::SearchBoxView(this, view_delegate));
+ container->AddChildView(search_box_container);
+ box_layout->SetFlexForView(search_box_container, 1);
+
+ for (size_t i = 0; i < kMaxIconNum; ++i)
+ container->AddChildView(new PlaceHolderButton());
+
+ set_background(views::Background::CreateSolidBackground(
+ 255, 255, 255, 255 * 0.9));
+}
+
+AthenaStartPageView::~AthenaStartPageView() {}
+
+void AthenaStartPageView::Layout() {
+ gfx::Rect container_bounds = bounds();
+ container_bounds.set_height(kPreferredHeightBottom);
+ child_at(0)->SetBoundsRect(container_bounds);
+}
+
+void AthenaStartPageView::QueryChanged(app_list::SearchBoxView* sender) {
+ // Nothing needs to be done.
+}
+
+} // namespace athena

Powered by Google App Engine
This is Rietveld 408576698