Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[RenderTreeBuilder] Move RenderRubyAsInline/AsBlock::takeChild mutati…
…on to a RenderTreeBuilder

https://bugs.webkit.org/show_bug.cgi?id=182651
<rdar://problem/37405042>

Reviewed by Antti Koivisto.

No change in functionality.

* rendering/RenderRuby.cpp:
(WebCore::RenderRubyAsInline::takeChild):
(WebCore::RenderRubyAsBlock::takeChild):
(WebCore::isAnonymousRubyInlineBlock): Deleted.
(WebCore::isRubyChildForNormalRemoval): Deleted.
(WebCore::findRubyRunParent): Deleted.
* rendering/updating/RenderTreeBuilder.cpp:
(WebCore::RenderTreeBuilder::takeChildFromRenderRubyAsInline):
(WebCore::RenderTreeBuilder::takeChildFromRenderRubyAsBlock):
* rendering/updating/RenderTreeBuilder.h:
* rendering/updating/RenderTreeBuilderRuby.cpp:
(WebCore::findRubyRunParent):
(WebCore::RenderTreeBuilder::Ruby::takeChild):
* rendering/updating/RenderTreeBuilderRuby.h:


Canonical link: https://commits.webkit.org/198468@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@228339 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
alanbaradlay committed Feb 9, 2018
1 parent 47b8307 commit 28ca054
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 73 deletions.
25 changes: 25 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,28 @@
2018-02-09 Zalan Bujtas <zalan@apple.com>

[RenderTreeBuilder] Move RenderRubyAsInline/AsBlock::takeChild mutation to a RenderTreeBuilder
https://bugs.webkit.org/show_bug.cgi?id=182651
<rdar://problem/37405042>

Reviewed by Antti Koivisto.

No change in functionality.

* rendering/RenderRuby.cpp:
(WebCore::RenderRubyAsInline::takeChild):
(WebCore::RenderRubyAsBlock::takeChild):
(WebCore::isAnonymousRubyInlineBlock): Deleted.
(WebCore::isRubyChildForNormalRemoval): Deleted.
(WebCore::findRubyRunParent): Deleted.
* rendering/updating/RenderTreeBuilder.cpp:
(WebCore::RenderTreeBuilder::takeChildFromRenderRubyAsInline):
(WebCore::RenderTreeBuilder::takeChildFromRenderRubyAsBlock):
* rendering/updating/RenderTreeBuilder.h:
* rendering/updating/RenderTreeBuilderRuby.cpp:
(WebCore::findRubyRunParent):
(WebCore::RenderTreeBuilder::Ruby::takeChild):
* rendering/updating/RenderTreeBuilderRuby.h:

2018-02-09 Per Arne Vollan <pvollan@apple.com>

