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