| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ash/test/test_launcher_delegate.h" |
| 6 |
| 7 #include "ash/launcher/launcher_model.h" |
| 8 #include "ash/wm/window_util.h" |
| 9 #include "base/utf_string_conversions.h" |
| 10 #include "grit/ui_resources.h" |
| 11 #include "ui/aura/window.h" |
| 12 |
| 13 namespace ash { |
| 14 namespace test { |
| 15 |
| 16 TestLauncherDelegate* TestLauncherDelegate::instance_ = NULL; |
| 17 |
| 18 TestLauncherDelegate::TestLauncherDelegate(LauncherModel* model) |
| 19 : model_(model) { |
| 20 CHECK(!instance_); |
| 21 instance_ = this; |
| 22 } |
| 23 |
| 24 TestLauncherDelegate::~TestLauncherDelegate() { |
| 25 instance_ = NULL; |
| 26 } |
| 27 |
| 28 void TestLauncherDelegate::AddLauncherItem(aura::Window* window) { |
| 29 ash::LauncherItem item; |
| 30 item.type = ash::TYPE_TABBED; |
| 31 DCHECK(window_to_id_.find(window) == window_to_id_.end()); |
| 32 window_to_id_[window] = model_->next_id(); |
| 33 item.image.setConfig(SkBitmap::kARGB_8888_Config, 16, 16); |
| 34 item.image.allocPixels(); |
| 35 model_->Add(item); |
| 36 if (observed_windows_.find(window->parent()) == observed_windows_.end()) { |
| 37 window->parent()->AddObserver(this); |
| 38 observed_windows_.insert(window->parent()); |
| 39 } |
| 40 } |
| 41 |
| 42 void TestLauncherDelegate::OnWillRemoveWindow(aura::Window* window) { |
| 43 ash::LauncherID id = GetIDByWindow(window); |
| 44 if (id == 0) |
| 45 return; |
| 46 int index = model_->ItemIndexByID(id); |
| 47 DCHECK_NE(-1, index); |
| 48 model_->RemoveItemAt(index); |
| 49 window_to_id_.erase(window); |
| 50 ObservedWindows::iterator it = observed_windows_.find(window->parent()); |
| 51 if (it != observed_windows_.end()) { |
| 52 window->parent()->RemoveObserver(this); |
| 53 observed_windows_.erase(it); |
| 54 } |
| 55 } |
| 56 |
| 57 void TestLauncherDelegate::CreateNewTab() { |
| 58 } |
| 59 |
| 60 void TestLauncherDelegate::CreateNewWindow() { |
| 61 } |
| 62 |
| 63 void TestLauncherDelegate::ItemClicked(const ash::LauncherItem& item) { |
| 64 aura::Window* window = GetWindowByID(item.id); |
| 65 window->Show(); |
| 66 ash::wm::ActivateWindow(window); |
| 67 } |
| 68 |
| 69 int TestLauncherDelegate::GetBrowserShortcutResourceId() { |
| 70 return IDR_AURA_LAUNCHER_BROWSER_SHORTCUT; |
| 71 } |
| 72 |
| 73 string16 TestLauncherDelegate::GetTitle(const ash::LauncherItem& item) { |
| 74 return GetWindowByID(item.id)->title(); |
| 75 } |
| 76 |
| 77 ui::MenuModel* TestLauncherDelegate::CreateContextMenu( |
| 78 const ash::LauncherItem& item) { |
| 79 return NULL; |
| 80 } |
| 81 |
| 82 ui::MenuModel* TestLauncherDelegate::CreateContextMenuForLauncher() { |
| 83 return NULL; |
| 84 } |
| 85 |
| 86 ash::LauncherID TestLauncherDelegate::GetIDByWindow(aura::Window* window) { |
| 87 WindowToID::const_iterator found = window_to_id_.find(window); |
| 88 if (found == window_to_id_.end()) |
| 89 return 0; |
| 90 return found->second; |
| 91 } |
| 92 |
| 93 aura::Window* TestLauncherDelegate::GetWindowByID(ash::LauncherID id) { |
| 94 for (WindowToID::const_iterator it = window_to_id_.begin(); |
| 95 it != window_to_id_.end(); |
| 96 it++) { |
| 97 if (it->second == id) |
| 98 return it->first; |
| 99 } |
| 100 return NULL; |
| 101 } |
| 102 |
| 103 } // namespace test |
| 104 } // namespace ash |
| OLD | NEW |