Chromium Code Reviews| 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_content_client/views_content_client.h" | |
| 18 | |
| 19 #if defined(OS_WIN) | |
| 20 #include "content/public/app/startup_helper_win.h" | |
| 21 #include "sandbox/win/src/sandbox_types.h" | |
| 22 #endif | |
| 23 | |
| 24 namespace { | |
| 25 | |
| 26 class AppListDemoService; | |
| 27 | |
| 28 // Number of dummy apps to populate in the app list. | |
| 29 const int kInitialItems = 20; | |
| 30 | |
| 31 // Extends the test AppListViewDelegate to quit the run loop when the launcher | |
| 32 // window is closed, and to close the window if it is simply dismissed. | |
| 33 class DemoAppListViewDelegate : public app_list::test::AppListTestViewDelegate { | |
| 34 public: | |
| 35 explicit DemoAppListViewDelegate(content::BrowserContext* browser_context) | |
| 36 : view_(NULL), browser_context_(browser_context) {} | |
| 37 virtual ~DemoAppListViewDelegate() {} | |
| 38 | |
| 39 app_list::AppListView* InitView(gfx::NativeView window_context); | |
| 40 | |
| 41 // Overridden from AppListViewDelegate: | |
| 42 virtual void Dismiss() OVERRIDE; | |
| 43 virtual void ViewClosing() OVERRIDE; | |
| 44 virtual content::WebContents* GetStartPageContents() OVERRIDE; | |
| 45 | |
| 46 private: | |
| 47 app_list::PaginationModel pagination_model_; | |
| 48 app_list::AppListView* view_; // Weak. Owns this. | |
| 49 content::BrowserContext* browser_context_; | |
| 50 scoped_ptr<content::WebContents> web_contents_; | |
| 51 | |
| 52 DISALLOW_COPY_AND_ASSIGN(DemoAppListViewDelegate); | |
| 53 }; | |
| 54 | |
| 55 app_list::AppListView* DemoAppListViewDelegate::InitView( | |
| 56 gfx::NativeView window_context) { | |
| 57 view_ = new app_list::AppListView(this); | |
|
calamity
2014/05/27 03:32:10
Note here that this is where the DemoAppListViewDe
tapted
2014/05/27 06:20:07
Done. Maybe we should change the constructor to ta
| |
| 58 view_->InitAsBubbleAtFixedLocation(window_context, | |
| 59 &pagination_model_, | |
| 60 gfx::Point(300, 300), | |
| 61 views::BubbleBorder::FLOAT, | |
| 62 false /* border_accepts_events */); | |
| 63 | |
| 64 // Populate some apps. | |
| 65 GetTestModel()->PopulateApps(kInitialItems); | |
| 66 app_list::AppListItemList* item_list = GetTestModel()->top_level_item_list(); | |
| 67 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 68 gfx::Image test_image = rb.GetImageNamed(IDR_DEFAULT_FAVICON_32); | |
| 69 for (size_t i = 0; i < item_list->item_count(); ++i) { | |
| 70 app_list::AppListItem* item = item_list->item_at(i); | |
| 71 // Alternate images with shadows and images without. | |
| 72 item->SetIcon(*test_image.ToImageSkia(), i & 1); | |
| 73 } | |
| 74 return view_; | |
| 75 } | |
| 76 | |
| 77 void DemoAppListViewDelegate::Dismiss() { | |
| 78 view_->GetWidget()->Close(); | |
| 79 } | |
| 80 | |
| 81 void DemoAppListViewDelegate::ViewClosing() { | |
| 82 web_contents_.reset(); | |
| 83 view_ = NULL; | |
| 84 base::MessageLoopForUI::current()->Quit(); | |
| 85 } | |
| 86 | |
| 87 content::WebContents* DemoAppListViewDelegate::GetStartPageContents() { | |
| 88 web_contents_.reset(content::WebContents::Create( | |
| 89 content::WebContents::CreateParams(browser_context_))); | |
| 90 web_contents_->GetController().LoadURL(GURL("http://www.google.com/"), | |
| 91 content::Referrer(), | |
| 92 content::PAGE_TRANSITION_AUTO_TOPLEVEL, | |
| 93 std::string()); | |
| 94 return web_contents_.get(); | |
| 95 } | |
| 96 | |
| 97 void ShowAppList(content::BrowserContext* browser_context, | |
| 98 gfx::NativeView window_context) { | |
| 99 DemoAppListViewDelegate* delegate = | |
| 100 new DemoAppListViewDelegate(browser_context); | |
| 101 app_list::AppListView* view = delegate->InitView(window_context); | |
| 102 view->GetWidget()->Show(); | |
| 103 view->GetWidget()->Activate(); | |
| 104 } | |
| 105 | |
| 106 } // namespace | |
| 107 | |
| 108 #if defined(OS_WIN) | |
| 109 int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t*, int) { | |
| 110 sandbox::SandboxInterfaceInfo sandbox_info = {0}; | |
| 111 content::InitializeSandboxInfo(&sandbox_info); | |
| 112 ui::ViewsContentClient views_content_client(instance, &sandbox_info); | |
| 113 #else | |
| 114 int main(int argc, const char** argv) { | |
| 115 ui::ViewsContentClient views_content_client(argc, argv); | |
| 116 #endif | |
| 117 | |
| 118 views_content_client.set_task(base::Bind(&ShowAppList)); | |
| 119 return views_content_client.RunMain(); | |
| 120 } | |
| OLD | NEW |