Commit e6f134ab authored by Kevin Strohbehn's avatar Kevin Strohbehn Committed by Commit Bot

Reland "Makes wallpaper dim in tablet mode, without relying on app_list_shield"

This is a reland of 0b107635

Includes changes to fix MSAN issues

Bug: 898712, 899158

Original change's description:
> Makes wallpaper dim in tablet mode, without relying on app_list_shield
>
> Bug: 898712
> Change-Id: I96ba08fec3f7df8547d753ff4d31366345be0ac8
> Reviewed-on: https://chromium-review.googlesource.com/c/1298507
> Reviewed-by: Weidong Guo <weidongg@chromium.org>
> Reviewed-by: Xiyuan Xia <xiyuan@chromium.org>
> Commit-Queue: Kevin Strohbehn <ginko@google.com>
> Cr-Commit-Position: refs/heads/master@{#602938}

Bug: 898712
Change-Id: Ief534b6dc58b5d36b3f96952141a51312c50a79f
Reviewed-on: https://chromium-review.googlesource.com/c/1303233
Commit-Queue: Kevin Strohbehn <ginko@google.com>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#603605}
parent b3b7012b
...@@ -1188,9 +1188,9 @@ TEST_F(AppListPresenterDelegateHomeLauncherTest, BackgroundOpacity) { ...@@ -1188,9 +1188,9 @@ TEST_F(AppListPresenterDelegateHomeLauncherTest, BackgroundOpacity) {
GetAppListView()->GetAppListBackgroundShieldForTest()->layer(); GetAppListView()->GetAppListBackgroundShieldForTest()->layer();
EXPECT_EQ(0.7f, background_layer->opacity()); EXPECT_EQ(0.7f, background_layer->opacity());
// Turn on tablet mode. The background sheild opacity should be 10%. // Turn on tablet mode. The background shield should be transparent.
EnableTabletMode(true); EnableTabletMode(true);
EXPECT_EQ(0.4f, background_layer->opacity()); EXPECT_EQ(0.f, background_layer->opacity());
} }
// Tests that the background blur is disabled for the app list. // Tests that the background blur is disabled for the app list.
......
...@@ -89,9 +89,6 @@ constexpr float kAppListAnimationDurationTestMs = 0; ...@@ -89,9 +89,6 @@ constexpr float kAppListAnimationDurationTestMs = 0;
constexpr float kAppListAnimationDurationMs = 200; constexpr float kAppListAnimationDurationMs = 200;
constexpr float kAppListAnimationDurationFromFullscreenMs = 250; constexpr float kAppListAnimationDurationFromFullscreenMs = 250;
// The app list opacity when the tablet mode is enabled.
constexpr float kAppListOpacityInTabletMode = 0.4;
// The background corner radius in peeking and fullscreen state. // The background corner radius in peeking and fullscreen state.
constexpr int kAppListBackgroundRadius = 28; constexpr int kAppListBackgroundRadius = 28;
...@@ -1120,8 +1117,7 @@ void AppListView::OnTabletModeChanged(bool started) { ...@@ -1120,8 +1117,7 @@ void AppListView::OnTabletModeChanged(bool started) {
parent_window->AddChild(window); parent_window->AddChild(window);
// Update background opacity. // Update background opacity.
app_list_background_shield_->layer()->SetOpacity( app_list_background_shield_->layer()->SetOpacity(0.f);
kAppListOpacityInTabletMode);
// Update background blur. // Update background blur.
if (is_background_blur_enabled_) if (is_background_blur_enabled_)
......
...@@ -31,6 +31,10 @@ ...@@ -31,6 +31,10 @@
namespace ash { namespace ash {
namespace { namespace {
// The value used for alpha to apply a dark filter to the wallpaper in tablet
// mode. A higher number up to 255 results in a darker wallpaper.
constexpr int kWallpaperDimnessInTabletMode = 102;
// A view that controls the child view's layer so that the layer always has the // A view that controls the child view's layer so that the layer always has the
// same size as the display's original, un-scaled size in DIP. The layer is then // same size as the display's original, un-scaled size in DIP. The layer is then
// transformed to fit to the virtual screen size when laid-out. This is to avoid // transformed to fit to the virtual screen size when laid-out. This is to avoid
...@@ -85,6 +89,10 @@ SkColor GetWallpaperDarkenColor() { ...@@ -85,6 +89,10 @@ SkColor GetWallpaperDarkenColor() {
return SkColorSetA(darken_color, login_constants::kTranslucentAlpha); return SkColorSetA(darken_color, login_constants::kTranslucentAlpha);
} }
SkColor GetWallpaperDarkenColorForTabletMode() {
return SkColorSetA(GetWallpaperDarkenColor(), kWallpaperDimnessInTabletMode);
}
} // namespace } // namespace
// This event handler receives events in the pre-target phase and takes care of // This event handler receives events in the pre-target phase and takes care of
...@@ -131,12 +139,30 @@ WallpaperView::WallpaperView() ...@@ -131,12 +139,30 @@ WallpaperView::WallpaperView()
: pre_dispatch_handler_(new PreEventDispatchHandler()) { : pre_dispatch_handler_(new PreEventDispatchHandler()) {
set_context_menu_controller(this); set_context_menu_controller(this);
AddPreTargetHandler(pre_dispatch_handler_.get()); AddPreTargetHandler(pre_dispatch_handler_.get());
tablet_mode_observer_.Add(Shell::Get()->tablet_mode_controller());
is_tablet_mode_ = Shell::Get()
->tablet_mode_controller()
->IsTabletModeWindowManagerEnabled();
} }
WallpaperView::~WallpaperView() { WallpaperView::~WallpaperView() {
RemovePreTargetHandler(pre_dispatch_handler_.get()); RemovePreTargetHandler(pre_dispatch_handler_.get());
} }
void WallpaperView::OnTabletModeStarted() {
is_tablet_mode_ = true;
SchedulePaint();
}
void WallpaperView::OnTabletModeEnded() {
is_tablet_mode_ = false;
SchedulePaint();
}
void WallpaperView::OnTabletControllerDestroyed() {
tablet_mode_observer_.RemoveAll();
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// WallpaperView, views::View overrides: // WallpaperView, views::View overrides:
...@@ -160,6 +186,9 @@ void WallpaperView::OnPaint(gfx::Canvas* canvas) { ...@@ -160,6 +186,9 @@ void WallpaperView::OnPaint(gfx::Canvas* canvas) {
if (controller->ShouldApplyDimming()) { if (controller->ShouldApplyDimming()) {
flags.setColorFilter(SkColorFilter::MakeModeFilter( flags.setColorFilter(SkColorFilter::MakeModeFilter(
GetWallpaperDarkenColor(), SkBlendMode::kDarken)); GetWallpaperDarkenColor(), SkBlendMode::kDarken));
} else if (is_tablet_mode_) {
flags.setColorFilter(SkColorFilter::MakeModeFilter(
GetWallpaperDarkenColorForTabletMode(), SkBlendMode::kDarken));
} }
switch (layout) { switch (layout) {
......
...@@ -7,6 +7,9 @@ ...@@ -7,6 +7,9 @@
#include <memory> #include <memory>
#include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "ash/wm/tablet_mode/tablet_mode_observer.h"
#include "base/scoped_observer.h"
#include "ui/views/context_menu_controller.h" #include "ui/views/context_menu_controller.h"
#include "ui/views/view.h" #include "ui/views/view.h"
...@@ -18,7 +21,9 @@ namespace ash { ...@@ -18,7 +21,9 @@ namespace ash {
class PreEventDispatchHandler; class PreEventDispatchHandler;
class WallpaperView : public views::View, public views::ContextMenuController { class WallpaperView : public views::View,
public views::ContextMenuController,
TabletModeObserver {
public: public:
WallpaperView(); WallpaperView();
~WallpaperView() override; ~WallpaperView() override;
...@@ -30,10 +35,20 @@ class WallpaperView : public views::View, public views::ContextMenuController { ...@@ -30,10 +35,20 @@ class WallpaperView : public views::View, public views::ContextMenuController {
void OnPaint(gfx::Canvas* canvas) override; void OnPaint(gfx::Canvas* canvas) override;
bool OnMousePressed(const ui::MouseEvent& event) override; bool OnMousePressed(const ui::MouseEvent& event) override;
// Overridden from TabletModeObserver:
void OnTabletModeStarted() override;
void OnTabletModeEnded() override;
void OnTabletControllerDestroyed() override;
// Overridden from views::ContextMenuController: // Overridden from views::ContextMenuController:
void ShowContextMenuForView(views::View* source, void ShowContextMenuForView(views::View* source,
const gfx::Point& point, const gfx::Point& point,
ui::MenuSourceType source_type) override; ui::MenuSourceType source_type) override;
ScopedObserver<TabletModeController, TabletModeObserver>
tablet_mode_observer_{this};
bool is_tablet_mode_ = false;
std::unique_ptr<PreEventDispatchHandler> pre_dispatch_handler_; std::unique_ptr<PreEventDispatchHandler> pre_dispatch_handler_;
DISALLOW_COPY_AND_ASSIGN(WallpaperView); DISALLOW_COPY_AND_ASSIGN(WallpaperView);
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "ash/wm/overview/window_selector_delegate.h" #include "ash/wm/overview/window_selector_delegate.h"
#include "ash/wm/overview/window_selector_item.h" #include "ash/wm/overview/window_selector_item.h"
#include "ash/wm/splitview/split_view_drag_indicators.h" #include "ash/wm/splitview/split_view_drag_indicators.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "ash/wm/tablet_mode/tablet_mode_window_state.h" #include "ash/wm/tablet_mode/tablet_mode_window_state.h"
#include "ash/wm/window_state.h" #include "ash/wm/window_state.h"
#include "ash/wm/window_util.h" #include "ash/wm/window_util.h"
...@@ -206,7 +207,12 @@ class WindowGrid::ShieldView : public views::View { ...@@ -206,7 +207,12 @@ class WindowGrid::ShieldView : public views::View {
background_view_ = new views::View(); background_view_ = new views::View();
background_view_->SetPaintToLayer(ui::LAYER_SOLID_COLOR); background_view_->SetPaintToLayer(ui::LAYER_SOLID_COLOR);
background_view_->layer()->SetColor(kShieldBaseColor); background_view_->layer()->SetColor(kShieldBaseColor);
background_view_->layer()->SetOpacity(kShieldOpacity); background_view_->layer()->SetOpacity(
!Shell::Get()
->tablet_mode_controller()
->IsTabletModeWindowManagerEnabled()
? kShieldOpacity
: 0.f);
label_ = new views::Label( label_ = new views::Label(
l10n_util::GetStringUTF16(IDS_ASH_OVERVIEW_NO_RECENT_ITEMS), l10n_util::GetStringUTF16(IDS_ASH_OVERVIEW_NO_RECENT_ITEMS),
......
...@@ -58,9 +58,9 @@ class ASH_EXPORT WindowGrid : public aura::WindowObserver, ...@@ -58,9 +58,9 @@ class ASH_EXPORT WindowGrid : public aura::WindowObserver,
const gfx::Rect& bounds_in_screen); const gfx::Rect& bounds_in_screen);
~WindowGrid() override; ~WindowGrid() override;
// The opacity of the shield widget that is used to darden the background of // The opacity of the shield widget that is used to darken the background of
// the grid. // the grid.
static constexpr float kShieldOpacity = 0.6f; static constexpr float kShieldOpacity = 0.4f;
// Returns the shield color that is used to darken the background of the grid. // Returns the shield color that is used to darken the background of the grid.
static SkColor GetShieldColor(); static SkColor GetShieldColor();
......
...@@ -166,6 +166,9 @@ TabletModeController::~TabletModeController() { ...@@ -166,6 +166,9 @@ TabletModeController::~TabletModeController() {
chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver( chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(
this); this);
for (auto& observer : tablet_mode_observers_)
observer.OnTabletControllerDestroyed();
TabletMode::SetCallback(TabletMode::TabletModeCallback()); TabletMode::SetCallback(TabletMode::TabletModeCallback());
} }
......
...@@ -29,8 +29,12 @@ class ASH_EXPORT TabletModeObserver { ...@@ -29,8 +29,12 @@ class ASH_EXPORT TabletModeObserver {
// connected. // connected.
virtual void OnTabletModeEventsBlockingChanged() {} virtual void OnTabletModeEventsBlockingChanged() {}
// Called when the tablet mode controller is destroyed, to help manage issues
// with observers being destroyed after controllers.
virtual void OnTabletControllerDestroyed() {}
protected: protected:
virtual ~TabletModeObserver() {} virtual ~TabletModeObserver() = default;
}; };
} // namespace ash } // 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