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