Skip to content

Commit

Permalink
desks: Allow multiple keyboard press to switch desks quickly.
Browse files Browse the repository at this point in the history
Second CL to allow chaining keyboard shortcuts.

Follow up to crrev.com/c/2354798 which allows RootWindowDeskSwitch to
handle more than two screenshots. This CL fills it out by handling
taking third and fourth screenshots and placing them on the animation
layer to get a nice smooth continuous animation. Tests in a follow up.

Test: manual
Bug: 1111445, 1068508
Change-Id: I33f4a26ae794fca799888953b23d617a9f8d0832
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2376418
Commit-Queue: Sammie Quon <sammiequon@chromium.org>
Reviewed-by: Ahmed Fakhry <afakhry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#803583}
  • Loading branch information
Sammie Quon authored and Commit Bot committed Sep 1, 2020
1 parent 4a1b842 commit ed9269e
Show file tree
Hide file tree
Showing 4 changed files with 229 additions and 120 deletions.
72 changes: 53 additions & 19 deletions ash/wm/desks/desk_animation_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ bool DeskActivationAnimation::Replace(bool moving_left,
if (source != switch_source_)
return false;

// If any of the animators are still taking either screenshot, do not replace
// the animation.
for (const auto& animator : desk_switch_animators_) {
if (!animator->starting_desk_screenshot_taken() ||
!animator->ending_desk_screenshot_taken()) {
return false;
}
}

const int new_ending_desk_index = ending_desk_index_ + (moving_left ? -1 : 1);
// Already at the leftmost or rightmost desk, nothing to replace.
if (new_ending_desk_index < 0 ||
Expand All @@ -55,14 +64,56 @@ bool DeskActivationAnimation::Replace(bool moving_left,
}

ending_desk_index_ = new_ending_desk_index;
for (const auto& animator : desk_switch_animators_)
animator->ReplaceAnimation(new_ending_desk_index);

// List of animators that need a screenshot. It should be either empty or
// match the size of |desk_switch_animators_| as all the animations should be
// in sync.
// TODO(sammiequon): Verify all the animations are in sync.
std::vector<RootWindowDeskSwitchAnimator*> pending_animators;
for (const auto& animator : desk_switch_animators_) {
if (animator->ReplaceAnimation(new_ending_desk_index))
pending_animators.push_back(animator.get());
}

// No screenshot needed. Call OnEndingDeskScreenshotTaken which will start the
// animation.
if (pending_animators.empty()) {
OnEndingDeskScreenshotTaken();
return true;
}

// Activate the target desk and take a screenshot.
DCHECK_EQ(pending_animators.size(), desk_switch_animators_.size());
PrepareDeskForScreenshot(new_ending_desk_index);
for (auto* animator : pending_animators)
animator->TakeEndingDeskScreenshot();
return true;
}

void DeskActivationAnimation::OnStartingDeskScreenshotTakenInternal(
int ending_desk_index) {
DCHECK_EQ(ending_desk_index_, ending_desk_index);
PrepareDeskForScreenshot(ending_desk_index);
}

void DeskActivationAnimation::OnDeskSwitchAnimationFinishedInternal() {
// During a chained animation we may not switch desks if a replaced target
// desk does not require a new screenshot. If that is the case, activate the
// proper desk here.
controller_->ActivateDeskInternal(
controller_->desks()[ending_desk_index_].get(),
/*update_window_activation=*/true);
}

metrics_util::ReportCallback DeskActivationAnimation::GetReportCallback()
const {
return metrics_util::ForSmoothness(base::BindRepeating([](int smoothness) {
UMA_HISTOGRAM_PERCENTAGE(kDeskActivationSmoothnessHistogramName,
smoothness);
}));
}

void DeskActivationAnimation::PrepareDeskForScreenshot(int index) {
// The order here matters. Overview must end before ending tablet split view
// before switching desks. (If clamshell split view is active on one or more
// displays, then it simply will end when we end overview.) That's because
Expand Down Expand Up @@ -92,23 +143,6 @@ void DeskActivationAnimation::OnStartingDeskScreenshotTakenInternal(
MaybeRestoreSplitView(/*refresh_snapped_windows=*/true);
}

void DeskActivationAnimation::OnDeskSwitchAnimationFinishedInternal() {
// During a chained animation we may not switch desks if a replaced target
// desk does not require a new screenshot. If that is the case, activate the
// proper desk here.
controller_->ActivateDeskInternal(
controller_->desks()[ending_desk_index_].get(),
/*update_window_activation=*/true);
}

metrics_util::ReportCallback DeskActivationAnimation::GetReportCallback()
const {
return metrics_util::ForSmoothness(base::BindRepeating([](int smoothness) {
UMA_HISTOGRAM_PERCENTAGE(kDeskActivationSmoothnessHistogramName,
smoothness);
}));
}

// -----------------------------------------------------------------------------
// DeskRemovalAnimation:

Expand Down
5 changes: 5 additions & 0 deletions ash/wm/desks/desk_animation_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ class DeskActivationAnimation : public DeskAnimationBase {
metrics_util::ReportCallback GetReportCallback() const override;

private:
// Prepares the desk associated with |index| for taking a screenshot. Exits
// overview and splitview if necessary and then activates the desk. Restores
// splitview if necessary after activating the desk.
void PrepareDeskForScreenshot(int index);

// The switch source that requested this animation.
const DesksSwitchSource switch_source_;
};
Expand Down
Loading

0 comments on commit ed9269e

Please sign in to comment.