Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(110)

Unified Diff: ash/test/test_launcher_delegate.cc

Issue 10116011: Add LauncherIconObserver. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: . Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ash/test/test_launcher_delegate.cc
diff --git a/ash/test/test_launcher_delegate.cc b/ash/test/test_launcher_delegate.cc
new file mode 100644
index 0000000000000000000000000000000000000000..cf16621863693b5fe969da059c5d789efdf95a46
--- /dev/null
+++ b/ash/test/test_launcher_delegate.cc
@@ -0,0 +1,91 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ash/test/test_launcher_delegate.h"
+
+#include "ash/launcher/launcher_model.h"
+#include "ash/wm/window_util.h"
+#include "base/utf_string_conversions.h"
+#include "grit/ui_resources.h"
+#include "ui/aura/window.h"
+
+namespace ash {
+namespace test {
+
+TestLauncherDelegate::TestLauncherDelegate(LauncherModel* model)
+ : model_(model) {
+}
+
+void TestLauncherDelegate::OnWillRemoveWindow(aura::Window* window) {
+ ash::LauncherID id = GetIDByWindow(window);
+ if (id == 0)
+ return;
+ int index = model_->ItemIndexByID(id);
+ DCHECK_NE(-1, index);
+ model_->RemoveItemAt(index);
+ window_to_id_.erase(window);
+}
+
+void TestLauncherDelegate::CreateNewTab() {
+}
+
+void TestLauncherDelegate::CreateNewWindow() {
+}
+
+void TestLauncherDelegate::ItemClicked(const ash::LauncherItem& item) {
+ aura::Window* window = GetWindowByID(item.id);
+ window->Show();
+ ash::wm::ActivateWindow(window);
+}
+
+int TestLauncherDelegate::GetBrowserShortcutResourceId() {
+ return IDR_AURA_LAUNCHER_BROWSER_SHORTCUT;
+}
+
+string16 TestLauncherDelegate::GetTitle(const ash::LauncherItem& item) {
+ return GetWindowByID(item.id)->title();
+}
+
+ui::MenuModel* TestLauncherDelegate::CreateContextMenu(
+ const ash::LauncherItem& item) {
+ return NULL;
+}
+
+ui::MenuModel* TestLauncherDelegate::CreateContextMenuForLauncher() {
+ return NULL;
+}
+
+ash::LauncherID TestLauncherDelegate::GetIDByWindow(aura::Window* window) {
+ WindowToID::const_iterator found = window_to_id_.find(window);
+ if (found == window_to_id_.end())
+ return 0;
+ return found->second;
+}
+
+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.
+ ash::LauncherItem item;
+ item.type = ash::TYPE_TABBED;
+ 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.
+ item.image.setConfig(SkBitmap::kARGB_8888_Config, 16, 16);
+ item.image.allocPixels();
+ model_->Add(item);
+ if (observed_windows_.find(window->parent()) == observed_windows_.end()) {
+ window->parent()->AddObserver(this);
sky 2012/04/19 00:05:40 You never remove this observer.
dcheng 2012/04/19 20:18:15 Done.
+ observed_windows_.insert(window->parent());
+ }
+}
+
+aura::Window* TestLauncherDelegate::GetWindowByID(ash::LauncherID id) {
+ for (WindowToID::const_iterator it = window_to_id_.begin();
+ it != window_to_id_.end();
+ it++) {
+ if (it->second == id)
+ return it->first;
+ }
+ return NULL;
+}
+
sky 2012/04/19 00:05:40 nit: only one newline.
dcheng 2012/04/19 20:18:15 Done.
+
+} // namespace test
+} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698