Index: src/webkit/port/rendering/RenderThemeWin.cpp |
diff --git a/src/webkit/port/rendering/RenderThemeWin.cpp b/src/webkit/port/rendering/RenderThemeWin.cpp |
index 7176f75d7337d69f21e5559f1610dc21ac2413d9..0f17b9e797adfe87f57eb54d8e8034503d63dcb3 100644 |
--- a/src/webkit/port/rendering/RenderThemeWin.cpp |
+++ b/src/webkit/port/rendering/RenderThemeWin.cpp |
@@ -41,6 +41,8 @@ |
#include "base/gfx/skia_utils.h" |
#include "base/win_util.h" |
+namespace { |
+ |
// These enums correspond to similarly named values defined by SafariTheme.h |
enum ControlSize { |
RegularControlSize, |
@@ -55,59 +57,76 @@ enum PaddingType { |
LeftPadding |
}; |
-namespace { |
- const int kDefaultButtonPadding = 2; |
+const int kDefaultButtonPadding = 2; |
+ |
+// These magic numbers come from Apple's version of RenderThemeWin.cpp. |
+const int kMenuListPadding[4] = { 1, 2, 1, 2 }; |
+ |
+// The kLayoutTest* constants are metrics used only in layout test mode, |
+// so as to match RenderThemeMac.mm and to remain consistent despite any |
+// theme or font changes. |
+const int kLayoutTestControlHeight[3] = { 21, 18, 15 }; |
+const int kLayoutTestButtonPadding[4] = { 0, 8, 0, 8 }; |
+const int kLayoutTestStyledMenuListInternalPadding[4] = { 1, 0, 2, 8 }; |
+const int kLayoutTestMenuListInternalPadding[3][4] = |
+{ |
+ { 2, 26, 3, 8 }, |
+ { 2, 23, 3, 8 }, |
+ { 2, 22, 3, 10 } |
+}; |
+const int kLayoutTestMenuListMinimumWidth[3] = { 9, 5, 0 }; |
+const float kLayoutTestBaseFontSize = 11.0f; |
+const float kLayoutTestStatusBarFontSize = 10.0f; |
+const float kLayoutTestSystemFontSize = 13.0f; |
- // These magic numbers come from Apple's version of RenderThemeWin.cpp. |
- const int kMenuListPadding[4] = { 1, 2, 1, 2 }; |
+const int kLayoutTestSliderThumbWidth = 15; |
+const int kLayoutTestSliderThumbHeight = 15; |
- // The kLayoutTest* constants are metrics used only in layout test mode, |
- // so as to match RenderThemeMac.mm and to remain consistent despite any |
- // theme or font changes. |
- const int kLayoutTestControlHeight[3] = { 21, 18, 15 }; |
- const int kLayoutTestButtonPadding[4] = { 0, 8, 0, 8 }; |
- const int kLayoutTestStyledMenuListInternalPadding[4] = { 1, 0, 2, 8 }; |
- const int kLayoutTestMenuListInternalPadding[3][4] = |
- { |
- { 2, 26, 3, 8 }, |
- { 2, 23, 3, 8 }, |
- { 2, 22, 3, 10 } |
- }; |
- const int kLayoutTestMenuListMinimumWidth[3] = { 9, 5, 0 }; |
- const float kLayoutTestBaseFontSize = 11.0f; |
- const float kLayoutTestStatusBarFontSize = 10.0f; |
- const float kLayoutTestSystemFontSize = 13.0f; |
+const int kLayoutTestMenuListButtonWidth = 15; |
+const int kLayoutTestButtonMinHeight = 15; |
- const int kLayoutTestSliderThumbWidth = 15; |
- const int kLayoutTestSliderThumbHeight = 15; |
+const int kLayoutTestSearchFieldHeight[3] = { 22, 19, 17 }; |
+const int kLayoutTestEmptyResultsOffset = 9; |
+const int kLayoutTestResultsArrowWidth = 5; |
- const int kLayoutTestMenuListButtonWidth = 15; |
- const int kLayoutTestButtonMinHeight = 15; |
+const short kLayoutTestSearchFieldBorderWidth = 2; |
+const int kLayoutTestSearchFieldPadding = 1; |
- const int kLayoutTestSearchFieldHeight[3] = { 22, 19, 17 }; |
- const int kLayoutTestEmptyResultsOffset = 9; |
- const int kLayoutTestResultsArrowWidth = 5; |
+// Constants that are used in non-layout-test mode. |
+const int kStyledMenuListInternalPadding[4] = { 1, 4, 1, 4 }; |
- const short kLayoutTestSearchFieldBorderWidth = 2; |
- const int kLayoutTestSearchFieldPadding = 1; |
+// The default variable-width font size. We use this as the default font |
+// size for the "system font", and as a base size (which we then shrink) for |
+// form control fonts. |
+float DefaultFontSize = 16.0; |
+WebCore::FontDescription smallSystemFont; |
+WebCore::FontDescription menuFont; |
+WebCore::FontDescription labelFont; |
+} // namespace |
- // Constants that are used in non-layout-test mode. |
- const int kStyledMenuListInternalPadding[4] = { 1, 4, 1, 4 }; |
+namespace WebCore { |
- // The default variable-width font size. We use this as the default font |
- // size for the "system font", and as a base size (which we then shrink) for |
- // form control fonts. |
- float DefaultFontSize = 16.0; |
+// Internal static helper functions. We don't put them in an anonymous |
+// namespace so they have easier access to the WebCore namespace. |
+ |
+static bool supportsFocus(ControlPart appearance) |
+{ |
+ switch (appearance) { |
+ case PushButtonPart: |
+ case ButtonPart: |
+ case DefaultButtonPart: |
+ case TextFieldPart: |
+ case TextAreaPart: |
+ return true; |
+ default: |
+ return false; |
+ } |
- WebCore::FontDescription smallSystemFont; |
- WebCore::FontDescription menuFont; |
- WebCore::FontDescription labelFont; |
+ return false; |
} |
-namespace WebCore { |
- |
static void setFixedPadding(RenderStyle* style, const int padding[4]) |
{ |
style->setPaddingLeft(Length(padding[LeftPadding], Fixed)); |
@@ -127,53 +146,10 @@ static ControlSize controlSizeForFont(RenderStyle* style) |
return MiniControlSize; |
} |
-RenderTheme* theme() |
-{ |
- static RenderThemeWin winTheme; |
- return &winTheme; |
-} |
- |
-RenderThemeWin::RenderThemeWin() |
-{ |
-} |
- |
-RenderThemeWin::~RenderThemeWin() |
-{ |
-} |
- |
-Color RenderThemeWin::platformActiveSelectionBackgroundColor() const |
-{ |
- if (ChromiumBridge::layoutTestMode()) |
- return Color("#0000FF"); // Royal blue |
- COLORREF color = GetSysColor(COLOR_HIGHLIGHT); |
- return Color(GetRValue(color), GetGValue(color), GetBValue(color), 255); |
-} |
- |
-Color RenderThemeWin::platformInactiveSelectionBackgroundColor() const |
-{ |
- if (ChromiumBridge::layoutTestMode()) |
- return Color("#999999"); // Medium grey |
- COLORREF color = GetSysColor(COLOR_GRAYTEXT); |
- return Color(GetRValue(color), GetGValue(color), GetBValue(color), 255); |
-} |
- |
-Color RenderThemeWin::platformActiveSelectionForegroundColor() const |
-{ |
- if (ChromiumBridge::layoutTestMode()) |
- return Color("#FFFFCC"); // Pale yellow |
- COLORREF color = GetSysColor(COLOR_HIGHLIGHTTEXT); |
- return Color(GetRValue(color), GetGValue(color), GetBValue(color), 255); |
-} |
- |
-Color RenderThemeWin::platformInactiveSelectionForegroundColor() const |
-{ |
- return Color::white; |
-} |
- |
static float systemFontSizeForControlSize(ControlSize controlSize) |
{ |
static float sizes[] = { 13.0f, 11.0f, 9.0f }; |
- |
+ |
return sizes[controlSize]; |
} |
@@ -189,7 +165,7 @@ static int layoutTestSetFontFromControlSize(CSSStyleSelector* selector, RenderSt |
fontDescription.setComputedSize(fontSize); |
fontDescription.setSpecifiedSize(fontSize); |
- |
+ |
// Reset line height |
style->setLineHeight(RenderStyle::initialLineHeight()); |
@@ -257,7 +233,7 @@ static wchar_t* defaultGUIFont(Document* document) |
family = GetFontFamilyForScript(dominantScript, GENERIC_FAMILY_NONE); |
if (family) |
return const_cast<wchar_t*>(family); |
- } |
+ } |
return L"Arial"; |
} |
@@ -279,6 +255,108 @@ static float pointsToPixels(float points) |
return points / POINTS_PER_INCH * pixelsPerInch; |
} |
+static void setSizeIfAuto(RenderStyle* style, const IntSize& size) |
+{ |
+ if (style->width().isIntrinsicOrAuto()) |
+ style->setWidth(Length(size.width(), Fixed)); |
+ if (style->height().isAuto()) |
+ style->setHeight(Length(size.height(), Fixed)); |
+} |
+ |
+static IntSize layoutTestCheckboxSize(RenderStyle* style) |
+{ |
+ static const IntSize sizes[3] = { IntSize(14, 14), IntSize(12, 12), IntSize(10, 10) }; |
+ return sizes[controlSizeForFont(style)]; |
+} |
+ |
+static IntSize layoutTestRadioboxSize(RenderStyle* style) |
+{ |
+ static const IntSize sizes[3] = { IntSize(14, 15), IntSize(12, 13), IntSize(10, 10) }; |
+ return sizes[controlSizeForFont(style)]; |
+} |
+ |
+// Hacks for using Mac menu list metrics when in layout test mode. |
+static int layoutTestMenuListInternalPadding(RenderStyle* style, int paddingType) |
+{ |
+ if (style->appearance() == MenulistPart) { |
+ return kLayoutTestMenuListInternalPadding[controlSizeForFont(style)][paddingType]; |
+ } |
+ if (style->appearance() == MenulistButtonPart) { |
+ if (paddingType == RightPadding) { |
+ const float baseArrowWidth = 5.0f; |
+ float fontScale = style->fontSize() / kLayoutTestBaseFontSize; |
+ float arrowWidth = ceilf(baseArrowWidth * fontScale); |
+ |
+ int arrowPaddingLeft = 6; |
+ int arrowPaddingRight = 6; |
+ int paddingBeforeSeparator = 4; |
+ // Add 2 for separator space, seems to match RenderThemeMac::paintMenuListButton. |
+ return static_cast<int>(arrowWidth + arrowPaddingLeft + arrowPaddingRight + |
+ paddingBeforeSeparator); |
+ } else { |
+ return kLayoutTestStyledMenuListInternalPadding[paddingType]; |
+ } |
+ } |
+ return 0; |
+} |
+ |
+static const IntSize* layoutTestCancelButtonSizes() |
+{ |
+ static const IntSize sizes[3] = { IntSize(16, 13), IntSize(13, 11), IntSize(13, 9) }; |
+ return sizes; |
+} |
+ |
+static const IntSize* layoutTestResultsButtonSizes() |
+{ |
+ static const IntSize sizes[3] = { IntSize(19, 13), IntSize(17, 11), IntSize(17, 9) }; |
+ return sizes; |
+} |
+ |
+// Implement WebCore::theme() for getting the global RenderTheme. |
+RenderTheme* theme() |
+{ |
+ static RenderThemeWin winTheme; |
+ return &winTheme; |
+} |
+ |
+bool RenderThemeWin::supportsFocusRing(const RenderStyle* style) const |
+{ |
+ // Let webkit draw one of its halo rings around any focused element, |
+ // except push buttons. For buttons we use the windows PBS_DEFAULTED |
+ // styling to give it a blue border. |
+ return style->appearance() == ButtonPart || |
+ style->appearance() == PushButtonPart; |
+} |
+ |
+Color RenderThemeWin::platformActiveSelectionBackgroundColor() const |
+{ |
+ if (ChromiumBridge::layoutTestMode()) |
+ return Color("#0000FF"); // Royal blue |
+ COLORREF color = GetSysColor(COLOR_HIGHLIGHT); |
+ return Color(GetRValue(color), GetGValue(color), GetBValue(color), 255); |
+} |
+ |
+Color RenderThemeWin::platformInactiveSelectionBackgroundColor() const |
+{ |
+ if (ChromiumBridge::layoutTestMode()) |
+ return Color("#999999"); // Medium grey |
+ COLORREF color = GetSysColor(COLOR_GRAYTEXT); |
+ return Color(GetRValue(color), GetGValue(color), GetBValue(color), 255); |
+} |
+ |
+Color RenderThemeWin::platformActiveSelectionForegroundColor() const |
+{ |
+ if (ChromiumBridge::layoutTestMode()) |
+ return Color("#FFFFCC"); // Pale yellow |
+ COLORREF color = GetSysColor(COLOR_HIGHLIGHTTEXT); |
+ return Color(GetRValue(color), GetGValue(color), GetBValue(color), 255); |
+} |
+ |
+Color RenderThemeWin::platformInactiveSelectionForegroundColor() const |
+{ |
+ return Color::white; |
+} |
+ |
double RenderThemeWin::caretBlinkFrequency() const |
{ |
// Disable the blinking caret in layout test mode, as it introduces |
@@ -391,125 +469,6 @@ void RenderThemeWin::systemFont(int propId, Document* document, FontDescription& |
fontDescription = *cachedDesc; |
} |
-static bool supportsFocus(ControlPart appearance) |
-{ |
- switch (appearance) { |
- case PushButtonPart: |
- case ButtonPart: |
- case DefaultButtonPart: |
- case TextFieldPart: |
- case TextAreaPart: |
- return true; |
- default: |
- return false; |
- } |
- |
- return false; |
-} |
- |
-bool RenderThemeWin::supportsFocusRing(const RenderStyle* style) const |
-{ |
- // Let webkit draw one of its halo rings around any focused element, |
- // except push buttons. For buttons we use the windows PBS_DEFAULTED |
- // styling to give it a blue border. |
- return style->appearance() == ButtonPart || |
- style->appearance() == PushButtonPart; |
-} |
- |
-unsigned RenderThemeWin::determineState(RenderObject* o) |
-{ |
- unsigned result = TS_NORMAL; |
- ControlPart appearance = o->style()->appearance(); |
- if (!isEnabled(o)) |
- result = TS_DISABLED; |
- else if (isReadOnlyControl(o) && (TextFieldPart == appearance || TextAreaPart == appearance)) |
- result = ETS_READONLY; // Readonly is supported on textfields. |
- else if (isPressed(o)) // Active overrides hover and focused. |
- result = TS_PRESSED; |
- else if (supportsFocus(appearance) && isFocused(o)) |
- result = ETS_FOCUSED; |
- else if (isHovered(o)) |
- result = TS_HOT; |
- if (isChecked(o)) |
- result += 4; // 4 unchecked states, 4 checked states. |
- return result; |
-} |
- |
-unsigned RenderThemeWin::determineClassicState(RenderObject* o) |
-{ |
- unsigned result = 0; |
- if (!isEnabled(o)) |
- result = DFCS_INACTIVE; |
- else if (isPressed(o)) // Active supersedes hover |
- result = DFCS_PUSHED; |
- else if (isHovered(o)) |
- result = DFCS_HOT; |
- if (isChecked(o)) |
- result |= DFCS_CHECKED; |
- return result; |
-} |
- |
-ThemeData RenderThemeWin::getThemeData(RenderObject* o) |
-{ |
- ThemeData result; |
- switch (o->style()->appearance()) { |
- case PushButtonPart: |
- case ButtonPart: |
- result.m_part = BP_PUSHBUTTON; |
- result.m_classicState = DFCS_BUTTONPUSH; |
- break; |
- case CheckboxPart: |
- result.m_part = BP_CHECKBOX; |
- result.m_classicState = DFCS_BUTTONCHECK; |
- break; |
- case RadioPart: |
- result.m_part = BP_RADIOBUTTON; |
- result.m_classicState = DFCS_BUTTONRADIO; |
- break; |
- case ListboxPart: |
- case MenulistPart: |
- case TextFieldPart: |
- case TextAreaPart: |
- result.m_part = ETS_NORMAL; |
- break; |
- } |
- |
- result.m_state = determineState(o); |
- result.m_classicState |= determineClassicState(o); |
- |
- return result; |
-} |
- |
-bool RenderThemeWin::paintButton(RenderObject* o, |
- const RenderObject::PaintInfo& i, |
- const IntRect& r) |
-{ |
- const ThemeData& themeData = getThemeData(o); |
- |
- WebCore::ThemeHelperWin helper(i.context, r); |
- gfx::PlatformCanvas* canvas = helper.context()->platformContext()->canvas(); |
- |
- HDC hdc = canvas->beginPlatformPaint(); |
- int state = themeData.m_state; |
- RECT renderRect = helper.rect(); |
- |
- gfx::NativeTheme::instance()->PaintButton(hdc, |
- themeData.m_part, |
- state, |
- themeData.m_classicState, |
- &renderRect); |
- canvas->endPlatformPaint(); |
- return false; |
-} |
- |
-static void setSizeIfAuto(RenderStyle* style, const IntSize& size) |
-{ |
- if (style->width().isIntrinsicOrAuto()) |
- style->setWidth(Length(size.width(), Fixed)); |
- if (style->height().isAuto()) |
- style->setHeight(Length(size.height(), Fixed)); |
-} |
- |
int RenderThemeWin::minimumMenuListSize(RenderStyle* style) const |
{ |
if (ChromiumBridge::layoutTestMode()) { |
@@ -519,18 +478,6 @@ int RenderThemeWin::minimumMenuListSize(RenderStyle* style) const |
} |
} |
-static IntSize layoutTestCheckboxSize(RenderStyle* style) |
-{ |
- static const IntSize sizes[3] = { IntSize(14, 14), IntSize(12, 12), IntSize(10, 10) }; |
- return sizes[controlSizeForFont(style)]; |
-} |
- |
-static IntSize layoutTestRadioboxSize(RenderStyle* style) |
-{ |
- static const IntSize sizes[3] = { IntSize(14, 15), IntSize(12, 13), IntSize(10, 10) }; |
- return sizes[controlSizeForFont(style)]; |
-} |
- |
void RenderThemeWin::setCheckboxSize(RenderStyle* style) const |
{ |
// If the width and height are both specified, then we have nothing to do. |
@@ -556,46 +503,33 @@ void RenderThemeWin::setRadioSize(RenderStyle* style) const |
} |
} |
-bool RenderThemeWin::paintTextField(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r) |
-{ |
- return paintTextFieldInternal(o, i, r, true); |
-} |
- |
-bool RenderThemeWin::paintTextFieldInternal(RenderObject* o, |
- const RenderObject::PaintInfo& i, |
- const IntRect& r, |
- bool drawEdges) |
+bool RenderThemeWin::paintButton(RenderObject* o, |
+ const RenderObject::PaintInfo& i, |
+ const IntRect& r) |
{ |
- // Nasty hack to make us not paint the border on text fields with a |
- // border-radius. Webkit paints elements with border-radius for us. |
- // TODO(ojan): Get rid of this if-check once we can properly clip rounded |
- // borders: http://b/1112604 and http://b/1108635 |
- // TODO(ojan): make sure we do the right thing if css background-clip is |
- // set. |
- if (o->style()->hasBorderRadius()) |
- return false; |
- |
const ThemeData& themeData = getThemeData(o); |
WebCore::ThemeHelperWin helper(i.context, r); |
gfx::PlatformCanvas* canvas = helper.context()->platformContext()->canvas(); |
HDC hdc = canvas->beginPlatformPaint(); |
- COLORREF clr = gfx::SkColorToCOLORREF(o->style()->backgroundColor().rgb()); |
+ int state = themeData.m_state; |
RECT renderRect = helper.rect(); |
- gfx::NativeTheme::instance()->PaintTextField(hdc, |
- themeData.m_part, |
- themeData.m_state, |
- themeData.m_classicState, |
- &renderRect, |
- clr, |
- true, |
- drawEdges); |
+ gfx::NativeTheme::instance()->PaintButton(hdc, |
+ themeData.m_part, |
+ state, |
+ themeData.m_classicState, |
+ &renderRect); |
canvas->endPlatformPaint(); |
return false; |
} |
+bool RenderThemeWin::paintTextField(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r) |
+{ |
+ return paintTextFieldInternal(o, i, r, true); |
+} |
+ |
bool RenderThemeWin::paintSearchField(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r) |
{ |
return paintTextField(o, i, r); |
@@ -621,11 +555,6 @@ void RenderThemeWin::adjustMenuListStyle(CSSStyleSelector* selector, RenderStyle |
} |
} |
-void RenderThemeWin::adjustMenuListButtonStyle(CSSStyleSelector* selector, RenderStyle* style, Element* e) const |
-{ |
- adjustMenuListStyle(selector, style, e); |
-} |
- |
// Used to paint unstyled menulists (i.e. with the default border) |
bool RenderThemeWin::paintMenuList(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r) |
{ |
@@ -635,7 +564,7 @@ bool RenderThemeWin::paintMenuList(RenderObject* o, const RenderObject::PaintInf |
int borderBottom = o->borderBottom(); |
// If all the borders are 0, then tell skia not to paint the border on the textfield. |
- // TODO(ojan): http://b/1210017 Figure out how to get Windows to not draw individual |
+ // TODO(ojan): http://b/1210017 Figure out how to get Windows to not draw individual |
// borders and then pass that to skia so we can avoid drawing any borders that are |
// set to 0. For non-zero borders, we draw the border, but webkit just draws |
// over it. |
@@ -648,7 +577,7 @@ bool RenderThemeWin::paintMenuList(RenderObject* o, const RenderObject::PaintInf |
// Take padding and border into account. |
// If the MenuList is smaller than the size of a button, make sure to |
- // shrink it appropriately and not put its x position to the left of |
+ // shrink it appropriately and not put its x position to the left of |
// the menulist. |
const int buttonWidth = ChromiumBridge::layoutTestMode() ? |
kLayoutTestMenuListButtonWidth : GetSystemMetrics(SM_CXVSCROLL); |
@@ -684,6 +613,11 @@ bool RenderThemeWin::paintMenuList(RenderObject* o, const RenderObject::PaintInf |
return false; |
} |
+void RenderThemeWin::adjustMenuListButtonStyle(CSSStyleSelector* selector, RenderStyle* style, Element* e) const |
+{ |
+ adjustMenuListStyle(selector, style, e); |
+} |
+ |
// Used to paint styled menulists (i.e. with a non-default border) |
bool RenderThemeWin::paintMenuListButton(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r) |
{ |
@@ -710,55 +644,8 @@ int RenderThemeWin::popupInternalPaddingBottom(RenderStyle* style) const |
return menuListInternalPadding(style, BottomPadding); |
} |
-// Hacks for using Mac menu list metrics when in layout test mode. |
-static int layoutTestMenuListInternalPadding(RenderStyle* style, int paddingType) |
-{ |
- if (style->appearance() == MenulistPart) { |
- return kLayoutTestMenuListInternalPadding[controlSizeForFont(style)][paddingType]; |
- } |
- if (style->appearance() == MenulistButtonPart) { |
- if (paddingType == RightPadding) { |
- const float baseArrowWidth = 5.0f; |
- float fontScale = style->fontSize() / kLayoutTestBaseFontSize; |
- float arrowWidth = ceilf(baseArrowWidth * fontScale); |
- |
- int arrowPaddingLeft = 6; |
- int arrowPaddingRight = 6; |
- int paddingBeforeSeparator = 4; |
- // Add 2 for separator space, seems to match RenderThemeMac::paintMenuListButton. |
- return static_cast<int>(arrowWidth + arrowPaddingLeft + arrowPaddingRight + |
- paddingBeforeSeparator); |
- } else { |
- return kLayoutTestStyledMenuListInternalPadding[paddingType]; |
- } |
- } |
- return 0; |
-} |
- |
-int RenderThemeWin::menuListInternalPadding(RenderStyle* style, int paddingType) const |
+void RenderThemeWin::adjustButtonInnerStyle(RenderStyle* style) const |
{ |
- if (ChromiumBridge::layoutTestMode()) { |
- return layoutTestMenuListInternalPadding(style, paddingType); |
- } |
- |
- // This internal padding is in addition to the user-supplied padding. |
- // Matches the FF behavior. |
- int padding = kStyledMenuListInternalPadding[paddingType]; |
- |
- // Reserve the space for right arrow here. The rest of the padding is |
- // set by adjustMenuListStyle, since PopMenuWin.cpp uses the padding from |
- // RenderMenuList to lay out the individual items in the popup. |
- // If the MenuList actually has appearance "NoAppearance", then that means |
- // we don't draw a button, so don't reserve space for it. |
- const int bar_type = style->direction() == LTR ? RightPadding : LeftPadding; |
- if (paddingType == bar_type && style->appearance() != NoPart) |
- padding += ScrollbarTheme::nativeTheme()->scrollbarThickness(); |
- |
- return padding; |
-} |
- |
-void RenderThemeWin::adjustButtonInnerStyle(RenderStyle* style) const |
-{ |
// This inner padding matches Firefox. |
style->setPaddingTop(Length(1, Fixed)); |
style->setPaddingRight(Length(3, Fixed)); |
@@ -766,38 +653,6 @@ void RenderThemeWin::adjustButtonInnerStyle(RenderStyle* style) const |
style->setPaddingLeft(Length(3, Fixed)); |
} |
-void RenderThemeWin::setButtonPadding(RenderStyle* style) const |
-{ |
- if (ChromiumBridge::layoutTestMode()) { |
- setFixedPadding(style, kLayoutTestButtonPadding); |
- |
- } else if (!style->width().isAuto()) { |
- // We need to set the minimum padding for the buttons, or else they |
- // render too small and clip the button face text. The right way to do |
- // this is to ask window's theme manager to give us the minimum |
- // (TS_MIN) size for the part. As a failsafe we set at least |
- // kDefaultButtonPadding because zero just looks bad. |
- Length minXPadding(kDefaultButtonPadding, Fixed); |
- Length minYPadding(kDefaultButtonPadding, Fixed); |
- // Find minimum padding. |
- getMinimalButtonPadding(&minXPadding); |
- |
- // Set the minimum padding. |
- if (style->paddingLeft().value() < minXPadding.value()) { |
- style->setPaddingLeft(minXPadding); |
- } |
- if (style->paddingRight().value() < minXPadding.value()) { |
- style->setPaddingRight(minXPadding); |
- } |
- if (style->paddingBottom().value() < minYPadding.value()) { |
- style->setPaddingBottom(minYPadding); |
- } |
- if (style->paddingTop().value() < minYPadding.value()) { |
- style->setPaddingTop(minYPadding); |
- } |
- } |
-} |
- |
void RenderThemeWin::adjustSliderThumbSize(RenderObject* o) const |
{ |
if (ChromiumBridge::layoutTestMode()) { |
@@ -838,18 +693,6 @@ void RenderThemeWin::adjustSearchFieldStyle(CSSStyleSelector* selector, RenderSt |
} |
} |
-static const IntSize* layoutTestCancelButtonSizes() |
-{ |
- static const IntSize sizes[3] = { IntSize(16, 13), IntSize(13, 11), IntSize(13, 9) }; |
- return sizes; |
-} |
- |
-static const IntSize* layoutTestResultsButtonSizes() |
-{ |
- static const IntSize sizes[3] = { IntSize(19, 13), IntSize(17, 11), IntSize(17, 9) }; |
- return sizes; |
-} |
- |
void RenderThemeWin::adjustSearchFieldCancelButtonStyle(CSSStyleSelector* selector, RenderStyle* style, Element* e) const |
{ |
if (ChromiumBridge::layoutTestMode()) { |
@@ -890,6 +733,145 @@ void RenderThemeWin::adjustSearchFieldResultsButtonStyle(CSSStyleSelector* selec |
} |
} |
+// static |
+void RenderThemeWin::setDefaultFontSize(int fontSize) { |
+ DefaultFontSize = static_cast<float>(fontSize); |
+ |
+ // Reset cached fonts. |
+ smallSystemFont = menuFont = labelFont = FontDescription(); |
+} |
+ |
+unsigned RenderThemeWin::determineState(RenderObject* o) |
+{ |
+ unsigned result = TS_NORMAL; |
+ ControlPart appearance = o->style()->appearance(); |
+ if (!isEnabled(o)) |
+ result = TS_DISABLED; |
+ else if (isReadOnlyControl(o) && (TextFieldPart == appearance || TextAreaPart == appearance)) |
+ result = ETS_READONLY; // Readonly is supported on textfields. |
+ else if (isPressed(o)) // Active overrides hover and focused. |
+ result = TS_PRESSED; |
+ else if (supportsFocus(appearance) && isFocused(o)) |
+ result = ETS_FOCUSED; |
+ else if (isHovered(o)) |
+ result = TS_HOT; |
+ if (isChecked(o)) |
+ result += 4; // 4 unchecked states, 4 checked states. |
+ return result; |
+} |
+ |
+unsigned RenderThemeWin::determineClassicState(RenderObject* o) |
+{ |
+ unsigned result = 0; |
+ if (!isEnabled(o)) |
+ result = DFCS_INACTIVE; |
+ else if (isPressed(o)) // Active supersedes hover |
+ result = DFCS_PUSHED; |
+ else if (isHovered(o)) |
+ result = DFCS_HOT; |
+ if (isChecked(o)) |
+ result |= DFCS_CHECKED; |
+ return result; |
+} |
+ |
+ThemeData RenderThemeWin::getThemeData(RenderObject* o) |
+{ |
+ ThemeData result; |
+ switch (o->style()->appearance()) { |
+ case PushButtonPart: |
+ case ButtonPart: |
+ result.m_part = BP_PUSHBUTTON; |
+ result.m_classicState = DFCS_BUTTONPUSH; |
+ break; |
+ case CheckboxPart: |
+ result.m_part = BP_CHECKBOX; |
+ result.m_classicState = DFCS_BUTTONCHECK; |
+ break; |
+ case RadioPart: |
+ result.m_part = BP_RADIOBUTTON; |
+ result.m_classicState = DFCS_BUTTONRADIO; |
+ break; |
+ case ListboxPart: |
+ case MenulistPart: |
+ case TextFieldPart: |
+ case TextAreaPart: |
+ result.m_part = ETS_NORMAL; |
+ break; |
+ } |
+ |
+ result.m_state = determineState(o); |
+ result.m_classicState |= determineClassicState(o); |
+ |
+ return result; |
+} |
+ |
+bool RenderThemeWin::paintTextFieldInternal(RenderObject* o, |
+ const RenderObject::PaintInfo& i, |
+ const IntRect& r, |
+ bool drawEdges) |
+{ |
+ // Nasty hack to make us not paint the border on text fields with a |
+ // border-radius. Webkit paints elements with border-radius for us. |
+ // TODO(ojan): Get rid of this if-check once we can properly clip rounded |
+ // borders: http://b/1112604 and http://b/1108635 |
+ // TODO(ojan): make sure we do the right thing if css background-clip is |
+ // set. |
+ if (o->style()->hasBorderRadius()) |
+ return false; |
+ |
+ const ThemeData& themeData = getThemeData(o); |
+ |
+ WebCore::ThemeHelperWin helper(i.context, r); |
+ gfx::PlatformCanvas* canvas = helper.context()->platformContext()->canvas(); |
+ |
+ HDC hdc = canvas->beginPlatformPaint(); |
+ COLORREF clr = gfx::SkColorToCOLORREF(o->style()->backgroundColor().rgb()); |
+ RECT renderRect = helper.rect(); |
+ |
+ gfx::NativeTheme::instance()->PaintTextField(hdc, |
+ themeData.m_part, |
+ themeData.m_state, |
+ themeData.m_classicState, |
+ &renderRect, |
+ clr, |
+ true, |
+ drawEdges); |
+ canvas->endPlatformPaint(); |
+ return false; |
+} |
+ |
+void RenderThemeWin::setButtonPadding(RenderStyle* style) const |
+{ |
+ if (ChromiumBridge::layoutTestMode()) { |
+ setFixedPadding(style, kLayoutTestButtonPadding); |
+ |
+ } else if (!style->width().isAuto()) { |
+ // We need to set the minimum padding for the buttons, or else they |
+ // render too small and clip the button face text. The right way to do |
+ // this is to ask window's theme manager to give us the minimum |
+ // (TS_MIN) size for the part. As a failsafe we set at least |
+ // kDefaultButtonPadding because zero just looks bad. |
+ Length minXPadding(kDefaultButtonPadding, Fixed); |
+ Length minYPadding(kDefaultButtonPadding, Fixed); |
+ // Find minimum padding. |
+ getMinimalButtonPadding(&minXPadding); |
+ |
+ // Set the minimum padding. |
+ if (style->paddingLeft().value() < minXPadding.value()) { |
+ style->setPaddingLeft(minXPadding); |
+ } |
+ if (style->paddingRight().value() < minXPadding.value()) { |
+ style->setPaddingRight(minXPadding); |
+ } |
+ if (style->paddingBottom().value() < minYPadding.value()) { |
+ style->setPaddingBottom(minYPadding); |
+ } |
+ if (style->paddingTop().value() < minYPadding.value()) { |
+ style->setPaddingTop(minYPadding); |
+ } |
+ } |
+} |
+ |
void RenderThemeWin::getMinimalButtonPadding(Length* minXPadding) const { |
// TODO(maruel): This get messy if 1. the theme change; 2. we are serializing. |
SIZE size; |
@@ -900,12 +882,26 @@ void RenderThemeWin::getMinimalButtonPadding(Length* minXPadding) const { |
} |
} |
-// static |
-void RenderThemeWin::setDefaultFontSize(int fontSize) { |
- DefaultFontSize = static_cast<float>(fontSize); |
+int RenderThemeWin::menuListInternalPadding(RenderStyle* style, int paddingType) const |
+{ |
+ if (ChromiumBridge::layoutTestMode()) { |
+ return layoutTestMenuListInternalPadding(style, paddingType); |
+ } |
- // Reset cached fonts. |
- smallSystemFont = menuFont = labelFont = FontDescription(); |
-} |
+ // This internal padding is in addition to the user-supplied padding. |
+ // Matches the FF behavior. |
+ int padding = kStyledMenuListInternalPadding[paddingType]; |
+ |
+ // Reserve the space for right arrow here. The rest of the padding is |
+ // set by adjustMenuListStyle, since PopMenuWin.cpp uses the padding from |
+ // RenderMenuList to lay out the individual items in the popup. |
+ // If the MenuList actually has appearance "NoAppearance", then that means |
+ // we don't draw a button, so don't reserve space for it. |
+ const int bar_type = style->direction() == LTR ? RightPadding : LeftPadding; |
+ if (paddingType == bar_type && style->appearance() != NoPart) |
+ padding += ScrollbarTheme::nativeTheme()->scrollbarThickness(); |
+ return padding; |
} |
+ |
+} // namespace WebCore |