Skip to content

Commit

Permalink
Fixed alignment issue in tray in guest mode.
Browse files Browse the repository at this point in the history
In guest mode, the avatar in the system tray is replaced by a label. The label has a variable size vs the fixed height of avatar images. This causes the tray container to shrink resulting in alignment issues.

I've modified the border around the label so that the height of a |TrayUser| will be consistent. I've also add a unit test to enforce this.

BUG=340673
TEST=Current unit tests pass. New unit test passes. Verify bug 340673.

Review URL: https://codereview.chromium.org/189193003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@256726 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
abodenha@chromium.org committed Mar 13, 2014
1 parent c906084 commit cd75c9e
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 2 deletions.
3 changes: 3 additions & 0 deletions ash/system/tray/tray_constants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ const int kTrayImageItemHorizontalPaddingBottomAlignment = 1;
const int kTrayImageItemHorizontalPaddingVerticalAlignment = 1;
const int kTrayImageItemVerticalPaddingVerticalAlignment = 1;

// Size of tray items on the primary axis.
const int kTrayItemSize = 32;

const int kTrayLabelItemHorizontalPaddingBottomAlignment = 7;

// Vertical padding between status tray items when the shelf is vertical.
Expand Down
4 changes: 4 additions & 0 deletions ash/system/tray/tray_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#ifndef ASH_SYSTEM_TRAY_TRAY_CONSTANTS_H_
#define ASH_SYSTEM_TRAY_TRAY_CONSTANTS_H_

#include "ash/ash_export.h"

typedef unsigned int SkColor;

namespace ash {
Expand All @@ -27,6 +29,8 @@ extern const int kTrayImageItemHorizontalPaddingBottomAlignment;
extern const int kTrayImageItemHorizontalPaddingVerticalAlignment;
extern const int kTrayImageItemVerticalPaddingVerticalAlignment;

ASH_EXPORT extern const int kTrayItemSize;

extern const int kTrayLabelItemHorizontalPaddingBottomAlignment;
extern const int kTrayLabelItemVerticalPaddingVerticalAlignment;

Expand Down
22 changes: 20 additions & 2 deletions ash/system/user/tray_user.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1112,11 +1112,23 @@ TrayUser::TestState TrayUser::GetStateForTest() const {
return user_->GetStateForTest();
}

gfx::Size TrayUser::GetLayoutSizeForTest() const {
if (!layout_view_) {
return gfx::Size(0, 0);
} else {
return layout_view_->size();
}
}

gfx::Rect TrayUser::GetUserPanelBoundsInScreenForTest() const {
DCHECK(user_);
return user_->GetBoundsInScreenOfUserButtonForTest();
}

void TrayUser::UpdateAfterLoginStatusChangeForTest(user::LoginStatus status) {
UpdateAfterLoginStatusChange(status);
}

views::View* TrayUser::CreateTrayView(user::LoginStatus status) {
CHECK(layout_view_ == NULL);

Expand Down Expand Up @@ -1252,10 +1264,16 @@ void TrayUser::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) {
}
}
if (label_) {
// If label_ hasn't figured out its size yet, do that first.
if (label_->GetContentsBounds().height() == 0)
label_->SizeToPreferredSize();
int height = label_->GetContentsBounds().height();
int vertical_pad = (kTrayItemSize - height) / 2;
int remainder = height % 2;
label_->SetBorder(views::Border::CreateEmptyBorder(
0,
vertical_pad + remainder,
kTrayLabelItemHorizontalPaddingBottomAlignment,
0,
vertical_pad,
kTrayLabelItemHorizontalPaddingBottomAlignment));
}
layout_view_->SetLayoutManager(
Expand Down
8 changes: 8 additions & 0 deletions ash/system/user/tray_user.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace gfx {
class Rect;
class Size;
}

namespace views {
Expand Down Expand Up @@ -48,10 +49,17 @@ class ASH_EXPORT TrayUser : public SystemTrayItem,
};
TestState GetStateForTest() const;

// Returns the size of layout_view_.
gfx::Size GetLayoutSizeForTest() const;

// Returns the bounds of the user panel in screen coordinates.
// Note: This only works when the panel shown.
gfx::Rect GetUserPanelBoundsInScreenForTest() const;

// Update the TrayUser as if the current LoginStatus is |status|.
void UpdateAfterLoginStatusChangeForTest(user::LoginStatus status);


private:
// Overridden from SystemTrayItem.
virtual views::View* CreateTrayView(user::LoginStatus status) OVERRIDE;
Expand Down
12 changes: 12 additions & 0 deletions ash/system/user/tray_user_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "ash/shell.h"
#include "ash/shell_delegate.h"
#include "ash/system/tray/system_tray.h"
#include "ash/system/tray/tray_constants.h"
#include "ash/system/user/tray_user.h"
#include "ash/system/user/tray_user_separator.h"
#include "ash/test/ash_test_base.h"
Expand Down Expand Up @@ -129,6 +130,17 @@ void TrayUserTest::ClickUserItem(aura::test::EventGenerator* generator,
generator->ClickLeftButton();
}

// Make sure that we show items for all users in the tray accordingly.
TEST_F(TrayUserTest, CheckTrayItemSize) {
InitializeParameters(1, false);
tray_user(0)->UpdateAfterLoginStatusChangeForTest(user::LOGGED_IN_GUEST);
gfx::Size size = tray_user(0)->GetLayoutSizeForTest();
EXPECT_EQ(kTrayItemSize, size.height());
tray_user(0)->UpdateAfterLoginStatusChangeForTest(user::LOGGED_IN_USER);
size = tray_user(0)->GetLayoutSizeForTest();
EXPECT_EQ(kTrayItemSize, size.height());
}

// Make sure that in single user mode the user panel cannot be activated and no
// separators are being created.
TEST_F(TrayUserTest, SingleUserModeDoesNotAllowAddingUser) {
Expand Down

0 comments on commit cd75c9e

Please sign in to comment.