Chromium Code Reviews| 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/painter.h" | |
| 20 #include "ui/views/shadow_border.h" | |
| 21 | |
| 22 namespace { | |
| 23 | |
| 24 const size_t kMaxIconNum = 3; | |
| 25 const int kIconSize = 50; | |
| 26 const int kIconMargin = 25; | |
| 27 | |
| 28 // The preferred height for VISIBLE_BOTTOM state. | |
| 29 const int kPreferredHeightBottom = 100; | |
| 30 | |
| 31 class PlaceHolderButton : public views::ImageButton, | |
| 32 public views::ButtonListener { | |
| 33 public: | |
| 34 PlaceHolderButton() | |
| 35 : ImageButton(this) { | |
| 36 gfx::Canvas canvas(gfx::Size(kIconSize, kIconSize), 1.0f, true); | |
| 37 SkPaint paint; | |
| 38 paint.setStyle(SkPaint::kFill_Style); | |
| 39 paint.setColor(SkColorSetRGB(86, 119, 252)); | |
| 40 paint.setFlags(SkPaint::kAntiAlias_Flag); | |
| 41 canvas.DrawCircle( | |
| 42 gfx::Point(kIconSize / 2, kIconSize / 2), kIconSize / 2, paint); | |
| 43 | |
| 44 scoped_ptr<gfx::ImageSkia> image( | |
| 45 new gfx::ImageSkia(canvas.ExtractImageRep())); | |
| 46 SetImage(STATE_NORMAL, image.get()); | |
| 47 } | |
| 48 | |
| 49 private: | |
| 50 // views::ButtonListener: | |
| 51 virtual void ButtonPressed(views::Button* sender, | |
| 52 const ui::Event& event) OVERRIDE { | |
| 53 // Do nothing: remove these place holders. | |
| 54 } | |
| 55 | |
| 56 DISALLOW_COPY_AND_ASSIGN(PlaceHolderButton); | |
| 57 }; | |
| 58 | |
| 59 class AppIconButton : public views::ImageButton, | |
| 60 public views::ButtonListener { | |
| 61 public: | |
| 62 explicit AppIconButton(app_list::AppListItem* item) | |
| 63 : ImageButton(this), | |
| 64 item_(item) { | |
| 65 // TODO(mukai): icon should be resized. | |
| 66 SetImage(STATE_NORMAL, &item->icon()); | |
| 67 } | |
| 68 | |
| 69 private: | |
| 70 // views::ButtonListener: | |
| 71 virtual void ButtonPressed(views::Button* sender, | |
| 72 const ui::Event& event) OVERRIDE { | |
| 73 DCHECK_EQ(sender, this); | |
| 74 item_->Activate(event.flags()); | |
| 75 } | |
| 76 | |
| 77 app_list::AppListItem* item_; | |
| 78 | |
| 79 DISALLOW_COPY_AND_ASSIGN(AppIconButton); | |
| 80 }; | |
| 81 | |
| 82 // This class draws the background and border of the search box. | |
| 83 class BorderedSearchBoxBackground : public views::Background { | |
| 84 public: | |
| 85 BorderedSearchBoxBackground() {} | |
| 86 virtual ~BorderedSearchBoxBackground() {} | |
| 87 | |
| 88 private: | |
| 89 static const int kBorderWidth = 1; | |
| 90 static const int kCornerRadius = 1; | |
| 91 | |
| 92 // views::Background: | |
| 93 virtual void Paint(gfx::Canvas* canvas, views::View* view) const OVERRIDE { | |
| 94 SkPath path; | |
| 95 gfx::Rect bounds = view->GetContentsBounds(); | |
| 96 bounds.Inset(1, 1); | |
| 97 path.addRoundRect(SkRect::MakeXYWH(bounds.x(), bounds.y(), | |
| 98 bounds.width(), bounds.height()), | |
| 99 kCornerRadius, kCornerRadius, SkPath::kCW_Direction); | |
| 100 SkPaint background_paint; | |
| 101 background_paint.setStyle(SkPaint::kFill_Style); | |
| 102 background_paint.setColor(SK_ColorWHITE); | |
| 103 canvas->DrawPath(path, background_paint); | |
| 104 | |
| 105 SkPaint border_paint; | |
| 106 border_paint.setStyle(SkPaint::kStroke_Style); | |
| 107 border_paint.setColor(SK_ColorGRAY); | |
| 108 border_paint.setStrokeWidth(SkIntToScalar(kBorderWidth)); | |
| 109 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
| |
| 110 } | |
| 111 | |
| 112 DISALLOW_COPY_AND_ASSIGN(BorderedSearchBoxBackground); | |
| 113 }; | |
| 114 | |
| 115 } // namespace | |
| 116 | |
| 117 namespace athena { | |
| 118 | |
| 119 AthenaStartPageView::AthenaStartPageView( | |
| 120 app_list::AppListViewDelegate* view_delegate) { | |
| 121 app_list::AppListItemList* top_level = | |
| 122 view_delegate->GetModel()->top_level_item_list(); | |
| 123 | |
| 124 views::View* container = new views::View(); | |
| 125 AddChildView(container); | |
| 126 | |
| 127 views::BoxLayout* box_layout = new views::BoxLayout( | |
| 128 views::BoxLayout::kHorizontal, kIconMargin, kIconMargin, kIconMargin); | |
| 129 box_layout->set_main_axis_alignment( | |
| 130 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); | |
| 131 box_layout->set_cross_axis_alignment( | |
| 132 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); | |
| 133 container->SetLayoutManager(box_layout); | |
| 134 for (size_t i = 0; i < std::min(top_level->item_count(), kMaxIconNum); ++i) | |
| 135 container->AddChildView(new AppIconButton(top_level->item_at(i))); | |
| 136 | |
| 137 views::View* search_box_container = new views::View(); | |
| 138 search_box_container->set_background(new BorderedSearchBoxBackground()); | |
| 139 search_box_container->SetLayoutManager(new views::FillLayout()); | |
| 140 search_box_container->AddChildView( | |
| 141 new app_list::SearchBoxView(this, view_delegate)); | |
| 142 container->AddChildView(search_box_container); | |
| 143 box_layout->SetFlexForView(search_box_container, 1); | |
| 144 | |
| 145 for (size_t i = 0; i < kMaxIconNum; ++i) | |
| 146 container->AddChildView(new PlaceHolderButton()); | |
| 147 | |
| 148 set_background(views::Background::CreateSolidBackground( | |
| 149 255, 255, 255, 255 * 0.9)); | |
| 150 } | |
| 151 | |
| 152 AthenaStartPageView::~AthenaStartPageView() {} | |
| 153 | |
| 154 void AthenaStartPageView::Layout() { | |
| 155 gfx::Rect container_bounds = bounds(); | |
| 156 container_bounds.set_height(kPreferredHeightBottom); | |
| 157 child_at(0)->SetBoundsRect(container_bounds); | |
| 158 } | |
| 159 | |
| 160 void AthenaStartPageView::QueryChanged(app_list::SearchBoxView* sender) { | |
| 161 // Nothing needs to be done. | |
| 162 } | |
| 163 | |
| 164 } // namespace athena | |
| OLD | NEW |