| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/app_list/app_list.h" | 5 #include "ash/app_list/app_list.h" |
| 6 | 6 |
| 7 #include "ash/app_list/app_list_model.h" | |
| 8 #include "ash/app_list/app_list_view.h" | 7 #include "ash/app_list/app_list_view.h" |
| 9 #include "ash/ash_switches.h" | 8 #include "ash/ash_switches.h" |
| 10 #include "ash/shell_delegate.h" | 9 #include "ash/shell_delegate.h" |
| 11 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| 12 #include "ash/shell_window_ids.h" | 11 #include "ash/shell_window_ids.h" |
| 13 #include "base/bind.h" | 12 #include "base/bind.h" |
| 14 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 15 #include "ui/aura/event.h" | 14 #include "ui/aura/event.h" |
| 16 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
| 17 #include "ui/gfx/compositor/scoped_layer_animation_settings.h" | 16 #include "ui/gfx/compositor/scoped_layer_animation_settings.h" |
| 18 #include "ui/gfx/screen.h" | 17 #include "ui/gfx/screen.h" |
| 19 | 18 |
| 20 namespace ash { | 19 namespace ash { |
| 21 namespace internal { | 20 namespace internal { |
| 22 | 21 |
| 23 namespace { | 22 namespace { |
| 24 | 23 |
| 25 // Gets preferred bounds of app list window in show/hide state. | 24 // Gets preferred bounds of app list window. |
| 26 gfx::Rect GetPreferredBounds(bool show) { | 25 gfx::Rect GetPreferredBounds() { |
| 27 // The y-axis offset used at the beginning of showing animation. | |
| 28 static const int kMoveUpAnimationOffset = 50; | |
| 29 | |
| 30 gfx::Point cursor = gfx::Screen::GetCursorScreenPoint(); | 26 gfx::Point cursor = gfx::Screen::GetCursorScreenPoint(); |
| 31 gfx::Rect work_area = gfx::Screen::GetMonitorWorkAreaNearestPoint(cursor); | 27 return gfx::Screen::GetMonitorAreaNearestPoint(cursor); |
| 32 gfx::Rect widget_bounds(work_area); | |
| 33 widget_bounds.Inset(100, 100); | |
| 34 if (!show) | |
| 35 widget_bounds.Offset(0, kMoveUpAnimationOffset); | |
| 36 | |
| 37 return widget_bounds; | |
| 38 } | 28 } |
| 39 | 29 |
| 40 ui::Layer* GetLayer(views::Widget* widget) { | 30 ui::Layer* GetLayer(views::Widget* widget) { |
| 41 return widget->GetNativeView()->layer(); | 31 return widget->GetNativeView()->layer(); |
| 42 } | 32 } |
| 43 | 33 |
| 44 } // namespace | 34 } // namespace |
| 45 | 35 |
| 46 //////////////////////////////////////////////////////////////////////////////// | 36 //////////////////////////////////////////////////////////////////////////////// |
| 47 // AppList, public: | 37 // AppList, public: |
| 48 | 38 |
| 49 AppList::AppList() : is_visible_(false), widget_(NULL) { | 39 AppList::AppList() : is_visible_(false), widget_(NULL) { |
| 50 } | 40 } |
| 51 | 41 |
| 52 AppList::~AppList() { | 42 AppList::~AppList() { |
| 53 ResetWidget(); | 43 ResetWidget(); |
| 54 } | 44 } |
| 55 | 45 |
| 56 void AppList::SetVisible(bool visible) { | 46 void AppList::SetVisible(bool visible) { |
| 57 if (visible == is_visible_) | 47 if (visible == is_visible_) |
| 58 return; | 48 return; |
| 59 | 49 |
| 60 is_visible_ = visible; | 50 is_visible_ = visible; |
| 61 | 51 |
| 62 if (widget_) { | 52 if (widget_) { |
| 63 ScheduleAnimation(); | 53 ScheduleAnimation(); |
| 64 } else if (is_visible_) { | 54 } else if (is_visible_) { |
| 65 scoped_ptr<AppListModel> model(new AppListModel); | |
| 66 Shell::GetInstance()->delegate()->BuildAppListModel(model.get()); | |
| 67 | |
| 68 // AppListModel and AppListViewDelegate are owned by AppListView. They | 55 // AppListModel and AppListViewDelegate are owned by AppListView. They |
| 69 // will be released with AppListView on close. | 56 // will be released with AppListView on close. |
| 70 AppListView* app_list_view = new AppListView( | 57 AppListView* app_list_view = new AppListView( |
| 71 model.release(), | |
| 72 Shell::GetInstance()->delegate()->CreateAppListViewDelegate(), | 58 Shell::GetInstance()->delegate()->CreateAppListViewDelegate(), |
| 73 GetPreferredBounds(false)); | 59 GetPreferredBounds()); |
| 74 SetWidget(app_list_view->GetWidget()); | 60 SetWidget(app_list_view->GetWidget()); |
| 75 } | 61 } |
| 76 } | 62 } |
| 77 | 63 |
| 78 bool AppList::IsVisible() { | 64 bool AppList::IsVisible() { |
| 79 return widget_ && widget_->IsVisible(); | 65 return widget_ && widget_->IsVisible(); |
| 80 } | 66 } |
| 81 | 67 |
| 82 //////////////////////////////////////////////////////////////////////////////// | 68 //////////////////////////////////////////////////////////////////////////////// |
| 83 // AppList, private: | 69 // AppList, private: |
| 84 | 70 |
| 85 void AppList::SetWidget(views::Widget* widget) { | 71 void AppList::SetWidget(views::Widget* widget) { |
| 86 DCHECK(widget_ == NULL); | 72 DCHECK(widget_ == NULL); |
| 87 | 73 |
| 88 if (is_visible_) { | 74 if (is_visible_) { |
| 89 widget_ = widget; | 75 widget_ = widget; |
| 90 widget_->AddObserver(this); | 76 widget_->AddObserver(this); |
| 91 Shell::GetInstance()->AddRootWindowEventFilter(this); | 77 Shell::GetInstance()->AddRootWindowEventFilter(this); |
| 92 | 78 |
| 93 widget_->SetBounds(GetPreferredBounds(false)); | |
| 94 widget_->SetOpacity(0); | 79 widget_->SetOpacity(0); |
| 95 ScheduleAnimation(); | 80 ScheduleAnimation(); |
| 96 | 81 |
| 97 widget_->Show(); | 82 widget_->Show(); |
| 83 widget_->Activate(); |
| 98 } else { | 84 } else { |
| 99 widget->Close(); | 85 widget->Close(); |
| 100 } | 86 } |
| 101 } | 87 } |
| 102 | 88 |
| 103 void AppList::ResetWidget() { | 89 void AppList::ResetWidget() { |
| 104 if (!widget_) | 90 if (!widget_) |
| 105 return; | 91 return; |
| 106 | 92 |
| 107 widget_->RemoveObserver(this); | 93 widget_->RemoveObserver(this); |
| 108 GetLayer(widget_)->GetAnimator()->RemoveObserver(this); | 94 GetLayer(widget_)->GetAnimator()->RemoveObserver(this); |
| 109 Shell::GetInstance()->RemoveRootWindowEventFilter(this); | 95 Shell::GetInstance()->RemoveRootWindowEventFilter(this); |
| 110 widget_ = NULL; | 96 widget_ = NULL; |
| 111 } | 97 } |
| 112 | 98 |
| 113 void AppList::ScheduleAnimation() { | 99 void AppList::ScheduleAnimation() { |
| 114 aura::Window* default_container = Shell::GetInstance()->GetContainer( | 100 aura::Window* default_container = Shell::GetInstance()->GetContainer( |
| 115 internal::kShellWindowId_DefaultContainer); | 101 internal::kShellWindowId_DefaultContainer); |
| 116 // |default_container| could be NULL during Shell shutdown. | 102 // |default_container| could be NULL during Shell shutdown. |
| 117 if (!default_container) | 103 if (!default_container) |
| 118 return; | 104 return; |
| 119 | 105 |
| 120 ui::Layer* layer = GetLayer(widget_); | 106 ui::Layer* layer = GetLayer(widget_); |
| 121 | 107 |
| 122 // Stop observing previous animation. | 108 // Stop observing previous animation. |
| 123 StopObservingImplicitAnimations(); | 109 StopObservingImplicitAnimations(); |
| 124 | 110 |
| 125 ui::ScopedLayerAnimationSettings app_list_animation(layer->GetAnimator()); | 111 ui::ScopedLayerAnimationSettings app_list_animation(layer->GetAnimator()); |
| 126 app_list_animation.AddObserver(this); | 112 app_list_animation.AddObserver(this); |
| 127 layer->SetBounds(GetPreferredBounds(is_visible_)); | |
| 128 layer->SetOpacity(is_visible_ ? 1.0 : 0.0); | 113 layer->SetOpacity(is_visible_ ? 1.0 : 0.0); |
| 129 | 114 |
| 130 ui::Layer* default_container_layer = default_container->layer(); | 115 ui::Layer* default_container_layer = default_container->layer(); |
| 131 ui::ScopedLayerAnimationSettings default_container_animation( | 116 ui::ScopedLayerAnimationSettings default_container_animation( |
| 132 default_container_layer->GetAnimator()); | 117 default_container_layer->GetAnimator()); |
| 133 app_list_animation.AddObserver(this); | 118 app_list_animation.AddObserver(this); |
| 134 default_container_layer->SetOpacity(is_visible_ ? 0.0 : 1.0); | 119 default_container_layer->SetOpacity(is_visible_ ? 0.0 : 1.0); |
| 135 } | 120 } |
| 136 | 121 |
| 137 //////////////////////////////////////////////////////////////////////////////// | 122 //////////////////////////////////////////////////////////////////////////////// |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 } | 167 } |
| 183 | 168 |
| 184 void AppList::OnWidgetActivationChanged(views::Widget* widget, bool active) { | 169 void AppList::OnWidgetActivationChanged(views::Widget* widget, bool active) { |
| 185 DCHECK(widget_ == widget); | 170 DCHECK(widget_ == widget); |
| 186 if (widget_ && is_visible_ && !active) | 171 if (widget_ && is_visible_ && !active) |
| 187 SetVisible(false); | 172 SetVisible(false); |
| 188 } | 173 } |
| 189 | 174 |
| 190 } // namespace internal | 175 } // namespace internal |
| 191 } // namespace ash | 176 } // namespace ash |
| OLD | NEW |