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

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

Issue 307333002: Add search results to 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_result_list_view.h"
13 #include "ui/app_list/views/tile_item_view.h" 14 #include "ui/app_list/views/tile_item_view.h"
14 #include "ui/gfx/canvas.h" 15 #include "ui/gfx/canvas.h"
15 #include "ui/views/controls/button/custom_button.h" 16 #include "ui/views/controls/button/custom_button.h"
16 #include "ui/views/controls/image_view.h" 17 #include "ui/views/controls/image_view.h"
17 #include "ui/views/controls/label.h" 18 #include "ui/views/controls/label.h"
18 #include "ui/views/layout/box_layout.h" 19 #include "ui/views/layout/box_layout.h"
19 20
20 namespace app_list { 21 namespace app_list {
21 22
22 namespace { 23 namespace {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 DISALLOW_COPY_AND_ASSIGN(BarPlaceholderButton); 70 DISALLOW_COPY_AND_ASSIGN(BarPlaceholderButton);
70 }; 71 };
71 72
72 } // namespace 73 } // namespace
73 74
74 StartPageView::StartPageView(AppListMainView* app_list_main_view, 75 StartPageView::StartPageView(AppListMainView* app_list_main_view,
75 AppListViewDelegate* view_delegate) 76 AppListViewDelegate* view_delegate)
76 : app_list_main_view_(app_list_main_view), 77 : app_list_main_view_(app_list_main_view),
77 model_(NULL), 78 model_(NULL),
78 view_delegate_(view_delegate), 79 view_delegate_(view_delegate),
80 results_view_(
81 new SearchResultListView(app_list_main_view, view_delegate)),
79 instant_container_(new views::View), 82 instant_container_(new views::View),
80 tiles_container_(new views::View) { 83 tiles_container_(new views::View),
81 SetLayoutManager(new views::BoxLayout( 84 show_state_(SHOW_START_PAGE) {
82 views::BoxLayout::kVertical, 0, kTopMargin, kInstantContainerSpacing));
83
84 // The view containing the start page WebContents and the BarPlaceholder. 85 // The view containing the start page WebContents and the BarPlaceholder.
85 AddChildView(instant_container_); 86 AddChildView(instant_container_);
86 views::BoxLayout* instant_layout_manager = new views::BoxLayout( 87 views::BoxLayout* instant_layout_manager = new views::BoxLayout(
87 views::BoxLayout::kVertical, 0, 0, kInstantContainerSpacing); 88 views::BoxLayout::kVertical, 0, 0, kInstantContainerSpacing);
89 instant_layout_manager->set_inside_border_insets(
90 gfx::Insets(kTopMargin, 0, kInstantContainerSpacing, 0));
88 instant_layout_manager->set_main_axis_alignment( 91 instant_layout_manager->set_main_axis_alignment(
89 views::BoxLayout::MAIN_AXIS_ALIGNMENT_END); 92 views::BoxLayout::MAIN_AXIS_ALIGNMENT_END);
90 instant_container_->SetLayoutManager(instant_layout_manager); 93 instant_container_->SetLayoutManager(instant_layout_manager);
91 94
92 views::View* web_view = view_delegate->CreateStartPageWebView( 95 views::View* web_view = view_delegate->CreateStartPageWebView(
93 gfx::Size(kWebViewWidth, kWebViewHeight)); 96 gfx::Size(kWebViewWidth, kWebViewHeight));
94 if (web_view) 97 if (web_view)
95 instant_container_->AddChildView(web_view); 98 instant_container_->AddChildView(web_view);
96 instant_container_->AddChildView(new BarPlaceholderButton(this)); 99 instant_container_->AddChildView(new BarPlaceholderButton(this));
97 100
101 // The view containing the search results.
102 AddChildView(results_view_);
103
98 // The view containing the start page tiles. 104 // The view containing the start page tiles.
99 AddChildView(tiles_container_); 105 AddChildView(tiles_container_);
100 views::BoxLayout* tiles_layout_manager = 106 views::BoxLayout* tiles_layout_manager =
101 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, kTileSpacing); 107 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, kTileSpacing);
102 tiles_layout_manager->set_main_axis_alignment( 108 tiles_layout_manager->set_main_axis_alignment(
103 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); 109 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER);
104 tiles_container_->SetLayoutManager(tiles_layout_manager); 110 tiles_container_->SetLayoutManager(tiles_layout_manager);
105 for (size_t i = 0; i < kNumStartPageTiles; ++i) { 111 for (size_t i = 0; i < kNumStartPageTiles; ++i) {
106 TileItemView* tile_item = new TileItemView(); 112 TileItemView* tile_item = new TileItemView();
107 tiles_container_->AddChildView(tile_item); 113 tiles_container_->AddChildView(tile_item);
108 tile_views_.push_back(tile_item); 114 tile_views_.push_back(tile_item);
109 } 115 }
110 116
111 SetModel(view_delegate_->GetModel()); 117 SetModel(view_delegate_->GetModel());
112 view_delegate_->AddObserver(this); 118 view_delegate_->AddObserver(this);
113 } 119 }
114 120
115 StartPageView::~StartPageView() { 121 StartPageView::~StartPageView() {
116 view_delegate_->RemoveObserver(this); 122 view_delegate_->RemoveObserver(this);
117 if (model_) 123 if (model_)
118 model_->RemoveObserver(this); 124 model_->RemoveObserver(this);
119 } 125 }
120 126
121 void StartPageView::SetModel(AppListModel* model) { 127 void StartPageView::SetModel(AppListModel* model) {
122 DCHECK(model); 128 DCHECK(model);
123 if (model_) 129 if (model_)
124 model_->RemoveObserver(this); 130 model_->RemoveObserver(this);
125 model_ = model; 131 model_ = model;
126 model_->AddObserver(this); 132 model_->AddObserver(this);
133 results_view_->SetResults(model_->results());
127 Reset(); 134 Reset();
128 } 135 }
129 136
130 void StartPageView::Reset() { 137 void StartPageView::Reset() {
131 instant_container_->SetVisible(true); 138 SetShowState(SHOW_START_PAGE);
132 if (!model_ || !model_->top_level_item_list()) 139 if (!model_ || !model_->top_level_item_list())
133 return; 140 return;
134 141
135 for (size_t i = 0; i < kNumStartPageTiles; ++i) { 142 for (size_t i = 0; i < kNumStartPageTiles; ++i) {
136 AppListItem* item = NULL; 143 AppListItem* item = NULL;
137 if (i < model_->top_level_item_list()->item_count()) 144 if (i < model_->top_level_item_list()->item_count())
138 item = model_->top_level_item_list()->item_at(i); 145 item = model_->top_level_item_list()->item_at(i);
139 tile_views_[i]->SetAppListItem(item); 146 tile_views_[i]->SetAppListItem(item);
140 } 147 }
148 }
141 149
142 Layout(); 150 void StartPageView::ShowSearchResults() {
151 SetShowState(SHOW_SEARCH_RESULTS);
152 }
153
154 void StartPageView::SetShowState(ShowState show_state) {
155 if (show_state_ == show_state)
tapted 2014/06/12 05:43:28 Note I think this will early exit when Reset() is
calamity 2014/06/12 07:09:37 Yep. That is completely necessary. Moved that up.
156 return;
157
158 show_state_ = show_state;
159
160 results_view_->UpdateAutoLaunchState();
161 if (show_state == SHOW_SEARCH_RESULTS)
162 results_view_->SetSelectedIndex(0);
163
164 instant_container_->SetVisible(show_state == SHOW_START_PAGE);
165 results_view_->SetVisible(show_state == SHOW_SEARCH_RESULTS);
166 }
167
168 bool StartPageView::IsShowingSearchResults() const {
169 return show_state_ == SHOW_SEARCH_RESULTS;
170 }
171
172 bool StartPageView::OnKeyPressed(const ui::KeyEvent& event) {
173 if (show_state_ == SHOW_SEARCH_RESULTS)
174 return results_view_->OnKeyPressed(event);
175
176 return false;
177 }
178
179 void StartPageView::Layout() {
180 // Instant and search results take up the height of the instant container.
181 gfx::Rect bounds(GetContentsBounds());
182 bounds.set_height(instant_container_->GetHeightForWidth(bounds.width()));
183 instant_container_->SetBoundsRect(bounds);
184 results_view_->SetBoundsRect(bounds);
185
186 // Tiles begin where the instant container ends.
187 bounds.set_y(bounds.bottom());
188 bounds.set_height(tiles_container_->GetHeightForWidth(bounds.width()));
189 tiles_container_->SetBoundsRect(bounds);
143 } 190 }
144 191
145 void StartPageView::ButtonPressed(views::Button* sender, 192 void StartPageView::ButtonPressed(views::Button* sender,
146 const ui::Event& event) { 193 const ui::Event& event) {
147 app_list_main_view_->OnStartPageSearchButtonPressed(); 194 app_list_main_view_->OnStartPageSearchButtonPressed();
148 instant_container_->SetVisible(false);
149 } 195 }
150 196
151 void StartPageView::OnProfilesChanged() { 197 void StartPageView::OnProfilesChanged() {
152 SetModel(view_delegate_->GetModel()); 198 SetModel(view_delegate_->GetModel());
153 } 199 }
154 200
155 void StartPageView::OnAppListModelStatusChanged() { 201 void StartPageView::OnAppListModelStatusChanged() {
156 Reset(); 202 Reset();
157 } 203 }
158 204
159 void StartPageView::OnAppListItemAdded(AppListItem* item) { 205 void StartPageView::OnAppListItemAdded(AppListItem* item) {
160 Reset(); 206 Reset();
161 } 207 }
162 208
163 void StartPageView::OnAppListItemDeleted() { 209 void StartPageView::OnAppListItemDeleted() {
164 Reset(); 210 Reset();
165 } 211 }
166 212
167 void StartPageView::OnAppListItemUpdated(AppListItem* item) { 213 void StartPageView::OnAppListItemUpdated(AppListItem* item) {
168 Reset(); 214 Reset();
169 } 215 }
170 216
171 } // namespace app_list 217 } // namespace app_list
OLDNEW
« ui/app_list/views/app_list_view_unittest.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