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