diff options
author | dcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-20 01:52:42 +0000 |
---|---|---|
committer | dcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-20 01:52:42 +0000 |
commit | e2dced44d39c58376c2cc5fdd85e78fb6cafec8d (patch) | |
tree | b2a4757e4511d9aec2e0e87345ece0feb6c8f280 /ash/test | |
parent | 150f339aee07be3bc9ea10f35c4d1b7e03459155 (diff) | |
download | chromium_src-e2dced44d39c58376c2cc5fdd85e78fb6cafec8d.zip chromium_src-e2dced44d39c58376c2cc5fdd85e78fb6cafec8d.tar.gz chromium_src-e2dced44d39c58376c2cc5fdd85e78fb6cafec8d.tar.bz2 |
Implement LauncherIconObserver.
This will be used to listen for changes in the launcher view so that panels can be correctly drawn over the corresponding launcher icon.
BUG=124115
TEST=aura_shell_unittests
Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=133089
Review URL: https://chromiumcodereview.appspot.com/10116011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@133120 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/test')
-rw-r--r-- | ash/test/test_launcher_delegate.cc | 104 | ||||
-rw-r--r-- | ash/test/test_launcher_delegate.h | 69 | ||||
-rw-r--r-- | ash/test/test_shell_delegate.cc | 3 |
3 files changed, 175 insertions, 1 deletions
diff --git a/ash/test/test_launcher_delegate.cc b/ash/test/test_launcher_delegate.cc new file mode 100644 index 0000000..5dab5c6 --- /dev/null +++ b/ash/test/test_launcher_delegate.cc @@ -0,0 +1,104 @@ +// 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::instance_ = NULL; + +TestLauncherDelegate::TestLauncherDelegate(LauncherModel* model) + : model_(model) { + CHECK(!instance_); + instance_ = this; +} + +TestLauncherDelegate::~TestLauncherDelegate() { + instance_ = NULL; +} + +void TestLauncherDelegate::AddLauncherItem(aura::Window* window) { + ash::LauncherItem item; + item.type = ash::TYPE_TABBED; + DCHECK(window_to_id_.find(window) == window_to_id_.end()); + window_to_id_[window] = model_->next_id(); + 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); + observed_windows_.insert(window->parent()); + } +} + +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); + ObservedWindows::iterator it = observed_windows_.find(window->parent()); + if (it != observed_windows_.end()) { + window->parent()->RemoveObserver(this); + observed_windows_.erase(it); + } +} + +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; +} + +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; +} + +} // namespace test +} // namespace ash diff --git a/ash/test/test_launcher_delegate.h b/ash/test/test_launcher_delegate.h new file mode 100644 index 0000000..289aacd --- /dev/null +++ b/ash/test/test_launcher_delegate.h @@ -0,0 +1,69 @@ +// 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. + +#ifndef ASH_TEST_TEST_LAUNCHER_DELEGATE_H_ +#define ASH_TEST_TEST_LAUNCHER_DELEGATE_H_ +#pragma once + +#include <map> +#include <set> + +#include "ash/launcher/launcher_delegate.h" +#include "base/compiler_specific.h" +#include "ui/aura/window_observer.h" + +namespace ash { + +class LauncherModel; + +namespace test { + +// Test implementation of LauncherDelegate. +// Tests may create icons for windows by calling AddLauncherItem +class TestLauncherDelegate : public LauncherDelegate, + public aura::WindowObserver { + public: + explicit TestLauncherDelegate(LauncherModel* model); + virtual ~TestLauncherDelegate(); + + void AddLauncherItem(aura::Window* window); + + static TestLauncherDelegate* instance() { return instance_; } + + // WindowObserver implementation + virtual void OnWillRemoveWindow(aura::Window* window) OVERRIDE; + + // LauncherDelegate implementation. + virtual void CreateNewTab() OVERRIDE; + virtual void CreateNewWindow() OVERRIDE; + virtual void ItemClicked(const LauncherItem& item) OVERRIDE; + virtual int GetBrowserShortcutResourceId() OVERRIDE; + virtual string16 GetTitle(const LauncherItem& item) OVERRIDE; + virtual ui::MenuModel* CreateContextMenu(const LauncherItem& item) OVERRIDE; + virtual ui::MenuModel* CreateContextMenuForLauncher() OVERRIDE; + virtual ash::LauncherID GetIDByWindow(aura::Window* window) OVERRIDE; + + private: + typedef std::map<aura::Window*, ash::LauncherID> WindowToID; + typedef std::set<aura::Window*> ObservedWindows; + + static TestLauncherDelegate* instance_; + + aura::Window* GetWindowByID(ash::LauncherID id); + + LauncherModel* model_; + + // Maps from window to the id we gave it. + WindowToID window_to_id_; + + // Parent windows we are watching. + ObservedWindows observed_windows_; + + DISALLOW_COPY_AND_ASSIGN(TestLauncherDelegate); +}; + +} // namespace test +} // namespace ash + +#endif // ASH_TEST_TEST_LAUNCHER_DELEGATE diff --git a/ash/test/test_shell_delegate.cc b/ash/test/test_shell_delegate.cc index dfb1112..d24d34b 100644 --- a/ash/test/test_shell_delegate.cc +++ b/ash/test/test_shell_delegate.cc @@ -9,6 +9,7 @@ #include "ash/screenshot_delegate.h" #include "ash/shell.h" #include "ash/shell_window_ids.h" +#include "ash/test/test_launcher_delegate.h" #include "grit/ui_resources.h" #include "ui/aura/window.h" @@ -58,7 +59,7 @@ void TestShellDelegate::StartPartialScreenshot( LauncherDelegate* TestShellDelegate::CreateLauncherDelegate( ash::LauncherModel* model) { - return NULL; + return new TestLauncherDelegate(model); } SystemTrayDelegate* TestShellDelegate::CreateSystemTrayDelegate( |