1 // Copyright 2013 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_shelf_delegate.h"
7 #include "ash/shelf/shelf_item_delegate_manager.h"
8 #include "ash/shelf/shelf_model.h"
9 #include "ash/shelf/shelf_util.h"
10 #include "ash/shell.h"
11 #include "ash/test/test_shelf_item_delegate.h"
12 #include "base/strings/string_util.h"
13 #include "base/strings/utf_string_conversions.h"
14 #include "ui/aura/window.h"
19 TestShelfDelegate
* TestShelfDelegate::instance_
= NULL
;
21 TestShelfDelegate::TestShelfDelegate(ShelfModel
* model
)
27 TestShelfDelegate::~TestShelfDelegate() {
31 void TestShelfDelegate::AddShelfItem(aura::Window
* window
) {
32 AddShelfItem(window
, STATUS_CLOSED
);
35 void TestShelfDelegate::AddShelfItem(aura::Window
* window
,
36 ShelfItemStatus status
) {
38 if (window
->type() == ui::wm::WINDOW_TYPE_PANEL
)
39 item
.type
= TYPE_APP_PANEL
;
41 item
.type
= TYPE_PLATFORM_APP
;
42 ShelfID id
= model_
->next_id();
45 window
->AddObserver(this);
47 ShelfItemDelegateManager
* manager
=
48 Shell::GetInstance()->shelf_item_delegate_manager();
49 // |manager| owns TestShelfItemDelegate.
50 scoped_ptr
<ShelfItemDelegate
> delegate(new TestShelfItemDelegate(window
));
51 manager
->SetShelfItemDelegate(id
, delegate
.Pass());
52 SetShelfIDForWindow(id
, window
);
55 void TestShelfDelegate::RemoveShelfItemForWindow(aura::Window
* window
) {
56 ShelfID id
= GetShelfIDForWindow(window
);
59 int index
= model_
->ItemIndexByID(id
);
61 model_
->RemoveItemAt(index
);
62 window
->RemoveObserver(this);
65 void TestShelfDelegate::OnWindowDestroying(aura::Window
* window
) {
66 RemoveShelfItemForWindow(window
);
69 void TestShelfDelegate::OnWindowHierarchyChanging(
70 const HierarchyChangeParams
& params
) {
71 // The window may be legitimately reparented while staying open if it moves
72 // to another display or container. If the window does not have a new parent
73 // then remove the shelf item.
74 if (!params
.new_parent
)
75 RemoveShelfItemForWindow(params
.target
);
78 void TestShelfDelegate::OnShelfCreated(Shelf
* shelf
) {
81 void TestShelfDelegate::OnShelfDestroyed(Shelf
* shelf
) {
84 ShelfID
TestShelfDelegate::GetShelfIDForAppID(const std::string
& app_id
) {
88 const std::string
& TestShelfDelegate::GetAppIDForShelfID(ShelfID id
) {
89 return base::EmptyString();
92 void TestShelfDelegate::PinAppWithID(const std::string
& app_id
) {
93 pinned_apps_
.insert(app_id
);
96 bool TestShelfDelegate::CanPin() const {
100 bool TestShelfDelegate::IsAppPinned(const std::string
& app_id
) {
101 return pinned_apps_
.find(app_id
) != pinned_apps_
.end();
104 void TestShelfDelegate::UnpinAppWithID(const std::string
& app_id
) {
105 pinned_apps_
.erase(app_id
);