1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
|
/*
* Copyright (C) 2011 Apple Inc. All rights reserved.
* Copyright (C) 2013-2017 Igalia S.L.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include "Grid.h"
#include "GridTrackSizingAlgorithm.h"
#include "RenderBlock.h"
namespace WebCore {
class GridArea;
class GridSpan;
struct ContentAlignmentData;
enum GridAxisPosition {GridAxisStart, GridAxisEnd, GridAxisCenter};
enum GridAxis { GridRowAxis, GridColumnAxis };
class RenderGrid final : public RenderBlock {
public:
RenderGrid(Element&, RenderStyle&&);
virtual ~RenderGrid();
Element& element() const { return downcast<Element>(nodeForNonAnonymous()); }
void styleDidChange(StyleDifference, const RenderStyle* oldStyle) override;
void layoutBlock(bool relayoutChildren, LayoutUnit pageLogicalHeight = 0) override;
bool avoidsFloats() const override { return true; }
bool canDropAnonymousBlockChild() const override { return false; }
void dirtyGrid();
Vector<LayoutUnit> trackSizesForComputedStyle(GridTrackSizingDirection) const;
const Vector<LayoutUnit>& columnPositions() const { return m_columnPositions; }
const Vector<LayoutUnit>& rowPositions() const { return m_rowPositions; }
unsigned autoRepeatCountForDirection(GridTrackSizingDirection direction) const { return m_grid.autoRepeatTracks(direction); }
// Required by GridTrackSizingAlgorithm. Keep them under control.
bool isOrthogonalChild(const RenderBox&) const;
LayoutUnit guttersSize(const Grid&, GridTrackSizingDirection, unsigned startLine, unsigned span, std::optional<LayoutUnit> availableSize) const;
StyleContentAlignmentData contentAlignment(GridTrackSizingDirection) const;
protected:
ItemPosition selfAlignmentNormalBehavior(const RenderBox* child = nullptr) const override
{
ASSERT(child);
return child->isRenderReplaced() ? ItemPositionStart : ItemPositionStretch;
}
private:
const char* renderName() const override;
bool isRenderGrid() const override { return true; }
void computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const override;
void addChild(RenderObject* newChild, RenderObject* beforeChild) final;
void removeChild(RenderObject&) final;
StyleSelfAlignmentData selfAlignmentForChild(GridAxis, const RenderBox&, const RenderStyle* = nullptr) const;
bool selfAlignmentChangedToStretch(GridAxis, const RenderStyle& oldStyle, const RenderStyle& newStyle, const RenderBox&) const;
bool selfAlignmentChangedFromStretch(GridAxis, const RenderStyle& oldStyle, const RenderStyle& newStyle, const RenderBox&) const;
std::optional<LayoutUnit> availableSpaceForGutters(GridTrackSizingDirection) const;
bool explicitGridDidResize(const RenderStyle&) const;
bool namedGridLinesDefinitionDidChange(const RenderStyle&) const;
std::optional<LayoutUnit> computeIntrinsicLogicalContentHeightUsing(Length logicalHeightLength, std::optional<LayoutUnit> intrinsicContentHeight, LayoutUnit borderAndPadding) const override;
unsigned computeAutoRepeatTracksCount(GridTrackSizingDirection, std::optional<LayoutUnit> availableSize) const;
unsigned clampAutoRepeatTracks(GridTrackSizingDirection, unsigned autoRepeatTracks) const;
std::unique_ptr<OrderedTrackIndexSet> computeEmptyTracksForAutoRepeat(Grid&, GridTrackSizingDirection) const;
void placeItemsOnGrid(Grid&, std::optional<LayoutUnit> availableSpaceForColumns) const;
void populateExplicitGridAndOrderIterator(Grid&) const;
std::unique_ptr<GridArea> createEmptyGridAreaAtSpecifiedPositionsOutsideGrid(Grid&, const RenderBox&, GridTrackSizingDirection, const GridSpan&) const;
void placeSpecifiedMajorAxisItemsOnGrid(Grid&, const Vector<RenderBox*>&) const;
void placeAutoMajorAxisItemsOnGrid(Grid&, const Vector<RenderBox*>&) const;
typedef std::pair<unsigned, unsigned> AutoPlacementCursor;
void placeAutoMajorAxisItemOnGrid(Grid&, RenderBox&, AutoPlacementCursor&) const;
GridTrackSizingDirection autoPlacementMajorAxisDirection() const;
GridTrackSizingDirection autoPlacementMinorAxisDirection() const;
bool canPerformSimplifiedLayout() const final;
void prepareChildForPositionedLayout(RenderBox&);
void layoutPositionedObject(RenderBox&, bool relayoutChildren, bool fixedPositionObjectsOnly) override;
void offsetAndBreadthForPositionedChild(const RenderBox&, GridTrackSizingDirection, LayoutUnit& offset, LayoutUnit& breadth);
void computeTrackSizesForDefiniteSize(GridTrackSizingDirection, LayoutUnit availableSpace);
void computeTrackSizesForIndefiniteSize(GridTrackSizingAlgorithm&, GridTrackSizingDirection, Grid&, LayoutUnit& minIntrinsicSize, LayoutUnit& maxIntrinsicSize) const;
LayoutUnit computeTrackBasedLogicalHeight() const;
void repeatTracksSizingIfNeeded(LayoutUnit availableSpaceForColumns, LayoutUnit availableSpaceForRows);
void layoutGridItems();
void populateGridPositionsForDirection(GridTrackSizingDirection);
GridAxisPosition columnAxisPositionForChild(const RenderBox&) const;
GridAxisPosition rowAxisPositionForChild(const RenderBox&) const;
LayoutUnit columnAxisOffsetForChild(const RenderBox&) const;
LayoutUnit rowAxisOffsetForChild(const RenderBox&) const;
ContentAlignmentData computeContentPositionAndDistributionOffset(GridTrackSizingDirection, const LayoutUnit& availableFreeSpace, unsigned numberOfGridTracks) const;
LayoutPoint findChildLogicalPosition(const RenderBox&) const;
GridArea cachedGridArea(const RenderBox&) const;
GridSpan cachedGridSpan(const RenderBox&, GridTrackSizingDirection) const;
LayoutUnit gridAreaBreadthForChildIncludingAlignmentOffsets(const RenderBox&, GridTrackSizingDirection) const;
void paintChildren(PaintInfo& forSelf, const LayoutPoint& paintOffset, PaintInfo& forChild, bool usePrintRect) override;
LayoutUnit marginLogicalSizeForChild(GridTrackSizingDirection, const RenderBox&) const;
LayoutUnit computeMarginLogicalSizeForChild(GridTrackSizingDirection, const RenderBox&) const;
LayoutUnit availableAlignmentSpaceForChildBeforeStretching(LayoutUnit gridAreaBreadthForChild, const RenderBox&) const;
StyleSelfAlignmentData justifySelfForChild(const RenderBox&, const RenderStyle* = nullptr) const;
StyleSelfAlignmentData alignSelfForChild(const RenderBox&, const RenderStyle* = nullptr) const;
void applyStretchAlignmentToChildIfNeeded(RenderBox&);
bool hasAutoSizeInColumnAxis(const RenderBox& child) const { return isHorizontalWritingMode() ? child.style().height().isAuto() : child.style().width().isAuto(); }
bool hasAutoSizeInRowAxis(const RenderBox& child) const { return isHorizontalWritingMode() ? child.style().width().isAuto() : child.style().height().isAuto(); }
bool allowedToStretchChildAlongColumnAxis(const RenderBox& child) const { return alignSelfForChild(child).position() == ItemPositionStretch && hasAutoSizeInColumnAxis(child) && !hasAutoMarginsInColumnAxis(child); }
bool allowedToStretchChildAlongRowAxis(const RenderBox& child) const { return justifySelfForChild(child).position() == ItemPositionStretch && hasAutoSizeInRowAxis(child) && !hasAutoMarginsInRowAxis(child); }
bool hasAutoMarginsInColumnAxis(const RenderBox&) const;
bool hasAutoMarginsInRowAxis(const RenderBox&) const;
void resetAutoMarginsAndLogicalTopInColumnAxis(RenderBox& child);
void updateAutoMarginsInColumnAxisIfNeeded(RenderBox&);
void updateAutoMarginsInRowAxisIfNeeded(RenderBox&);
int baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const final;
std::optional<int> firstLineBaseline() const final;
std::optional<int> inlineBlockBaseline(LineDirectionMode) const final;
bool isInlineBaselineAlignedChild(const RenderBox&) const;
LayoutUnit gridGap(GridTrackSizingDirection) const;
LayoutUnit gridGap(GridTrackSizingDirection, std::optional<LayoutUnit> availableSize) const;
unsigned numTracks(GridTrackSizingDirection, const Grid&) const;
LayoutUnit translateRTLCoordinate(LayoutUnit) const;
GridTrackSizingDirection flowAwareDirectionForChild(const RenderBox&, GridTrackSizingDirection) const;
Grid m_grid;
GridTrackSizingAlgorithm m_trackSizingAlgorithm;
Vector<LayoutUnit> m_columnPositions;
Vector<LayoutUnit> m_rowPositions;
LayoutUnit m_offsetBetweenColumns;
LayoutUnit m_offsetBetweenRows;
std::optional<LayoutUnit> m_minContentHeight;
std::optional<LayoutUnit> m_maxContentHeight;
};
} // namespace WebCore
SPECIALIZE_TYPE_TRAITS_RENDER_OBJECT(RenderGrid, isRenderGrid())
|