Changeset 10909 in webkit


Ignore:
Timestamp:
Oct 22, 2005, 11:19:27 AM (20 years ago)
Author:
hyatt
Message:

Reviewed by darin

  • khtml/css/cssstyleselector.cpp: Add support for the GrayText CSS2 system color to represent the disabled text color for controls.
  • khtml/css/html4.css: Make sure that the default cursor is set for all types of buttons and not just the HTML4 button.

Set the foreground color for buttons using the CSS2 system color.
Set the disabled text color using the CSS2 system color.

Move the default padding for buttons into the CSS file. It will
get overridden by Aqua buttons but be honored by all other types
of buttons. This allows the author to override it as well when
customizing.

  • khtml/rendering/render_block.h: Make paintChildren virtual so that RenderButton can push a clip and pop a clip when painting children.
  • khtml/rendering/render_box.cpp: (RenderBox::paintBoxDecorations): Let the theme now decide whether the border/background should still be painted after the theme has painted. This allows buttons to paint custom borders but still use a pretty OS X background for the button face.
  • khtml/rendering/render_button.cpp: (khtml::RenderButton::paintChildren): Overridden to push/pop a clip so that the contents of a button don't ever spill out.
  • khtml/rendering/render_button.h: Added paintChildren method.
  • khtml/rendering/render_style.h: (khtml::BorderData::hasBorder): Fixed a regression in hasBorder. The border-image logic was inverted, resulting in hasBorder being true for every element!
  • khtml/rendering/render_theme.cpp: (khtml::RenderTheme::paint): Patched to return a boolean indicating whether or not the border/background should be painted.
  • khtml/rendering/render_theme.h:
  • khtml/rendering/render_theme_mac.h:
  • khtml/rendering/render_theme_mac.mm: (khtml::RenderThemeMac::adjustRepaintRect): Forgot to include radio and button in this method so that repaint rects would be correct.

(khtml::RenderThemeMac::paintCheckbox):
(khtml::RenderThemeMac::paintRadio):
Adjusted to return the boolean to indicate that painting of
border/background should not occur.

(khtml::RenderThemeMac::adjustButtonStyle):
Added support for border/background/colors. Also locked
white-space to nowrap for Aqua buttons to avoid line wrapping.

(khtml::RenderThemeMac::setButtonCellState):
(khtml::RenderThemeMac::paintButton):
More support for custom border/background/color.

