Commit 80db7d21 authored by Manu Cornet's avatar Manu Cornet Committed by Commit Bot

CrOS shelf: permanent background behind back + launcher buttons

Replace the logic in ShelfView's overridden OnPaint with a simpler
view and rounded corners.

You can see a screenshot in comment #17 of the linked bug.

Bug: 874161
Change-Id: I416e670ca578e6fd5d4e7681c8c19acf2fa17c3a
Reviewed-on: https://chromium-review.googlesource.com/1198525Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Reviewed-by: default avatarAlex Newcomer <newcomer@chromium.org>
Commit-Queue: Manu Cornet <manucornet@chromium.org>
Cr-Commit-Position: refs/heads/master@{#588220}
parent ab10871a
......@@ -70,7 +70,6 @@ AppListButton::AppListButton(InkDropButtonListener* listener,
Shell::Get()->AddShellObserver(this);
Shell::Get()->session_controller()->AddObserver(this);
const int shelf_size = ShelfConstants::shelf_size();
mojom::VoiceInteractionObserverPtr ptr;
voice_interaction_binding_.Bind(mojo::MakeRequest(&ptr));
Shell::Get()->voice_interaction_controller()->AddObserver(std::move(ptr));
......@@ -79,7 +78,7 @@ AppListButton::AppListButton(InkDropButtonListener* listener,
set_ink_drop_visible_opacity(kShelfInkDropVisibleOpacity);
SetAccessibleName(
l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_LAUNCHER_TITLE));
SetSize(gfx::Size(shelf_size, shelf_size));
SetSize(gfx::Size(kShelfControlSizeNewUi, kShelfControlSizeNewUi));
SetFocusPainter(TrayPopupUtils::CreateFocusPainter());
set_notify_action(Button::NOTIFY_ON_PRESS);
......
......@@ -33,9 +33,8 @@ BackButton::BackButton() : views::ImageButton(nullptr) {
set_ink_drop_base_color(kShelfInkDropBaseColor);
set_ink_drop_visible_opacity(kShelfInkDropVisibleOpacity);
const int shelf_size = ShelfConstants::shelf_size();
SetAccessibleName(l10n_util::GetStringUTF16(IDS_ASH_SHELF_BACK_BUTTON_TITLE));
SetSize(gfx::Size(shelf_size, shelf_size));
SetSize(gfx::Size(kShelfControlSizeNewUi, kShelfControlSizeNewUi));
SetFocusPainter(TrayPopupUtils::CreateFocusPainter());
}
......
......@@ -366,6 +366,18 @@ ShelfView::~ShelfView() {
void ShelfView::Init() {
model_->AddObserver(this);
// Add the background view behind the app list and back buttons first, so
// that other views will appear above it.
if (chromeos::switches::ShouldUseShelfNewUi()) {
back_and_app_list_background_ = new views::View();
back_and_app_list_background_->SetBackground(
CreateBackgroundFromPainter(views::Painter::CreateSolidRoundRectPainter(
kShelfControlPermanentHighlightBackground,
ShelfConstants::control_border_radius())));
ConfigureChildView(back_and_app_list_background_);
AddChildView(back_and_app_list_background_);
}
const ShelfItems& items(model_->items());
for (ShelfItems::const_iterator i = items.begin(); i != items.end(); ++i) {
views::View* child = CreateViewForItem(*i);
......@@ -1006,6 +1018,20 @@ void ShelfView::CalculateIdealBounds(gfx::Rect* overflow_bounds) const {
if (i == kAppListButtonIndex) {
app_list_button_position = shelf_->PrimaryAxisValue(x, y);
if (chromeos::switches::ShouldUseShelfNewUi()) {
// "Secondary" as in "orthogonal to the shelf primary axis".
const int control_secondary_padding =
(ShelfConstants::shelf_size() - kShelfControlSizeNewUi) / 2;
const int back_and_app_list_background_size =
kShelfControlSizeNewUi +
(IsTabletModeEnabled() ? kShelfControlSizeNewUi + 2 * button_spacing
: 0);
back_and_app_list_background_->SetBounds(
shelf_->PrimaryAxisValue(button_spacing, control_secondary_padding),
shelf_->PrimaryAxisValue(control_secondary_padding, button_spacing),
shelf_->PrimaryAxisValue(back_and_app_list_background_size,
kShelfControlSizeNewUi),
shelf_->PrimaryAxisValue(kShelfControlSizeNewUi,
back_and_app_list_background_size));
// In the new UI, a larger minimum padding after the app list button
// is required: increment with the necessary extra amount.
x += shelf_->PrimaryAxisValue(kAppListButtonMargin - button_spacing, 0);
......@@ -1740,41 +1766,6 @@ void ShelfView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
overflow_bubble_->Hide();
}
void ShelfView::OnPaint(gfx::Canvas* canvas) {
if (overflow_mode_)
return;
const int app_list_button_radius = ShelfConstants::app_list_button_radius();
cc::PaintFlags flags;
flags.setColor(shelf_item_background_color_);
flags.setAntiAlias(true);
flags.setStyle(cc::PaintFlags::kFill_Style);
// Draws a round rect around the back button and app list button. This will
// just be a circle if the back button is hidden.
const gfx::PointF circle_center(
GetMirroredRect(GetAppListButton()->bounds()).origin() +
gfx::Vector2d(GetAppListButton()->GetCenterPoint().x(),
GetAppListButton()->GetCenterPoint().y()));
if (GetBackButton()->layer()->opacity() <= 0.f) {
canvas->DrawCircle(circle_center, app_list_button_radius, flags);
return;
}
const int button_size = ShelfConstants::button_size();
const gfx::PointF back_center(
GetMirroredRect(GetBackButton()->bounds()).x() + button_size / 2,
GetBackButton()->bounds().y() + button_size / 2);
const gfx::RectF background_bounds(
std::min(back_center.x(), circle_center.x()) - app_list_button_radius,
back_center.y() - app_list_button_radius,
std::abs(circle_center.x() - back_center.x()) +
2 * app_list_button_radius,
2 * app_list_button_radius);
canvas->DrawRoundRect(background_bounds, app_list_button_radius, flags);
}
views::FocusTraversable* ShelfView::GetPaneFocusTraversable() {
return this;
}
......
......@@ -383,7 +383,6 @@ class ASH_EXPORT ShelfView : public views::View,
// Overridden from views::View:
gfx::Size CalculatePreferredSize() const override;
void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
void OnPaint(gfx::Canvas* canvas) override;
FocusTraversable* GetPaneFocusTraversable() override;
void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
void ViewHierarchyChanged(
......@@ -585,7 +584,11 @@ class ASH_EXPORT ShelfView : public views::View,
// A reference to the view used as a separator between pinned and unpinned
// items.
views::Separator* separator_;
views::Separator* separator_ = nullptr;
// A view to draw a background behind the app list and back buttons.
// Owned by the view hierarchy.
views::View* back_and_app_list_background_ = nullptr;
base::WeakPtrFactory<ShelfView> weak_factory_;
......
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