| 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/wm/window_util.h" | 11 #include "ash/test/test_launcher_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(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); | |
| 34 } | 26 } |
| 35 | 27 |
| 36 TestLauncherDelegate::~TestLauncherDelegate() { | 28 TestLauncherDelegate::~TestLauncherDelegate() { |
| 37 instance_ = NULL; | 29 instance_ = NULL; |
| 38 } | 30 } |
| 39 | 31 |
| 40 void TestLauncherDelegate::AddLauncherItem(aura::Window* window) { | 32 void TestLauncherDelegate::AddLauncherItem(aura::Window* window) { |
| 41 AddLauncherItem(window, STATUS_CLOSED); | 33 AddLauncherItem(window, STATUS_CLOSED); |
| 42 } | 34 } |
| 43 | 35 |
| 44 void TestLauncherDelegate::AddLauncherItem( | 36 void TestLauncherDelegate::AddLauncherItem( |
| 45 aura::Window* window, | 37 aura::Window* window, |
| 46 LauncherItemStatus status) { | 38 LauncherItemStatus status) { |
| 47 ash::LauncherItem item; | 39 ash::LauncherItem item; |
| 48 if (window->type() == aura::client::WINDOW_TYPE_PANEL) | 40 if (window->type() == aura::client::WINDOW_TYPE_PANEL) |
| 49 item.type = ash::TYPE_APP_PANEL; | 41 item.type = ash::TYPE_APP_PANEL; |
| 50 else | 42 else |
| 51 item.type = ash::TYPE_PLATFORM_APP; | 43 item.type = ash::TYPE_PLATFORM_APP; |
| 52 DCHECK(window_to_id_.find(window) == window_to_id_.end()); | 44 DCHECK(window_to_id_.find(window) == window_to_id_.end()); |
| 53 window_to_id_[window] = model_->next_id(); | 45 window_to_id_[window] = model_->next_id(); |
| 54 item.status = status; | 46 item.status = status; |
| 55 model_->Add(item); | 47 model_->Add(item); |
| 56 window->AddObserver(this); | 48 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()); |
| 57 } | 56 } |
| 58 | 57 |
| 59 void TestLauncherDelegate::RemoveLauncherItemForWindow(aura::Window* window) { | 58 void TestLauncherDelegate::RemoveLauncherItemForWindow(aura::Window* window) { |
| 60 ash::LauncherID id = GetIDByWindow(window); | 59 ash::LauncherID id = GetIDByWindow(window); |
| 61 if (id == 0) | 60 if (id == 0) |
| 62 return; | 61 return; |
| 63 int index = model_->ItemIndexByID(id); | 62 int index = model_->ItemIndexByID(id); |
| 64 DCHECK_NE(-1, index); | 63 DCHECK_NE(-1, index); |
| 65 model_->RemoveItemAt(index); | 64 model_->RemoveItemAt(index); |
| 66 window_to_id_.erase(window); | 65 window_to_id_.erase(window); |
| 67 window->RemoveObserver(this); | 66 window->RemoveObserver(this); |
| 68 } | 67 } |
| 69 | 68 |
| 70 void TestLauncherDelegate::OnWindowDestroying(aura::Window* window) { | 69 void TestLauncherDelegate::OnWindowDestroying(aura::Window* window) { |
| 71 RemoveLauncherItemForWindow(window); | 70 RemoveLauncherItemForWindow(window); |
| 72 } | 71 } |
| 73 | 72 |
| 74 void TestLauncherDelegate::OnWindowHierarchyChanging( | 73 void TestLauncherDelegate::OnWindowHierarchyChanging( |
| 75 const HierarchyChangeParams& params) { | 74 const HierarchyChangeParams& params) { |
| 76 // The window may be legitimately reparented while staying open if it moves | 75 // The window may be legitimately reparented while staying open if it moves |
| 77 // to another display or container. If the window does not have a new parent | 76 // to another display or container. If the window does not have a new parent |
| 78 // then remove the launcher item. | 77 // then remove the launcher item. |
| 79 if (!params.new_parent) | 78 if (!params.new_parent) |
| 80 RemoveLauncherItemForWindow(params.target); | 79 RemoveLauncherItemForWindow(params.target); |
| 81 } | 80 } |
| 82 | 81 |
| 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 | |
| 109 ash::LauncherID TestLauncherDelegate::GetIDByWindow(aura::Window* window) { | 82 ash::LauncherID TestLauncherDelegate::GetIDByWindow(aura::Window* window) { |
| 110 WindowToID::const_iterator found = window_to_id_.find(window); | 83 WindowToID::const_iterator found = window_to_id_.find(window); |
| 111 if (found == window_to_id_.end()) | 84 if (found == window_to_id_.end()) |
| 112 return 0; | 85 return 0; |
| 113 return found->second; | 86 return found->second; |
| 114 } | 87 } |
| 115 | 88 |
| 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 | |
| 134 void TestLauncherDelegate::OnLauncherCreated(Launcher* launcher) { | 89 void TestLauncherDelegate::OnLauncherCreated(Launcher* launcher) { |
| 135 } | 90 } |
| 136 | 91 |
| 137 void TestLauncherDelegate::OnLauncherDestroyed(Launcher* launcher) { | 92 void TestLauncherDelegate::OnLauncherDestroyed(Launcher* launcher) { |
| 138 } | 93 } |
| 139 | 94 |
| 140 LauncherID TestLauncherDelegate::GetLauncherIDForAppID( | 95 LauncherID TestLauncherDelegate::GetLauncherIDForAppID( |
| 141 const std::string& app_id) { | 96 const std::string& app_id) { |
| 142 return 0; | 97 return 0; |
| 143 } | 98 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 155 | 110 |
| 156 bool TestLauncherDelegate::IsAppPinned(const std::string& app_id) { | 111 bool TestLauncherDelegate::IsAppPinned(const std::string& app_id) { |
| 157 return false; | 112 return false; |
| 158 } | 113 } |
| 159 | 114 |
| 160 void TestLauncherDelegate::UnpinAppWithID(const std::string& app_id) { | 115 void TestLauncherDelegate::UnpinAppWithID(const std::string& app_id) { |
| 161 } | 116 } |
| 162 | 117 |
| 163 } // namespace test | 118 } // namespace test |
| 164 } // namespace ash | 119 } // namespace ash |
| OLD | NEW |