Commit 700f8aa8 authored by estade@chromium.org's avatar estade@chromium.org

views: Make sure menu checks and submenu arrows have high contrast even when selected.

BUG=298398

Review URL: https://codereview.chromium.org/25144002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@226416 0039d316-1c4b-4281-b951-d872f2087c98
parent fa8acde7
...@@ -240,6 +240,7 @@ ...@@ -240,6 +240,7 @@
</if> </if>
<if expr="pp_ifdef('toolkit_views')"> <if expr="pp_ifdef('toolkit_views')">
<structure type="chrome_scaled_image" name="IDR_MENU_HIERARCHY_ARROW" file="common/menu_hierarchy_arrow.png" /> <structure type="chrome_scaled_image" name="IDR_MENU_HIERARCHY_ARROW" file="common/menu_hierarchy_arrow.png" />
<structure type="chrome_scaled_image" name="IDR_MENU_HIERARCHY_ARROW_DARK_BACKGROUND" file="common/menu_hierarchy_arrow_white.png" />
</if> </if>
<if expr="is_macosx or is_ios"> <if expr="is_macosx or is_ios">
<structure type="chrome_scaled_image" name="IDR_MENU_HIERARCHY_ARROW" file="mac/menu_hierarchy_arrow.png" /> <structure type="chrome_scaled_image" name="IDR_MENU_HIERARCHY_ARROW" file="mac/menu_hierarchy_arrow.png" />
...@@ -247,6 +248,7 @@ ...@@ -247,6 +248,7 @@
<if expr="pp_ifdef('toolkit_views')"> <if expr="pp_ifdef('toolkit_views')">
<structure type="chrome_scaled_image" name="IDR_MENU_CHECK" file="cros/menu_check.png" /> <structure type="chrome_scaled_image" name="IDR_MENU_CHECK" file="cros/menu_check.png" />
<structure type="chrome_scaled_image" name="IDR_MENU_CHECK_CHECKED" file="common/menu_check.png" /> <structure type="chrome_scaled_image" name="IDR_MENU_CHECK_CHECKED" file="common/menu_check.png" />
<structure type="chrome_scaled_image" name="IDR_MENU_CHECK_CHECKED_DARK_BACKGROUND" file="common/menu_check_white.png" />
<structure type="chrome_scaled_image" name="IDR_MENU_RADIO_EMPTY" file="common/menu_radio_empty.png" /> <structure type="chrome_scaled_image" name="IDR_MENU_RADIO_EMPTY" file="common/menu_radio_empty.png" />
<structure type="chrome_scaled_image" name="IDR_MENU_RADIO_SELECTED" file="common/menu_radio_selected.png" /> <structure type="chrome_scaled_image" name="IDR_MENU_RADIO_SELECTED" file="common/menu_radio_selected.png" />
<structure type="chrome_scaled_image" name="IDR_SLIDER_ACTIVE_LEFT" file="slider_left_active.png" /> <structure type="chrome_scaled_image" name="IDR_SLIDER_ACTIVE_LEFT" file="slider_left_active.png" />
......
...@@ -32,12 +32,12 @@ void MenuConfig::InitAura(const ui::NativeTheme* theme) { ...@@ -32,12 +32,12 @@ void MenuConfig::InitAura(const ui::NativeTheme* theme) {
text_color = theme->GetSystemColor( text_color = theme->GetSystemColor(
ui::NativeTheme::kColorId_EnabledMenuItemForegroundColor); ui::NativeTheme::kColorId_EnabledMenuItemForegroundColor);
submenu_horizontal_inset = 1; submenu_horizontal_inset = 1;
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
arrow_to_edge_padding = 20; arrow_to_edge_padding = 20;
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
arrow_width = arrow_width =
rb.GetImageNamed(IDR_MENU_HIERARCHY_ARROW).ToImageSkia()->width(); rb.GetImageNamed(IDR_MENU_HIERARCHY_ARROW).ToImageSkia()->width();
const gfx::ImageSkia* check = GetMenuCheckImage(); gfx::ImageSkia check = GetMenuCheckImage(false);
check_height = check->height(); check_height = check.height();
item_min_height = 29; item_min_height = 29;
separator_spacing_height = 7; separator_spacing_height = 7;
separator_lower_height = 8; separator_lower_height = 8;
......
...@@ -105,15 +105,15 @@ gfx::ImageSkia* CreateRadioButtonImage(bool selected) { ...@@ -105,15 +105,15 @@ gfx::ImageSkia* CreateRadioButtonImage(bool selected) {
class SubmenuArrowImageSource : public gfx::CanvasImageSource { class SubmenuArrowImageSource : public gfx::CanvasImageSource {
public: public:
SubmenuArrowImageSource() SubmenuArrowImageSource(int image_id)
: gfx::CanvasImageSource(GetSubmenuArrowSize(), false) { : gfx::CanvasImageSource(ui::ResourceBundle::GetSharedInstance().
} GetImageNamed(image_id).ToImageSkia()->size(), false),
image_id_(image_id) {}
virtual ~SubmenuArrowImageSource() {} virtual ~SubmenuArrowImageSource() {}
virtual void Draw(gfx::Canvas* canvas) OVERRIDE { virtual void Draw(gfx::Canvas* canvas) OVERRIDE {
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
const gfx::ImageSkia* r = const gfx::ImageSkia* r = rb.GetImageNamed(image_id_).ToImageSkia();
rb.GetImageNamed(IDR_MENU_HIERARCHY_ARROW).ToImageSkia();
canvas->Scale(-1, 1); canvas->Scale(-1, 1);
canvas->DrawImageInt(*r, - r->width(), 0); canvas->DrawImageInt(*r, - r->width(), 0);
} }
...@@ -124,38 +124,52 @@ class SubmenuArrowImageSource : public gfx::CanvasImageSource { ...@@ -124,38 +124,52 @@ class SubmenuArrowImageSource : public gfx::CanvasImageSource {
.GetImageNamed(IDR_MENU_HIERARCHY_ARROW).ToImageSkia()->size(); .GetImageNamed(IDR_MENU_HIERARCHY_ARROW).ToImageSkia()->size();
} }
int image_id_;
DISALLOW_COPY_AND_ASSIGN(SubmenuArrowImageSource); DISALLOW_COPY_AND_ASSIGN(SubmenuArrowImageSource);
}; };
gfx::ImageSkia* GetRtlSubmenuArrowImage() { gfx::ImageSkia GetRtlSubmenuArrowImage(bool rtl,
bool dark_background) {
int image_id = dark_background ? IDR_MENU_HIERARCHY_ARROW_DARK_BACKGROUND :
IDR_MENU_HIERARCHY_ARROW;
if (!rtl) {
return ui::ResourceBundle::GetSharedInstance().GetImageNamed(image_id).
AsImageSkia();
}
static gfx::ImageSkia* kRtlArrow = NULL; static gfx::ImageSkia* kRtlArrow = NULL;
if (!kRtlArrow) { static gfx::ImageSkia* kRtlArrowDarkBg = NULL;
SubmenuArrowImageSource* source = new SubmenuArrowImageSource(); gfx::ImageSkia** image = dark_background ? &kRtlArrowDarkBg : &kRtlArrow;
kRtlArrow = new gfx::ImageSkia(source, source->size());
if (!*image) {
SubmenuArrowImageSource* source = new SubmenuArrowImageSource(image_id);
*image = new gfx::ImageSkia(source, source->size());
} }
return kRtlArrow;
return **image;
} }
} // namespace } // namespace
namespace views { namespace views {
const gfx::ImageSkia* GetMenuCheckImage() { gfx::ImageSkia GetMenuCheckImage(bool dark_background) {
return ui::ResourceBundle::GetSharedInstance().GetImageNamed( int image_id = dark_background ? IDR_MENU_CHECK_CHECKED_DARK_BACKGROUND :
IDR_MENU_CHECK_CHECKED).ToImageSkia(); IDR_MENU_CHECK_CHECKED;
return ui::ResourceBundle::GetSharedInstance().GetImageNamed(image_id).
AsImageSkia();
} }
const gfx::ImageSkia* GetRadioButtonImage(bool selected) { gfx::ImageSkia GetRadioButtonImage(bool selected) {
int image_id = selected ? IDR_MENU_RADIO_SELECTED : IDR_MENU_RADIO_EMPTY; int image_id = selected ? IDR_MENU_RADIO_SELECTED : IDR_MENU_RADIO_EMPTY;
return ui::ResourceBundle::GetSharedInstance().GetImageNamed( return ui::ResourceBundle::GetSharedInstance().GetImageNamed(image_id).
image_id).ToImageSkia(); AsImageSkia();
} }
const gfx::ImageSkia* GetSubmenuArrowImage() { gfx::ImageSkia GetSubmenuArrowImage(bool dark_background) {
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); return GetRtlSubmenuArrowImage(base::i18n::IsRTL(), dark_background);
return base::i18n::IsRTL()
? GetRtlSubmenuArrowImage()
: rb.GetImageNamed(IDR_MENU_HIERARCHY_ARROW).ToImageSkia();
} }
} // namespace views } // namespace views
...@@ -13,16 +13,20 @@ namespace views { ...@@ -13,16 +13,20 @@ namespace views {
// Returns the Menu Check box image (always checked). // Returns the Menu Check box image (always checked).
// The returned image is global object and should not be freed. // The returned image is global object and should not be freed.
const gfx::ImageSkia* GetMenuCheckImage(); // |dark_background| should be true if the check will be displayed on a
// dark background (such as a hovered menu item).
gfx::ImageSkia GetMenuCheckImage(bool dark_background);
// Return the RadioButton image for given state. // Return the RadioButton image for given state.
// It returns the "selected" image when |selected| is // It returns the "selected" image when |selected| is
// true, or the "unselected" image if false. // true, or the "unselected" image if false.
// The returned image is global object and should not be freed. // The returned image is global object and should not be freed.
const gfx::ImageSkia* GetRadioButtonImage(bool selected); gfx::ImageSkia GetRadioButtonImage(bool selected);
// Returns the image for submenu arrow for current RTL setting. // Returns the image for submenu arrow for current RTL setting.
const gfx::ImageSkia* GetSubmenuArrowImage(); // |dark_background| should be true if the check will be displayed on a
// dark background (such as a hovered menu item).
gfx::ImageSkia GetSubmenuArrowImage(bool dark_background);
} // namespace views } // namespace views
......
...@@ -768,23 +768,23 @@ void MenuItemView::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) { ...@@ -768,23 +768,23 @@ void MenuItemView::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) {
// Render the check. // Render the check.
if (type_ == CHECKBOX && delegate->IsItemChecked(GetCommand())) { if (type_ == CHECKBOX && delegate->IsItemChecked(GetCommand())) {
const gfx::ImageSkia* check = GetMenuCheckImage(); gfx::ImageSkia check = GetMenuCheckImage(IsSelected());
// Don't use config.check_width here as it's padded // Don't use config.check_width here as it's padded
// to force more padding (AURA). // to force more padding (AURA).
gfx::Rect check_bounds(icon_x, icon_y, check->width(), icon_height); gfx::Rect check_bounds(icon_x, icon_y, check.width(), icon_height);
AdjustBoundsForRTLUI(&check_bounds); AdjustBoundsForRTLUI(&check_bounds);
canvas->DrawImageInt(*check, check_bounds.x(), check_bounds.y()); canvas->DrawImageInt(check, check_bounds.x(), check_bounds.y());
} else if (type_ == RADIO) { } else if (type_ == RADIO) {
const gfx::ImageSkia* image = gfx::ImageSkia image =
GetRadioButtonImage(delegate->IsItemChecked(GetCommand())); GetRadioButtonImage(delegate->IsItemChecked(GetCommand()));
gfx::Rect radio_bounds(icon_x, gfx::Rect radio_bounds(icon_x,
top_margin + top_margin +
(height() - top_margin - bottom_margin - (height() - top_margin - bottom_margin -
image->height()) / 2, image.height()) / 2,
image->width(), image.width(),
image->height()); image.height());
AdjustBoundsForRTLUI(&radio_bounds); AdjustBoundsForRTLUI(&radio_bounds);
canvas->DrawImageInt(*image, radio_bounds.x(), radio_bounds.y()); canvas->DrawImageInt(image, radio_bounds.x(), radio_bounds.y());
} }
// Render the foreground. // Render the foreground.
...@@ -843,7 +843,7 @@ void MenuItemView::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) { ...@@ -843,7 +843,7 @@ void MenuItemView::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) {
config.arrow_width) / 2, config.arrow_width) / 2,
config.arrow_width, height()); config.arrow_width, height());
AdjustBoundsForRTLUI(&arrow_bounds); AdjustBoundsForRTLUI(&arrow_bounds);
canvas->DrawImageInt(*GetSubmenuArrowImage(), canvas->DrawImageInt(GetSubmenuArrowImage(IsSelected()),
arrow_bounds.x(), arrow_bounds.y()); arrow_bounds.x(), arrow_bounds.y());
} }
} }
......
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