[webkit-changes] cvs commit: WebCore/khtml/rendering render_style.h render_theme.cpp render_theme.h render_theme_mac.h render_theme_mac.mm

David hyatt at opensource.apple.com
Fri Oct 28 00:03:27 PDT 2005


hyatt       05/10/28 00:03:27

  Modified:    .        ChangeLog
               khtml/css cssstyleselector.cpp cssstyleselector.h html4.css
               khtml/rendering render_style.h render_theme.cpp
                        render_theme.h render_theme_mac.h
                        render_theme_mac.mm
  Log:
  	Fix for bug 5519, buttons need to honor background/border: none and turn off styles.
  	This patch changes the default style rules so that buttons have both a border and
  	a background color.
  
  	If the author changes the border/background so that it no longer matches these chosen
  	defaults, we assume that the button has now been styled and we turn off the Aqua
  	appearance.
  
  	We also play more games with border and padding and juggle the values around so that
  	things look right with Aqua turned on and off.
  
          Reviewed by mjs
  
          * khtml/css/cssstyleselector.cpp:
          (khtml::CSSStyleSelector::matchRules):
          (khtml::CSSStyleSelector::initForStyleResolve):
          (khtml::CSSStyleSelector::styleForElement):
          (khtml::CSSStyleSelector::adjustRenderStyle):
          (khtml::CSSStyleSelector::applyDeclarations):
          * khtml/css/cssstyleselector.h:
          * khtml/css/html4.css:
          * khtml/rendering/render_style.h:
          (khtml::BorderValue::BorderValue):
          (khtml::BorderData::operator!=):
          (khtml::RenderStyle::border):
          * khtml/rendering/render_theme.cpp:
          (khtml::RenderTheme::paint):
          (khtml::RenderTheme::isControlStyled):
          * khtml/rendering/render_theme.h:
          * khtml/rendering/render_theme_mac.h:
          * khtml/rendering/render_theme_mac.mm:
          (khtml::RenderThemeMac::adjustButtonStyle):
          (khtml::RenderThemeMac::setButtonCellState):
          (khtml::RenderThemeMac::paintButton):
  
  Revision  Changes    Path
  1.310     +37 -0     WebCore/ChangeLog
  
  Index: ChangeLog
  ===================================================================
  RCS file: /cvs/root/WebCore/ChangeLog,v
  retrieving revision 1.309
  retrieving revision 1.310
  diff -u -r1.309 -r1.310
  --- ChangeLog	28 Oct 2005 01:50:56 -0000	1.309
  +++ ChangeLog	28 Oct 2005 07:03:24 -0000	1.310
  @@ -1,3 +1,40 @@
  +2005-10-27  David Hyatt  <hyatt at apple.com>
  +
  +	Fix for bug 5519, buttons need to honor background/border: none and turn off styles.
  +	This patch changes the default style rules so that buttons have both a border and
  +	a background color.
  +
  +	If the author changes the border/background so that it no longer matches these chosen
  +	defaults, we assume that the button has now been styled and we turn off the Aqua
  +	appearance.
  +
  +	We also play more games with border and padding and juggle the values around so that
  +	things look right with Aqua turned on and off.
  +	
  +        Reviewed by mjs
  +
  +        * khtml/css/cssstyleselector.cpp:
  +        (khtml::CSSStyleSelector::matchRules):
  +        (khtml::CSSStyleSelector::initForStyleResolve):
  +        (khtml::CSSStyleSelector::styleForElement):
  +        (khtml::CSSStyleSelector::adjustRenderStyle):
  +        (khtml::CSSStyleSelector::applyDeclarations):
  +        * khtml/css/cssstyleselector.h:
  +        * khtml/css/html4.css:
  +        * khtml/rendering/render_style.h:
  +        (khtml::BorderValue::BorderValue):
  +        (khtml::BorderData::operator!=):
  +        (khtml::RenderStyle::border):
  +        * khtml/rendering/render_theme.cpp:
  +        (khtml::RenderTheme::paint):
  +        (khtml::RenderTheme::isControlStyled):
  +        * khtml/rendering/render_theme.h:
  +        * khtml/rendering/render_theme_mac.h:
  +        * khtml/rendering/render_theme_mac.mm:
  +        (khtml::RenderThemeMac::adjustButtonStyle):
  +        (khtml::RenderThemeMac::setButtonCellState):
  +        (khtml::RenderThemeMac::paintButton):
  +
   2005-10-26  Vicki Murley  <vicki at apple.com>
   
           Reviewed by Hyatt.
  
  
  
  1.218     +22 -9     WebCore/khtml/css/cssstyleselector.cpp
  
  Index: cssstyleselector.cpp
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/css/cssstyleselector.cpp,v
  retrieving revision 1.217
  retrieving revision 1.218
  diff -u -r1.217 -r1.218
  --- cssstyleselector.cpp	27 Oct 2005 09:30:38 -0000	1.217
  +++ cssstyleselector.cpp	28 Oct 2005 07:03:25 -0000	1.218
  @@ -357,7 +357,6 @@
   void CSSStyleSelector::matchRules(CSSRuleSet* rules, int& firstRuleIndex, int& lastRuleIndex)
   {
       m_matchedRuleCount = 0;
  -    firstRuleIndex = lastRuleIndex = -1;
       if (!rules || !element) return;
       
       // We need to collect the rules for id, class, tag, and everything else into a buffer and
  @@ -523,6 +522,11 @@
       m_tmpRuleCount = 0;
       
       fontDirty = false;
  +    
  +    // Clear out our cached border/background data.
  +    m_borderData = BorderData();
  +    m_backgroundData = BackgroundLayer();
  +    m_backgroundColor = QColor();
   }
   
   // modified version of the one in kurl.cpp
  @@ -815,8 +819,16 @@
           fontDirty = false;
       }
       
  -    // Now do the normal priority properties.
  -    applyDeclarations(false, false, 0, m_matchedDeclCount-1);
  +    // Now do the normal priority UA properties.
  +    applyDeclarations(false, false, firstUARule, lastUARule);
  +    
  +    // Cache our border and background so that we can examine them later.
  +    m_borderData = style->border();
  +    m_backgroundData = *style->backgroundLayers();
  +    m_backgroundColor = style->backgroundColor();
  +
  +    // Now do the author and user normal priority properties and all the !important properties.
  +    applyDeclarations(false, false, lastUARule+1, m_matchedDeclCount-1);
       applyDeclarations(false, true, firstAuthorRule, lastAuthorRule);
       applyDeclarations(false, true, firstUserRule, lastUserRule);
       applyDeclarations(false, true, firstUARule, lastUARule);
  @@ -1001,8 +1013,12 @@
       style->adjustBackgroundLayers();
   
       // Let the theme get a crack at changing the style if an appearance has been set.
  -    if (style->hasAppearance())
  -        theme()->adjustStyle(this, style, e);
  +    if (style->hasAppearance()) {
  +        if (theme()->isControlStyled(style, m_borderData, m_backgroundData, m_backgroundColor))
  +            style->setAppearance(NoAppearance);
  +        else
  +            theme()->adjustStyle(this, style, e);
  +    }
   
       // Only use slow repaints if we actually have a background image.
       // FIXME: We only need to invalidate the fixed regions when scrolling.  It's total overkill to
  @@ -1842,10 +1858,7 @@
               // give special priority to font-xxx, color properties
               if (isImportant == current.isImportant()) {
                   bool first;
  -                switch(current.id())
  -                {
  -                    case CSS_PROP_BACKGROUND:
  -                    case CSS_PROP_BACKGROUND_IMAGE:
  +                switch(current.id()) {
                       case CSS_PROP_COLOR:
                       case CSS_PROP_DIRECTION:
                       case CSS_PROP_DISPLAY:
  
  
  
  1.41      +4 -0      WebCore/khtml/css/cssstyleselector.h
  
  Index: cssstyleselector.h
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/css/cssstyleselector.h,v
  retrieving revision 1.40
  retrieving revision 1.41
  diff -u -r1.40 -r1.41
  --- cssstyleselector.h	21 Oct 2005 21:27:44 -0000	1.40
  +++ cssstyleselector.h	28 Oct 2005 07:03:25 -0000	1.41
  @@ -175,6 +175,10 @@
   	CSSRuleSet* m_authorStyle;
           CSSRuleSet* m_userStyle;
           DOM::CSSStyleSheetImpl* m_userSheet;
  +        
  +        BorderData m_borderData;
  +        BackgroundLayer m_backgroundData;
  +        QColor m_backgroundColor;
   
   public:
   	static RenderStyle* styleNotYetAvailable;
  
  
  
  1.81      +11 -1     WebCore/khtml/css/html4.css
  
  Index: html4.css
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/css/html4.css,v
  retrieving revision 1.80
  retrieving revision 1.81
  diff -u -r1.80 -r1.81
  --- html4.css	26 Oct 2005 06:08:03 -0000	1.80
  +++ html4.css	28 Oct 2005 07:03:25 -0000	1.81
  @@ -317,13 +317,23 @@
       text-align: center;
       cursor: default;
       color: ButtonText;
  -    padding: 2px 8px 3px 8px
  +    padding: 2px 6px 3px 6px;
  +    border: 2px outset ButtonFace;
  +    background-color: ButtonFace
   }
   
   input[type="button"]:disabled, input[type="submit"]:disabled, input[type="reset"]:disabled, button:disabled {
       color: GrayText;
   }
   
  +input[type="button"]:active, input[type="submit"]:active, input[type="reset"]:active, button:active {
  +    border-style: inset
  +}
  +
  +input[type="button"]:active:disabled, input[type="submit"]:active:disabled, input[type="reset"]:active:disabled, button:active:disabled {
  +    border-style: outset
  +}
  +
   select, button, input[type="button"], input[type="image"], input[type="submit"], input[type="reset"], img {
       -khtml-user-select: ignore
   }
  
  
  
  1.96      +7 -2      WebCore/khtml/rendering/render_style.h
  
  Index: render_style.h
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/rendering/render_style.h,v
  retrieving revision 1.95
  retrieving revision 1.96
  diff -u -r1.95 -r1.96
  --- render_style.h	22 Oct 2005 18:19:27 -0000	1.95
  +++ render_style.h	28 Oct 2005 07:03:26 -0000	1.96
  @@ -195,11 +195,11 @@
   class BorderValue
   {
   public:
  -    BorderValue()
  -    {
  +    BorderValue() {
   	width = 3; // medium is default value
           style = BNONE;
       }
  +
       QColor color;
       unsigned short width : 12;
       EBorderStyle style : 4;
  @@ -358,6 +358,10 @@
       	return left == o.left && right == o.right && top == o.top && bottom == o.bottom && image == o.image &&
                  topLeft == o.topLeft && topRight == o.topRight && bottomLeft == o.bottomLeft && bottomRight == o.bottomRight;
       }
  +    
  +    bool operator!=(const BorderData& o) const {
  +        return !(*this == o);
  +    }
   };
   
   enum EMarginCollapse { MCOLLAPSE, MSEPARATE, MDISCARD };
  @@ -1206,6 +1210,7 @@
       Length  	minHeight() const { return box->min_height; }
       Length  	maxHeight() const { return box->max_height; }
   
  +    const BorderData& border() const { return surround->border; }
       const BorderValue& borderLeft() const { return surround->border.left; }
       const BorderValue& borderRight() const { return surround->border.right; }
       const BorderValue& borderTop() const { return surround->border.top; }
  
  
  
  1.15      +20 -1     WebCore/khtml/rendering/render_theme.cpp
  
  Index: render_theme.cpp
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/rendering/render_theme.cpp,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- render_theme.cpp	26 Oct 2005 19:44:07 -0000	1.14
  +++ render_theme.cpp	28 Oct 2005 07:03:26 -0000	1.15
  @@ -86,7 +86,7 @@
               break;
       }
       
  -    return false;
  +    return true; // We don't support the appearance, so let the normal background/border paint.
   }
   
   short RenderTheme::baselinePosition(const RenderObject* o) const
  @@ -101,6 +101,25 @@
       return appearance != CheckboxAppearance && appearance != RadioAppearance;
   }
   
  +bool RenderTheme::isControlStyled(const RenderStyle* style, const BorderData& border, const BackgroundLayer& background,
  +                                  const QColor& backgroundColor) const
  +{
  +    switch (style->appearance()) {
  +        case PushButtonAppearance:
  +        case SquareButtonAppearance:
  +        case ButtonAppearance: {
  +            // Test the style to see if the UA border and background match.
  +            return (style->border() != border ||
  +                    *style->backgroundLayers() != background ||
  +                    style->backgroundColor() != backgroundColor);
  +        }
  +        default:
  +            return false;
  +    }
  +    
  +    return false;
  +}
  +
   bool RenderTheme::stateChanged(RenderObject* o, ControlState state) const
   {
       // Default implementation assumes the controls dont respond to changes in :hover state
  
  
  
  1.13      +9 -6      WebCore/khtml/rendering/render_theme.h
  
  Index: render_theme.h
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/rendering/render_theme.h,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- render_theme.h	26 Oct 2005 19:44:07 -0000	1.12
  +++ render_theme.h	28 Oct 2005 07:03:26 -0000	1.13
  @@ -23,6 +23,7 @@
   #ifndef RENDER_THEME_H
   #define RENDER_THEME_H
   
  +#include "render_style.h"
   #include "render_object.h"
   
   namespace DOM {
  @@ -31,8 +32,6 @@
   
   namespace khtml {
   
  -class RenderStyle;
  -
   enum ControlState { HoverState, PressedState, FocusState, EnabledState, CheckedState };
   
   class RenderTheme {
  @@ -55,19 +54,23 @@
       // The remaining methods should be implemented by the platform-specific portion of the theme, e.g.,
       // render_theme_mac.cpp for Mac OS X.
       
  -    // An API to obtain the baseline position for a "leaf" control.  This will only be used if a baseline
  +    // A method to obtain the baseline position for a "leaf" control.  This will only be used if a baseline
       // position cannot be determined by examining child content. Checkboxes and radio buttons are examples of
       // controls that need to do this.
       virtual short baselinePosition(const RenderObject* o) const;
   
  -    // An API for asking if a control is a container or not.  Leaf controls have to have some special behavior (like
  +    // A method for asking if a control is a container or not.  Leaf controls have to have some special behavior (like
       // the baseline position API above).
       virtual bool isControlContainer(EAppearance appearance) const;
   
  -    // An API asking if the control changes its tint when the window has focus or not.
  +    // A method asking if the control changes its tint when the window has focus or not.
       virtual bool controlSupportsTints(const RenderObject* o) const { return false; }
   
  -    // A general API asking if any control tinting is supported at all.
  +    // Whether or not the control has been styled enough by the author to disable the native appearance.
  +    virtual bool isControlStyled(const RenderStyle* style, const BorderData& border, 
  +                                 const BackgroundLayer& background, const QColor& backgroundColor) const;
  +
  +    // A general method asking if any control tinting is supported at all.
       virtual bool supportsControlTints() const { return false; }
   
       // Some controls may spill out of their containers (e.g., the check on an OS X checkbox).  When these controls repaint,
  
  
  
  1.9       +3 -3      WebCore/khtml/rendering/render_theme_mac.h
  
  Index: render_theme_mac.h
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/rendering/render_theme_mac.h,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- render_theme_mac.h	22 Oct 2005 18:19:27 -0000	1.8
  +++ render_theme_mac.h	28 Oct 2005 07:03:26 -0000	1.9
  @@ -34,15 +34,15 @@
       RenderThemeMac();
       virtual ~RenderThemeMac() { /* Have to just leak the cells, since statics are destroyed with no autorelease pool available */ }
   
  -    // An API to obtain the baseline position for a "leaf" control.  This will only be used if a baseline
  +    // A method to obtain the baseline position for a "leaf" control.  This will only be used if a baseline
       // position cannot be determined by examining child content. Checkboxes and radio buttons are examples of
       // controls that need to do this.
       virtual short baselinePosition(const RenderObject* o) const;
   
  -    // An API asking if the control changes its tint when the window has focus or not.
  +    // A method asking if the control changes its tint when the window has focus or not.
       virtual bool controlSupportsTints(const RenderObject* o) const;
   
  -    // A general API asking if any control tinting is supported at all.
  +    // A general method asking if any control tinting is supported at all.
       virtual bool supportsControlTints() const { return true; }
   
       virtual void adjustRepaintRect(const RenderObject* o, QRect& r);
  
  
  
  1.14      +46 -48    WebCore/khtml/rendering/render_theme_mac.mm
  
  Index: render_theme_mac.mm
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/rendering/render_theme_mac.mm,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- render_theme_mac.mm	26 Oct 2005 19:44:07 -0000	1.13
  +++ render_theme_mac.mm	28 Oct 2005 07:03:26 -0000	1.14
  @@ -408,30 +408,34 @@
   
       // Add in intrinsic margins
       addIntrinsicMargins(style, controlSize);
  -            
  -    // Whenever a button has a background or border specified, then appearance is disabled.
  -    bool disableAppearance = style->hasBorder() || style->hasBackground();
  -    if (!disableAppearance) {
  -        if (style->appearance() == PushButtonAppearance) {
  -            // Height is locked to auto.
  -            style->setHeight(Length(Auto));
  -            
  -            // White-space is locked to nowrap
  -            style->setWhiteSpace(PRE);
   
  -            // Set the button's vertical size.
  -            setButtonSize(style);
  +    if (style->appearance() == PushButtonAppearance) {
  +        // Ditch the border.
  +        style->resetBorder();
  +
  +        // Height is locked to auto.
  +        style->setHeight(Length(Auto));
  +        
  +        // White-space is locked to nowrap
  +        style->setWhiteSpace(PRE);
   
  -            // Add in the padding that we'd like to use.
  -            setButtonPaddingFromControlSize(style, controlSize);
  +        // Set the button's vertical size.
  +        setButtonSize(style);
   
  -            // Our font is locked to the appropriate system font size for the control.  To clarify, we first use the CSS-specified font to figure out
  -            // a reasonable control size, but once that control size is determined, we throw that font away and use the appropriate
  -            // system font for the control size instead.
  -            setFontFromControlSize(selector, style, controlSize);
  -        } else
  -            // Set a min-height so that we can't get smaller than the mini button.
  -            style->setMinHeight(Length(15, Fixed));
  +        // Add in the padding that we'd like to use.
  +        setButtonPaddingFromControlSize(style, controlSize);
  +
  +        // Our font is locked to the appropriate system font size for the control.  To clarify, we first use the CSS-specified font to figure out
  +        // a reasonable control size, but once that control size is determined, we throw that font away and use the appropriate
  +        // system font for the control size instead.
  +        setFontFromControlSize(selector, style, controlSize);
  +    } else {
  +        // Set a min-height so that we can't get smaller than the mini button.
  +        style->setMinHeight(Length(15, Fixed));
  +        
  +        // Reset the top and bottom borders.
  +        style->resetBorderTop();
  +        style->resetBorderBottom();
       }
   }
   
  @@ -472,7 +476,6 @@
   
       // Set the control size based off the rectangle we're painting into.
       if (o->style()->appearance() == SquareButtonAppearance ||
  -        o->style()->hasBorder() || 
           r.height() > buttonSizes()[NSRegularControlSize].height()) {
           // Use the square button
           if ([button bezelStyle] != NSShadowlessSquareBezelStyle)
  @@ -490,35 +493,30 @@
   }
   
   bool RenderThemeMac::paintButton(RenderObject* o, const RenderObject::PaintInfo& i, const QRect& r)
  -{
  -    bool hasBorder = o->style()->hasBorder();
  -    bool hasBackground = o->style()->hasBackground();
  +{    
  +    // Determine the width and height needed for the control and prepare the cell for painting.
  +    setButtonCellState(o, r);
       
  -    if (!hasBackground) {
  -        // Determine the width and height needed for the control and prepare the cell for painting.
  -        setButtonCellState(o, r);
  -        
  -        // We inflate the rect as needed to account for padding included in the cell to accommodate the button
  -        // shadow.  We don't consider this part of the bounds of the control in WebKit.
  -        QSize size = buttonSizes()[[button controlSize]];
  -        size.setWidth(r.width());
  -        QRect inflatedRect = r;
  -        if ([button bezelStyle] == NSRoundedBezelStyle) {
  -            // Center the button within the available space.
  -            if (inflatedRect.height() > size.height()) {
  -                inflatedRect.setX(inflatedRect.x() + (inflatedRect.height() - size.height())/2);
  -                inflatedRect.setHeight(size.height());
  -            }
  -            
  -            // Now inflate it to account for the shadow.
  -            inflatedRect = inflateRect(inflatedRect, size, buttonMargins());
  +    // We inflate the rect as needed to account for padding included in the cell to accommodate the button
  +    // shadow.  We don't consider this part of the bounds of the control in WebKit.
  +    QSize size = buttonSizes()[[button controlSize]];
  +    size.setWidth(r.width());
  +    QRect inflatedRect = r;
  +    if ([button bezelStyle] == NSRoundedBezelStyle) {
  +        // Center the button within the available space.
  +        if (inflatedRect.height() > size.height()) {
  +            inflatedRect.setX(inflatedRect.x() + (inflatedRect.height() - size.height())/2);
  +            inflatedRect.setHeight(size.height());
           }
  -
  -        [button drawWithFrame:NSRect(inflatedRect) inView:o->canvas()->view()->getDocumentView()];
  -        [button setControlView: nil];
  +        
  +        // Now inflate it to account for the shadow.
  +        inflatedRect = inflateRect(inflatedRect, size, buttonMargins());
       }
  -    
  -    return hasBorder || hasBackground;
  +
  +    [button drawWithFrame:NSRect(inflatedRect) inView:o->canvas()->view()->getDocumentView()];
  +    [button setControlView: nil];
  +
  +    return false;
   }
   
   }
  
  
  



More information about the webkit-changes mailing list