Changeset 158115 in webkit


Ignore:
Timestamp:
Oct 28, 2013 10:35:52 AM (10 years ago)
Author:
svillar@igalia.com
Message:

[CSS Grid Layout] Add support for order inside grid items
https://bugs.webkit.org/show_bug.cgi?id=123208

Reviewed by Antti Koivisto.

Source/WebCore:

Based on Blink r153457 and r153536 by <jchaffraix@chromium.org>

Added support for sorting grid items by using -webkit-order
property. Used OrderIterator to implement it so it had to be moved
out of RenderFlexibleBox to be shared with RenderGrid.

Tests: fast/css-grid-layout/grid-item-order-auto-flow-resolution.html

fast/css-grid-layout/grid-item-order-paint-order.html

  • CMakeLists.txt: Added new file.
  • GNUmakefile.list.am: Ditto.
  • WebCore.vcxproj/WebCore.vcxproj: Ditto.
  • WebCore.xcodeproj/project.pbxproj: Ditto.
  • rendering/OrderIterator.cpp: Added. Ripped out of RenderFlexibleBox.

(WebCore::OrderIterator::OrderIterator):
(WebCore::OrderIterator::setOrderValues): Use std::move semantics.
(WebCore::OrderIterator::first): Use an integer as iterator.
(WebCore::OrderIterator::next): Ditto.
(WebCore::OrderIterator::reset): Ditto.

  • rendering/OrderIterator.h: Added.

(WebCore::OrderIterator::currentChild):

  • rendering/RenderFlexibleBox.cpp:

(WebCore::RenderFlexibleBox::RenderFlexibleBox):
(WebCore::RenderFlexibleBox::layoutBlock):

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

(WebCore::RenderGrid::RenderGrid):
(WebCore::RenderGrid::placeItemsOnGrid):
(WebCore::RenderGrid::populateExplicitGridAndOrderIterator):
(WebCore::RenderGrid::paintChildren):

  • rendering/RenderGrid.h:

LayoutTests:

From Blink r153536 by <jchaffraix@chromium.org>

Added a couple of tests to verify that we respect the specified
order of grid items both in the auto-placement algorithm and in
the final painting.

  • fast/css-grid-layout/grid-item-order-auto-flow-resolution-expected.txt: Added.
  • fast/css-grid-layout/grid-item-order-auto-flow-resolution.html: Added.
  • fast/css-grid-layout/grid-item-order-paint-order-expected.html: Added.
  • fast/css-grid-layout/grid-item-order-paint-order.html: Added.
