OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/test/test_launcher_delegate.h" | 5 #include "ash/test/test_launcher_delegate.h" |
6 | 6 |
7 #include "ash/launcher/launcher_item_delegate_manager.h" | 7 #include "ash/shelf/shelf_item_delegate_manager.h" |
8 #include "ash/shelf/shelf_model.h" | 8 #include "ash/shelf/shelf_model.h" |
9 #include "ash/shelf/shelf_util.h" | 9 #include "ash/shelf/shelf_util.h" |
10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
11 #include "ash/test/test_launcher_item_delegate.h" | 11 #include "ash/test/test_shelf_item_delegate.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "grit/ash_resources.h" | 14 #include "grit/ash_resources.h" |
15 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
16 | 16 |
17 namespace ash { | 17 namespace ash { |
18 namespace test { | 18 namespace test { |
19 | 19 |
20 TestLauncherDelegate* TestLauncherDelegate::instance_ = NULL; | 20 TestLauncherDelegate* TestLauncherDelegate::instance_ = NULL; |
21 | 21 |
22 TestLauncherDelegate::TestLauncherDelegate(ShelfModel* model) | 22 TestLauncherDelegate::TestLauncherDelegate(ShelfModel* model) |
23 : model_(model) { | 23 : model_(model) { |
24 CHECK(!instance_); | 24 CHECK(!instance_); |
25 instance_ = this; | 25 instance_ = this; |
26 } | 26 } |
27 | 27 |
28 TestLauncherDelegate::~TestLauncherDelegate() { | 28 TestLauncherDelegate::~TestLauncherDelegate() { |
29 instance_ = NULL; | 29 instance_ = NULL; |
30 } | 30 } |
31 | 31 |
32 void TestLauncherDelegate::AddLauncherItem(aura::Window* window) { | 32 void TestLauncherDelegate::AddLauncherItem(aura::Window* window) { |
33 AddLauncherItem(window, STATUS_CLOSED); | 33 AddLauncherItem(window, STATUS_CLOSED); |
34 } | 34 } |
35 | 35 |
36 void TestLauncherDelegate::AddLauncherItem( | 36 void TestLauncherDelegate::AddLauncherItem(aura::Window* window, |
37 aura::Window* window, | 37 LauncherItemStatus status) { |
38 LauncherItemStatus status) { | 38 LauncherItem item; |
39 ash::LauncherItem item; | |
40 if (window->type() == aura::client::WINDOW_TYPE_PANEL) | 39 if (window->type() == aura::client::WINDOW_TYPE_PANEL) |
41 item.type = ash::TYPE_APP_PANEL; | 40 item.type = TYPE_APP_PANEL; |
42 else | 41 else |
43 item.type = ash::TYPE_PLATFORM_APP; | 42 item.type = TYPE_PLATFORM_APP; |
44 LauncherID id = model_->next_id(); | 43 LauncherID id = model_->next_id(); |
45 item.status = status; | 44 item.status = status; |
46 model_->Add(item); | 45 model_->Add(item); |
47 window->AddObserver(this); | 46 window->AddObserver(this); |
48 | 47 |
49 ash::LauncherItemDelegateManager* manager = | 48 ShelfItemDelegateManager* manager = |
50 ash::Shell::GetInstance()->launcher_item_delegate_manager(); | 49 Shell::GetInstance()->shelf_item_delegate_manager(); |
51 // |manager| owns TestLauncherItemDelegate. | 50 // |manager| owns TestShelfItemDelegate. |
52 scoped_ptr<LauncherItemDelegate> delegate( | 51 scoped_ptr<ShelfItemDelegate> delegate(new TestShelfItemDelegate(window)); |
53 new TestLauncherItemDelegate(window)); | 52 manager->SetShelfItemDelegate(id, delegate.Pass()); |
54 manager->SetLauncherItemDelegate(id, delegate.Pass()); | |
55 SetLauncherIDForWindow(id, window); | 53 SetLauncherIDForWindow(id, window); |
56 } | 54 } |
57 | 55 |
58 void TestLauncherDelegate::RemoveLauncherItemForWindow(aura::Window* window) { | 56 void TestLauncherDelegate::RemoveLauncherItemForWindow(aura::Window* window) { |
59 ash::LauncherID id = GetLauncherIDForWindow(window); | 57 LauncherID id = GetLauncherIDForWindow(window); |
60 if (id == 0) | 58 if (id == 0) |
61 return; | 59 return; |
62 int index = model_->ItemIndexByID(id); | 60 int index = model_->ItemIndexByID(id); |
63 DCHECK_NE(-1, index); | 61 DCHECK_NE(-1, index); |
64 model_->RemoveItemAt(index); | 62 model_->RemoveItemAt(index); |
65 window->RemoveObserver(this); | 63 window->RemoveObserver(this); |
66 } | 64 } |
67 | 65 |
68 void TestLauncherDelegate::OnWindowDestroying(aura::Window* window) { | 66 void TestLauncherDelegate::OnWindowDestroying(aura::Window* window) { |
69 RemoveLauncherItemForWindow(window); | 67 RemoveLauncherItemForWindow(window); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 | 100 |
103 bool TestLauncherDelegate::IsAppPinned(const std::string& app_id) { | 101 bool TestLauncherDelegate::IsAppPinned(const std::string& app_id) { |
104 return false; | 102 return false; |
105 } | 103 } |
106 | 104 |
107 void TestLauncherDelegate::UnpinAppWithID(const std::string& app_id) { | 105 void TestLauncherDelegate::UnpinAppWithID(const std::string& app_id) { |
108 } | 106 } |
109 | 107 |
110 } // namespace test | 108 } // namespace test |
111 } // namespace ash | 109 } // namespace ash |
OLD | NEW |