OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "athena/home/athena_start_page_view.h" |
| 6 |
| 7 #include "third_party/skia/include/core/SkPaint.h" |
| 8 #include "third_party/skia/include/core/SkPath.h" |
| 9 #include "ui/app_list/app_list_item.h" |
| 10 #include "ui/app_list/app_list_item_list.h" |
| 11 #include "ui/app_list/app_list_model.h" |
| 12 #include "ui/app_list/app_list_view_delegate.h" |
| 13 #include "ui/app_list/views/search_box_view.h" |
| 14 #include "ui/gfx/canvas.h" |
| 15 #include "ui/views/background.h" |
| 16 #include "ui/views/border.h" |
| 17 #include "ui/views/layout/box_layout.h" |
| 18 #include "ui/views/layout/fill_layout.h" |
| 19 #include "ui/views/round_rect_painter.h" |
| 20 |
| 21 namespace { |
| 22 |
| 23 const size_t kMaxIconNum = 3; |
| 24 const int kIconSize = 50; |
| 25 const int kIconMargin = 25; |
| 26 |
| 27 const int kBorderWidth = 1; |
| 28 const int kCornerRadius = 1; |
| 29 |
| 30 // The preferred height for VISIBLE_BOTTOM state. |
| 31 const int kPreferredHeightBottom = 100; |
| 32 |
| 33 class PlaceHolderButton : public views::ImageButton, |
| 34 public views::ButtonListener { |
| 35 public: |
| 36 PlaceHolderButton() |
| 37 : ImageButton(this) { |
| 38 gfx::Canvas canvas(gfx::Size(kIconSize, kIconSize), 1.0f, true); |
| 39 SkPaint paint; |
| 40 paint.setStyle(SkPaint::kFill_Style); |
| 41 paint.setColor(SkColorSetRGB(86, 119, 252)); |
| 42 paint.setFlags(SkPaint::kAntiAlias_Flag); |
| 43 canvas.DrawCircle( |
| 44 gfx::Point(kIconSize / 2, kIconSize / 2), kIconSize / 2, paint); |
| 45 |
| 46 scoped_ptr<gfx::ImageSkia> image( |
| 47 new gfx::ImageSkia(canvas.ExtractImageRep())); |
| 48 SetImage(STATE_NORMAL, image.get()); |
| 49 } |
| 50 |
| 51 private: |
| 52 // views::ButtonListener: |
| 53 virtual void ButtonPressed(views::Button* sender, |
| 54 const ui::Event& event) OVERRIDE { |
| 55 // Do nothing: remove these place holders. |
| 56 } |
| 57 |
| 58 DISALLOW_COPY_AND_ASSIGN(PlaceHolderButton); |
| 59 }; |
| 60 |
| 61 class AppIconButton : public views::ImageButton, |
| 62 public views::ButtonListener { |
| 63 public: |
| 64 explicit AppIconButton(app_list::AppListItem* item) |
| 65 : ImageButton(this), |
| 66 item_(item) { |
| 67 // TODO(mukai): icon should be resized. |
| 68 SetImage(STATE_NORMAL, &item->icon()); |
| 69 } |
| 70 |
| 71 private: |
| 72 // views::ButtonListener: |
| 73 virtual void ButtonPressed(views::Button* sender, |
| 74 const ui::Event& event) OVERRIDE { |
| 75 DCHECK_EQ(sender, this); |
| 76 item_->Activate(event.flags()); |
| 77 } |
| 78 |
| 79 app_list::AppListItem* item_; |
| 80 |
| 81 DISALLOW_COPY_AND_ASSIGN(AppIconButton); |
| 82 }; |
| 83 |
| 84 // The background to paint the round rectangle of the view area. |
| 85 class RoundRectBackground : public views::Background { |
| 86 public: |
| 87 RoundRectBackground(SkColor color, int corner_radius) |
| 88 : color_(color), |
| 89 corner_radius_(corner_radius) {} |
| 90 virtual ~RoundRectBackground() {} |
| 91 |
| 92 private: |
| 93 // views::Background: |
| 94 virtual void Paint(gfx::Canvas* canvas, views::View* view) const OVERRIDE { |
| 95 SkPaint paint; |
| 96 paint.setStyle(SkPaint::kFill_Style); |
| 97 paint.setColor(color_); |
| 98 canvas->DrawRoundRect(view->GetContentsBounds(), corner_radius_, paint); |
| 99 } |
| 100 |
| 101 SkColor color_; |
| 102 int corner_radius_; |
| 103 |
| 104 DISALLOW_COPY_AND_ASSIGN(RoundRectBackground); |
| 105 }; |
| 106 |
| 107 } // namespace |
| 108 |
| 109 namespace athena { |
| 110 |
| 111 AthenaStartPageView::AthenaStartPageView( |
| 112 app_list::AppListViewDelegate* view_delegate) { |
| 113 app_list::AppListItemList* top_level = |
| 114 view_delegate->GetModel()->top_level_item_list(); |
| 115 |
| 116 container_ = new views::View(); |
| 117 AddChildView(container_); |
| 118 |
| 119 views::BoxLayout* box_layout = new views::BoxLayout( |
| 120 views::BoxLayout::kHorizontal, kIconMargin, kIconMargin, kIconMargin); |
| 121 box_layout->set_main_axis_alignment( |
| 122 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); |
| 123 box_layout->set_cross_axis_alignment( |
| 124 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); |
| 125 container_->SetLayoutManager(box_layout); |
| 126 for (size_t i = 0; i < std::min(top_level->item_count(), kMaxIconNum); ++i) |
| 127 container_->AddChildView(new AppIconButton(top_level->item_at(i))); |
| 128 |
| 129 views::View* search_box_container = new views::View(); |
| 130 search_box_container->set_background( |
| 131 new RoundRectBackground(SK_ColorWHITE, kCornerRadius)); |
| 132 search_box_container->SetBorder(views::Border::CreateBorderPainter( |
| 133 new views::RoundRectPainter(SK_ColorGRAY, kCornerRadius), |
| 134 gfx::Insets(kBorderWidth, kBorderWidth, kBorderWidth, kBorderWidth))); |
| 135 search_box_container->SetLayoutManager(new views::FillLayout()); |
| 136 search_box_container->AddChildView( |
| 137 new app_list::SearchBoxView(this, view_delegate)); |
| 138 container_->AddChildView(search_box_container); |
| 139 box_layout->SetFlexForView(search_box_container, 1); |
| 140 |
| 141 for (size_t i = 0; i < kMaxIconNum; ++i) |
| 142 container_->AddChildView(new PlaceHolderButton()); |
| 143 |
| 144 set_background(views::Background::CreateSolidBackground( |
| 145 255, 255, 255, 255 * 0.9)); |
| 146 } |
| 147 |
| 148 AthenaStartPageView::~AthenaStartPageView() {} |
| 149 |
| 150 void AthenaStartPageView::Layout() { |
| 151 gfx::Rect container_bounds = bounds(); |
| 152 container_bounds.set_height(kPreferredHeightBottom); |
| 153 container_->SetBoundsRect(container_bounds); |
| 154 } |
| 155 |
| 156 void AthenaStartPageView::QueryChanged(app_list::SearchBoxView* sender) { |
| 157 // Nothing needs to be done. |
| 158 } |
| 159 |
| 160 } // namespace athena |
OLD | NEW |