Commit ded3461c authored by Sammie Quon's avatar Sammie Quon Committed by Commit Bot

splitview: Change highlights to use a single solid color layer.

Replaces the old three view setup which was used before we could
apply rounded corners directly on layers. Tested manually on
LTR and RTL on all 4 orientations. Visually no difference.

Ran ui.OverviewDragWindowPerf.drag_to_snap. Not noticeable
improvements on caroline, but input latency goes from 95ms to 80ms
on krane.

Test: added tests
Bug: 1047778
Change-Id: Idff6345fb5778d2e898bc51cd76bd7eac3c1741d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2033564
Commit-Queue: Sammie Quon <sammiequon@chromium.org>
Reviewed-by: default avatarXiaoqian Dai <xdai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#738262}
parent d7b8a9d1
......@@ -2353,8 +2353,6 @@ static_library("test_support") {
"wm/lock_state_controller_test_api.h",
"wm/splitview/multi_display_overview_and_split_view_test.cc",
"wm/splitview/multi_display_overview_and_split_view_test.h",
"wm/splitview/split_view_highlight_view_test_api.cc",
"wm/splitview/split_view_highlight_view_test_api.h",
"wm/tablet_mode/tablet_mode_controller_test_api.cc",
"wm/tablet_mode/tablet_mode_controller_test_api.h",
"wm/test_activation_delegate.cc",
......
......@@ -236,11 +236,6 @@ class SplitViewDragIndicators::SplitViewDragIndicatorsView
right_highlight_view_ = AddChildView(
std::make_unique<SplitViewHighlightView>(/*is_right_or_bottom=*/true));
left_highlight_view_->SetPaintToLayer();
right_highlight_view_->SetPaintToLayer();
left_highlight_view_->layer()->SetFillsBoundsOpaquely(false);
right_highlight_view_->layer()->SetFillsBoundsOpaquely(false);
left_rotated_view_ = AddChildView(
std::make_unique<RotatedImageLabelView>(/*is_right_or_bottom=*/false));
right_rotated_view_ = AddChildView(
......@@ -464,9 +459,8 @@ class SplitViewDragIndicators::SplitViewDragIndicatorsView
}
left_highlight_view_->SetBounds(GetMirroredRect(left_highlight_bounds),
horizontal, left_highlight_animation_type);
left_highlight_animation_type);
right_highlight_view_->SetBounds(GetMirroredRect(right_highlight_bounds),
horizontal,
right_highlight_animation_type);
// Calculate the bounds of the views which contain the guidance text and
......
......@@ -13,37 +13,23 @@
namespace ash {
class RoundedRectView;
class SplitViewHighlightViewTestApi;
// View that is used for displaying and animating the highlights which tell
// users where to drag windows to enter splitview, and previews the space which
// a snapped window will occupy. It is a view consisting of a rectangle with
// rounded corners on the left or top, a rectangle in the middle and a rectangle
// with rounded corners on the right or bottom. It is done this way to ensure
// rounded corners remain the same during the duration of an animation.
// (Transforming a rounded rect will stretch the corners, and having to repaint
// every animation tick is expensive.)
//
// Although rounded corners are prevented from stretching along one axis, there
// is one animation where the rounded corners will stretch along the
// perpendicular axis. Specifically, the preview area has a small inset (on all
// four sides) until you actually snap the window, and then the preview area
// animates to nix that inset while fading out. So the rounded corners will
// stretch by an amount depending on the dimensions of the work area, but it is
// unlikely to be noticeable under normal circumstances.
// a snapped window will occupy. It is a view consists of one solid color layer
// with rounded corners. If animations are needed, they are performed by
// animating the layer's clip rect.
class ASH_EXPORT SplitViewHighlightView : public views::View {
public:
explicit SplitViewHighlightView(bool is_right_or_bottom);
~SplitViewHighlightView() override;
SplitViewHighlightView(const SplitViewHighlightView&) = delete;
SplitViewHighlightView& operator=(const SplitViewHighlightView&) = delete;
// Updates bounds, animating if |animation_type| has a value.
void SetBounds(const gfx::Rect& bounds,
bool landscape,
const base::Optional<SplitviewAnimationType>& animation_type);
void SetColor(SkColor color);
// Called to update the opacity of the highlights view on transition from
// |previous_window_dragging_state| to |window_dragging_state|. If
// |previews_only|, then there shall be no visible drag indicators except for
......@@ -57,21 +43,11 @@ class ASH_EXPORT SplitViewHighlightView : public views::View {
bool can_dragged_window_be_snapped);
private:
friend class SplitViewHighlightViewTestApi;
// The three components of this view.
RoundedRectView* left_top_ = nullptr;
RoundedRectView* right_bottom_ = nullptr;
views::View* middle_ = nullptr;
bool landscape_ = true;
// Determines whether this particular highlight view is located at the right
// or bottom of the screen. These highlights animate in the opposite direction
// as left or top highlights, so when we use SetBounds extra calucations have
// to be done to ensure the animation is correct.
// as left or top highlights, so when we use |SetBounds()| extra calucations
// have to be done to ensure the animation is correct.
const bool is_right_or_bottom_;
DISALLOW_COPY_AND_ASSIGN(SplitViewHighlightView);
};
} // namespace ash
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/wm/splitview/split_view_highlight_view_test_api.h"
#include "ash/wm/overview/rounded_rect_view.h"
#include "ui/views/view.h"
namespace ash {
SplitViewHighlightViewTestApi::SplitViewHighlightViewTestApi(
SplitViewHighlightView* highlight_view)
: highlight_view_(highlight_view) {}
SplitViewHighlightViewTestApi::~SplitViewHighlightViewTestApi() = default;
views::View* SplitViewHighlightViewTestApi::GetLeftTopView() {
return static_cast<views::View*>(highlight_view_->left_top_);
}
views::View* SplitViewHighlightViewTestApi::GetRightBottomView() {
return static_cast<views::View*>(highlight_view_->right_bottom_);
}
views::View* SplitViewHighlightViewTestApi::GetMiddleView() {
return highlight_view_->middle_;
}
} // namespace ash
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_WM_SPLITVIEW_SPLIT_VIEW_HIGHLIGHT_VIEW_TEST_API_H_
#define ASH_WM_SPLITVIEW_SPLIT_VIEW_HIGHLIGHT_VIEW_TEST_API_H_
#include "ash/wm/splitview/split_view_highlight_view.h"
#include "base/macros.h"
namespace views {
class View;
} // namespace views
namespace ash {
// Use the api in this class to test SplitViewHighlightView.
class SplitViewHighlightViewTestApi {
public:
explicit SplitViewHighlightViewTestApi(
SplitViewHighlightView* highlight_view);
~SplitViewHighlightViewTestApi();
views::View* GetLeftTopView();
views::View* GetRightBottomView();
views::View* GetMiddleView();
private:
SplitViewHighlightView* highlight_view_;
DISALLOW_COPY_AND_ASSIGN(SplitViewHighlightViewTestApi);
};
} // namespace ash
#endif // ASH_WM_SPLITVIEW_SPLIT_VIEW_HIGHLIGHT_VIEW_TEST_API_H_
......@@ -243,13 +243,9 @@ void DoSplitviewTransformAnimation(
return;
switch (type) {
case SPLITVIEW_ANIMATION_OTHER_HIGHLIGHT_SLIDE_IN:
case SPLITVIEW_ANIMATION_OTHER_HIGHLIGHT_SLIDE_OUT:
case SPLITVIEW_ANIMATION_OTHER_HIGHLIGHT_TEXT_SLIDE_IN:
case SPLITVIEW_ANIMATION_OTHER_HIGHLIGHT_TEXT_SLIDE_OUT:
case SPLITVIEW_ANIMATION_PREVIEW_AREA_NIX_INSET:
case SPLITVIEW_ANIMATION_PREVIEW_AREA_SLIDE_IN:
case SPLITVIEW_ANIMATION_PREVIEW_AREA_SLIDE_OUT:
case SPLITVIEW_ANIMATION_PREVIEW_AREA_TEXT_SLIDE_IN:
case SPLITVIEW_ANIMATION_PREVIEW_AREA_TEXT_SLIDE_OUT:
case SPLITVIEW_ANIMATION_SET_WINDOW_TRANSFORM:
......@@ -276,6 +272,42 @@ void DoSplitviewTransformAnimation(
layer->SetTransform(target_transform);
}
void DoSplitviewClipRectAnimation(
ui::Layer* layer,
SplitviewAnimationType type,
const gfx::Rect& target_clip_rect,
std::unique_ptr<ui::ImplicitAnimationObserver> animation_observer) {
ui::LayerAnimator* animator = layer->GetAnimator();
if (animator->GetTargetClipRect() == target_clip_rect)
return;
switch (type) {
case SPLITVIEW_ANIMATION_OTHER_HIGHLIGHT_SLIDE_IN:
case SPLITVIEW_ANIMATION_OTHER_HIGHLIGHT_SLIDE_OUT:
case SPLITVIEW_ANIMATION_PREVIEW_AREA_NIX_INSET:
case SPLITVIEW_ANIMATION_PREVIEW_AREA_SLIDE_IN:
case SPLITVIEW_ANIMATION_PREVIEW_AREA_SLIDE_OUT:
break;
default:
NOTREACHED() << "Not a valid split view clip rect type.";
return;
}
base::TimeDelta duration;
gfx::Tween::Type tween;
ui::LayerAnimator::PreemptionStrategy preemption_strategy;
base::TimeDelta delay;
GetAnimationValuesForType(type, &duration, &tween, &preemption_strategy,
&delay);
ui::ScopedLayerAnimationSettings settings(animator);
if (animation_observer.get())
settings.AddObserver(animation_observer.release());
ApplyAnimationSettings(&settings, animator, ui::LayerAnimationElement::CLIP,
duration, tween, preemption_strategy, delay);
layer->SetClipRect(target_clip_rect);
}
void MaybeRestoreSplitView(bool refresh_snapped_windows) {
if (!ShouldAllowSplitView() ||
!Shell::Get()->tablet_mode_controller()->InTabletMode()) {
......
......@@ -112,6 +112,13 @@ void DoSplitviewTransformAnimation(
const gfx::Transform& target_transform,
std::unique_ptr<ui::ImplicitAnimationObserver> animation_observer);
// Animates |layer|'s clip rect based on |type|.
void DoSplitviewClipRectAnimation(
ui::Layer* layer,
SplitviewAnimationType type,
const gfx::Rect& target_clip_rect,
std::unique_ptr<ui::ImplicitAnimationObserver> animation_observer);
// Restores split view and overview based on the current split view's state.
// If |refresh_snapped_windows| is true, it will update the left and right
// snapped windows based on the MRU windows snapped states.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment