Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(162)

Side by Side Diff: athena/wm/window_overview_mode.cc

Issue 331593005: athena: Allow scrolling the window list in overview mode. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "ui/aura/scoped_window_targeter.h" 12 #include "ui/aura/scoped_window_targeter.h"
13 #include "ui/aura/window.h" 13 #include "ui/aura/window.h"
14 #include "ui/aura/window_delegate.h" 14 #include "ui/aura/window_delegate.h"
15 #include "ui/aura/window_property.h" 15 #include "ui/aura/window_property.h"
16 #include "ui/aura/window_targeter.h" 16 #include "ui/aura/window_targeter.h"
17 #include "ui/compositor/scoped_layer_animation_settings.h" 17 #include "ui/compositor/scoped_layer_animation_settings.h"
18 #include "ui/events/event_handler.h" 18 #include "ui/events/event_handler.h"
19 #include "ui/gfx/transform.h" 19 #include "ui/gfx/transform.h"
20 #include "ui/wm/core/shadow.h" 20 #include "ui/wm/core/shadow.h"
21 21
22 namespace { 22 namespace {
23 23
24 const float kEpsilon = 1e-3f;
oshima 2014/06/13 05:26:50 nit: move this to DoScroll() ?
sadrul 2014/06/13 14:00:08 Done.
25
24 struct WindowOverviewState { 26 struct WindowOverviewState {
25 // The transform for when the window is at the topmost position. 27 // The transform for when the window is at the topmost position.
26 gfx::Transform top; 28 gfx::Transform top;
27 29
28 // The transform for when the window is at the bottom-most position. 30 // The transform for when the window is at the bottom-most position.
29 gfx::Transform bottom; 31 gfx::Transform bottom;
30 32
31 // The current overview state of the window. 0.f means the window is at the 33 // The current overview state of the window. 0.f means the window is at the
32 // topmost position. 1.f means the window is at the bottom-most position. 34 // topmost position. 1.f means the window is at the bottom-most position.
33 float progress; 35 float progress;
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 ++iter, ++index) { 138 ++iter, ++index) {
137 aura::Window* window = (*iter); 139 aura::Window* window = (*iter);
138 140
139 gfx::Transform top_transform; 141 gfx::Transform top_transform;
140 int top = (window_count - index - 1) * kGapBetweenWindowsTop; 142 int top = (window_count - index - 1) * kGapBetweenWindowsTop;
141 float x_translate = container_size.width() * (1 - kMinScale) / 2.; 143 float x_translate = container_size.width() * (1 - kMinScale) / 2.;
142 top_transform.Translate(x_translate, top); 144 top_transform.Translate(x_translate, top);
143 top_transform.Scale(kMinScale, kMinScale); 145 top_transform.Scale(kMinScale, kMinScale);
144 146
145 gfx::Transform bottom_transform; 147 gfx::Transform bottom_transform;
146 int bottom = container_size.height() - (index * kGapBetweenWindowsBottom); 148 int bottom = GetScrollableHeight() - (index * kGapBetweenWindowsBottom);
147 x_translate = container_size.width() * (1 - kMaxScale) / 2.; 149 x_translate = container_size.width() * (1 - kMaxScale) / 2.;
148 bottom_transform.Translate(x_translate, bottom - window->bounds().y()); 150 bottom_transform.Translate(x_translate, bottom - window->bounds().y());
149 bottom_transform.Scale(kMaxScale, kMaxScale); 151 bottom_transform.Scale(kMaxScale, kMaxScale);
150 152
151 WindowOverviewState* state = new WindowOverviewState; 153 WindowOverviewState* state = new WindowOverviewState;
152 state->top = top_transform; 154 state->top = top_transform;
153 state->bottom = bottom_transform; 155 state->bottom = bottom_transform;
154 state->progress = 0.f; 156 state->progress = 0.f;
155 state->shadow = CreateShadowForWindow(window); 157 state->shadow = CreateShadowForWindow(window);
156 window->SetProperty(kWindowOverviewState, state); 158 window->SetProperty(kWindowOverviewState, state);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 } 213 }
212 if (!targeter) 214 if (!targeter)
213 return NULL; 215 return NULL;
214 aura::Window* target = static_cast<aura::Window*>( 216 aura::Window* target = static_cast<aura::Window*>(
215 targeter->FindTargetForLocatedEvent(container_, event)); 217 targeter->FindTargetForLocatedEvent(container_, event));
216 while (target && target->parent() != container_) 218 while (target && target->parent() != container_)
217 target = target->parent(); 219 target = target->parent();
218 return target; 220 return target;
219 } 221 }
220 222
223 // Scroll the window list by |delta_y| amount. |delta_y| is negative when
224 // scrolling up; and positive when scrolling down.
225 void DoScroll(float delta_y) {
226 aura::Window::Windows windows = container_->children();
227 float delta_y_p = std::abs(delta_y) / GetScrollableHeight();
228 if (delta_y < 0) {
229 // Scroll up. Start with the top-most (i.e. behind-most in terms of
230 // z-index) window, and try to scroll them up.
231 for (aura::Window::Windows::iterator iter = windows.begin();
232 delta_y_p > kEpsilon && iter != windows.end();
233 ++iter) {
234 aura::Window* window = (*iter);
235 WindowOverviewState* state = window->GetProperty(kWindowOverviewState);
236 if (state->progress > kEpsilon) {
237 // It is possible to scroll |window| up. Scroll it up, and update
238 // |delta_y_p| for the next window.
239 float apply = delta_y_p * state->progress;
240 SetWindowProgress(window, std::max(0.f, state->progress - apply * 3));
241 delta_y_p -= apply;
242 }
243 }
244 } else {
245 // Scroll down. Start with the bottom-most (i.e. front-most in terms of
246 // z-index) window, and try to scroll them down.
247 for (aura::Window::Windows::reverse_iterator iter = windows.rbegin();
248 delta_y_p > kEpsilon && iter != windows.rend();
249 ++iter) {
250 aura::Window* window = (*iter);
251 WindowOverviewState* state = window->GetProperty(kWindowOverviewState);
252 if (1.f - state->progress > kEpsilon) {
253 // It is possible to scroll |window| down. Scroll it down, and update
254 // |delta_y_p| for the next window.
255 SetWindowProgress(window, std::min(1.f, state->progress + delta_y_p));
256 delta_y_p /= 2.f;
257 }
258 }
259 }
260 }
261
262 int GetScrollableHeight() const {
263 const float kScrollableFraction = 0.65f;
264 return container_->bounds().height() * kScrollableFraction;
265 }
266
221 // ui::EventHandler: 267 // ui::EventHandler:
222 virtual void OnMouseEvent(ui::MouseEvent* mouse) OVERRIDE { 268 virtual void OnMouseEvent(ui::MouseEvent* mouse) OVERRIDE {
223 if (mouse->type() != ui::ET_MOUSE_PRESSED) 269 if (mouse->type() == ui::ET_MOUSE_PRESSED) {
224 return; 270 aura::Window* select = SelectWindowAt(mouse);
225 aura::Window* select = SelectWindowAt(mouse); 271 if (select) {
226 if (select) { 272 mouse->SetHandled();
227 mouse->SetHandled(); 273 delegate_->OnSelectWindow(select);
228 delegate_->OnSelectWindow(select); 274 }
275 } else if (mouse->type() == ui::ET_MOUSEWHEEL) {
276 DoScroll(static_cast<ui::MouseWheelEvent*>(mouse)->y_offset());
229 } 277 }
230 } 278 }
231 279
280 virtual void OnScrollEvent(ui::ScrollEvent* scroll) OVERRIDE {
281 if (scroll->type() == ui::ET_SCROLL)
282 DoScroll(scroll->y_offset());
283 }
284
232 virtual void OnGestureEvent(ui::GestureEvent* gesture) OVERRIDE { 285 virtual void OnGestureEvent(ui::GestureEvent* gesture) OVERRIDE {
233 if (gesture->type() != ui::ET_GESTURE_TAP) 286 if (gesture->type() == ui::ET_GESTURE_TAP) {
234 return; 287 aura::Window* select = SelectWindowAt(gesture);
235 aura::Window* select = SelectWindowAt(gesture); 288 if (select) {
236 if (select) { 289 gesture->SetHandled();
237 gesture->SetHandled(); 290 delegate_->OnSelectWindow(select);
238 delegate_->OnSelectWindow(select); 291 }
292 } else if (gesture->type() == ui::ET_GESTURE_SCROLL_UPDATE) {
293 DoScroll(gesture->details().scroll_y());
239 } 294 }
240 } 295 }
241 296
242 aura::Window* container_; 297 aura::Window* container_;
243 WindowOverviewModeDelegate* delegate_; 298 WindowOverviewModeDelegate* delegate_;
244 scoped_ptr<aura::ScopedWindowTargeter> scoped_targeter_; 299 scoped_ptr<aura::ScopedWindowTargeter> scoped_targeter_;
245 300
246 DISALLOW_COPY_AND_ASSIGN(WindowOverviewModeImpl); 301 DISALLOW_COPY_AND_ASSIGN(WindowOverviewModeImpl);
247 }; 302 };
248 303
249 } // namespace 304 } // namespace
250 305
251 scoped_ptr<WindowOverviewMode> WindowOverviewMode::Create( 306 scoped_ptr<WindowOverviewMode> WindowOverviewMode::Create(
252 aura::Window* window, 307 aura::Window* window,
253 WindowOverviewModeDelegate* delegate) { 308 WindowOverviewModeDelegate* delegate) {
254 return scoped_ptr<WindowOverviewMode>( 309 return scoped_ptr<WindowOverviewMode>(
255 new WindowOverviewModeImpl(window, delegate)); 310 new WindowOverviewModeImpl(window, delegate));
256 } 311 }
257 312
258 } // namespace athena 313 } // namespace athena
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698