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 "content/public/browser/web_contents.h" | 8 #include "content/public/browser/web_contents.h" |
9 #include "ui/app_list/app_list_constants.h" | 9 #include "ui/app_list/app_list_constants.h" |
10 #include "ui/app_list/app_list_item.h" | 10 #include "ui/app_list/app_list_item.h" |
11 #include "ui/app_list/app_list_model.h" | 11 #include "ui/app_list/app_list_model.h" |
12 #include "ui/app_list/app_list_view_delegate.h" | 12 #include "ui/app_list/app_list_view_delegate.h" |
13 #include "ui/app_list/views/app_list_main_view.h" | 13 #include "ui/app_list/views/app_list_main_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/controls/button/custom_button.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" |
19 #include "ui/views/controls/webview/webview.h" | 20 #include "ui/views/controls/webview/webview.h" |
20 #include "ui/views/layout/box_layout.h" | 21 #include "ui/views/layout/box_layout.h" |
21 | 22 |
22 namespace app_list { | 23 namespace app_list { |
23 | 24 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
71 DISALLOW_COPY_AND_ASSIGN(BarPlaceholderButton); | 72 DISALLOW_COPY_AND_ASSIGN(BarPlaceholderButton); |
72 }; | 73 }; |
73 | 74 |
74 } // namespace | 75 } // namespace |
75 | 76 |
76 StartPageView::StartPageView(AppListMainView* app_list_main_view, | 77 StartPageView::StartPageView(AppListMainView* app_list_main_view, |
77 AppListViewDelegate* view_delegate) | 78 AppListViewDelegate* view_delegate) |
78 : app_list_main_view_(app_list_main_view), | 79 : app_list_main_view_(app_list_main_view), |
79 model_(NULL), | 80 model_(NULL), |
80 view_delegate_(view_delegate), | 81 view_delegate_(view_delegate), |
82 results_view_( | |
83 new SearchResultListView(app_list_main_view, view_delegate)), | |
81 instant_container_(new views::View), | 84 instant_container_(new views::View), |
82 tiles_container_(new views::View) { | 85 tiles_container_(new views::View) { |
83 SetLayoutManager(new views::BoxLayout( | |
84 views::BoxLayout::kVertical, 0, kTopMargin, kInstantContainerSpacing)); | |
85 | |
86 // The view containing the start page WebContents and the BarPlaceholder. | 86 // The view containing the start page WebContents and the BarPlaceholder. |
87 AddChildView(instant_container_); | 87 AddChildView(instant_container_); |
88 views::BoxLayout* instant_layout_manager = new views::BoxLayout( | 88 views::BoxLayout* instant_layout_manager = new views::BoxLayout( |
89 views::BoxLayout::kVertical, 0, 0, kInstantContainerSpacing); | 89 views::BoxLayout::kVertical, 0, 0, kInstantContainerSpacing); |
90 instant_layout_manager->set_inside_border_insets( | |
91 gfx::Insets(kTopMargin, 0, kInstantContainerSpacing, 0)); | |
90 instant_layout_manager->set_main_axis_alignment( | 92 instant_layout_manager->set_main_axis_alignment( |
91 views::BoxLayout::MAIN_AXIS_ALIGNMENT_END); | 93 views::BoxLayout::MAIN_AXIS_ALIGNMENT_END); |
92 instant_container_->SetLayoutManager(instant_layout_manager); | 94 instant_container_->SetLayoutManager(instant_layout_manager); |
93 | 95 |
94 content::WebContents* start_page_web_contents = | 96 content::WebContents* start_page_web_contents = |
95 view_delegate->GetStartPageContents(); | 97 view_delegate->GetStartPageContents(); |
96 views::WebView* web_view = new views::WebView( | 98 views::WebView* web_view = new views::WebView( |
97 start_page_web_contents ? start_page_web_contents->GetBrowserContext() | 99 start_page_web_contents ? start_page_web_contents->GetBrowserContext() |
98 : NULL); | 100 : NULL); |
99 web_view->SetPreferredSize(gfx::Size(kWebViewWidth, kWebViewHeight)); | 101 web_view->SetPreferredSize(gfx::Size(kWebViewWidth, kWebViewHeight)); |
100 web_view->SetWebContents(start_page_web_contents); | 102 web_view->SetWebContents(start_page_web_contents); |
101 | 103 |
102 instant_container_->AddChildView(web_view); | 104 instant_container_->AddChildView(web_view); |
103 instant_container_->AddChildView(new BarPlaceholderButton(this)); | 105 instant_container_->AddChildView(new BarPlaceholderButton(this)); |
104 | 106 |
107 // The view containing the search results. | |
108 AddChildView(results_view_); | |
109 | |
105 // The view containing the start page tiles. | 110 // The view containing the start page tiles. |
106 AddChildView(tiles_container_); | 111 AddChildView(tiles_container_); |
107 views::BoxLayout* tiles_layout_manager = | 112 views::BoxLayout* tiles_layout_manager = |
108 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, kTileSpacing); | 113 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, kTileSpacing); |
109 tiles_layout_manager->set_main_axis_alignment( | 114 tiles_layout_manager->set_main_axis_alignment( |
110 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); | 115 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); |
111 tiles_container_->SetLayoutManager(tiles_layout_manager); | 116 tiles_container_->SetLayoutManager(tiles_layout_manager); |
112 for (size_t i = 0; i < kNumStartPageTiles; ++i) { | 117 for (size_t i = 0; i < kNumStartPageTiles; ++i) { |
113 TileItemView* tile_item = new TileItemView(); | 118 TileItemView* tile_item = new TileItemView(); |
114 tiles_container_->AddChildView(tile_item); | 119 tiles_container_->AddChildView(tile_item); |
115 tile_views_.push_back(tile_item); | 120 tile_views_.push_back(tile_item); |
116 } | 121 } |
117 | 122 |
118 SetModel(view_delegate_->GetModel()); | 123 SetModel(view_delegate_->GetModel()); |
119 view_delegate_->AddObserver(this); | 124 view_delegate_->AddObserver(this); |
120 } | 125 } |
121 | 126 |
122 StartPageView::~StartPageView() { | 127 StartPageView::~StartPageView() { |
123 view_delegate_->RemoveObserver(this); | 128 view_delegate_->RemoveObserver(this); |
124 } | 129 } |
125 | 130 |
126 void StartPageView::SetModel(AppListModel* model) { | 131 void StartPageView::SetModel(AppListModel* model) { |
127 DCHECK(model); | 132 DCHECK(model); |
128 if (model_) | 133 if (model_) |
129 model_->RemoveObserver(this); | 134 model_->RemoveObserver(this); |
130 model_ = model; | 135 model_ = model; |
131 model_->AddObserver(this); | 136 model_->AddObserver(this); |
137 results_view_->SetResults(model_->results()); | |
132 Reset(); | 138 Reset(); |
133 } | 139 } |
134 | 140 |
135 void StartPageView::Reset() { | 141 void StartPageView::Reset() { |
136 instant_container_->SetVisible(true); | 142 instant_container_->SetVisible(true); |
143 results_view_->SetVisible(false); | |
137 if (!model_ || !model_->top_level_item_list()) | 144 if (!model_ || !model_->top_level_item_list()) |
138 return; | 145 return; |
139 | 146 |
140 for (size_t i = 0; i < kNumStartPageTiles; ++i) { | 147 for (size_t i = 0; i < kNumStartPageTiles; ++i) { |
141 AppListItem* item = NULL; | 148 AppListItem* item = NULL; |
142 if (i < model_->top_level_item_list()->item_count()) | 149 if (i < model_->top_level_item_list()->item_count()) |
143 item = model_->top_level_item_list()->item_at(i); | 150 item = model_->top_level_item_list()->item_at(i); |
144 tile_views_[i]->SetAppListItem(item); | 151 tile_views_[i]->SetAppListItem(item); |
145 } | 152 } |
153 } | |
146 | 154 |
147 Layout(); | 155 void StartPageView::ShowSearchResults() { |
156 instant_container_->SetVisible(false); | |
157 results_view_->SetVisible(true); | |
158 results_view_->SetSelectedIndex(0); | |
159 results_view_->UpdateAutoLaunchState(); | |
160 } | |
161 | |
162 bool StartPageView::OnKeyPressed(const ui::KeyEvent& event) { | |
163 if (results_view_->visible()) | |
164 return results_view_->OnKeyPressed(event); | |
tapted
2014/06/04 06:12:43
this seems a bit odd here and might have accessibi
calamity
2014/06/12 05:16:56
The SearchResultListView sends accessibility event
| |
165 | |
166 return false; | |
167 } | |
168 | |
169 void StartPageView::Layout() { | |
170 // Instant and search results take up the height of the instant container. | |
171 gfx::Rect bounds(GetContentsBounds()); | |
172 bounds.set_height(instant_container_->GetHeightForWidth(bounds.width())); | |
173 instant_container_->SetBoundsRect(bounds); | |
174 results_view_->SetBoundsRect(bounds); | |
175 | |
176 // Tiles begin where the instant container ends. | |
177 bounds.set_y(bounds.bottom()); | |
178 bounds.set_height(tiles_container_->GetHeightForWidth(bounds.width())); | |
179 tiles_container_->SetBoundsRect(bounds); | |
148 } | 180 } |
149 | 181 |
150 void StartPageView::ButtonPressed(views::Button* sender, | 182 void StartPageView::ButtonPressed(views::Button* sender, |
151 const ui::Event& event) { | 183 const ui::Event& event) { |
152 app_list_main_view_->OnStartPageSearchButtonPressed(); | 184 app_list_main_view_->OnStartPageSearchButtonPressed(); |
153 instant_container_->SetVisible(false); | 185 instant_container_->SetVisible(false); |
154 } | 186 } |
155 | 187 |
156 void StartPageView::OnProfilesChanged() { | 188 void StartPageView::OnProfilesChanged() { |
157 SetModel(view_delegate_->GetModel()); | 189 SetModel(view_delegate_->GetModel()); |
158 } | 190 } |
159 | 191 |
160 void StartPageView::OnAppListModelStatusChanged() { | 192 void StartPageView::OnAppListModelStatusChanged() { |
161 Reset(); | 193 Reset(); |
162 } | 194 } |
163 | 195 |
164 void StartPageView::OnAppListItemAdded(AppListItem* item) { | 196 void StartPageView::OnAppListItemAdded(AppListItem* item) { |
165 Reset(); | 197 Reset(); |
166 } | 198 } |
167 | 199 |
168 void StartPageView::OnAppListItemDeleted() { | 200 void StartPageView::OnAppListItemDeleted() { |
169 Reset(); | 201 Reset(); |
170 } | 202 } |
171 | 203 |
172 void StartPageView::OnAppListItemUpdated(AppListItem* item) { | 204 void StartPageView::OnAppListItemUpdated(AppListItem* item) { |
173 Reset(); | 205 Reset(); |
174 } | 206 } |
175 | 207 |
176 } // namespace app_list | 208 } // namespace app_list |
OLD | NEW |