summaryrefslogtreecommitdiffstats
path: root/ash
diff options
context:
space:
mode:
authorsadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-09 21:20:32 +0000
committersadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-09 21:20:32 +0000
commit17da26a8e321b3ea620e8818394cd4c9935379bd (patch)
tree4050c2fd047d251e93df59e00b9a4dbbc4745f07 /ash
parent5621518723517aa6a4f9e3b56f8496371a11a920 (diff)
downloadchromium_src-17da26a8e321b3ea620e8818394cd4c9935379bd.zip
chromium_src-17da26a8e321b3ea620e8818394cd4c9935379bd.tar.gz
chromium_src-17da26a8e321b3ea620e8818394cd4c9935379bd.tar.bz2
ash: Fix shelf dragging from auto-hidden state.
The fixes include: * When shelf-dragging starts with the shelf hidden, the initial height of the shelf should start at the default auto-hide size, and then be adjusted for the drag. * During the drag, make sure the launcher has the same height as the shelf. This fixes the launcher highlights to always stick to the edge of the screen. * Make sure the shelf is always bottom aligned with the screen during the drag. This CL also adds mechanism to test the state of the UI after each step of a scroll sequence. BUG=222390, 222389, 222395 Review URL: https://codereview.chromium.org/13825002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@193213 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r--ash/shelf/shelf_layout_manager.cc58
-rw-r--r--ash/shelf/shelf_layout_manager_unittest.cc129
2 files changed, 143 insertions, 44 deletions
diff --git a/ash/shelf/shelf_layout_manager.cc b/ash/shelf/shelf_layout_manager.cc
index b38b803d..b26f524 100644
--- a/ash/shelf/shelf_layout_manager.cc
+++ b/ash/shelf/shelf_layout_manager.cc
@@ -651,19 +651,20 @@ void ShelfLayoutManager::CalculateTargetBounds(
if (state.visibility_state == SHELF_AUTO_HIDE &&
state.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN) {
- // Keep the launcher to its full height when dragging is in progress.
- if (gesture_drag_status_ == GESTURE_DRAG_NONE) {
- if (IsHorizontalAlignment())
- shelf_height = kAutoHideSize;
- else
- shelf_width = kAutoHideSize;
- }
+ // Auto-hidden shelf always starts with the default size. If a gesture-drag
+ // is in progress, then the call to UpdateTargetBoundsForGesture() below
+ // takes care of setting the height properly.
+ if (IsHorizontalAlignment())
+ shelf_height = kAutoHideSize;
+ else
+ shelf_width = kAutoHideSize;
} else if (state.visibility_state == SHELF_HIDDEN) {
if (IsHorizontalAlignment())
shelf_height = 0;
else
shelf_width = 0;
}
+
target_bounds->shelf_bounds_in_root = SelectValueForShelfAlignment(
gfx::Rect(available_bounds.x(), available_bounds.bottom() - shelf_height,
available_bounds.width(), shelf_height),
@@ -689,14 +690,6 @@ void ShelfLayoutManager::CalculateTargetBounds(
shelf_height - (status_size.height() + status_inset),
status_size.width(), status_size.height()));
- target_bounds->launcher_bounds_in_shelf = SelectValueForShelfAlignment(
- gfx::Rect(base::i18n::IsRTL() ? status_size.width() : 0, 0,
- shelf_width - status_size.width(), shelf_height),
- gfx::Rect(0, 0, shelf_width, shelf_height - status_size.height()),
- gfx::Rect(0, 0, shelf_width, shelf_height - status_size.height()),
- gfx::Rect(base::i18n::IsRTL() ? status_size.width() : 0, 0,
- shelf_width - status_size.width(), shelf_height));
-
target_bounds->work_area_insets = SelectValueForShelfAlignment(
gfx::Insets(0, 0, GetWorkAreaSize(state, shelf_height), 0),
gfx::Insets(0, GetWorkAreaSize(state, shelf_width), 0, 0),
@@ -707,8 +700,21 @@ void ShelfLayoutManager::CalculateTargetBounds(
(gesture_drag_status_ != GESTURE_DRAG_NONE ||
state.visibility_state == SHELF_VISIBLE ||
state.visibility_state == SHELF_AUTO_HIDE) ? 1.0f : 0.0f;
+
if (gesture_drag_status_ == GESTURE_DRAG_IN_PROGRESS)
UpdateTargetBoundsForGesture(target_bounds);
+
+ // This needs to happen after calling UpdateTargetBoundsForGesture(), because
+ // that can change the size of the shelf.
+ target_bounds->launcher_bounds_in_shelf = SelectValueForShelfAlignment(
+ gfx::Rect(base::i18n::IsRTL() ? status_size.width() : 0, 0,
+ shelf_width - status_size.width(),
+ target_bounds->shelf_bounds_in_root.height()),
+ gfx::Rect(0, 0, shelf_width, shelf_height - status_size.height()),
+ gfx::Rect(0, 0, shelf_width, shelf_height - status_size.height()),
+ gfx::Rect(base::i18n::IsRTL() ? status_size.width() : 0, 0,
+ shelf_width - status_size.width(),
+ target_bounds->shelf_bounds_in_root.height()));
}
void ShelfLayoutManager::UpdateTargetBoundsForGesture(
@@ -748,13 +754,12 @@ void ShelfLayoutManager::UpdateTargetBoundsForGesture(
if (horizontal) {
// Move and size the launcher with the gesture.
+ int shelf_height = target_bounds->shelf_bounds_in_root.height() - translate;
+ shelf_height = std::max(shelf_height, kAutoHideSize);
+ target_bounds->shelf_bounds_in_root.set_height(shelf_height);
if (alignment_ == SHELF_ALIGNMENT_BOTTOM) {
- target_bounds->shelf_bounds_in_root.Offset(0, translate);
- target_bounds->shelf_bounds_in_root.set_height(
- available_bounds.bottom() - target_bounds->shelf_bounds_in_root.y());
- } else {
- target_bounds->shelf_bounds_in_root.set_height(
- target_bounds->shelf_bounds_in_root.height() + translate);
+ target_bounds->shelf_bounds_in_root.set_y(
+ available_bounds.bottom() - shelf_height);
}
// The statusbar should be in the center of the shelf.
@@ -765,13 +770,12 @@ void ShelfLayoutManager::UpdateTargetBoundsForGesture(
target_bounds->status_bounds_in_shelf.set_y(status_y.y());
} else {
// Move and size the launcher with the gesture.
+ int shelf_width = target_bounds->shelf_bounds_in_root.width() - translate;
+ shelf_width = std::max(shelf_width, kAutoHideSize);
+ target_bounds->shelf_bounds_in_root.set_width(shelf_width);
if (alignment_ == SHELF_ALIGNMENT_RIGHT) {
- target_bounds->shelf_bounds_in_root.Offset(translate, 0);
- target_bounds->shelf_bounds_in_root.set_width(
- available_bounds.right() - target_bounds->shelf_bounds_in_root.x());
- } else {
- target_bounds->shelf_bounds_in_root.set_width(
- target_bounds->shelf_bounds_in_root.width() + translate);
+ target_bounds->shelf_bounds_in_root.set_y(
+ available_bounds.right() - shelf_width);
}
// The statusbar should be in the center of the shelf.
diff --git a/ash/shelf/shelf_layout_manager_unittest.cc b/ash/shelf/shelf_layout_manager_unittest.cc
index b3e7a77..74d88df 100644
--- a/ash/shelf/shelf_layout_manager_unittest.cc
+++ b/ash/shelf/shelf_layout_manager_unittest.cc
@@ -66,6 +66,78 @@ SystemTray* GetSystemTray() {
return Shell::GetPrimaryRootWindowController()->GetSystemTray();
}
+class ShelfDragCallback {
+ public:
+ ShelfDragCallback(const gfx::Rect& not_visible, const gfx::Rect& visible)
+ : not_visible_bounds_(not_visible),
+ visible_bounds_(visible),
+ was_visible_on_drag_start_(false) {
+ EXPECT_EQ(not_visible_bounds_.bottom(), visible_bounds_.bottom());
+ }
+
+ virtual ~ShelfDragCallback() {
+ }
+
+ void ProcessScroll(ui::EventType type, const gfx::Vector2dF& delta) {
+ if (GetShelfLayoutManager()->visibility_state() == ash::SHELF_HIDDEN)
+ return;
+
+ if (type == ui::ET_GESTURE_SCROLL_BEGIN) {
+ scroll_ = gfx::Vector2dF();
+ was_visible_on_drag_start_ = GetShelfLayoutManager()->IsVisible();
+ return;
+ }
+
+ // The state of the shelf at the end of the gesture is tested separately.
+ if (type == ui::ET_GESTURE_SCROLL_END)
+ return;
+
+ if (type == ui::ET_GESTURE_SCROLL_UPDATE)
+ scroll_.Add(delta);
+
+ gfx::Rect shelf_bounds = GetShelfWidget()->GetWindowBoundsInScreen();
+ EXPECT_EQ(not_visible_bounds_.bottom(), shelf_bounds.bottom());
+ EXPECT_EQ(visible_bounds_.bottom(), shelf_bounds.bottom());
+
+ // The shelf should never be smaller than the hidden state.
+ EXPECT_GE(shelf_bounds.height(), not_visible_bounds_.height());
+
+ if (was_visible_on_drag_start_) {
+ if (scroll_.y() < 0) {
+ // If dragging up from the visible state, then the shelf should increase
+ // in height, but not as much as the scroll delta.
+ EXPECT_LE(shelf_bounds.y(), visible_bounds_.y());
+ EXPECT_LE(abs(shelf_bounds.y() - visible_bounds_.y()),
+ abs(scroll_.y()));
+ } else {
+ if (shelf_bounds.height() > not_visible_bounds_.height()) {
+ // If dragging down from the visible state, then the shelf should
+ // decrease in height, until it reaches the minimum height.
+ EXPECT_EQ(shelf_bounds.y(), visible_bounds_.y() + (scroll_.y()));
+ }
+ }
+ } else {
+ if (fabs(scroll_.y()) < not_visible_bounds_.y() - visible_bounds_.y()) {
+ // Tests that the shelf sticks with the touch point during the drag
+ // until the shelf is completely visible.
+ EXPECT_EQ(shelf_bounds.y(), not_visible_bounds_.y() + scroll_.y());
+ } else {
+ // Tests that after the shelf is completely visible, the shelf starts
+ // resisting the drag.
+ EXPECT_GT(shelf_bounds.y(), not_visible_bounds_.y() + scroll_.y());
+ }
+ }
+ }
+
+ private:
+ const gfx::Rect not_visible_bounds_;
+ const gfx::Rect visible_bounds_;
+ gfx::Vector2dF scroll_;
+ bool was_visible_on_drag_start_;
+
+ DISALLOW_COPY_AND_ASSIGN(ShelfDragCallback);
+};
+
class ShelfLayoutObserverTest : public ShelfLayoutManager::Observer {
public:
ShelfLayoutObserverTest()
@@ -885,7 +957,19 @@ TEST_F(ShelfLayoutManagerTest, MAYBE_GestureDrag) {
gfx::Rect bounds_shelf = window->bounds();
EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
+ shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
+ shelf->LayoutShelf();
+ EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
+
+ gfx::Rect bounds_noshelf = window->bounds();
+ gfx::Rect shelf_hidden = GetShelfWidget()->GetWindowBoundsInScreen();
+
+ shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
+ shelf->LayoutShelf();
+
aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
+ const int kNumScrollSteps = 10;
+ ShelfDragCallback handler(shelf_hidden, shelf_shown);
// Swipe up on the shelf. This should not change any state.
gfx::Point start = GetShelfWidget()->GetWindowBoundsInScreen().CenterPoint();
@@ -893,8 +977,10 @@ TEST_F(ShelfLayoutManagerTest, MAYBE_GestureDrag) {
// Swipe down on the shelf to hide it.
end.set_y(start.y() + 100);
- generator.GestureScrollSequence(start, end,
- base::TimeDelta::FromMilliseconds(10), 1);
+ generator.GestureScrollSequenceWithCallback(start, end,
+ base::TimeDelta::FromMilliseconds(10), kNumScrollSteps,
+ base::Bind(&ShelfDragCallback::ProcessScroll,
+ base::Unretained(&handler)));
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
@@ -902,12 +988,11 @@ TEST_F(ShelfLayoutManagerTest, MAYBE_GestureDrag) {
EXPECT_NE(shelf_shown.ToString(),
GetShelfWidget()->GetWindowBoundsInScreen().ToString());
- gfx::Rect bounds_noshelf = window->bounds();
- gfx::Rect shelf_hidden = GetShelfWidget()->GetWindowBoundsInScreen();
-
// Swipe up to show the shelf.
- generator.GestureScrollSequence(end, start,
- base::TimeDelta::FromMilliseconds(10), 1);
+ generator.GestureScrollSequenceWithCallback(end, start,
+ base::TimeDelta::FromMilliseconds(10), kNumScrollSteps,
+ base::Bind(&ShelfDragCallback::ProcessScroll,
+ base::Unretained(&handler)));
EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior());
EXPECT_EQ(bounds_shelf.ToString(), window->bounds().ToString());
@@ -916,8 +1001,10 @@ TEST_F(ShelfLayoutManagerTest, MAYBE_GestureDrag) {
// Swipe up again. The shelf should hide.
end.set_y(start.y() - 100);
- generator.GestureScrollSequence(start, end,
- base::TimeDelta::FromMilliseconds(10), 1);
+ generator.GestureScrollSequenceWithCallback(start, end,
+ base::TimeDelta::FromMilliseconds(10), kNumScrollSteps,
+ base::Bind(&ShelfDragCallback::ProcessScroll,
+ base::Unretained(&handler)));
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
@@ -926,13 +1013,17 @@ TEST_F(ShelfLayoutManagerTest, MAYBE_GestureDrag) {
// Swipe up yet again to show it.
end.set_y(start.y() + 100);
- generator.GestureScrollSequence(end, start,
- base::TimeDelta::FromMilliseconds(10), 1);
+ generator.GestureScrollSequenceWithCallback(end, start,
+ base::TimeDelta::FromMilliseconds(10), kNumScrollSteps,
+ base::Bind(&ShelfDragCallback::ProcessScroll,
+ base::Unretained(&handler)));
// Swipe down very little. It shouldn't change any state.
end.set_y(start.y() + shelf_shown.height() * 3 / 10);
- generator.GestureScrollSequence(start, end,
- base::TimeDelta::FromMilliseconds(100), 1);
+ generator.GestureScrollSequenceWithCallback(start, end,
+ base::TimeDelta::FromMilliseconds(100), 1,
+ base::Bind(&ShelfDragCallback::ProcessScroll,
+ base::Unretained(&handler)));
EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior());
EXPECT_EQ(bounds_shelf.ToString(), window->bounds().ToString());
@@ -941,8 +1032,10 @@ TEST_F(ShelfLayoutManagerTest, MAYBE_GestureDrag) {
// Swipe down again to hide.
end.set_y(start.y() + 100);
- generator.GestureScrollSequence(start, end,
- base::TimeDelta::FromMilliseconds(10), 1);
+ generator.GestureScrollSequenceWithCallback(start, end,
+ base::TimeDelta::FromMilliseconds(10), kNumScrollSteps,
+ base::Bind(&ShelfDragCallback::ProcessScroll,
+ base::Unretained(&handler)));
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
@@ -958,8 +1051,10 @@ TEST_F(ShelfLayoutManagerTest, MAYBE_GestureDrag) {
EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state());
// Swipe-up. This should not change anything.
- generator.GestureScrollSequence(end, start,
- base::TimeDelta::FromMilliseconds(10), 1);
+ generator.GestureScrollSequenceWithCallback(end, start,
+ base::TimeDelta::FromMilliseconds(10), kNumScrollSteps,
+ base::Bind(&ShelfDragCallback::ProcessScroll,
+ base::Unretained(&handler)));
EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state());
EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
EXPECT_EQ(bounds_fullscreen.ToString(), window->bounds().ToString());