intrinsic margins. Move the intrinsic margin addition code into
adjustRenderStyle and get it out of the theme code and the old form control
code.
Reviewed by aroben
* css/cssstyleselector.cpp:
(WebCore::addIntrinsicMargins):
(WebCore::CSSStyleSelector::adjustRenderStyle):
* css/html4.css:
* rendering/DeprecatedRenderSelect.h:
(WebCore::DeprecatedRenderSelect::calcReplacedHeight):
* rendering/DeprecatedSlider.h:
* rendering/RenderFormElement.cpp:
(WebCore::RenderFormElement::setStyle):
* rendering/RenderFormElement.h:
* rendering/RenderLayer.cpp:
(WebCore::RenderLayer::resize):
* rendering/RenderThemeMac.h:
* rendering/RenderThemeMac.mm:
(WebCore::RenderThemeMac::adjustButtonStyle):
(WebCore::RenderThemeMac::adjustTextFieldStyle):
(WebCore::RenderThemeMac::adjustTextAreaStyle):
(WebCore::RenderThemeMac::adjustMenuListStyle):
(WebCore::RenderThemeMac::adjustMenuListButtonStyle):
* rendering/RenderThemeWin.cpp:
(WebCore::RenderThemeWin::adjustButtonStyle):
(WebCore::RenderThemeWin::adjustTextFieldStyle):
(WebCore::RenderThemeWin::adjustTextAreaStyle):
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@16289
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2006-09-10 David Hyatt <hyatt@apple.com>
+
+ Fix for bug 10801, form controls that get styled suddenly lose their
+ intrinsic margins. Move the intrinsic margin addition code into
+ adjustRenderStyle and get it out of the theme code and the old form control
+ code.
+
+ Reviewed by aroben
+
+ * css/cssstyleselector.cpp:
+ (WebCore::addIntrinsicMargins):
+ (WebCore::CSSStyleSelector::adjustRenderStyle):
+ * css/html4.css:
+ * rendering/DeprecatedRenderSelect.h:
+ (WebCore::DeprecatedRenderSelect::calcReplacedHeight):
+ * rendering/DeprecatedSlider.h:
+ * rendering/RenderFormElement.cpp:
+ (WebCore::RenderFormElement::setStyle):
+ * rendering/RenderFormElement.h:
+ * rendering/RenderLayer.cpp:
+ (WebCore::RenderLayer::resize):
+ * rendering/RenderThemeMac.h:
+ * rendering/RenderThemeMac.mm:
+ (WebCore::RenderThemeMac::adjustButtonStyle):
+ (WebCore::RenderThemeMac::adjustTextFieldStyle):
+ (WebCore::RenderThemeMac::adjustTextAreaStyle):
+ (WebCore::RenderThemeMac::adjustMenuListStyle):
+ (WebCore::RenderThemeMac::adjustMenuListButtonStyle):
+ * rendering/RenderThemeWin.cpp:
+ (WebCore::RenderThemeWin::adjustButtonStyle):
+ (WebCore::RenderThemeWin::adjustTextFieldStyle):
+ (WebCore::RenderThemeWin::adjustTextAreaStyle):
+
2006-09-10 Darin Adler <darin@apple.com>
- test for http://bugzilla.opendarwin.org/show_bug.cgi?id=10547
return style;
}
+static void addIntrinsicMargins(RenderStyle* style)
+{
+ // Intrinsic margin value.
+ const int intrinsicMargin = 2;
+
+ // FIXME: Using width/height alone and not also dealing with min-width/max-width is flawed.
+ // FIXME: Using "quirk" to decide the margin wasn't set is kind of lame.
+ if (style->width().isIntrinsicOrAuto()) {
+ if (style->marginLeft().quirk())
+ style->setMarginLeft(Length(intrinsicMargin, Fixed));
+ if (style->marginRight().quirk())
+ style->setMarginRight(Length(intrinsicMargin, Fixed));
+ }
+
+ if (style->height().isAuto()) {
+ if (style->marginTop().quirk())
+ style->setMarginTop(Length(intrinsicMargin, Fixed));
+ if (style->marginBottom().quirk())
+ style->setMarginBottom(Length(intrinsicMargin, Fixed));
+ }
+}
+
void CSSStyleSelector::adjustRenderStyle(RenderStyle* style, Element *e)
{
// Cache our original display.
// Cull out any useless layers and also repeat patterns into additional layers.
style->adjustBackgroundLayers();
+ // Important: Intrinsic margins get added to controls before the theme has adjusted the style, since the theme will
+ // alter fonts and heights/widths.
+ if (e && e->isControl() && style->fontSize() >= 11) {
+ // Don't apply intrinsic margins to image buttons. The designer knows how big the images are,
+ // so we have to treat all image buttons as though they were explicitly sized.
+ if (!e->hasTagName(inputTag) || static_cast<HTMLInputElement*>(e)->inputType() != HTMLInputElement::IMAGE)
+ addIntrinsicMargins(style);
+ }
+
// Let the theme also have a crack at adjusting the style.
if (style->hasAppearance())
theme()->adjustStyle(this, style, e, m_hasUAAppearance, m_borderData, m_backgroundData, m_backgroundColor);
-
+
#ifdef SVG_SUPPORT
if (e && e->isSVGElement()) {
// Spec: http://www.w3.org/TR/SVG/masking.html#OverflowProperty
select[size],
select[multiple],
select[size][multiple] {
- // FIXME: When converting the list box implementation, remove these.
+ /* FIXME: When converting the list box implementation, remove these. */
-webkit-appearance: none;
-webkit-box-align: initial;
box-sizing: initial;
short baselinePosition(bool f, bool b) const;
int calcReplacedHeight() const { if (!m_useListBox) return intrinsicHeight(); return RenderFormElement::calcReplacedHeight(); }
- virtual bool canHaveIntrinsicMargins() const { return true; }
virtual void calcMinMaxWidth();
virtual void layout();
virtual const char* renderName() const { return "DeprecatedSlider"; }
- virtual bool canHaveIntrinsicMargins() const { return true; }
virtual void calcMinMaxWidth();
virtual void updateFromElement();
void RenderFormElement::setStyle(RenderStyle* s)
{
- if (canHaveIntrinsicMargins())
- addIntrinsicMarginsIfAllowed(s);
-
RenderWidget::setStyle(s);
// Do not paint a background or border for Aqua form elements
return AlignLeft;
}
-
-void RenderFormElement::addIntrinsicMarginsIfAllowed(RenderStyle* _style)
-{
- // Cut out the intrinsic margins completely if we end up using mini controls.
- if (_style->fontSize() < 11)
- return;
-
- // FIXME: Using width/height alone and not also dealing with min-width/max-width is flawed.
- int m = intrinsicMargin();
- if (_style->width().isIntrinsicOrAuto()) {
- if (_style->marginLeft().quirk())
- _style->setMarginLeft(Length(m, Fixed));
- if (_style->marginRight().quirk())
- _style->setMarginRight(Length(m, Fixed));
- }
-
- if (_style->height().isAuto()) {
- if (_style->marginTop().quirk())
- _style->setMarginTop(Length(m, Fixed));
- if (_style->marginBottom().quirk())
- _style->setMarginBottom(Length(m, Fixed));
- }
-}
-
} // namespace WebCore
int paddingLeft() const { return 0; }
int paddingRight() const { return 0; }
- // Aqua controls use intrinsic margin values in order to leave space for focus rings
- // and to keep controls from butting up against one another. This intrinsic margin
- // is only applied if the Web page allows the control to size intrinsically. If the
- // Web page specifies an explicit width for a control, then we go ahead and honor that
- // precise width. Similarly, if a Web page uses a specific margin value, we will go ahead
- // and honor that value.
- void addIntrinsicMarginsIfAllowed(RenderStyle*);
- virtual bool canHaveIntrinsicMargins() const { return false; }
- int intrinsicMargin() const { return 2; }
-
virtual void setStyle(RenderStyle*);
virtual void updateFromElement();
#include "OverflowEvent.h"
#include "PlatformMouseEvent.h"
#include "RenderArena.h"
-#include "RenderFormElement.h"
#include "RenderInline.h"
#include "RenderTheme.h"
#include "RenderView.h"
RenderObject* renderer = m_object->node()->shadowAncestorNode()->renderer();
if (diffWidth && (m_object->style()->resize() == RESIZE_HORIZONTAL || m_object->style()->resize() == RESIZE_BOTH)) {
CSSStyleDeclaration* style = static_cast<Element*>(m_object->node()->shadowAncestorNode())->style();
- if (renderer->style()->hasAppearance() || renderer->isFormElement() && static_cast<RenderFormElement*>(renderer)->canHaveIntrinsicMargins()) {
+ if (renderer->element() && renderer->element()->isControl()) {
style->setProperty(CSS_PROP_MARGIN_LEFT, String::number(renderer->marginLeft()) + "px", false, ec);
style->setProperty(CSS_PROP_MARGIN_RIGHT, String::number(renderer->marginRight()) + "px", false, ec);
}
if (diffHeight && (m_object->style()->resize() == RESIZE_VERTICAL || m_object->style()->resize() == RESIZE_BOTH)) {
CSSStyleDeclaration* style = static_cast<Element*>(m_object->node()->shadowAncestorNode())->style();
- if (renderer->style()->hasAppearance() || renderer->isFormElement() && static_cast<RenderFormElement*>(renderer)->canHaveIntrinsicMargins()) {
+ if (renderer->element() && renderer->element()->isControl()) {
style->setProperty(CSS_PROP_MARGIN_TOP, String::number(renderer->marginTop()) + "px", false, ec);
style->setProperty(CSS_PROP_MARGIN_BOTTOM, String::number(renderer->marginBottom()) + "px", false, ec);
}
IntSize sizeForFont(RenderStyle*, const IntSize* sizes) const;
void setFontFromControlSize(CSSStyleSelector*, RenderStyle*, NSControlSize) const;
- void addIntrinsicMargins(RenderStyle*, NSControlSize) const;
-
void updateCheckedState(NSCell*, const RenderObject*);
void updateEnabledState(NSCell*, const RenderObject*);
void updateFocusedState(NSCell*, const RenderObject*);
style->font().update();
}
-void RenderThemeMac::addIntrinsicMargins(RenderStyle* style, NSControlSize size) const
-{
- // Cut out the intrinsic margins completely if we end up using mini controls.
- if (size == NSMiniControlSize)
- return;
-
- // Intrinsic margin value.
- const int m = 2;
-
- // FIXME: Using width/height alone and not also dealing with min-width/max-width is flawed.
- if (style->width().isIntrinsicOrAuto()) {
- if (style->marginLeft().quirk())
- style->setMarginLeft(Length(m, Fixed));
- if (style->marginRight().quirk())
- style->setMarginRight(Length(m, Fixed));
- }
-
- if (style->height().isAuto()) {
- if (style->marginTop().quirk())
- style->setMarginTop(Length(m, Fixed));
- if (style->marginBottom().quirk())
- style->setMarginBottom(Length(m, Fixed));
- }
-}
-
bool RenderThemeMac::paintCheckbox(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r)
{
// Determine the width and height needed for the control and prepare the cell for painting.
// Determine our control size based off our font.
NSControlSize controlSize = controlSizeForFont(style);
- // Add in intrinsic margins
- addIntrinsicMargins(style, controlSize);
-
if (style->appearance() == PushButtonAppearance) {
// Ditch the border.
style->resetBorder();
void RenderThemeMac::adjustTextFieldStyle(CSSStyleSelector* selector, RenderStyle* style, Element* e) const
{
- // Add in intrinsic margins if the font size isn't too small
- if (style->fontSize() >= 11)
- addIntrinsicMargins(style, NSRegularControlSize);
}
bool RenderThemeMac::paintTextArea(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r)
void RenderThemeMac::adjustTextAreaStyle(CSSStyleSelector* selector, RenderStyle* style, Element* e) const
{
- // Add in intrinsic margins if the font size isn't too small
- if (style->fontSize() >= 11)
- addIntrinsicMargins(style, NSRegularControlSize);
}
const int* RenderThemeMac::popupButtonMargins() const
{
NSControlSize controlSize = controlSizeForFont(style);
- // Add in intrinsic margins
- addIntrinsicMargins(style, controlSize);
-
style->resetBorder();
// Height is locked to auto.
}
void RenderThemeMac::adjustMenuListButtonStyle(CSSStyleSelector* selector, RenderStyle* style, Element* e) const
-{
- // Add in intrinsic margins if the font size isn't too small
- if (style->fontSize() >= 11)
- addIntrinsicMargins(style, NSRegularControlSize);
-
+{
float fontScale = style->fontSize() / baseFontSize;
float arrowWidth = baseArrowWidth * fontScale;
return Color::white;
}
-void RenderThemeWin::addIntrinsicMargins(RenderStyle* style) const
-{
- // Cut out the intrinsic margins completely if we end up using a small font size
- if (style->fontSize() < 11)
- return;
-
- // Intrinsic margin value.
- const int m = 2;
-
- // FIXME: Using width/height alone and not also dealing with min-width/max-width is flawed.
- if (style->width().isIntrinsicOrAuto()) {
- if (style->marginLeft().quirk())
- style->setMarginLeft(Length(m, Fixed));
- if (style->marginRight().quirk())
- style->setMarginRight(Length(m, Fixed));
- }
-
- if (style->height().isAuto()) {
- if (style->marginTop().quirk())
- style->setMarginTop(Length(m, Fixed));
- if (style->marginBottom().quirk())
- style->setMarginBottom(Length(m, Fixed));
- }
-}
-
bool RenderThemeWin::supportsFocus(EAppearance appearance)
{
switch (appearance) {
void RenderThemeWin::adjustButtonStyle(CSSStyleSelector*, RenderStyle* style, Element*) const
{
- addIntrinsicMargins(style);
}
static HDC prepareForDrawing(GraphicsContext* g)
void RenderThemeWin::adjustTextFieldStyle(CSSStyleSelector*, RenderStyle* style, Element*) const
{
- addIntrinsicMargins(style);
}
bool RenderThemeWin::paintTextField(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r)
void RenderThemeWin::adjustTextAreaStyle(CSSStyleSelector*, RenderStyle* style, Element*) const
{
- addIntrinsicMargins(style);
}
bool RenderThemeWin::paintTextArea(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r)