Changeset 134935 in webkit


Ignore:
Timestamp:
Nov 16, 2012, 5:32:18 AM (13 years ago)
Author:
jchaffraix@webkit.org
Message:

RenderGrid should have a function to resolve grid position
https://bugs.webkit.org/show_bug.cgi?id=102441

Reviewed by Ojan Vafai.

The code was doing this conversion implicitly inside RenderGrid::findChildLogicalPosition.
Also note that we also provided a fallback by returning LayoutPoint() (ie the (0, 0) position
on the grid) if we couldn't handle the value. The explicit conversion is needed in order to
support render areas and add a proper grid model to RenderGrid.

No expected change in behavior.

  • rendering/RenderGrid.h:
  • rendering/RenderGrid.cpp:

(WebCore::RenderGrid::resolveGridPosition):
Added this new function to handle the conversion. We re-use Length but should never see
a lot of the <length> values so I added some ASSERTs to enforce and catch that.

(WebCore::RenderGrid::findChildLogicalPosition):
Simplified the function now that it just use resolveGridPosition.

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r134934 r134935  
     12012-11-16  Julien Chaffraix  <jchaffraix@webkit.org>
     2
     3        RenderGrid should have a function to resolve grid position
     4        https://bugs.webkit.org/show_bug.cgi?id=102441
     5
     6        Reviewed by Ojan Vafai.
     7
     8        The code was doing this conversion implicitly inside RenderGrid::findChildLogicalPosition.
     9        Also note that we also provided a fallback by returning LayoutPoint() (ie the (0, 0) position
     10        on the grid) if we couldn't handle the value. The explicit conversion is needed in order to
     11        support render areas and add a proper grid model to RenderGrid.
     12
     13        No expected change in behavior.
     14
     15        * rendering/RenderGrid.h:
     16        * rendering/RenderGrid.cpp:
     17        (WebCore::RenderGrid::resolveGridPosition):
     18        Added this new function to handle the conversion. We re-use Length but should never see
     19        a lot of the <length> values so I added some ASSERTs to enforce and catch that.
     20
     21        (WebCore::RenderGrid::findChildLogicalPosition):
     22        Simplified the function now that it just use resolveGridPosition.
     23
    1242012-11-16  Ulan Degenbaev  <ulan@chromium.org>
    225
  • trunk/Source/WebCore/rendering/RenderGrid.cpp

    r131050 r134935  
    176176}
    177177
     178size_t RenderGrid::resolveGridPosition(const Length& position) const
     179{
     180    // FIXME: Handle other values for grid-{row,column} like ranges or line names.
     181    switch (position.type()) {
     182    case Fixed:
     183        // FIXME: What does a non-positive integer mean for a column/row?
     184        if (!position.isPositive())
     185            return 0;
     186
     187        return position.intValue() - 1;
     188    case Auto:
     189        // FIXME: We should follow 'grid-auto-flow' for resolution.
     190        // Until then, we use the 'grid-auto-flow: none' behavior (which is the default)
     191        // and resolve 'auto' as the first row / column.
     192        return 0;
     193    case Relative:
     194    case Percent:
     195    case Intrinsic:
     196    case MinIntrinsic:
     197    case MinContent:
     198    case MaxContent:
     199    case FillAvailable:
     200    case FitContent:
     201    case Calculated:
     202    case ViewportPercentageWidth:
     203    case ViewportPercentageHeight:
     204    case ViewportPercentageMin:
     205    case Undefined:
     206        break;
     207    }
     208    ASSERT_NOT_REACHED();
     209    return 0;
     210}
     211
    178212LayoutPoint RenderGrid::findChildLogicalPosition(RenderBox* child, const Vector<GridTrack>& columnTracks, const Vector<GridTrack>& rowTracks)
    179213{
    180     Length column = child->style()->gridItemColumn();
    181     Length row = child->style()->gridItemRow();
    182 
    183     // FIXME: What does a non-positive integer mean for a column/row?
    184     if (!column.isPositive() || !row.isPositive())
    185         return LayoutPoint();
    186 
    187     // FIXME: Handle other values for grid-{row,column} like ranges or line names.
    188     if (!column.isFixed() || !row.isFixed())
    189         return LayoutPoint();
    190 
    191     size_t columnTrack = static_cast<size_t>(column.intValue()) - 1;
    192     size_t rowTrack = static_cast<size_t>(row.intValue()) - 1;
     214    size_t columnTrack = resolveGridPosition(child->style()->gridItemColumn());
     215    size_t rowTrack = resolveGridPosition(child->style()->gridItemRow());
    193216
    194217    LayoutPoint offset;
     218    // FIXME: |columnTrack| and |rowTrack| should be smaller than our column / row count.
    195219    for (size_t i = 0; i < columnTrack && i < columnTracks.size(); ++i)
    196220        offset.setX(offset.x() + columnTracks[i].m_usedBreadth);
  • trunk/Source/WebCore/rendering/RenderGrid.h

    r126071 r134935  
    5151
    5252    LayoutPoint findChildLogicalPosition(RenderBox*, const Vector<GridTrack>& columnTracks, const Vector<GridTrack>& rowTracks);
     53    size_t resolveGridPosition(const Length&) const;
    5354};
    5455
Note: See TracChangeset for help on using the changeset viewer.