forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_list_demo_views.cc
94 lines (76 loc) · 3.14 KB
/
app_list_demo_views.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// 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 <stddef.h>
#include <memory>
#include "ash/app_list/test/app_list_test_model.h"
#include "ash/app_list/test/app_list_test_view_delegate.h"
#include "ash/app_list/views/app_list_view.h"
#include "base/bind.h"
#include "base/macros.h"
#include "base/run_loop.h"
#include "base/single_thread_task_runner.h"
#include "base/threading/thread_task_runner_handle.h"
#include "build/build_config.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/resources/grit/ui_resources.h"
#include "ui/views_content_client/views_content_client.h"
namespace ash {
// 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 test::AppListTestViewDelegate {
public:
DemoAppListViewDelegate() : view_(nullptr) {}
~DemoAppListViewDelegate() override {}
AppListView* InitView(gfx::NativeWindow window_context);
// Overridden from AppListViewDelegate:
void DismissAppList() override;
void ViewClosing() override;
private:
AppListView* view_; // Weak. Owns this.
DISALLOW_COPY_AND_ASSIGN(DemoAppListViewDelegate);
};
AppListView* DemoAppListViewDelegate::InitView(
gfx::NativeWindow window_context) {
// On Ash, the app list is placed into an aura::Window container. For the demo
// use the root window context as the parent. This only works on Aura since an
// aura::Window is also a NativeView.
gfx::NativeView container = window_context;
view_ = new AppListView(this);
view_->InitView(container);
view_->Show(false /*is_side_shelf*/);
// Populate some apps.
GetTestModel()->PopulateApps(kInitialItems);
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) {
AppListItem* item = item_list->item_at(i);
// Alternate images with shadows and images without.
item->SetIcon(AppListConfigType::kShared, *test_image.ToImageSkia());
}
return view_;
}
void DemoAppListViewDelegate::DismissAppList() {
view_->GetWidget()->Close();
}
void DemoAppListViewDelegate::ViewClosing() {
base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this);
base::RunLoop::QuitCurrentWhenIdleDeprecated();
}
void ShowAppList(content::BrowserContext* browser_context,
gfx::NativeWindow window_context) {
DemoAppListViewDelegate* delegate = new DemoAppListViewDelegate;
AppListView* view = delegate->InitView(window_context);
view->GetWidget()->Show();
view->GetWidget()->Activate();
}
} // namespace ash
int main(int argc, const char** argv) {
ui::ViewsContentClient views_content_client(argc, argv);
views_content_client.set_on_pre_main_message_loop_run_callback(
base::BindOnce(&ash::ShowAppList));
return views_content_client.RunMain();
}