Skip to content

Commit

Permalink
MacViews: draw Mac combobox arrows
Browse files Browse the repository at this point in the history
This CL adds Mac-specific combobox arrow drawing code to NativeThemeMac.

BUG=543683
TEST=adhoc
Build views_examples_with_content_exe and look at the Combobox page.

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

Cr-Commit-Position: refs/heads/master@{#385759}
  • Loading branch information
ellyjones authored and Commit bot committed Apr 7, 2016
1 parent dd6297e commit 0cdd649
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 82 deletions.
4 changes: 4 additions & 0 deletions ui/gfx/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,10 @@ action("aggregate_vector_icons") {
"--output_cc=" + rebase_path(vector_icons_cc_file, root_build_dir),
"--output_h=" + rebase_path(vector_icons_h_file, root_build_dir),
]

if (is_mac) {
sources += [ "vector_icons/combobox_arrow_mac.icon" ]
}
}

# Looking for gfx_geometry? It's //ui/gfx/geometry:geometry
Expand Down
13 changes: 13 additions & 0 deletions ui/gfx/vector_icons/combobox_arrow_mac.icon
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

CANVAS_DIMENSIONS, 32,
STROKE, 4,
MOVE_TO, 8, 10,
LINE_TO, 16, 2,
LINE_TO, 24, 10,
MOVE_TO, 8, 22,
LINE_TO, 16, 30,
LINE_TO, 24, 22,
END
22 changes: 0 additions & 22 deletions ui/native_theme/common_theme.cc
Original file line number Diff line number Diff line change
Expand Up @@ -405,28 +405,6 @@ SkColor GetAuraColor(NativeTheme::ColorId color_id,
return gfx::kPlaceholderColor;
}

gfx::Size CommonThemeGetPartSize(NativeTheme::Part part,
NativeTheme::State state,
const NativeTheme::ExtraParams& extra) {
gfx::Size size;
switch (part) {
case NativeTheme::kComboboxArrow:
return ui::ResourceBundle::GetSharedInstance().GetImageNamed(
IDR_MENU_DROPARROW).Size();

default:
break;
}

return size;
}

void CommonThemePaintComboboxArrow(SkCanvas* canvas, const gfx::Rect& rect) {
gfx::ImageSkia* arrow = ui::ResourceBundle::GetSharedInstance().
GetImageSkiaNamed(IDR_MENU_DROPARROW);
CommonThemeCreateCanvas(canvas)->DrawImageInt(*arrow, rect.x(), rect.y());
}

