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/launcher/launcher_item_delegate_manager.h" |
8 #include "ash/launcher/launcher_model.h" | 8 #include "ash/launcher/launcher_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/wm/window_util.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(LauncherModel* model) | 22 TestLauncherDelegate::TestLauncherDelegate(LauncherModel* model) |
23 : model_(model) { | 23 : model_(model) { |
24 CHECK(!instance_); | 24 CHECK(!instance_); |
25 instance_ = this; | 25 instance_ = this; |
| 26 |
| 27 ash::LauncherItemDelegateManager* manager = |
| 28 ash::Shell::GetInstance()->launcher_item_delegate_manager(); |
| 29 manager->RegisterLauncherItemDelegate(ash::TYPE_APP_PANEL, this); |
| 30 manager->RegisterLauncherItemDelegate(ash::TYPE_APP_SHORTCUT, this); |
| 31 manager->RegisterLauncherItemDelegate(ash::TYPE_BROWSER_SHORTCUT, this); |
| 32 manager->RegisterLauncherItemDelegate(ash::TYPE_PLATFORM_APP, this); |
| 33 manager->RegisterLauncherItemDelegate(ash::TYPE_WINDOWED_APP, this); |
26 } | 34 } |
27 | 35 |
28 TestLauncherDelegate::~TestLauncherDelegate() { | 36 TestLauncherDelegate::~TestLauncherDelegate() { |
29 instance_ = NULL; | 37 instance_ = NULL; |
30 } | 38 } |
31 | 39 |
32 void TestLauncherDelegate::AddLauncherItem(aura::Window* window) { | 40 void TestLauncherDelegate::AddLauncherItem(aura::Window* window) { |
33 AddLauncherItem(window, STATUS_CLOSED); | 41 AddLauncherItem(window, STATUS_CLOSED); |
34 } | 42 } |
35 | 43 |
36 void TestLauncherDelegate::AddLauncherItem( | 44 void TestLauncherDelegate::AddLauncherItem( |
37 aura::Window* window, | 45 aura::Window* window, |
38 LauncherItemStatus status) { | 46 LauncherItemStatus status) { |
39 ash::LauncherItem item; | 47 ash::LauncherItem item; |
40 if (window->type() == aura::client::WINDOW_TYPE_PANEL) | 48 if (window->type() == aura::client::WINDOW_TYPE_PANEL) |
41 item.type = ash::TYPE_APP_PANEL; | 49 item.type = ash::TYPE_APP_PANEL; |
42 else | 50 else |
43 item.type = ash::TYPE_PLATFORM_APP; | 51 item.type = ash::TYPE_PLATFORM_APP; |
44 DCHECK(window_to_id_.find(window) == window_to_id_.end()); | 52 DCHECK(window_to_id_.find(window) == window_to_id_.end()); |
45 window_to_id_[window] = model_->next_id(); | 53 window_to_id_[window] = model_->next_id(); |
46 item.status = status; | 54 item.status = status; |
47 model_->Add(item); | 55 model_->Add(item); |
48 window->AddObserver(this); | 56 window->AddObserver(this); |
49 | |
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()); | |
56 } | 57 } |
57 | 58 |
58 void TestLauncherDelegate::RemoveLauncherItemForWindow(aura::Window* window) { | 59 void TestLauncherDelegate::RemoveLauncherItemForWindow(aura::Window* window) { |
59 ash::LauncherID id = GetIDByWindow(window); | 60 ash::LauncherID id = GetIDByWindow(window); |
60 if (id == 0) | 61 if (id == 0) |
61 return; | 62 return; |
62 int index = model_->ItemIndexByID(id); | 63 int index = model_->ItemIndexByID(id); |
63 DCHECK_NE(-1, index); | 64 DCHECK_NE(-1, index); |
64 model_->RemoveItemAt(index); | 65 model_->RemoveItemAt(index); |
65 window_to_id_.erase(window); | 66 window_to_id_.erase(window); |
66 window->RemoveObserver(this); | 67 window->RemoveObserver(this); |
67 } | 68 } |
68 | 69 |
69 void TestLauncherDelegate::OnWindowDestroying(aura::Window* window) { | 70 void TestLauncherDelegate::OnWindowDestroying(aura::Window* window) { |
70 RemoveLauncherItemForWindow(window); | 71 RemoveLauncherItemForWindow(window); |
71 } | 72 } |
72 | 73 |
73 void TestLauncherDelegate::OnWindowHierarchyChanging( | 74 void TestLauncherDelegate::OnWindowHierarchyChanging( |
74 const HierarchyChangeParams& params) { | 75 const HierarchyChangeParams& params) { |
75 // The window may be legitimately reparented while staying open if it moves | 76 // 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 // to another display or container. If the window does not have a new parent |
77 // then remove the launcher item. | 78 // then remove the launcher item. |
78 if (!params.new_parent) | 79 if (!params.new_parent) |
79 RemoveLauncherItemForWindow(params.target); | 80 RemoveLauncherItemForWindow(params.target); |
80 } | 81 } |
81 | 82 |
| 83 void TestLauncherDelegate::ItemSelected(const ash::LauncherItem& item, |
| 84 const ui::Event& event) { |
| 85 aura::Window* window = GetWindowByID(item.id); |
| 86 if (window->type() == aura::client::WINDOW_TYPE_PANEL) |
| 87 ash::wm::MoveWindowToEventRoot(window, event); |
| 88 window->Show(); |
| 89 ash::wm::ActivateWindow(window); |
| 90 } |
| 91 |
| 92 base::string16 TestLauncherDelegate::GetTitle(const ash::LauncherItem& item) { |
| 93 aura::Window* window = GetWindowByID(item.id); |
| 94 return window ? window->title() : base::string16(); |
| 95 } |
| 96 |
| 97 ui::MenuModel* TestLauncherDelegate::CreateContextMenu( |
| 98 const ash::LauncherItem& item, |
| 99 aura::RootWindow* root) { |
| 100 return NULL; |
| 101 } |
| 102 |
| 103 ash::LauncherMenuModel* TestLauncherDelegate::CreateApplicationMenu( |
| 104 const ash::LauncherItem& item, |
| 105 int event_flags) { |
| 106 return NULL; |
| 107 } |
| 108 |
82 ash::LauncherID TestLauncherDelegate::GetIDByWindow(aura::Window* window) { | 109 ash::LauncherID TestLauncherDelegate::GetIDByWindow(aura::Window* window) { |
83 WindowToID::const_iterator found = window_to_id_.find(window); | 110 WindowToID::const_iterator found = window_to_id_.find(window); |
84 if (found == window_to_id_.end()) | 111 if (found == window_to_id_.end()) |
85 return 0; | 112 return 0; |
86 return found->second; | 113 return found->second; |
87 } | 114 } |
88 | 115 |
| 116 aura::Window* TestLauncherDelegate::GetWindowByID(ash::LauncherID id) { |
| 117 for (WindowToID::const_iterator it = window_to_id_.begin(); |
| 118 it != window_to_id_.end(); |
| 119 it++) { |
| 120 if (it->second == id) |
| 121 return it->first; |
| 122 } |
| 123 return NULL; |
| 124 } |
| 125 |
| 126 bool TestLauncherDelegate::IsDraggable(const ash::LauncherItem& item) { |
| 127 return true; |
| 128 } |
| 129 |
| 130 bool TestLauncherDelegate::ShouldShowTooltip(const ash::LauncherItem& item) { |
| 131 return true; |
| 132 } |
| 133 |
89 void TestLauncherDelegate::OnLauncherCreated(Launcher* launcher) { | 134 void TestLauncherDelegate::OnLauncherCreated(Launcher* launcher) { |
90 } | 135 } |
91 | 136 |
92 void TestLauncherDelegate::OnLauncherDestroyed(Launcher* launcher) { | 137 void TestLauncherDelegate::OnLauncherDestroyed(Launcher* launcher) { |
93 } | 138 } |
94 | 139 |
95 LauncherID TestLauncherDelegate::GetLauncherIDForAppID( | 140 LauncherID TestLauncherDelegate::GetLauncherIDForAppID( |
96 const std::string& app_id) { | 141 const std::string& app_id) { |
97 return 0; | 142 return 0; |
98 } | 143 } |
(...skipping 11 matching lines...) Expand all Loading... |
110 | 155 |
111 bool TestLauncherDelegate::IsAppPinned(const std::string& app_id) { | 156 bool TestLauncherDelegate::IsAppPinned(const std::string& app_id) { |
112 return false; | 157 return false; |
113 } | 158 } |
114 | 159 |
115 void TestLauncherDelegate::UnpinAppWithID(const std::string& app_id) { | 160 void TestLauncherDelegate::UnpinAppWithID(const std::string& app_id) { |
116 } | 161 } |
117 | 162 |
118 } // namespace test | 163 } // namespace test |
119 } // namespace ash | 164 } // namespace ash |
OLD | NEW |