summaryrefslogtreecommitdiffstats
path: root/ash
diff options
context:
space:
mode:
authorsimonhong@chromium.org <simonhong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-26 23:24:17 +0000
committersimonhong@chromium.org <simonhong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-26 23:24:17 +0000
commit15cc6bedb9143afb15db0e6d5435a60244467b62 (patch)
tree3ade7d16049dabac02c2b7d012dde93d5c7c2711 /ash
parent6f742dd07eaf78c0defb248e487a53480b1971e1 (diff)
downloadchromium_src-15cc6bedb9143afb15db0e6d5435a60244467b62.zip
chromium_src-15cc6bedb9143afb15db0e6d5435a60244467b62.tar.gz
chromium_src-15cc6bedb9143afb15db0e6d5435a60244467b62.tar.bz2
[ash] Cannot re-insert an item in the scrolled OverflowBubble
Problem: Origin of DragInsertBounds is calculated by using ShelfView. When scroll is occurred to last item, the origin of ShelfView in OverflowBubble is different from OverflowBubble's. R=jamescook@chromium.org BUG=322389 TEST=ash_unittests --gtest_filter=ShelfViewTest.CheckDragInsertBoundsOfScrolledOverflowBubble Review URL: https://codereview.chromium.org/82793003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@237432 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r--ash/ash.gyp2
-rw-r--r--ash/shelf/overflow_bubble.cc4
-rw-r--r--ash/shelf/overflow_bubble.h4
-rw-r--r--ash/shelf/overflow_bubble_view.h11
-rw-r--r--ash/shelf/shelf_view.cc15
-rw-r--r--ash/shelf/shelf_view_unittest.cc62
-rw-r--r--ash/test/overflow_bubble_view_test_api.cc30
-rw-r--r--ash/test/overflow_bubble_view_test_api.h43
8 files changed, 161 insertions, 10 deletions
diff --git a/ash/ash.gyp b/ash/ash.gyp
index 1bb6063..091465e 100644
--- a/ash/ash.gyp
+++ b/ash/ash.gyp
@@ -661,6 +661,8 @@
'test/launcher_item_delegate_manager_test_api.h',
'test/mirror_window_test_api.cc',
'test/mirror_window_test_api.h',
+ 'test/overflow_bubble_view_test_api.cc',
+ 'test/overflow_bubble_view_test_api.h',
'test/shell_test_api.cc',
'test/shell_test_api.h',
'test/test_activation_delegate.cc',
diff --git a/ash/shelf/overflow_bubble.cc b/ash/shelf/overflow_bubble.cc
index c8f232a..35c885f 100644
--- a/ash/shelf/overflow_bubble.cc
+++ b/ash/shelf/overflow_bubble.cc
@@ -69,10 +69,6 @@ void OverflowBubble::HideBubbleAndRefreshButton() {
anchor->SchedulePaint();
}
-gfx::Rect OverflowBubble::GetBubbleBounds() {
- return bubble_->GetBubbleBounds();
-}
-
void OverflowBubble::ProcessPressedEvent(ui::LocatedEvent* event) {
aura::Window* target = static_cast<aura::Window*>(event->target());
gfx::Point event_location_in_screen = event->location();
diff --git a/ash/shelf/overflow_bubble.h b/ash/shelf/overflow_bubble.h
index da152fa..26bdf7a 100644
--- a/ash/shelf/overflow_bubble.h
+++ b/ash/shelf/overflow_bubble.h
@@ -44,9 +44,7 @@ class OverflowBubble : public ui::EventHandler,
bool IsShowing() const { return !!bubble_; }
ShelfView* shelf_view() { return shelf_view_; }
-
- // Returns overflow bubble bounds in screen coordinate.
- gfx::Rect GetBubbleBounds();
+ OverflowBubbleView* bubble_view() { return bubble_; }
private:
void ProcessPressedEvent(ui::LocatedEvent* event);
diff --git a/ash/shelf/overflow_bubble_view.h b/ash/shelf/overflow_bubble_view.h
index 2b3076d..f5bfdc1 100644
--- a/ash/shelf/overflow_bubble_view.h
+++ b/ash/shelf/overflow_bubble_view.h
@@ -5,18 +5,25 @@
#ifndef ASH_SHELF_OVERFLOW_BUBBLE_VIEW_H_
#define ASH_SHELF_OVERFLOW_BUBBLE_VIEW_H_
+#include "ash/ash_export.h"
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "ui/views/bubble/bubble_delegate.h"
namespace ash {
+
+namespace test {
+class OverflowBubbleViewTestAPI;
+}
+
namespace internal {
class ShelfLayoutManager;
class ShelfView;
// OverflowBubbleView hosts a ShelfView to display overflown items.
-class OverflowBubbleView : public views::BubbleDelegateView {
+// Exports to access this class from OverflowBubbleViewTestAPI.
+class ASH_EXPORT OverflowBubbleView : public views::BubbleDelegateView {
public:
OverflowBubbleView();
virtual ~OverflowBubbleView();
@@ -27,6 +34,8 @@ class OverflowBubbleView : public views::BubbleDelegateView {
virtual gfx::Rect GetBubbleBounds() OVERRIDE;
private:
+ friend class test::OverflowBubbleViewTestAPI;
+
bool IsHorizontalAlignment() const;
const gfx::Size GetContentsSize() const;
diff --git a/ash/shelf/shelf_view.cc b/ash/shelf/shelf_view.cc
index 87316fb..7fc5ec6 100644
--- a/ash/shelf/shelf_view.cc
+++ b/ash/shelf/shelf_view.cc
@@ -17,6 +17,7 @@
#include "ash/shelf/alternate_app_list_button.h"
#include "ash/shelf/app_list_button.h"
#include "ash/shelf/overflow_bubble.h"
+#include "ash/shelf/overflow_bubble_view.h"
#include "ash/shelf/overflow_button.h"
#include "ash/shelf/shelf_button.h"
#include "ash/shelf/shelf_icon_observer.h"
@@ -1341,7 +1342,8 @@ gfx::Rect ShelfView::GetBoundsForDragInsertInScreen() {
gfx::Size preferred_size;
if (is_overflow_mode()) {
DCHECK(owner_overflow_bubble_);
- gfx::Rect bubble_bounds = owner_overflow_bubble_->GetBubbleBounds();
+ gfx::Rect bubble_bounds =
+ owner_overflow_bubble_->bubble_view()->GetBubbleBounds();
preferred_size = bubble_bounds.size();
} else {
const int preferred_shelf_size = layout_manager_->GetPreferredShelfSize();
@@ -1365,7 +1367,16 @@ gfx::Rect ShelfView::GetBoundsForDragInsertInScreen() {
}
}
gfx::Point origin(GetMirroredXWithWidthInView(0, preferred_size.width()), 0);
- ConvertPointToScreen(this, &origin);
+
+ // In overflow mode, we should use OverflowBubbleView as a source for
+ // converting |origin| to screen coordinates. When a scroll operation is
+ // occurred in OverflowBubble, the bounds of ShelfView in OverflowBubble can
+ // be changed.
+ if (is_overflow_mode())
+ ConvertPointToScreen(owner_overflow_bubble_->bubble_view(), &origin);
+ else
+ ConvertPointToScreen(this, &origin);
+
return gfx::Rect(origin, preferred_size);
}
diff --git a/ash/shelf/shelf_view_unittest.cc b/ash/shelf/shelf_view_unittest.cc
index 21f3f91..28812d1 100644
--- a/ash/shelf/shelf_view_unittest.cc
+++ b/ash/shelf/shelf_view_unittest.cc
@@ -13,6 +13,7 @@
#include "ash/launcher/launcher_types.h"
#include "ash/root_window_controller.h"
#include "ash/shelf/overflow_bubble.h"
+#include "ash/shelf/overflow_bubble_view.h"
#include "ash/shelf/shelf_button.h"
#include "ash/shelf/shelf_icon_observer.h"
#include "ash/shelf/shelf_layout_manager.h"
@@ -23,6 +24,7 @@
#include "ash/shell_window_ids.h"
#include "ash/test/ash_test_base.h"
#include "ash/test/launcher_test_api.h"
+#include "ash/test/overflow_bubble_view_test_api.h"
#include "ash/test/shelf_view_test_api.h"
#include "ash/test/shell_test_api.h"
#include "ash/test/test_launcher_delegate.h"
@@ -1415,6 +1417,66 @@ TEST_F(ShelfViewLegacyShelfLayoutTest, CheckFittsLaw) {
EXPECT_GT(ideal_bounds_0.width(), ideal_bounds_1.width());
}
+// Check the drag insertion bounds of scrolled overflow bubble.
+TEST_F(ShelfViewTest, CheckDragInsertBoundsOfScrolledOverflowBubble) {
+ UpdateDisplay("400x300");
+
+ EXPECT_EQ(2, model_->item_count());
+
+ // Add buttons until overflow.
+ int items_added = 0;
+ while (!test_api_->IsOverflowButtonVisible()) {
+ AddAppShortcut();
+ ++items_added;
+ ASSERT_LT(items_added, 10000);
+ }
+
+ // Show overflow bubble.
+ test_api_->ShowOverflowBubble();
+ ASSERT_TRUE(test_api_->overflow_bubble() &&
+ test_api_->overflow_bubble()->IsShowing());
+
+ int item_width = test_api_->GetButtonSize() +
+ test_api_->GetButtonSpacing();
+ internal::OverflowBubbleView* bubble_view =
+ test_api_->overflow_bubble()->bubble_view();
+ test::OverflowBubbleViewTestAPI bubble_view_api(bubble_view);
+
+ // Add more buttons until OverflowBubble is scrollable and it has 3 invisible
+ // items.
+ while (bubble_view_api.GetContentsSize().width() <
+ (bubble_view->GetContentsBounds().width() + 3 * item_width))
+ AddAppShortcut();
+
+ ASSERT_TRUE(test_api_->overflow_bubble() &&
+ test_api_->overflow_bubble()->IsShowing());
+
+ ash::test::ShelfViewTestAPI test_for_overflow_view(
+ test_api_->overflow_bubble()->shelf_view());
+ int first_index = test_for_overflow_view.GetFirstVisibleIndex();
+ int last_index = test_for_overflow_view.GetLastVisibleIndex();
+
+ ash::internal::ShelfButton* first_button =
+ test_for_overflow_view.GetButton(first_index);
+ ash::internal::ShelfButton* last_button =
+ test_for_overflow_view.GetButton(last_index);
+ gfx::Point first_point = first_button->GetBoundsInScreen().CenterPoint();
+ gfx::Point last_point = last_button->GetBoundsInScreen().CenterPoint();
+ gfx::Rect drag_reinsert_bounds =
+ test_for_overflow_view.GetBoundsForDragInsertInScreen();
+ EXPECT_TRUE(drag_reinsert_bounds.Contains(first_point));
+ EXPECT_FALSE(drag_reinsert_bounds.Contains(last_point));
+
+ // Scrolls sufficiently to show last item.
+ bubble_view_api.ScrollByXOffset(3 * item_width);
+ drag_reinsert_bounds =
+ test_for_overflow_view.GetBoundsForDragInsertInScreen();
+ first_point = first_button->GetBoundsInScreen().CenterPoint();
+ last_point = last_button->GetBoundsInScreen().CenterPoint();
+ EXPECT_FALSE(drag_reinsert_bounds.Contains(first_point));
+ EXPECT_TRUE(drag_reinsert_bounds.Contains(last_point));
+}
+
// Check the drag insertion bounds of shelf view in multi monitor environment.
TEST_F(ShelfViewTest, CheckDragInsertBoundsWithMultiMonitor) {
// win8-aura doesn't support multiple display.
diff --git a/ash/test/overflow_bubble_view_test_api.cc b/ash/test/overflow_bubble_view_test_api.cc
new file mode 100644
index 0000000..cfbfc73
--- /dev/null
+++ b/ash/test/overflow_bubble_view_test_api.cc
@@ -0,0 +1,30 @@
+// Copyright 2013 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/test/overflow_bubble_view_test_api.h"
+
+#include "ash/shelf/overflow_bubble_view.h"
+
+namespace ash {
+namespace test {
+
+OverflowBubbleViewTestAPI::OverflowBubbleViewTestAPI(
+ internal::OverflowBubbleView* bubble_view)
+ : bubble_view_(bubble_view) {
+}
+
+OverflowBubbleViewTestAPI::~OverflowBubbleViewTestAPI() {
+}
+
+gfx::Size OverflowBubbleViewTestAPI::GetContentsSize() {
+ return bubble_view_->GetContentsSize();
+}
+
+void OverflowBubbleViewTestAPI::ScrollByXOffset(int x_offset) {
+ bubble_view_->ScrollByXOffset(x_offset);
+ bubble_view_->Layout();
+}
+
+} // namespace test
+} // namespace ash
diff --git a/ash/test/overflow_bubble_view_test_api.h b/ash/test/overflow_bubble_view_test_api.h
new file mode 100644
index 0000000..b789b73
--- /dev/null
+++ b/ash/test/overflow_bubble_view_test_api.h
@@ -0,0 +1,43 @@
+// Copyright 2013 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_TEST_OVERFLOW_BUBBLE_VIEW_TEST_API_
+#define ASH_TEST_OVERFLOW_BUBBLE_VIEW_TEST_API_
+
+#include "base/basictypes.h"
+
+namespace gfx {
+class Size;
+}
+
+namespace ash {
+
+namespace internal {
+class OverflowBubbleView;
+}
+
+namespace test {
+
+class OverflowBubbleViewTestAPI {
+ public:
+ explicit OverflowBubbleViewTestAPI(internal::OverflowBubbleView* bubble_view);
+ ~OverflowBubbleViewTestAPI();
+
+ // Returns the total width of items included in ShelfView.
+ gfx::Size GetContentsSize();
+
+ // Emulates scroll operations on OverflowBubble to make invisible last item
+ // visible.
+ void ScrollByXOffset(int x_offset);
+
+ private:
+ internal::OverflowBubbleView* bubble_view_;
+
+ DISALLOW_COPY_AND_ASSIGN(OverflowBubbleViewTestAPI);
+};
+
+} // namespace test
+} // namespace ash
+
+#endif // ASH_TEST_OVERFLOW_BUBBLE_VIEW_TEST_API_