Commit 7ca3e696 authored by Manu Cornet's avatar Manu Cornet Committed by Commit Bot

CrOS sys tray: add a level of indirection for separator width

This allows us to set a different value for the width in the new UI.

This mechanism is similar to what is already in use in ShelfConstants.

Bug: 880586, 880589
Change-Id: Ice307799331e4765a3b6bc289d3442e23bf90c4c
Reviewed-on: https://chromium-review.googlesource.com/1205751Reviewed-by: default avatarYoshiki Iguchi <yoshiki@chromium.org>
Commit-Queue: Manu Cornet <manucornet@chromium.org>
Cr-Commit-Position: refs/heads/master@{#588833}
parent ab7b44b9
......@@ -81,7 +81,8 @@ void SystemInfoDefaultView::Layout() {
}
int SystemInfoDefaultView::CalculateDateViewWidth(int preferred_width) {
const float snap_to_width = kSeparatorWidth + kMenuButtonSize;
const float snap_to_width =
TrayConstants::separator_width() + kMenuButtonSize;
int num_extra_tile_widths = 0;
if (preferred_width > kMenuButtonSize) {
const float extra_width = preferred_width - kMenuButtonSize;
......
......@@ -28,21 +28,23 @@ TEST_F(SystemInfoDefaultViewTest, PreferredWidthSmallerThanButtonWidth) {
EXPECT_LT(kPreferredWidth, kMenuButtonSize);
const int effective_width = CalculateDateViewWidth(kPreferredWidth);
EXPECT_EQ(effective_width,
kMenuButtonSize + kSeparatorWidth + kMenuButtonSize);
EXPECT_EQ(
effective_width,
kMenuButtonSize + TrayConstants::separator_width() + kMenuButtonSize);
}
TEST_F(SystemInfoDefaultViewTest, PreferredWidthGreaterThanOneButtonWidth) {
const int kPreferredWidth = kMenuButtonSize + 1;
const int effective_width = CalculateDateViewWidth(kPreferredWidth);
EXPECT_EQ(effective_width,
kMenuButtonSize + kSeparatorWidth + kMenuButtonSize);
EXPECT_EQ(
effective_width,
kMenuButtonSize + TrayConstants::separator_width() + kMenuButtonSize);
}
TEST_F(SystemInfoDefaultViewTest, PreferredWidthEqualToTwoButtonWidths) {
const int kPreferredWidth =
kMenuButtonSize + kSeparatorWidth + kMenuButtonSize;
kMenuButtonSize + TrayConstants::separator_width() + kMenuButtonSize;
const int effective_width = CalculateDateViewWidth(kPreferredWidth);
EXPECT_EQ(effective_width, kPreferredWidth);
......@@ -50,16 +52,19 @@ TEST_F(SystemInfoDefaultViewTest, PreferredWidthEqualToTwoButtonWidths) {
TEST_F(SystemInfoDefaultViewTest, PreferredWidthGreaterThanTwoButtonWidths) {
const int kPreferredWidth =
kMenuButtonSize + (kSeparatorWidth + kMenuButtonSize) + 1;
kMenuButtonSize + (TrayConstants::separator_width() + kMenuButtonSize) +
1;
const int effective_width = CalculateDateViewWidth(kPreferredWidth);
EXPECT_EQ(effective_width,
kMenuButtonSize + (kSeparatorWidth + kMenuButtonSize) * 2);
kMenuButtonSize +
(TrayConstants::separator_width() + kMenuButtonSize) * 2);
}
TEST_F(SystemInfoDefaultViewTest, PreferredWidthEqualToThreeButtonWidths) {
const int kPreferredWidth =
kMenuButtonSize + (kSeparatorWidth + kMenuButtonSize) * 2;
kMenuButtonSize +
(TrayConstants::separator_width() + kMenuButtonSize) * 2;
const int effective_width = CalculateDateViewWidth(kPreferredWidth);
EXPECT_EQ(effective_width, kPreferredWidth);
......@@ -67,11 +72,13 @@ TEST_F(SystemInfoDefaultViewTest, PreferredWidthEqualToThreeButtonWidths) {
TEST_F(SystemInfoDefaultViewTest, PreferredWidthGreaterThanThreeButtonWidths) {
const int kPreferredWidth =
kMenuButtonSize + (kSeparatorWidth + kMenuButtonSize) * 2 + 1;
kMenuButtonSize +
(TrayConstants::separator_width() + kMenuButtonSize) * 2 + 1;
const int effective_width = CalculateDateViewWidth(kPreferredWidth);
EXPECT_EQ(effective_width,
kMenuButtonSize + (kSeparatorWidth + kMenuButtonSize) * 2);
kMenuButtonSize +
(TrayConstants::separator_width() + kMenuButtonSize) * 2);
}
} // namespace ash
......@@ -126,10 +126,11 @@ SystemMenuButton* CreateImeMenuButton(views::ButtonListener* listener,
class ImeTitleView : public views::View, public views::ButtonListener {
public:
explicit ImeTitleView(bool show_settings_button) : settings_button_(nullptr) {
const int separator_width = TrayConstants::separator_width();
SetBorder(views::CreatePaddedBorder(
views::CreateSolidSidedBorder(0, 0, kSeparatorWidth, 0,
views::CreateSolidSidedBorder(0, 0, separator_width, 0,
kMenuSeparatorColor),
gfx::Insets(kMenuSeparatorVerticalPadding - kSeparatorWidth, 0)));
gfx::Insets(kMenuSeparatorVerticalPadding - separator_width, 0)));
auto box_layout =
std::make_unique<views::BoxLayout>(views::BoxLayout::kHorizontal);
box_layout->set_minimum_cross_axis_size(kTrayPopupItemMinHeight);
......@@ -221,12 +222,13 @@ class ImeButtonsView : public views::View, public views::ButtonListener {
void Init(bool show_emoji, bool show_handwriting, bool show_voice) {
auto box_layout =
std::make_unique<views::BoxLayout>(views::BoxLayout::kHorizontal);
const int separator_width = TrayConstants::separator_width();
box_layout->set_minimum_cross_axis_size(kTrayPopupItemMinHeight);
SetLayoutManager(std::move(box_layout));
SetBorder(views::CreatePaddedBorder(
views::CreateSolidSidedBorder(kSeparatorWidth, 0, 0, 0,
views::CreateSolidSidedBorder(separator_width, 0, 0, 0,
kMenuSeparatorColor),
gfx::Insets(kMenuSeparatorVerticalPadding - kSeparatorWidth,
gfx::Insets(kMenuSeparatorVerticalPadding - separator_width,
kMenuExtraMarginFromLeftEdge)));
const int right_border = 1;
......
......@@ -73,13 +73,14 @@ gfx::Insets GetMirroredBackgroundInsets(bool is_shelf_horizontal) {
chromeos::switches::ShouldUseShelfNewUi() ? 0 : ash::kHitRegionPadding;
const int secondary_padding =
chromeos::switches::ShouldUseShelfNewUi() ? -ash::kHitRegionPadding : 0;
const int separator_width = ash::TrayConstants::separator_width();
if (is_shelf_horizontal) {
insets.Set(secondary_padding, primary_padding, secondary_padding,
primary_padding + ash::kSeparatorWidth);
primary_padding + separator_width);
} else {
insets.Set(primary_padding, secondary_padding,
primary_padding + ash::kSeparatorWidth, secondary_padding);
primary_padding + separator_width, secondary_padding);
}
MirrorInsetsIfNecessary(&insets);
return insets;
......@@ -379,16 +380,17 @@ void TrayBackgroundView::PaintButtonContents(gfx::Canvas* canvas) {
const gfx::Rect local_bounds = GetLocalBounds();
const SkColor color = SkColorSetA(SK_ColorWHITE, 0x4D);
const int shelf_size = ShelfConstants::shelf_size();
const int separator_width = ash::TrayConstants::separator_width();
if (shelf_->IsHorizontalAlignment()) {
const gfx::PointF point(
base::i18n::IsRTL() ? 0 : (local_bounds.width() - kSeparatorWidth),
base::i18n::IsRTL() ? 0 : (local_bounds.width() - separator_width),
(shelf_size - kTrayItemSize) / 2);
const gfx::Vector2dF vector(0, kTrayItemSize);
canvas->Draw1pxLine(point, point + vector, color);
} else {
const gfx::PointF point((shelf_size - kTrayItemSize) / 2,
local_bounds.height() - kSeparatorWidth);
local_bounds.height() - separator_width);
const gfx::Vector2dF vector(kTrayItemSize, 0);
canvas->Draw1pxLine(point, point + vector, color);
}
......
......@@ -66,7 +66,6 @@ const int kMenuEdgeEffectivePadding =
kMenuExtraMarginFromLeftEdge + (kMenuButtonSize - kMenuIconSize) / 2;
const int kHitRegionPadding = 4;
const int kSeparatorWidth = 1;
const SkColor kMenuSeparatorColor = SkColorSetA(SK_ColorBLACK, 0x1F);
......
......@@ -6,6 +6,8 @@
#define ASH_SYSTEM_TRAY_TRAY_CONSTANTS_H_
#include "ash/ash_export.h"
#include "base/macros.h"
#include "chromeos/chromeos_switches.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/geometry/size.h"
......@@ -84,7 +86,8 @@ extern const SkColor kMobileNotConnectedXIconColor;
extern const int kHitRegionPadding;
// Width of a line used to separate tray items in the shelf.
ASH_EXPORT extern const int kSeparatorWidth;
ASH_EXPORT const int kSeparatorWidth = 1;
const int kSeparatorWidthNewUi = 0;
// The color of the separators used in the system menu.
extern const SkColor kMenuSeparatorColor;
......@@ -226,6 +229,22 @@ constexpr int kUnifiedTopShortcutButtonMinSpacing = 4;
constexpr gfx::Insets kUnifiedDetailedViewTitlePadding(0, 0, 0, 16);
constexpr int kUnifiedDetailedViewTitleRowHeight = 64;
class TrayConstants {
public:
// Returns the width of a line used to separate tray items in the shelf.
static int separator_width() {
return UseNewUi() ? kSeparatorWidthNewUi : kSeparatorWidth;
}
private:
static bool UseNewUi() {
static bool use_new_ui = chromeos::switches::ShouldUseShelfNewUi();
return use_new_ui;
}
DISALLOW_IMPLICIT_CONSTRUCTORS(TrayConstants);
};
} // namespace ash
#endif // ASH_SYSTEM_TRAY_TRAY_CONSTANTS_H_
......@@ -68,7 +68,8 @@ void TrayContainer::UpdateLayout() {
is_horizontal ? views::BoxLayout::kHorizontal
: views::BoxLayout::kVertical;
const int hit_region_with_separator = kHitRegionPadding + kSeparatorWidth;
const int hit_region_with_separator =
kHitRegionPadding + TrayConstants::separator_width();
gfx::Insets insets(
is_horizontal
? gfx::Insets(0, kHitRegionPadding, 0, hit_region_with_separator)
......
......@@ -112,8 +112,9 @@ class ScrollContentsView : public views::View {
// that's below the header view so we don't get both a separator and a full
// shadow.
if (y() != 0 && !did_draw_shadow)
DrawShadow(paint_info.context(),
gfx::Rect(0, 0, width(), -y() - kSeparatorWidth));
DrawShadow(
paint_info.context(),
gfx::Rect(0, 0, width(), -y() - TrayConstants::separator_width()));
}
void Layout() override {
......
......@@ -240,11 +240,12 @@ void TrayPopupUtils::ConfigureAsStickyHeader(views::View* view) {
void TrayPopupUtils::ShowStickyHeaderSeparator(views::View* view,
bool show_separator) {
if (show_separator) {
const int separator_width = ash::TrayConstants::separator_width();
view->SetBorder(views::CreatePaddedBorder(
views::CreateSolidSidedBorder(0, 0, kSeparatorWidth, 0,
views::CreateSolidSidedBorder(0, 0, separator_width, 0,
kMenuSeparatorColor),
gfx::Insets(kMenuSeparatorVerticalPadding, 0,
kMenuSeparatorVerticalPadding - kSeparatorWidth, 0)));
kMenuSeparatorVerticalPadding - separator_width, 0)));
} else {
view->SetBorder(views::CreateEmptyBorder(
gfx::Insets(kMenuSeparatorVerticalPadding, 0)));
......
......@@ -149,11 +149,12 @@ void UnifiedDetailedViewDelegate::ShowStickyHeaderSeparator(
views::View* view,
bool show_separator) {
if (show_separator) {
const int separator_width = ash::TrayConstants::separator_width();
view->SetBorder(views::CreatePaddedBorder(
views::CreateSolidSidedBorder(0, 0, kSeparatorWidth, 0,
views::CreateSolidSidedBorder(0, 0, separator_width, 0,
kUnifiedMenuSeparatorColor),
gfx::Insets(kMenuSeparatorVerticalPadding, 0,
kMenuSeparatorVerticalPadding - kSeparatorWidth, 0)));
kMenuSeparatorVerticalPadding - separator_width, 0)));
} else {
view->SetBorder(views::CreateEmptyBorder(
gfx::Insets(kMenuSeparatorVerticalPadding, 0)));
......
......@@ -299,10 +299,11 @@ class ActiveUserBorder : public views::Border {
// views::Border:
void Paint(const views::View& view, gfx::Canvas* canvas) override {
const int separator_width = TrayConstants::separator_width();
canvas->FillRect(
gfx::Rect(
0, view.height() - kMenuSeparatorVerticalPadding - kSeparatorWidth,
view.width(), kSeparatorWidth),
0, view.height() - kMenuSeparatorVerticalPadding - separator_width,
view.width(), separator_width),
kMenuSeparatorColor);
}
......@@ -449,13 +450,14 @@ void UserView::ToggleUserDropdownWidget(bool toggled_by_key_event) {
Shell::Get()->session_controller();
const AddUserSessionPolicy add_user_policy =
session_controller->GetAddUserPolicy();
const int separator_width = TrayConstants::separator_width();
add_user_enabled_ = add_user_policy == AddUserSessionPolicy::ALLOWED;
// Position the widget on top of the user card view (which is still in the
// system menu). The top half of the widget will be transparent to allow
// the active user to show through.
gfx::Rect bounds = user_card_container_->GetBoundsInScreen();
bounds.set_width(bounds.width() + kSeparatorWidth);
bounds.set_width(bounds.width() + separator_width);
int row_height = bounds.height();
UserDropdownWidgetContents* container =
......@@ -464,18 +466,18 @@ void UserView::ToggleUserDropdownWidget(bool toggled_by_key_event) {
views::View* add_user_view = CreateAddUserView(add_user_policy);
const SkColor bg_color = add_user_view->background()->get_color();
container->SetBorder(views::CreatePaddedBorder(
views::CreateSolidSidedBorder(0, 0, 0, kSeparatorWidth, bg_color),
views::CreateSolidSidedBorder(0, 0, 0, separator_width, bg_color),
gfx::Insets(row_height, 0, 0, 0)));
// Create the contents aside from the empty window through which the active
// user is seen.
views::View* user_dropdown_padding = new views::View();
user_dropdown_padding->SetBorder(views::CreateSolidSidedBorder(
kMenuSeparatorVerticalPadding - kSeparatorWidth, 0, 0, 0, bg_color));
kMenuSeparatorVerticalPadding - separator_width, 0, 0, 0, bg_color));
user_dropdown_padding->SetLayoutManager(
std::make_unique<views::BoxLayout>(views::BoxLayout::kVertical));
views::Separator* separator = new views::Separator();
separator->SetPreferredHeight(kSeparatorWidth);
separator->SetPreferredHeight(separator_width);
separator->SetColor(
color_utils::GetResultingPaintColor(kMenuSeparatorColor, bg_color));
const int separator_horizontal_padding =
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment