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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 } | 85 } |
86 | 86 |
87 aura::Window* target_; | 87 aura::Window* target_; |
88 DISALLOW_COPY_AND_ASSIGN(StaticWindowTargeter); | 88 DISALLOW_COPY_AND_ASSIGN(StaticWindowTargeter); |
89 }; | 89 }; |
90 | 90 |
91 class WindowOverviewModeImpl : public WindowOverviewMode, | 91 class WindowOverviewModeImpl : public WindowOverviewMode, |
92 public ui::EventHandler { | 92 public ui::EventHandler { |
93 public: | 93 public: |
94 WindowOverviewModeImpl(aura::Window* container, | 94 WindowOverviewModeImpl(aura::Window* container, |
95 aura::Window::Windows windows, | |
95 WindowOverviewModeDelegate* delegate) | 96 WindowOverviewModeDelegate* delegate) |
96 : container_(container), | 97 : container_(container), |
98 windows_(windows), | |
97 delegate_(delegate), | 99 delegate_(delegate), |
98 scoped_targeter_(new aura::ScopedWindowTargeter( | 100 scoped_targeter_(new aura::ScopedWindowTargeter( |
99 container, | 101 container, |
100 scoped_ptr<ui::EventTargeter>( | 102 scoped_ptr<ui::EventTargeter>( |
101 new StaticWindowTargeter(container)))) { | 103 new StaticWindowTargeter(container)))) { |
102 container_->set_target_handler(this); | 104 container_->set_target_handler(this); |
103 | 105 |
104 // Prepare the desired transforms for all the windows, and set the initial | 106 // Prepare the desired transforms for all the windows, and set the initial |
105 // state on the windows. | 107 // state on the windows. |
106 ComputeTerminalStatesForAllWindows(); | 108 ComputeTerminalStatesForAllWindows(); |
107 SetInitialWindowStates(); | 109 SetInitialWindowStates(); |
108 } | 110 } |
109 | 111 |
110 virtual ~WindowOverviewModeImpl() { | 112 virtual ~WindowOverviewModeImpl() { |
111 container_->set_target_handler(container_->delegate()); | 113 container_->set_target_handler(container_->delegate()); |
112 | 114 |
113 aura::Window::Windows windows = container_->children(); | 115 if (windows_.empty()) |
114 if (windows.empty()) | |
115 return; | 116 return; |
116 std::for_each(windows.begin(), windows.end(), &RestoreWindowState); | 117 std::for_each(windows_.begin(), windows_.end(), &RestoreWindowState); |
117 } | 118 } |
118 | 119 |
119 private: | 120 private: |
120 // Computes the transforms for all windows in both the topmost and bottom-most | 121 // Computes the transforms for all windows in both the topmost and bottom-most |
121 // positions. The transforms are set in the |kWindowOverviewState| property of | 122 // positions. The transforms are set in the |kWindowOverviewState| property of |
122 // the windows. | 123 // the windows. |
123 void ComputeTerminalStatesForAllWindows() { | 124 void ComputeTerminalStatesForAllWindows() { |
124 aura::Window::Windows windows = container_->children(); | 125 size_t window_count = windows_.size(); |
125 size_t window_count = windows.size(); | |
126 size_t index = 0; | 126 size_t index = 0; |
127 const gfx::Size container_size = container_->bounds().size(); | 127 const gfx::Size container_size = container_->bounds().size(); |
128 | 128 |
129 const int kGapBetweenWindowsBottom = 10; | 129 const int kGapBetweenWindowsBottom = 10; |
130 const int kGapBetweenWindowsTop = 5; | 130 const int kGapBetweenWindowsTop = 5; |
131 const float kMinScale = 0.6f; | 131 const float kMinScale = 0.6f; |
132 const float kMaxScale = 0.95f; | 132 const float kMaxScale = 0.95f; |
133 | 133 |
134 for (aura::Window::Windows::reverse_iterator iter = windows.rbegin(); | 134 for (aura::Window::Windows::const_reverse_iterator iter = windows_.rbegin(); |
135 iter != windows.rend(); | 135 iter != windows_.rend(); |
136 ++iter, ++index) { | 136 ++iter, ++index) { |
137 aura::Window* window = (*iter); | 137 aura::Window* window = (*iter); |
138 | 138 |
139 gfx::Transform top_transform; | 139 gfx::Transform top_transform; |
140 int top = (window_count - index - 1) * kGapBetweenWindowsTop; | 140 int top = (window_count - index - 1) * kGapBetweenWindowsTop; |
141 float x_translate = container_size.width() * (1 - kMinScale) / 2.; | 141 float x_translate = container_size.width() * (1 - kMinScale) / 2.; |
142 top_transform.Translate(x_translate, top); | 142 top_transform.Translate(x_translate, top); |
143 top_transform.Scale(kMinScale, kMinScale); | 143 top_transform.Scale(kMinScale, kMinScale); |
144 | 144 |
145 gfx::Transform bottom_transform; | 145 gfx::Transform bottom_transform; |
146 int bottom = GetScrollableHeight() - (index * kGapBetweenWindowsBottom); | 146 int bottom = GetScrollableHeight() - (index * kGapBetweenWindowsBottom); |
147 x_translate = container_size.width() * (1 - kMaxScale) / 2.; | 147 x_translate = container_size.width() * (1 - kMaxScale) / 2.; |
148 bottom_transform.Translate(x_translate, bottom - window->bounds().y()); | 148 bottom_transform.Translate(x_translate, bottom - window->bounds().y()); |
149 bottom_transform.Scale(kMaxScale, kMaxScale); | 149 bottom_transform.Scale(kMaxScale, kMaxScale); |
150 | 150 |
151 WindowOverviewState* state = new WindowOverviewState; | 151 WindowOverviewState* state = new WindowOverviewState; |
152 state->top = top_transform; | 152 state->top = top_transform; |
153 state->bottom = bottom_transform; | 153 state->bottom = bottom_transform; |
154 state->progress = 0.f; | 154 state->progress = 0.f; |
155 state->shadow = CreateShadowForWindow(window); | 155 state->shadow = CreateShadowForWindow(window); |
156 window->SetProperty(kWindowOverviewState, state); | 156 window->SetProperty(kWindowOverviewState, state); |
157 } | 157 } |
158 } | 158 } |
159 | 159 |
160 // Sets the initial position for the windows for the overview mode. | 160 // Sets the initial position for the windows for the overview mode. |
161 void SetInitialWindowStates() { | 161 void SetInitialWindowStates() { |
162 aura::Window::Windows windows = container_->children(); | 162 size_t window_count = windows_.size(); |
163 size_t window_count = windows.size(); | |
164 // The initial overview state of the topmost three windows. | 163 // The initial overview state of the topmost three windows. |
165 const float kInitialProgress[] = { 0.5f, 0.05f, 0.01f }; | 164 const float kInitialProgress[] = { 0.5f, 0.05f, 0.01f }; |
166 for (size_t i = 0; i < window_count; ++i) { | 165 for (size_t i = 0; i < window_count; ++i) { |
167 float progress = 0.f; | 166 float progress = 0.f; |
168 aura::Window* window = windows[window_count - 1 - i]; | 167 aura::Window* window = windows_[window_count - 1 - i]; |
169 if (i < arraysize(kInitialProgress)) | 168 if (i < arraysize(kInitialProgress)) |
170 progress = kInitialProgress[i]; | 169 progress = kInitialProgress[i]; |
171 | 170 |
172 scoped_refptr<ui::LayerAnimator> animator = | 171 scoped_refptr<ui::LayerAnimator> animator = |
173 window->layer()->GetAnimator(); | 172 window->layer()->GetAnimator(); |
174 | 173 |
175 // Unset any in-progress animation. | 174 // Unset any in-progress animation. |
176 { | 175 { |
177 ui::ScopedLayerAnimationSettings settings(animator); | 176 ui::ScopedLayerAnimationSettings settings(animator); |
178 settings.SetPreemptionStrategy( | 177 settings.SetPreemptionStrategy( |
179 ui::LayerAnimator::IMMEDIATELY_SET_NEW_TARGET); | 178 ui::LayerAnimator::IMMEDIATELY_SET_NEW_TARGET); |
180 window->Show(); | 179 window->Show(); |
181 window->SetTransform(gfx::Transform()); | 180 window->SetTransform(gfx::Transform()); |
182 } | 181 } |
183 // Setup the animation. | 182 // Setup the animation. |
184 { | 183 { |
185 ui::ScopedLayerAnimationSettings settings(animator); | 184 ui::ScopedLayerAnimationSettings settings(animator); |
186 settings.SetPreemptionStrategy( | 185 settings.SetPreemptionStrategy( |
187 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 186 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
188 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(250)); | 187 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(250)); |
189 SetWindowProgress(window, progress); | 188 SetWindowProgress(window, progress); |
190 } | 189 } |
191 } | 190 } |
192 } | 191 } |
193 | 192 |
194 scoped_ptr<wm::Shadow> CreateShadowForWindow(aura::Window* window) { | 193 scoped_ptr<wm::Shadow> CreateShadowForWindow(aura::Window* window) { |
195 scoped_ptr<wm::Shadow> shadow(new wm::Shadow()); | 194 scoped_ptr<wm::Shadow> shadow(new wm::Shadow()); |
196 shadow->Init(wm::Shadow::STYLE_ACTIVE); | 195 shadow->Init(wm::Shadow::STYLE_ACTIVE); |
197 shadow->SetContentBounds(gfx::Rect(window->bounds().size())); | 196 shadow->SetContentBounds(gfx::Rect(container_->bounds().size())); |
Jun Mukai
2014/08/05 21:13:39
Why this needs to be changed to container_? Is th
mfomitchev
2014/08/06 18:11:32
conainer_ is window's parent. The reason this was
Jun Mukai
2014/08/06 19:56:10
I got confused. Here's my understanding:
- contain
mfomitchev
2014/08/06 20:09:59
It's the split view transform, not the overview mo
Jun Mukai
2014/08/06 20:49:01
Okay
| |
198 shadow->layer()->SetVisible(true); | 197 shadow->layer()->SetVisible(true); |
199 window->layer()->Add(shadow->layer()); | 198 window->layer()->Add(shadow->layer()); |
200 return shadow.Pass(); | 199 return shadow.Pass(); |
201 } | 200 } |
202 | 201 |
203 aura::Window* SelectWindowAt(ui::LocatedEvent* event) { | 202 aura::Window* SelectWindowAt(ui::LocatedEvent* event) { |
204 CHECK_EQ(container_, event->target()); | 203 CHECK_EQ(container_, event->target()); |
205 // Find the old targeter to find the target of the event. | 204 // Find the old targeter to find the target of the event. |
206 ui::EventTarget* window = container_; | 205 ui::EventTarget* window = container_; |
207 ui::EventTargeter* targeter = scoped_targeter_->old_targeter(); | 206 ui::EventTargeter* targeter = scoped_targeter_->old_targeter(); |
208 while (!targeter && window->GetParentTarget()) { | 207 while (!targeter && window->GetParentTarget()) { |
209 window = window->GetParentTarget(); | 208 window = window->GetParentTarget(); |
210 targeter = window->GetEventTargeter(); | 209 targeter = window->GetEventTargeter(); |
211 } | 210 } |
212 if (!targeter) | 211 if (!targeter) |
213 return NULL; | 212 return NULL; |
214 aura::Window* target = static_cast<aura::Window*>( | 213 aura::Window* target = static_cast<aura::Window*>( |
215 targeter->FindTargetForLocatedEvent(container_, event)); | 214 targeter->FindTargetForLocatedEvent(container_, event)); |
216 while (target && target->parent() != container_) | 215 while (target && target->parent() != container_) |
217 target = target->parent(); | 216 target = target->parent(); |
218 return target; | 217 return target; |
219 } | 218 } |
220 | 219 |
221 // Scroll the window list by |delta_y| amount. |delta_y| is negative when | 220 // Scroll the window list by |delta_y| amount. |delta_y| is negative when |
222 // scrolling up; and positive when scrolling down. | 221 // scrolling up; and positive when scrolling down. |
223 void DoScroll(float delta_y) { | 222 void DoScroll(float delta_y) { |
224 const float kEpsilon = 1e-3f; | 223 const float kEpsilon = 1e-3f; |
225 aura::Window::Windows windows = container_->children(); | |
226 float delta_y_p = std::abs(delta_y) / GetScrollableHeight(); | 224 float delta_y_p = std::abs(delta_y) / GetScrollableHeight(); |
227 if (delta_y < 0) { | 225 if (delta_y < 0) { |
228 // Scroll up. Start with the top-most (i.e. behind-most in terms of | 226 // Scroll up. Start with the top-most (i.e. behind-most in terms of |
229 // z-index) window, and try to scroll them up. | 227 // z-index) window, and try to scroll them up. |
230 for (aura::Window::Windows::iterator iter = windows.begin(); | 228 for (aura::Window::Windows::const_iterator iter = windows_.begin(); |
231 delta_y_p > kEpsilon && iter != windows.end(); | 229 delta_y_p > kEpsilon && iter != windows_.end(); |
232 ++iter) { | 230 ++iter) { |
233 aura::Window* window = (*iter); | 231 aura::Window* window = (*iter); |
234 WindowOverviewState* state = window->GetProperty(kWindowOverviewState); | 232 WindowOverviewState* state = window->GetProperty(kWindowOverviewState); |
235 if (state->progress > kEpsilon) { | 233 if (state->progress > kEpsilon) { |
236 // It is possible to scroll |window| up. Scroll it up, and update | 234 // It is possible to scroll |window| up. Scroll it up, and update |
237 // |delta_y_p| for the next window. | 235 // |delta_y_p| for the next window. |
238 float apply = delta_y_p * state->progress; | 236 float apply = delta_y_p * state->progress; |
239 SetWindowProgress(window, std::max(0.f, state->progress - apply * 3)); | 237 SetWindowProgress(window, std::max(0.f, state->progress - apply * 3)); |
240 delta_y_p -= apply; | 238 delta_y_p -= apply; |
241 } | 239 } |
242 } | 240 } |
243 } else { | 241 } else { |
244 // Scroll down. Start with the bottom-most (i.e. front-most in terms of | 242 // Scroll down. Start with the bottom-most (i.e. front-most in terms of |
245 // z-index) window, and try to scroll them down. | 243 // z-index) window, and try to scroll them down. |
246 for (aura::Window::Windows::reverse_iterator iter = windows.rbegin(); | 244 aura::Window::Windows::const_reverse_iterator iter; |
247 delta_y_p > kEpsilon && iter != windows.rend(); | 245 for (iter = windows_.rbegin(); |
246 delta_y_p > kEpsilon && iter != windows_.rend(); | |
248 ++iter) { | 247 ++iter) { |
249 aura::Window* window = (*iter); | 248 aura::Window* window = (*iter); |
250 WindowOverviewState* state = window->GetProperty(kWindowOverviewState); | 249 WindowOverviewState* state = window->GetProperty(kWindowOverviewState); |
251 if (1.f - state->progress > kEpsilon) { | 250 if (1.f - state->progress > kEpsilon) { |
252 // It is possible to scroll |window| down. Scroll it down, and update | 251 // It is possible to scroll |window| down. Scroll it down, and update |
253 // |delta_y_p| for the next window. | 252 // |delta_y_p| for the next window. |
254 SetWindowProgress(window, std::min(1.f, state->progress + delta_y_p)); | 253 SetWindowProgress(window, std::min(1.f, state->progress + delta_y_p)); |
255 delta_y_p /= 2.f; | 254 delta_y_p /= 2.f; |
256 } | 255 } |
257 } | 256 } |
(...skipping 29 matching lines...) Expand all Loading... | |
287 if (select) { | 286 if (select) { |
288 gesture->SetHandled(); | 287 gesture->SetHandled(); |
289 delegate_->OnSelectWindow(select); | 288 delegate_->OnSelectWindow(select); |
290 } | 289 } |
291 } else if (gesture->type() == ui::ET_GESTURE_SCROLL_UPDATE) { | 290 } else if (gesture->type() == ui::ET_GESTURE_SCROLL_UPDATE) { |
292 DoScroll(gesture->details().scroll_y()); | 291 DoScroll(gesture->details().scroll_y()); |
293 } | 292 } |
294 } | 293 } |
295 | 294 |
296 aura::Window* container_; | 295 aura::Window* container_; |
296 // The stack of windows to show in the overview mode | |
297 aura::Window::Windows windows_; | |
Jun Mukai
2014/08/05 21:13:38
Can we set this as const? I think the order of |w
mfomitchev
2014/08/06 18:11:32
Done.
| |
297 WindowOverviewModeDelegate* delegate_; | 298 WindowOverviewModeDelegate* delegate_; |
298 scoped_ptr<aura::ScopedWindowTargeter> scoped_targeter_; | 299 scoped_ptr<aura::ScopedWindowTargeter> scoped_targeter_; |
299 | 300 |
300 DISALLOW_COPY_AND_ASSIGN(WindowOverviewModeImpl); | 301 DISALLOW_COPY_AND_ASSIGN(WindowOverviewModeImpl); |
301 }; | 302 }; |
302 | 303 |
303 } // namespace | 304 } // namespace |
304 | 305 |
305 // static | 306 // static |
306 scoped_ptr<WindowOverviewMode> WindowOverviewMode::Create( | 307 scoped_ptr<WindowOverviewMode> WindowOverviewMode::Create( |
307 aura::Window* container, | 308 aura::Window* container, |
309 aura::Window::Windows windows, | |
308 WindowOverviewModeDelegate* delegate) { | 310 WindowOverviewModeDelegate* delegate) { |
309 return scoped_ptr<WindowOverviewMode>( | 311 return scoped_ptr<WindowOverviewMode>( |
310 new WindowOverviewModeImpl(container, delegate)); | 312 new WindowOverviewModeImpl(container, windows, delegate)); |
311 } | 313 } |
312 | 314 |
313 } // namespace athena | 315 } // namespace athena |
OLD | NEW |