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

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

Issue 459613008: athena: Allow getting into split-view mode from overview-mode. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 4 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
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 "athena/common/closure_animation_observer.h" 11 #include "athena/common/closure_animation_observer.h"
12 #include "athena/wm/overview_toolbar.h"
12 #include "athena/wm/public/window_list_provider.h" 13 #include "athena/wm/public/window_list_provider.h"
13 #include "base/bind.h" 14 #include "base/bind.h"
14 #include "base/macros.h" 15 #include "base/macros.h"
15 #include "ui/aura/scoped_window_targeter.h" 16 #include "ui/aura/scoped_window_targeter.h"
16 #include "ui/aura/window.h" 17 #include "ui/aura/window.h"
17 #include "ui/aura/window_delegate.h" 18 #include "ui/aura/window_delegate.h"
18 #include "ui/aura/window_property.h" 19 #include "ui/aura/window_property.h"
19 #include "ui/aura/window_targeter.h" 20 #include "ui/aura/window_targeter.h"
20 #include "ui/aura/window_tree_host.h" 21 #include "ui/aura/window_tree_host.h"
21 #include "ui/compositor/compositor.h" 22 #include "ui/compositor/compositor.h"
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 294
294 void RemoveAnimationObserver() { 295 void RemoveAnimationObserver() {
295 ui::Compositor* compositor = container_->GetHost()->compositor(); 296 ui::Compositor* compositor = container_->GetHost()->compositor();
296 if (compositor->HasAnimationObserver(this)) 297 if (compositor->HasAnimationObserver(this))
297 compositor->RemoveAnimationObserver(this); 298 compositor->RemoveAnimationObserver(this);
298 } 299 }
299 300
300 void DragWindow(const ui::GestureEvent& event) { 301 void DragWindow(const ui::GestureEvent& event) {
301 CHECK(dragged_window_); 302 CHECK(dragged_window_);
302 CHECK_EQ(ui::ET_GESTURE_SCROLL_UPDATE, event.type()); 303 CHECK_EQ(ui::ET_GESTURE_SCROLL_UPDATE, event.type());
304 CHECK(overview_toolbar_);
303 gfx::Vector2dF dragged_distance = 305 gfx::Vector2dF dragged_distance =
304 dragged_start_location_ - event.location(); 306 dragged_start_location_ - event.location();
305 WindowOverviewState* dragged_state = 307 WindowOverviewState* dragged_state =
306 dragged_window_->GetProperty(kWindowOverviewState); 308 dragged_window_->GetProperty(kWindowOverviewState);
307 CHECK(dragged_state); 309 CHECK(dragged_state);
308 gfx::Transform transform = GetTransformForState(dragged_state); 310 gfx::Transform transform = GetTransformForState(dragged_state);
309 transform.Translate(-dragged_distance.x(), 0); 311 transform.Translate(-dragged_distance.x(), 0);
310 dragged_window_->SetTransform(transform); 312 dragged_window_->SetTransform(transform);
311 313
314 // Update the toolbar.
315 const int kMinDistanceForActionButtons = 20;
316 if (fabs(dragged_distance.x()) > kMinDistanceForActionButtons)
317 overview_toolbar_->ShowActionButtons();
318 else
319 overview_toolbar_->HideActionButtons();
320
321 // See if the touch-point is above one of the action-buttons.
322 OverviewToolbar::ActionType new_action =
323 overview_toolbar_->GetHighlightAction(event);
324
325 // If the touch-point is not above any of the action buttons, then highlight
326 // the close-button by default, if the user has dragged enough to close the
327 // window.
328 if (new_action == OverviewToolbar::ACTION_TYPE_NONE) {
329 if (fabs(dragged_distance.x()) > kMinDistanceForDismissal)
330 new_action = OverviewToolbar::ACTION_TYPE_CLOSE;
331 else
332 new_action = OverviewToolbar::ACTION_TYPE_NONE;
333 }
334 OverviewToolbar::ActionType previous_action =
335 overview_toolbar_->current_action();
336 overview_toolbar_->SetHighlightAction(new_action);
337
338 // If the user has selected to get into split-view mode, then show the
339 // window with full opacity. Otherwise, fade it out as it closes. Animate
340 // the opacity if transitioning to/from the split-view button.
341 bool animate_opacity =
342 (new_action != previous_action) &&
343 ((new_action == OverviewToolbar::ACTION_TYPE_SPLIT) ||
344 (previous_action == OverviewToolbar::ACTION_TYPE_SPLIT));
312 float ratio = std::min( 345 float ratio = std::min(
313 1.f, std::abs(dragged_distance.x()) / kMinDistanceForDismissal); 346 1.f, std::abs(dragged_distance.x()) / kMinDistanceForDismissal);
314 float opacity = 347 float opacity =
315 gfx::Tween::FloatValueBetween(ratio, kMaxOpacity, kMinOpacity); 348 (new_action == OverviewToolbar::ACTION_TYPE_SPLIT)
316 dragged_window_->layer()->SetOpacity(opacity); 349 ? 1
350 : gfx::Tween::FloatValueBetween(ratio, kMaxOpacity, kMinOpacity);
351 if (animate_opacity) {
352 ui::ScopedLayerAnimationSettings settings(
353 dragged_window_->layer()->GetAnimator());
354 dragged_window_->layer()->SetOpacity(opacity);
355 } else {
356 dragged_window_->layer()->SetOpacity(opacity);
357 }
317 } 358 }
318 359
319 bool ShouldCloseDragWindow(const ui::GestureEvent& event) const { 360 bool ShouldCloseDragWindow(const ui::GestureEvent& event) const {
320 gfx::Vector2dF dragged_distance = 361 gfx::Vector2dF dragged_distance =
321 dragged_start_location_ - event.location(); 362 dragged_start_location_ - event.location();
322 if (event.type() == ui::ET_GESTURE_SCROLL_END) 363 if (event.type() == ui::ET_GESTURE_SCROLL_END)
323 return std::abs(dragged_distance.x()) >= kMinDistanceForDismissal; 364 return std::abs(dragged_distance.x()) >= kMinDistanceForDismissal;
324 CHECK_EQ(ui::ET_SCROLL_FLING_START, event.type()); 365 CHECK_EQ(ui::ET_SCROLL_FLING_START, event.type());
325 const bool dragging_towards_right = dragged_distance.x() < 0; 366 const bool dragging_towards_right = dragged_distance.x() < 0;
326 const bool swipe_towards_right = event.details().velocity_x() > 0; 367 const bool swipe_towards_right = event.details().velocity_x() > 0;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 426
386 ui::ScopedLayerAnimationSettings settings( 427 ui::ScopedLayerAnimationSettings settings(
387 dragged_window_->layer()->GetAnimator()); 428 dragged_window_->layer()->GetAnimator());
388 settings.SetPreemptionStrategy( 429 settings.SetPreemptionStrategy(
389 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); 430 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
390 dragged_window_->SetTransform(GetTransformForState(dragged_state)); 431 dragged_window_->SetTransform(GetTransformForState(dragged_state));
391 dragged_window_->layer()->SetOpacity(1.f); 432 dragged_window_->layer()->SetOpacity(1.f);
392 dragged_window_ = NULL; 433 dragged_window_ = NULL;
393 } 434 }
394 435
436 void EndDragWindow(const ui::GestureEvent& gesture) {
437 CHECK(dragged_window_);
438 CHECK(overview_toolbar_);
439 OverviewToolbar::ActionType action = overview_toolbar_->current_action();
440 overview_toolbar_.reset();
441 if (action == OverviewToolbar::ACTION_TYPE_SPLIT)
442 delegate_->OnSplitViewMode(NULL, dragged_window_);
mfomitchev 2014/08/13 15:12:31 Why not pass the left window here as well? The bot
sadrul 2014/08/13 16:20:12 The purpose here is to tell the delegate that the
mfomitchev 2014/08/13 17:42:52 Acknowledged.
443 else if (ShouldCloseDragWindow(gesture))
444 CloseDragWindow(gesture);
445 else
446 RestoreDragWindow();
447 }
448
395 // ui::EventHandler: 449 // ui::EventHandler:
396 virtual void OnMouseEvent(ui::MouseEvent* mouse) OVERRIDE { 450 virtual void OnMouseEvent(ui::MouseEvent* mouse) OVERRIDE {
397 if (mouse->type() == ui::ET_MOUSE_PRESSED) { 451 if (mouse->type() == ui::ET_MOUSE_PRESSED) {
398 aura::Window* select = SelectWindowAt(mouse); 452 aura::Window* select = SelectWindowAt(mouse);
399 if (select) { 453 if (select) {
400 mouse->SetHandled(); 454 mouse->SetHandled();
401 delegate_->OnSelectWindow(select); 455 delegate_->OnSelectWindow(select);
402 } 456 }
403 } else if (mouse->type() == ui::ET_MOUSEWHEEL) { 457 } else if (mouse->type() == ui::ET_MOUSEWHEEL) {
404 DoScroll(static_cast<ui::MouseWheelEvent*>(mouse)->y_offset()); 458 DoScroll(static_cast<ui::MouseWheelEvent*>(mouse)->y_offset());
(...skipping 10 matching lines...) Expand all
415 aura::Window* select = SelectWindowAt(gesture); 469 aura::Window* select = SelectWindowAt(gesture);
416 if (select) { 470 if (select) {
417 gesture->SetHandled(); 471 gesture->SetHandled();
418 delegate_->OnSelectWindow(select); 472 delegate_->OnSelectWindow(select);
419 } 473 }
420 } else if (gesture->type() == ui::ET_GESTURE_SCROLL_BEGIN) { 474 } else if (gesture->type() == ui::ET_GESTURE_SCROLL_BEGIN) {
421 if (std::abs(gesture->details().scroll_x_hint()) > 475 if (std::abs(gesture->details().scroll_x_hint()) >
422 std::abs(gesture->details().scroll_y_hint()) * 2) { 476 std::abs(gesture->details().scroll_y_hint()) * 2) {
423 dragged_start_location_ = gesture->location(); 477 dragged_start_location_ = gesture->location();
424 dragged_window_ = SelectWindowAt(gesture); 478 dragged_window_ = SelectWindowAt(gesture);
479 if (dragged_window_)
480 overview_toolbar_.reset(new OverviewToolbar(container_));
425 } 481 }
426 } else if (gesture->type() == ui::ET_GESTURE_SCROLL_UPDATE) { 482 } else if (gesture->type() == ui::ET_GESTURE_SCROLL_UPDATE) {
427 if (dragged_window_) 483 if (dragged_window_)
428 DragWindow(*gesture); 484 DragWindow(*gesture);
429 else 485 else
430 DoScroll(gesture->details().scroll_y()); 486 DoScroll(gesture->details().scroll_y());
431 gesture->SetHandled(); 487 gesture->SetHandled();
432 } else if (gesture->type() == ui::ET_GESTURE_SCROLL_END) { 488 } else if (gesture->type() == ui::ET_GESTURE_SCROLL_END) {
433 if (dragged_window_) { 489 if (dragged_window_)
434 if (ShouldCloseDragWindow(*gesture)) 490 EndDragWindow(*gesture);
435 CloseDragWindow(*gesture);
436 else
437 RestoreDragWindow();
438 }
439 gesture->SetHandled(); 491 gesture->SetHandled();
440 } else if (gesture->type() == ui::ET_SCROLL_FLING_START) { 492 } else if (gesture->type() == ui::ET_SCROLL_FLING_START) {
441 if (dragged_window_) { 493 if (dragged_window_) {
442 if (ShouldCloseDragWindow(*gesture)) 494 EndDragWindow(*gesture);
443 CloseDragWindow(*gesture);
444 else
445 RestoreDragWindow();
446 } else { 495 } else {
447 CreateFlingerFor(*gesture); 496 CreateFlingerFor(*gesture);
448 AddAnimationObserver(); 497 AddAnimationObserver();
449 } 498 }
450 gesture->SetHandled(); 499 gesture->SetHandled();
451 } else if (gesture->type() == ui::ET_GESTURE_TAP_DOWN) { 500 } else if (gesture->type() == ui::ET_GESTURE_TAP_DOWN) {
452 if (fling_) { 501 if (fling_) {
453 fling_.reset(); 502 fling_.reset();
454 RemoveAnimationObserver(); 503 RemoveAnimationObserver();
455 gesture->SetHandled(); 504 gesture->SetHandled();
(...skipping 24 matching lines...) Expand all
480 529
481 aura::Window* container_; 530 aura::Window* container_;
482 // Provider of the stack of windows to show in the overview mode. Not owned. 531 // Provider of the stack of windows to show in the overview mode. Not owned.
483 const WindowListProvider* window_list_provider_; 532 const WindowListProvider* window_list_provider_;
484 WindowOverviewModeDelegate* delegate_; 533 WindowOverviewModeDelegate* delegate_;
485 scoped_ptr<aura::ScopedWindowTargeter> scoped_targeter_; 534 scoped_ptr<aura::ScopedWindowTargeter> scoped_targeter_;
486 scoped_ptr<ui::FlingCurve> fling_; 535 scoped_ptr<ui::FlingCurve> fling_;
487 536
488 aura::Window* dragged_window_; 537 aura::Window* dragged_window_;
489 gfx::Point dragged_start_location_; 538 gfx::Point dragged_start_location_;
539 scoped_ptr<OverviewToolbar> overview_toolbar_;
490 540
491 DISALLOW_COPY_AND_ASSIGN(WindowOverviewModeImpl); 541 DISALLOW_COPY_AND_ASSIGN(WindowOverviewModeImpl);
492 }; 542 };
493 543
494 } // namespace 544 } // namespace
495 545
496 // static 546 // static
497 scoped_ptr<WindowOverviewMode> WindowOverviewMode::Create( 547 scoped_ptr<WindowOverviewMode> WindowOverviewMode::Create(
498 aura::Window* container, 548 aura::Window* container,
499 const WindowListProvider* window_list_provider, 549 const WindowListProvider* window_list_provider,
500 WindowOverviewModeDelegate* delegate) { 550 WindowOverviewModeDelegate* delegate) {
501 return scoped_ptr<WindowOverviewMode>( 551 return scoped_ptr<WindowOverviewMode>(
502 new WindowOverviewModeImpl(container, window_list_provider, delegate)); 552 new WindowOverviewModeImpl(container, window_list_provider, delegate));
503 } 553 }
504 554
505 } // namespace athena 555 } // namespace athena
OLDNEW
« athena/wm/window_manager_impl.cc ('K') | « athena/wm/window_overview_mode.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698