Commit 56fc9d63 authored by estade's avatar estade Committed by Commit bot

Introduce a type of View background that stays in sync with its host

View's native theme.

This fixes a few bugs where we weren't using the right native theme,
whether by not updating after the NativeTheme changes or by trying to
access the NativeTheme before the View is added to a hierarchy (which
yields the default NativeTheme --- for most platforms, this didn't
effectively create a bug as there's only one NativeTheme).

Best example is that now the sad tab respects the GTK native theme.

Get rid of Ash's tray_constants::kBackgroundColor in favor of using the
bubble background color from the NativeTheme.

This is a reland of 097f9cde with fix
for asan failure.

BUG=711183, 693282
TBR=stevenjb@chromium.org,tdanderson@chromium.org

Review-Url: https://codereview.chromium.org/2838273002
Cr-Commit-Position: refs/heads/master@{#468157}
parent a88d3cb5
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/paint_vector_icon.h" #include "ui/gfx/paint_vector_icon.h"
#include "ui/gfx/vector_icon_types.h" #include "ui/gfx/vector_icon_types.h"
#include "ui/native_theme/native_theme.h"
#include "ui/views/background.h" #include "ui/views/background.h"
#include "ui/views/border.h" #include "ui/views/border.h"
#include "ui/views/controls/button/custom_button.h" #include "ui/views/controls/button/custom_button.h"
...@@ -130,7 +131,9 @@ VolumeView::VolumeView(SystemTrayItem* owner, ...@@ -130,7 +131,9 @@ VolumeView::VolumeView(SystemTrayItem* owner,
l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_VOLUME)); l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_VOLUME));
tri_view_->AddView(TriView::Container::CENTER, slider_); tri_view_->AddView(TriView::Container::CENTER, slider_);
set_background(views::Background::CreateSolidBackground(kBackgroundColor)); set_background(views::Background::CreateThemedSolidBackground(
this, ui::NativeTheme::kColorId_BubbleBackground));
Update(); Update();
} }
......
...@@ -63,6 +63,7 @@ ...@@ -63,6 +63,7 @@
#include "ui/gfx/skia_util.h" #include "ui/gfx/skia_util.h"
#include "ui/message_center/message_center.h" #include "ui/message_center/message_center.h"
#include "ui/message_center/message_center_style.h" #include "ui/message_center/message_center_style.h"
#include "ui/native_theme/native_theme.h"
#include "ui/views/border.h" #include "ui/views/border.h"
#include "ui/views/controls/label.h" #include "ui/views/controls/label.h"
#include "ui/views/view.h" #include "ui/views/view.h"
...@@ -471,7 +472,6 @@ void SystemTray::ShowItems(const std::vector<SystemTrayItem*>& items, ...@@ -471,7 +472,6 @@ void SystemTray::ShowItems(const std::vector<SystemTrayItem*>& items,
// This is the case where a volume control or brightness control bubble // This is the case where a volume control or brightness control bubble
// is created. // is created.
init_params.max_height = default_bubble_height_; init_params.max_height = default_bubble_height_;
init_params.bg_color = kBackgroundColor;
} else { } else {
init_params.bg_color = kHeaderBackgroundColor; init_params.bg_color = kHeaderBackgroundColor;
} }
......
...@@ -64,7 +64,6 @@ const int kTrayRoundedBorderRadius = 2; ...@@ -64,7 +64,6 @@ const int kTrayRoundedBorderRadius = 2;
const int kTrayToggleButtonWidth = 68; const int kTrayToggleButtonWidth = 68;
const SkColor kBackgroundColor = SK_ColorWHITE;
const SkColor kPublicAccountUserCardTextColor = SkColorSetRGB(0x66, 0x66, 0x66); const SkColor kPublicAccountUserCardTextColor = SkColorSetRGB(0x66, 0x66, 0x66);
const SkColor kPublicAccountUserCardNameColor = SK_ColorBLACK; const SkColor kPublicAccountUserCardNameColor = SK_ColorBLACK;
......
...@@ -77,7 +77,6 @@ extern const int kTrayRoundedBorderRadius; ...@@ -77,7 +77,6 @@ extern const int kTrayRoundedBorderRadius;
// The width of ToggleButton views including any border padding. // The width of ToggleButton views including any border padding.
extern const int kTrayToggleButtonWidth; extern const int kTrayToggleButtonWidth;
extern const SkColor kBackgroundColor;
extern const SkColor kPublicAccountUserCardTextColor; extern const SkColor kPublicAccountUserCardTextColor;
extern const SkColor kPublicAccountUserCardNameColor; extern const SkColor kPublicAccountUserCardNameColor;
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "ui/gfx/paint_vector_icon.h" #include "ui/gfx/paint_vector_icon.h"
#include "ui/gfx/skia_paint_util.h" #include "ui/gfx/skia_paint_util.h"
#include "ui/gfx/vector_icon_types.h" #include "ui/gfx/vector_icon_types.h"
#include "ui/native_theme/native_theme.h"
#include "ui/views/background.h" #include "ui/views/background.h"
#include "ui/views/border.h" #include "ui/views/border.h"
#include "ui/views/controls/image_view.h" #include "ui/views/controls/image_view.h"
...@@ -244,7 +245,8 @@ TrayDetailsView::TrayDetailsView(SystemTrayItem* owner) ...@@ -244,7 +245,8 @@ TrayDetailsView::TrayDetailsView(SystemTrayItem* owner)
tri_view_(nullptr), tri_view_(nullptr),
back_button_(nullptr) { back_button_(nullptr) {
SetLayoutManager(box_layout_); SetLayoutManager(box_layout_);
set_background(views::Background::CreateSolidBackground(kBackgroundColor)); set_background(views::Background::CreateThemedSolidBackground(
this, ui::NativeTheme::kColorId_BubbleBackground));
} }
TrayDetailsView::~TrayDetailsView() {} TrayDetailsView::~TrayDetailsView() {}
...@@ -301,8 +303,8 @@ void TrayDetailsView::CreateScrollableList() { ...@@ -301,8 +303,8 @@ void TrayDetailsView::CreateScrollableList() {
// Make the |scroller_| have a layer to clip |scroll_content_|'s children. // Make the |scroller_| have a layer to clip |scroll_content_|'s children.
// TODO(varkha): Make the sticky rows work with EnableViewPortLayer(). // TODO(varkha): Make the sticky rows work with EnableViewPortLayer().
scroller_->SetPaintToLayer(); scroller_->SetPaintToLayer();
scroller_->set_background( scroller_->set_background(views::Background::CreateThemedSolidBackground(
views::Background::CreateSolidBackground(kBackgroundColor)); scroller_, ui::NativeTheme::kColorId_BubbleBackground));
scroller_->layer()->SetMasksToBounds(true); scroller_->layer()->SetMasksToBounds(true);
AddChildView(scroller_); AddChildView(scroller_);
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/color_palette.h" #include "ui/gfx/color_palette.h"
#include "ui/gfx/paint_vector_icon.h" #include "ui/gfx/paint_vector_icon.h"
#include "ui/native_theme/native_theme.h"
#include "ui/views/animation/flood_fill_ink_drop_ripple.h" #include "ui/views/animation/flood_fill_ink_drop_ripple.h"
#include "ui/views/animation/ink_drop_highlight.h" #include "ui/views/animation/ink_drop_highlight.h"
#include "ui/views/animation/ink_drop_impl.h" #include "ui/views/animation/ink_drop_impl.h"
...@@ -227,9 +228,8 @@ views::Label* TrayPopupUtils::CreateDefaultLabel() { ...@@ -227,9 +228,8 @@ views::Label* TrayPopupUtils::CreateDefaultLabel() {
// Frequently the label will paint to a layer that's non-opaque, so subpixel // Frequently the label will paint to a layer that's non-opaque, so subpixel
// rendering won't work unless we explicitly set a background. See // rendering won't work unless we explicitly set a background. See
// crbug.com/686363 // crbug.com/686363
label->set_background( label->set_background(views::Background::CreateThemedSolidBackground(
views::Background::CreateSolidBackground(kBackgroundColor)); label, ui::NativeTheme::kColorId_BubbleBackground));
label->SetBackgroundColor(kBackgroundColor);
return label; return label;
} }
...@@ -288,8 +288,8 @@ void TrayPopupUtils::ConfigureTrayPopupButton(views::CustomButton* button) { ...@@ -288,8 +288,8 @@ void TrayPopupUtils::ConfigureTrayPopupButton(views::CustomButton* button) {
void TrayPopupUtils::ConfigureAsStickyHeader(views::View* view) { void TrayPopupUtils::ConfigureAsStickyHeader(views::View* view) {
view->set_id(VIEW_ID_STICKY_HEADER); view->set_id(VIEW_ID_STICKY_HEADER);
view->set_background( view->set_background(views::Background::CreateThemedSolidBackground(
views::Background::CreateSolidBackground(kBackgroundColor)); view, ui::NativeTheme::kColorId_BubbleBackground));
view->SetBorder( view->SetBorder(
views::CreateEmptyBorder(gfx::Insets(kMenuSeparatorVerticalPadding, 0))); views::CreateEmptyBorder(gfx::Insets(kMenuSeparatorVerticalPadding, 0)));
view->SetPaintToLayer(); view->SetPaintToLayer();
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/image/image.h" #include "ui/gfx/image/image.h"
#include "ui/gfx/paint_vector_icon.h" #include "ui/gfx/paint_vector_icon.h"
#include "ui/native_theme/native_theme.h"
#include "ui/resources/grit/ui_resources.h" #include "ui/resources/grit/ui_resources.h"
#include "ui/views/background.h" #include "ui/views/background.h"
#include "ui/views/controls/button/custom_button.h" #include "ui/views/controls/button/custom_button.h"
...@@ -130,7 +131,8 @@ AccessibilityPopupView::AccessibilityPopupView(uint32_t enabled_state_bits) ...@@ -130,7 +131,8 @@ AccessibilityPopupView::AccessibilityPopupView(uint32_t enabled_state_bits)
: label_(CreateLabel(enabled_state_bits)) {} : label_(CreateLabel(enabled_state_bits)) {}
void AccessibilityPopupView::Init() { void AccessibilityPopupView::Init() {
set_background(views::Background::CreateSolidBackground(kBackgroundColor)); set_background(views::Background::CreateThemedSolidBackground(
this, ui::NativeTheme::kColorId_BubbleBackground));
views::GridLayout* layout = new views::GridLayout(this); views::GridLayout* layout = new views::GridLayout(this);
SetLayoutManager(layout); SetLayoutManager(layout);
......
...@@ -292,7 +292,8 @@ UserCardView::UserCardView(LoginStatus login_status, int user_index) ...@@ -292,7 +292,8 @@ UserCardView::UserCardView(LoginStatus login_status, int user_index)
layout->set_cross_axis_alignment( layout->set_cross_axis_alignment(
views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER);
set_background(views::Background::CreateSolidBackground(kBackgroundColor)); set_background(views::Background::CreateThemedSolidBackground(
this, ui::NativeTheme::kColorId_BubbleBackground));
Shell::Get()->media_controller()->AddObserver(this); Shell::Get()->media_controller()->AddObserver(this);
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include "ui/gfx/color_utils.h" #include "ui/gfx/color_utils.h"
#include "ui/gfx/geometry/insets.h" #include "ui/gfx/geometry/insets.h"
#include "ui/gfx/paint_vector_icon.h" #include "ui/gfx/paint_vector_icon.h"
#include "ui/native_theme/native_theme.h"
#include "ui/views/controls/button/label_button.h" #include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/label.h" #include "ui/views/controls/label.h"
#include "ui/views/controls/separator.h" #include "ui/views/controls/separator.h"
...@@ -73,8 +74,7 @@ bool IsMultiProfileSupportedAndUserActive() { ...@@ -73,8 +74,7 @@ bool IsMultiProfileSupportedAndUserActive() {
} }
// Creates the view shown in the user switcher popup ("AddUserMenuOption"). // Creates the view shown in the user switcher popup ("AddUserMenuOption").
views::View* CreateAddUserView(AddUserSessionPolicy policy, views::View* CreateAddUserView(AddUserSessionPolicy policy) {
views::ButtonListener* listener) {
auto* view = new views::View; auto* view = new views::View;
const int icon_padding = (kMenuButtonSize - kMenuIconSize) / 2; const int icon_padding = (kMenuButtonSize - kMenuIconSize) / 2;
auto* layout = auto* layout =
...@@ -82,8 +82,8 @@ views::View* CreateAddUserView(AddUserSessionPolicy policy, ...@@ -82,8 +82,8 @@ views::View* CreateAddUserView(AddUserSessionPolicy policy,
kTrayPopupLabelHorizontalPadding + icon_padding); kTrayPopupLabelHorizontalPadding + icon_padding);
layout->set_minimum_cross_axis_size(kTrayPopupItemMinHeight); layout->set_minimum_cross_axis_size(kTrayPopupItemMinHeight);
view->SetLayoutManager(layout); view->SetLayoutManager(layout);
view->set_background( view->set_background(views::Background::CreateThemedSolidBackground(
views::Background::CreateSolidBackground(kBackgroundColor)); view, ui::NativeTheme::kColorId_BubbleBackground));
int message_id = 0; int message_id = 0;
switch (policy) { switch (policy) {
...@@ -124,13 +124,6 @@ views::View* CreateAddUserView(AddUserSessionPolicy policy, ...@@ -124,13 +124,6 @@ views::View* CreateAddUserView(AddUserSessionPolicy policy,
view->SetBorder(views::CreateEmptyBorder(vertical_padding, icon_padding, view->SetBorder(views::CreateEmptyBorder(vertical_padding, icon_padding,
vertical_padding, vertical_padding,
kTrayPopupLabelHorizontalPadding)); kTrayPopupLabelHorizontalPadding));
if (policy == AddUserSessionPolicy::ALLOWED) {
auto* button =
new ButtonFromView(view, listener, TrayPopupInkDropStyle::INSET_BOUNDS);
button->SetAccessibleName(
l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT));
return button;
}
return view; return view;
} }
...@@ -228,11 +221,11 @@ UserView::UserView(SystemTrayItem* owner, LoginStatus login) : owner_(owner) { ...@@ -228,11 +221,11 @@ UserView::UserView(SystemTrayItem* owner, LoginStatus login) : owner_(owner) {
} }
UserView::~UserView() { UserView::~UserView() {
RemoveAddUserMenuOption(); HideUserDropdownWidget();
} }
TrayUser::TestState UserView::GetStateForTest() const { TrayUser::TestState UserView::GetStateForTest() const {
if (add_menu_option_) if (user_dropdown_widget_)
return add_user_enabled_ ? TrayUser::ACTIVE : TrayUser::ACTIVE_BUT_DISABLED; return add_user_enabled_ ? TrayUser::ACTIVE : TrayUser::ACTIVE_BUT_DISABLED;
// If the container is the user card view itself, there's no ButtonFromView // If the container is the user card view itself, there's no ButtonFromView
...@@ -257,13 +250,13 @@ int UserView::GetHeightForWidth(int width) const { ...@@ -257,13 +250,13 @@ int UserView::GetHeightForWidth(int width) const {
void UserView::ButtonPressed(views::Button* sender, const ui::Event& event) { void UserView::ButtonPressed(views::Button* sender, const ui::Event& event) {
if (sender == logout_button_) { if (sender == logout_button_) {
ShellPort::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_SIGN_OUT); ShellPort::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_SIGN_OUT);
RemoveAddUserMenuOption(); HideUserDropdownWidget();
Shell::Get()->system_tray_controller()->SignOut(); Shell::Get()->system_tray_controller()->SignOut();
} else if (sender == user_card_container_ && } else if (sender == user_card_container_ &&
IsMultiProfileSupportedAndUserActive()) { IsMultiProfileSupportedAndUserActive()) {
ToggleAddUserMenuOption(); ToggleUserDropdownWidget();
} else if (add_menu_option_ && } else if (user_dropdown_widget_ &&
sender->GetWidget() == add_menu_option_.get()) { sender->GetWidget() == user_dropdown_widget_.get()) {
DCHECK_EQ(Shell::Get()->session_controller()->NumberOfLoggedInUsers(), DCHECK_EQ(Shell::Get()->session_controller()->NumberOfLoggedInUsers(),
sender->parent()->child_count() - 1); sender->parent()->child_count() - 1);
const int index_in_add_menu = sender->parent()->GetIndexOf(sender); const int index_in_add_menu = sender->parent()->GetIndexOf(sender);
...@@ -275,7 +268,7 @@ void UserView::ButtonPressed(views::Button* sender, const ui::Event& event) { ...@@ -275,7 +268,7 @@ void UserView::ButtonPressed(views::Button* sender, const ui::Event& event) {
const int user_index = index_in_add_menu; const int user_index = index_in_add_menu;
SwitchUser(user_index); SwitchUser(user_index);
} }
RemoveAddUserMenuOption(); HideUserDropdownWidget();
owner_->system_tray()->CloseSystemBubble(); owner_->system_tray()->CloseSystemBubble();
} else { } else {
NOTREACHED(); NOTREACHED();
...@@ -284,7 +277,7 @@ void UserView::ButtonPressed(views::Button* sender, const ui::Event& event) { ...@@ -284,7 +277,7 @@ void UserView::ButtonPressed(views::Button* sender, const ui::Event& event) {
void UserView::OnWillChangeFocus(View* focused_before, View* focused_now) { void UserView::OnWillChangeFocus(View* focused_before, View* focused_now) {
if (focused_now) if (focused_now)
RemoveAddUserMenuOption(); HideUserDropdownWidget();
} }
void UserView::OnDidChangeFocus(View* focused_before, View* focused_now) { void UserView::OnDidChangeFocus(View* focused_before, View* focused_now) {
...@@ -314,16 +307,16 @@ void UserView::AddUserCard(LoginStatus login) { ...@@ -314,16 +307,16 @@ void UserView::AddUserCard(LoginStatus login) {
AddChildViewAt(user_card_container_, 0); AddChildViewAt(user_card_container_, 0);
} }
void UserView::ToggleAddUserMenuOption() { void UserView::ToggleUserDropdownWidget() {
if (add_menu_option_) { if (user_dropdown_widget_) {
RemoveAddUserMenuOption(); HideUserDropdownWidget();
return; return;
} }
// Note: We do not need to install a global event handler to delete this // Note: We do not need to install a global event handler to delete this
// item since it will destroyed automatically before the menu / user menu item // item since it will destroyed automatically before the menu / user menu item
// gets destroyed.. // gets destroyed..
add_menu_option_.reset(new views::Widget); user_dropdown_widget_.reset(new views::Widget);
views::Widget::InitParams params; views::Widget::InitParams params;
params.type = views::Widget::InitParams::TYPE_MENU; params.type = views::Widget::InitParams::TYPE_MENU;
params.keep_on_top = true; params.keep_on_top = true;
...@@ -334,9 +327,9 @@ void UserView::ToggleAddUserMenuOption() { ...@@ -334,9 +327,9 @@ void UserView::ToggleAddUserMenuOption() {
WmWindow::Get(GetWidget()->GetNativeWindow()) WmWindow::Get(GetWidget()->GetNativeWindow())
->GetRootWindowController() ->GetRootWindowController()
->ConfigureWidgetInitParamsForContainer( ->ConfigureWidgetInitParamsForContainer(
add_menu_option_.get(), kShellWindowId_DragImageAndTooltipContainer, user_dropdown_widget_.get(),
&params); kShellWindowId_DragImageAndTooltipContainer, &params);
add_menu_option_->Init(params); user_dropdown_widget_->Init(params);
const SessionController* const session_controller = const SessionController* const session_controller =
Shell::Get()->session_controller(); Shell::Get()->session_controller();
...@@ -352,48 +345,63 @@ void UserView::ToggleAddUserMenuOption() { ...@@ -352,48 +345,63 @@ void UserView::ToggleAddUserMenuOption() {
int row_height = bounds.height(); int row_height = bounds.height();
views::View* container = new UserDropdownWidgetContents( views::View* container = new UserDropdownWidgetContents(
base::Bind(&UserView::RemoveAddUserMenuOption, base::Unretained(this))); base::Bind(&UserView::HideUserDropdownWidget, base::Unretained(this)));
views::View* add_user_view = CreateAddUserView(add_user_policy);
const SkColor bg_color = add_user_view->background()->get_color();
container->SetBorder(views::CreatePaddedBorder( container->SetBorder(views::CreatePaddedBorder(
views::CreateSolidSidedBorder(0, 0, 0, kSeparatorWidth, kBackgroundColor), views::CreateSolidSidedBorder(0, 0, 0, kSeparatorWidth, bg_color),
gfx::Insets(row_height, 0, 0, 0))); gfx::Insets(row_height, 0, 0, 0)));
// Create the contents aside from the empty window through which the active
// user is seen.
views::View* user_dropdown_padding = new views::View(); views::View* user_dropdown_padding = new views::View();
user_dropdown_padding->SetBorder(views::CreateSolidSidedBorder( user_dropdown_padding->SetBorder(views::CreateSolidSidedBorder(
kMenuSeparatorVerticalPadding - kSeparatorWidth, 0, 0, 0, kMenuSeparatorVerticalPadding - kSeparatorWidth, 0, 0, 0, bg_color));
kBackgroundColor));
user_dropdown_padding->SetLayoutManager( user_dropdown_padding->SetLayoutManager(
new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0));
views::Separator* separator = new views::Separator(); views::Separator* separator = new views::Separator();
separator->SetPreferredHeight(kSeparatorWidth); separator->SetPreferredHeight(kSeparatorWidth);
separator->SetColor(color_utils::GetResultingPaintColor(kMenuSeparatorColor, separator->SetColor(
kBackgroundColor)); color_utils::GetResultingPaintColor(kMenuSeparatorColor, bg_color));
const int separator_horizontal_padding = const int separator_horizontal_padding =
(kTrayPopupItemMinStartWidth - kTrayItemSize) / 2; (kTrayPopupItemMinStartWidth - kTrayItemSize) / 2;
separator->SetBorder(views::CreateSolidSidedBorder( separator->SetBorder(
0, separator_horizontal_padding, 0, separator_horizontal_padding, views::CreateSolidSidedBorder(0, separator_horizontal_padding, 0,
kBackgroundColor)); separator_horizontal_padding, bg_color));
user_dropdown_padding->AddChildView(separator); user_dropdown_padding->AddChildView(separator);
// Add other logged in users.
for (int i = 1; i < session_controller->NumberOfLoggedInUsers(); ++i) { for (int i = 1; i < session_controller->NumberOfLoggedInUsers(); ++i) {
user_dropdown_padding->AddChildView( user_dropdown_padding->AddChildView(
new ButtonFromView(new UserCardView(LoginStatus::USER, i), this, new ButtonFromView(new UserCardView(LoginStatus::USER, i), this,
TrayPopupInkDropStyle::INSET_BOUNDS)); TrayPopupInkDropStyle::INSET_BOUNDS));
} }
user_dropdown_padding->AddChildView(CreateAddUserView(add_user_policy, this)); // Add the "add user" option or the "can't add another user" message.
if (add_user_enabled_) {
auto* button = new ButtonFromView(add_user_view, this,
TrayPopupInkDropStyle::INSET_BOUNDS);
button->SetAccessibleName(
l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT));
user_dropdown_padding->AddChildView(button);
} else {
user_dropdown_padding->AddChildView(add_user_view);
}
container->AddChildView(user_dropdown_padding); container->AddChildView(user_dropdown_padding);
container->SetLayoutManager(new views::FillLayout()); container->SetLayoutManager(new views::FillLayout());
add_menu_option_->SetContentsView(container); user_dropdown_widget_->SetContentsView(container);
bounds.set_height(container->GetPreferredSize().height()); bounds.set_height(container->GetPreferredSize().height());
add_menu_option_->SetBounds(bounds); user_dropdown_widget_->SetBounds(bounds);
// Suppress the appearance of the collective capture icon while the dropdown // Suppress the appearance of the collective capture icon while the dropdown
// is open (the icon will appear in the specific user rows). // is open (the icon will appear in the specific user rows).
user_card_view_->SetSuppressCaptureIcon(true); user_card_view_->SetSuppressCaptureIcon(true);
// Show the content. // Show the content.
add_menu_option_->SetAlwaysOnTop(true); user_dropdown_widget_->SetAlwaysOnTop(true);
add_menu_option_->Show(); user_dropdown_widget_->Show();
// Install a listener to focus changes so that we can remove the card when // Install a listener to focus changes so that we can remove the card when
// the focus gets changed. When called through the destruction of the bubble, // the focus gets changed. When called through the destruction of the bubble,
...@@ -402,15 +410,15 @@ void UserView::ToggleAddUserMenuOption() { ...@@ -402,15 +410,15 @@ void UserView::ToggleAddUserMenuOption() {
focus_manager_->AddFocusChangeListener(this); focus_manager_->AddFocusChangeListener(this);
} }
void UserView::RemoveAddUserMenuOption() { void UserView::HideUserDropdownWidget() {
if (!add_menu_option_) if (!user_dropdown_widget_)
return; return;
focus_manager_->RemoveFocusChangeListener(this); focus_manager_->RemoveFocusChangeListener(this);
focus_manager_ = nullptr; focus_manager_ = nullptr;
if (user_card_container_->GetFocusManager()) if (user_card_container_->GetFocusManager())
user_card_container_->GetFocusManager()->ClearFocus(); user_card_container_->GetFocusManager()->ClearFocus();
user_card_view_->SetSuppressCaptureIcon(false); user_card_view_->SetSuppressCaptureIcon(false);
add_menu_option_.reset(); user_dropdown_widget_.reset();
} }
} // namespace tray } // namespace tray
......
...@@ -62,10 +62,10 @@ class UserView : public views::View, ...@@ -62,10 +62,10 @@ class UserView : public views::View,
// Create the menu option to add another user. If |disabled| is set the user // Create the menu option to add another user. If |disabled| is set the user
// cannot actively click on the item. // cannot actively click on the item.
void ToggleAddUserMenuOption(); void ToggleUserDropdownWidget();
// Removes the add user menu option. // Removes the add user menu option.
void RemoveAddUserMenuOption(); void HideUserDropdownWidget();
// If |user_card_view_| is clickable, this is a ButtonFromView that wraps it. // If |user_card_view_| is clickable, this is a ButtonFromView that wraps it.
// If |user_card_view_| is not clickable, this will be equal to // If |user_card_view_| is not clickable, this will be equal to
...@@ -79,7 +79,7 @@ class UserView : public views::View, ...@@ -79,7 +79,7 @@ class UserView : public views::View,
SystemTrayItem* owner_; SystemTrayItem* owner_;
views::View* logout_button_ = nullptr; views::View* logout_button_ = nullptr;
std::unique_ptr<views::Widget> add_menu_option_; std::unique_ptr<views::Widget> user_dropdown_widget_;
// False when the add user panel is visible but not activatable. // False when the add user panel is visible but not activatable.
bool add_user_enabled_ = true; bool add_user_enabled_ = true;
......
...@@ -155,9 +155,8 @@ PasswordGenerationPopupViewViews::PasswordGenerationPopupViewViews( ...@@ -155,9 +155,8 @@ PasswordGenerationPopupViewViews::PasswordGenerationPopupViewViews(
PasswordGenerationPopupController::kHorizontalPadding)); PasswordGenerationPopupController::kHorizontalPadding));
AddChildView(help_label_); AddChildView(help_label_);
set_background(views::Background::CreateSolidBackground( set_background(views::Background::CreateThemedSolidBackground(
GetNativeTheme()->GetSystemColor( this, ui::NativeTheme::kColorId_ResultsTableNormalBackground));
ui::NativeTheme::kColorId_ResultsTableNormalBackground)));
} }
PasswordGenerationPopupViewViews::~PasswordGenerationPopupViewViews() {} PasswordGenerationPopupViewViews::~PasswordGenerationPopupViewViews() {}
...@@ -212,12 +211,11 @@ void PasswordGenerationPopupViewViews::PasswordSelectionUpdated() { ...@@ -212,12 +211,11 @@ void PasswordGenerationPopupViewViews::PasswordSelectionUpdated() {
if (controller_->password_selected()) if (controller_->password_selected())
NotifyAccessibilityEvent(ui::AX_EVENT_SELECTION, true); NotifyAccessibilityEvent(ui::AX_EVENT_SELECTION, true);
password_view_->set_background( password_view_->set_background(views::Background::CreateThemedSolidBackground(
views::Background::CreateSolidBackground( password_view_,
GetNativeTheme()->GetSystemColor( controller_->password_selected()
controller_->password_selected() ? ? ui::NativeTheme::kColorId_ResultsTableHoveredBackground
ui::NativeTheme::kColorId_ResultsTableHoveredBackground : : ui::NativeTheme::kColorId_ResultsTableNormalBackground));
ui::NativeTheme::kColorId_ResultsTableNormalBackground)));
} }
void PasswordGenerationPopupViewViews::Layout() { void PasswordGenerationPopupViewViews::Layout() {
......
...@@ -36,10 +36,8 @@ constexpr int kTitleBottomSpacing = 13; ...@@ -36,10 +36,8 @@ constexpr int kTitleBottomSpacing = 13;
SadTabView::SadTabView(content::WebContents* web_contents, SadTabView::SadTabView(content::WebContents* web_contents,
chrome::SadTabKind kind) chrome::SadTabKind kind)
: SadTab(web_contents, kind) { : SadTab(web_contents, kind) {
// Set the background color. set_background(views::Background::CreateThemedSolidBackground(
set_background( this, ui::NativeTheme::kColorId_DialogBackground));
views::Background::CreateSolidBackground(GetNativeTheme()->GetSystemColor(
ui::NativeTheme::kColorId_DialogBackground)));
views::GridLayout* layout = new views::GridLayout(this); views::GridLayout* layout = new views::GridLayout(this);
SetLayoutManager(layout); SetLayoutManager(layout);
...@@ -61,7 +59,7 @@ SadTabView::SadTabView(content::WebContents* web_contents, ...@@ -61,7 +59,7 @@ SadTabView::SadTabView(content::WebContents* web_contents,
layout->StartRow(0, column_set_id); layout->StartRow(0, column_set_id);
layout->AddView(image, 2, 1); layout->AddView(image, 2, 1);
title_ = CreateLabel(l10n_util::GetStringUTF16(GetTitle())); title_ = new views::Label(l10n_util::GetStringUTF16(GetTitle()));
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
title_->SetFontList(rb.GetFontList(ui::ResourceBundle::LargeFont)); title_->SetFontList(rb.GetFontList(ui::ResourceBundle::LargeFont));
title_->SetMultiLine(true); title_->SetMultiLine(true);
...@@ -70,13 +68,10 @@ SadTabView::SadTabView(content::WebContents* web_contents, ...@@ -70,13 +68,10 @@ SadTabView::SadTabView(content::WebContents* web_contents,
views::kPanelVerticalSpacing); views::kPanelVerticalSpacing);
layout->AddView(title_, 2, 1); layout->AddView(title_, 2, 1);
const SkColor text_color = GetNativeTheme()->GetSystemColor( message_ = new views::Label(l10n_util::GetStringUTF16(GetMessage()));
ui::NativeTheme::kColorId_LabelDisabledColor);
message_ = CreateLabel(l10n_util::GetStringUTF16(GetMessage()));
message_->SetMultiLine(true); message_->SetMultiLine(true);
message_->SetEnabledColor(text_color); message_->SetEnabled(false);
message_->SetHorizontalAlignment(gfx::ALIGN_LEFT); message_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
message_->SetLineHeight(views::kPanelSubVerticalSpacing); message_->SetLineHeight(views::kPanelSubVerticalSpacing);
...@@ -86,8 +81,8 @@ SadTabView::SadTabView(content::WebContents* web_contents, ...@@ -86,8 +81,8 @@ SadTabView::SadTabView(content::WebContents* web_contents,
action_button_ = views::MdTextButton::CreateSecondaryUiBlueButton( action_button_ = views::MdTextButton::CreateSecondaryUiBlueButton(
this, l10n_util::GetStringUTF16(GetButtonTitle())); this, l10n_util::GetStringUTF16(GetButtonTitle()));
help_link_ = help_link_ = new views::Link(l10n_util::GetStringUTF16(GetHelpLinkTitle()));
CreateLink(l10n_util::GetStringUTF16(GetHelpLinkTitle()), text_color); help_link_->set_listener(this);
layout->StartRowWithPadding(0, column_set_id, 0, layout->StartRowWithPadding(0, column_set_id, 0,
views::kPanelVerticalSpacing); views::kPanelVerticalSpacing);
layout->AddView(help_link_, 1, 1, views::GridLayout::LEADING, layout->AddView(help_link_, 1, 1, views::GridLayout::LEADING,
...@@ -150,21 +145,6 @@ void SadTabView::OnPaint(gfx::Canvas* canvas) { ...@@ -150,21 +145,6 @@ void SadTabView::OnPaint(gfx::Canvas* canvas) {
View::OnPaint(canvas); View::OnPaint(canvas);
} }
views::Label* SadTabView::CreateLabel(const base::string16& text) {
views::Label* label = new views::Label(text);
label->SetBackgroundColor(background()->get_color());
return label;
}
views::Link* SadTabView::CreateLink(const base::string16& text,
const SkColor& color) {
views::Link* link = new views::Link(text);
link->SetBackgroundColor(background()->get_color());
link->SetEnabledColor(color);
link->set_listener(this);
return link;
}
namespace chrome { namespace chrome {
SadTab* SadTab::Create(content::WebContents* web_contents, SadTab* SadTab::Create(content::WebContents* web_contents,
......
...@@ -51,10 +51,6 @@ class SadTabView : public chrome::SadTab, ...@@ -51,10 +51,6 @@ class SadTabView : public chrome::SadTab,
void OnPaint(gfx::Canvas* canvas) override; void OnPaint(gfx::Canvas* canvas) override;
private: private:
views::Label* CreateLabel(const base::string16& text);
views::Link* CreateLink(const base::string16& text, const SkColor& color);
bool painted_ = false; bool painted_ = false;
views::Label* message_; views::Label* message_;
views::Link* help_link_; views::Link* help_link_;
......
...@@ -21,9 +21,6 @@ const int kMessageBubbleBaseDefaultMaxHeight = 400; ...@@ -21,9 +21,6 @@ const int kMessageBubbleBaseDefaultMaxHeight = 400;
namespace message_center { namespace message_center {
const SkColor MessageBubbleBase::kBackgroundColor =
SkColorSetRGB(0xfe, 0xfe, 0xfe);
MessageBubbleBase::MessageBubbleBase(MessageCenter* message_center, MessageBubbleBase::MessageBubbleBase(MessageCenter* message_center,
MessageCenterTray* tray) MessageCenterTray* tray)
: message_center_(message_center), : message_center_(message_center),
......
...@@ -57,8 +57,6 @@ class MESSAGE_CENTER_EXPORT MessageBubbleBase { ...@@ -57,8 +57,6 @@ class MESSAGE_CENTER_EXPORT MessageBubbleBase {
views::TrayBubbleView* bubble_view() const { return bubble_view_; } views::TrayBubbleView* bubble_view() const { return bubble_view_; }
static const SkColor kBackgroundColor;
protected: protected:
views::TrayBubbleView::InitParams GetDefaultInitParams( views::TrayBubbleView::InitParams GetDefaultInitParams(
views::TrayBubbleView::AnchorAlignment anchor_alignment); views::TrayBubbleView::AnchorAlignment anchor_alignment);
......
...@@ -6,11 +6,14 @@ ...@@ -6,11 +6,14 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/scoped_observer.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "ui/gfx/canvas.h" #include "ui/gfx/canvas.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/color_utils.h" #include "ui/gfx/color_utils.h"
#include "ui/views/painter.h" #include "ui/views/painter.h"
#include "ui/views/view.h" #include "ui/views/view.h"
#include "ui/views/view_observer.h"
#if defined(OS_WIN) #if defined(OS_WIN)
#include "skia/ext/skia_utils_win.h" #include "skia/ext/skia_utils_win.h"
...@@ -36,6 +39,33 @@ class SolidBackground : public Background { ...@@ -36,6 +39,33 @@ class SolidBackground : public Background {
DISALLOW_COPY_AND_ASSIGN(SolidBackground); DISALLOW_COPY_AND_ASSIGN(SolidBackground);
}; };
// ThemedSolidBackground is a solid background that stays in sync with a view's
// native theme.
class ThemedSolidBackground : public SolidBackground, public ViewObserver {
public:
explicit ThemedSolidBackground(View* view, ui::NativeTheme::ColorId color_id)
: SolidBackground(gfx::kPlaceholderColor),
observer_(this),
color_id_(color_id) {
observer_.Add(view);
OnViewNativeThemeChanged(view);
}
~ThemedSolidBackground() override {}
// ViewObserver:
void OnViewNativeThemeChanged(View* view) override {
SetNativeControlColor(view->GetNativeTheme()->GetSystemColor(color_id_));
view->SchedulePaint();
}
void OnViewIsDeleting(View* view) override { observer_.Remove(view); }
private:
ScopedObserver<View, ViewObserver> observer_;
ui::NativeTheme::ColorId color_id_;
DISALLOW_COPY_AND_ASSIGN(ThemedSolidBackground);
};
class BackgroundPainter : public Background { class BackgroundPainter : public Background {
public: public:
explicit BackgroundPainter(std::unique_ptr<Painter> painter) explicit BackgroundPainter(std::unique_ptr<Painter> painter)
...@@ -72,6 +102,13 @@ Background* Background::CreateSolidBackground(SkColor color) { ...@@ -72,6 +102,13 @@ Background* Background::CreateSolidBackground(SkColor color) {
return new SolidBackground(color); return new SolidBackground(color);
} }
// static
Background* Background::CreateThemedSolidBackground(
View* view,
ui::NativeTheme::ColorId color_id) {
return new ThemedSolidBackground(view, color_id);
}
// static // static
Background* Background::CreateStandardPanelBackground() { Background* Background::CreateStandardPanelBackground() {
// TODO(beng): Should be in NativeTheme. // TODO(beng): Should be in NativeTheme.
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/core/SkColor.h"
#include "ui/native_theme/native_theme.h"
#include "ui/views/views_export.h" #include "ui/views/views_export.h"
#if defined(OS_WIN) #if defined(OS_WIN)
...@@ -47,6 +48,12 @@ class VIEWS_EXPORT Background { ...@@ -47,6 +48,12 @@ class VIEWS_EXPORT Background {
// Creates a background that fills the canvas in the specified color. // Creates a background that fills the canvas in the specified color.
static Background* CreateSolidBackground(SkColor color); static Background* CreateSolidBackground(SkColor color);
// Creates a background that fills the canvas in the color specified by the
// view's NativeTheme and the given color identifier.
static Background* CreateThemedSolidBackground(
View* view,
ui::NativeTheme::ColorId color_id);
// Creates a background that fills the canvas in the specified color. // Creates a background that fills the canvas in the specified color.
static Background* CreateSolidBackground(int r, int g, int b) { static Background* CreateSolidBackground(int r, int g, int b) {
return CreateSolidBackground(SkColorSetRGB(r, g, b)); return CreateSolidBackground(SkColorSetRGB(r, g, b));
......
...@@ -179,8 +179,7 @@ TrayBubbleView::InitParams::InitParams(AnchorAlignment anchor_alignment, ...@@ -179,8 +179,7 @@ TrayBubbleView::InitParams::InitParams(AnchorAlignment anchor_alignment,
max_width(max_width), max_width(max_width),
max_height(0), max_height(0),
can_activate(false), can_activate(false),
close_on_deactivate(true), close_on_deactivate(true) {}
bg_color(gfx::kPlaceholderColor) {}
TrayBubbleView::InitParams::InitParams(const InitParams& other) = default; TrayBubbleView::InitParams::InitParams(const InitParams& other) = default;
...@@ -200,12 +199,14 @@ TrayBubbleView::TrayBubbleView(View* anchor, ...@@ -200,12 +199,14 @@ TrayBubbleView::TrayBubbleView(View* anchor,
layout_(new BottomAlignedBoxLayout(this)), layout_(new BottomAlignedBoxLayout(this)),
delegate_(delegate), delegate_(delegate),
preferred_width_(init_params.min_width), preferred_width_(init_params.min_width),
bubble_border_(new BubbleBorder(arrow(), bubble_border_(new BubbleBorder(
BubbleBorder::NO_ASSETS, arrow(),
init_params.bg_color)), BubbleBorder::NO_ASSETS,
init_params.bg_color.value_or(gfx::kPlaceholderColor))),
owned_bubble_border_(bubble_border_), owned_bubble_border_(bubble_border_),
is_gesture_dragging_(false), is_gesture_dragging_(false),
mouse_actively_entered_(false) { mouse_actively_entered_(false) {
bubble_border_->set_use_theme_background_color(!init_params.bg_color);
bubble_border_->set_alignment(BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); bubble_border_->set_alignment(BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE);
bubble_border_->set_paint_arrow(BubbleBorder::PAINT_NONE); bubble_border_->set_paint_arrow(BubbleBorder::PAINT_NONE);
set_can_activate(params_.can_activate); set_can_activate(params_.can_activate);
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <memory> #include <memory>
#include "base/macros.h" #include "base/macros.h"
#include "base/optional.h"
#include "ui/views/bubble/bubble_dialog_delegate.h" #include "ui/views/bubble/bubble_dialog_delegate.h"
#include "ui/views/mouse_watcher.h" #include "ui/views/mouse_watcher.h"
#include "ui/views/views_export.h" #include "ui/views/views_export.h"
...@@ -83,7 +84,8 @@ class VIEWS_EXPORT TrayBubbleView : public BubbleDialogDelegateView, ...@@ -83,7 +84,8 @@ class VIEWS_EXPORT TrayBubbleView : public BubbleDialogDelegateView,
int max_height; int max_height;
bool can_activate; bool can_activate;
bool close_on_deactivate; bool close_on_deactivate;
SkColor bg_color; // If not provided, the bg color will be derived from the NativeTheme.
base::Optional<SkColor> bg_color;
}; };
// Constructs and returns a TrayBubbleView. |init_params| may be modified. // Constructs and returns a TrayBubbleView. |init_params| may be modified.
......
...@@ -2136,6 +2136,8 @@ void View::PropagateNativeThemeChanged(const ui::NativeTheme* theme) { ...@@ -2136,6 +2136,8 @@ void View::PropagateNativeThemeChanged(const ui::NativeTheme* theme) {
child->PropagateNativeThemeChanged(theme); child->PropagateNativeThemeChanged(theme);
} }
OnNativeThemeChanged(theme); OnNativeThemeChanged(theme);
for (ViewObserver& observer : observers_)
observer.OnViewNativeThemeChanged(this);
} }
// Size and disposition -------------------------------------------------------- // Size and disposition --------------------------------------------------------
......
...@@ -35,6 +35,9 @@ class VIEWS_EXPORT ViewObserver { ...@@ -35,6 +35,9 @@ class VIEWS_EXPORT ViewObserver {
// View::ReorderChildView() is called on |observed_view|. // View::ReorderChildView() is called on |observed_view|.
virtual void OnChildViewReordered(View* observed_view, View* child) {} virtual void OnChildViewReordered(View* observed_view, View* child) {}
// Called when the active NativeTheme has changed for |observed_view|.
virtual void OnViewNativeThemeChanged(View* observed_view) {}
// Called from ~View. // Called from ~View.
virtual void OnViewIsDeleting(View* observed_view) {} virtual void OnViewIsDeleting(View* observed_view) {}
......
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