void CommonThemePaintMenuItemBackground(
const NativeTheme* theme,
SkCanvas* canvas,
Expand Down
9 changes: 0 additions & 9 deletions ui/native_theme/common_theme.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,6 @@ namespace ui {
SkColor NATIVE_THEME_EXPORT GetAuraColor(NativeTheme::ColorId color_id,
const NativeTheme* base_theme);

gfx::Size NATIVE_THEME_EXPORT CommonThemeGetPartSize(
NativeTheme::Part part,
NativeTheme::State state,
const NativeTheme::ExtraParams& extra);

void NATIVE_THEME_EXPORT CommonThemePaintComboboxArrow(
SkCanvas* canvas,
const gfx::Rect& rect);

void NATIVE_THEME_EXPORT CommonThemePaintMenuItemBackground(
const NativeTheme* theme,
SkCanvas* canvas,
Expand Down
1 change: 0 additions & 1 deletion ui/native_theme/native_theme.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class NATIVE_THEME_EXPORT NativeTheme {
public:
// The part to be painted / sized.
enum Part {
kComboboxArrow,
kCheckbox,
kInnerSpinButton,
kMenuList,
Expand Down
4 changes: 0 additions & 4 deletions ui/native_theme/native_theme_aurawin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ void NativeThemeAuraWin::Paint(SkCanvas* canvas,
gfx::Size NativeThemeAuraWin::GetPartSize(Part part,
State state,
const ExtraParams& extra) const {
gfx::Size part_size = CommonThemeGetPartSize(part, state, extra);
if (!part_size.IsEmpty())
return part_size;

// We want aura on windows to use the same size for scrollbars as we would in
// the native theme.
if (IsScrollbarPart(part))
Expand Down
7 changes: 0 additions & 7 deletions ui/native_theme/native_theme_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,6 @@ namespace ui {
gfx::Size NativeThemeBase::GetPartSize(Part part,
State state,
const ExtraParams& extra) const {
gfx::Size size = CommonThemeGetPartSize(part, state, extra);
if (!size.IsEmpty())
return size;

switch (part) {
// Please keep these in the order of NativeTheme::Part.
case kCheckbox:
Expand Down Expand Up @@ -197,9 +193,6 @@ void NativeThemeBase::Paint(SkCanvas* canvas,

switch (part) {
// Please keep these in the order of NativeTheme::Part.
case kComboboxArrow:
CommonThemePaintComboboxArrow(canvas, rect);
break;
case kCheckbox:
PaintCheckbox(canvas, state, rect, extra.button);
break;
Expand Down
11 changes: 0 additions & 11 deletions ui/native_theme/native_theme_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,6 @@ NativeThemeWin* NativeThemeWin::instance() {
gfx::Size NativeThemeWin::GetPartSize(Part part,
State state,
const ExtraParams& extra) const {
gfx::Size part_size = CommonThemeGetPartSize(part, state, extra);
if (!part_size.IsEmpty())
return part_size;

// The GetThemePartSize call below returns the default size without
// accounting for user customization (crbug/218291).
switch (part) {
Expand Down Expand Up @@ -242,9 +238,6 @@ void NativeThemeWin::Paint(SkCanvas* canvas,
return;

switch (part) {
case kComboboxArrow:
CommonThemePaintComboboxArrow(canvas, rect);
return;
case kMenuPopupGutter:
PaintMenuGutter(canvas, rect);
return;
Expand Down Expand Up @@ -464,7 +457,6 @@ void NativeThemeWin::PaintDirect(SkCanvas* canvas,
case kWindowResizeGripper:
PaintWindowResizeGripper(hdc, rect);
return;
case kComboboxArrow:
case kSliderTrack:
case kSliderThumb:
case kMaxPart:
Expand Down Expand Up @@ -1708,7 +1700,6 @@ NativeThemeWin::ThemeName NativeThemeWin::GetThemeName(Part part) {
return TEXTFIELD;
case kWindowResizeGripper:
return STATUS;
case kComboboxArrow:
case kMenuCheckBackground:
case kMenuPopupBackground:
case kMenuItemBackground:
Expand Down Expand Up @@ -1754,7 +1745,6 @@ int NativeThemeWin::GetWindowsPart(Part part,
return SBP_THUMBBTNVERT;
case kWindowResizeGripper:
return SP_GRIPPER;
case kComboboxArrow:
case kInnerSpinButton:
case kMenuList:
case kMenuCheckBackground:
Expand Down Expand Up @@ -1948,7 +1938,6 @@ int NativeThemeWin::GetWindowsState(Part part,
NOTREACHED();
return 0;
}
case kComboboxArrow:
case kInnerSpinButton:
case kMenuList:
case kMenuCheckBackground:
Expand Down
32 changes: 4 additions & 28 deletions ui/views/controls/combobox/combobox.cc
Original file line number Diff line number Diff line change
Expand Up @@ -752,19 +752,9 @@ void Combobox::PaintText(gfx::Canvas* canvas) {
arrow_size.height());
AdjustBoundsForRTLUI(&arrow_bounds);

// TODO(estade): hack alert! Remove this direct call into CommonTheme. For now
// STYLE_ACTION isn't properly themed so we have to override the NativeTheme
// behavior. See crbug.com/384071
if (style_ == STYLE_ACTION) {
ui::CommonThemePaintComboboxArrow(canvas->sk_canvas(), arrow_bounds);
} else {
ui::NativeTheme::ExtraParams ignored;
GetNativeTheme()->Paint(canvas->sk_canvas(),
ui::NativeTheme::kComboboxArrow,
ui::NativeTheme::kNormal,
arrow_bounds,
ignored);
}
gfx::ImageSkia arrow_image = PlatformStyle::CreateComboboxArrow(
enabled(), style_);
canvas->DrawImageInt(arrow_image, arrow_bounds.x(), arrow_bounds.y());
}

void Combobox::PaintButtons(gfx::Canvas* canvas) {
Expand Down Expand Up @@ -905,21 +895,7 @@ int Combobox::GetDisclosureArrowRightPadding() const {
}

gfx::Size Combobox::ArrowSize() const {
#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
// TODO(estade): hack alert! This should always use GetNativeTheme(). For now
// STYLE_ACTION isn't properly themed so we have to override the NativeTheme
// behavior. See crbug.com/384071
const ui::NativeTheme* native_theme_for_arrow =
style_ == STYLE_ACTION ? ui::NativeThemeAura::instance()
: GetNativeTheme();
#else
const ui::NativeTheme* native_theme_for_arrow = GetNativeTheme();
#endif

ui::NativeTheme::ExtraParams ignored;
return native_theme_for_arrow->GetPartSize(ui::NativeTheme::kComboboxArrow,
ui::NativeTheme::kNormal,
ignored);
return PlatformStyle::CreateComboboxArrow(enabled(), style_).size();
}

gfx::Size Combobox::GetContentSize() const {
Expand Down
9 changes: 9 additions & 0 deletions ui/views/style/platform_style.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include "build/build_config.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/resources/grit/ui_resources.h"
#include "ui/views/background.h"
#include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/button/label_button_border.h"
Expand All @@ -16,6 +18,13 @@ namespace views {

#if !defined(OS_MACOSX)

// static
gfx::ImageSkia PlatformStyle::CreateComboboxArrow(bool is_enabled,
Combobox::Style style) {
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
return *rb.GetImageSkiaNamed(IDR_MENU_DROPARROW);
}

// static
scoped_ptr<FocusableBorder> PlatformStyle::CreateComboboxBorder() {
return make_scoped_ptr(new FocusableBorder());
Expand Down
8 changes: 8 additions & 0 deletions ui/views/style/platform_style.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/combobox/combobox.h"

namespace views {

Expand All @@ -20,6 +21,13 @@ class ScrollBar;
// Cross-platform API for providing platform-specific styling for toolkit-views.
class PlatformStyle {
public:
// Creates an ImageSkia containing the image to use for the combobox arrow.
// The |is_enabled| argument is true if the control the arrow is for is
// enabled, and false if the control is disabled. The |style| argument is the
// style of the combobox the arrow is being drawn for.
static gfx::ImageSkia CreateComboboxArrow(bool is_enabled,
Combobox::Style style);

// Creates the appropriate border for a focusable Combobox.
static scoped_ptr<FocusableBorder> CreateComboboxBorder();

Expand Down
19 changes: 19 additions & 0 deletions ui/views/style/platform_style_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

#include "ui/views/style/platform_style.h"

#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/gfx/vector_icons.h"
#include "ui/resources/grit/ui_resources.h"
#include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/button/label_button_border.h"
#include "ui/views/controls/focusable_rounded_border_mac.h"
Expand All @@ -13,6 +17,21 @@

namespace views {

// static
gfx::ImageSkia PlatformStyle::CreateComboboxArrow(bool is_enabled,
Combobox::Style style) {
// TODO(ellyjones): IDR_MENU_DROPARROW is a cross-platform image that doesn't
// look right on Mac. See https://crbug.com/384071.
if (style == Combobox::STYLE_ACTION) {
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
return *rb.GetImageSkiaNamed(IDR_MENU_DROPARROW);
}
const int kComboboxArrowWidth = 13;
return gfx::CreateVectorIcon(gfx::VectorIconId::COMBOBOX_ARROW_MAC,
kComboboxArrowWidth,
is_enabled ? SK_ColorWHITE : SK_ColorBLACK);
}

// static
scoped_ptr<FocusableBorder> PlatformStyle::CreateComboboxBorder() {
return make_scoped_ptr(new FocusableRoundedBorder);
Expand Down

0 comments on commit 0cdd649

Please sign in to comment.