Commit 430904b9 authored by tapted@chromium.org's avatar tapted@chromium.org

Add app_list_demo, a standalone executable for testing the app list UI.

This will facilitate development of the out-of-process UI compositor for
MacViews by providing a views example that uses UI layers and composited
animations.

It also gives app list developers a target to ease development of
upcoming changes, without compiling all of Chromium and manually
installing two dozen apps from the webstore.

BUG=365977

Review URL: https://codereview.chromium.org/281383012

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@273063 0039d316-1c4b-4281-b951-d872f2087c98
parent 41256cdb
......@@ -281,4 +281,44 @@
'msvs_disabled_warnings': [ 4267, ],
},
],
'conditions': [
['toolkit_views==1', {
'targets': [
{
'target_name': 'app_list_demo',
'type': 'executable',
'sources': [
'../../content/app/startup_helper_win.cc',
'views/app_list_demo.cc',
],
'dependencies': [
'../../base/base.gyp:base',
'../../content/content.gyp:content',
'../../skia/skia.gyp:skia',
'../../url/url.gyp:url_lib',
'../base/ui_base.gyp:ui_base',
'../events/events.gyp:events',
'../resources/ui_resources.gyp:ui_resources',
'../resources/ui_resources.gyp:ui_test_pak',
'../views/views.gyp:views',
'../views_content_client/views_content_client.gyp:views_content_client',
'app_list',
'app_list_test_support',
],
'conditions': [
['OS=="win"', {
'msvs_settings': {
'VCLinkerTool': {
'SubSystem': '2', # Set /SUBSYSTEM:WINDOWS
},
},
'dependencies': [
'../../sandbox/sandbox.gyp:sandbox',
],
}],
],
},
],
}], # toolkit_views==1
],
}
include_rules = [
"+content/public",
]
specific_include_rules = {
"app_list_demo\.cc": [
"+sandbox",
"+ui/views_content_client",
],
}
// 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_content_client/views_content_client.h"
#if defined(OS_WIN)
#include "content/public/app/startup_helper_win.h"
#include "sandbox/win/src/sandbox_types.h"
#endif
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() OVERRIDE;
private:
app_list::PaginationModel pagination_model_;
app_list::AppListView* view_; // Weak. Owns this.
content::BrowserContext* browser_context_;
scoped_ptr<content::WebContents> web_contents_;
DISALLOW_COPY_AND_ASSIGN(DemoAppListViewDelegate);
};
app_list::AppListView* DemoAppListViewDelegate::InitView(
gfx::NativeView window_context) {
// Note AppListView takes ownership of |this| on the next line.
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);
// Alternate images with shadows and images without.
item->SetIcon(*test_image.ToImageSkia(), i & 1);
}
return view_;
}
void DemoAppListViewDelegate::Dismiss() {
view_->GetWidget()->Close();
}
void DemoAppListViewDelegate::ViewClosing() {
web_contents_.reset();
view_ = NULL;
base::MessageLoopForUI::current()->Quit();
}
content::WebContents* DemoAppListViewDelegate::GetStartPageContents() {
web_contents_.reset(content::WebContents::Create(
content::WebContents::CreateParams(browser_context_)));
web_contents_->GetController().LoadURL(GURL("http://www.google.com/"),
content::Referrer(),
content::PAGE_TRANSITION_AUTO_TOPLEVEL,
std::string());
return web_contents_.get();
}
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) {
sandbox::SandboxInterfaceInfo sandbox_info = {0};
content::InitializeSandboxInfo(&sandbox_info);
ui::ViewsContentClient views_content_client(instance, &sandbox_info);
#else
int main(int argc, const char** argv) {
ui::ViewsContentClient views_content_client(argc, argv);
#endif
views_content_client.set_task(base::Bind(&ShowAppList));
return views_content_client.RunMain();
}
......@@ -116,7 +116,7 @@ class APP_LIST_EXPORT AppListView : public views::BubbleDelegateView,
AppListMainView* app_list_main_view() { return app_list_main_view_; }
private:
friend class test::AppListViewTestApi;
friend class ::test::AppListViewTestApi;
void InitAsBubbleInternal(gfx::NativeView parent,
PaginationModel* pagination_model,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment