Chromium Code Reviews| 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(LauncherModel* model) | |
| 17 : model_(model) { | |
| 18 } | |
| 19 | |
| 20 void TestLauncherDelegate::OnWillRemoveWindow(aura::Window* window) { | |
| 21 ash::LauncherID id = GetIDByWindow(window); | |
| 22 if (id == 0) | |
| 23 return; | |
| 24 int index = model_->ItemIndexByID(id); | |
| 25 DCHECK_NE(-1, index); | |
| 26 model_->RemoveItemAt(index); | |
| 27 window_to_id_.erase(window); | |
| 28 } | |
| 29 | |
| 30 void TestLauncherDelegate::CreateNewTab() { | |
| 31 } | |
| 32 | |
| 33 void TestLauncherDelegate::CreateNewWindow() { | |
| 34 } | |
| 35 | |
| 36 void TestLauncherDelegate::ItemClicked(const ash::LauncherItem& item) { | |
| 37 aura::Window* window = GetWindowByID(item.id); | |
| 38 window->Show(); | |
| 39 ash::wm::ActivateWindow(window); | |
| 40 } | |
| 41 | |
| 42 int TestLauncherDelegate::GetBrowserShortcutResourceId() { | |
| 43 return IDR_AURA_LAUNCHER_BROWSER_SHORTCUT; | |
| 44 } | |
| 45 | |
| 46 string16 TestLauncherDelegate::GetTitle(const ash::LauncherItem& item) { | |
| 47 return GetWindowByID(item.id)->title(); | |
| 48 } | |
| 49 | |
| 50 ui::MenuModel* TestLauncherDelegate::CreateContextMenu( | |
| 51 const ash::LauncherItem& item) { | |
| 52 return NULL; | |
| 53 } | |
| 54 | |
| 55 ui::MenuModel* TestLauncherDelegate::CreateContextMenuForLauncher() { | |
| 56 return NULL; | |
| 57 } | |
| 58 | |
| 59 ash::LauncherID TestLauncherDelegate::GetIDByWindow(aura::Window* window) { | |
| 60 WindowToID::const_iterator found = window_to_id_.find(window); | |
| 61 if (found == window_to_id_.end()) | |
| 62 return 0; | |
| 63 return found->second; | |
| 64 } | |
| 65 | |
| 66 void TestLauncherDelegate::AddLauncherItem(aura::Window* window) { | |
|
sky
2012/04/19 00:05:40
Position should match header.
dcheng
2012/04/19 20:18:15
Done.
| |
| 67 ash::LauncherItem item; | |
| 68 item.type = ash::TYPE_TABBED; | |
| 69 window_to_id_[window] = model_->next_id(); | |
|
sky
2012/04/19 00:05:40
How about a DCHECK(window_to_id_.find(window) == w
dcheng
2012/04/19 20:18:15
Done.
| |
| 70 item.image.setConfig(SkBitmap::kARGB_8888_Config, 16, 16); | |
| 71 item.image.allocPixels(); | |
| 72 model_->Add(item); | |
| 73 if (observed_windows_.find(window->parent()) == observed_windows_.end()) { | |
| 74 window->parent()->AddObserver(this); | |
|
sky
2012/04/19 00:05:40
You never remove this observer.
dcheng
2012/04/19 20:18:15
Done.
| |
| 75 observed_windows_.insert(window->parent()); | |
| 76 } | |
| 77 } | |
| 78 | |
| 79 aura::Window* TestLauncherDelegate::GetWindowByID(ash::LauncherID id) { | |
| 80 for (WindowToID::const_iterator it = window_to_id_.begin(); | |
| 81 it != window_to_id_.end(); | |
| 82 it++) { | |
| 83 if (it->second == id) | |
| 84 return it->first; | |
| 85 } | |
| 86 return NULL; | |
| 87 } | |
| 88 | |
|
sky
2012/04/19 00:05:40
nit: only one newline.
dcheng
2012/04/19 20:18:15
Done.
| |
| 89 | |
| 90 } // namespace test | |
| 91 } // namespace ash | |
| OLD | NEW |