OLD | NEW |
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. |
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 int kDummySearchBoxBorderWidth = 1; |
| 39 const int kDummySearchBoxBorderBottomWidth = 2; |
| 40 const int kDummySearchBoxBorderCornerRadius = 2; |
33 | 41 |
| 42 // Tile container constants. |
34 const size_t kNumStartPageTiles = 5; | 43 const size_t kNumStartPageTiles = 5; |
35 const int kTileSpacing = 10; | 44 const int kTileSpacing = 10; |
36 | 45 |
37 // A button that is the placeholder for the search bar in the start page view. | 46 // A background that paints a solid white rounded rect with a thin grey border. |
38 class BarPlaceholderButton : public views::CustomButton { | 47 class DummySearchBoxBackground : public views::Background { |
39 public: | 48 public: |
40 explicit BarPlaceholderButton(views::ButtonListener* listener) | 49 DummySearchBoxBackground() {} |
41 : views::CustomButton(listener) {} | 50 virtual ~DummySearchBoxBackground() {} |
42 | 51 |
43 virtual ~BarPlaceholderButton() {} | 52 private: |
| 53 // views::Background overrides: |
| 54 virtual void Paint(gfx::Canvas* canvas, views::View* view) const OVERRIDE { |
| 55 gfx::Rect bounds = view->GetContentsBounds(); |
| 56 |
| 57 SkPaint paint; |
| 58 paint.setFlags(SkPaint::kAntiAlias_Flag); |
| 59 paint.setColor(kStartPageBorderColor); |
| 60 canvas->DrawRoundRect(bounds, kDummySearchBoxBorderCornerRadius, paint); |
| 61 bounds.Inset(kDummySearchBoxBorderWidth, |
| 62 kDummySearchBoxBorderWidth, |
| 63 kDummySearchBoxBorderWidth, |
| 64 kDummySearchBoxBorderBottomWidth); |
| 65 paint.setColor(SK_ColorWHITE); |
| 66 canvas->DrawRoundRect(bounds, kDummySearchBoxBorderCornerRadius, paint); |
| 67 } |
| 68 |
| 69 DISALLOW_COPY_AND_ASSIGN(DummySearchBoxBackground); |
| 70 }; |
| 71 |
| 72 // A placeholder search box which is sized to fit within the start page view. |
| 73 class DummySearchBoxView : public SearchBoxView { |
| 74 public: |
| 75 DummySearchBoxView(SearchBoxViewDelegate* delegate, |
| 76 AppListViewDelegate* view_delegate) |
| 77 : SearchBoxView(delegate, view_delegate) { |
| 78 set_background(new DummySearchBoxBackground()); |
| 79 } |
| 80 |
| 81 virtual ~DummySearchBoxView() {} |
44 | 82 |
45 // Overridden from views::View: | 83 // Overridden from views::View: |
46 virtual gfx::Size GetPreferredSize() const OVERRIDE { | 84 virtual gfx::Size GetPreferredSize() const OVERRIDE { |
47 return gfx::Size(kBarPlaceholderWidth, kBarPlaceholderHeight); | 85 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 } | 86 } |
55 | 87 |
56 private: | 88 private: |
57 // Paints a rectangular button. | 89 DISALLOW_COPY_AND_ASSIGN(DummySearchBoxView); |
58 void PaintButton(gfx::Canvas* canvas, SkColor base_color) { | |
59 gfx::Rect rect(GetContentsBounds()); | |
60 rect.ClampToCenteredSize( | |
61 gfx::Size(kBarPlaceholderWidth, kBarPlaceholderHeight)); | |
62 | |
63 SkPaint paint; | |
64 paint.setAntiAlias(true); | |
65 paint.setStyle(SkPaint::kFill_Style); | |
66 paint.setColor(base_color); | |
67 canvas->DrawRect(rect, paint); | |
68 } | |
69 | |
70 DISALLOW_COPY_AND_ASSIGN(BarPlaceholderButton); | |
71 }; | 90 }; |
72 | 91 |
73 } // namespace | 92 } // namespace |
74 | 93 |
75 StartPageView::StartPageView(AppListMainView* app_list_main_view, | 94 StartPageView::StartPageView(AppListMainView* app_list_main_view, |
76 AppListViewDelegate* view_delegate) | 95 AppListViewDelegate* view_delegate) |
77 : app_list_main_view_(app_list_main_view), | 96 : app_list_main_view_(app_list_main_view), |
78 model_(NULL), | 97 model_(NULL), |
79 view_delegate_(view_delegate), | 98 view_delegate_(view_delegate), |
| 99 search_box_view_(new DummySearchBoxView(this, view_delegate_)), |
80 results_view_( | 100 results_view_( |
81 new SearchResultListView(app_list_main_view, view_delegate)), | 101 new SearchResultListView(app_list_main_view, view_delegate)), |
82 instant_container_(new views::View), | 102 instant_container_(new views::View), |
83 tiles_container_(new views::View), | 103 tiles_container_(new views::View), |
84 show_state_(SHOW_START_PAGE) { | 104 show_state_(SHOW_START_PAGE) { |
85 // The view containing the start page WebContents and the BarPlaceholder. | 105 // The view containing the start page WebContents and DummySearchBoxView. |
| 106 InitInstantContainer(); |
86 AddChildView(instant_container_); | 107 AddChildView(instant_container_); |
| 108 |
| 109 // The view containing the search results. |
| 110 AddChildView(results_view_); |
| 111 |
| 112 // The view containing the start page tiles. |
| 113 InitTilesContainer(); |
| 114 AddChildView(tiles_container_); |
| 115 |
| 116 SetModel(view_delegate_->GetModel()); |
| 117 view_delegate_->AddObserver(this); |
| 118 } |
| 119 |
| 120 StartPageView::~StartPageView() { |
| 121 view_delegate_->RemoveObserver(this); |
| 122 if (model_) |
| 123 model_->RemoveObserver(this); |
| 124 } |
| 125 |
| 126 void StartPageView::InitInstantContainer() { |
87 views::BoxLayout* instant_layout_manager = new views::BoxLayout( | 127 views::BoxLayout* instant_layout_manager = new views::BoxLayout( |
88 views::BoxLayout::kVertical, 0, 0, kInstantContainerSpacing); | 128 views::BoxLayout::kVertical, 0, 0, kInstantContainerSpacing); |
89 instant_layout_manager->set_inside_border_insets( | 129 instant_layout_manager->set_inside_border_insets( |
90 gfx::Insets(kTopMargin, 0, kInstantContainerSpacing, 0)); | 130 gfx::Insets(kTopMargin, 0, kInstantContainerSpacing, 0)); |
91 instant_layout_manager->set_main_axis_alignment( | 131 instant_layout_manager->set_main_axis_alignment( |
92 views::BoxLayout::MAIN_AXIS_ALIGNMENT_END); | 132 views::BoxLayout::MAIN_AXIS_ALIGNMENT_END); |
93 instant_container_->SetLayoutManager(instant_layout_manager); | 133 instant_container_->SetLayoutManager(instant_layout_manager); |
94 | 134 |
95 views::View* web_view = view_delegate->CreateStartPageWebView( | 135 views::View* web_view = view_delegate_->CreateStartPageWebView( |
96 gfx::Size(kWebViewWidth, kWebViewHeight)); | 136 gfx::Size(kWebViewWidth, kWebViewHeight)); |
97 if (web_view) | 137 if (web_view) |
98 instant_container_->AddChildView(web_view); | 138 instant_container_->AddChildView(web_view); |
99 instant_container_->AddChildView(new BarPlaceholderButton(this)); | |
100 | 139 |
101 // The view containing the search results. | 140 // TODO(calamity): This container is needed to horizontally center the search |
102 AddChildView(results_view_); | 141 // box view. Remove this container once BoxLayout supports CrossAxisAlignment. |
| 142 views::View* search_box_container = new views::View(); |
| 143 views::BoxLayout* layout_manager = |
| 144 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0); |
| 145 layout_manager->set_main_axis_alignment( |
| 146 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); |
| 147 search_box_container->SetLayoutManager(layout_manager); |
| 148 search_box_container->AddChildView(search_box_view_); |
103 | 149 |
104 // The view containing the start page tiles. | 150 instant_container_->AddChildView(search_box_container); |
105 AddChildView(tiles_container_); | 151 } |
| 152 |
| 153 void StartPageView::InitTilesContainer() { |
106 views::BoxLayout* tiles_layout_manager = | 154 views::BoxLayout* tiles_layout_manager = |
107 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, kTileSpacing); | 155 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, kTileSpacing); |
108 tiles_layout_manager->set_main_axis_alignment( | 156 tiles_layout_manager->set_main_axis_alignment( |
109 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); | 157 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); |
110 tiles_container_->SetLayoutManager(tiles_layout_manager); | 158 tiles_container_->SetLayoutManager(tiles_layout_manager); |
111 for (size_t i = 0; i < kNumStartPageTiles; ++i) { | 159 for (size_t i = 0; i < kNumStartPageTiles; ++i) { |
112 TileItemView* tile_item = new TileItemView(); | 160 TileItemView* tile_item = new TileItemView(); |
113 tiles_container_->AddChildView(tile_item); | 161 tiles_container_->AddChildView(tile_item); |
114 tile_views_.push_back(tile_item); | 162 tile_views_.push_back(tile_item); |
115 } | 163 } |
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 } | 164 } |
126 | 165 |
127 void StartPageView::SetModel(AppListModel* model) { | 166 void StartPageView::SetModel(AppListModel* model) { |
128 DCHECK(model); | 167 DCHECK(model); |
129 if (model_) | 168 if (model_) |
130 model_->RemoveObserver(this); | 169 model_->RemoveObserver(this); |
131 model_ = model; | 170 model_ = model; |
132 model_->AddObserver(this); | 171 model_->AddObserver(this); |
133 results_view_->SetResults(model_->results()); | 172 results_view_->SetResults(model_->results()); |
134 Reset(); | 173 Reset(); |
(...skipping 13 matching lines...) Expand all Loading... |
148 } | 187 } |
149 | 188 |
150 void StartPageView::ShowSearchResults() { | 189 void StartPageView::ShowSearchResults() { |
151 SetShowState(SHOW_SEARCH_RESULTS); | 190 SetShowState(SHOW_SEARCH_RESULTS); |
152 } | 191 } |
153 | 192 |
154 void StartPageView::SetShowState(ShowState show_state) { | 193 void StartPageView::SetShowState(ShowState show_state) { |
155 instant_container_->SetVisible(show_state == SHOW_START_PAGE); | 194 instant_container_->SetVisible(show_state == SHOW_START_PAGE); |
156 results_view_->SetVisible(show_state == SHOW_SEARCH_RESULTS); | 195 results_view_->SetVisible(show_state == SHOW_SEARCH_RESULTS); |
157 | 196 |
| 197 if (show_state == SHOW_START_PAGE) |
| 198 search_box_view_->search_box()->RequestFocus(); |
| 199 |
158 if (show_state_ == show_state) | 200 if (show_state_ == show_state) |
159 return; | 201 return; |
160 | 202 |
161 show_state_ = show_state; | 203 show_state_ = show_state; |
162 | 204 |
163 results_view_->UpdateAutoLaunchState(); | 205 results_view_->UpdateAutoLaunchState(); |
164 if (show_state == SHOW_SEARCH_RESULTS) | 206 if (show_state == SHOW_SEARCH_RESULTS) |
165 results_view_->SetSelectedIndex(0); | 207 results_view_->SetSelectedIndex(0); |
166 } | 208 } |
167 | 209 |
(...skipping 14 matching lines...) Expand all Loading... |
182 bounds.set_height(instant_container_->GetHeightForWidth(bounds.width())); | 224 bounds.set_height(instant_container_->GetHeightForWidth(bounds.width())); |
183 instant_container_->SetBoundsRect(bounds); | 225 instant_container_->SetBoundsRect(bounds); |
184 results_view_->SetBoundsRect(bounds); | 226 results_view_->SetBoundsRect(bounds); |
185 | 227 |
186 // Tiles begin where the instant container ends. | 228 // Tiles begin where the instant container ends. |
187 bounds.set_y(bounds.bottom()); | 229 bounds.set_y(bounds.bottom()); |
188 bounds.set_height(tiles_container_->GetHeightForWidth(bounds.width())); | 230 bounds.set_height(tiles_container_->GetHeightForWidth(bounds.width())); |
189 tiles_container_->SetBoundsRect(bounds); | 231 tiles_container_->SetBoundsRect(bounds); |
190 } | 232 } |
191 | 233 |
192 void StartPageView::ButtonPressed(views::Button* sender, | 234 void StartPageView::QueryChanged(SearchBoxView* sender) { |
193 const ui::Event& event) { | 235 // Forward the search terms on to the real search box and clear the dummy |
194 app_list_main_view_->OnStartPageSearchButtonPressed(); | 236 // search box. |
| 237 app_list_main_view_->OnStartPageSearchTextfieldChanged( |
| 238 sender->search_box()->text()); |
| 239 sender->search_box()->SetText(base::string16()); |
195 } | 240 } |
196 | 241 |
197 void StartPageView::OnProfilesChanged() { | 242 void StartPageView::OnProfilesChanged() { |
198 SetModel(view_delegate_->GetModel()); | 243 SetModel(view_delegate_->GetModel()); |
199 } | 244 } |
200 | 245 |
201 void StartPageView::OnAppListModelStatusChanged() { | 246 void StartPageView::OnAppListModelStatusChanged() { |
202 Reset(); | 247 Reset(); |
203 } | 248 } |
204 | 249 |
205 void StartPageView::OnAppListItemAdded(AppListItem* item) { | 250 void StartPageView::OnAppListItemAdded(AppListItem* item) { |
206 Reset(); | 251 Reset(); |
207 } | 252 } |
208 | 253 |
209 void StartPageView::OnAppListItemDeleted() { | 254 void StartPageView::OnAppListItemDeleted() { |
210 Reset(); | 255 Reset(); |
211 } | 256 } |
212 | 257 |
213 void StartPageView::OnAppListItemUpdated(AppListItem* item) { | 258 void StartPageView::OnAppListItemUpdated(AppListItem* item) { |
214 Reset(); | 259 Reset(); |
215 } | 260 } |
216 | 261 |
217 } // namespace app_list | 262 } // namespace app_list |
OLD | NEW |