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 | |
21 namespace { | |
22 | |
23 const size_t kMaxIconNum = 3; | |
24 const int kIconSize = 50; | |
25 const int kIconMargin = 25; | |
26 | |
27 const int kCornerRadius = 1; | |
28 | |
29 // The preferred height for VISIBLE_BOTTOM state. | |
30 const int kPreferredHeightBottom = 100; | |
31 | |
32 class PlaceHolderButton : public views::ImageButton, | |
33 public views::ButtonListener { | |
34 public: | |
35 PlaceHolderButton() | |
36 : ImageButton(this) { | |
37 gfx::Canvas canvas(gfx::Size(kIconSize, kIconSize), 1.0f, true); | |
38 SkPaint paint; | |
39 paint.setStyle(SkPaint::kFill_Style); | |
40 paint.setColor(SkColorSetRGB(86, 119, 252)); | |
41 paint.setFlags(SkPaint::kAntiAlias_Flag); | |
42 canvas.DrawCircle( | |
43 gfx::Point(kIconSize / 2, kIconSize / 2), kIconSize / 2, paint); | |
44 | |
45 scoped_ptr<gfx::ImageSkia> image( | |
46 new gfx::ImageSkia(canvas.ExtractImageRep())); | |
47 SetImage(STATE_NORMAL, image.get()); | |
48 } | |
49 | |
50 private: | |
51 // views::ButtonListener: | |
52 virtual void ButtonPressed(views::Button* sender, | |
53 const ui::Event& event) OVERRIDE { | |
54 // Do nothing: remove these place holders. | |
55 } | |
56 | |
57 DISALLOW_COPY_AND_ASSIGN(PlaceHolderButton); | |
58 }; | |
59 | |
60 class AppIconButton : public views::ImageButton, | |
61 public views::ButtonListener { | |
62 public: | |
63 explicit AppIconButton(app_list::AppListItem* item) | |
64 : ImageButton(this), | |
65 item_(item) { | |
66 // TODO(mukai): icon should be resized. | |
67 SetImage(STATE_NORMAL, &item->icon()); | |
68 } | |
69 | |
70 private: | |
71 // views::ButtonListener: | |
72 virtual void ButtonPressed(views::Button* sender, | |
73 const ui::Event& event) OVERRIDE { | |
74 DCHECK_EQ(sender, this); | |
75 item_->Activate(event.flags()); | |
76 } | |
77 | |
78 app_list::AppListItem* item_; | |
79 | |
80 DISALLOW_COPY_AND_ASSIGN(AppIconButton); | |
81 }; | |
82 | |
83 // The background to paint the round rectangle of the view area. | |
84 class RoundRectBackground : public views::Background { | |
85 public: | |
86 RoundRectBackground(SkColor color, int corner_radius) | |
87 : color_(color), | |
88 corner_radius_(corner_radius) {} | |
89 virtual ~RoundRectBackground() {} | |
90 | |
91 private: | |
92 // views::Background: | |
93 virtual void Paint(gfx::Canvas* canvas, views::View* view) const OVERRIDE { | |
94 SkPaint paint; | |
95 paint.setStyle(SkPaint::kFill_Style); | |
96 paint.setColor(color_); | |
97 canvas->DrawRoundRect(view->GetContentsBounds(), corner_radius_, paint); | |
98 } | |
99 | |
100 SkColor color_; | |
101 int corner_radius_; | |
102 | |
103 DISALLOW_COPY_AND_ASSIGN(RoundRectBackground); | |
104 }; | |
105 | |
106 // The border to draw 1px width round rectangle of the specified view area. | |
107 class RoundRectBorder : public views::Border { | |
sadrul
2014/08/14 03:03:27
Maybe you could use views::RoundRectPainter instea
Jun Mukai
2014/08/14 16:49:36
Done.
| |
108 public: | |
109 RoundRectBorder(SkColor color, int corner_radius) | |
110 : color_(color), | |
111 corner_radius_(corner_radius) {} | |
112 virtual ~RoundRectBorder() {} | |
113 | |
114 private: | |
115 static const int kBorderWidth = 1; | |
116 | |
117 // views::Border: | |
118 virtual void Paint(const views::View& view, gfx::Canvas* canvas) OVERRIDE { | |
119 SkPaint paint; | |
120 paint.setStyle(SkPaint::kStroke_Style); | |
121 paint.setColor(color_); | |
122 paint.setStrokeWidth(kBorderWidth); | |
123 gfx::Rect bounds = view.GetLocalBounds(); | |
124 bounds.Inset(kBorderWidth, kBorderWidth); | |
125 canvas->DrawRoundRect(bounds, corner_radius_, paint); | |
126 } | |
127 virtual gfx::Insets GetInsets() const OVERRIDE { | |
128 return gfx::Insets(kBorderWidth, kBorderWidth, kBorderWidth, kBorderWidth); | |
129 } | |
130 virtual gfx::Size GetMinimumSize() const OVERRIDE { | |
131 return gfx::Size(); | |
132 } | |
133 | |
134 SkColor color_; | |
135 int corner_radius_; | |
136 | |
137 DISALLOW_COPY_AND_ASSIGN(RoundRectBorder); | |
138 }; | |
139 | |
140 } // namespace | |
141 | |
142 namespace athena { | |
143 | |
144 AthenaStartPageView::AthenaStartPageView( | |
145 app_list::AppListViewDelegate* view_delegate) { | |
146 app_list::AppListItemList* top_level = | |
147 view_delegate->GetModel()->top_level_item_list(); | |
148 | |
149 views::View* container = new views::View(); | |
150 AddChildView(container); | |
151 | |
152 views::BoxLayout* box_layout = new views::BoxLayout( | |
153 views::BoxLayout::kHorizontal, kIconMargin, kIconMargin, kIconMargin); | |
154 box_layout->set_main_axis_alignment( | |
155 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); | |
156 box_layout->set_cross_axis_alignment( | |
157 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); | |
158 container->SetLayoutManager(box_layout); | |
159 for (size_t i = 0; i < std::min(top_level->item_count(), kMaxIconNum); ++i) | |
160 container->AddChildView(new AppIconButton(top_level->item_at(i))); | |
161 | |
162 views::View* search_box_container = new views::View(); | |
163 search_box_container->set_background( | |
164 new RoundRectBackground(SK_ColorWHITE, kCornerRadius)); | |
165 search_box_container->SetBorder(scoped_ptr<views::Border>( | |
166 new RoundRectBorder(SK_ColorGRAY, kCornerRadius))); | |
167 search_box_container->SetLayoutManager(new views::FillLayout()); | |
168 search_box_container->AddChildView( | |
169 new app_list::SearchBoxView(this, view_delegate)); | |
170 container->AddChildView(search_box_container); | |
171 box_layout->SetFlexForView(search_box_container, 1); | |
172 | |
173 for (size_t i = 0; i < kMaxIconNum; ++i) | |
174 container->AddChildView(new PlaceHolderButton()); | |
175 | |
176 set_background(views::Background::CreateSolidBackground( | |
177 255, 255, 255, 255 * 0.9)); | |
178 } | |
179 | |
180 AthenaStartPageView::~AthenaStartPageView() {} | |
181 | |
182 void AthenaStartPageView::Layout() { | |
183 gfx::Rect container_bounds = bounds(); | |
184 container_bounds.set_height(kPreferredHeightBottom); | |
185 child_at(0)->SetBoundsRect(container_bounds); | |
sadrul
2014/08/14 03:03:27
Maybe keep track of |app_icon_container_| (or some
Jun Mukai
2014/08/14 16:49:36
Done. Since it also contains the search box, named
| |
186 } | |
187 | |
188 void AthenaStartPageView::QueryChanged(app_list::SearchBoxView* sender) { | |
189 // Nothing needs to be done. | |
190 } | |
191 | |
192 } // namespace athena | |
OLD | NEW |