2018-10-19 Zalan Bujtas <zalan@apple.com>
+ [LFC][IFC] RenderReplaced renderer should create InlineBox
+ https://bugs.webkit.org/show_bug.cgi?id=190720
+
+ Reviewed by Antti Koivisto.
+
+ * layout/layouttree/LayoutTreeBuilder.cpp:
+ (WebCore::Layout::TreeBuilder::createSubTree):
+
+2018-10-19 Zalan Bujtas <zalan@apple.com>
+
[LFC][IFC] Inline replaced width should default to 300px only if width is auto.
https://bugs.webkit.org/show_bug.cgi?id=190722
class BlockContainer : public Container {
WTF_MAKE_ISO_ALLOCATED(BlockContainer);
public:
- friend class TreeBuilder;
+ BlockContainer(std::optional<ElementAttributes>, RenderStyle&&, BaseTypeFlags = BlockContainerFlag);
bool establishesInlineFormattingContext() const final;
-protected:
- BlockContainer(std::optional<ElementAttributes>, RenderStyle&&, BaseTypeFlags = BlockContainerFlag);
-
};
}
class Box : public CanMakeWeakPtr<Box> {
WTF_MAKE_ISO_ALLOCATED(Box);
public:
- friend class TreeBuilder;
+ enum class ElementType {
+ Document,
+ Body,
+ TableColumn,
+ TableRow,
+ TableColumnGroup,
+ TableRowGroup,
+ TableHeaderGroup,
+ TableFooterGroup,
+ GenericElement
+ };
+ struct ElementAttributes {
+ ElementType elementType;
+ };
+
+ enum BaseTypeFlag {
+ ContainerFlag = 1 << 0,
+ BlockContainerFlag = 1 << 1,
+ InlineBoxFlag = 1 << 2,
+ InlineContainerFlag = 1 << 3,
+ LineBreakBoxFlag = 1 << 4
+ };
+ typedef unsigned BaseTypeFlags;
+
+ Box(std::optional<ElementAttributes>, RenderStyle&&, BaseTypeFlags);
virtual ~Box();
bool establishesFormattingContext() const;
const Box* previousInFlowSibling() const;
const Box* previousInFlowOrFloatingSibling() const;
- typedef unsigned BaseTypeFlags;
bool isContainer() const { return m_baseTypeFlags & ContainerFlag; }
bool isBlockContainer() const { return m_baseTypeFlags & BlockContainerFlag; }
bool isInlineBox() const { return m_baseTypeFlags & InlineBoxFlag; }
std::optional<const Replaced> replaced() const { return m_replaced; }
-protected:
- enum class ElementType {
- Document,
- Body,
- TableColumn,
- TableRow,
- TableColumnGroup,
- TableRowGroup,
- TableHeaderGroup,
- TableFooterGroup,
- GenericElement
- };
-
- struct ElementAttributes {
- ElementType elementType;
- };
-
- enum BaseTypeFlag {
- ContainerFlag = 1 << 0,
- BlockContainerFlag = 1 << 1,
- InlineBoxFlag = 1 << 2,
- InlineContainerFlag = 1 << 3,
- LineBreakBoxFlag = 1 << 4
- };
- Box(std::optional<ElementAttributes>, RenderStyle&&, BaseTypeFlags);
-
-private:
void setParent(Container& parent) { m_parent = &parent; }
void setNextSibling(Box& nextSibling) { m_nextSibling = &nextSibling; }
void setPreviousSibling(Box& previousSibling) { m_previousSibling = &previousSibling; }
+private:
RenderStyle m_style;
std::optional<ElementAttributes> m_elementAttributes;
class Container : public Box {
WTF_MAKE_ISO_ALLOCATED(Container);
public:
- friend class TreeBuilder;
+ Container(std::optional<ElementAttributes>, RenderStyle&&, BaseTypeFlags);
const Box* firstChild() const { return m_firstChild; }
const Box* firstInFlowChild() const;
const Vector<WeakPtr<const Box>>& outOfFlowDescendants() const { return m_outOfFlowDescendants; }
-protected:
- Container(std::optional<ElementAttributes>, RenderStyle&&, BaseTypeFlags);
-
-private:
void setFirstChild(Box&);
void setLastChild(Box&);
void addOutOfFlowDescendant(const Box&);
+private:
Box* m_firstChild { nullptr };
Box* m_lastChild { nullptr };
Vector<WeakPtr<const Box>> m_outOfFlowDescendants;
class InlineContainer : public Container {
WTF_MAKE_ISO_ALLOCATED(InlineContainer);
public:
- friend class TreeBuilder;
-
-protected:
InlineContainer(std::optional<ElementAttributes>, RenderStyle&&, BaseTypeFlags = InlineContainerFlag);
};
};
for (auto& child : childrenOfType<RenderObject>(rootRenderer)) {
- Box* box = nullptr;
+ std::unique_ptr<Box> box;
- if (is<RenderElement>(child)) {
+ if (is<RenderText>(child)) {
+ box = std::make_unique<InlineBox>(std::optional<Box::ElementAttributes>(), RenderStyle::createAnonymousStyleWithDisplay(rootRenderer.style(), DisplayType::Inline));
+ downcast<InlineBox>(*box).setTextContent(downcast<RenderText>(child).originalText());
+ } else if (is<RenderReplaced>(child)) {
+ auto& renderer = downcast<RenderReplaced>(child);
+ box = std::make_unique<InlineBox>(elementAttributes(renderer), RenderStyle::clone(renderer.style()));
+ } else if (is<RenderElement>(child)) {
auto& renderer = downcast<RenderElement>(child);
auto display = renderer.style().display();
if (display == DisplayType::Block)
- box = new BlockContainer(elementAttributes(renderer), RenderStyle::clone(renderer.style()));
+ box = std::make_unique<BlockContainer>(elementAttributes(renderer), RenderStyle::clone(renderer.style()));
else if (display == DisplayType::Inline)
- box = new InlineContainer(elementAttributes(renderer), RenderStyle::clone(renderer.style()));
+ box = std::make_unique<InlineContainer>(elementAttributes(renderer), RenderStyle::clone(renderer.style()));
else {
ASSERT_NOT_IMPLEMENTED_YET();
continue;
}
-
- } else if (is<RenderText>(child)) {
- box = new InlineBox( { }, RenderStyle::createAnonymousStyleWithDisplay(rootRenderer.style(), DisplayType::Inline));
- downcast<InlineBox>(*box).setTextContent(downcast<RenderText>(child).originalText());
} else {
ASSERT_NOT_IMPLEMENTED_YET();
continue;
auto& containingBlockFormattingContextRoot = box->containingBlock()->formattingContextRoot();
const_cast<Container&>(containingBlockFormattingContextRoot).addOutOfFlowDescendant(*box);
}
- if (is<RenderElement>(child))
+ if (is<Container>(*box))
createSubTree(downcast<RenderElement>(child), downcast<Container>(*box));
+ // Temporary
+ box.release();
}
}