Location:
trunk
Files:
6 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r158113 r158115  
     12013-10-28  Sergio Villar Senin  <svillar@igalia.com>
     2
     3        [CSS Grid Layout] Add support for order inside grid items
     4        https://bugs.webkit.org/show_bug.cgi?id=123208
     5
     6        Reviewed by Antti Koivisto.
     7
     8        From Blink r153536 by <jchaffraix@chromium.org>
     9
     10        Added a couple of tests to verify that we respect the specified
     11        order of grid items both in the auto-placement algorithm and in
     12        the final painting.
     13
     14        * fast/css-grid-layout/grid-item-order-auto-flow-resolution-expected.txt: Added.
     15        * fast/css-grid-layout/grid-item-order-auto-flow-resolution.html: Added.
     16        * fast/css-grid-layout/grid-item-order-paint-order-expected.html: Added.
     17        * fast/css-grid-layout/grid-item-order-paint-order.html: Added.
     18
    1192013-10-28  Afonso R. Costa Jr.  <afonso.costa@samsung.com>
    220
  • trunk/Source/WebCore/CMakeLists.txt

    r158018 r158115  
    20882088    rendering/LayoutState.cpp
    20892089    rendering/LineWidth.cpp
     2090    rendering/OrderIterator.cpp
    20902091    rendering/PointerEventsHitRules.cpp
    20912092    rendering/RenderArena.cpp
  • trunk/Source/WebCore/ChangeLog

    r158113 r158115  
     12013-10-28  Sergio Villar Senin  <svillar@igalia.com>
     2
     3        [CSS Grid Layout] Add support for order inside grid items
     4        https://bugs.webkit.org/show_bug.cgi?id=123208
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Based on Blink r153457 and r153536 by <jchaffraix@chromium.org>
     9
     10        Added support for sorting grid items by using -webkit-order
     11        property. Used OrderIterator to implement it so it had to be moved
     12        out of RenderFlexibleBox to be shared with RenderGrid.
     13
     14        Tests: fast/css-grid-layout/grid-item-order-auto-flow-resolution.html
     15               fast/css-grid-layout/grid-item-order-paint-order.html
     16
     17        * CMakeLists.txt: Added new file.
     18        * GNUmakefile.list.am: Ditto.
     19        * WebCore.vcxproj/WebCore.vcxproj: Ditto.
     20        * WebCore.xcodeproj/project.pbxproj: Ditto.
     21        * rendering/OrderIterator.cpp: Added. Ripped out of RenderFlexibleBox.
     22        (WebCore::OrderIterator::OrderIterator):
     23        (WebCore::OrderIterator::setOrderValues): Use std::move semantics.
     24        (WebCore::OrderIterator::first): Use an integer as iterator.
     25        (WebCore::OrderIterator::next): Ditto.
     26        (WebCore::OrderIterator::reset): Ditto.
     27        * rendering/OrderIterator.h: Added.
     28        (WebCore::OrderIterator::currentChild):
     29        * rendering/RenderFlexibleBox.cpp:
     30        (WebCore::RenderFlexibleBox::RenderFlexibleBox):
     31        (WebCore::RenderFlexibleBox::layoutBlock):
     32        * rendering/RenderFlexibleBox.h:
     33        * rendering/RenderGrid.cpp:
     34        (WebCore::RenderGrid::RenderGrid):
     35        (WebCore::RenderGrid::placeItemsOnGrid):
     36        (WebCore::RenderGrid::populateExplicitGridAndOrderIterator):
     37        (WebCore::RenderGrid::paintChildren):
     38        * rendering/RenderGrid.h:
     39
    1402013-10-28  Afonso R. Costa Jr.  <afonso.costa@samsung.com>
    241
  • trunk/Source/WebCore/GNUmakefile.list.am

    r157950 r158115  
    42994299        Source/WebCore/rendering/LineWidth.cpp \
    43004300        Source/WebCore/rendering/OverlapTestRequestClient.h \
     4301        Source/WebCore/rendering/OrderIterator.cpp \
     4302        Source/WebCore/rendering/OrderIterator.h \
    43014303        Source/WebCore/rendering/Pagination.h \
    43024304        Source/WebCore/rendering/PaintInfo.h \
  • trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj

    r157950 r158115  
    95409540    </ClCompile>
    95419541    <ClCompile Include="..\rendering\LineWidth.cpp" />
     9542    <ClCompile Include="..\rendering\OrderIterator.cpp" />
    95429543    <ClCompile Include="..\rendering\PointerEventsHitRules.cpp">
    95439544      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
     
    1956619567    <ClInclude Include="..\rendering\LineLayoutState.h" />
    1956719568    <ClInclude Include="..\rendering\LineWidth.h" />
     19569    <ClInclude Include="..\rendering\OrderIterator.h" />
    1956819570    <ClInclude Include="..\rendering\PaintInfo.h" />
    1956919571    <ClInclude Include="..\rendering\PaintPhase.h" />
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r158096 r158115  
    53685368                CDE3A85717F6020400C5BE20 /* AudioTrackPrivateAVFObjC.mm in Sources */ = {isa = PBXBuildFile; fileRef = CDE3A85517F6020400C5BE20 /* AudioTrackPrivateAVFObjC.mm */; };
    53695369                CDE3A85817F6020400C5BE20 /* AudioTrackPrivateAVFObjC.h in Headers */ = {isa = PBXBuildFile; fileRef = CDE3A85617F6020400C5BE20 /* AudioTrackPrivateAVFObjC.h */; };
     5370                CDE7FC44181904B1002BBB77 /* OrderIterator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDE7FC42181904B1002BBB77 /* OrderIterator.cpp */; };
     5371                CDE7FC45181904B1002BBB77 /* OrderIterator.h in Headers */ = {isa = PBXBuildFile; fileRef = CDE7FC43181904B1002BBB77 /* OrderIterator.h */; };
    53705372                CDEA763014608A53008B31F1 /* PlatformClockCA.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDEA762E146084DE008B31F1 /* PlatformClockCA.cpp */; };
    53715373                CDEA76341460B56F008B31F1 /* ClockGeneric.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDEA76321460AE29008B31F1 /* ClockGeneric.cpp */; };
     
    1233812340                CDE3A85617F6020400C5BE20 /* AudioTrackPrivateAVFObjC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AudioTrackPrivateAVFObjC.h; path = objc/AudioTrackPrivateAVFObjC.h; sourceTree = "<group>"; };
    1233912341                CDE6560E17CA6E7600526BA7 /* mediaControlsApple.js */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.javascript; path = mediaControlsApple.js; sourceTree = "<group>"; };
     12342                CDE7FC42181904B1002BBB77 /* OrderIterator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = OrderIterator.cpp; sourceTree = "<group>"; };
     12343                CDE7FC43181904B1002BBB77 /* OrderIterator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OrderIterator.h; sourceTree = "<group>"; };
    1234012344                CDEA762C14608224008B31F1 /* Clock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Clock.h; sourceTree = "<group>"; };
    1234112345                CDEA762E146084DE008B31F1 /* PlatformClockCA.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PlatformClockCA.cpp; sourceTree = "<group>"; };
     
    2054320547                        isa = PBXGroup;
    2054420548                        children = (
     20549                                CDE7FC42181904B1002BBB77 /* OrderIterator.cpp */,
     20550                                CDE7FC43181904B1002BBB77 /* OrderIterator.h */,
    2054520551                                439046C212DA25CE00AF80A2 /* mathml */,
    2054620552                                FD08A879175D3926002CD360 /* shapes */,
     
    2475324759                                CD3E252418046BCD00E27F56 /* CSSGridTemplateValue.h in Headers */,
    2475424760                                CDEF4FD717E85C8F00AEE24B /* GridLength.h in Headers */,
     24761                                CDE7FC45181904B1002BBB77 /* OrderIterator.h in Headers */,
    2475524762                        );
    2475624763                        runOnlyForDeploymentPostprocessing = 0;
     
    2778427791                                A0CB002417DF82660017896B /* LineWidth.cpp in Sources */,
    2778527792                                CD3E252318046BCD00E27F56 /* CSSGridTemplateValue.cpp in Sources */,
     27793                                CDE7FC44181904B1002BBB77 /* OrderIterator.cpp in Sources */,
    2778627794                        );
    2778727795                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/Source/WebCore/rendering/RenderFlexibleBox.cpp

    r158097 r158115  
    4040namespace WebCore {
    4141
    42 RenderFlexibleBox::OrderIterator::OrderIterator(const RenderFlexibleBox* flexibleBox)
    43     : m_flexibleBox(flexibleBox)
    44     , m_currentChild(0)
    45     , m_orderValuesIterator(0)
    46 {
    47 }
    48 
    49 void RenderFlexibleBox::OrderIterator::setOrderValues(const OrderValues& orderValues)
    50 {
    51     reset();
    52     m_orderValues = orderValues;
    53     if (m_orderValues.size() < 2)
    54         return;
    55 
    56     std::sort(m_orderValues.begin(), m_orderValues.end());
    57     auto nextElement = std::unique(m_orderValues.begin(), m_orderValues.end());
    58     m_orderValues.shrinkCapacity(nextElement - m_orderValues.begin());
    59 }
    60 
    61 RenderBox* RenderFlexibleBox::OrderIterator::first()
    62 {
    63     reset();
    64     return next();
    65 }
    66 
    67 RenderBox* RenderFlexibleBox::OrderIterator::next()
    68 {
    69     do {
    70         if (!m_currentChild) {
    71             if (m_orderValuesIterator == m_orderValues.end())
    72                 return 0;
    73             if (m_orderValuesIterator) {
    74                 ++m_orderValuesIterator;
    75                 if (m_orderValuesIterator == m_orderValues.end())
    76                     return 0;
    77             } else
    78                 m_orderValuesIterator = m_orderValues.begin();
    79 
    80             m_currentChild = m_flexibleBox->firstChildBox();
    81         } else
    82             m_currentChild = m_currentChild->nextSiblingBox();
    83     } while (!m_currentChild || m_currentChild->style()->order() != *m_orderValuesIterator);
    84 
    85     return m_currentChild;
    86 }
    87 
    88 void RenderFlexibleBox::OrderIterator::reset()
    89 {
    90     m_currentChild = 0;
    91     m_orderValuesIterator = 0;
    92 }
    93 
    9442struct RenderFlexibleBox::LineContext {
    9543    LineContext(LayoutUnit crossAxisOffset, LayoutUnit crossAxisExtent, size_t numberOfChildren, LayoutUnit maxAscent)
     
    12169RenderFlexibleBox::RenderFlexibleBox(Element& element, PassRef<RenderStyle> style)
    12270    : RenderBlock(element, std::move(style), 0)
    123     , m_orderIterator(this)
     71    , m_orderIterator(*this)
    12472    , m_numberOfInFlowChildrenOnFirstLine(-1)
    12573{
     
    12977RenderFlexibleBox::RenderFlexibleBox(Document& document, PassRef<RenderStyle> style)
    13078    : RenderBlock(document, std::move(style), 0)
    131     , m_orderIterator(this)
     79    , m_orderIterator(*this)
    13280    , m_numberOfInFlowChildrenOnFirstLine(-1)
    13381{
     
    346294    OrderIterator::OrderValues orderValues;
    347295    computeMainAxisPreferredSizes(orderValues);
    348     m_orderIterator.setOrderValues(orderValues);
     296    m_orderIterator.setOrderValues(std::move(orderValues));
    349297
    350298    ChildFrameRects oldChildRects;
  • trunk/Source/WebCore/rendering/RenderFlexibleBox.h

    r158097 r158115  
    3232#define RenderFlexibleBox_h
    3333
     34#include "OrderIterator.h"
    3435#include "RenderBlock.h"
    3536
     
    7273        FlipForRowReverse,
    7374        NoFlipForRowReverse,
    74     };
    75 
    76     class OrderIterator {
    77         WTF_MAKE_NONCOPYABLE(OrderIterator);
    78     public:
    79         typedef Vector<int, 1> OrderValues;
    80 
    81         OrderIterator(const RenderFlexibleBox*);
    82         void setOrderValues(const OrderValues&);
    83         RenderBox* currentChild() const { return m_currentChild; }
    84         RenderBox* first();
    85         RenderBox* next();
    86         void reset();
    87 
    88     private:
    89         const RenderFlexibleBox* m_flexibleBox;
    90         RenderBox* m_currentChild;
    91         OrderValues m_orderValues;
    92         Vector<int>::const_iterator m_orderValuesIterator;
    9375    };
    9476
  • trunk/Source/WebCore/rendering/RenderGrid.cpp

    r158097 r158115  
    11/*
    22 * Copyright (C) 2011 Apple Inc. All rights reserved.
    3  * Copyright (C) 2013 Igalia S.L.
     3 * Copyright (C) 2013 Igalia S.L. All rights reserved.
    44 *
    55 * Redistribution and use in source and binary forms, with or without
     
    144144RenderGrid::RenderGrid(Element& element, PassRef<RenderStyle> style)
    145145    : RenderBlock(element, std::move(style), 0)
     146    , m_orderIterator(*this)
    146147{
    147148    // All of our children must be block level.
     
    428429}
    429430
    430 size_t RenderGrid::maximumIndexInDirection(TrackSizingDirection direction) const
    431 {
    432     size_t maximumIndex = std::max<size_t>(1, (direction == ForColumns) ? explicitGridColumnCount() : explicitGridRowCount());
    433 
    434     for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBox()) {
    435         OwnPtr<GridSpan> positions = resolveGridPositionsFromStyle(child, direction);
    436 
    437         // |positions| is null if we need to run the auto-placement algorithm. Our estimation ignores
    438         // this case as the auto-placement algorithm will grow the grid as needed.
    439         if (!positions)
    440             continue;
    441 
    442         maximumIndex = std::max(maximumIndex, positions->finalPositionIndex + 1);
    443     }
    444 
    445     return maximumIndex;
    446 }
    447 
    448431LayoutUnit RenderGrid::logicalContentHeightForChild(RenderBox* child, Vector<GridTrack>& columnTracks)
    449432{
     
    626609    ASSERT(m_gridItemCoordinate.isEmpty());
    627610
    628     m_grid.grow(maximumIndexInDirection(ForRows));
    629     size_t maximumColumnIndex = maximumIndexInDirection(ForColumns);
    630     for (size_t i = 0; i < m_grid.size(); ++i)
    631         m_grid[i].grow(maximumColumnIndex);
     611    populateExplicitGridAndOrderIterator();
    632612
    633613    Vector<RenderBox*> autoMajorAxisAutoGridItems;
    634614    Vector<RenderBox*> specifiedMajorAxisAutoGridItems;
    635615    GridAutoFlow autoFlow = style()->gridAutoFlow();
    636     for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBox()) {
     616    for (RenderBox* child = m_orderIterator.first(); child; child = m_orderIterator.next()) {
    637617        // FIXME: We never re-resolve positions if the grid is grown during auto-placement which may lead auto / <integer>
    638618        // positions to not match the author's intent. The specification is unclear on what should be done in this case.
     
    662642    placeSpecifiedMajorAxisItemsOnGrid(specifiedMajorAxisAutoGridItems);
    663643    placeAutoMajorAxisItemsOnGrid(autoMajorAxisAutoGridItems);
     644}
     645
     646void RenderGrid::populateExplicitGridAndOrderIterator()
     647{
     648    // FIXME: We should find a way to share OrderValues's initialization code with RenderFlexibleBox.
     649    OrderIterator::OrderValues orderValues;
     650    size_t maximumRowIndex = std::max<size_t>(1, explicitGridRowCount());
     651    size_t maximumColumnIndex = std::max<size_t>(1, explicitGridColumnCount());
     652
     653    for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBox()) {
     654        // Avoid growing the vector for the common-case default value of 0. This optimizes the most common case which is
     655        // one or a few values with the default order 0
     656        int order = child->style()->order();
     657        if (orderValues.isEmpty() || orderValues.last() != order)
     658            orderValues.append(order);
     659
     660        // This function bypasses the cache (cachedGridCoordinate()) as it is used to build it.
     661        OwnPtr<GridSpan> rowPositions = resolveGridPositionsFromStyle(child, ForRows);
     662        OwnPtr<GridSpan> columnPositions = resolveGridPositionsFromStyle(child, ForColumns);
     663
     664        // |positions| is 0 if we need to run the auto-placement algorithm. Our estimation ignores
     665        // this case as the auto-placement algorithm will grow the grid as needed.
     666        if (rowPositions)
     667            maximumRowIndex = std::max(maximumRowIndex, rowPositions->finalPositionIndex + 1);
     668        if (columnPositions)
     669            maximumColumnIndex = std::max(maximumColumnIndex, columnPositions->finalPositionIndex + 1);
     670    }
     671
     672    m_grid.grow(maximumRowIndex);
     673    for (size_t i = 0; i < m_grid.size(); ++i)
     674        m_grid[i].grow(maximumColumnIndex);
     675
     676    m_orderIterator.setOrderValues(std::move(orderValues));
    664677}
    665678
     
    10151028}
    10161029
     1030void RenderGrid::paintChildren(PaintInfo& paintInfo, const LayoutPoint& paintOffset, PaintInfo& forChild, bool usePrintRect)
     1031{
     1032    for (RenderBox* child = m_orderIterator.first(); child; child = m_orderIterator.next())
     1033        paintChild(*child, paintInfo, paintOffset, forChild, usePrintRect);
     1034}
     1035
    10171036const char* RenderGrid::renderName() const
    10181037{
  • trunk/Source/WebCore/rendering/RenderGrid.h

    r158097 r158115  
    11/*
    22 * Copyright (C) 2011 Apple Inc. All rights reserved.
     3 * Copyright (C) 2013 Igalia S.L. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    2728#define RenderGrid_h
    2829
     30#include "OrderIterator.h"
    2931#include "RenderBlock.h"
    3032
     
    7476    void insertItemIntoGrid(RenderBox*, const GridCoordinate&);
    7577    void placeItemsOnGrid();
     78    void populateExplicitGridAndOrderIterator();
    7679    void placeSpecifiedMajorAxisItemsOnGrid(Vector<RenderBox*>);
    7780    void placeAutoMajorAxisItemsOnGrid(Vector<RenderBox*>);
     
    9699    size_t explicitGridRowCount() const;
    97100    size_t explicitGridSizeForSide(GridPositionSide) const;
    98     size_t maximumIndexInDirection(TrackSizingDirection) const;
    99101
    100102    LayoutUnit logicalContentHeightForChild(RenderBox*, Vector<GridTrack>&);
     
    114116
    115117    LayoutUnit gridAreaBreadthForChild(const RenderBox* child, TrackSizingDirection, const Vector<GridTrack>&) const;
     118
     119    virtual void paintChildren(PaintInfo& forSelf, const LayoutPoint& paintOffset, PaintInfo& forChild, bool usePrintRect) OVERRIDE FINAL;
    116120
    117121#ifndef NDEBUG
     
    133137    Vector<Vector<Vector<RenderBox*, 1>>> m_grid;
    134138    HashMap<const RenderBox*, GridCoordinate> m_gridItemCoordinate;
     139    OrderIterator m_orderIterator;
    135140};
    136141
Note: See TracChangeset for help on using the changeset viewer.