| 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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 = container_size.height() - (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); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 } | 211 } |
| 212 if (!targeter) | 212 if (!targeter) |
| 213 return NULL; | 213 return NULL; |
| 214 aura::Window* target = static_cast<aura::Window*>( | 214 aura::Window* target = static_cast<aura::Window*>( |
| 215 targeter->FindTargetForLocatedEvent(container_, event)); | 215 targeter->FindTargetForLocatedEvent(container_, event)); |
| 216 while (target && target->parent() != container_) | 216 while (target && target->parent() != container_) |
| 217 target = target->parent(); | 217 target = target->parent(); |
| 218 return target; | 218 return target; |
| 219 } | 219 } |
| 220 | 220 |
| 221 // Scroll the window list by |delta_y| amount. |delta_y| is negative when |
| 222 // scrolling up; and positive when scrolling down. |
| 223 void DoScroll(float delta_y) { |
| 224 const float kEpsilon = 1e-3f; |
| 225 aura::Window::Windows windows = container_->children(); |
| 226 float delta_y_p = std::abs(delta_y) / GetScrollableHeight(); |
| 227 if (delta_y < 0) { |
| 228 // Scroll up. Start with the top-most (i.e. behind-most in terms of |
| 229 // z-index) window, and try to scroll them up. |
| 230 for (aura::Window::Windows::iterator iter = windows.begin(); |
| 231 delta_y_p > kEpsilon && iter != windows.end(); |
| 232 ++iter) { |
| 233 aura::Window* window = (*iter); |
| 234 WindowOverviewState* state = window->GetProperty(kWindowOverviewState); |
| 235 if (state->progress > kEpsilon) { |
| 236 // It is possible to scroll |window| up. Scroll it up, and update |
| 237 // |delta_y_p| for the next window. |
| 238 float apply = delta_y_p * state->progress; |
| 239 SetWindowProgress(window, std::max(0.f, state->progress - apply * 3)); |
| 240 delta_y_p -= apply; |
| 241 } |
| 242 } |
| 243 } else { |
| 244 // Scroll down. Start with the bottom-most (i.e. front-most in terms of |
| 245 // z-index) window, and try to scroll them down. |
| 246 for (aura::Window::Windows::reverse_iterator iter = windows.rbegin(); |
| 247 delta_y_p > kEpsilon && iter != windows.rend(); |
| 248 ++iter) { |
| 249 aura::Window* window = (*iter); |
| 250 WindowOverviewState* state = window->GetProperty(kWindowOverviewState); |
| 251 if (1.f - state->progress > kEpsilon) { |
| 252 // It is possible to scroll |window| down. Scroll it down, and update |
| 253 // |delta_y_p| for the next window. |
| 254 SetWindowProgress(window, std::min(1.f, state->progress + delta_y_p)); |
| 255 delta_y_p /= 2.f; |
| 256 } |
| 257 } |
| 258 } |
| 259 } |
| 260 |
| 261 int GetScrollableHeight() const { |
| 262 const float kScrollableFraction = 0.65f; |
| 263 return container_->bounds().height() * kScrollableFraction; |
| 264 } |
| 265 |
| 221 // ui::EventHandler: | 266 // ui::EventHandler: |
| 222 virtual void OnMouseEvent(ui::MouseEvent* mouse) OVERRIDE { | 267 virtual void OnMouseEvent(ui::MouseEvent* mouse) OVERRIDE { |
| 223 if (mouse->type() != ui::ET_MOUSE_PRESSED) | 268 if (mouse->type() == ui::ET_MOUSE_PRESSED) { |
| 224 return; | 269 aura::Window* select = SelectWindowAt(mouse); |
| 225 aura::Window* select = SelectWindowAt(mouse); | 270 if (select) { |
| 226 if (select) { | 271 mouse->SetHandled(); |
| 227 mouse->SetHandled(); | 272 delegate_->OnSelectWindow(select); |
| 228 delegate_->OnSelectWindow(select); | 273 } |
| 274 } else if (mouse->type() == ui::ET_MOUSEWHEEL) { |
| 275 DoScroll(static_cast<ui::MouseWheelEvent*>(mouse)->y_offset()); |
| 229 } | 276 } |
| 230 } | 277 } |
| 231 | 278 |
| 279 virtual void OnScrollEvent(ui::ScrollEvent* scroll) OVERRIDE { |
| 280 if (scroll->type() == ui::ET_SCROLL) |
| 281 DoScroll(scroll->y_offset()); |
| 282 } |
| 283 |
| 232 virtual void OnGestureEvent(ui::GestureEvent* gesture) OVERRIDE { | 284 virtual void OnGestureEvent(ui::GestureEvent* gesture) OVERRIDE { |
| 233 if (gesture->type() != ui::ET_GESTURE_TAP) | 285 if (gesture->type() == ui::ET_GESTURE_TAP) { |
| 234 return; | 286 aura::Window* select = SelectWindowAt(gesture); |
| 235 aura::Window* select = SelectWindowAt(gesture); | 287 if (select) { |
| 236 if (select) { | 288 gesture->SetHandled(); |
| 237 gesture->SetHandled(); | 289 delegate_->OnSelectWindow(select); |
| 238 delegate_->OnSelectWindow(select); | 290 } |
| 291 } else if (gesture->type() == ui::ET_GESTURE_SCROLL_UPDATE) { |
| 292 DoScroll(gesture->details().scroll_y()); |
| 239 } | 293 } |
| 240 } | 294 } |
| 241 | 295 |
| 242 aura::Window* container_; | 296 aura::Window* container_; |
| 243 WindowOverviewModeDelegate* delegate_; | 297 WindowOverviewModeDelegate* delegate_; |
| 244 scoped_ptr<aura::ScopedWindowTargeter> scoped_targeter_; | 298 scoped_ptr<aura::ScopedWindowTargeter> scoped_targeter_; |
| 245 | 299 |
| 246 DISALLOW_COPY_AND_ASSIGN(WindowOverviewModeImpl); | 300 DISALLOW_COPY_AND_ASSIGN(WindowOverviewModeImpl); |
| 247 }; | 301 }; |
| 248 | 302 |
| 249 } // namespace | 303 } // namespace |
| 250 | 304 |
| 251 scoped_ptr<WindowOverviewMode> WindowOverviewMode::Create( | 305 scoped_ptr<WindowOverviewMode> WindowOverviewMode::Create( |
| 252 aura::Window* window, | 306 aura::Window* window, |
| 253 WindowOverviewModeDelegate* delegate) { | 307 WindowOverviewModeDelegate* delegate) { |
| 254 return scoped_ptr<WindowOverviewMode>( | 308 return scoped_ptr<WindowOverviewMode>( |
| 255 new WindowOverviewModeImpl(window, delegate)); | 309 new WindowOverviewModeImpl(window, delegate)); |
| 256 } | 310 } |
| 257 | 311 |
| 258 } // namespace athena | 312 } // namespace athena |
| OLD | NEW |