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

Side by Side Diff: ui/app_list/views/start_page_view.cc

Issue 335343002: Add a DummySearchBoxView to the experimental app list start page. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/app_list/views/start_page_view.h" 5 #include "ui/app_list/views/start_page_view.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "ui/app_list/app_list_constants.h" 8 #include "ui/app_list/app_list_constants.h"
9 #include "ui/app_list/app_list_item.h" 9 #include "ui/app_list/app_list_item.h"
10 #include "ui/app_list/app_list_model.h" 10 #include "ui/app_list/app_list_model.h"
11 #include "ui/app_list/app_list_view_delegate.h" 11 #include "ui/app_list/app_list_view_delegate.h"
12 #include "ui/app_list/views/app_list_main_view.h" 12 #include "ui/app_list/views/app_list_main_view.h"
13 #include "ui/app_list/views/search_box_view.h"
13 #include "ui/app_list/views/search_result_list_view.h" 14 #include "ui/app_list/views/search_result_list_view.h"
14 #include "ui/app_list/views/tile_item_view.h" 15 #include "ui/app_list/views/tile_item_view.h"
15 #include "ui/gfx/canvas.h" 16 #include "ui/gfx/canvas.h"
16 #include "ui/views/controls/button/custom_button.h" 17 #include "ui/views/background.h"
17 #include "ui/views/controls/image_view.h" 18 #include "ui/views/controls/image_view.h"
18 #include "ui/views/controls/label.h" 19 #include "ui/views/controls/label.h"
20 #include "ui/views/controls/textfield/textfield.h"
19 #include "ui/views/layout/box_layout.h" 21 #include "ui/views/layout/box_layout.h"
20 22
21 namespace app_list { 23 namespace app_list {
22 24
23 namespace { 25 namespace {
24 26
27 // Layout constants
tapted 2014/06/18 02:46:05 nit: full-stop at the end of comments. More below.
calamity 2014/06/18 06:49:40 Done.
25 const int kTopMargin = 30; 28 const int kTopMargin = 30;
29 const int kInstantContainerSpacing = 20;
26 30
31 // WebView constants
27 const int kWebViewWidth = 200; 32 const int kWebViewWidth = 200;
28 const int kWebViewHeight = 105; 33 const int kWebViewHeight = 105;
29 34
30 const int kInstantContainerSpacing = 20; 35 // DummySearchBoxView constants
31 const int kBarPlaceholderWidth = 490; 36 const int kDummySearchBoxWidth = 490;
32 const int kBarPlaceholderHeight = 30; 37 const int kDummySearchBoxHeight = 40;
38 const SkColor kDummySearchBoxBorderColor =
39 SkColorSetARGB(0x30, 0xD0, 0xD0, 0xD0);
tapted 2014/06/18 02:46:06 If the thing behind the color is always solid, I t
calamity 2014/06/18 06:49:40 Done. Moved this to app_list_constants.h
40 const int kDummySearchBoxBorderWidth = 1;
41 const int kDummySearchBoxBorderBottomWidth = 2;
42 const int kDummySearchBoxBorderCornerRadius = 2;
33 43
44 // Tile container constants
34 const size_t kNumStartPageTiles = 5; 45 const size_t kNumStartPageTiles = 5;
35 const int kTileSpacing = 10; 46 const int kTileSpacing = 10;
36 47
37 // A button that is the placeholder for the search bar in the start page view. 48 // A placeholder search box which is sized to fit within the start page view.
38 class BarPlaceholderButton : public views::CustomButton { 49 class DummySearchBoxView : public SearchBoxView {
39 public: 50 public:
40 explicit BarPlaceholderButton(views::ButtonListener* listener) 51 explicit DummySearchBoxView(SearchBoxViewDelegate* delegate,
tapted 2014/06/18 02:46:05 nit: explicit not required
calamity 2014/06/18 06:49:40 Done.
41 : views::CustomButton(listener) {} 52 AppListViewDelegate* view_delegate)
53 : SearchBoxView(delegate, view_delegate) {}
42 54
43 virtual ~BarPlaceholderButton() {} 55 virtual ~DummySearchBoxView() {}
44 56
45 // Overridden from views::View: 57 // Overridden from views::View:
46 virtual gfx::Size GetPreferredSize() const OVERRIDE { 58 virtual gfx::Size GetPreferredSize() const OVERRIDE {
47 return gfx::Size(kBarPlaceholderWidth, kBarPlaceholderHeight); 59 return gfx::Size(kDummySearchBoxWidth, kDummySearchBoxHeight);
48 }
49
50 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
51 PaintButton(
52 canvas,
53 state() == STATE_HOVERED ? kPagerHoverColor : kPagerNormalColor);
54 } 60 }
55 61
56 private: 62 private:
57 // Paints a rectangular button. 63 DISALLOW_COPY_AND_ASSIGN(DummySearchBoxView);
58 void PaintButton(gfx::Canvas* canvas, SkColor base_color) { 64 };
59 gfx::Rect rect(GetContentsBounds()); 65
60 rect.ClampToCenteredSize( 66 class DummySearchBoxBackground : public views::Background {
tapted 2014/06/18 02:46:06 this class needs a brief comment describing what P
calamity 2014/06/18 06:49:40 Done.
61 gfx::Size(kBarPlaceholderWidth, kBarPlaceholderHeight)); 67 public:
68 DummySearchBoxBackground() {}
69 virtual ~DummySearchBoxBackground() {}
70
71 private:
72 // views::Background overrides:
73 virtual void Paint(gfx::Canvas* canvas, views::View* view) const OVERRIDE {
74 gfx::Rect bounds = view->GetContentsBounds();
62 75
63 SkPaint paint; 76 SkPaint paint;
64 paint.setAntiAlias(true); 77 paint.setFlags(SkPaint::kAntiAlias_Flag);
65 paint.setStyle(SkPaint::kFill_Style); 78 paint.setColor(kDummySearchBoxBorderColor);
66 paint.setColor(base_color); 79 canvas->DrawRoundRect(bounds, kDummySearchBoxBorderCornerRadius, paint);
67 canvas->DrawRect(rect, paint); 80 bounds.Inset(kDummySearchBoxBorderWidth,
81 kDummySearchBoxBorderWidth,
82 kDummySearchBoxBorderWidth,
83 kDummySearchBoxBorderBottomWidth);
84 paint.setColor(SK_ColorWHITE);
85 canvas->DrawRoundRect(bounds, kDummySearchBoxBorderCornerRadius, paint);
68 } 86 }
69 87
70 DISALLOW_COPY_AND_ASSIGN(BarPlaceholderButton); 88 DISALLOW_COPY_AND_ASSIGN(DummySearchBoxBackground);
71 }; 89 };
72 90
73 } // namespace 91 } // namespace
74 92
75 StartPageView::StartPageView(AppListMainView* app_list_main_view, 93 StartPageView::StartPageView(AppListMainView* app_list_main_view,
76 AppListViewDelegate* view_delegate) 94 AppListViewDelegate* view_delegate)
77 : app_list_main_view_(app_list_main_view), 95 : app_list_main_view_(app_list_main_view),
78 model_(NULL), 96 model_(NULL),
79 view_delegate_(view_delegate), 97 view_delegate_(view_delegate),
98 search_box_view_(new DummySearchBoxView(this, view_delegate_)),
80 results_view_( 99 results_view_(
81 new SearchResultListView(app_list_main_view, view_delegate)), 100 new SearchResultListView(app_list_main_view, view_delegate)),
82 instant_container_(new views::View), 101 instant_container_(new views::View),
83 tiles_container_(new views::View), 102 tiles_container_(new views::View),
84 show_state_(SHOW_START_PAGE) { 103 show_state_(SHOW_START_PAGE) {
85 // The view containing the start page WebContents and the BarPlaceholder. 104 // The view containing the start page WebContents and DummySearchBoxView.
105 InitInstantContainer();
86 AddChildView(instant_container_); 106 AddChildView(instant_container_);
107
108 // The view containing the search results.
109 AddChildView(results_view_);
110
111 // The view containing the start page tiles.
112 InitTilesContainer();
113 AddChildView(tiles_container_);
114
115 SetModel(view_delegate_->GetModel());
116 view_delegate_->AddObserver(this);
117 }
118
119 StartPageView::~StartPageView() {
120 view_delegate_->RemoveObserver(this);
121 if (model_)
122 model_->RemoveObserver(this);
123 }
124
125 void StartPageView::InitInstantContainer() {
87 views::BoxLayout* instant_layout_manager = new views::BoxLayout( 126 views::BoxLayout* instant_layout_manager = new views::BoxLayout(
88 views::BoxLayout::kVertical, 0, 0, kInstantContainerSpacing); 127 views::BoxLayout::kVertical, 0, 0, kInstantContainerSpacing);
89 instant_layout_manager->set_inside_border_insets( 128 instant_layout_manager->set_inside_border_insets(
90 gfx::Insets(kTopMargin, 0, kInstantContainerSpacing, 0)); 129 gfx::Insets(kTopMargin, 0, kInstantContainerSpacing, 0));
91 instant_layout_manager->set_main_axis_alignment( 130 instant_layout_manager->set_main_axis_alignment(
92 views::BoxLayout::MAIN_AXIS_ALIGNMENT_END); 131 views::BoxLayout::MAIN_AXIS_ALIGNMENT_END);
93 instant_container_->SetLayoutManager(instant_layout_manager); 132 instant_container_->SetLayoutManager(instant_layout_manager);
94 133
95 views::View* web_view = view_delegate->CreateStartPageWebView( 134 views::View* web_view = view_delegate_->CreateStartPageWebView(
96 gfx::Size(kWebViewWidth, kWebViewHeight)); 135 gfx::Size(kWebViewWidth, kWebViewHeight));
97 if (web_view) 136 if (web_view)
98 instant_container_->AddChildView(web_view); 137 instant_container_->AddChildView(web_view);
99 instant_container_->AddChildView(new BarPlaceholderButton(this));
100 138
101 // The view containing the search results. 139 // TODO(calamity): This container is needed to horizontally center the search
102 AddChildView(results_view_); 140 // box view. Remove this container once BoxLayout supports CrossAxisAlignment.
141 views::View* search_box_container = new views::View();
142 views::BoxLayout* layout_manager =
143 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0);
144 layout_manager->set_main_axis_alignment(
145 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER);
146 search_box_container->SetLayoutManager(layout_manager);
103 147
104 // The view containing the start page tiles. 148 search_box_container->AddChildView(search_box_view_);
105 AddChildView(tiles_container_); 149 search_box_view_->set_background(new DummySearchBoxBackground());
tapted 2014/06/18 02:46:06 maybe do this in the DummySearchBoxView constructo
calamity 2014/06/18 06:49:40 Done.
150
151 instant_container_->AddChildView(search_box_container);
152 }
153
154 void StartPageView::InitTilesContainer() {
106 views::BoxLayout* tiles_layout_manager = 155 views::BoxLayout* tiles_layout_manager =
107 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, kTileSpacing); 156 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, kTileSpacing);
108 tiles_layout_manager->set_main_axis_alignment( 157 tiles_layout_manager->set_main_axis_alignment(
109 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); 158 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER);
110 tiles_container_->SetLayoutManager(tiles_layout_manager); 159 tiles_container_->SetLayoutManager(tiles_layout_manager);
111 for (size_t i = 0; i < kNumStartPageTiles; ++i) { 160 for (size_t i = 0; i < kNumStartPageTiles; ++i) {
112 TileItemView* tile_item = new TileItemView(); 161 TileItemView* tile_item = new TileItemView();
113 tiles_container_->AddChildView(tile_item); 162 tiles_container_->AddChildView(tile_item);
114 tile_views_.push_back(tile_item); 163 tile_views_.push_back(tile_item);
115 } 164 }
116
117 SetModel(view_delegate_->GetModel());
118 view_delegate_->AddObserver(this);
119 }
120
121 StartPageView::~StartPageView() {
122 view_delegate_->RemoveObserver(this);
123 if (model_)
124 model_->RemoveObserver(this);
125 } 165 }
126 166
127 void StartPageView::SetModel(AppListModel* model) { 167 void StartPageView::SetModel(AppListModel* model) {
128 DCHECK(model); 168 DCHECK(model);
129 if (model_) 169 if (model_)
130 model_->RemoveObserver(this); 170 model_->RemoveObserver(this);
131 model_ = model; 171 model_ = model;
132 model_->AddObserver(this); 172 model_->AddObserver(this);
133 results_view_->SetResults(model_->results()); 173 results_view_->SetResults(model_->results());
134 Reset(); 174 Reset();
(...skipping 13 matching lines...) Expand all
148 } 188 }
149 189
150 void StartPageView::ShowSearchResults() { 190 void StartPageView::ShowSearchResults() {
151 SetShowState(SHOW_SEARCH_RESULTS); 191 SetShowState(SHOW_SEARCH_RESULTS);
152 } 192 }
153 193
154 void StartPageView::SetShowState(ShowState show_state) { 194 void StartPageView::SetShowState(ShowState show_state) {
155 instant_container_->SetVisible(show_state == SHOW_START_PAGE); 195 instant_container_->SetVisible(show_state == SHOW_START_PAGE);
156 results_view_->SetVisible(show_state == SHOW_SEARCH_RESULTS); 196 results_view_->SetVisible(show_state == SHOW_SEARCH_RESULTS);
157 197
198 if (show_state == SHOW_START_PAGE)
199 search_box_view_->search_box()->RequestFocus();
200
158 if (show_state_ == show_state) 201 if (show_state_ == show_state)
159 return; 202 return;
160 203
161 show_state_ = show_state; 204 show_state_ = show_state;
162 205
163 results_view_->UpdateAutoLaunchState(); 206 results_view_->UpdateAutoLaunchState();
164 if (show_state == SHOW_SEARCH_RESULTS) 207 if (show_state == SHOW_SEARCH_RESULTS)
165 results_view_->SetSelectedIndex(0); 208 results_view_->SetSelectedIndex(0);
166 } 209 }
167 210
(...skipping 14 matching lines...) Expand all
182 bounds.set_height(instant_container_->GetHeightForWidth(bounds.width())); 225 bounds.set_height(instant_container_->GetHeightForWidth(bounds.width()));
183 instant_container_->SetBoundsRect(bounds); 226 instant_container_->SetBoundsRect(bounds);
184 results_view_->SetBoundsRect(bounds); 227 results_view_->SetBoundsRect(bounds);
185 228
186 // Tiles begin where the instant container ends. 229 // Tiles begin where the instant container ends.
187 bounds.set_y(bounds.bottom()); 230 bounds.set_y(bounds.bottom());
188 bounds.set_height(tiles_container_->GetHeightForWidth(bounds.width())); 231 bounds.set_height(tiles_container_->GetHeightForWidth(bounds.width()));
189 tiles_container_->SetBoundsRect(bounds); 232 tiles_container_->SetBoundsRect(bounds);
190 } 233 }
191 234
192 void StartPageView::ButtonPressed(views::Button* sender, 235 void StartPageView::QueryChanged(SearchBoxView* sender) {
193 const ui::Event& event) { 236 // Forward the search terms on to the real search box and clear the dummy
194 app_list_main_view_->OnStartPageSearchButtonPressed(); 237 // search box.
238 app_list_main_view_->OnStartPageSearchTextfieldChanged(
239 sender->search_box()->text());
240 sender->search_box()->SetText(base::string16());
tapted 2014/06/18 02:46:06 each SearchBoxView has a reference to the the same
calamity 2014/06/18 06:49:40 Hmm. This doesn't _actually_ affect anything due t
calamity 2014/06/18 07:08:30 Actually, it looks like this isn't exactly easy. T
195 } 241 }
196 242
197 void StartPageView::OnProfilesChanged() { 243 void StartPageView::OnProfilesChanged() {
198 SetModel(view_delegate_->GetModel()); 244 SetModel(view_delegate_->GetModel());
199 } 245 }
200 246
201 void StartPageView::OnAppListModelStatusChanged() { 247 void StartPageView::OnAppListModelStatusChanged() {
202 Reset(); 248 Reset();
203 } 249 }
204 250
205 void StartPageView::OnAppListItemAdded(AppListItem* item) { 251 void StartPageView::OnAppListItemAdded(AppListItem* item) {
206 Reset(); 252 Reset();
207 } 253 }
208 254
209 void StartPageView::OnAppListItemDeleted() { 255 void StartPageView::OnAppListItemDeleted() {
210 Reset(); 256 Reset();
211 } 257 }
212 258
213 void StartPageView::OnAppListItemUpdated(AppListItem* item) { 259 void StartPageView::OnAppListItemUpdated(AppListItem* item) {
214 Reset(); 260 Reset();
215 } 261 }
216 262
217 } // namespace app_list 263 } // namespace app_list
OLDNEW
« ui/app_list/views/app_list_main_view.cc ('K') | « ui/app_list/views/start_page_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698