1 // Copyright (c) 2012 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.
5 #include "ash/test/test_launcher_delegate.h"
7 #include "ash/launcher/launcher_item_delegate_manager.h"
8 #include "ash/launcher/launcher_model.h"
9 #include "ash/shelf/shelf_util.h"
10 #include "ash/shell.h"
11 #include "ash/test/test_launcher_item_delegate.h"
12 #include "base/strings/string_util.h"
13 #include "base/strings/utf_string_conversions.h"
14 #include "grit/ash_resources.h"
15 #include "ui/aura/window.h"
20 TestLauncherDelegate
* TestLauncherDelegate::instance_
= NULL
;
22 TestLauncherDelegate::TestLauncherDelegate(LauncherModel
* model
)
28 TestLauncherDelegate::~TestLauncherDelegate() {
32 void TestLauncherDelegate::AddLauncherItem(aura::Window
* window
) {
33 AddLauncherItem(window
, STATUS_CLOSED
);
36 void TestLauncherDelegate::AddLauncherItem(
38 LauncherItemStatus status
) {
39 ash::LauncherItem item
;
40 if (window
->type() == aura::client::WINDOW_TYPE_PANEL
)
41 item
.type
= ash::TYPE_APP_PANEL
;
43 item
.type
= ash::TYPE_PLATFORM_APP
;
44 DCHECK(window_to_id_
.find(window
) == window_to_id_
.end());
45 window_to_id_
[window
] = model_
->next_id();
48 window
->AddObserver(this);
50 ash::LauncherItemDelegateManager
* manager
=
51 ash::Shell::GetInstance()->launcher_item_delegate_manager();
52 // |manager| owns TestLauncherItemDelegate.
53 scoped_ptr
<LauncherItemDelegate
> delegate(
54 new TestLauncherItemDelegate(window
));
55 manager
->SetLauncherItemDelegate(window_to_id_
[window
], delegate
.Pass());
58 void TestLauncherDelegate::RemoveLauncherItemForWindow(aura::Window
* window
) {
59 ash::LauncherID id
= GetIDByWindow(window
);
62 int index
= model_
->ItemIndexByID(id
);
64 model_
->RemoveItemAt(index
);
65 window_to_id_
.erase(window
);
66 window
->RemoveObserver(this);
69 void TestLauncherDelegate::OnWindowDestroying(aura::Window
* window
) {
70 RemoveLauncherItemForWindow(window
);
73 void TestLauncherDelegate::OnWindowHierarchyChanging(
74 const HierarchyChangeParams
& params
) {
75 // The window may be legitimately reparented while staying open if it moves
76 // to another display or container. If the window does not have a new parent
77 // then remove the launcher item.
78 if (!params
.new_parent
)
79 RemoveLauncherItemForWindow(params
.target
);
82 ash::LauncherID
TestLauncherDelegate::GetIDByWindow(aura::Window
* window
) {
83 WindowToID::const_iterator found
= window_to_id_
.find(window
);
84 if (found
== window_to_id_
.end())
89 void TestLauncherDelegate::OnLauncherCreated(Launcher
* launcher
) {
92 void TestLauncherDelegate::OnLauncherDestroyed(Launcher
* launcher
) {
95 LauncherID
TestLauncherDelegate::GetLauncherIDForAppID(
96 const std::string
& app_id
) {
100 const std::string
& TestLauncherDelegate::GetAppIDForLauncherID(LauncherID id
) {
101 return EmptyString();
104 void TestLauncherDelegate::PinAppWithID(const std::string
& app_id
) {
107 bool TestLauncherDelegate::CanPin() const {
111 bool TestLauncherDelegate::IsAppPinned(const std::string
& app_id
) {
115 void TestLauncherDelegate::UnpinAppWithID(const std::string
& app_id
) {