Commit 5fa8d94b authored by bruthig's avatar bruthig Committed by Commit bot

[ash-md] Updated the overflow shelf to change colors based on the wallpaper.

The overflow shelf was incorrectly hard coded to use a black background. This
change updates the overflow shelf color based on the wallpaper color.

BUG=719724
TEST=ash_unittest --gtest_filter=ShelfViewTest.OverflowShelfColorIsDerivedFromWallpaper

Review-Url: https://codereview.chromium.org/2867413002
Cr-Commit-Position: refs/heads/master@{#470703}
parent f4f904ed
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "ash/root_window_controller.h" #include "ash/root_window_controller.h"
#include "ash/shelf/shelf_constants.h" #include "ash/shelf/shelf_constants.h"
#include "ash/shelf/wm_shelf.h" #include "ash/shelf/wm_shelf.h"
#include "ash/shell.h"
#include "ash/wm_window.h" #include "ash/wm_window.h"
#include "base/i18n/rtl.h" #include "base/i18n/rtl.h"
#include "ui/display/display.h" #include "ui/display/display.h"
...@@ -29,17 +30,24 @@ const int kEndPadding = 16; ...@@ -29,17 +30,24 @@ const int kEndPadding = 16;
// Distance between overflow bubble and the main shelf. // Distance between overflow bubble and the main shelf.
const int kDistanceToMainShelf = 4; const int kDistanceToMainShelf = 4;
constexpr SkColor kBackgroundColor =
SkColorSetA(kShelfDefaultBaseColor, kShelfTranslucentAlpha);
} // namespace } // namespace
OverflowBubbleView::OverflowBubbleView(WmShelf* wm_shelf) OverflowBubbleView::OverflowBubbleView(WmShelf* wm_shelf)
: wm_shelf_(wm_shelf), shelf_view_(nullptr) { : wm_shelf_(wm_shelf),
shelf_view_(nullptr),
background_animator_(SHELF_BACKGROUND_OVERLAP,
// Don't pass the WmShelf so the translucent color is
// always used.
nullptr,
Shell::Get()->wallpaper_controller()) {
DCHECK(wm_shelf_); DCHECK(wm_shelf_);
background_animator_.AddObserver(this);
} }
OverflowBubbleView::~OverflowBubbleView() {} OverflowBubbleView::~OverflowBubbleView() {
background_animator_.RemoveObserver(this);
}
void OverflowBubbleView::InitOverflowBubble(views::View* anchor, void OverflowBubbleView::InitOverflowBubble(views::View* anchor,
views::View* shelf_view) { views::View* shelf_view) {
...@@ -48,7 +56,6 @@ void OverflowBubbleView::InitOverflowBubble(views::View* anchor, ...@@ -48,7 +56,6 @@ void OverflowBubbleView::InitOverflowBubble(views::View* anchor,
SetAnchorView(anchor); SetAnchorView(anchor);
set_arrow(views::BubbleBorder::NONE); set_arrow(views::BubbleBorder::NONE);
set_background(nullptr); set_background(nullptr);
set_color(kBackgroundColor);
if (wm_shelf_->IsHorizontalAlignment()) if (wm_shelf_->IsHorizontalAlignment())
set_margins(gfx::Insets(0, kEndPadding)); set_margins(gfx::Insets(0, kEndPadding));
else else
...@@ -197,4 +204,8 @@ gfx::Rect OverflowBubbleView::GetBubbleBounds() { ...@@ -197,4 +204,8 @@ gfx::Rect OverflowBubbleView::GetBubbleBounds() {
return bounds; return bounds;
} }
void OverflowBubbleView::UpdateShelfBackground(SkColor color) {
set_color(color);
}
} // namespace ash } // namespace ash
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
#define ASH_SHELF_OVERFLOW_BUBBLE_VIEW_H_ #define ASH_SHELF_OVERFLOW_BUBBLE_VIEW_H_
#include "ash/ash_export.h" #include "ash/ash_export.h"
#include "ash/shelf/shelf_background_animator.h"
#include "ash/shelf/shelf_background_animator_observer.h"
#include "base/macros.h" #include "base/macros.h"
#include "ui/views/bubble/bubble_dialog_delegate.h" #include "ui/views/bubble/bubble_dialog_delegate.h"
...@@ -22,7 +24,8 @@ class OverflowBubbleViewTestAPI; ...@@ -22,7 +24,8 @@ class OverflowBubbleViewTestAPI;
// OverflowBubbleView hosts a ShelfView to display overflown items. // OverflowBubbleView hosts a ShelfView to display overflown items.
// Exports to access this class from OverflowBubbleViewTestAPI. // Exports to access this class from OverflowBubbleViewTestAPI.
class ASH_EXPORT OverflowBubbleView : public views::BubbleDialogDelegateView { class ASH_EXPORT OverflowBubbleView : public views::BubbleDialogDelegateView,
public ShelfBackgroundAnimatorObserver {
public: public:
explicit OverflowBubbleView(WmShelf* wm_shelf); explicit OverflowBubbleView(WmShelf* wm_shelf);
~OverflowBubbleView() override; ~OverflowBubbleView() override;
...@@ -52,10 +55,15 @@ class ASH_EXPORT OverflowBubbleView : public views::BubbleDialogDelegateView { ...@@ -52,10 +55,15 @@ class ASH_EXPORT OverflowBubbleView : public views::BubbleDialogDelegateView {
// ui::EventHandler overrides: // ui::EventHandler overrides:
void OnScrollEvent(ui::ScrollEvent* event) override; void OnScrollEvent(ui::ScrollEvent* event) override;
// ShelfBackgroundAnimatorObserver:
void UpdateShelfBackground(SkColor color) override;
WmShelf* wm_shelf_; WmShelf* wm_shelf_;
views::View* shelf_view_; // Owned by views hierarchy. views::View* shelf_view_; // Owned by views hierarchy.
gfx::Vector2d scroll_offset_; gfx::Vector2d scroll_offset_;
ShelfBackgroundAnimator background_animator_;
DISALLOW_COPY_AND_ASSIGN(OverflowBubbleView); DISALLOW_COPY_AND_ASSIGN(OverflowBubbleView);
}; };
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include "ash/animation/animation_change_type.h" #include "ash/animation/animation_change_type.h"
#include "ash/shelf/shelf_background_animator_observer.h" #include "ash/shelf/shelf_background_animator_observer.h"
#include "ash/shelf/shelf_constants.h" #include "ash/shelf/shelf_constants.h"
#include "ash/wallpaper/wallpaper_controller.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/test/test_mock_time_task_runner.h" #include "base/test/test_mock_time_task_runner.h"
......
...@@ -35,6 +35,8 @@ ...@@ -35,6 +35,8 @@
#include "ash/test/shell_test_api.h" #include "ash/test/shell_test_api.h"
#include "ash/test/test_shell_delegate.h" #include "ash/test/test_shell_delegate.h"
#include "ash/test/test_system_tray_delegate.h" #include "ash/test/test_system_tray_delegate.h"
#include "ash/test/wallpaper_controller_test_api.h"
#include "ash/wallpaper/wallpaper_controller.h"
#include "ash/wm_window.h" #include "ash/wm_window.h"
#include "base/i18n/rtl.h" #include "base/i18n/rtl.h"
#include "base/macros.h" #include "base/macros.h"
...@@ -1574,6 +1576,19 @@ TEST_F(ShelfViewTest, OverflowBubbleSize) { ...@@ -1574,6 +1576,19 @@ TEST_F(ShelfViewTest, OverflowBubbleSize) {
test_for_overflow_view.GetPreferredSize().width()); test_for_overflow_view.GetPreferredSize().width());
} }
TEST_F(ShelfViewTest, OverflowShelfColorIsDerivedFromWallpaper) {
test::WallpaperControllerTestApi wallpaper_test_api(
Shell::Get()->wallpaper_controller());
const SkColor opaque_expected_color =
wallpaper_test_api.ApplyColorProducingWallpaper();
AddButtonsUntilOverflow();
test_api_->ShowOverflowBubble();
OverflowBubbleView* bubble_view = test_api_->overflow_bubble()->bubble_view();
EXPECT_EQ(opaque_expected_color, SkColorSetA(bubble_view->color(), 255));
}
// Check the drag insertion bounds of scrolled overflow bubble. // Check the drag insertion bounds of scrolled overflow bubble.
TEST_F(ShelfViewTest, CheckDragInsertBoundsOfScrolledOverflowBubble) { TEST_F(ShelfViewTest, CheckDragInsertBoundsOfScrolledOverflowBubble) {
UpdateDisplay("400x300"); UpdateDisplay("400x300");
......
...@@ -84,9 +84,7 @@ ShelfWidget::DelegateView::DelegateView(ShelfWidget* shelf_widget) ...@@ -84,9 +84,7 @@ ShelfWidget::DelegateView::DelegateView(ShelfWidget* shelf_widget)
DCHECK(shelf_widget_); DCHECK(shelf_widget_);
SetLayoutManager(new views::FillLayout()); SetLayoutManager(new views::FillLayout());
set_allow_deactivate_on_esc(true); set_allow_deactivate_on_esc(true);
opaque_background_.SetColor(SK_ColorBLACK);
opaque_background_.SetBounds(GetLocalBounds()); opaque_background_.SetBounds(GetLocalBounds());
opaque_foreground_.SetColor(SK_ColorBLACK);
opaque_foreground_.SetBounds(GetLocalBounds()); opaque_foreground_.SetBounds(GetLocalBounds());
opaque_foreground_.SetOpacity(0.0f); opaque_foreground_.SetOpacity(0.0f);
} }
......
...@@ -125,6 +125,8 @@ static_library("test_support_common") { ...@@ -125,6 +125,8 @@ static_library("test_support_common") {
"ui_controls_factory_ash.h", "ui_controls_factory_ash.h",
"user_metrics_recorder_test_api.cc", "user_metrics_recorder_test_api.cc",
"user_metrics_recorder_test_api.h", "user_metrics_recorder_test_api.h",
"wallpaper_controller_test_api.cc",
"wallpaper_controller_test_api.h",
"wm_window_test_api.cc", "wm_window_test_api.cc",
"wm_window_test_api.h", "wm_window_test_api.h",
"workspace_event_handler_test_helper.cc", "workspace_event_handler_test_helper.cc",
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/test/wallpaper_controller_test_api.h"
#include "ash/wallpaper/wallpaper_controller.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/image/image_skia.h"
namespace ash {
namespace test {
WallpaperControllerTestApi::WallpaperControllerTestApi(
WallpaperController* controller)
: controller_(controller) {}
WallpaperControllerTestApi::~WallpaperControllerTestApi() {}
SkColor WallpaperControllerTestApi::ApplyColorProducingWallpaper() {
const SkColor color = SkColorSetRGB(60, 40, 40);
const SkColor expected_color = SkColorSetRGB(30, 20, 20);
gfx::Canvas canvas(gfx::Size(5, 5), 1.0f, true);
canvas.DrawColor(color);
gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(canvas.GetBitmap());
controller_->SetWallpaperImage(image, wallpaper::WALLPAPER_LAYOUT_CENTER);
return expected_color;
}
} // namespace test
} // namespace ash
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/ash_export.h"
#include "base/macros.h"
#include "third_party/skia/include/core/SkColor.h"
namespace ash {
class WallpaperController;
namespace test {
class ASH_EXPORT WallpaperControllerTestApi {
public:
explicit WallpaperControllerTestApi(WallpaperController* controller);
virtual ~WallpaperControllerTestApi();
// Creates and sets a new wallpaper that cause the prominent color of the
// |controller_| to be a valid (aka not kInvalidColor) color. The
// WallpaperControllerObservers should be notified as well. This is assumes
// the default DARK-MUTED luma-saturation ranges are in effect.
//
// The expected prominent color is returned.
SkColor ApplyColorProducingWallpaper();
private:
WallpaperController* controller_;
DISALLOW_COPY_AND_ASSIGN(WallpaperControllerTestApi);
};
} // namespace test
} // namespace ash
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