Assert that NSApp is not running in the WebProcess.
Expand Down
75 changes: 2 additions & 73 deletions Source/WebCore/rendering/RenderRuby.cpp
Expand Up @@ -45,39 +45,6 @@ namespace WebCore {
WTF_MAKE_ISO_ALLOCATED_IMPL(RenderRubyAsInline);
WTF_MAKE_ISO_ALLOCATED_IMPL(RenderRubyAsBlock);

//=== generic helper functions to avoid excessive code duplication ===

static inline bool isAnonymousRubyInlineBlock(const RenderObject* object)
{
ASSERT(!object
|| !isRuby(object->parent())
|| is<RenderRubyRun>(*object)
|| (object->isInline() && (object->isBeforeContent() || object->isAfterContent()))
|| (object->isAnonymous() && is<RenderBlock>(*object) && object->style().display() == INLINE_BLOCK));

return object
&& isRuby(object->parent())
&& is<RenderBlock>(*object)
&& !is<RenderRubyRun>(*object);
}

#ifndef ASSERT_DISABLED
static inline bool isRubyChildForNormalRemoval(const RenderObject& object)
{
return object.isRubyRun()
|| object.isBeforeContent()
|| object.isAfterContent()
|| object.isRenderMultiColumnFlow()
|| object.isRenderMultiColumnSet()
|| isAnonymousRubyInlineBlock(&object);
}
#endif

static inline RenderRubyRun& findRubyRunParent(RenderObject& child)
{
return *lineageOfType<RenderRubyRun>(child).first();
}

//=== ruby as inline object ===

RenderRubyAsInline::RenderRubyAsInline(Element& element, RenderStyle&& style)
Expand All @@ -95,26 +62,7 @@ void RenderRubyAsInline::styleDidChange(StyleDifference diff, const RenderStyle*

RenderPtr<RenderObject> RenderRubyAsInline::takeChild(RenderTreeBuilder& builder, RenderObject& child)
{
// If the child's parent is *this (must be a ruby run or generated content or anonymous block),
// just use the normal remove method.
if (child.parent() == this) {
#ifndef ASSERT_DISABLED
ASSERT(isRubyChildForNormalRemoval(child));
#endif
return RenderInline::takeChild(builder, child);
}
// If the child's parent is an anoymous block (must be generated :before/:after content)
// just use the block's remove method.
if (isAnonymousRubyInlineBlock(child.parent())) {
ASSERT(child.isBeforeContent() || child.isAfterContent());
auto& parent = *child.parent();
auto takenChild = parent.takeChild(builder, child);
parent.removeFromParentAndDestroy(builder);
return takenChild;
}

// Otherwise find the containing run and remove it from there.
return findRubyRunParent(child).takeChild(builder, child);
return builder.takeChildFromRenderRubyAsInline(*this, child);
}

//=== ruby as block object ===
Expand All @@ -134,26 +82,7 @@ void RenderRubyAsBlock::styleDidChange(StyleDifference diff, const RenderStyle*

RenderPtr<RenderObject> RenderRubyAsBlock::takeChild(RenderTreeBuilder& builder, RenderObject& child)
{
// If the child's parent is *this (must be a ruby run or generated content or anonymous block),
// just use the normal remove method.
if (child.parent() == this) {
#ifndef ASSERT_DISABLED
ASSERT(isRubyChildForNormalRemoval(child));
#endif
return RenderBlockFlow::takeChild(builder, child);
}
// If the child's parent is an anoymous block (must be generated :before/:after content)
// just use the block's remove method.
if (isAnonymousRubyInlineBlock(child.parent())) {
ASSERT(child.isBeforeContent() || child.isAfterContent());
auto& parent = *child.parent();
auto takenChild = parent.takeChild(builder, child);
parent.removeFromParentAndDestroy(builder);
return takenChild;
}

// Otherwise find the containing run and remove it from there.
return findRubyRunParent(child).takeChild(builder, child);
return builder.takeChildFromRenderRubyAsBlock(*this, child);
}

} // namespace WebCore
10 changes: 10 additions & 0 deletions Source/WebCore/rendering/updating/RenderTreeBuilder.cpp
Expand Up @@ -470,6 +470,16 @@ void RenderTreeBuilder::insertChildToRenderMathMLFenced(RenderMathMLFenced& pare
mathMLBuilder().insertChild(parent, WTFMove(child), beforeChild);
}

RenderPtr<RenderObject> RenderTreeBuilder::takeChildFromRenderRubyAsInline(RenderRubyAsInline& parent, RenderObject& child)
{
return rubyBuilder().takeChild(parent, child);
}

RenderPtr<RenderObject> RenderTreeBuilder::takeChildFromRenderRubyAsBlock(RenderRubyAsBlock& parent, RenderObject& child)
{
return rubyBuilder().takeChild(parent, child);
}

void RenderTreeBuilder::updateAfterDescendants(RenderElement& renderer)
{
if (is<RenderBlock>(renderer))
Expand Down
5 changes: 5 additions & 0 deletions Source/WebCore/rendering/updating/RenderTreeBuilder.h
Expand Up @@ -30,6 +30,8 @@
namespace WebCore {

class RenderMathMLFenced;
class RenderRubyAsBlock;
class RenderRubyAsInline;
class RenderRubyBase;
class RenderRubyRun;
class RenderSVGContainer;
Expand Down Expand Up @@ -71,6 +73,9 @@ class RenderTreeBuilder {
void insertChildToRenderTableRow(RenderTableRow& parent, RenderPtr<RenderObject> child, RenderObject* beforeChild = nullptr);
void insertChildToRenderMathMLFenced(RenderMathMLFenced& parent, RenderPtr<RenderObject> child, RenderObject* beforeChild = nullptr);

RenderPtr<RenderObject> takeChildFromRenderRubyAsInline(RenderRubyAsInline& parent, RenderObject& child);
RenderPtr<RenderObject> takeChildFromRenderRubyAsBlock(RenderRubyAsBlock& parent, RenderObject& child);

bool childRequiresTable(const RenderElement& parent, const RenderObject& child);
void makeChildrenNonInline(RenderBlock& parent, RenderObject* insertionPoint = nullptr);
RenderObject* splitAnonymousBoxesAroundChild(RenderBox& parent, RenderObject* beforeChild);
Expand Down
53 changes: 53 additions & 0 deletions Source/WebCore/rendering/updating/RenderTreeBuilderRuby.cpp
Expand Up @@ -33,6 +33,11 @@

namespace WebCore {

static inline RenderRubyRun& findRubyRunParent(RenderObject& child)
{
return *lineageOfType<RenderRubyRun>(child).first();
}

static inline bool isAnonymousRubyInlineBlock(const RenderObject* object)
{
ASSERT(!object
Expand Down Expand Up @@ -367,4 +372,52 @@ RenderRubyBase& RenderTreeBuilder::Ruby::rubyBaseSafe(RenderRubyRun& rubyRun)
return *base;
}

RenderPtr<RenderObject> RenderTreeBuilder::Ruby::takeChild(RenderRubyAsInline& parent, RenderObject& child)
{
// If the child's parent is *this (must be a ruby run or generated content or anonymous block),
// just use the normal remove method.
if (child.parent() == &parent) {
#ifndef ASSERT_DISABLED
ASSERT(isRubyChildForNormalRemoval(child));
#endif
return parent.RenderInline::takeChild(m_builder, child);
}
// If the child's parent is an anoymous block (must be generated :before/:after content)
// just use the block's remove method.
if (isAnonymousRubyInlineBlock(child.parent())) {
ASSERT(child.isBeforeContent() || child.isAfterContent());
auto& parent = *child.parent();
auto takenChild = parent.takeChild(m_builder, child);
parent.removeFromParentAndDestroy(m_builder);
return takenChild;
}

// Otherwise find the containing run and remove it from there.
return findRubyRunParent(child).takeChild(m_builder, child);
}

RenderPtr<RenderObject> RenderTreeBuilder::Ruby::takeChild(RenderRubyAsBlock& parent, RenderObject& child)
{
// If the child's parent is *this (must be a ruby run or generated content or anonymous block),
// just use the normal remove method.
if (child.parent() == &parent) {
#ifndef ASSERT_DISABLED
ASSERT(isRubyChildForNormalRemoval(child));
#endif
return parent.RenderBlockFlow::takeChild(m_builder, child);
}
// If the child's parent is an anoymous block (must be generated :before/:after content)
// just use the block's remove method.
if (isAnonymousRubyInlineBlock(child.parent())) {
ASSERT(child.isBeforeContent() || child.isAfterContent());
auto& parent = *child.parent();
auto takenChild = parent.takeChild(m_builder, child);
parent.removeFromParentAndDestroy(m_builder);
return takenChild;
}

// Otherwise find the containing run and remove it from there.
return findRubyRunParent(child).takeChild(m_builder, child);
}

}
3 changes: 3 additions & 0 deletions Source/WebCore/rendering/updating/RenderTreeBuilderRuby.h
Expand Up @@ -42,6 +42,9 @@ class RenderTreeBuilder::Ruby {
Ruby(RenderTreeBuilder&);

void insertChild(RenderRubyRun& parent, RenderPtr<RenderObject> child, RenderObject* beforeChild);
RenderPtr<RenderObject> takeChild(RenderRubyAsInline& parent, RenderObject& child);
RenderPtr<RenderObject> takeChild(RenderRubyAsBlock& parent, RenderObject& child);

RenderElement& findOrCreateParentForChild(RenderRubyAsBlock& parent, const RenderObject& child, RenderObject*& beforeChild);
RenderElement& findOrCreateParentForChild(RenderRubyAsInline& parent, const RenderObject& child, RenderObject*& beforeChild);

Expand Down

0 comments on commit 28ca054

Please sign in to comment.