Index: ash/launcher/overflow_bubble.cc |
diff --git a/ash/launcher/overflow_bubble.cc b/ash/launcher/overflow_bubble.cc |
index b5a1be5e5c3e8d538455471331371c0268ee6a05..75d28afff3c1bddf931c9d1f5a97028bd1e2d337 100644 |
--- a/ash/launcher/overflow_bubble.cc |
+++ b/ash/launcher/overflow_bubble.cc |
@@ -10,6 +10,7 @@ |
#include "ash/launcher/launcher_view.h" |
#include "ash/system/tray/system_tray.h" |
#include "ash/shell.h" |
+#include "ash/wm/shelf_layout_manager.h" |
#include "ui/gfx/insets.h" |
#include "ui/gfx/screen.h" |
#include "ui/views/bubble/bubble_delegate.h" |
@@ -30,22 +31,6 @@ const int kPadding = 2; |
// Padding space in pixels between LauncherView's left/top edge to its contents. |
const int kLauncherViewLeadingInset = 8; |
-// Gets arrow location based on shelf alignment. |
-views::BubbleBorder::ArrowLocation GetBubbleArrowLocation( |
- ShelfAlignment shelf_alignment) { |
- switch (shelf_alignment) { |
- case ash::SHELF_ALIGNMENT_BOTTOM: |
- return views::BubbleBorder::BOTTOM_LEFT; |
- case ash::SHELF_ALIGNMENT_LEFT: |
- return views::BubbleBorder::LEFT_TOP; |
- case ash::SHELF_ALIGNMENT_RIGHT: |
- return views::BubbleBorder::RIGHT_TOP; |
- default: |
- NOTREACHED() << "Unknown shelf alignment " << shelf_alignment; |
- return views::BubbleBorder::BOTTOM_LEFT; |
- } |
-} |
- |
//////////////////////////////////////////////////////////////////////////////// |
// OverflowBubbleView |
// OverflowBubbleView hosts a LauncherView to display overflown items. |
@@ -58,18 +43,25 @@ class OverflowBubbleView : public views::BubbleDelegateView { |
void InitOverflowBubble(LauncherDelegate* delegate, |
LauncherModel* model, |
views::View* anchor, |
- ShelfAlignment shelf_alignment, |
int overflow_start_index); |
private: |
- bool is_horizontal_alignment() const { |
- return shelf_alignment_ == SHELF_ALIGNMENT_BOTTOM; |
+ bool IsHorizontalAlignment() const { |
+ return GetShelfLayoutManagerForLauncher()->IsHorizontalAlignment(); |
} |
const gfx::Size GetContentsSize() const { |
return static_cast<views::View*>(launcher_view_)->GetPreferredSize(); |
} |
+ // Gets arrow location based on shelf alignment. |
+ views::BubbleBorder::ArrowLocation GetBubbleArrowLocation() const { |
+ return GetShelfLayoutManagerForLauncher()->SelectValueForShelfAlignment( |
+ views::BubbleBorder::BOTTOM_LEFT, |
+ views::BubbleBorder::LEFT_TOP, |
+ views::BubbleBorder::RIGHT_TOP); |
+ } |
+ |
void ScrollByXOffset(int x_offset); |
void ScrollByYOffset(int y_offset); |
@@ -85,7 +77,11 @@ class OverflowBubbleView : public views::BubbleDelegateView { |
// views::BubbleDelegate overrides: |
virtual gfx::Rect GetBubbleBounds() OVERRIDE; |
- ShelfAlignment shelf_alignment_; |
+ ShelfLayoutManager* GetShelfLayoutManagerForLauncher() const { |
+ return ShelfLayoutManager::ForLauncher( |
+ anchor_view()->GetWidget()->GetNativeView()); |
+ } |
+ |
LauncherView* launcher_view_; // Owned by views hierarchy. |
gfx::Vector2d scroll_offset_; |
@@ -93,8 +89,7 @@ class OverflowBubbleView : public views::BubbleDelegateView { |
}; |
OverflowBubbleView::OverflowBubbleView() |
- : shelf_alignment_(SHELF_ALIGNMENT_BOTTOM), |
- launcher_view_(NULL) { |
+ : launcher_view_(NULL) { |
} |
OverflowBubbleView::~OverflowBubbleView() { |
@@ -103,14 +98,13 @@ OverflowBubbleView::~OverflowBubbleView() { |
void OverflowBubbleView::InitOverflowBubble(LauncherDelegate* delegate, |
LauncherModel* model, |
views::View* anchor, |
- ShelfAlignment shelf_alignment, |
int overflow_start_index) { |
- shelf_alignment_ = shelf_alignment; |
- |
// Makes bubble view has a layer and clip its children layers. |
SetPaintToLayer(true); |
SetFillsBoundsOpaquely(false); |
layer()->SetMasksToBounds(true); |
+ ShelfAlignment shelf_alignment = GetShelfLayoutManagerForLauncher()-> |
+ GetAlignment(); |
launcher_view_ = new LauncherView(model, delegate, NULL); |
launcher_view_->set_first_visible_index(overflow_start_index); |
@@ -120,7 +114,7 @@ void OverflowBubbleView::InitOverflowBubble(LauncherDelegate* delegate, |
AddChildView(launcher_view_); |
set_anchor_view(anchor); |
- set_arrow_location(GetBubbleArrowLocation(shelf_alignment)); |
+ set_arrow_location(GetBubbleArrowLocation()); |
set_background(NULL); |
set_color(SkColorSetARGB(kLauncherBackgroundAlpha, 0, 0, 0)); |
set_margins(gfx::Insets(kPadding, kPadding, kPadding, kPadding)); |
@@ -152,7 +146,7 @@ gfx::Size OverflowBubbleView::GetPreferredSize() { |
const gfx::Rect monitor_rect = Shell::GetScreen()->GetDisplayNearestPoint( |
GetAnchorRect().CenterPoint()).work_area(); |
if (!monitor_rect.IsEmpty()) { |
- if (is_horizontal_alignment()) { |
+ if (IsHorizontalAlignment()) { |
preferred_size.set_width(std::min( |
preferred_size.width(), |
static_cast<int>(monitor_rect.width() * |
@@ -183,7 +177,7 @@ void OverflowBubbleView::ChildPreferredSizeChanged(views::View* child) { |
} |
bool OverflowBubbleView::OnMouseWheel(const ui::MouseWheelEvent& event) { |
- if (is_horizontal_alignment()) |
+ if (IsHorizontalAlignment()) |
ScrollByXOffset(-event.offset()); |
else |
ScrollByYOffset(-event.offset()); |
@@ -257,7 +251,6 @@ OverflowBubble::~OverflowBubble() { |
void OverflowBubble::Show(LauncherDelegate* delegate, |
LauncherModel* model, |
views::View* anchor, |
- ShelfAlignment shelf_alignment, |
int overflow_start_index) { |
Hide(); |
@@ -265,7 +258,6 @@ void OverflowBubble::Show(LauncherDelegate* delegate, |
bubble_view->InitOverflowBubble(delegate, |
model, |
anchor, |
- shelf_alignment, |
overflow_start_index); |
bubble_ = bubble_view; |