Commit 00dd9093 authored by Sammie Quon's avatar Sammie Quon Committed by Commit Bot

overview: Hide close button and title bar on overview item dragged.

Hide both for the item currently dragged. Only hide the close button for
the rest of the items.
Spec: https://mccanny.users.x20web.corp.google.com/www/splitscreen-motion/index.html
Window selection and deselection

Test: ash_unittests WindowSelectorTest.WindowItemTitleCloseVisibilityOnDrag
Bug: 782320, 775655
Change-Id: I7e06a0154a9afdb391966109517b1aed419083e4
Reviewed-on: https://chromium-review.googlesource.com/893212Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Commit-Queue: Sammie Quon <sammiequon@chromium.org>
Cr-Commit-Position: refs/heads/master@{#534764}
parent 28769b5b
...@@ -685,6 +685,16 @@ void WindowGrid::UpdateCannotSnapWarningVisibility() { ...@@ -685,6 +685,16 @@ void WindowGrid::UpdateCannotSnapWarningVisibility() {
window_selector_item->UpdateCannotSnapWarningVisibility(); window_selector_item->UpdateCannotSnapWarningVisibility();
} }
void WindowGrid::OnSelectorItemDragStarted(WindowSelectorItem* item) {
for (auto& window_selector_item : window_list_)
window_selector_item->OnSelectorItemDragStarted(item);
}
void WindowGrid::OnSelectorItemDragEnded(WindowSelectorItem* item) {
for (auto& window_selector_item : window_list_)
window_selector_item->OnSelectorItemDragEnded(item);
}
void WindowGrid::OnWindowDestroying(aura::Window* window) { void WindowGrid::OnWindowDestroying(aura::Window* window) {
window_observer_.Remove(window); window_observer_.Remove(window);
window_state_observer_.Remove(wm::GetWindowState(window)); window_state_observer_.Remove(wm::GetWindowState(window));
......
...@@ -123,6 +123,11 @@ class ASH_EXPORT WindowGrid : public aura::WindowObserver, ...@@ -123,6 +123,11 @@ class ASH_EXPORT WindowGrid : public aura::WindowObserver,
void UpdateCannotSnapWarningVisibility(); void UpdateCannotSnapWarningVisibility();
// Called when any WindowSelectorItem on any WindowGrid has started/ended
// being dragged.
void OnSelectorItemDragStarted(WindowSelectorItem* item);
void OnSelectorItemDragEnded(WindowSelectorItem* item);
// Returns true if the grid has no more windows. // Returns true if the grid has no more windows.
bool empty() const { return window_list_.empty(); } bool empty() const { return window_list_.empty(); }
......
...@@ -545,6 +545,12 @@ void WindowSelector::InitiateDrag(WindowSelectorItem* item, ...@@ -545,6 +545,12 @@ void WindowSelector::InitiateDrag(WindowSelectorItem* item,
const gfx::Point& location_in_screen) { const gfx::Point& location_in_screen) {
window_drag_controller_.reset(new OverviewWindowDragController(this)); window_drag_controller_.reset(new OverviewWindowDragController(this));
window_drag_controller_->InitiateDrag(item, location_in_screen); window_drag_controller_->InitiateDrag(item, location_in_screen);
if (!IsNewOverviewUi())
return;
for (std::unique_ptr<WindowGrid>& grid : grid_list_)
grid->OnSelectorItemDragStarted(item);
} }
void WindowSelector::Drag(WindowSelectorItem* item, void WindowSelector::Drag(WindowSelectorItem* item,
...@@ -559,6 +565,12 @@ void WindowSelector::CompleteDrag(WindowSelectorItem* item, ...@@ -559,6 +565,12 @@ void WindowSelector::CompleteDrag(WindowSelectorItem* item,
DCHECK(window_drag_controller_.get()); DCHECK(window_drag_controller_.get());
DCHECK_EQ(item, window_drag_controller_->item()); DCHECK_EQ(item, window_drag_controller_->item());
window_drag_controller_->CompleteDrag(location_in_screen); window_drag_controller_->CompleteDrag(location_in_screen);
if (!IsNewOverviewUi())
return;
for (std::unique_ptr<WindowGrid>& grid : grid_list_)
grid->OnSelectorItemDragEnded(item);
} }
void WindowSelector::ActivateDraggedWindow() { void WindowSelector::ActivateDraggedWindow() {
......
...@@ -106,6 +106,10 @@ constexpr int kSelectorFadeInMilliseconds = 350; ...@@ -106,6 +106,10 @@ constexpr int kSelectorFadeInMilliseconds = 350;
// Duration of background opacity transition when exiting overview mode. // Duration of background opacity transition when exiting overview mode.
constexpr int kExitFadeInMilliseconds = 30; constexpr int kExitFadeInMilliseconds = 30;
// Duration of the header and close button fade in/out when a drag is
// started/finished on a window selector item;
constexpr int kDragAnimationMs = 167;
// Before closing a window animate both the window and the caption to shrink by // Before closing a window animate both the window and the caption to shrink by
// this fraction of size. // this fraction of size.
constexpr float kPreCloseScale = 0.02f; constexpr float kPreCloseScale = 0.02f;
...@@ -495,6 +499,14 @@ class WindowSelectorItem::CaptionContainerView : public views::View { ...@@ -495,6 +499,14 @@ class WindowSelectorItem::CaptionContainerView : public views::View {
ShieldButton* listener_button() { return listener_button_; } ShieldButton* listener_button() { return listener_button_; }
void SetCloseButtonVisibility(bool visible) {
AnimateLayerOpacity(close_button_->layer(), visible);
}
void SetTitleLabelVisibility(bool visible) {
AnimateLayerOpacity(background_->layer(), visible);
}
void SetCannotSnapLabelVisibility(bool visible) { void SetCannotSnapLabelVisibility(bool visible) {
AnimateSplitviewLabelOpacity(cannot_snap_container_->layer(), visible); AnimateSplitviewLabelOpacity(cannot_snap_container_->layer(), visible);
} }
...@@ -560,6 +572,34 @@ class WindowSelectorItem::CaptionContainerView : public views::View { ...@@ -560,6 +572,34 @@ class WindowSelectorItem::CaptionContainerView : public views::View {
const char* GetClassName() const override { return "CaptionContainerView"; } const char* GetClassName() const override { return "CaptionContainerView"; }
private: private:
// Animates |layer| from 0 -> 1 opacity if |visible| and 1 -> 0 opacity
// otherwise. The tween type differs for |visible| and if |visible| is true
// there is a slight delay before the animation begins. Does not animate if
// opacity matches |visible|.
void AnimateLayerOpacity(ui::Layer* layer, bool visible) {
float target_opacity = visible ? 1.f : 0.f;
if (layer->GetTargetOpacity() == target_opacity)
return;
layer->SetOpacity(1.f - target_opacity);
{
ui::LayerAnimator* animator = layer->GetAnimator();
ui::ScopedLayerAnimationSettings settings(animator);
settings.SetPreemptionStrategy(
ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS);
if (visible) {
animator->SchedulePauseForProperties(
base::TimeDelta::FromMilliseconds(kDragAnimationMs),
ui::LayerAnimationElement::OPACITY);
}
settings.SetTransitionDuration(
base::TimeDelta::FromMilliseconds(kDragAnimationMs));
settings.SetTweenType(visible ? gfx::Tween::LINEAR_OUT_SLOW_IN
: gfx::Tween::FAST_OUT_LINEAR_IN);
layer->SetOpacity(target_opacity);
}
}
ShieldButton* listener_button_; ShieldButton* listener_button_;
WindowSelectorItem::RoundedContainerView* background_; WindowSelectorItem::RoundedContainerView* background_;
views::ImageView* image_view_; views::ImageView* image_view_;
...@@ -710,6 +750,17 @@ void WindowSelectorItem::UpdateCannotSnapWarningVisibility() { ...@@ -710,6 +750,17 @@ void WindowSelectorItem::UpdateCannotSnapWarningVisibility() {
caption_container_view_->SetCannotSnapLabelVisibility(visible); caption_container_view_->SetCannotSnapLabelVisibility(visible);
} }
void WindowSelectorItem::OnSelectorItemDragStarted(WindowSelectorItem* item) {
caption_container_view_->SetCloseButtonVisibility(false);
if (item == this)
caption_container_view_->SetTitleLabelVisibility(false);
}
void WindowSelectorItem::OnSelectorItemDragEnded(WindowSelectorItem* item) {
caption_container_view_->SetCloseButtonVisibility(true);
caption_container_view_->SetTitleLabelVisibility(true);
}
ScopedTransformOverviewWindow::GridWindowFillMode ScopedTransformOverviewWindow::GridWindowFillMode
WindowSelectorItem::GetWindowDimensionsType() const { WindowSelectorItem::GetWindowDimensionsType() const {
return transform_window_.type(); return transform_window_.type();
...@@ -791,6 +842,14 @@ void WindowSelectorItem::ResetDraggedWindowGesture() { ...@@ -791,6 +842,14 @@ void WindowSelectorItem::ResetDraggedWindowGesture() {
window_selector_->ResetDraggedWindowGesture(); window_selector_->ResetDraggedWindowGesture();
} }
float WindowSelectorItem::GetCloseButtonOpacityForTesting() {
return close_button_->layer()->opacity();
}
float WindowSelectorItem::GetTitlebarOpacityForTesting() {
return background_view_->layer()->opacity();
}
gfx::Rect WindowSelectorItem::GetTargetBoundsInScreen() const { gfx::Rect WindowSelectorItem::GetTargetBoundsInScreen() const {
return transform_window_.GetTargetBoundsInScreen(); return transform_window_.GetTargetBoundsInScreen();
} }
......
...@@ -122,6 +122,12 @@ class ASH_EXPORT WindowSelectorItem : public views::ButtonListener, ...@@ -122,6 +122,12 @@ class ASH_EXPORT WindowSelectorItem : public views::ButtonListener,
// window cannot be snapped. // window cannot be snapped.
void UpdateCannotSnapWarningVisibility(); void UpdateCannotSnapWarningVisibility();
// Called when a WindowSelectorItem on any grid is dragged. Hides the close
// button when a drag is started, and reshows it when a drag is finished.
// Additional hides the title and window icon if |item| is this.
void OnSelectorItemDragStarted(WindowSelectorItem* item);
void OnSelectorItemDragEnded(WindowSelectorItem* item);
ScopedTransformOverviewWindow::GridWindowFillMode GetWindowDimensionsType() ScopedTransformOverviewWindow::GridWindowFillMode GetWindowDimensionsType()
const; const;
...@@ -150,6 +156,9 @@ class ASH_EXPORT WindowSelectorItem : public views::ButtonListener, ...@@ -150,6 +156,9 @@ class ASH_EXPORT WindowSelectorItem : public views::ButtonListener,
void ActivateDraggedWindow(); void ActivateDraggedWindow();
void ResetDraggedWindowGesture(); void ResetDraggedWindowGesture();
float GetCloseButtonOpacityForTesting();
float GetTitlebarOpacityForTesting();
private: private:
class CaptionContainerView; class CaptionContainerView;
class RoundedContainerView; class RoundedContainerView;
......
...@@ -2121,6 +2121,48 @@ TEST_F(WindowSelectorTest, ExtremeWindowBounds) { ...@@ -2121,6 +2121,48 @@ TEST_F(WindowSelectorTest, ExtremeWindowBounds) {
normal_item->GetWindowDimensionsType()); normal_item->GetWindowDimensionsType());
} }
// Verify that the window selector items titlebar and close button change
// visibility when a item is being dragged.
TEST_F(WindowSelectorTest, WindowItemTitleCloseVisibilityOnDrag) {
base::CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kAshEnableNewOverviewUi);
UpdateDisplay("400x400");
const gfx::Rect bounds(10, 10, 200, 200);
std::unique_ptr<aura::Window> window1(CreateWindow(bounds));
std::unique_ptr<aura::Window> window2(CreateWindow(bounds));
// Dragging is only allowed in tablet mode.
RunAllPendingInMessageLoop();
Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(true);
ToggleOverview();
WindowSelectorItem* item1 = GetWindowItemForWindow(0, window1.get());
WindowSelectorItem* item2 = GetWindowItemForWindow(0, window2.get());
// Start the drag on |item1|. Verify the dragged item, |item1| has both the
// close button and titlebar hidden. All other items, |item2| should only have
// the close button hidden.
GetEventGenerator().MoveMouseTo(item1->target_bounds().CenterPoint());
GetEventGenerator().PressLeftButton();
RunAllPendingInMessageLoop();
EXPECT_EQ(0.f, item1->GetTitlebarOpacityForTesting());
EXPECT_EQ(0.f, item1->GetCloseButtonOpacityForTesting());
EXPECT_EQ(1.f, item2->GetTitlebarOpacityForTesting());
EXPECT_EQ(0.f, item2->GetCloseButtonOpacityForTesting());
// Drag |item1| in a way so that |window1| does not get activated (drags
// within a certain threshold count as clicks). Verify the close button and
// titlebar is visible for all items.
GetEventGenerator().MoveMouseTo(gfx::Point(200, 200));
GetEventGenerator().ReleaseLeftButton();
RunAllPendingInMessageLoop();
EXPECT_EQ(1.f, item1->GetTitlebarOpacityForTesting());
EXPECT_EQ(1.f, item1->GetCloseButtonOpacityForTesting());
EXPECT_EQ(1.f, item2->GetTitlebarOpacityForTesting());
EXPECT_EQ(1.f, item2->GetCloseButtonOpacityForTesting());
}
class SplitViewWindowSelectorTest : public WindowSelectorTest { class SplitViewWindowSelectorTest : public WindowSelectorTest {
public: public:
SplitViewWindowSelectorTest() = default; SplitViewWindowSelectorTest() = default;
......
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