diff options
-rw-r--r-- | ui/gfx/native_theme_win.cc | 68 | ||||
-rw-r--r-- | ui/gfx/native_theme_win.h | 3 | ||||
-rw-r--r-- | views/controls/button/checkbox.cc | 1 | ||||
-rw-r--r-- | views/controls/button/text_button.cc | 12 | ||||
-rw-r--r-- | views/examples/native_theme_button_example.cc | 9 |
5 files changed, 77 insertions, 16 deletions
diff --git a/ui/gfx/native_theme_win.cc b/ui/gfx/native_theme_win.cc index b0f8a47..29e1faf 100644 --- a/ui/gfx/native_theme_win.cc +++ b/ui/gfx/native_theme_win.cc @@ -126,7 +126,26 @@ gfx::Size NativeThemeWin::GetPartSize(Part part, NULL, TS_TRUE, &size); ReleaseDC(NULL, hdc); - return SUCCEEDED(hr) ? Size(size.cx, size.cy) : Size(); + if (FAILED(hr)) { + // TODO(rogerta): For now, we need to support radio buttons and checkboxes + // when theming is not enabled. Support for other parts can be added + // if/when needed. + switch (part) { + case kCheckbox: + case kRadio: + // TODO(rogerta): I was not able to find any API to get the default + // size of these controls, so determined these values empirically. + size.cx = 13; + size.cy = 13; + break; + default: + size.cx = 0; + size.cy = 0; + break; + } + } + + return Size(size.cx, size.cy); } void NativeThemeWin::PaintToNonPlatformCanvas(SkCanvas* canvas, @@ -497,8 +516,7 @@ HRESULT NativeThemeWin::PaintPushButton(HDC hdc, } RECT rect_win = rect.ToRECT(); - return PaintButton(hdc, BP_PUSHBUTTON, state_id, extra.classic_state, - &rect_win); + return PaintButton(hdc, state, extra, BP_PUSHBUTTON, state_id, &rect_win); } HRESULT NativeThemeWin::PaintRadioButton(HDC hdc, @@ -526,8 +544,7 @@ HRESULT NativeThemeWin::PaintRadioButton(HDC hdc, } RECT rect_win = rect.ToRECT(); - return PaintButton(hdc, BP_RADIOBUTTON, state_id, extra.classic_state, - &rect_win); + return PaintButton(hdc, state, extra, BP_RADIOBUTTON, state_id, &rect_win); } HRESULT NativeThemeWin::PaintCheckbox(HDC hdc, @@ -563,19 +580,54 @@ HRESULT NativeThemeWin::PaintCheckbox(HDC hdc, } RECT rect_win = rect.ToRECT(); - return PaintButton(hdc, BP_CHECKBOX, state_id, extra.classic_state, - &rect_win); + return PaintButton(hdc, state, extra, BP_CHECKBOX, state_id, &rect_win); } HRESULT NativeThemeWin::PaintButton(HDC hdc, + State state, + const ButtonExtraParams& extra, int part_id, int state_id, - int classic_state, RECT* rect) const { HANDLE handle = GetThemeHandle(BUTTON); if (handle && draw_theme_) return draw_theme_(handle, hdc, part_id, state_id, rect, NULL); + // Adjust classic_state based on part, state, and extras. + int classic_state = extra.classic_state; + switch(part_id) { + case BP_CHECKBOX: + classic_state |= DFCS_BUTTONCHECK; + break; + case BP_RADIOBUTTON: + classic_state |= DFCS_BUTTONRADIO; + break; + case BP_PUSHBUTTON: + classic_state |= DFCS_BUTTONPUSH; + break; + default: + NOTREACHED() << "Unknown part_id: " << part_id; + break; + } + + switch(state) { + case kDisabled: + classic_state |= DFCS_INACTIVE; + break; + case kPressed: + classic_state |= DFCS_PUSHED; + break; + case kNormal: + case kHovered: + break; + default: + NOTREACHED() << "Unknown state: " << state; + break; + } + + if (extra.checked) + classic_state |= DFCS_CHECKED; + // Draw it manually. // All pressed states have both low bits set, and no other states do. const bool focused = ((state_id & ETS_FOCUSED) == ETS_FOCUSED); diff --git a/ui/gfx/native_theme_win.h b/ui/gfx/native_theme_win.h index 61420a5..9df8ec8 100644 --- a/ui/gfx/native_theme_win.h +++ b/ui/gfx/native_theme_win.h @@ -124,9 +124,10 @@ class NativeThemeWin : public NativeTheme { SIZE* size) const; HRESULT PaintButton(HDC hdc, + State state, + const ButtonExtraParams& extra, int part_id, int state_id, - int classic_state, RECT* rect) const; HRESULT PaintMenuSeparator(HDC hdc, diff --git a/views/controls/button/checkbox.cc b/views/controls/button/checkbox.cc index fe33428..91e7f79 100644 --- a/views/controls/button/checkbox.cc +++ b/views/controls/button/checkbox.cc @@ -300,7 +300,6 @@ gfx::Rect Checkbox::GetThemePaintRect() const { void Checkbox::GetExtraParams(gfx::NativeTheme::ExtraParams* params) const { TextButtonBase::GetExtraParams(params); - params->button.is_default = false; params->button.checked = checked_; } diff --git a/views/controls/button/text_button.cc b/views/controls/button/text_button.cc index f85a887..5ad963b 100644 --- a/views/controls/button/text_button.cc +++ b/views/controls/button/text_button.cc @@ -17,6 +17,7 @@ #include "views/widget/widget.h" #if defined(OS_WIN) +#include "ui/gfx/native_theme_win.h" #include "ui/gfx/platform_font_win.h" #endif @@ -607,7 +608,12 @@ gfx::NativeTheme::State TextButtonBase::GetThemeState( } const ui::Animation* TextButtonBase::GetThemeAnimation() const { +#if defined(OS_WIN) + return gfx::NativeThemeWin::instance()->IsThemingActive() + ? hover_animation_.get() : NULL; +#else return hover_animation_.get(); +#endif } gfx::NativeTheme::State TextButtonBase::GetBackgroundThemeState( @@ -726,12 +732,8 @@ gfx::NativeTheme::Part TextButton::GetThemePart() const { } void TextButton::GetExtraParams(gfx::NativeTheme::ExtraParams* params) const { - params->button.checked = false; - params->button.indeterminate = false; + TextButtonBase::GetExtraParams(params); params->button.is_default = is_default_; - params->button.has_border = false; - params->button.classic_state = 0; - params->button.background_color = kEnabledColor; } gfx::Rect TextButton::GetTextBounds() const { diff --git a/views/examples/native_theme_button_example.cc b/views/examples/native_theme_button_example.cc index 7810b04..1b20281 100644 --- a/views/examples/native_theme_button_example.cc +++ b/views/examples/native_theme_button_example.cc @@ -137,7 +137,14 @@ gfx::NativeTheme::Part ExampleNativeThemeButton::GetThemePart() const { } gfx::Rect ExampleNativeThemeButton::GetThemePaintRect() const { - return GetLocalBounds(); + gfx::NativeTheme::ExtraParams extra; + gfx::NativeTheme::State state = GetThemeState(&extra); + gfx::Size size(gfx::NativeTheme::instance()->GetPartSize(GetThemePart(), + state, + extra)); + gfx::Rect rect(size); + rect.set_x(GetMirroredXForRect(rect)); + return rect; } gfx::NativeTheme::State ExampleNativeThemeButton::GetThemeState( |