Commit 9fa90759 authored by Navid Zolghadr's avatar Navid Zolghadr Committed by Commit Bot

Move some objects to DISALLOW_NEW and STACK_ALLOCATED

This makes moving ComputedStyle to Oilpan in these
classes that are referencing it in the future
easier.

Firstly it replaces a const & reference of ComputedStyle
in BoxInfo with a cached value needed in that class.
Secondly it makes a local FloatObject class public so that it
can be stored in a HeapVector and have
WTF_ALLOW_MOVE_INIT_AND_COMPARE_WITH_MEM_FUNCTIONS  on it
and later have a trace function for its CompuetedStyle reference.

Bug: 1030176
Change-Id: Iff63d1fb385bbb5ac85fc5445caf7dfd775352ed
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1946051Reviewed-by: default avatarKouhei Ueno <kouhei@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Navid Zolghadr <nzolghadr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#722417}
parent 5d0754ef
...@@ -46,7 +46,7 @@ class LayoutView; ...@@ -46,7 +46,7 @@ class LayoutView;
class Font; class Font;
class CORE_EXPORT CSSToLengthConversionData { class CORE_EXPORT CSSToLengthConversionData {
DISALLOW_NEW(); STACK_ALLOCATED();
public: public:
class CORE_EXPORT FontSizes { class CORE_EXPORT FontSizes {
......
...@@ -139,7 +139,7 @@ using NGInlineItemResults = Vector<NGInlineItemResult, 32>; ...@@ -139,7 +139,7 @@ using NGInlineItemResults = Vector<NGInlineItemResult, 32>;
// //
// NGLineBreaker produces, and NGInlineLayoutAlgorithm consumes. // NGLineBreaker produces, and NGInlineLayoutAlgorithm consumes.
class CORE_EXPORT NGLineInfo { class CORE_EXPORT NGLineInfo {
DISALLOW_NEW(); STACK_ALLOCATED();
public: public:
const NGInlineItemsData& ItemsData() const { const NGInlineItemsData& ItemsData() const {
......
...@@ -197,8 +197,8 @@ NGInlineItemsBuilderTemplate<OffsetMappingBuilder>::BoxInfo::BoxInfo( ...@@ -197,8 +197,8 @@ NGInlineItemsBuilderTemplate<OffsetMappingBuilder>::BoxInfo::BoxInfo(
const NGInlineItem& item) const NGInlineItem& item)
: item_index(item_index), : item_index(item_index),
should_create_box_fragment(item.ShouldCreateBoxFragment()), should_create_box_fragment(item.ShouldCreateBoxFragment()),
style(*item.Style()), may_have_margin_(item.Style()->MayHaveMargin()),
text_metrics(NGLineHeightMetrics(style)) { text_metrics(NGLineHeightMetrics(*item.Style())) {
DCHECK(item.Style()); DCHECK(item.Style());
} }
...@@ -208,7 +208,7 @@ bool NGInlineItemsBuilderTemplate<OffsetMappingBuilder>::BoxInfo:: ...@@ -208,7 +208,7 @@ bool NGInlineItemsBuilderTemplate<OffsetMappingBuilder>::BoxInfo::
ShouldCreateBoxFragmentForChild(const BoxInfo& child) const { ShouldCreateBoxFragmentForChild(const BoxInfo& child) const {
// When a child inline box has margins, the parent has different width/height // When a child inline box has margins, the parent has different width/height
// from the union of children. // from the union of children.
if (child.style.MayHaveMargin()) if (child.may_have_margin_)
return true; return true;
// Returns true when parent and child boxes have different font metrics, since // Returns true when parent and child boxes have different font metrics, since
......
...@@ -160,9 +160,11 @@ class NGInlineItemsBuilderTemplate { ...@@ -160,9 +160,11 @@ class NGInlineItemsBuilderTemplate {
// Keep track of inline boxes to compute ShouldCreateBoxFragment. // Keep track of inline boxes to compute ShouldCreateBoxFragment.
struct BoxInfo { struct BoxInfo {
DISALLOW_NEW();
unsigned item_index; unsigned item_index;
bool should_create_box_fragment; bool should_create_box_fragment;
const ComputedStyle& style; bool may_have_margin_;
NGLineHeightMetrics text_metrics; NGLineHeightMetrics text_metrics;
BoxInfo(unsigned item_index, const NGInlineItem& item); BoxInfo(unsigned item_index, const NGInlineItem& item);
......
...@@ -1524,7 +1524,7 @@ static LayoutUnit ComputeContentSize( ...@@ -1524,7 +1524,7 @@ static LayoutUnit ComputeContentSize(
void AddFloat(const ComputedStyle& float_style, void AddFloat(const ComputedStyle& float_style,
const ComputedStyle& style, const ComputedStyle& style,
LayoutUnit float_inline_max_size_with_margin) { LayoutUnit float_inline_max_size_with_margin) {
floating_objects_.push_back(FloatingObject{ floating_objects_.push_back(NGInlineNode::FloatingObject{
float_style, style, float_inline_max_size_with_margin}); float_style, style, float_inline_max_size_with_margin});
} }
...@@ -1566,12 +1566,7 @@ static LayoutUnit ComputeContentSize( ...@@ -1566,12 +1566,7 @@ static LayoutUnit ComputeContentSize(
private: private:
LayoutUnit floats_inline_size_; LayoutUnit floats_inline_size_;
struct FloatingObject { HeapVector<NGInlineNode::FloatingObject, 4> floating_objects_;
const ComputedStyle& float_style;
const ComputedStyle& style;
LayoutUnit float_inline_max_size_with_margin;
};
Vector<FloatingObject, 4> floating_objects_;
}; };
// This struct computes the max size from the line break results for the min // This struct computes the max size from the line break results for the min
......
...@@ -121,6 +121,16 @@ class CORE_EXPORT NGInlineNode : public NGLayoutInputNode { ...@@ -121,6 +121,16 @@ class CORE_EXPORT NGInlineNode : public NGLayoutInputNode {
String ToString() const; String ToString() const;
struct FloatingObject {
DISALLOW_NEW();
void Trace(blink::Visitor* visitor) {}
const ComputedStyle& float_style;
const ComputedStyle& style;
LayoutUnit float_inline_max_size_with_margin;
};
protected: protected:
bool IsPrepareLayoutFinished() const; bool IsPrepareLayoutFinished() const;
...@@ -202,4 +212,7 @@ struct DowncastTraits<NGInlineNode> { ...@@ -202,4 +212,7 @@ struct DowncastTraits<NGInlineNode> {
} // namespace blink } // namespace blink
WTF_ALLOW_MOVE_INIT_AND_COMPARE_WITH_MEM_FUNCTIONS(
blink::NGInlineNode::FloatingObject)
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_NG_INLINE_NG_INLINE_NODE_H_ #endif // THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_NG_INLINE_NG_INLINE_NODE_H_
...@@ -28,8 +28,9 @@ class NGLineBreakerTest : public NGLayoutTest { ...@@ -28,8 +28,9 @@ class NGLineBreakerTest : public NGLayoutTest {
} }
// Break lines using the specified available width. // Break lines using the specified available width.
Vector<NGLineInfo> BreakToLineInfo(NGInlineNode node, Vector<NGInlineItemResults> BreakLines(NGInlineNode node,
LayoutUnit available_width) { LayoutUnit available_width,
bool fill_first_space_ = false) {
DCHECK(node); DCHECK(node);
node.PrepareLayoutIfNeeded(); node.PrepareLayoutIfNeeded();
...@@ -42,13 +43,13 @@ class NGLineBreakerTest : public NGLayoutTest { ...@@ -42,13 +43,13 @@ class NGLineBreakerTest : public NGLayoutTest {
scoped_refptr<NGInlineBreakToken> break_token; scoped_refptr<NGInlineBreakToken> break_token;
Vector<NGLineInfo> line_infos; Vector<NGInlineItemResults> lines;
trailing_whitespaces_.resize(0); trailing_whitespaces_.resize(0);
NGExclusionSpace exclusion_space; NGExclusionSpace exclusion_space;
NGPositionedFloatVector leading_floats; NGPositionedFloatVector leading_floats;
NGLineLayoutOpportunity line_opportunity(available_width); NGLineLayoutOpportunity line_opportunity(available_width);
while (!break_token || !break_token->IsFinished()) { while (!break_token || !break_token->IsFinished()) {
NGLineInfo& line_info = line_infos.emplace_back(); NGLineInfo line_info;
NGLineBreaker line_breaker(node, NGLineBreakerMode::kContent, space, NGLineBreaker line_breaker(node, NGLineBreakerMode::kContent, space,
line_opportunity, leading_floats, 0u, line_opportunity, leading_floats, 0u,
break_token.get(), &exclusion_space); break_token.get(), &exclusion_space);
...@@ -60,21 +61,20 @@ class NGLineBreakerTest : public NGLayoutTest { ...@@ -60,21 +61,20 @@ class NGLineBreakerTest : public NGLayoutTest {
break; break;
break_token = line_breaker.CreateBreakToken(line_info); break_token = line_breaker.CreateBreakToken(line_info);
if (fill_first_space_ && lines.IsEmpty()) {
first_should_hang_trailing_space_ =
line_info.ShouldHangTrailingSpaces();
first_hang_width_ = line_info.HangWidth();
}
lines.push_back(std::move(line_info.Results()));
} }
return line_infos;
}
Vector<NGInlineItemResults> BreakLines(NGInlineNode node,
LayoutUnit available_width) {
Vector<NGLineInfo> line_infos = BreakToLineInfo(node, available_width);
Vector<NGInlineItemResults> lines;
for (NGLineInfo& line_info : line_infos)
lines.push_back(std::move(line_info.Results()));
return lines; return lines;
} }
Vector<NGLineBreaker::WhitespaceState> trailing_whitespaces_; Vector<NGLineBreaker::WhitespaceState> trailing_whitespaces_;
bool first_should_hang_trailing_space_;
LayoutUnit first_hang_width_;
}; };
namespace { namespace {
...@@ -451,7 +451,7 @@ TEST_P(NGWhitespaceStateTest, WhitespaceState) { ...@@ -451,7 +451,7 @@ TEST_P(NGWhitespaceStateTest, WhitespaceState) {
R"HTML(</div> R"HTML(</div>
)HTML"); )HTML");
Vector<NGLineInfo> line_infos = BreakToLineInfo(node, LayoutUnit(50)); BreakLines(node, LayoutUnit(50));
EXPECT_EQ(trailing_whitespaces_[0], data.expected); EXPECT_EQ(trailing_whitespaces_[0], data.expected);
} }
...@@ -512,13 +512,11 @@ TEST_P(NGTrailingSpaceWidthTest, TrailingSpaceWidth) { ...@@ -512,13 +512,11 @@ TEST_P(NGTrailingSpaceWidthTest, TrailingSpaceWidth) {
R"HTML(</div> R"HTML(</div>
)HTML"); )HTML");
Vector<NGLineInfo> line_infos = BreakToLineInfo(node, LayoutUnit(50)); BreakLines(node, LayoutUnit(50), true);
const NGLineInfo& line_info = line_infos[0]; if (first_should_hang_trailing_space_) {
if (line_info.ShouldHangTrailingSpaces()) { EXPECT_EQ(first_hang_width_, LayoutUnit(10) * data.trailing_space_width);
EXPECT_EQ(line_info.HangWidth(),
LayoutUnit(10) * data.trailing_space_width);
} else { } else {
EXPECT_EQ(line_info.HangWidth(), LayoutUnit()); EXPECT_EQ(first_hang_width_, LayoutUnit());
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment