File: RenderBoxModelObject.h

package info (click to toggle)
webkit2gtk 2.48.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 429,764 kB
  • sloc: cpp: 3,697,587; javascript: 194,444; ansic: 169,997; python: 46,499; asm: 19,295; ruby: 18,528; perl: 16,602; xml: 4,650; yacc: 2,360; sh: 2,098; java: 1,993; lex: 1,327; pascal: 366; makefile: 298
file content (275 lines) | stat: -rw-r--r-- 11,698 bytes parent folder | download | duplicates (6)
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
/*
 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
 *           (C) 1999 Antti Koivisto (koivisto@kde.org)
 * Copyright (C) 2003-2024 Apple Inc. All rights reserved.
 * Copyright (C) 2010-2018 Google Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 *
 */

#pragma once

#include "FontBaseline.h"
#include "LayoutRect.h"
#include "RectEdges.h"
#include "RenderLayerModelObject.h"

namespace WebCore {

// Modes for some of the line-related functions.
enum LinePositionMode { PositionOnContainingLine, PositionOfInteriorLineBoxes };
enum LineDirectionMode { HorizontalLine, VerticalLine };

enum class BleedAvoidance : uint8_t {
    None,
    ShrinkBackground,
    UseTransparencyLayer,
    BackgroundOverBorder
};

enum class ContentChangeType : uint8_t {
    Image,
    MaskImage,
    BackgroundIImage,
    Canvas,
    CanvasPixels,
    Video,
    FullScreen,
    Model
};

class BorderEdge;
class BorderShape;
class ImageBuffer;
class RenderTextFragment;
class StickyPositionViewportConstraints;
class TransformationMatrix;

namespace InlineIterator {
class InlineBoxIterator;
};

enum class BoxSideFlag : uint8_t;
using BoxSideSet = OptionSet<BoxSideFlag>;
using BorderEdges = RectEdges<BorderEdge>;

// This class is the base for all objects that adhere to the CSS box model as described
// at http://www.w3.org/TR/CSS21/box.html

class RenderBoxModelObject : public RenderLayerModelObject {
    WTF_MAKE_TZONE_OR_ISO_ALLOCATED(RenderBoxModelObject);
    WTF_OVERRIDE_DELETE_FOR_CHECKED_PTR(RenderBoxModelObject);
public:
    virtual ~RenderBoxModelObject();
    
    LayoutSize relativePositionOffset() const;
    inline LayoutSize relativePositionLogicalOffset() const;

    FloatRect constrainingRectForStickyPosition() const;
    std::pair<const RenderBox&, const RenderLayer*> enclosingClippingBoxForStickyPosition() const;
    void computeStickyPositionConstraints(StickyPositionViewportConstraints&, const FloatRect& constrainingRect) const;
    LayoutSize stickyPositionOffset() const;
    inline LayoutSize stickyPositionLogicalOffset() const;

    LayoutSize offsetForInFlowPosition() const;

    // IE extensions. Used to calculate offsetWidth/Height.  Overridden by inlines (RenderFlow)
    // to return the remaining width on a given line (and the height of a single line).
    virtual LayoutUnit offsetLeft() const;
    virtual LayoutUnit offsetTop() const;
    virtual LayoutUnit offsetWidth() const = 0;
    virtual LayoutUnit offsetHeight() const = 0;

    void updateFromStyle() override;

    bool requiresLayer() const override;

    // This will work on inlines to return the bounding box of all of the lines' border boxes.
    virtual LayoutRect borderBoundingBox() const = 0;

    // These return the CSS computed padding values.
    inline LayoutUnit computedCSSPaddingTop() const;
    inline LayoutUnit computedCSSPaddingBottom() const;
    inline LayoutUnit computedCSSPaddingLeft() const;
    inline LayoutUnit computedCSSPaddingRight() const;
    inline LayoutUnit computedCSSPaddingBefore() const;
    inline LayoutUnit computedCSSPaddingAfter() const;
    inline LayoutUnit computedCSSPaddingStart() const;
    inline LayoutUnit computedCSSPaddingEnd() const;

    // These functions are used during layout. Table cells and the MathML
    // code override them to include some extra intrinsic padding.
    virtual inline RectEdges<LayoutUnit> padding() const;
    virtual inline LayoutUnit paddingTop() const;
    virtual inline LayoutUnit paddingBottom() const;
    virtual inline LayoutUnit paddingLeft() const;
    virtual inline LayoutUnit paddingRight() const;
    virtual inline LayoutUnit paddingBefore() const;
    virtual inline LayoutUnit paddingAfter() const;
    virtual inline LayoutUnit paddingStart() const;
    virtual inline LayoutUnit paddingEnd() const;

    virtual inline RectEdges<LayoutUnit> borderWidths() const;
    virtual inline LayoutUnit borderTop() const;
    virtual inline LayoutUnit borderBottom() const;
    virtual inline LayoutUnit borderLeft() const;
    virtual inline LayoutUnit borderRight() const;

    virtual inline LayoutUnit horizontalBorderExtent() const;
    virtual inline LayoutUnit verticalBorderExtent() const;

    virtual inline LayoutUnit borderBefore() const;
    virtual inline LayoutUnit borderAfter() const;
    virtual inline LayoutUnit borderStart() const;
    virtual inline LayoutUnit borderEnd() const;

    inline LayoutUnit borderAndPaddingStart() const;
    inline LayoutUnit borderAndPaddingEnd() const;
    inline LayoutUnit borderAndPaddingBefore() const;
    inline LayoutUnit borderAndPaddingAfter() const;

    inline LayoutUnit marginAndBorderAndPaddingStart() const;
    inline LayoutUnit marginAndBorderAndPaddingEnd() const;
    inline LayoutUnit marginAndBorderAndPaddingBefore() const;
    inline LayoutUnit marginAndBorderAndPaddingAfter() const;

    inline LayoutUnit verticalBorderAndPaddingExtent() const;
    inline LayoutUnit horizontalBorderAndPaddingExtent() const;
    inline LayoutUnit borderAndPaddingLogicalHeight() const;
    inline LayoutUnit borderAndPaddingLogicalWidth() const;
    inline LayoutUnit borderAndPaddingLogicalLeft() const;
    inline LayoutUnit borderAndPaddingLogicalRight() const;

    inline LayoutUnit borderLogicalLeft() const;
    inline LayoutUnit borderLogicalRight() const;
    inline LayoutUnit borderLogicalWidth() const;
    inline LayoutUnit borderLogicalHeight() const;

    inline LayoutUnit paddingLogicalLeft() const;
    inline LayoutUnit paddingLogicalRight() const;
    inline LayoutUnit paddingLogicalWidth() const;
    inline LayoutUnit paddingLogicalHeight() const;

    virtual LayoutUnit marginTop() const = 0;
    virtual LayoutUnit marginBottom() const = 0;
    virtual LayoutUnit marginLeft() const = 0;
    virtual LayoutUnit marginRight() const = 0;
    virtual LayoutUnit marginBefore(const WritingMode) const = 0;
    virtual LayoutUnit marginAfter(const WritingMode) const = 0;
    virtual LayoutUnit marginStart(const WritingMode) const = 0;
    virtual LayoutUnit marginEnd(const WritingMode) const = 0;
    LayoutUnit marginBefore() const { return marginBefore(writingMode()); }
    LayoutUnit marginAfter() const { return marginAfter(writingMode()); }
    LayoutUnit marginStart() const { return marginStart(writingMode()); }
    LayoutUnit marginEnd() const { return marginEnd(writingMode()); }
    LayoutUnit verticalMarginExtent() const { return marginTop() + marginBottom(); }
    LayoutUnit horizontalMarginExtent() const { return marginLeft() + marginRight(); }
    LayoutUnit marginLogicalHeight() const { return marginBefore() + marginAfter(); }
    LayoutUnit marginLogicalWidth() const { return marginStart() + marginEnd(); }

    BorderShape borderShapeForContentClipping(const LayoutRect& borderBoxRect, RectEdges<bool> closedEdges = { true }) const;

    inline bool hasInlineDirectionBordersPaddingOrMargin() const;
    inline bool hasInlineDirectionBordersOrPadding() const;

    virtual LayoutUnit containingBlockLogicalWidthForContent() const;

    // Overridden by subclasses to determine line height and baseline position.
    virtual LayoutUnit lineHeight(bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const = 0;
    virtual LayoutUnit baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const = 0;

    void mapAbsoluteToLocalPoint(OptionSet<MapCoordinatesMode>, TransformState&) const override;

    void setSelectionState(HighlightState) override;

    bool canHaveBoxInfoInFragment() const { return !isFloating() && !isReplacedOrAtomicInline() && !isInline() && !isRenderTableCell() && isRenderBlock() && !isRenderSVGBlock(); }

    void contentChanged(ContentChangeType);
    bool hasAcceleratedCompositing() const;

    RenderBoxModelObject* continuation() const;
    WEBCORE_EXPORT RenderInline* inlineContinuation() const;

    static void forRendererAndContinuations(RenderBoxModelObject&, const std::function<void(RenderBoxModelObject&)>&);

    void insertIntoContinuationChainAfter(RenderBoxModelObject&);
    void removeFromContinuationChain();

    bool hasRunningAcceleratedAnimations() const;

    void applyTransform(TransformationMatrix&, const RenderStyle&, const FloatRect& boundingBox, OptionSet<RenderStyle::TransformOperationOption>) const override;

protected:
    RenderBoxModelObject(Type, Element&, RenderStyle&&, OptionSet<TypeFlag>, TypeSpecificFlags);
    RenderBoxModelObject(Type, Document&, RenderStyle&&, OptionSet<TypeFlag>, TypeSpecificFlags);

    void willBeDestroyed() override;

    void styleWillChange(StyleDifference, const RenderStyle& newStyle) override;

    LayoutPoint adjustedPositionRelativeToOffsetParent(const LayoutPoint&) const;

    bool hasVisibleBoxDecorationStyle() const;
    bool borderObscuresBackgroundEdge(const FloatSize& contextScale) const;
    bool borderObscuresBackground() const;

public:
    bool fixedBackgroundPaintsInLocalCoordinates() const;
    InterpolationQuality chooseInterpolationQuality(GraphicsContext&, Image&, const void*, const LayoutSize&) const;
    DecodingMode decodingModeForImageDraw(const Image&, const PaintInfo&) const;

    void paintMaskForTextFillBox(GraphicsContext&, const FloatRect&, const InlineIterator::InlineBoxIterator&, const LayoutRect&);

    // For RenderBlocks and RenderInlines with m_style->pseudoElementType() == PseudoId::FirstLetter, this tracks their remaining text fragments
    RenderTextFragment* firstLetterRemainingText() const;
    void setFirstLetterRemainingText(RenderTextFragment&);
    void clearFirstLetterRemainingText();

    enum class ScaleByUsedZoom : bool { No, Yes };
    LayoutSize calculateImageIntrinsicDimensions(StyleImage*, const LayoutSize& scaledPositioningAreaSize, ScaleByUsedZoom) const;

    RenderBlock* containingBlockForAutoHeightDetection(Length logicalHeight) const;

    struct ContinuationChainNode {
        WTF_MAKE_STRUCT_FAST_ALLOCATED;

        SingleThreadWeakPtr<RenderBoxModelObject> renderer;
        ContinuationChainNode* previous { nullptr };
        ContinuationChainNode* next { nullptr };

        ContinuationChainNode(RenderBoxModelObject&);
        ~ContinuationChainNode();

        void insertAfter(ContinuationChainNode&);
    };

    ContinuationChainNode* continuationChainNode() const;

protected:
    LayoutUnit resolveLengthPercentageUsingContainerLogicalWidth(const Length&) const;
    virtual void absoluteQuadsIgnoringContinuation(const FloatRect&, Vector<FloatQuad>&, bool* /*wasFixed*/) const { ASSERT_NOT_REACHED(); }
    void collectAbsoluteQuadsForContinuation(Vector<FloatQuad>& quads, bool* wasFixed) const;

private:
    ContinuationChainNode& ensureContinuationChainNode();
    
    virtual LayoutRect frameRectForStickyPositioning() const = 0;
};

} // namespace WebCore

SPECIALIZE_TYPE_TRAITS_RENDER_OBJECT(RenderBoxModelObject, isRenderBoxModelObject())