OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <string> | 5 #include <string> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "ash/session/session_state_delegate.h" | 8 #include "ash/session/session_state_delegate.h" |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "ash/shell/example_factory.h" | 10 #include "ash/shell/example_factory.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
48 EXAMPLES_WINDOW, | 48 EXAMPLES_WINDOW, |
49 LAST_TYPE, | 49 LAST_TYPE, |
50 }; | 50 }; |
51 | 51 |
52 explicit WindowTypeShelfItem(const std::string& id, Type type) | 52 explicit WindowTypeShelfItem(const std::string& id, Type type) |
53 : app_list::AppListItem(id), | 53 : app_list::AppListItem(id), |
54 type_(type) { | 54 type_(type) { |
55 std::string title(GetTitle(type)); | 55 std::string title(GetTitle(type)); |
56 SetIcon(GetIcon(type), false); | 56 SetIcon(GetIcon(type), false); |
57 SetName(title); | 57 SetName(title); |
58 } | 58 } |
James Cook
2014/10/27 23:45:34
Do you think this class should have ~WindowTypeShe
dcheng
2014/10/27 23:47:55
If the clang plugin doesn't enforce it, I would ar
| |
59 | 59 |
60 static gfx::ImageSkia GetIcon(Type type) { | 60 static gfx::ImageSkia GetIcon(Type type) { |
61 static const SkColor kColors[] = { | 61 static const SkColor kColors[] = { |
62 SK_ColorRED, | 62 SK_ColorRED, |
63 SK_ColorGREEN, | 63 SK_ColorGREEN, |
64 SK_ColorBLUE, | 64 SK_ColorBLUE, |
65 SK_ColorYELLOW, | 65 SK_ColorYELLOW, |
66 SK_ColorCYAN, | 66 SK_ColorCYAN, |
67 }; | 67 }; |
68 | 68 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 Shell::GetInstance()->delegate()->GetActiveBrowserContext(), | 131 Shell::GetInstance()->delegate()->GetActiveBrowserContext(), |
132 NULL); | 132 NULL); |
133 break; | 133 break; |
134 } | 134 } |
135 default: | 135 default: |
136 break; | 136 break; |
137 } | 137 } |
138 } | 138 } |
139 | 139 |
140 // AppListItem | 140 // AppListItem |
141 virtual void Activate(int event_flags) override { | 141 void Activate(int event_flags) override { ActivateItem(type_, event_flags); } |
142 ActivateItem(type_, event_flags); | |
143 } | |
144 | 142 |
145 private: | 143 private: |
146 Type type_; | 144 Type type_; |
147 | 145 |
148 DISALLOW_COPY_AND_ASSIGN(WindowTypeShelfItem); | 146 DISALLOW_COPY_AND_ASSIGN(WindowTypeShelfItem); |
149 }; | 147 }; |
150 | 148 |
151 // ExampleSearchResult is an app list search result. It provides what icon to | 149 // ExampleSearchResult is an app list search result. It provides what icon to |
152 // show, what should title and details text look like. It also carries the | 150 // show, what should title and details text look like. It also carries the |
153 // matching window launch type so that AppListViewDelegate knows how to open | 151 // matching window launch type so that AppListViewDelegate knows how to open |
(...skipping 28 matching lines...) Expand all Loading... | |
182 base::UTF8ToUTF16(WindowTypeShelfItem::GetDetails(type_)); | 180 base::UTF8ToUTF16(WindowTypeShelfItem::GetDetails(type_)); |
183 set_details(details); | 181 set_details(details); |
184 Tags details_tags; | 182 Tags details_tags; |
185 details_tags.push_back(Tag(Tag::DIM, 0, details.length())); | 183 details_tags.push_back(Tag(Tag::DIM, 0, details.length())); |
186 set_details_tags(details_tags); | 184 set_details_tags(details_tags); |
187 } | 185 } |
188 | 186 |
189 WindowTypeShelfItem::Type type() const { return type_; } | 187 WindowTypeShelfItem::Type type() const { return type_; } |
190 | 188 |
191 // app_list::SearchResult: | 189 // app_list::SearchResult: |
192 virtual scoped_ptr<SearchResult> Duplicate() override { | 190 scoped_ptr<SearchResult> Duplicate() override { |
193 return scoped_ptr<SearchResult>(); | 191 return scoped_ptr<SearchResult>(); |
194 } | 192 } |
195 | 193 |
196 private: | 194 private: |
197 WindowTypeShelfItem::Type type_; | 195 WindowTypeShelfItem::Type type_; |
198 | 196 |
199 DISALLOW_COPY_AND_ASSIGN(ExampleSearchResult); | 197 DISALLOW_COPY_AND_ASSIGN(ExampleSearchResult); |
200 }; | 198 }; |
201 | 199 |
202 class ExampleAppListViewDelegate : public app_list::AppListViewDelegate { | 200 class ExampleAppListViewDelegate : public app_list::AppListViewDelegate { |
(...skipping 30 matching lines...) Expand all Loading... | |
233 | 231 |
234 return gfx::ImageSkia(canvas.ExtractImageRep()); | 232 return gfx::ImageSkia(canvas.ExtractImageRep()); |
235 } | 233 } |
236 | 234 |
237 void DecorateSearchBox(app_list::SearchBoxModel* search_box_model) { | 235 void DecorateSearchBox(app_list::SearchBoxModel* search_box_model) { |
238 search_box_model->SetIcon(CreateSearchBoxIcon()); | 236 search_box_model->SetIcon(CreateSearchBoxIcon()); |
239 search_box_model->SetHintText(base::ASCIIToUTF16("Type to search...")); | 237 search_box_model->SetHintText(base::ASCIIToUTF16("Type to search...")); |
240 } | 238 } |
241 | 239 |
242 // Overridden from app_list::AppListViewDelegate: | 240 // Overridden from app_list::AppListViewDelegate: |
243 virtual bool ForceNativeDesktop() const override { | 241 bool ForceNativeDesktop() const override { return false; } |
244 return false; | |
245 } | |
246 | 242 |
247 virtual void SetProfileByPath(const base::FilePath& profile_path) override { | 243 void SetProfileByPath(const base::FilePath& profile_path) override { |
248 // Nothing needs to be done. | 244 // Nothing needs to be done. |
249 } | 245 } |
250 | 246 |
251 virtual const Users& GetUsers() const override { | 247 const Users& GetUsers() const override { return users_; } |
252 return users_; | |
253 } | |
254 | 248 |
255 virtual bool ShouldCenterWindow() const override { | 249 bool ShouldCenterWindow() const override { return false; } |
256 return false; | |
257 } | |
258 | 250 |
259 virtual app_list::AppListModel* GetModel() override { return model_.get(); } | 251 app_list::AppListModel* GetModel() override { return model_.get(); } |
260 | 252 |
261 virtual app_list::SpeechUIModel* GetSpeechUI() override { | 253 app_list::SpeechUIModel* GetSpeechUI() override { return &speech_ui_; } |
262 return &speech_ui_; | |
263 } | |
264 | 254 |
265 virtual void GetShortcutPathForApp( | 255 void GetShortcutPathForApp( |
266 const std::string& app_id, | 256 const std::string& app_id, |
267 const base::Callback<void(const base::FilePath&)>& callback) override { | 257 const base::Callback<void(const base::FilePath&)>& callback) override { |
268 callback.Run(base::FilePath()); | 258 callback.Run(base::FilePath()); |
269 } | 259 } |
270 | 260 |
271 virtual void OpenSearchResult(app_list::SearchResult* result, | 261 void OpenSearchResult(app_list::SearchResult* result, |
272 bool auto_launch, | 262 bool auto_launch, |
273 int event_flags) override { | 263 int event_flags) override { |
274 const ExampleSearchResult* example_result = | 264 const ExampleSearchResult* example_result = |
275 static_cast<const ExampleSearchResult*>(result); | 265 static_cast<const ExampleSearchResult*>(result); |
276 WindowTypeShelfItem::ActivateItem(example_result->type(), event_flags); | 266 WindowTypeShelfItem::ActivateItem(example_result->type(), event_flags); |
277 } | 267 } |
278 | 268 |
279 virtual void InvokeSearchResultAction(app_list::SearchResult* result, | 269 void InvokeSearchResultAction(app_list::SearchResult* result, |
280 int action_index, | 270 int action_index, |
281 int event_flags) override { | 271 int event_flags) override { |
282 NOTIMPLEMENTED(); | 272 NOTIMPLEMENTED(); |
283 } | 273 } |
284 | 274 |
285 virtual base::TimeDelta GetAutoLaunchTimeout() override { | 275 base::TimeDelta GetAutoLaunchTimeout() override { return base::TimeDelta(); } |
286 return base::TimeDelta(); | |
287 } | |
288 | 276 |
289 virtual void AutoLaunchCanceled() override { | 277 void AutoLaunchCanceled() override {} |
290 } | |
291 | 278 |
292 virtual void StartSearch() override { | 279 void StartSearch() override { |
293 base::string16 query; | 280 base::string16 query; |
294 base::TrimWhitespace(model_->search_box()->text(), base::TRIM_ALL, &query); | 281 base::TrimWhitespace(model_->search_box()->text(), base::TRIM_ALL, &query); |
295 query = base::i18n::ToLower(query); | 282 query = base::i18n::ToLower(query); |
296 | 283 |
297 model_->results()->DeleteAll(); | 284 model_->results()->DeleteAll(); |
298 if (query.empty()) | 285 if (query.empty()) |
299 return; | 286 return; |
300 | 287 |
301 for (int i = 0; i < static_cast<int>(WindowTypeShelfItem::LAST_TYPE); ++i) { | 288 for (int i = 0; i < static_cast<int>(WindowTypeShelfItem::LAST_TYPE); ++i) { |
302 WindowTypeShelfItem::Type type = | 289 WindowTypeShelfItem::Type type = |
303 static_cast<WindowTypeShelfItem::Type>(i); | 290 static_cast<WindowTypeShelfItem::Type>(i); |
304 | 291 |
305 base::string16 title = | 292 base::string16 title = |
306 base::UTF8ToUTF16(WindowTypeShelfItem::GetTitle(type)); | 293 base::UTF8ToUTF16(WindowTypeShelfItem::GetTitle(type)); |
307 if (base::i18n::StringSearchIgnoringCaseAndAccents( | 294 if (base::i18n::StringSearchIgnoringCaseAndAccents( |
308 query, title, NULL, NULL)) { | 295 query, title, NULL, NULL)) { |
309 model_->results()->Add(new ExampleSearchResult(type, query)); | 296 model_->results()->Add(new ExampleSearchResult(type, query)); |
310 } | 297 } |
311 } | 298 } |
312 } | 299 } |
313 | 300 |
314 virtual void StopSearch() override { | 301 void StopSearch() override { |
315 // Nothing needs to be done. | 302 // Nothing needs to be done. |
316 } | 303 } |
317 | 304 |
318 virtual void ViewInitialized() override { | 305 void ViewInitialized() override { |
319 // Nothing needs to be done. | 306 // Nothing needs to be done. |
320 } | 307 } |
321 | 308 |
322 virtual void Dismiss() override { | 309 void Dismiss() override { |
323 DCHECK(ash::Shell::HasInstance()); | 310 DCHECK(ash::Shell::HasInstance()); |
324 Shell::GetInstance()->DismissAppList(); | 311 Shell::GetInstance()->DismissAppList(); |
325 } | 312 } |
326 | 313 |
327 virtual void ViewClosing() override { | 314 void ViewClosing() override { |
328 // Nothing needs to be done. | 315 // Nothing needs to be done. |
329 } | 316 } |
330 | 317 |
331 virtual gfx::ImageSkia GetWindowIcon() override { | 318 gfx::ImageSkia GetWindowIcon() override { return gfx::ImageSkia(); } |
332 return gfx::ImageSkia(); | |
333 } | |
334 | 319 |
335 virtual void OpenSettings() override { | 320 void OpenSettings() override { |
336 // Nothing needs to be done. | 321 // Nothing needs to be done. |
337 } | 322 } |
338 | 323 |
339 virtual void OpenHelp() override { | 324 void OpenHelp() override { |
340 // Nothing needs to be done. | 325 // Nothing needs to be done. |
341 } | 326 } |
342 | 327 |
343 virtual void OpenFeedback() override { | 328 void OpenFeedback() override { |
344 // Nothing needs to be done. | 329 // Nothing needs to be done. |
345 } | 330 } |
346 | 331 |
347 virtual void ToggleSpeechRecognition() override { | 332 void ToggleSpeechRecognition() override { NOTIMPLEMENTED(); } |
348 NOTIMPLEMENTED(); | |
349 } | |
350 | 333 |
351 virtual void ShowForProfileByPath( | 334 void ShowForProfileByPath(const base::FilePath& profile_path) override { |
352 const base::FilePath& profile_path) override { | |
353 // Nothing needs to be done. | 335 // Nothing needs to be done. |
354 } | 336 } |
355 | 337 |
356 virtual views::View* CreateStartPageWebView(const gfx::Size& size) override { | 338 views::View* CreateStartPageWebView(const gfx::Size& size) override { |
357 return NULL; | 339 return NULL; |
358 } | 340 } |
359 | 341 |
360 virtual std::vector<views::View*> CreateCustomPageWebViews( | 342 std::vector<views::View*> CreateCustomPageWebViews( |
361 const gfx::Size& size) override { | 343 const gfx::Size& size) override { |
362 return std::vector<views::View*>(); | 344 return std::vector<views::View*>(); |
363 } | 345 } |
364 | 346 |
365 virtual bool IsSpeechRecognitionEnabled() override { | 347 bool IsSpeechRecognitionEnabled() override { return false; } |
366 return false; | |
367 } | |
368 | 348 |
369 scoped_ptr<app_list::AppListModel> model_; | 349 scoped_ptr<app_list::AppListModel> model_; |
370 app_list::SpeechUIModel speech_ui_; | 350 app_list::SpeechUIModel speech_ui_; |
371 Users users_; | 351 Users users_; |
372 | 352 |
373 DISALLOW_COPY_AND_ASSIGN(ExampleAppListViewDelegate); | 353 DISALLOW_COPY_AND_ASSIGN(ExampleAppListViewDelegate); |
374 }; | 354 }; |
375 | 355 |
376 } // namespace | 356 } // namespace |
377 | 357 |
378 app_list::AppListViewDelegate* CreateAppListViewDelegate() { | 358 app_list::AppListViewDelegate* CreateAppListViewDelegate() { |
379 return new ExampleAppListViewDelegate; | 359 return new ExampleAppListViewDelegate; |
380 } | 360 } |
381 | 361 |
382 } // namespace shell | 362 } // namespace shell |
383 } // namespace ash | 363 } // namespace ash |
OLD | NEW |