#ifndef RenderElement_h
#define RenderElement_h
#include "AnimationController.h"
#include "RenderObject.h"
namespace WebCore {
class ControlStates;
class RenderBlock;
class RenderElement : public RenderObject {
public:
virtual ~RenderElement();
static RenderPtr<RenderElement> createFor(Element&, Ref<RenderStyle>&&);
bool hasInitializedStyle() const { return m_hasInitializedStyle; }
RenderStyle& style() const { return const_cast<RenderStyle&>(m_style.get()); }
RenderStyle& firstLineStyle() const;
void initializeStyle();
void setStyle(Ref<RenderStyle>&&, StyleDifference minimalStyleDifference = StyleDifferenceEqual);
void setAnimatableStyle(Ref<RenderStyle>&&, StyleDifference minimalStyleDifference);
RenderStyle* getCachedPseudoStyle(PseudoId, RenderStyle* parentStyle = nullptr) const;
PassRefPtr<RenderStyle> getUncachedPseudoStyle(const PseudoStyleRequest&, RenderStyle* parentStyle = nullptr, RenderStyle* ownStyle = nullptr) const;
Element* element() const { return downcast<Element>(RenderObject::node()); }
Element* nonPseudoElement() const { return downcast<Element>(RenderObject::nonPseudoNode()); }
Element* generatingElement() const;
RenderObject* firstChild() const { return m_firstChild; }
RenderObject* lastChild() const { return m_lastChild; }
virtual bool isEmpty() const override { return !firstChild(); }
bool canContainFixedPositionObjects() const;
bool canContainAbsolutelyPositionedObjects() const;
Color selectionColor(int colorProperty) const;
PassRefPtr<RenderStyle> selectionPseudoStyle() const;
Color selectionBackgroundColor() const;
Color selectionForegroundColor() const;
Color selectionEmphasisMarkColor() const;
bool isRenderLayerModelObject() const;
bool isBoxModelObject() const;
bool isRenderBlock() const;
bool isRenderBlockFlow() const;
bool isRenderReplaced() const;
bool isRenderInline() const;
bool isRenderNamedFlowFragmentContainer() const;
virtual bool isChildAllowed(const RenderObject&, const RenderStyle&) const { return true; }
virtual void addChild(RenderObject* newChild, RenderObject* beforeChild = nullptr);
virtual void addChildIgnoringContinuation(RenderObject* newChild, RenderObject* beforeChild = nullptr) { return addChild(newChild, beforeChild); }
virtual void removeChild(RenderObject&);
void addLayers(RenderLayer* parentLayer);
void removeLayers(RenderLayer* parentLayer);
void moveLayers(RenderLayer* oldParent, RenderLayer* newParent);
RenderLayer* findNextLayer(RenderLayer* parentLayer, RenderObject* startPoint, bool checkParent = true);
enum NotifyChildrenType { NotifyChildren, DontNotifyChildren };
void insertChildInternal(RenderObject*, RenderObject* beforeChild, NotifyChildrenType);
void removeChildInternal(RenderObject&, NotifyChildrenType);
virtual RenderElement* hoverAncestor() const;
virtual void dirtyLinesFromChangedChild(RenderObject&) { }
bool ancestorLineBoxDirty() const { return m_ancestorLineBoxDirty; }
void setAncestorLineBoxDirty(bool f = true);
void setChildNeedsLayout(MarkingBehavior = MarkContainingBlockChain);
void clearChildNeedsLayout();
void setNeedsPositionedMovementLayout(const RenderStyle* oldStyle);
void setNeedsSimplifiedNormalFlowLayout();
virtual void paint(PaintInfo&, const LayoutPoint&) = 0;
void paintAsInlineBlock(PaintInfo&, const LayoutPoint&);
virtual void layout();
void layoutIfNeeded() { if (needsLayout()) layout(); }
RenderElement& rendererForRootBackground();
PassRefPtr<RenderStyle> uncachedFirstLineStyle(RenderStyle*) const;
void setStyleInternal(Ref<RenderStyle>&& style) { m_style = WTF::move(style); }
bool repaintAfterLayoutIfNeeded(const RenderLayerModelObject* repaintContainer, const LayoutRect& oldBounds, const LayoutRect& oldOutlineBox, const LayoutRect* newBoundsPtr = nullptr, const LayoutRect* newOutlineBoxPtr = nullptr);
bool borderImageIsLoadedAndCanBeRendered() const;
bool mayCauseRepaintInsideViewport(const IntRect* visibleRect = nullptr) const;
bool createsGroup() const { return isTransparent() || hasMask() || hasFilter() || hasBackdropFilter() || hasBlendMode(); }
bool isTransparent() const { return style().opacity() < 1.0f; }
float opacity() const { return style().opacity(); }
bool visibleToHitTesting() const { return style().visibility() == VISIBLE && style().pointerEvents() != PE_NONE; }
bool hasBackground() const { return style().hasBackground(); }
bool hasMask() const { return style().hasMask(); }
bool hasClip() const { return isOutOfFlowPositioned() && style().hasClip(); }
bool hasClipOrOverflowClip() const { return hasClip() || hasOverflowClip(); }
bool hasClipPath() const { return style().clipPath(); }
bool hasHiddenBackface() const { return style().backfaceVisibility() == BackfaceVisibilityHidden; }
LayoutRect anchorRect() const;
bool hasFilter() const { return style().hasFilter(); }
bool hasBackdropFilter() const
{
#if ENABLE(FILTERS_LEVEL_2)
return style().hasBackdropFilter();
#else
return false;
#endif
}
#if ENABLE(CSS_COMPOSITING)
bool hasBlendMode() const { return style().hasBlendMode(); }
#else
bool hasBlendMode() const { return false; }
#endif
#if ENABLE(CSS_SHAPES)
bool hasShapeOutside() const { return style().shapeOutside(); }
#else
bool hasShapeOutside() const { return false; }
#endif
bool repaintForPausedImageAnimationsIfNeeded(const IntRect& visibleRect);
bool hasPausedImageAnimations() const { return m_hasPausedImageAnimations; }
void setHasPausedImageAnimations(bool b) { m_hasPausedImageAnimations = b; }
RenderNamedFlowThread* renderNamedFlowThreadWrapper();
void setRenderBoxNeedsLazyRepaint(bool b) { m_renderBoxNeedsLazyRepaint = b; }
bool renderBoxNeedsLazyRepaint() const { return m_renderBoxNeedsLazyRepaint; }
bool hasCounterNodeMap() const { return m_hasCounterNodeMap; }
void setHasCounterNodeMap(bool f) { m_hasCounterNodeMap = f; }
bool isCSSAnimating() const { return m_isCSSAnimating; }
void setIsCSSAnimating(bool b) { m_isCSSAnimating = b; }
const RenderElement* enclosingRendererWithTextDecoration(TextDecoration, bool firstLine) const;
protected:
enum BaseTypeFlags {
RenderLayerModelObjectFlag = 1 << 0,
RenderBoxModelObjectFlag = 1 << 1,
RenderInlineFlag = 1 << 2,
RenderReplacedFlag = 1 << 3,
RenderBlockFlag = 1 << 4,
RenderBlockFlowFlag = 1 << 5,
};
RenderElement(Element&, Ref<RenderStyle>&&, unsigned baseTypeFlags);
RenderElement(Document&, Ref<RenderStyle>&&, unsigned baseTypeFlags);
bool layerCreationAllowedForSubtree() const;
enum StylePropagationType { PropagateToAllChildren, PropagateToBlockChildrenOnly };
void propagateStyleToAnonymousChildren(StylePropagationType);
LayoutUnit valueForLength(const Length&, LayoutUnit maximumValue) const;
LayoutUnit minimumValueForLength(const Length&, LayoutUnit maximumValue, bool roundPercentages = false) const;
void setFirstChild(RenderObject* child) { m_firstChild = child; }
void setLastChild(RenderObject* child) { m_lastChild = child; }
void destroyLeftoverChildren();
virtual void styleWillChange(StyleDifference, const RenderStyle& newStyle);
virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
virtual void insertedIntoTree() override;
virtual void willBeRemovedFromTree() override;
virtual void willBeDestroyed() override;
void setRenderInlineAlwaysCreatesLineBoxes(bool b) { m_renderInlineAlwaysCreatesLineBoxes = b; }
bool renderInlineAlwaysCreatesLineBoxes() const { return m_renderInlineAlwaysCreatesLineBoxes; }
void setHasContinuation(bool b) { m_hasContinuation = b; }
bool hasContinuation() const { return m_hasContinuation; }
static bool hasControlStatesForRenderer(const RenderObject*);
static ControlStates* controlStatesForRenderer(const RenderObject*);
static void removeControlStatesForRenderer(const RenderObject*);
static void addControlStatesForRenderer(const RenderObject*, ControlStates*);
void setRenderBlockHasMarginBeforeQuirk(bool b) { m_renderBlockHasMarginBeforeQuirk = b; }
void setRenderBlockHasMarginAfterQuirk(bool b) { m_renderBlockHasMarginAfterQuirk = b; }
void setRenderBlockHasBorderOrPaddingLogicalWidthChanged(bool b) { m_renderBlockHasBorderOrPaddingLogicalWidthChanged = b; }
bool renderBlockHasMarginBeforeQuirk() const { return m_renderBlockHasMarginBeforeQuirk; }
bool renderBlockHasMarginAfterQuirk() const { return m_renderBlockHasMarginAfterQuirk; }
bool renderBlockHasBorderOrPaddingLogicalWidthChanged() const { return m_renderBlockHasBorderOrPaddingLogicalWidthChanged; }
void setRenderBlockFlowLineLayoutPath(unsigned u) { m_renderBlockFlowLineLayoutPath = u; }
void setRenderBlockFlowHasMarkupTruncation(bool b) { m_renderBlockFlowHasMarkupTruncation = b; }
unsigned renderBlockFlowLineLayoutPath() const { return m_renderBlockFlowLineLayoutPath; }
bool renderBlockFlowHasMarkupTruncation() const { return m_renderBlockFlowHasMarkupTruncation; }
private:
RenderElement(ContainerNode&, Ref<RenderStyle>&&, unsigned baseTypeFlags);
void node() const = delete;
void nonPseudoNode() const = delete;
void generatingNode() const = delete;
void isText() const = delete;
void isRenderElement() const = delete;
virtual RenderObject* firstChildSlow() const override final { return firstChild(); }
virtual RenderObject* lastChildSlow() const override final { return lastChild(); }
void handleDynamicFloatPositionChange();
void removeAnonymousWrappersForInlinesIfNecessary();
bool shouldRepaintForStyleDifference(StyleDifference) const;
bool hasImmediateNonWhitespaceTextChildOrBorderOrOutline() const;
void updateFillImages(const FillLayer*, const FillLayer*);
void updateImage(StyleImage*, StyleImage*);
#if ENABLE(CSS_SHAPES)
void updateShapeImage(const ShapeValue*, const ShapeValue*);
#endif
StyleDifference adjustStyleDifference(StyleDifference, unsigned contextSensitiveProperties) const;
RenderStyle* cachedFirstLineStyle() const;
virtual void newImageAnimationFrameAvailable(CachedImage&) final override;
bool getLeadingCorner(FloatPoint& output) const;
bool getTrailingCorner(FloatPoint& output) const;
bool shouldWillChangeCreateStackingContext() const;
unsigned m_baseTypeFlags : 6;
unsigned m_ancestorLineBoxDirty : 1;
unsigned m_hasInitializedStyle : 1;
unsigned m_renderInlineAlwaysCreatesLineBoxes : 1;
unsigned m_renderBoxNeedsLazyRepaint : 1;
unsigned m_hasPausedImageAnimations : 1;
unsigned m_hasCounterNodeMap : 1;
unsigned m_isCSSAnimating : 1;
unsigned m_hasContinuation : 1;
unsigned m_renderBlockHasMarginBeforeQuirk : 1;
unsigned m_renderBlockHasMarginAfterQuirk : 1;
unsigned m_renderBlockHasBorderOrPaddingLogicalWidthChanged : 1;
unsigned m_renderBlockFlowHasMarkupTruncation : 1;
unsigned m_renderBlockFlowLineLayoutPath : 2;
RenderObject* m_firstChild;
RenderObject* m_lastChild;
Ref<RenderStyle> m_style;
static bool s_affectsParentBlock;
static bool s_noLongerAffectsParentBlock;
};
inline void RenderElement::setAnimatableStyle(Ref<RenderStyle>&& style, StyleDifference minimalStyleDifference)
{
Ref<RenderStyle> animatedStyle = WTF::move(style);
if (animation().updateAnimations(*this, animatedStyle, animatedStyle))
minimalStyleDifference = std::max(minimalStyleDifference, StyleDifferenceRecompositeLayer);
setStyle(WTF::move(animatedStyle), minimalStyleDifference);
}
inline RenderStyle& RenderElement::firstLineStyle() const
{
return document().styleSheetCollection().usesFirstLineRules() ? *cachedFirstLineStyle() : style();
}
inline void RenderElement::setAncestorLineBoxDirty(bool f)
{
m_ancestorLineBoxDirty = f;
if (m_ancestorLineBoxDirty)
setNeedsLayout();
}
inline void RenderElement::setChildNeedsLayout(MarkingBehavior markParents)
{
ASSERT(!isSetNeedsLayoutForbidden());
if (normalChildNeedsLayout())
return;
setNormalChildNeedsLayoutBit(true);
if (markParents == MarkContainingBlockChain)
markContainingBlocksForLayout();
}
inline LayoutUnit RenderElement::valueForLength(const Length& length, LayoutUnit maximumValue) const
{
return WebCore::valueForLength(length, maximumValue);
}
inline LayoutUnit RenderElement::minimumValueForLength(const Length& length, LayoutUnit maximumValue, bool roundPercentages) const
{
return WebCore::minimumValueForLength(length, maximumValue, roundPercentages);
}
inline bool RenderElement::isRenderLayerModelObject() const
{
return m_baseTypeFlags & RenderLayerModelObjectFlag;
}
inline bool RenderElement::isBoxModelObject() const
{
return m_baseTypeFlags & RenderBoxModelObjectFlag;
}
inline bool RenderElement::isRenderBlock() const
{
return m_baseTypeFlags & RenderBlockFlag;
}
inline bool RenderElement::isRenderBlockFlow() const
{
return m_baseTypeFlags & RenderBlockFlowFlag;
}
inline bool RenderElement::isRenderReplaced() const
{
return m_baseTypeFlags & RenderReplacedFlag;
}
inline bool RenderElement::isRenderInline() const
{
return m_baseTypeFlags & RenderInlineFlag;
}
inline Element* RenderElement::generatingElement() const
{
if (parent() && isRenderNamedFlowFragment())
return parent()->generatingElement();
return downcast<Element>(RenderObject::generatingNode());
}
inline bool RenderElement::canContainFixedPositionObjects() const
{
return isRenderView()
|| (hasTransform() && isRenderBlock())
|| isSVGForeignObject()
|| isOutOfFlowRenderFlowThread();
}
inline bool RenderElement::canContainAbsolutelyPositionedObjects() const
{
return style().position() != StaticPosition
|| (isRenderBlock() && hasTransformRelatedProperty())
|| isSVGForeignObject()
|| isRenderView();
}
inline bool RenderObject::isRenderLayerModelObject() const
{
return is<RenderElement>(*this) && downcast<RenderElement>(*this).isRenderLayerModelObject();
}
inline bool RenderObject::isBoxModelObject() const
{
return is<RenderElement>(*this) && downcast<RenderElement>(*this).isBoxModelObject();
}
inline bool RenderObject::isRenderBlock() const
{
return is<RenderElement>(*this) && downcast<RenderElement>(*this).isRenderBlock();
}
inline bool RenderObject::isRenderBlockFlow() const
{
return is<RenderElement>(*this) && downcast<RenderElement>(*this).isRenderBlockFlow();
}
inline bool RenderObject::isRenderReplaced() const
{
return is<RenderElement>(*this) && downcast<RenderElement>(*this).isRenderReplaced();
}
inline bool RenderObject::isRenderInline() const
{
return is<RenderElement>(*this) && downcast<RenderElement>(*this).isRenderInline();
}
inline RenderStyle& RenderObject::style() const
{
if (isText())
return m_parent->style();
return downcast<RenderElement>(*this).style();
}
inline RenderStyle& RenderObject::firstLineStyle() const
{
if (isText())
return m_parent->firstLineStyle();
return downcast<RenderElement>(*this).firstLineStyle();
}
inline RenderElement* ContainerNode::renderer() const
{
return downcast<RenderElement>(Node::renderer());
}
inline int adjustForAbsoluteZoom(int value, const RenderElement& renderer)
{
return adjustForAbsoluteZoom(value, renderer.style());
}
inline LayoutUnit adjustLayoutUnitForAbsoluteZoom(LayoutUnit value, const RenderElement& renderer)
{
return adjustLayoutUnitForAbsoluteZoom(value, renderer.style());
}
RenderBlock* containingBlockForFixedPosition(const RenderElement*);
RenderBlock* containingBlockForAbsolutePosition(const RenderElement*);
RenderBlock* containingBlockForObjectInFlow(const RenderElement*);
}
SPECIALIZE_TYPE_TRAITS_RENDER_OBJECT(RenderElement, isRenderElement())
#endif // RenderElement_h