Index: ash/system/tray/tray_item_view.cc |
diff --git a/ash/system/tray/tray_item_view.cc b/ash/system/tray/tray_item_view.cc |
index f95ceb935708c20e5b509c1e88b2a47ea74a8f4f..b13309527c155226f0f44ea423fc9062bfeda26d 100644 |
--- a/ash/system/tray/tray_item_view.cc |
+++ b/ash/system/tray/tray_item_view.cc |
@@ -5,6 +5,7 @@ |
#include "ash/system/tray/tray_item_view.h" |
#include "ash/shelf/shelf_types.h" |
+#include "ash/shell.h" |
#include "ash/system/tray/system_tray.h" |
#include "ash/system/tray/system_tray_item.h" |
#include "ui/base/animation/slide_animation.h" |
@@ -29,14 +30,20 @@ namespace internal { |
TrayItemView::TrayItemView(SystemTrayItem* owner) |
: owner_(owner), |
label_(NULL), |
- image_view_(NULL) { |
+ image_view_(NULL), |
+ alignment_override_(AUTO) { |
SetPaintToLayer(true); |
SetFillsBoundsOpaquely(false); |
- SetLayoutManager( |
- new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); |
+ SetLayoutAlignment(); |
+ // Observe any shelf alignment changes to change view alignments. |
+ if (ash::Shell::HasInstance()) |
+ ash::Shell::GetInstance()->AddShellObserver(this); |
} |
-TrayItemView::~TrayItemView() {} |
+TrayItemView::~TrayItemView() { |
+ if (ash::Shell::HasInstance()) |
+ ash::Shell::GetInstance()->RemoveShellObserver(this); |
+} |
// static |
void TrayItemView::DisableAnimationsForTest() { |
@@ -53,6 +60,11 @@ void TrayItemView::CreateImageView() { |
AddChildView(image_view_); |
} |
+void TrayItemView::SetAlignmentOverride(AlignmentOverride alignment_override) { |
+ alignment_override_ = alignment_override; |
+ SetLayoutAlignment(); |
+} |
+ |
void TrayItemView::SetVisible(bool set_visible) { |
if (!GetWidget() || !animations_enabled) { |
views::View::SetVisible(set_visible); |
@@ -102,6 +114,11 @@ int TrayItemView::GetHeightForWidth(int width) { |
return GetPreferredSize().height(); |
} |
+void TrayItemView::OnShelfAlignmentChanged( |
+ aura::RootWindow* root_window) { |
+ SetLayoutAlignment(); |
+} |
+ |
void TrayItemView::ChildPreferredSizeChanged(views::View* child) { |
PreferredSizeChanged(); |
} |
@@ -125,5 +142,31 @@ void TrayItemView::AnimationCanceled(const ui::Animation* animation) { |
AnimationEnded(animation); |
} |
+void TrayItemView::SetLayoutAlignment() { |
+ views::BoxLayout::Orientation alignment = views::BoxLayout::kHorizontal; |
+ switch (alignment_override_) { |
+ case AUTO: |
+ switch (owner()->system_tray()->shelf_alignment()) { |
+ case ash::SHELF_ALIGNMENT_BOTTOM: |
+ case ash::SHELF_ALIGNMENT_TOP: |
+ alignment = views::BoxLayout::kHorizontal; |
+ break; |
+ case ash::SHELF_ALIGNMENT_LEFT: |
+ case ash::SHELF_ALIGNMENT_RIGHT: |
+ alignment = views::BoxLayout::kVertical; |
+ break; |
+ } |
+ break; |
+ case HORIZONTAL: |
+ alignment = views::BoxLayout::kHorizontal; |
+ break; |
+ case VERTICAL: |
+ alignment = views::BoxLayout::kVertical; |
+ break; |
+ } |
+ SetLayoutManager(new views::BoxLayout(alignment, 0, 0, 0)); |
+ Layout(); |
+} |
+ |
} // namespace internal |
} // namespace ash |