Skip to content

Commit

Permalink
dark_mode: Add content layer concept in AshColorProvider.
Browse files Browse the repository at this point in the history
Add content layer and corresponding getters in AshColorProvider.
See info here
https://docs.google.com/spreadsheets/d/1ozIoqVHPafIe3HLVLCxY68S8OCnMCP6fw7qWRnMS2ss/edit?ts=5d0ac331#gid=0

See the colors for text and icon here:
https://spec.googleplex.com/crosux-spec/style/typography.html#typography-typescale-surfaces-colors

And use them to get the icon and text colors for system tray.
For icons, since their colors are the same as in AshColorProvider,
use GetContentLayerColor(*) directly.
For texts, their colors are different with colors of
ContentLayerType::kText*, use DeprecatedGetContentLayerColor to keep
the default colors.

Bug: 972162, 982950
Change-Id: I5d0565aba253a341de1bc060417082b000448801
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1752114
Commit-Queue: Min Chen <minch@chromium.org>
Reviewed-by: Xiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#687440}
  • Loading branch information
minch authored and Commit Bot committed Aug 15, 2019
1 parent 63eb580 commit bee2e31
Show file tree
Hide file tree
Showing 38 changed files with 398 additions and 191 deletions.
2 changes: 1 addition & 1 deletion ash/shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ Shell::Shell(std::unique_ptr<ShellDelegate> shell_delegate,
std::make_unique<KeyboardBrightnessController>()),
locale_update_controller_(std::make_unique<LocaleUpdateControllerImpl>()),
media_controller_(std::make_unique<MediaControllerImpl>(connector)),
ash_color_provider_(std::make_unique<AshColorProvider>()),
session_controller_(std::make_unique<SessionControllerImpl>()),
shell_delegate_(std::move(shell_delegate)),
shell_state_(std::make_unique<ShellState>()),
Expand Down Expand Up @@ -1145,7 +1146,6 @@ void Shell::Init(
split_view_controller_.reset(new SplitViewController());
snap_controller_ = std::make_unique<SnapControllerImpl>();
key_accessibility_enabler_ = std::make_unique<KeyAccessibilityEnabler>();
ash_color_provider_ = std::make_unique<AshColorProvider>();

// The compositor thread and main message loop have to be running in
// order to create mirror window. Run it after the main message loop
Expand Down
4 changes: 1 addition & 3 deletions ash/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,7 @@ class ASH_EXPORT Shell : public SessionObserver,
std::unique_ptr<MultiDeviceNotificationPresenter>
multidevice_notification_presenter_;
std::unique_ptr<ResizeShadowController> resize_shadow_controller_;
std::unique_ptr<AshColorProvider> ash_color_provider_;
std::unique_ptr<SessionControllerImpl> session_controller_;
std::unique_ptr<NightLightControllerImpl> night_light_controller_;
std::unique_ptr<PolicyRecommendationRestorer> policy_recommendation_restorer_;
Expand Down Expand Up @@ -795,9 +796,6 @@ class ASH_EXPORT Shell : public SessionObserver,
// volume keys.
std::unique_ptr<KeyAccessibilityEnabler> key_accessibility_enabler_;

// Color provider for ash.
std::unique_ptr<AshColorProvider> ash_color_provider_;

// For testing only: simulate that a modal window is open
bool simulate_modal_window_open_for_test_ = false;

Expand Down
47 changes: 46 additions & 1 deletion ash/style/ash_color_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,24 @@ SkColor AshColorProvider::GetControlsLayerColor(
return GetControlsLayerColorImpl(type, color_mode);
}

SkColor AshColorProvider::DeprecatedGetContentLayerColor(
ContentLayerType type,
SkColor default_color) const {
if (color_mode_ == AshColorMode::kDefault)
return default_color;

return GetContentLayerColorImpl(type, color_mode_);
}

SkColor AshColorProvider::GetContentLayerColor(
ContentLayerType type,
AshColorMode given_color_mode) const {
AshColorMode color_mode =
color_mode_ != AshColorMode::kDefault ? color_mode_ : given_color_mode;
DCHECK(color_mode != AshColorMode::kDefault);
return GetContentLayerColorImpl(type, color_mode);
}

AshColorProvider::RippleAttributes AshColorProvider::GetRippleAttributes(
SkColor bg_color) const {
const SkColor base_color = color_utils::GetColorWithMaxContrast(bg_color);
Expand Down Expand Up @@ -170,7 +188,6 @@ SkColor AshColorProvider::GetControlsLayerColorImpl(
SkColor light_color, dark_color;
switch (type) {
case ControlsLayerType::kHairlineBorder:
case ControlsLayerType::kSeparator:
light_color = SkColorSetA(SK_ColorBLACK, 0x24); // 14%
dark_color = SkColorSetA(SK_ColorWHITE, 0x24);
break;
Expand All @@ -187,4 +204,32 @@ SkColor AshColorProvider::GetControlsLayerColorImpl(
return color_mode == AshColorMode::kLight ? light_color : dark_color;
}

SkColor AshColorProvider::GetContentLayerColorImpl(
ContentLayerType type,
AshColorMode color_mode) const {
SkColor light_color, dark_color;
switch (type) {
case ContentLayerType::kSeparator:
light_color = SkColorSetA(SK_ColorBLACK, 0x24); // 14%
dark_color = SkColorSetA(SK_ColorWHITE, 0x24);
break;
case ContentLayerType::kTextPrimary:
light_color = gfx::kGoogleGrey900;
dark_color = gfx::kGoogleGrey200;
break;
case ContentLayerType::kTextSecondary:
light_color = gfx::kGoogleGrey700;
dark_color = gfx::kGoogleGrey500;
break;
case ContentLayerType::kIconPrimary:
light_color = gfx::kGoogleGrey700;
dark_color = gfx::kGoogleGrey200;
break;
case ContentLayerType::kIconSecondary:
light_color = dark_color = gfx::kGoogleGrey500;
break;
}
return color_mode == AshColorMode::kLight ? light_color : dark_color;
}

} // namespace ash
22 changes: 21 additions & 1 deletion ash/style/ash_color_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,19 @@ class ASH_EXPORT AshColorProvider {
// Types of Controls layer.
enum class ControlsLayerType {
kHairlineBorder,
kSeparator,
kActiveControlBackground,
kInactiveControlBackground,
kFocusRing,
};

enum class ContentLayerType {
kSeparator,
kTextPrimary,
kTextSecondary,
kIconPrimary,
kIconSecondary,
};

// Attributes of ripple, includes the base color, opacity of inkdrop and
// highlight.
struct RippleAttributes {
Expand Down Expand Up @@ -110,6 +117,13 @@ class ASH_EXPORT AshColorProvider {
SkColor GetControlsLayerColor(ControlsLayerType type,
AshColorMode given_color_mode) const;

// Gets color of Content layer. See details at the corresponding function of
// Base layer.
SkColor DeprecatedGetContentLayerColor(ContentLayerType type,
SkColor default_color) const;
SkColor GetContentLayerColor(ContentLayerType type,
AshColorMode given_color_mode) const;

// Gets the attributes of ripple on |bg_color|. |bg_color| is the background
// color of the UI element that wants to show inkdrop.
RippleAttributes GetRippleAttributes(SkColor bg_color) const;
Expand Down Expand Up @@ -139,6 +153,12 @@ class ASH_EXPORT AshColorProvider {
SkColor GetControlsLayerColorImpl(ControlsLayerType type,
AshColorMode color_mode) const;

// Gets Content layer color on |type| and |color_mode|. This function will be
// merged into GetContentLayerColor after DeprecatedGetContentLayerColor got
// be removed.
SkColor GetContentLayerColorImpl(ContentLayerType type,
AshColorMode color_mode) const;

// Current color mode of system UI.
AshColorMode color_mode_ = AshColorMode::kDefault;

Expand Down
6 changes: 6 additions & 0 deletions ash/style/default_color_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ constexpr SkColor kSeparatorOnDarkBackgroundColor =
SkColorSetA(SK_ColorWHITE, 0x23); // 14%

constexpr SkColor kNotificationBackgroundColor = SK_ColorWHITE;

constexpr SkColor kUnifiedMenuTextColor = gfx::kGoogleGrey100;
constexpr SkColor kUnifiedMenuSecondaryTextColor =
SkColorSetA(gfx::kGoogleGrey200, 0xa3); // 64%
constexpr SkColor kUnifiedMenuTextColorDisabled = gfx::kGoogleGrey700;

//----------------------------------End----------------------------------------

#endif // ASH_STYLE_DEFAULT_COLOR_CONSTANTS_H_
15 changes: 9 additions & 6 deletions ash/system/accessibility/autoclick_menu_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,17 @@ class AutoclickMenuButton : public TopShortcutButton {

private:
void UpdateImage() {
const SkColor icon_color = AshColorProvider::Get()->GetContentLayerColor(
AshColorProvider::ContentLayerType::kIconPrimary,
AshColorProvider::AshColorMode::kDark);
SetImage(views::Button::STATE_NORMAL,
gfx::CreateVectorIcon(
*icon_, toggled_ ? kAutoclickMenuButtonIconColorActive
: kIconOnDarkBackgroundColor));
*icon_,
toggled_ ? kAutoclickMenuButtonIconColorActive : icon_color));
SetImage(views::Button::STATE_DISABLED,
gfx::CreateVectorIcon(
*icon_, toggled_ ? kAutoclickMenuButtonIconColorActive
: kIconOnDarkBackgroundColor));
*icon_,
toggled_ ? kAutoclickMenuButtonIconColorActive : icon_color));
}

const gfx::VectorIcon* icon_;
Expand Down Expand Up @@ -215,8 +218,8 @@ AutoclickMenuView::AutoclickMenuView(AutoclickEventType type,
AddChildView(action_button_container);

views::Separator* separator = new views::Separator();
separator->SetColor(AshColorProvider::Get()->DeprecatedGetControlsLayerColor(
AshColorProvider::ControlsLayerType::kSeparator,
separator->SetColor(AshColorProvider::Get()->DeprecatedGetContentLayerColor(
AshColorProvider::ContentLayerType::kSeparator,
kSeparatorOnDarkBackgroundColor));
separator->SetPreferredHeight(kSeparatorHeight);
int total_height = kUnifiedTopShortcutSpacing * 2 + kTrayItemSize;
Expand Down
15 changes: 11 additions & 4 deletions ash/system/accessibility/autoclick_scroll_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "ash/resources/vector_icons/vector_icons.h"
#include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/style/ash_color_provider.h"
#include "ash/system/accessibility/autoclick_menu_bubble_controller.h"
#include "ash/system/tray/tray_constants.h"
#include "ash/system/unified/custom_shape_button.h"
Expand Down Expand Up @@ -50,9 +51,12 @@ class AutoclickScrollCloseButton : public TopShortcutButton,
EnableCanvasFlippingForRTLUI(false);
SetPreferredSize(
gfx::Size(kScrollButtonCloseSizeDips, kScrollButtonCloseSizeDips));
SetImage(
views::Button::STATE_NORMAL,
gfx::CreateVectorIcon(kAutoclickCloseIcon, kIconOnDarkBackgroundColor));
SetImage(views::Button::STATE_NORMAL,
gfx::CreateVectorIcon(
kAutoclickCloseIcon,
AshColorProvider::Get()->GetContentLayerColor(
AshColorProvider::ContentLayerType::kIconPrimary,
AshColorProvider::AshColorMode::kDark)));
}

~AutoclickScrollCloseButton() override = default;
Expand Down Expand Up @@ -131,7 +135,10 @@ class AutoclickScrollButton : public CustomShapeButton,
base::BindRepeating(&AutoclickScrollButton::DoScrollAction,
base::Unretained(this)));
SetImage(views::Button::STATE_NORMAL,
gfx::CreateVectorIcon(icon, kIconOnDarkBackgroundColor));
gfx::CreateVectorIcon(
icon, AshColorProvider::Get()->GetContentLayerColor(
AshColorProvider::ContentLayerType::kIconPrimary,
AshColorProvider::AshColorMode::kDark)));
if (action_ == AutoclickController::ScrollPadAction::kScrollLeft ||
action_ == AutoclickController::ScrollPadAction::kScrollRight) {
size_ = gfx::Size(kScrollPadButtonHypotenuseDips / 2,
Expand Down
10 changes: 6 additions & 4 deletions ash/system/audio/unified_volume_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "ash/resources/vector_icons/vector_icons.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/style/ash_color_provider.h"
#include "ash/system/audio/unified_volume_slider_controller.h"
#include "ash/system/tray/tray_constants.h"
#include "ash/system/tray/tray_popup_utils.h"
Expand Down Expand Up @@ -67,10 +68,12 @@ class MoreButton : public views::Button {
2),
2));

const SkColor icon_color = AshColorProvider::Get()->GetContentLayerColor(
AshColorProvider::ContentLayerType::kIconPrimary,
AshColorProvider::AshColorMode::kDark);
auto* headset = new views::ImageView();
headset->set_can_process_events_within_subtree(false);
headset->SetImage(CreateVectorIcon(vector_icons::kHeadsetIcon,
kIconOnDarkBackgroundColor));
headset->SetImage(CreateVectorIcon(vector_icons::kHeadsetIcon, icon_color));
AddChildView(headset);

auto* more = new views::ImageView();
Expand All @@ -79,8 +82,7 @@ class MoreButton : public views::Button {
? SkBitmapOperations::ROTATION_270_CW
: SkBitmapOperations::ROTATION_90_CW;
more->SetImage(gfx::ImageSkiaOperations::CreateRotatedImage(
CreateVectorIcon(kUnifiedMenuExpandIcon, kIconOnDarkBackgroundColor),
icon_rotation));
CreateVectorIcon(kUnifiedMenuExpandIcon, icon_color), icon_rotation));
AddChildView(more);

SetTooltipText(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_AUDIO));
Expand Down
7 changes: 5 additions & 2 deletions ash/system/ime/tray_ime_chromeos.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#include "ash/resources/vector_icons/vector_icons.h"
#include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/style/ash_color_provider.h"
#include "ash/system/model/system_tray_model.h"
#include "ash/system/tray/tray_constants.h"
#include "ash/system/tray/tray_detailed_view.h"
#include "ash/system/tray/tray_popup_item_style.h"
#include "ash/system/tray/tray_popup_utils.h"
Expand Down Expand Up @@ -66,7 +66,10 @@ void IMEDetailedView::CreateExtraTitleRowButtons() {
if (ime_controller_->managed_by_policy()) {
controlled_setting_icon_ = TrayPopupUtils::CreateMainImageView();
controlled_setting_icon_->SetImage(gfx::CreateVectorIcon(
kSystemMenuBusinessIcon, kIconOnLightBackgroundColor));
kSystemMenuBusinessIcon,
AshColorProvider::Get()->GetContentLayerColor(
AshColorProvider::ContentLayerType::kIconPrimary,
AshColorProvider::AshColorMode::kLight)));
controlled_setting_icon_->set_tooltip_text(
l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_IME_MANAGED));
tri_view()->AddView(TriView::Container::END, controlled_setting_icon_);
Expand Down
22 changes: 15 additions & 7 deletions ash/system/ime_menu/ime_list_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
#include "ash/resources/vector_icons/vector_icons.h"
#include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/style/ash_color_provider.h"
#include "ash/style/default_color_constants.h"
#include "ash/system/tray/actionable_view.h"
#include "ash/system/tray/system_menu_button.h"
#include "ash/system/tray/tray_constants.h"
#include "ash/system/tray/tray_detailed_view.h"
#include "ash/system/tray/tray_popup_item_style.h"
#include "ash/system/tray/tray_popup_utils.h"
Expand Down Expand Up @@ -64,7 +65,10 @@ class ImeListItemView : public ActionableView {
// |id_label| contains the IME short name (e.g., 'US', 'GB', 'IT').
views::Label* id_label = TrayPopupUtils::CreateDefaultLabel();
if (use_unified_theme) {
id_label->SetEnabledColor(kUnifiedMenuTextColor);
id_label->SetEnabledColor(
AshColorProvider::Get()->DeprecatedGetContentLayerColor(
AshColorProvider::ContentLayerType::kTextPrimary,
kUnifiedMenuTextColor));
id_label->SetAutoColorReadabilityEnabled(false);
}
id_label->SetText(id);
Expand Down Expand Up @@ -158,9 +162,11 @@ class KeyboardStatusRow : public views::View {

// The on-screen keyboard image button.
views::ImageView* keyboard_image = TrayPopupUtils::CreateMainImageView();
keyboard_image->SetImage(
gfx::CreateVectorIcon(kImeMenuOnScreenKeyboardIcon, kMenuIconSize,
kIconOnLightBackgroundColor));
keyboard_image->SetImage(gfx::CreateVectorIcon(
kImeMenuOnScreenKeyboardIcon, kMenuIconSize,
AshColorProvider::Get()->GetContentLayerColor(
AshColorProvider::ContentLayerType::kIconPrimary,
AshColorProvider::AshColorMode::kLight)));
tri_view->AddView(TriView::Container::START, keyboard_image);

// The on-screen keyboard label ('On-screen keyboard').
Expand Down Expand Up @@ -277,12 +283,14 @@ void ImeListView::AppendImeListAndProperties(
scroll_content()->AddChildView(
TrayPopupUtils::CreateListItemSeparator(true));

const SkColor icon_color = AshColorProvider::Get()->GetContentLayerColor(
AshColorProvider::ContentLayerType::kIconPrimary,
AshColorProvider::AshColorMode::kLight);
// Adds the property items.
for (size_t i = 0; i < property_list.size(); i++) {
ImeListItemView* property_view = new ImeListItemView(
this, base::string16(), property_list[i].label,
property_list[i].checked, kIconOnLightBackgroundColor,
use_unified_theme_);
property_list[i].checked, icon_color, use_unified_theme_);
scroll_content()->AddChildView(property_view);
property_map_[property_view] = property_list[i].key;
}
Expand Down
15 changes: 8 additions & 7 deletions ash/system/ime_menu/ime_menu_tray.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include "ash/system/tray/detailed_view_delegate.h"
#include "ash/system/tray/system_menu_button.h"
#include "ash/system/tray/system_tray_notifier.h"
#include "ash/system/tray/tray_constants.h"
#include "ash/system/tray/tray_container.h"
#include "ash/system/tray/tray_popup_item_style.h"
#include "ash/system/tray/tray_popup_utils.h"
Expand Down Expand Up @@ -131,8 +130,8 @@ class ImeTitleView : public views::View, public views::ButtonListener {
SetBorder(views::CreatePaddedBorder(
views::CreateSolidSidedBorder(
0, 0, kMenuSeparatorWidth, 0,
AshColorProvider::Get()->DeprecatedGetControlsLayerColor(
AshColorProvider::ControlsLayerType::kSeparator,
AshColorProvider::Get()->DeprecatedGetContentLayerColor(
AshColorProvider::ContentLayerType::kSeparator,
kSeparatorOnLightBackgroundColor)),
gfx::Insets(kMenuSeparatorVerticalPadding - kMenuSeparatorWidth, 0)));
auto box_layout = std::make_unique<views::BoxLayout>(
Expand Down Expand Up @@ -237,8 +236,8 @@ class ImeButtonsView : public views::View, public views::ButtonListener {
SetBorder(views::CreatePaddedBorder(
views::CreateSolidSidedBorder(
kMenuSeparatorWidth, 0, 0, 0,
AshColorProvider::Get()->DeprecatedGetControlsLayerColor(
AshColorProvider::ControlsLayerType::kSeparator,
AshColorProvider::Get()->DeprecatedGetContentLayerColor(
AshColorProvider::ContentLayerType::kSeparator,
kSeparatorOnLightBackgroundColor)),
gfx::Insets(kMenuSeparatorVerticalPadding - kMenuSeparatorWidth,
kMenuExtraMarginFromLeftEdge)));
Expand Down Expand Up @@ -540,8 +539,10 @@ void ImeMenuTray::UpdateTrayLabel() {
// IME.
if (chromeos::extension_ime_util::IsArcIME(current_ime.id)) {
CreateImageView();
image_view_->SetImage(
gfx::CreateVectorIcon(kShelfGlobeIcon, kIconOnDarkBackgroundColor));
image_view_->SetImage(gfx::CreateVectorIcon(
kShelfGlobeIcon, AshColorProvider::Get()->GetContentLayerColor(
AshColorProvider::ContentLayerType::kIconPrimary,
AshColorProvider::AshColorMode::kDark)));
return;
}

Expand Down
Loading

0 comments on commit bee2e31

Please sign in to comment.