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" | |
10 #include "ash/shell_delegate.h" | 8 #include "ash/shell_delegate.h" |
11 #include "ash/shell.h" | 9 #include "ash/shell.h" |
12 #include "ash/shell_window_ids.h" | 10 #include "ash/shell_window_ids.h" |
13 #include "base/bind.h" | |
14 #include "base/command_line.h" | |
15 #include "ui/aura/event.h" | 11 #include "ui/aura/event.h" |
| 12 #include "ui/aura/root_window.h" |
16 #include "ui/aura/window.h" | 13 #include "ui/aura/window.h" |
17 #include "ui/gfx/compositor/scoped_layer_animation_settings.h" | 14 #include "ui/gfx/compositor/scoped_layer_animation_settings.h" |
18 #include "ui/gfx/screen.h" | 15 #include "ui/gfx/screen.h" |
19 | 16 |
20 namespace ash { | 17 namespace ash { |
21 namespace internal { | 18 namespace internal { |
22 | 19 |
23 namespace { | 20 namespace { |
24 | 21 |
25 // Gets preferred bounds of app list window in show/hide state. | 22 // Gets preferred bounds of app list window. |
26 gfx::Rect GetPreferredBounds(bool show) { | 23 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(); | 24 gfx::Point cursor = gfx::Screen::GetCursorScreenPoint(); |
31 gfx::Rect work_area = gfx::Screen::GetMonitorWorkAreaNearestPoint(cursor); | 25 // Use full monitor rect so that the app list shade goes behind the launcher. |
32 gfx::Rect widget_bounds(work_area); | 26 return gfx::Screen::GetMonitorAreaNearestPoint(cursor); |
33 widget_bounds.Inset(100, 100); | |
34 if (!show) | |
35 widget_bounds.Offset(0, kMoveUpAnimationOffset); | |
36 | |
37 return widget_bounds; | |
38 } | 27 } |
39 | 28 |
40 ui::Layer* GetLayer(views::Widget* widget) { | 29 ui::Layer* GetLayer(views::Widget* widget) { |
41 return widget->GetNativeView()->layer(); | 30 return widget->GetNativeView()->layer(); |
42 } | 31 } |
43 | 32 |
44 } // namespace | 33 } // namespace |
45 | 34 |
46 //////////////////////////////////////////////////////////////////////////////// | 35 //////////////////////////////////////////////////////////////////////////////// |
47 // AppList, public: | 36 // AppList, public: |
48 | 37 |
49 AppList::AppList() : is_visible_(false), widget_(NULL) { | 38 AppList::AppList() : is_visible_(false), widget_(NULL) { |
50 } | 39 } |
51 | 40 |
52 AppList::~AppList() { | 41 AppList::~AppList() { |
53 ResetWidget(); | 42 ResetWidget(); |
54 } | 43 } |
55 | 44 |
56 void AppList::SetVisible(bool visible) { | 45 void AppList::SetVisible(bool visible) { |
57 if (visible == is_visible_) | 46 if (visible == is_visible_) |
58 return; | 47 return; |
59 | 48 |
60 is_visible_ = visible; | 49 is_visible_ = visible; |
61 | 50 |
62 if (widget_) { | 51 if (widget_) { |
63 ScheduleAnimation(); | 52 ScheduleAnimation(); |
64 } else if (is_visible_) { | 53 } 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 | 54 // AppListModel and AppListViewDelegate are owned by AppListView. They |
69 // will be released with AppListView on close. | 55 // will be released with AppListView on close. |
70 AppListView* app_list_view = new AppListView( | 56 AppListView* app_list_view = new AppListView( |
71 model.release(), | |
72 Shell::GetInstance()->delegate()->CreateAppListViewDelegate(), | 57 Shell::GetInstance()->delegate()->CreateAppListViewDelegate(), |
73 GetPreferredBounds(false)); | 58 GetPreferredBounds()); |
74 SetWidget(app_list_view->GetWidget()); | 59 SetWidget(app_list_view->GetWidget()); |
75 } | 60 } |
76 } | 61 } |
77 | 62 |
78 bool AppList::IsVisible() { | 63 bool AppList::IsVisible() { |
79 return widget_ && widget_->IsVisible(); | 64 return widget_ && widget_->IsVisible(); |
80 } | 65 } |
81 | 66 |
82 //////////////////////////////////////////////////////////////////////////////// | 67 //////////////////////////////////////////////////////////////////////////////// |
83 // AppList, private: | 68 // AppList, private: |
84 | 69 |
85 void AppList::SetWidget(views::Widget* widget) { | 70 void AppList::SetWidget(views::Widget* widget) { |
86 DCHECK(widget_ == NULL); | 71 DCHECK(widget_ == NULL); |
87 | 72 |
88 if (is_visible_) { | 73 if (is_visible_) { |
89 widget_ = widget; | 74 widget_ = widget; |
90 widget_->AddObserver(this); | 75 widget_->AddObserver(this); |
91 Shell::GetInstance()->AddRootWindowEventFilter(this); | 76 Shell::GetInstance()->AddRootWindowEventFilter(this); |
| 77 Shell::GetRootWindow()->AddRootWindowObserver(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); |
| 96 Shell::GetRootWindow()->RemoveRootWindowObserver(this); |
110 widget_ = NULL; | 97 widget_ = NULL; |
111 } | 98 } |
112 | 99 |
113 void AppList::ScheduleAnimation() { | 100 void AppList::ScheduleAnimation() { |
114 aura::Window* default_container = Shell::GetInstance()->GetContainer( | 101 aura::Window* default_container = Shell::GetInstance()->GetContainer( |
115 internal::kShellWindowId_DefaultContainer); | 102 internal::kShellWindowId_DefaultContainer); |
116 // |default_container| could be NULL during Shell shutdown. | 103 // |default_container| could be NULL during Shell shutdown. |
117 if (!default_container) | 104 if (!default_container) |
118 return; | 105 return; |
119 | 106 |
120 ui::Layer* layer = GetLayer(widget_); | 107 ui::Layer* layer = GetLayer(widget_); |
121 | 108 |
122 // Stop observing previous animation. | 109 // Stop observing previous animation. |
123 StopObservingImplicitAnimations(); | 110 StopObservingImplicitAnimations(); |
124 | 111 |
125 ui::ScopedLayerAnimationSettings app_list_animation(layer->GetAnimator()); | 112 ui::ScopedLayerAnimationSettings app_list_animation(layer->GetAnimator()); |
126 app_list_animation.AddObserver(this); | 113 app_list_animation.AddObserver(this); |
127 layer->SetBounds(GetPreferredBounds(is_visible_)); | |
128 layer->SetOpacity(is_visible_ ? 1.0 : 0.0); | 114 layer->SetOpacity(is_visible_ ? 1.0 : 0.0); |
129 | 115 |
130 ui::Layer* default_container_layer = default_container->layer(); | 116 ui::Layer* default_container_layer = default_container->layer(); |
131 ui::ScopedLayerAnimationSettings default_container_animation( | 117 ui::ScopedLayerAnimationSettings default_container_animation( |
132 default_container_layer->GetAnimator()); | 118 default_container_layer->GetAnimator()); |
133 app_list_animation.AddObserver(this); | 119 app_list_animation.AddObserver(this); |
134 default_container_layer->SetOpacity(is_visible_ ? 0.0 : 1.0); | 120 default_container_layer->SetOpacity(is_visible_ ? 0.0 : 1.0); |
135 } | 121 } |
136 | 122 |
137 //////////////////////////////////////////////////////////////////////////////// | 123 //////////////////////////////////////////////////////////////////////////////// |
138 // AppList, aura::EventFilter implementation: | 124 // AppList, aura::EventFilter implementation: |
139 | 125 |
140 bool AppList::PreHandleKeyEvent(aura::Window* target, | 126 bool AppList::PreHandleKeyEvent(aura::Window* target, |
141 aura::KeyEvent* event) { | 127 aura::KeyEvent* event) { |
142 return false; | 128 return false; |
143 } | 129 } |
144 | 130 |
145 bool AppList::PreHandleMouseEvent(aura::Window* target, | 131 bool AppList::PreHandleMouseEvent(aura::Window* target, |
146 aura::MouseEvent* event) { | 132 aura::MouseEvent* event) { |
147 if (widget_ && is_visible_ && event->type() == ui::ET_MOUSE_PRESSED) { | 133 if (widget_ && is_visible_ && event->type() == ui::ET_MOUSE_PRESSED) { |
148 aura::MouseEvent translated(*event, target, widget_->GetNativeView()); | 134 aura::MouseEvent translated(*event, target, widget_->GetNativeView()); |
149 if (!widget_->GetNativeView()->ContainsPoint(translated.location())) | 135 if (!widget_->GetNativeView()->ContainsPoint(translated.location())) |
150 SetVisible(false); | 136 SetVisible(false); |
151 } | 137 } |
152 return false; | 138 return false; |
153 } | 139 } |
154 | 140 |
155 ui::TouchStatus AppList::PreHandleTouchEvent(aura::Window* target, | 141 ui::TouchStatus AppList::PreHandleTouchEvent(aura::Window* target, |
156 aura::TouchEvent* event) { | 142 aura::TouchEvent* event) { |
157 return ui::TOUCH_STATUS_UNKNOWN; | 143 return ui::TOUCH_STATUS_UNKNOWN; |
158 } | 144 } |
159 | 145 |
160 ui::GestureStatus AppList::PreHandleGestureEvent( | 146 ui::GestureStatus AppList::PreHandleGestureEvent( |
161 aura::Window* target, | 147 aura::Window* target, |
162 aura::GestureEvent* event) { | 148 aura::GestureEvent* event) { |
163 return ui::GESTURE_STATUS_UNKNOWN; | 149 return ui::GESTURE_STATUS_UNKNOWN; |
164 } | 150 } |
165 | 151 |
166 //////////////////////////////////////////////////////////////////////////////// | 152 //////////////////////////////////////////////////////////////////////////////// |
| 153 // AppList, ura::RootWindowObserver implementation: |
| 154 void AppList::OnRootWindowResized(const gfx::Size& new_size) { |
| 155 if (widget_ && is_visible_) |
| 156 widget_->SetBounds(gfx::Rect(new_size)); |
| 157 } |
| 158 |
| 159 //////////////////////////////////////////////////////////////////////////////// |
167 // AppList, ui::ImplicitAnimationObserver implementation: | 160 // AppList, ui::ImplicitAnimationObserver implementation: |
168 | 161 |
169 void AppList::OnImplicitAnimationsCompleted() { | 162 void AppList::OnImplicitAnimationsCompleted() { |
170 if (!is_visible_ ) | 163 if (!is_visible_ ) |
171 widget_->Close(); | 164 widget_->Close(); |
172 } | 165 } |
173 | 166 |
174 //////////////////////////////////////////////////////////////////////////////// | 167 //////////////////////////////////////////////////////////////////////////////// |
175 // AppList, views::Widget::Observer implementation: | 168 // AppList, views::Widget::Observer implementation: |
176 | 169 |
177 void AppList::OnWidgetClosing(views::Widget* widget) { | 170 void AppList::OnWidgetClosing(views::Widget* widget) { |
178 DCHECK(widget_ == widget); | 171 DCHECK(widget_ == widget); |
179 if (is_visible_) | 172 if (is_visible_) |
180 SetVisible(false); | 173 SetVisible(false); |
181 ResetWidget(); | 174 ResetWidget(); |
182 } | 175 } |
183 | 176 |
184 void AppList::OnWidgetActivationChanged(views::Widget* widget, bool active) { | 177 void AppList::OnWidgetActivationChanged(views::Widget* widget, bool active) { |
185 DCHECK(widget_ == widget); | 178 DCHECK(widget_ == widget); |
186 if (widget_ && is_visible_ && !active) | 179 if (widget_ && is_visible_ && !active) |
187 SetVisible(false); | 180 SetVisible(false); |
188 } | 181 } |
189 | 182 |
190 } // namespace internal | 183 } // namespace internal |
191 } // namespace ash | 184 } // namespace ash |
OLD | NEW |