Changeset 139329 in webkit


Ignore:
Timestamp:
Jan 10, 2013, 10:08:36 AM (12 years ago)
Author:
ojan@chromium.org
Message:

intrinsic min-widths don't override width for file upload controls
https://bugs.webkit.org/show_bug.cgi?id=106517

Reviewed by Tony Chang.

Source/WebCore:

Separate out computing intrinsic width from perferred width so that
we can use the intrinsic width correctly when applying min-width/max-width.
The preferred width is the width used in its container's computation
of its intrinsic width.

This is the first in a series of patches making this work across
the render tree.

Test: fast/forms/file/intrinsic-min-width-overrides-width.html

  • rendering/RenderBox.cpp:

(WebCore::RenderBox::minIntrinsicLogicalWidth):
(WebCore):
(WebCore::RenderBox::maxIntrinsicLogicalWidth):
(WebCore::RenderBox::computeIntrinsicLogicalWidths):
(WebCore::RenderBox::computeLogicalWidthInRegionUsing):

  • rendering/RenderBox.h:

(RenderBox):

  • rendering/RenderFileUploadControl.cpp:

(WebCore::RenderFileUploadControl::computeIntrinsicLogicalWidths):
(WebCore):
(WebCore::RenderFileUploadControl::computePreferredLogicalWidths):

  • rendering/RenderFileUploadControl.h:

(RenderFileUploadControl):

LayoutTests:

  • fast/forms/file/intrinsic-min-width-overrides-width-expected.html: Added.
  • fast/forms/file/intrinsic-min-width-overrides-width.html: Added.
