OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/bind.h" |
| 6 #include "base/command_line.h" |
| 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/run_loop.h" |
| 9 #include "content/public/browser/web_contents.h" |
| 10 #include "content/public/common/content_switches.h" |
| 11 #include "grit/ui_resources.h" |
| 12 #include "ui/app_list/pagination_model.h" |
| 13 #include "ui/app_list/test/app_list_test_model.h" |
| 14 #include "ui/app_list/test/app_list_test_view_delegate.h" |
| 15 #include "ui/app_list/views/app_list_view.h" |
| 16 #include "ui/base/resource/resource_bundle.h" |
| 17 #include "ui/views/examples/content_client/examples_main.h" |
| 18 |
| 19 namespace { |
| 20 |
| 21 class AppListDemoService; |
| 22 |
| 23 // Number of dummy apps to populate in the app list. |
| 24 const int kInitialItems = 20; |
| 25 |
| 26 // Extends the test AppListViewDelegate to quit the run loop when the launcher |
| 27 // window is closed, and to close the window if it is simply dismissed. |
| 28 class DemoAppListViewDelegate : public app_list::test::AppListTestViewDelegate { |
| 29 public: |
| 30 explicit DemoAppListViewDelegate(content::BrowserContext* browser_context) |
| 31 : view_(NULL), browser_context_(browser_context) {} |
| 32 virtual ~DemoAppListViewDelegate() {} |
| 33 |
| 34 app_list::AppListView* InitView(gfx::NativeView window_context); |
| 35 |
| 36 // Overridden from AppListViewDelegate: |
| 37 virtual void Dismiss() OVERRIDE; |
| 38 virtual void ViewClosing() OVERRIDE; |
| 39 virtual content::WebContents* GetStartPageContents(); |
| 40 |
| 41 private: |
| 42 app_list::PaginationModel pagination_model_; |
| 43 app_list::AppListView* view_; // Weak. Owns this. |
| 44 content::BrowserContext* browser_context_; |
| 45 |
| 46 DISALLOW_COPY_AND_ASSIGN(DemoAppListViewDelegate); |
| 47 }; |
| 48 |
| 49 app_list::AppListView* DemoAppListViewDelegate::InitView( |
| 50 gfx::NativeView window_context) { |
| 51 view_ = new app_list::AppListView(this); |
| 52 view_->InitAsBubbleAtFixedLocation(window_context, |
| 53 &pagination_model_, |
| 54 gfx::Point(300, 300), |
| 55 views::BubbleBorder::FLOAT, |
| 56 false /* border_accepts_events */); |
| 57 |
| 58 // Populate some apps. |
| 59 GetTestModel()->PopulateApps(kInitialItems); |
| 60 app_list::AppListItemList* item_list = GetTestModel()->top_level_item_list(); |
| 61 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 62 gfx::Image test_image = rb.GetImageNamed(IDR_DEFAULT_FAVICON_32); |
| 63 for (size_t i = 0; i < item_list->item_count(); ++i) { |
| 64 app_list::AppListItem* item = item_list->item_at(i); |
| 65 item->SetIcon(*test_image.ToImageSkia(), i & 1); |
| 66 } |
| 67 return view_; |
| 68 } |
| 69 |
| 70 void DemoAppListViewDelegate::Dismiss() { |
| 71 view_->GetWidget()->Close(); |
| 72 } |
| 73 |
| 74 void DemoAppListViewDelegate::ViewClosing() { |
| 75 view_ = NULL; |
| 76 base::MessageLoopForUI::current()->Quit(); |
| 77 } |
| 78 |
| 79 content::WebContents* DemoAppListViewDelegate::GetStartPageContents() { |
| 80 // TODO(tapted): Implement this properly. For now, we need a dependency on |
| 81 // content to force a particular link order in shared library builds. Without |
| 82 // this, sandbox::InitLibcUrandomOverrides() will fail because it can't find |
| 83 // the symbol for fopen, when the linker places libc before libcontent in the |
| 84 // link order. |
| 85 return content::WebContents::Create( |
| 86 content::WebContents::CreateParams(browser_context_)); |
| 87 } |
| 88 |
| 89 void ShowAppList(content::BrowserContext* browser_context, |
| 90 gfx::NativeView window_context) { |
| 91 DemoAppListViewDelegate* delegate = |
| 92 new DemoAppListViewDelegate(browser_context); |
| 93 app_list::AppListView* view = delegate->InitView(window_context); |
| 94 view->GetWidget()->Show(); |
| 95 view->GetWidget()->Activate(); |
| 96 } |
| 97 |
| 98 } // namespace |
| 99 |
| 100 #if defined(OS_WIN) |
| 101 int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t*, int) { |
| 102 views::examples::ExamplesMainParams params(instance); |
| 103 #else |
| 104 int main(int argc, const char** argv) { |
| 105 views::examples::ExamplesMainParams params(argc, argv); |
| 106 #endif |
| 107 |
| 108 params.set_task(base::Bind(&ShowAppList)); |
| 109 return params.RunMain(); |
| 110 } |
OLD | NEW |