Commit e8131e80 authored by minch's avatar minch Committed by Commit Bot

dark_mode: Help keeping UI elements' current colors.

- Add DeprecatedGet*LayerColor functions in a separate file to help
  keeping UI elements' current colors before launching dark/light mode.

- Add ScopedLightModeAsDefeault to set the default color mode to light.
  This is done to support UI elements are light by default. E.g. Power
  button menu.

Bug: 1133952
Change-Id: I169f13991a649a1d1aacea451a6fb8ba8001396c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2440661
Commit-Queue: Min Chen <minch@chromium.org>
Reviewed-by: default avatarAhmed Fakhry <afakhry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#813003}
parent 0832bc62
......@@ -831,6 +831,11 @@ component("ash") {
"sticky_keys/sticky_keys_state.h",
"style/ash_color_provider.cc",
"style/ash_color_provider.h",
"style/default_color_constants.h",
"style/default_colors.cc",
"style/default_colors.h",
"style/scoped_light_mode_as_default.cc",
"style/scoped_light_mode_as_default.h",
"system/accessibility/accessibility_feature_disable_dialog.cc",
"system/accessibility/accessibility_feature_disable_dialog.h",
"system/accessibility/accessibility_feature_pod_controller.cc",
......
......@@ -299,6 +299,9 @@ void AshColorProvider::RemoveObserver(ColorModeObserver* observer) {
}
bool AshColorProvider::IsDarkModeEnabled() const {
if (override_light_mode_as_default_)
return false;
if (!active_user_pref_service_)
return kDefaultDarkModeEnabled;
return active_user_pref_service_->GetBoolean(prefs::kDarkModeEnabled);
......
......@@ -207,6 +207,8 @@ class ASH_EXPORT AshColorProvider : public SessionObserver {
SkColor GetLoginBackgroundBaseColor() const;
private:
friend class ScopedLightModeAsDefault;
// Gets the background default color.
SkColor GetBackgroundDefaultColor() const;
......@@ -222,6 +224,13 @@ class ASH_EXPORT AshColorProvider : public SessionObserver {
// Notifies all the observers on |kColorModeThemed|'s change.
void NotifyColorModeThemedPrefChange();
// Default color mode is dark, which is controlled by pref |kDarkModeEnabled|
// currently. But we can also override it to light through
// ScopedLightModeAsDefault. This is done to help keeping some of the UI
// elements as light by default before launching dark/light mode. This will be
// removed once enabling dark/light mode.
bool override_light_mode_as_default_ = false;
base::ObserverList<ColorModeObserver> observers_;
std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_;
PrefService* active_user_pref_service_ = nullptr; // Not owned.
......
// Copyright 2020 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.
#ifndef ASH_STYLE_DEFAULT_COLOR_CONSTANTS_H_
#define ASH_STYLE_DEFAULT_COLOR_CONSTANTS_H_
// Colors that can't be found in AshColorProvider. This is used to keep the UI
// element's current look before launching dark/light mode. Using this together
// with the Deprecated* functions inside default_colors.h file. Note: This file
// will be removed once enabled dark/light mode.
#endif // ASH_STYLE_DEFAULT_COLOR_CONSTANTS_H_
// Copyright 2020 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/style/default_colors.h"
#include "ash/public/cpp/ash_features.h"
namespace ash {
SkColor DeprecatedGetShieldLayerColor(AshColorProvider::ShieldLayerType type,
SkColor default_color) {
if (!features::IsDarkLightModeEnabled())
return default_color;
return AshColorProvider::Get()->GetShieldLayerColor(type);
}
SkColor DeprecatedGetBaseLayerColor(AshColorProvider::BaseLayerType type,
SkColor default_color) {
if (!features::IsDarkLightModeEnabled())
return default_color;
return AshColorProvider::Get()->GetBaseLayerColor(type);
}
SkColor DeprecatedGetControlsLayerColor(
AshColorProvider::ControlsLayerType type,
SkColor default_color) {
if (!features::IsDarkLightModeEnabled())
return default_color;
return AshColorProvider::Get()->GetControlsLayerColor(type);
}
SkColor DeprecatedGetContentLayerColor(AshColorProvider::ContentLayerType type,
SkColor default_color) {
if (!features::IsDarkLightModeEnabled())
return default_color;
return AshColorProvider::Get()->GetContentLayerColor(type);
}
} // namespace ash
// Copyright 2020 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.
#ifndef ASH_STYLE_DEFAULT_COLORS_H_
#define ASH_STYLE_DEFAULT_COLORS_H_
#include "ash/style/ash_color_provider.h"
#include "third_party/skia/include/core/SkColor.h"
namespace ash {
// APIs to help keeping the UI element's current color before launching
// dark/light mode. |default_color| will be returned if the dark mode feature is
// not enabled. Use these functions if the |default_color| can't be found in
// AshColorProvider. And move |default_color| to default_color_constants.h file
// to benefit future maintenance.
SkColor DeprecatedGetShieldLayerColor(AshColorProvider::ShieldLayerType type,
SkColor default_color);
SkColor DeprecatedGetBaseLayerColor(AshColorProvider::BaseLayerType type,
SkColor default_color);
SkColor DeprecatedGetControlsLayerColor(
AshColorProvider::ControlsLayerType type,
SkColor default_color);
SkColor DeprecatedGetContentLayerColor(AshColorProvider::ContentLayerType type,
SkColor default_color);
} // namespace ash
#endif // ASH_STYLE_DEFAULT_COLORS_H_
// Copyright 2020 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/style/scoped_light_mode_as_default.h"
#include "ash/style/ash_color_provider.h"
namespace ash {
ScopedLightModeAsDefault::ScopedLightModeAsDefault()
: previous_override_light_mode_as_default_(
AshColorProvider::Get()->override_light_mode_as_default_) {
AshColorProvider::Get()->override_light_mode_as_default_ = true;
}
ScopedLightModeAsDefault::~ScopedLightModeAsDefault() {
AshColorProvider::Get()->override_light_mode_as_default_ =
previous_override_light_mode_as_default_;
}
} // namespace ash
// Copyright 2020 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.
#ifndef ASH_STYLE_SCOPED_LIGHT_MODE_AS_DEFAULT_H_
#define ASH_STYLE_SCOPED_LIGHT_MODE_AS_DEFAULT_H_
namespace ash {
// A helper class to set default color mode to light. Color mode is dark by
// default, which is controlled by pref |kDarkModeEnabled| currently. Some of
// the components need to be kept as LIGHT by default before launching
// dark/light mode. E.g. power button menu and system toast.
class ScopedLightModeAsDefault {
public:
ScopedLightModeAsDefault();
ScopedLightModeAsDefault(const ScopedLightModeAsDefault&) = delete;
ScopedLightModeAsDefault& operator=(const ScopedLightModeAsDefault&) = delete;
~ScopedLightModeAsDefault();
private:
// Value of |override_light_mode_as_default_| inside AshColorProvider before
// setting.
bool previous_override_light_mode_as_default_;
};
} // namespace ash
#endif // ASH_STYLE_SCOPED_LIGHT_MODE_AS_DEFAULT_H_
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