Location:
trunk
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r139328 r139329  
     12013-01-09  Ojan Vafai  <ojan@chromium.org>
     2
     3        intrinsic min-widths don't override width for file upload controls
     4        https://bugs.webkit.org/show_bug.cgi?id=106517
     5
     6        Reviewed by Tony Chang.
     7
     8        * fast/forms/file/intrinsic-min-width-overrides-width-expected.html: Added.
     9        * fast/forms/file/intrinsic-min-width-overrides-width.html: Added.
     10
    1112013-01-10  Florin Malita  <fmalita@chromium.org>
    212
  • trunk/Source/WebCore/ChangeLog

    r139326 r139329  
     12013-01-09  Ojan Vafai  <ojan@chromium.org>
     2
     3        intrinsic min-widths don't override width for file upload controls
     4        https://bugs.webkit.org/show_bug.cgi?id=106517
     5
     6        Reviewed by Tony Chang.
     7
     8        Separate out computing intrinsic width from perferred width so that
     9        we can use the intrinsic width correctly when applying min-width/max-width.
     10        The preferred width is the width used in its container's computation
     11        of its intrinsic width.
     12
     13        This is the first in a series of patches making this work across
     14        the render tree.
     15
     16        Test: fast/forms/file/intrinsic-min-width-overrides-width.html
     17
     18        * rendering/RenderBox.cpp:
     19        (WebCore::RenderBox::minIntrinsicLogicalWidth):
     20        (WebCore):
     21        (WebCore::RenderBox::maxIntrinsicLogicalWidth):
     22        (WebCore::RenderBox::computeIntrinsicLogicalWidths):
     23        (WebCore::RenderBox::computeLogicalWidthInRegionUsing):
     24        * rendering/RenderBox.h:
     25        (RenderBox):
     26        * rendering/RenderFileUploadControl.cpp:
     27        (WebCore::RenderFileUploadControl::computeIntrinsicLogicalWidths):
     28        (WebCore):
     29        (WebCore::RenderFileUploadControl::computePreferredLogicalWidths):
     30        * rendering/RenderFileUploadControl.h:
     31        (RenderFileUploadControl):
     32
    1332013-01-10  Victor Carbune  <victor@rosedu.org>
    234
  • trunk/Source/WebCore/rendering/RenderBox.cpp

    r139137 r139329  
    792792}
    793793
     794LayoutUnit RenderBox::minIntrinsicLogicalWidth() const
     795{
     796    LayoutUnit minLogicalWidth = 0;
     797    LayoutUnit maxLogicalWidth = 0;
     798    computeIntrinsicLogicalWidths(minLogicalWidth, maxLogicalWidth);
     799    return minLogicalWidth + borderAndPaddingLogicalWidth();
     800}
     801
     802LayoutUnit RenderBox::maxIntrinsicLogicalWidth() const
     803{
     804    LayoutUnit minLogicalWidth = 0;
     805    LayoutUnit maxLogicalWidth = 0;
     806    computeIntrinsicLogicalWidths(minLogicalWidth, maxLogicalWidth);
     807    return maxLogicalWidth + borderAndPaddingLogicalWidth();
     808}
     809
     810void RenderBox::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const
     811{
     812    minLogicalWidth = minPreferredLogicalWidth() - borderAndPaddingLogicalWidth();
     813    maxLogicalWidth = maxPreferredLogicalWidth() - borderAndPaddingLogicalWidth();
     814}
     815
    794816LayoutUnit RenderBox::minPreferredLogicalWidth() const
    795817{
     
    19962018
    19972019    if (logicalWidth.type() == MinContent)
    1998         return minPreferredLogicalWidth();
     2020        return minIntrinsicLogicalWidth();
    19992021    if (logicalWidth.type() == MaxContent)
    2000         return maxPreferredLogicalWidth();
     2022        return maxIntrinsicLogicalWidth();
    20012023
    20022024    RenderView* renderView = view();
  • trunk/Source/WebCore/rendering/RenderBox.h

    r139044 r139329  
    295295    virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) OVERRIDE;
    296296
     297    LayoutUnit minIntrinsicLogicalWidth() const;
     298    LayoutUnit maxIntrinsicLogicalWidth() const;
     299
    297300    virtual LayoutUnit minPreferredLogicalWidth() const;
    298301    virtual LayoutUnit maxPreferredLogicalWidth() const;
     
    651654    void computePositionedLogicalWidthReplaced(LogicalExtentComputedValues&) const;
    652655
     656    virtual void computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const;
     657
    653658    // This function calculates the minimum and maximum preferred widths for an object.
    654659    // These values are used in shrink-to-fit layout systems.
  • trunk/Source/WebCore/rendering/RenderFileUploadControl.cpp

    r139216 r139329  
    165165}
    166166
     167void RenderFileUploadControl::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const
     168{
     169    // Figure out how big the filename space needs to be for a given number of characters
     170    // (using "0" as the nominal character).
     171    const UChar character = '0';
     172    const String characterAsString = String(&character, 1);
     173    const Font& font = style()->font();
     174    // FIXME: Remove the need for this const_cast by making constructTextRun take a const RenderObject*.
     175    RenderFileUploadControl* renderer = const_cast<RenderFileUploadControl*>(this);
     176    float minDefaultLabelWidth = defaultWidthNumChars * font.width(constructTextRun(renderer, font, characterAsString, style(), TextRun::AllowTrailingExpansion));
     177
     178    const String label = theme()->fileListDefaultLabel(node()->toInputElement()->multiple());
     179    float defaultLabelWidth = font.width(constructTextRun(renderer, font, label, style(), TextRun::AllowTrailingExpansion));
     180    if (HTMLInputElement* button = uploadButton())
     181        if (RenderObject* buttonRenderer = button->renderer())
     182            defaultLabelWidth += buttonRenderer->maxPreferredLogicalWidth() + afterButtonSpacing;
     183    maxLogicalWidth = static_cast<int>(ceilf(max(minDefaultLabelWidth, defaultLabelWidth)));
     184
     185    if (!style()->width().isPercent())
     186        minLogicalWidth = maxLogicalWidth;
     187}
     188
    167189void RenderFileUploadControl::computePreferredLogicalWidths()
    168190{
     
    172194    m_maxPreferredLogicalWidth = 0;
    173195
    174     RenderStyle* style = this->style();
    175     ASSERT(style);
    176 
    177     const Font& font = style->font();
    178     if (style->width().isFixed() && style->width().value() > 0)
    179         m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = adjustContentBoxLogicalWidthForBoxSizing(style->width().value());
    180     else {
    181         // Figure out how big the filename space needs to be for a given number of characters
    182         // (using "0" as the nominal character).
    183         const UChar character = '0';
    184         const String characterAsString = String(&character, 1);
    185         float minDefaultLabelWidth = defaultWidthNumChars * font.width(constructTextRun(this, font, characterAsString, style, TextRun::AllowTrailingExpansion));
    186 
    187         const String label = theme()->fileListDefaultLabel(node()->toInputElement()->multiple());
    188         float defaultLabelWidth = font.width(constructTextRun(this, font, label, style, TextRun::AllowTrailingExpansion));
    189         if (HTMLInputElement* button = uploadButton())
    190             if (RenderObject* buttonRenderer = button->renderer())
    191                 defaultLabelWidth += buttonRenderer->maxPreferredLogicalWidth() + afterButtonSpacing;
    192         m_maxPreferredLogicalWidth = static_cast<int>(ceilf(max(minDefaultLabelWidth, defaultLabelWidth)));
    193 
    194         if (!style->width().isPercent())
    195             m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth;
    196     }
    197 
    198     if (style->minWidth().isFixed() && style->minWidth().value() > 0) {
    199         m_maxPreferredLogicalWidth = max(m_maxPreferredLogicalWidth, adjustContentBoxLogicalWidthForBoxSizing(style->minWidth().value()));
    200         m_minPreferredLogicalWidth = max(m_minPreferredLogicalWidth, adjustContentBoxLogicalWidthForBoxSizing(style->minWidth().value()));
    201     }
    202 
    203     if (style->maxWidth().isFixed()) {
    204         m_maxPreferredLogicalWidth = min(m_maxPreferredLogicalWidth, adjustContentBoxLogicalWidthForBoxSizing(style->maxWidth().value()));
    205         m_minPreferredLogicalWidth = min(m_minPreferredLogicalWidth, adjustContentBoxLogicalWidthForBoxSizing(style->maxWidth().value()));
     196    if (style()->width().isFixed() && style()->width().value() > 0)
     197        m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = adjustContentBoxLogicalWidthForBoxSizing(style()->width().value());
     198    else
     199        computeIntrinsicLogicalWidths(m_minPreferredLogicalWidth, m_maxPreferredLogicalWidth);
     200
     201    if (style()->minWidth().isFixed() && style()->minWidth().value() > 0) {
     202        m_maxPreferredLogicalWidth = max(m_maxPreferredLogicalWidth, adjustContentBoxLogicalWidthForBoxSizing(style()->minWidth().value()));
     203        m_minPreferredLogicalWidth = max(m_minPreferredLogicalWidth, adjustContentBoxLogicalWidthForBoxSizing(style()->minWidth().value()));
     204    }
     205
     206    if (style()->maxWidth().isFixed()) {
     207        m_maxPreferredLogicalWidth = min(m_maxPreferredLogicalWidth, adjustContentBoxLogicalWidthForBoxSizing(style()->maxWidth().value()));
     208        m_minPreferredLogicalWidth = min(m_minPreferredLogicalWidth, adjustContentBoxLogicalWidthForBoxSizing(style()->maxWidth().value()));
    206209    }
    207210
  • trunk/Source/WebCore/rendering/RenderFileUploadControl.h

    r124556 r139329  
    4747    virtual bool canBeReplacedWithInlineRunIn() const OVERRIDE;
    4848    virtual void updateFromElement();
     49    virtual void computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const OVERRIDE;
    4950    virtual void computePreferredLogicalWidths();
    5051    virtual void paintObject(PaintInfo&, const LayoutPoint&);
Note: See TracChangeset for help on using the changeset viewer.