Support 8bpp screens in X11
[chromium-blink-merge.git] / ash / test / test_shelf_delegate.cc
blobe32561081f77a1d22a6fb8553847eb87a814317c
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 "grit/ash_resources.h"
15 #include "ui/aura/window.h"
17 namespace ash {
18 namespace test {
20 TestShelfDelegate* TestShelfDelegate::instance_ = NULL;
22 TestShelfDelegate::TestShelfDelegate(ShelfModel* model)
23 : model_(model) {
24 CHECK(!instance_);
25 instance_ = this;
28 TestShelfDelegate::~TestShelfDelegate() {
29 instance_ = NULL;
32 void TestShelfDelegate::AddShelfItem(aura::Window* window) {
33 AddShelfItem(window, STATUS_CLOSED);
36 void TestShelfDelegate::AddShelfItem(aura::Window* window,
37 ShelfItemStatus status) {
38 ShelfItem item;
39 if (window->type() == ui::wm::WINDOW_TYPE_PANEL)
40 item.type = TYPE_APP_PANEL;
41 else
42 item.type = TYPE_PLATFORM_APP;
43 ShelfID id = model_->next_id();
44 item.status = status;
45 model_->Add(item);
46 window->AddObserver(this);
48 ShelfItemDelegateManager* manager =
49 Shell::GetInstance()->shelf_item_delegate_manager();
50 // |manager| owns TestShelfItemDelegate.
51 scoped_ptr<ShelfItemDelegate> delegate(new TestShelfItemDelegate(window));
52 manager->SetShelfItemDelegate(id, delegate.Pass());
53 SetShelfIDForWindow(id, window);
56 void TestShelfDelegate::RemoveShelfItemForWindow(aura::Window* window) {
57 ShelfID id = GetShelfIDForWindow(window);
58 if (id == 0)
59 return;
60 int index = model_->ItemIndexByID(id);
61 DCHECK_NE(-1, index);
62 model_->RemoveItemAt(index);
63 window->RemoveObserver(this);
66 void TestShelfDelegate::OnWindowDestroying(aura::Window* window) {
67 RemoveShelfItemForWindow(window);
70 void TestShelfDelegate::OnWindowHierarchyChanging(
71 const HierarchyChangeParams& params) {
72 // The window may be legitimately reparented while staying open if it moves
73 // to another display or container. If the window does not have a new parent
74 // then remove the shelf item.
75 if (!params.new_parent)
76 RemoveShelfItemForWindow(params.target);
79 void TestShelfDelegate::OnShelfCreated(Shelf* shelf) {
82 void TestShelfDelegate::OnShelfDestroyed(Shelf* shelf) {
85 ShelfID TestShelfDelegate::GetShelfIDForAppID(const std::string& app_id) {
86 return 0;
89 const std::string& TestShelfDelegate::GetAppIDForShelfID(ShelfID id) {
90 return base::EmptyString();
93 void TestShelfDelegate::PinAppWithID(const std::string& app_id) {
96 bool TestShelfDelegate::CanPin() const {
97 return true;
100 bool TestShelfDelegate::IsAppPinned(const std::string& app_id) {
101 return false;
104 void TestShelfDelegate::UnpinAppWithID(const std::string& app_id) {
107 } // namespace test
108 } // namespace ash