Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Unified Diff: ui/app_list/views/app_list_demo.cc

Issue 284113011: Repurpose views+content example into a generic multiprocess views runtime (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: app_list_demo.cc using example_main Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/app_list/app_list.gyp ('k') | ui/views/examples/content_client/examples_browser_main_parts.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/app_list/views/app_list_demo.cc
diff --git a/ui/app_list/views/app_list_demo.cc b/ui/app_list/views/app_list_demo.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4695da0a699cd4fa9dc1dbd418b0d6a049c7d4e2
--- /dev/null
+++ b/ui/app_list/views/app_list_demo.cc
@@ -0,0 +1,110 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/bind.h"
+#include "base/command_line.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/run_loop.h"
+#include "content/public/browser/web_contents.h"
+#include "content/public/common/content_switches.h"
+#include "grit/ui_resources.h"
+#include "ui/app_list/pagination_model.h"
+#include "ui/app_list/test/app_list_test_model.h"
+#include "ui/app_list/test/app_list_test_view_delegate.h"
+#include "ui/app_list/views/app_list_view.h"
+#include "ui/base/resource/resource_bundle.h"
+#include "ui/views/examples/content_client/examples_main.h"
+
+namespace {
+
+class AppListDemoService;
+
+// Number of dummy apps to populate in the app list.
+const int kInitialItems = 20;
+
+// Extends the test AppListViewDelegate to quit the run loop when the launcher
+// window is closed, and to close the window if it is simply dismissed.
+class DemoAppListViewDelegate : public app_list::test::AppListTestViewDelegate {
+ public:
+ explicit DemoAppListViewDelegate(content::BrowserContext* browser_context)
+ : view_(NULL), browser_context_(browser_context) {}
+ virtual ~DemoAppListViewDelegate() {}
+
+ app_list::AppListView* InitView(gfx::NativeView window_context);
+
+ // Overridden from AppListViewDelegate:
+ virtual void Dismiss() OVERRIDE;
+ virtual void ViewClosing() OVERRIDE;
+ virtual content::WebContents* GetStartPageContents();
+
+ private:
+ app_list::PaginationModel pagination_model_;
+ app_list::AppListView* view_; // Weak. Owns this.
+ content::BrowserContext* browser_context_;
+
+ DISALLOW_COPY_AND_ASSIGN(DemoAppListViewDelegate);
+};
+
+app_list::AppListView* DemoAppListViewDelegate::InitView(
+ gfx::NativeView window_context) {
+ view_ = new app_list::AppListView(this);
+ view_->InitAsBubbleAtFixedLocation(window_context,
+ &pagination_model_,
+ gfx::Point(300, 300),
+ views::BubbleBorder::FLOAT,
+ false /* border_accepts_events */);
+
+ // Populate some apps.
+ GetTestModel()->PopulateApps(kInitialItems);
+ app_list::AppListItemList* item_list = GetTestModel()->top_level_item_list();
+ ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
+ gfx::Image test_image = rb.GetImageNamed(IDR_DEFAULT_FAVICON_32);
+ for (size_t i = 0; i < item_list->item_count(); ++i) {
+ app_list::AppListItem* item = item_list->item_at(i);
+ item->SetIcon(*test_image.ToImageSkia(), i & 1);
+ }
+ return view_;
+}
+
+void DemoAppListViewDelegate::Dismiss() {
+ view_->GetWidget()->Close();
+}
+
+void DemoAppListViewDelegate::ViewClosing() {
+ view_ = NULL;
+ base::MessageLoopForUI::current()->Quit();
+}
+
+content::WebContents* DemoAppListViewDelegate::GetStartPageContents() {
+ // TODO(tapted): Implement this properly. For now, we need a dependency on
+ // content to force a particular link order in shared library builds. Without
+ // this, sandbox::InitLibcUrandomOverrides() will fail because it can't find
+ // the symbol for fopen, when the linker places libc before libcontent in the
+ // link order.
+ return content::WebContents::Create(
+ content::WebContents::CreateParams(browser_context_));
+}
+
+void ShowAppList(content::BrowserContext* browser_context,
+ gfx::NativeView window_context) {
+ DemoAppListViewDelegate* delegate =
+ new DemoAppListViewDelegate(browser_context);
+ app_list::AppListView* view = delegate->InitView(window_context);
+ view->GetWidget()->Show();
+ view->GetWidget()->Activate();
+}
+
+} // namespace
+
+#if defined(OS_WIN)
+int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t*, int) {
+ views::examples::ExamplesMainParams params(instance);
+#else
+int main(int argc, const char** argv) {
+ views::examples::ExamplesMainParams params(argc, argv);
+#endif
+
+ params.set_task(base::Bind(&ShowAppList));
+ return params.RunMain();
+}
« no previous file with comments | « ui/app_list/app_list.gyp ('k') | ui/views/examples/content_client/examples_browser_main_parts.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698