Location:
trunk/WebCore
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog-2005-12-19

    r10903 r10909  
     12005-10-21  David Hyatt  <hyatt@apple.com>
     2
     3        Reviewed by darin
     4
     5        * khtml/css/cssstyleselector.cpp:
     6        Add support for the GrayText CSS2 system color to represent
     7        the disabled text color for controls.
     8       
     9        * khtml/css/html4.css:
     10        Make sure that the default cursor is set for all types of buttons
     11        and not just the HTML4 button.
     12
     13        Set the foreground color for buttons using the CSS2 system color.
     14        Set the disabled text color using the CSS2 system color.
     15
     16        Move the default padding for buttons into the CSS file.  It will
     17        get overridden by Aqua buttons but be honored by all other types
     18        of buttons.  This allows the author to override it as well when
     19        customizing.
     20       
     21        * khtml/rendering/render_block.h:
     22        Make paintChildren virtual so that RenderButton can push a clip
     23        and pop a clip when painting children.
     24       
     25        * khtml/rendering/render_box.cpp:
     26        (RenderBox::paintBoxDecorations):
     27        Let the theme now decide whether the border/background should
     28        still be painted after the theme has painted.  This allows buttons
     29        to paint custom borders but still use a pretty OS X background for
     30        the button face.
     31       
     32        * khtml/rendering/render_button.cpp:
     33        (khtml::RenderButton::paintChildren):
     34        Overridden to push/pop a clip so that the contents of a button
     35        don't ever spill out.
     36       
     37        * khtml/rendering/render_button.h:
     38        Added paintChildren method.
     39       
     40        * khtml/rendering/render_style.h:
     41        (khtml::BorderData::hasBorder):
     42        Fixed a regression in hasBorder.  The border-image logic was
     43        inverted, resulting in hasBorder being true for every element!
     44       
     45        * khtml/rendering/render_theme.cpp:
     46        (khtml::RenderTheme::paint):
     47        Patched to return a boolean indicating whether or not the
     48        border/background should be painted.
     49       
     50        * khtml/rendering/render_theme.h:
     51        * khtml/rendering/render_theme_mac.h:
     52        * khtml/rendering/render_theme_mac.mm:
     53        (khtml::RenderThemeMac::adjustRepaintRect):
     54        Forgot to include radio and button in this method so that repaint
     55        rects would be correct.
     56       
     57        (khtml::RenderThemeMac::paintCheckbox):
     58        (khtml::RenderThemeMac::paintRadio):
     59        Adjusted to return the boolean to indicate that painting of
     60        border/background should not occur.
     61       
     62        (khtml::RenderThemeMac::adjustButtonStyle):
     63        Added support for border/background/colors.  Also locked
     64        white-space to nowrap for Aqua buttons to avoid line wrapping.
     65       
     66        (khtml::RenderThemeMac::setButtonCellState):
     67        (khtml::RenderThemeMac::paintButton):
     68        More support for custom border/background/color.
     69       
    1702005-10-21  Geoffrey Garen  <ggaren@apple.com>
    271
  • trunk/WebCore/khtml/css/cssstyleselector.cpp

    r10888 r10909  
    747747    if (m_medium == "print")
    748748        matchRules(defaultPrintStyle, firstUARule, lastUARule);
    749    
     749
    750750    // 4. Now we check user sheet rules.
    751751    int firstUserRule = -1, lastUserRule = -1;
     
    16261626    { CSS_VAL_BUTTONTEXT, 0xFF000000 },
    16271627    { CSS_VAL_CAPTIONTEXT, 0xFF000000 },
    1628     { CSS_VAL_GRAYTEXT, 0xFF000000 },
     1628    { CSS_VAL_GRAYTEXT, 0xFF808080 },
    16291629    { CSS_VAL_HIGHLIGHT, 0xFFFFFFFF },
    16301630    { CSS_VAL_HIGHLIGHTTEXT, 0xFFFFFFFF },
  • trunk/WebCore/khtml/css/html4.css

    r10888 r10909  
    279279
    280280button {
    281     cursor: default;
    282     -khtml-appearance: button
     281    -khtml-appearance: button;
     282    white-space: normal
    283283}
    284284
     
    307307input[type="button"], input[type="submit"], input[type="reset"]
    308308{
    309     -khtml-appearance: push-button
     309    -khtml-appearance: push-button;
     310    white-space: pre;
     311    line-height: normal !important
    310312}
    311313
     
    313315    -khtml-box-align: center;
    314316    text-align:center;
     317    cursor: default;
     318    color: ButtonText;
     319    padding: 2px 8px 3px 8px
     320}
     321
     322input[type="button"]:disabled, input[type="submit"]:disabled, input[type="reset"]:disabled, button:disabled {
     323    color: GrayText;
    315324}
    316325
  • trunk/WebCore/khtml/rendering/render_box.cpp

    r10755 r10909  
    326326        mh = kMin(i.r.height(), h);
    327327
    328     // If we have a native theme appearance, use that instead of painting our border/background.
    329     if (style()->hasAppearance())
    330         return theme()->paint(this, i, QRect(_tx, _ty, w, h));
    331        
     328    // If we have a native theme appearance, paint that before painting our border/background.  The theme will
     329    // tell us whether or not we should also paint the CSS border/background.
     330    if (style()->hasAppearance() && !theme()->paint(this, i, QRect(_tx, _ty, w, h)))
     331        return;
     332
    332333    // The <body> only paints its background if the root element has defined a background
    333334    // independent of the body.  Go through the DOM to get to the root element's render object,
  • trunk/WebCore/khtml/rendering/render_button.cpp

    r10888 r10909  
    9494}
    9595
     96void RenderButton::paintObject(PaintInfo& i, int _tx, int _ty)
     97{
     98    // Push a clip.
     99    if (m_inner && i.phase == PaintActionForeground) {
     100        QRect clipRect(_tx + m_inner->xPos(), _ty + m_inner->yPos(), m_inner->width(), m_inner->height());
     101        clipRect = i.p->xForm(clipRect);
     102        i.p->save();
     103        i.p->addClip(clipRect);
     104    }
     105   
     106    // Paint the children.
     107    RenderBlock::paintObject(i, _tx, _ty);
     108   
     109    // Pop the clip.
     110    if (m_inner && i.phase == PaintActionForeground)
     111        i.p->restore();
    96112}
     113
     114}
  • trunk/WebCore/khtml/rendering/render_button.h

    r10888 r10909  
    4444    virtual void updateFromElement();
    4545
     46    void paintObject(PaintInfo& i, int _tx, int _ty);
     47
    4648    virtual const char *renderName() const { return "RenderButton"; }
    4749
  • trunk/WebCore/khtml/rendering/render_style.h

    r10888 r10909  
    315315    {
    316316        bool haveImage = image.hasImage();
    317         return left.nonZero(haveImage) || right.nonZero(haveImage) || top.nonZero(haveImage) || bottom.nonZero(haveImage);
     317        return left.nonZero(!haveImage) || right.nonZero(!haveImage) || top.nonZero(!haveImage) || bottom.nonZero(!haveImage);
    318318    }
    319319
  • trunk/WebCore/khtml/rendering/render_theme.cpp

    r10888 r10909  
    6060}
    6161
    62 void RenderTheme::paint(RenderObject* o, const RenderObject::PaintInfo& i, const QRect& r)
     62bool RenderTheme::paint(RenderObject* o, const RenderObject::PaintInfo& i, const QRect& r)
    6363{
    6464    // If painting is disabled, but we aren't updating control tints, then just bail.
     
    6868        if (controlSupportsTints(o))
    6969            o->repaint();
    70         return;
     70        return false;
    7171    }
    7272    if (i.p->paintingDisabled())
    73         return;
     73        return false;
    7474       
    7575    // Call the appropriate paint method based off the appearance value.
     
    8686            break;
    8787    }
     88   
     89    return false;
    8890}
    8991
  • trunk/WebCore/khtml/rendering/render_theme.h

    r10888 r10909  
    4949   
    5050    // This method is called to paint the widget as a background of the RenderObject.  A widget's foreground, e.g., the
    51     // text of a button, is always rendered by the engine itself.
    52     void paint(RenderObject* o, const RenderObject::PaintInfo& i, const QRect& r);
     51    // text of a button, is always rendered by the engine itself.  The boolean return value indicates
     52    // whether the CSS border/background should also be painted.
     53    bool paint(RenderObject* o, const RenderObject::PaintInfo& i, const QRect& r);
    5354
    5455    // The remaining methods should be implemented by the platform-specific portion of the theme, e.g.,
     
    9192    // Methods for each appearance value.
    9293    virtual void adjustCheckboxStyle(CSSStyleSelector* selector, RenderStyle* style, DOM::ElementImpl* e) const;
    93     virtual void paintCheckbox(RenderObject* o, const RenderObject::PaintInfo& i, const QRect& r) = 0;
     94    virtual bool paintCheckbox(RenderObject* o, const RenderObject::PaintInfo& i, const QRect& r) = 0;
    9495    virtual void setCheckboxSize(RenderStyle* style) const {};
    9596   
    9697    virtual void adjustRadioStyle(CSSStyleSelector* selector, RenderStyle* style, DOM::ElementImpl* e) const;
    97     virtual void paintRadio(RenderObject* o, const RenderObject::PaintInfo& i, const QRect& r) = 0;
     98    virtual bool paintRadio(RenderObject* o, const RenderObject::PaintInfo& i, const QRect& r) = 0;
    9899    virtual void setRadioSize(RenderStyle* style) const {};
    99100   
    100101    virtual void adjustButtonStyle(CSSStyleSelector* selector, RenderStyle* style, DOM::ElementImpl* e) const;
    101     virtual void paintButton(RenderObject* o, const RenderObject::PaintInfo& i, const QRect& r) = 0;
     102    virtual bool paintButton(RenderObject* o, const RenderObject::PaintInfo& i, const QRect& r) = 0;
    102103    virtual void setButtonSize(RenderStyle* style) const {};
    103104};
  • trunk/WebCore/khtml/rendering/render_theme_mac.h

    r10888 r10909  
    5050protected:
    5151    // Methods for each appearance value.
    52     virtual void paintCheckbox(RenderObject* o, const RenderObject::PaintInfo& i, const QRect& r);
     52    virtual bool paintCheckbox(RenderObject* o, const RenderObject::PaintInfo& i, const QRect& r);
    5353    virtual void setCheckboxSize(RenderStyle* style) const;
    5454   
    55     virtual void paintRadio(RenderObject* o, const RenderObject::PaintInfo& i, const QRect& r);
     55    virtual bool paintRadio(RenderObject* o, const RenderObject::PaintInfo& i, const QRect& r);
    5656    virtual void setRadioSize(RenderStyle* style) const;
    5757   
    5858    virtual void adjustButtonStyle(CSSStyleSelector* selector, RenderStyle* style, DOM::ElementImpl* e) const;
    59     virtual void paintButton(RenderObject* o, const RenderObject::PaintInfo& i, const QRect& r);
     59    virtual bool paintButton(RenderObject* o, const RenderObject::PaintInfo& i, const QRect& r);
    6060    virtual void setButtonSize(RenderStyle* style) const;
    6161
  • trunk/WebCore/khtml/rendering/render_theme_mac.mm

    r10894 r10909  
    5656void RenderThemeMac::adjustRepaintRect(const RenderObject* o, QRect& r)
    5757{
    58     if (o->style()->appearance() == CheckboxAppearance) {
    59         // Since we query the prototype cell, we need to update its state to match.
    60         setCheckboxCellState(o, r);
    61    
    62         // We inflate the rect as needed to account for padding included in the cell to accommodate the checkbox
    63         // shadow" and the check.  We don't consider this part of the bounds of the control in WebKit.
    64         r = inflateRect(r, checkboxSizes()[[checkbox controlSize]], checkboxMargins());
     58    switch (o->style()->appearance()) {
     59        case CheckboxAppearance: {
     60            // Since we query the prototype cell, we need to update its state to match.
     61            setCheckboxCellState(o, r);
     62       
     63            // We inflate the rect as needed to account for padding included in the cell to accommodate the checkbox
     64            // shadow" and the check.  We don't consider this part of the bounds of the control in WebKit.
     65            r = inflateRect(r, checkboxSizes()[[checkbox controlSize]], checkboxMargins());
     66            break;
     67        }
     68        case RadioAppearance: {
     69            // Since we query the prototype cell, we need to update its state to match.
     70            setRadioCellState(o, r);
     71       
     72            // We inflate the rect as needed to account for padding included in the cell to accommodate the checkbox
     73            // shadow" and the check.  We don't consider this part of the bounds of the control in WebKit.
     74            r = inflateRect(r, radioSizes()[[radio controlSize]], radioMargins());
     75            break;
     76        }
     77        case PushButtonAppearance:
     78        case ButtonAppearance: {
     79            // Since we query the prototype cell, we need to update its state to match.
     80            setButtonCellState(o, r);
     81       
     82            // We inflate the rect as needed to account for padding included in the cell to accommodate the checkbox
     83            // shadow" and the check.  We don't consider this part of the bounds of the control in WebKit.
     84            if ([button bezelStyle] == NSRoundedBezelStyle)
     85                r = inflateRect(r, buttonSizes()[[button controlSize]], buttonMargins());
     86            break;
     87        }
     88        default:
     89            break;
    6590    }
    6691}
     
    217242}
    218243
    219 void RenderThemeMac::paintCheckbox(RenderObject* o, const RenderObject::PaintInfo& i, const QRect& r)
     244bool RenderThemeMac::paintCheckbox(RenderObject* o, const RenderObject::PaintInfo& i, const QRect& r)
    220245{
    221246    // Determine the width and height needed for the control and prepare the cell for painting.
     
    227252    [checkbox drawWithFrame:NSRect(inflatedRect) inView:o->canvas()->view()->getDocumentView()];
    228253    [checkbox setControlView: nil];
     254   
     255    return false;
    229256}
    230257
     
    274301}
    275302
    276 void RenderThemeMac::paintRadio(RenderObject* o, const RenderObject::PaintInfo& i, const QRect& r)
     303bool RenderThemeMac::paintRadio(RenderObject* o, const RenderObject::PaintInfo& i, const QRect& r)
    277304{
    278305    // Determine the width and height needed for the control and prepare the cell for painting.
     
    284311    [radio drawWithFrame:NSRect(inflatedRect) inView:o->canvas()->view()->getDocumentView()];
    285312    [radio setControlView: nil];
     313   
     314    return false;
    286315}
    287316
     
    358387    // There are three appearance constants for buttons.
    359388    // (1) Push-button is the constant for the default Aqua system button.  Push buttons will not scale vertically and will not allow
    360     // custom fonts or colors.  <input>s use this constant.  The fundamental rule for push-button is that we will never display a push-button
    361     // that looks "half-Aqua."  Either the button will look perfectly native, or it will turn off the Aqua look completely.
     389    // custom fonts or colors.  <input>s use this constant.  This button will allow custom colors and font weights/variants but won't
     390    // scale vertically.
    362391    // (2) square-button is the constant for the square button.  This button will allow custom fonts and colors and will scale vertically.
    363392    // (3) Button is the constant that means "pick the best button as appropriate."  <button>s use this constant.  This button will
     
    372401           
    373402    // Whenever a button has a background or border specified, then appearance is disabled.
    374     // FIXME: We can't support the disabling of appearance yet until box-sizing is fully implemented.
    375     bool disableAppearance = false; // style->hasBorder() || style->hasBackground();
     403    // FIXME: We need to support box-sizing properly on bordered buttons!  They end up too big right now!
     404    bool disableAppearance = style->hasBorder() || style->hasBackground();
    376405    if (!disableAppearance) {
    377         // FIXME: This line is temporary. It can go away once the presence of a border really disables appearance.
    378         style->resetBorder();
    379      
    380406        if (style->appearance() == PushButtonAppearance) {
    381             // Color is locked to black.
    382             if (!e || e->isEnabled())
    383                 style->setColor(Qt::black);
    384             else
    385                 style->setColor(QColor(128,128,128));
    386 
    387407            // Height is locked to auto.
    388408            style->setHeight(Length(Auto));
    389409           
     410            // White-space is locked to nowrap
     411            style->setWhiteSpace(PRE);
     412
    390413            // Set the button's vertical size.
    391414            setButtonSize(style);
     
    399422            setFontFromControlSize(selector, style, controlSize);
    400423        } else {
    401             // Reset padding to a sensible size.
    402             // FIXME: Honor author's padding if it's set.
    403             style->setPaddingLeft(Length(8, Fixed));
    404             style->setPaddingRight(Length(8, Fixed));
    405             style->setPaddingTop(Length(2, Fixed));
    406             style->setPaddingBottom(Length(3, Fixed));
    407            
    408424            // Set a min-height so that we can't get smaller than the mini button.
    409425            // FIXME: Once we support box-sizing, we'll have to change this value to include the padding.
    410426            style->setMinHeight(Length(10, Fixed));
    411 
    412             // Color is locked to black.
    413             // FIXME: Honor author's color if it's set.
    414             if (!e || e->isEnabled())
    415                 style->setColor(Qt::black);
    416             else
    417                 style->setColor(QColor(128,128,128));
    418427        }
    419     } else {
    420         // FIXME: We're going to have to make sure some sort of decent padding/border/background is in effect when the appearance gets turned off.
    421         // We will need to know whether or not the user set these, and then fill in the ones that weren't set.
    422     }
    423 
     428    }
    424429}
    425430
     
    460465
    461466    // Set the control size based off the rectangle we're painting into.
    462     if (o->style()->appearance() == SquareButtonAppearance || r.height() > buttonSizes()[NSRegularControlSize].height()) {
     467    if (o->style()->appearance() == SquareButtonAppearance ||
     468        o->style()->hasBorder() ||
     469        r.height() > buttonSizes()[NSRegularControlSize].height()) {
    463470        // Use the square button
    464471        if ([button bezelStyle] != NSShadowlessSquareBezelStyle)
     
    476483}
    477484
    478 void RenderThemeMac::paintButton(RenderObject* o, const RenderObject::PaintInfo& i, const QRect& r)
    479 {
    480     // Determine the width and height needed for the control and prepare the cell for painting.
    481     setButtonCellState(o, r);
    482    
    483     // We inflate the rect as needed to account for padding included in the cell to accommodate the button
    484     // shadow.  We don't consider this part of the bounds of the control in WebKit.
    485     QSize size = buttonSizes()[[button controlSize]];
    486     size.setWidth(r.width());
    487     QRect inflatedRect = r;
    488     if ([button bezelStyle] == NSRoundedBezelStyle) {
    489         // Center the button within the available space.
    490         if (inflatedRect.height() > size.height()) {
    491             inflatedRect.setX(inflatedRect.x() + (inflatedRect.height() - size.height())/2);
    492             inflatedRect.setHeight(size.height());
     485bool RenderThemeMac::paintButton(RenderObject* o, const RenderObject::PaintInfo& i, const QRect& r)
     486{
     487    bool hasBorder = o->style()->hasBorder();
     488    bool hasBackground = o->style()->hasBackground();
     489   
     490    if (!hasBackground) {
     491        // Determine the width and height needed for the control and prepare the cell for painting.
     492        setButtonCellState(o, r);
     493       
     494        // We inflate the rect as needed to account for padding included in the cell to accommodate the button
     495        // shadow.  We don't consider this part of the bounds of the control in WebKit.
     496        QSize size = buttonSizes()[[button controlSize]];
     497        size.setWidth(r.width());
     498        QRect inflatedRect = r;
     499        if ([button bezelStyle] == NSRoundedBezelStyle) {
     500            // Center the button within the available space.
     501            if (inflatedRect.height() > size.height()) {
     502                inflatedRect.setX(inflatedRect.x() + (inflatedRect.height() - size.height())/2);
     503                inflatedRect.setHeight(size.height());
     504            }
     505           
     506            // Now inflate it to account for the shadow.
     507            inflatedRect = inflateRect(inflatedRect, size, buttonMargins());
    493508        }
    494        
    495         // Now inflate it to account for the shadow.
    496         inflatedRect = inflateRect(inflatedRect, size, buttonMargins());
    497     }
    498     [button drawWithFrame:NSRect(inflatedRect) inView:o->canvas()->view()->getDocumentView()];
    499     [button setControlView: nil];
    500 }
    501 
    502 }
     509
     510        [button drawWithFrame:NSRect(inflatedRect) inView:o->canvas()->view()->getDocumentView()];
     511        [button setControlView: nil];
     512    }
     513   
     514    return hasBorder || hasBackground;
     515}
     516
     517}
Note: See TracChangeset for help on using the changeset viewer.