diff options
author | xiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-30 14:53:34 +0000 |
---|---|---|
committer | xiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-30 14:53:34 +0000 |
commit | 4f08470c76d8bb2b8959d06eac0f58671940b395 (patch) | |
tree | 67cbfca6085cc3c2f8b28041d6be44655e8efd3f /ash/wm/app_list_controller.cc | |
parent | 61f790d9313c405c54159dd65f4dc473fd0c43fa (diff) | |
download | chromium_src-4f08470c76d8bb2b8959d06eac0f58671940b395.zip chromium_src-4f08470c76d8bb2b8959d06eac0f58671940b395.tar.gz chromium_src-4f08470c76d8bb2b8959d06eac0f58671940b395.tar.bz2 |
ash: Update app list button.
- Update the icons assets;
- Make app list button a ToggleImageButton and wire its
toggle state with app list UI visibility;
- Make app list button icon vertically center aligned and
get rid of the special handling;
- Expose toggled state from ToggleImageButton so that it
could be checked in test;
BUG=235994
R=sky@chromium.org
Review URL: https://codereview.chromium.org/13993027
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@197366 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/wm/app_list_controller.cc')
-rw-r--r-- | ash/wm/app_list_controller.cc | 61 |
1 files changed, 46 insertions, 15 deletions
diff --git a/ash/wm/app_list_controller.cc b/ash/wm/app_list_controller.cc index 7fcf76c..6776b60 100644 --- a/ash/wm/app_list_controller.cc +++ b/ash/wm/app_list_controller.cc @@ -10,6 +10,7 @@ #include "ash/shell.h" #include "ash/shell_delegate.h" #include "ash/shell_window_ids.h" +#include "ash/wm/app_list_controller_observer.h" #include "ash/wm/property_util.h" #include "ui/app_list/app_list_constants.h" #include "ui/app_list/pagination_model.h" @@ -52,10 +53,11 @@ views::BubbleBorder::Arrow GetBubbleArrow(aura::Window* window) { views::BubbleBorder::TOP_CENTER); } -// Offset given |rect| towards shelf. -gfx::Rect OffsetTowardsShelf(const gfx::Rect& rect, views::Widget* widget) { - DCHECK(Shell::HasInstance()); - ShelfAlignment shelf_alignment = Shell::GetInstance()->GetShelfAlignment( +// Offsets the given |rect| towards shelf. +gfx::Rect OffsetTowardsShelf(Shell* shell, + const gfx::Rect& rect, + views::Widget* widget) { + ShelfAlignment shelf_alignment = shell->GetShelfAlignment( widget->GetNativeView()->GetRootWindow()); gfx::Rect offseted(rect); switch (shelf_alignment) { @@ -81,23 +83,31 @@ gfx::Rect OffsetTowardsShelf(const gfx::Rect& rect, views::Widget* widget) { //////////////////////////////////////////////////////////////////////////////// // AppListController, public: -AppListController::AppListController() - : pagination_model_(new app_list::PaginationModel), +AppListController::AppListController(Shell* shell) + : shell_(shell), + pagination_model_(new app_list::PaginationModel), is_visible_(false), view_(NULL), should_snap_back_(false) { - Shell::GetInstance()->AddShellObserver(this); + shell_->AddShellObserver(this); pagination_model_->AddObserver(this); } AppListController::~AppListController() { + Shutdown(); + pagination_model_->RemoveObserver(this); +} + +void AppListController::Shutdown() { // Ensures app list view goes before the controller since pagination model // lives in the controller and app list view would access it on destruction. if (view_ && view_->GetWidget()) view_->GetWidget()->CloseNow(); - Shell::GetInstance()->RemoveShellObserver(this); - pagination_model_->RemoveObserver(this); + if (shell_) { + shell_->RemoveShellObserver(this); + shell_ = NULL; + } } void AppListController::SetVisible(bool visible, aura::Window* window) { @@ -111,14 +121,18 @@ void AppListController::SetVisible(bool visible, aura::Window* window) { Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager()-> UpdateAutoHideState(); + // Determine the root window to show the UI. + aura::RootWindow* root_window = + window ? window->GetRootWindow() : Shell::GetActiveRootWindow(); + if (view_) { ScheduleAnimation(); } else if (is_visible_) { // AppListModel and AppListViewDelegate are owned by AppListView. They // will be released with AppListView on close. app_list::AppListView* view = new app_list::AppListView( - Shell::GetInstance()->delegate()->CreateAppListViewDelegate()); - aura::Window* container = GetRootWindowController(window->GetRootWindow())-> + shell_->delegate()->CreateAppListViewDelegate()); + aura::Window* container = GetRootWindowController(root_window)-> GetContainer(kShellWindowId_AppListContainer); view->InitAsBubble( container, @@ -129,16 +143,32 @@ void AppListController::SetVisible(bool visible, aura::Window* window) { true /* border_accepts_events */); SetView(view); } + + FOR_EACH_OBSERVER(AppListControllerObserver, + observers_, + OnAppLauncherVisibilityChanged(is_visible_, root_window)); } bool AppListController::IsVisible() const { return view_ && view_->GetWidget()->IsVisible(); } +void AppListController::Toggle(aura::Window* window) { + SetVisible(!IsVisible(), window); +} + aura::Window* AppListController::GetWindow() { return is_visible_ && view_ ? view_->GetWidget()->GetNativeWindow() : NULL; } +void AppListController::AddObserver(AppListControllerObserver* observer) { + observers_.AddObserver(observer); +} + +void AppListController::RemoveObserver(AppListControllerObserver* observer) { + observers_.RemoveObserver(observer); +} + //////////////////////////////////////////////////////////////////////////////// // AppListController, private: @@ -149,7 +179,7 @@ void AppListController::SetView(app_list::AppListView* view) { view_ = view; views::Widget* widget = view_->GetWidget(); widget->AddObserver(this); - Shell::GetInstance()->AddPreTargetHandler(this); + shell_->AddPreTargetHandler(this); Launcher::ForWindow(widget->GetNativeWindow())->AddIconObserver(this); widget->GetNativeView()->GetRootWindow()->AddRootWindowObserver(this); aura::client::GetFocusClient(widget->GetNativeView())->AddObserver(this); @@ -164,7 +194,7 @@ void AppListController::ResetView() { views::Widget* widget = view_->GetWidget(); widget->RemoveObserver(this); GetLayer(widget)->GetAnimator()->RemoveObserver(this); - Shell::GetInstance()->RemovePreTargetHandler(this); + shell_->RemovePreTargetHandler(this); Launcher::ForWindow(widget->GetNativeWindow())->RemoveIconObserver(this); widget->GetNativeView()->GetRootWindow()->RemoveRootWindowObserver(this); aura::client::GetFocusClient(widget->GetNativeView())->RemoveObserver(this); @@ -182,9 +212,10 @@ void AppListController::ScheduleAnimation() { gfx::Rect target_bounds; if (is_visible_) { target_bounds = widget->GetWindowBoundsInScreen(); - widget->SetBounds(OffsetTowardsShelf(target_bounds, widget)); + widget->SetBounds(OffsetTowardsShelf(shell_, target_bounds, widget)); } else { - target_bounds = OffsetTowardsShelf(widget->GetWindowBoundsInScreen(), + target_bounds = OffsetTowardsShelf(shell_, + widget->GetWindowBoundsInScreen(), widget); } |