Commit 632ec8db authored by Min Chen's avatar Min Chen Committed by Commit Bot

No top drag indicator if a window is dragged from top in portrait screen orientation.

1. Added IndicatorType
   kDragAreaLeft, kCannotSnapLeft to show only left/top drag indicator,
   kDragAreaRight, kCannotSnapRight to show only right/bottom drag indicator,
   only kDragAreRight and kCannotSnapRight are used in this change, but still
   added kDragAreLeft and kCannotSnapLeft to keep consistence.

2. Move the logic to update the opacity of highlight view and label view from
   SplitViewDragIndicators to SplitViewHighligtView and RotatedImageLabelView
   instead.

see recorded video:
https://drive.google.com/file/d/0B5I0jFeLxqIiOGV3c0puTkJpTElBNUFSUlZpNEp6TElKUHJZ/view?usp=sharing

Bug: 871607
Test: SplitViewTabDraggingTest.DragIndicatorsInPortraitOrientationTest
Change-Id: I64f76766cd14dd2bca686be3f13d274993f24639
Reviewed-on: https://chromium-review.googlesource.com/1167998Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Commit-Queue: Min Chen <minch@chromium.org>
Cr-Commit-Position: refs/heads/master@{#583405}
parent a17f963e
......@@ -82,11 +82,6 @@ gfx::Point GetBoundedPosition(const gfx::Point& location_in_screen,
bounds_in_screen.y()));
}
// Transpose the given |rect|.
void TransposeRect(gfx::Rect* rect) {
rect->SetRect(rect->y(), rect->x(), rect->height(), rect->width());
}
mojom::SplitViewState ToMojomSplitViewState(SplitViewController::State state) {
switch (state) {
case SplitViewController::NO_SNAP:
......
......@@ -2299,6 +2299,49 @@ TEST_F(SplitViewTabDraggingTest, OverviewExitAnimationTest) {
EXPECT_FALSE(overview_observer->overview_animate_when_exiting());
}
// Tests that there is no top drag indicator if drag a window in portrait screen
// orientation.
TEST_F(SplitViewTabDraggingTest, DragIndicatorsInPortraitOrientationTest) {
UpdateDisplay("800x600");
int64_t display_id = display::Screen::GetScreen()->GetPrimaryDisplay().id();
display::DisplayManager* display_manager = Shell::Get()->display_manager();
display::test::ScopedSetInternalDisplayId set_internal(display_manager,
display_id);
ScreenOrientationControllerTestApi test_api(
Shell::Get()->screen_orientation_controller());
ASSERT_EQ(test_api.GetCurrentOrientation(),
OrientationLockType::kLandscapePrimary);
const gfx::Rect bounds(0, 0, 400, 400);
std::unique_ptr<aura::Window> window(CreateWindow(bounds));
wm::GetWindowState(window.get())->Maximize();
EXPECT_TRUE(wm::GetWindowState(window.get())->IsMaximized());
std::unique_ptr<WindowResizer> resizer =
StartDrag(window.get(), window.get());
ASSERT_TRUE(resizer.get());
EXPECT_TRUE(Shell::Get()->window_selector_controller()->IsSelecting());
// Drag the window past the indicators threshold to show the indicators.
DragWindowTo(resizer.get(),
gfx::Point(200, GetIndicatorsThreshold(window.get())));
EXPECT_EQ(GetIndicatorState(resizer.get()), IndicatorState::kDragArea);
CompleteDrag(std::move(resizer));
EXPECT_TRUE(wm::GetWindowState(window.get())->IsMaximized());
// Rotate the screen by 270 degree to portrait primary orientation.
test_api.SetDisplayRotation(display::Display::ROTATE_270,
display::Display::RotationSource::ACTIVE);
EXPECT_EQ(test_api.GetCurrentOrientation(),
OrientationLockType::kPortraitPrimary);
resizer = StartDrag(window.get(), window.get());
ASSERT_TRUE(resizer.get());
// Drag the window past the indicators threshold to show the indicators.
DragWindowTo(resizer.get(),
gfx::Point(200, GetIndicatorsThreshold(window.get())));
EXPECT_EQ(GetIndicatorState(resizer.get()), IndicatorState::kDragAreaRight);
CompleteDrag(std::move(resizer));
EXPECT_TRUE(wm::GetWindowState(window.get())->IsMaximized());
}
class TestWindowDelegateWithWidget : public views::WidgetDelegate {
public:
TestWindowDelegateWithWidget(bool can_activate)
......
......@@ -22,9 +22,30 @@ namespace ash {
// Enum which contains the possible states SplitViewDragIndicators can be in.
enum class IndicatorState {
kNone,
// Showing both left/top and right/bottom drag guidances.
kDragArea,
// Showing only left/top drag guidance.
kDragAreaLeft,
// Showing only right/bottom drag guidance.
kDragAreaRight,
// Showing both left/top and right/bottom cannot drag indicators.
kCannotSnap,
// Showing only left/top cannot drag indicator.
kCannotSnapLeft,
// Showing only right/bottom cannot drag indicator.
kCannotSnapRight,
// Showing a left/top preview area with the same bounds as left/top snapped
// window.
kPreviewAreaLeft,
// Showing a right/bottom preview area with the same bounds as right/bottom
// snapped window.
kPreviewAreaRight
};
......@@ -43,6 +64,15 @@ enum class IndicatorType {
// window has entered a snap region.
class ASH_EXPORT SplitViewDragIndicators {
public:
static bool IsPreviewAreaState(IndicatorState indicator_state);
static bool IsLeftIndicatorState(IndicatorState indicator_state);
static bool IsRightIndicatorState(IndicatorState indicator_state);
static bool IsCannotSnapState(IndicatorState indicator_state);
// Calculates whether the preview area should physically be on the left or
// top of the screen.
static bool IsPreviewAreaOnLeftTopOfScreen(IndicatorState indicator_state);
SplitViewDragIndicators();
~SplitViewDragIndicators();
......
......@@ -4,7 +4,9 @@
#include "ash/wm/splitview/split_view_highlight_view.h"
#include "ash/shell.h"
#include "ash/wm/overview/rounded_rect_view.h"
#include "ash/wm/splitview/split_view_controller.h"
#include "ash/wm/splitview/split_view_utils.h"
#include "ui/gfx/canvas.h"
#include "ui/views/view.h"
......@@ -168,4 +170,43 @@ void SplitViewHighlightView::SetColor(SkColor color) {
middle_->layer()->SetColor(color);
}
void SplitViewHighlightView::OnIndicatorTypeChanged(
IndicatorState indicator_state) {
if (indicator_state == IndicatorState::kNone) {
DoSplitviewOpacityAnimation(layer(),
SPLITVIEW_ANIMATION_HIGHLIGHT_FADE_OUT);
return;
}
if (SplitViewDragIndicators::IsPreviewAreaState(indicator_state)) {
const bool is_preview_on_left_or_top =
SplitViewDragIndicators::IsPreviewAreaOnLeftTopOfScreen(
indicator_state);
const bool should_fade_in = is_right_or_bottom_ ? !is_preview_on_left_or_top
: is_preview_on_left_or_top;
DoSplitviewOpacityAnimation(
layer(), should_fade_in ? SPLITVIEW_ANIMATION_PREVIEW_AREA_FADE_IN
: SPLITVIEW_ANIMATION_OTHER_HIGHLIGHT_FADE_OUT);
return;
}
// No need to update left/top highlight view for right indicator state and
// also no need to update right/bottom highlight view for left indicator
// state.
if ((!is_right_or_bottom_ &&
SplitViewDragIndicators::IsRightIndicatorState(indicator_state)) ||
(is_right_or_bottom_ &&
SplitViewDragIndicators::IsLeftIndicatorState(indicator_state))) {
return;
}
SetColor(SplitViewDragIndicators::IsCannotSnapState(indicator_state)
? SK_ColorBLACK
: SK_ColorWHITE);
DoSplitviewOpacityAnimation(layer(),
Shell::Get()->split_view_controller()->state() ==
SplitViewController::NO_SNAP
? SPLITVIEW_ANIMATION_HIGHLIGHT_FADE_IN
: SPLITVIEW_ANIMATION_HIGHLIGHT_FADE_OUT);
}
} // namespace ash
......@@ -6,6 +6,7 @@
#define ASH_WM_SPLITVIEW_SPLIT_VIEW_HIGHLIGHT_VIEW_H_
#include "ash/ash_export.h"
#include "ash/wm/splitview/split_view_drag_indicators.h"
#include "ui/views/view.h"
namespace ash {
......@@ -30,6 +31,9 @@ class ASH_EXPORT SplitViewHighlightView : public views::View {
void SetColor(SkColor color);
// Called to update the opacity of the highlights view on |indicator_state|.
void OnIndicatorTypeChanged(IndicatorState indicator_state);
private:
friend class SplitViewHighlightViewTestApi;
......@@ -50,4 +54,4 @@ class ASH_EXPORT SplitViewHighlightView : public views::View {
} // namespace ash
#endif // ASH_WM_SPLITVIEW_SPLIT_VIEW_HIGHLIGHT_VIEW_H_
\ No newline at end of file
#endif // ASH_WM_SPLITVIEW_SPLIT_VIEW_HIGHLIGHT_VIEW_H_
......@@ -9,6 +9,7 @@
#include "ui/compositor/layer_animation_observer.h"
#include "ui/compositor/layer_animator.h"
#include "ui/compositor/scoped_layer_animation_settings.h"
#include "ui/gfx/geometry/rect.h"
namespace ash {
......@@ -190,4 +191,8 @@ void DoSplitviewTransformAnimation(ui::Layer* layer,
layer->SetTransform(target_transform);
}
void TransposeRect(gfx::Rect* rect) {
rect->SetRect(rect->y(), rect->x(), rect->height(), rect->width());
}
} // namespace ash
......@@ -7,6 +7,10 @@
#include "ui/gfx/transform.h"
namespace gfx {
class Rect;
} // namespace gfx
namespace ui {
class Layer;
} // namespace ui
......@@ -66,6 +70,9 @@ void DoSplitviewTransformAnimation(ui::Layer* layer,
SplitviewAnimationType type,
const gfx::Transform& target_transform);
// Transposes the given |rect|.
void TransposeRect(gfx::Rect* rect);
} // namespace ash
#endif // ASH_WM_SPLITVIEW_SPLIT_VIEW_UTILS_H_
......@@ -320,7 +320,12 @@ IndicatorState TabletModeWindowDragDelegate::GetIndicatorState(
return IndicatorState::kNone;
}
return can_snap ? IndicatorState::kDragArea : IndicatorState::kCannotSnap;
// No top drag indicator if in portrait screen orientation.
if (split_view_controller_->IsCurrentScreenOrientationLandscape())
return can_snap ? IndicatorState::kDragArea : IndicatorState::kCannotSnap;
return can_snap ? IndicatorState::kDragAreaRight
: IndicatorState::kCannotSnapRight;
}
void TabletModeWindowDragDelegate::UpdateDraggedWindowTransform(
......
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