Update JNI generator for javap version 1.8.
[chromium-blink-merge.git] / ash / test / test_shelf_delegate.cc
blob7fced01da833d4d0210844ebca368d870e993a57
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"
16 namespace ash {
17 namespace test {
19 TestShelfDelegate* TestShelfDelegate::instance_ = NULL;
21 TestShelfDelegate::TestShelfDelegate(ShelfModel* model)
22 : model_(model) {
23 CHECK(!instance_);
24 instance_ = this;
27 TestShelfDelegate::~TestShelfDelegate() {
28 instance_ = NULL;
31 void TestShelfDelegate::AddShelfItem(aura::Window* window) {
32 AddShelfItem(window, STATUS_CLOSED);
35 void TestShelfDelegate::AddShelfItem(aura::Window* window,
36 ShelfItemStatus status) {
37 ShelfItem item;
38 if (window->type() == ui::wm::WINDOW_TYPE_PANEL)
39 item.type = TYPE_APP_PANEL;
40 else
41 item.type = TYPE_PLATFORM_APP;
42 ShelfID id = model_->next_id();
43 item.status = status;
44 model_->Add(item);
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);
57 if (id == 0)
58 return;
59 int index = model_->ItemIndexByID(id);
60 DCHECK_NE(-1, index);
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) {
85 return 0;
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 {
97 return true;
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);
108 } // namespace test
109 } // namespace ash