OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "athena/wm/window_overview_mode.h" | 5 #include "athena/wm/window_overview_mode.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 27 matching lines...) Expand all Loading... |
38 } // namespace | 38 } // namespace |
39 | 39 |
40 DECLARE_WINDOW_PROPERTY_TYPE(WindowOverviewState*) | 40 DECLARE_WINDOW_PROPERTY_TYPE(WindowOverviewState*) |
41 DEFINE_OWNED_WINDOW_PROPERTY_KEY(WindowOverviewState, | 41 DEFINE_OWNED_WINDOW_PROPERTY_KEY(WindowOverviewState, |
42 kWindowOverviewState, | 42 kWindowOverviewState, |
43 NULL) | 43 NULL) |
44 namespace athena { | 44 namespace athena { |
45 | 45 |
46 namespace { | 46 namespace { |
47 | 47 |
| 48 bool ShouldShowWindowInOverviewMode(aura::Window* window) { |
| 49 return window->type() == ui::wm::WINDOW_TYPE_NORMAL; |
| 50 } |
| 51 |
48 // Sets the progress-state for the window in the overview mode. | 52 // Sets the progress-state for the window in the overview mode. |
49 void SetWindowProgress(aura::Window* window, float progress) { | 53 void SetWindowProgress(aura::Window* window, float progress) { |
50 WindowOverviewState* state = window->GetProperty(kWindowOverviewState); | 54 WindowOverviewState* state = window->GetProperty(kWindowOverviewState); |
51 gfx::Transform transform = | 55 gfx::Transform transform = |
52 gfx::Tween::TransformValueBetween(progress, state->top, state->bottom); | 56 gfx::Tween::TransformValueBetween(progress, state->top, state->bottom); |
53 window->SetTransform(transform); | 57 window->SetTransform(transform); |
54 state->progress = progress; | 58 state->progress = progress; |
55 } | 59 } |
56 | 60 |
57 // Resets the overview-related state for |window|. | 61 // Resets the overview-related state for |window|. |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 | 107 |
104 // Prepare the desired transforms for all the windows, and set the initial | 108 // Prepare the desired transforms for all the windows, and set the initial |
105 // state on the windows. | 109 // state on the windows. |
106 ComputeTerminalStatesForAllWindows(); | 110 ComputeTerminalStatesForAllWindows(); |
107 SetInitialWindowStates(); | 111 SetInitialWindowStates(); |
108 } | 112 } |
109 | 113 |
110 virtual ~WindowOverviewModeImpl() { | 114 virtual ~WindowOverviewModeImpl() { |
111 container_->set_target_handler(container_->delegate()); | 115 container_->set_target_handler(container_->delegate()); |
112 | 116 |
113 aura::Window::Windows windows = container_->children(); | 117 const aura::Window::Windows& windows = container_->children(); |
114 if (windows.empty()) | 118 for (aura::Window::Windows::const_iterator iter = windows.begin(); |
115 return; | 119 iter != windows.end(); |
116 std::for_each(windows.begin(), windows.end(), &RestoreWindowState); | 120 ++iter) { |
| 121 if ((*iter)->GetProperty(kWindowOverviewState)) |
| 122 RestoreWindowState(*iter); |
| 123 } |
117 } | 124 } |
118 | 125 |
119 private: | 126 private: |
120 // Computes the transforms for all windows in both the topmost and bottom-most | 127 // Computes the transforms for all windows in both the topmost and bottom-most |
121 // positions. The transforms are set in the |kWindowOverviewState| property of | 128 // positions. The transforms are set in the |kWindowOverviewState| property of |
122 // the windows. | 129 // the windows. |
123 void ComputeTerminalStatesForAllWindows() { | 130 void ComputeTerminalStatesForAllWindows() { |
124 aura::Window::Windows windows = container_->children(); | 131 const aura::Window::Windows& windows = container_->children(); |
125 size_t window_count = windows.size(); | 132 size_t window_count = std::count_if(windows.begin(), windows.end(), |
| 133 ShouldShowWindowInOverviewMode); |
| 134 |
126 size_t index = 0; | 135 size_t index = 0; |
127 const gfx::Size container_size = container_->bounds().size(); | 136 const gfx::Size container_size = container_->bounds().size(); |
128 | 137 |
129 const int kGapBetweenWindowsBottom = 10; | 138 const int kGapBetweenWindowsBottom = 10; |
130 const int kGapBetweenWindowsTop = 5; | 139 const int kGapBetweenWindowsTop = 5; |
131 const float kMinScale = 0.6f; | 140 const float kMinScale = 0.6f; |
132 const float kMaxScale = 0.95f; | 141 const float kMaxScale = 0.95f; |
133 | 142 |
134 for (aura::Window::Windows::reverse_iterator iter = windows.rbegin(); | 143 for (aura::Window::Windows::const_reverse_iterator iter = windows.rbegin(); |
135 iter != windows.rend(); | 144 iter != windows.rend(); |
136 ++iter, ++index) { | 145 ++iter) { |
137 aura::Window* window = (*iter); | 146 aura::Window* window = (*iter); |
| 147 if (!ShouldShowWindowInOverviewMode(window)) |
| 148 continue; |
138 | 149 |
139 gfx::Transform top_transform; | 150 gfx::Transform top_transform; |
140 int top = (window_count - index - 1) * kGapBetweenWindowsTop; | 151 int top = (window_count - index - 1) * kGapBetweenWindowsTop; |
141 float x_translate = container_size.width() * (1 - kMinScale) / 2.; | 152 float x_translate = container_size.width() * (1 - kMinScale) / 2.; |
142 top_transform.Translate(x_translate, top); | 153 top_transform.Translate(x_translate, top); |
143 top_transform.Scale(kMinScale, kMinScale); | 154 top_transform.Scale(kMinScale, kMinScale); |
144 | 155 |
145 gfx::Transform bottom_transform; | 156 gfx::Transform bottom_transform; |
146 int bottom = GetScrollableHeight() - (index * kGapBetweenWindowsBottom); | 157 int bottom = GetScrollableHeight() - (index * kGapBetweenWindowsBottom); |
147 x_translate = container_size.width() * (1 - kMaxScale) / 2.; | 158 x_translate = container_size.width() * (1 - kMaxScale) / 2.; |
148 bottom_transform.Translate(x_translate, bottom - window->bounds().y()); | 159 bottom_transform.Translate(x_translate, bottom - window->bounds().y()); |
149 bottom_transform.Scale(kMaxScale, kMaxScale); | 160 bottom_transform.Scale(kMaxScale, kMaxScale); |
150 | 161 |
151 WindowOverviewState* state = new WindowOverviewState; | 162 WindowOverviewState* state = new WindowOverviewState; |
152 state->top = top_transform; | 163 state->top = top_transform; |
153 state->bottom = bottom_transform; | 164 state->bottom = bottom_transform; |
154 state->progress = 0.f; | 165 state->progress = 0.f; |
155 state->shadow = CreateShadowForWindow(window); | 166 state->shadow = CreateShadowForWindow(window); |
156 window->SetProperty(kWindowOverviewState, state); | 167 window->SetProperty(kWindowOverviewState, state); |
| 168 |
| 169 index++; |
157 } | 170 } |
158 } | 171 } |
159 | 172 |
160 // Sets the initial position for the windows for the overview mode. | 173 // Sets the initial position for the windows for the overview mode. |
161 void SetInitialWindowStates() { | 174 void SetInitialWindowStates() { |
162 aura::Window::Windows windows = container_->children(); | |
163 size_t window_count = windows.size(); | |
164 // The initial overview state of the topmost three windows. | 175 // The initial overview state of the topmost three windows. |
165 const float kInitialProgress[] = { 0.5f, 0.05f, 0.01f }; | 176 const float kInitialProgress[] = { 0.5f, 0.05f, 0.01f }; |
166 for (size_t i = 0; i < window_count; ++i) { | 177 size_t index = 0; |
| 178 const aura::Window::Windows& windows = container_->children(); |
| 179 for (aura::Window::Windows::const_reverse_iterator iter = windows.rbegin(); |
| 180 iter != windows.rend(); |
| 181 ++iter) { |
| 182 aura::Window* window = (*iter); |
| 183 if (!window->GetProperty(kWindowOverviewState)) |
| 184 continue; |
| 185 |
167 float progress = 0.f; | 186 float progress = 0.f; |
168 aura::Window* window = windows[window_count - 1 - i]; | 187 if (index < arraysize(kInitialProgress)) |
169 if (i < arraysize(kInitialProgress)) | 188 progress = kInitialProgress[index]; |
170 progress = kInitialProgress[i]; | |
171 | 189 |
172 scoped_refptr<ui::LayerAnimator> animator = | 190 scoped_refptr<ui::LayerAnimator> animator = |
173 window->layer()->GetAnimator(); | 191 window->layer()->GetAnimator(); |
174 | 192 |
175 // Unset any in-progress animation. | 193 // Unset any in-progress animation. |
176 { | 194 { |
177 ui::ScopedLayerAnimationSettings settings(animator); | 195 ui::ScopedLayerAnimationSettings settings(animator); |
178 settings.SetPreemptionStrategy( | 196 settings.SetPreemptionStrategy( |
179 ui::LayerAnimator::IMMEDIATELY_SET_NEW_TARGET); | 197 ui::LayerAnimator::IMMEDIATELY_SET_NEW_TARGET); |
180 window->Show(); | 198 window->Show(); |
181 window->SetTransform(gfx::Transform()); | 199 window->SetTransform(gfx::Transform()); |
182 } | 200 } |
183 // Setup the animation. | 201 // Setup the animation. |
184 { | 202 { |
185 ui::ScopedLayerAnimationSettings settings(animator); | 203 ui::ScopedLayerAnimationSettings settings(animator); |
186 settings.SetPreemptionStrategy( | 204 settings.SetPreemptionStrategy( |
187 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 205 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
188 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(250)); | 206 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(250)); |
189 SetWindowProgress(window, progress); | 207 SetWindowProgress(window, progress); |
190 } | 208 } |
| 209 index++; |
191 } | 210 } |
192 } | 211 } |
193 | 212 |
194 scoped_ptr<wm::Shadow> CreateShadowForWindow(aura::Window* window) { | 213 scoped_ptr<wm::Shadow> CreateShadowForWindow(aura::Window* window) { |
195 scoped_ptr<wm::Shadow> shadow(new wm::Shadow()); | 214 scoped_ptr<wm::Shadow> shadow(new wm::Shadow()); |
196 shadow->Init(wm::Shadow::STYLE_ACTIVE); | 215 shadow->Init(wm::Shadow::STYLE_ACTIVE); |
197 shadow->SetContentBounds(gfx::Rect(window->bounds().size())); | 216 shadow->SetContentBounds(gfx::Rect(window->bounds().size())); |
198 shadow->layer()->SetVisible(true); | 217 shadow->layer()->SetVisible(true); |
199 window->layer()->Add(shadow->layer()); | 218 window->layer()->Add(shadow->layer()); |
200 return shadow.Pass(); | 219 return shadow.Pass(); |
(...skipping 14 matching lines...) Expand all Loading... |
215 targeter->FindTargetForLocatedEvent(container_, event)); | 234 targeter->FindTargetForLocatedEvent(container_, event)); |
216 while (target && target->parent() != container_) | 235 while (target && target->parent() != container_) |
217 target = target->parent(); | 236 target = target->parent(); |
218 return target; | 237 return target; |
219 } | 238 } |
220 | 239 |
221 // Scroll the window list by |delta_y| amount. |delta_y| is negative when | 240 // Scroll the window list by |delta_y| amount. |delta_y| is negative when |
222 // scrolling up; and positive when scrolling down. | 241 // scrolling up; and positive when scrolling down. |
223 void DoScroll(float delta_y) { | 242 void DoScroll(float delta_y) { |
224 const float kEpsilon = 1e-3f; | 243 const float kEpsilon = 1e-3f; |
225 aura::Window::Windows windows = container_->children(); | |
226 float delta_y_p = std::abs(delta_y) / GetScrollableHeight(); | 244 float delta_y_p = std::abs(delta_y) / GetScrollableHeight(); |
| 245 const aura::Window::Windows& windows = container_->children(); |
227 if (delta_y < 0) { | 246 if (delta_y < 0) { |
228 // Scroll up. Start with the top-most (i.e. behind-most in terms of | 247 // Scroll up. Start with the top-most (i.e. behind-most in terms of |
229 // z-index) window, and try to scroll them up. | 248 // z-index) window, and try to scroll them up. |
230 for (aura::Window::Windows::iterator iter = windows.begin(); | 249 for (aura::Window::Windows::const_iterator iter = windows.begin(); |
231 delta_y_p > kEpsilon && iter != windows.end(); | 250 delta_y_p > kEpsilon && iter != windows.end(); |
232 ++iter) { | 251 ++iter) { |
233 aura::Window* window = (*iter); | 252 aura::Window* window = (*iter); |
234 WindowOverviewState* state = window->GetProperty(kWindowOverviewState); | 253 WindowOverviewState* state = window->GetProperty(kWindowOverviewState); |
| 254 if (!state) |
| 255 continue; |
235 if (state->progress > kEpsilon) { | 256 if (state->progress > kEpsilon) { |
236 // It is possible to scroll |window| up. Scroll it up, and update | 257 // It is possible to scroll |window| up. Scroll it up, and update |
237 // |delta_y_p| for the next window. | 258 // |delta_y_p| for the next window. |
238 float apply = delta_y_p * state->progress; | 259 float apply = delta_y_p * state->progress; |
239 SetWindowProgress(window, std::max(0.f, state->progress - apply * 3)); | 260 SetWindowProgress(window, std::max(0.f, state->progress - apply * 3)); |
240 delta_y_p -= apply; | 261 delta_y_p -= apply; |
241 } | 262 } |
242 } | 263 } |
243 } else { | 264 } else { |
244 // Scroll down. Start with the bottom-most (i.e. front-most in terms of | 265 // Scroll down. Start with the bottom-most (i.e. front-most in terms of |
245 // z-index) window, and try to scroll them down. | 266 // z-index) window, and try to scroll them down. |
246 for (aura::Window::Windows::reverse_iterator iter = windows.rbegin(); | 267 for (aura::Window::Windows::const_reverse_iterator iter = |
| 268 windows.rbegin(); |
247 delta_y_p > kEpsilon && iter != windows.rend(); | 269 delta_y_p > kEpsilon && iter != windows.rend(); |
248 ++iter) { | 270 ++iter) { |
249 aura::Window* window = (*iter); | 271 aura::Window* window = (*iter); |
250 WindowOverviewState* state = window->GetProperty(kWindowOverviewState); | 272 WindowOverviewState* state = window->GetProperty(kWindowOverviewState); |
| 273 if (!state) |
| 274 continue; |
251 if (1.f - state->progress > kEpsilon) { | 275 if (1.f - state->progress > kEpsilon) { |
252 // It is possible to scroll |window| down. Scroll it down, and update | 276 // It is possible to scroll |window| down. Scroll it down, and update |
253 // |delta_y_p| for the next window. | 277 // |delta_y_p| for the next window. |
254 SetWindowProgress(window, std::min(1.f, state->progress + delta_y_p)); | 278 SetWindowProgress(window, std::min(1.f, state->progress + delta_y_p)); |
255 delta_y_p /= 2.f; | 279 delta_y_p /= 2.f; |
256 } | 280 } |
257 } | 281 } |
258 } | 282 } |
259 } | 283 } |
260 | 284 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 | 328 |
305 // static | 329 // static |
306 scoped_ptr<WindowOverviewMode> WindowOverviewMode::Create( | 330 scoped_ptr<WindowOverviewMode> WindowOverviewMode::Create( |
307 aura::Window* container, | 331 aura::Window* container, |
308 WindowOverviewModeDelegate* delegate) { | 332 WindowOverviewModeDelegate* delegate) { |
309 return scoped_ptr<WindowOverviewMode>( | 333 return scoped_ptr<WindowOverviewMode>( |
310 new WindowOverviewModeImpl(container, delegate)); | 334 new WindowOverviewModeImpl(container, delegate)); |
311 } | 335 } |
312 | 336 |
313 } // namespace athena | 337 } // namespace athena |
OLD | NEW |