Commit b9bcd436 authored by Koji Ishii's avatar Koji Ishii Committed by Commit Bot

Cleanup InlineFlowBox::AddTextBoxVisualOverflow

In order to port/share the logic with LayoutNG, this patch cleans up
visual overflow logic for InlineTextBox.

Bug: 636993
Cq-Include-Trybots: master.tryserver.chromium.linux:linux_layout_tests_slimming_paint_v2
Change-Id: Ie2bd84c6f332d372b744aa0b7c6de6b9e7406bc8
Reviewed-on: https://chromium-review.googlesource.com/768592
Commit-Queue: Koji Ishii <kojii@chromium.org>
Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Cr-Commit-Position: refs/heads/master@{#517330}
parent 2d8d9dd6
...@@ -1068,94 +1068,52 @@ inline void InlineFlowBox::AddTextBoxVisualOverflow( ...@@ -1068,94 +1068,52 @@ inline void InlineFlowBox::AddTextBoxVisualOverflow(
if (text_box->KnownToHaveNoOverflow()) if (text_box->KnownToHaveNoOverflow())
return; return;
LayoutRectOutsets visual_rect_outsets;
const ComputedStyle& style = const ComputedStyle& style =
text_box->GetLineLayoutItem().StyleRef(IsFirstLineStyle()); text_box->GetLineLayoutItem().StyleRef(IsFirstLineStyle());
GlyphOverflowAndFallbackFontsMap::iterator it = GlyphOverflowAndFallbackFontsMap::iterator it =
text_box_data_map.find(text_box); text_box_data_map.find(text_box);
GlyphOverflow* glyph_overflow = if (it != text_box_data_map.end()) {
it == text_box_data_map.end() ? nullptr : &it->value.second; const GlyphOverflow& glyph_overflow = it->value.second;
bool is_flipped_line = style.IsFlippedLinesWritingMode(); bool is_flipped_line = style.IsFlippedLinesWritingMode();
visual_rect_outsets = EnclosingLayoutRectOutsets(FloatRectOutsets(
float top_glyph_edge = is_flipped_line ? glyph_overflow.bottom : glyph_overflow.top,
glyph_overflow glyph_overflow.right,
? (is_flipped_line ? glyph_overflow->bottom : glyph_overflow->top) is_flipped_line ? glyph_overflow.top : glyph_overflow.bottom,
: 0; glyph_overflow.left));
float bottom_glyph_edge = }
glyph_overflow
? (is_flipped_line ? glyph_overflow->top : glyph_overflow->bottom) if (float stroke_width = style.TextStrokeWidth()) {
: 0; visual_rect_outsets += LayoutUnit::FromFloatCeil(stroke_width / 2.0f);
float left_glyph_edge = glyph_overflow ? glyph_overflow->left : 0; }
float right_glyph_edge = glyph_overflow ? glyph_overflow->right : 0;
float stroke_overflow = style.TextStrokeWidth() / 2.0f;
float top_glyph_overflow = -stroke_overflow - top_glyph_edge;
float bottom_glyph_overflow = stroke_overflow + bottom_glyph_edge;
float left_glyph_overflow = -stroke_overflow - left_glyph_edge;
float right_glyph_overflow = stroke_overflow + right_glyph_edge;
TextEmphasisPosition emphasis_mark_position; TextEmphasisPosition emphasis_mark_position;
if (style.GetTextEmphasisMark() != TextEmphasisMark::kNone && if (style.GetTextEmphasisMark() != TextEmphasisMark::kNone &&
text_box->GetEmphasisMarkPosition(style, emphasis_mark_position)) { text_box->GetEmphasisMarkPosition(style, emphasis_mark_position)) {
float emphasis_mark_height = LayoutUnit emphasis_mark_height = LayoutUnit(
style.GetFont().EmphasisMarkHeight(style.TextEmphasisMarkString()); style.GetFont().EmphasisMarkHeight(style.TextEmphasisMarkString()));
if (HasEmphasisMarkBefore(text_box)) if (HasEmphasisMarkBefore(text_box)) {
top_glyph_overflow = std::min(top_glyph_overflow, -emphasis_mark_height); visual_rect_outsets.SetTop(
else std::max(visual_rect_outsets.Top(), emphasis_mark_height));
bottom_glyph_overflow = } else {
std::max(bottom_glyph_overflow, emphasis_mark_height); visual_rect_outsets.SetBottom(
std::max(visual_rect_outsets.Bottom(), emphasis_mark_height));
}
} }
LayoutRectOutsets text_shadow_logical_outsets;
if (ShadowList* text_shadow = style.TextShadow()) { if (ShadowList* text_shadow = style.TextShadow()) {
text_shadow_logical_outsets = LayoutRectOutsets text_shadow_logical_outsets =
LayoutRectOutsets(text_shadow->RectOutsetsIncludingOriginal()) LayoutRectOutsets(text_shadow->RectOutsetsIncludingOriginal())
.LineOrientationOutsets(style.GetWritingMode()); .LineOrientationOutsets(style.GetWritingMode());
text_shadow_logical_outsets.ClampNegativeToZero();
visual_rect_outsets += text_shadow_logical_outsets;
} }
// FIXME: This code currently uses negative values for expansion of the top LayoutRect frame_rect = text_box->LogicalFrameRect();
// and left edges. This should be cleaned up. frame_rect.Expand(visual_rect_outsets);
LayoutUnit text_shadow_logical_top = -text_shadow_logical_outsets.Top(); frame_rect = LayoutRect(EnclosingIntRect(frame_rect));
LayoutUnit text_shadow_logical_bottom = text_shadow_logical_outsets.Bottom(); logical_visual_overflow.Unite(frame_rect);
LayoutUnit text_shadow_logical_left = -text_shadow_logical_outsets.Left();
LayoutUnit text_shadow_logical_right = text_shadow_logical_outsets.Right();
LayoutUnit child_overflow_logical_top(std::min(
text_shadow_logical_top + top_glyph_overflow, top_glyph_overflow));
LayoutUnit child_overflow_logical_bottom(
std::max(text_shadow_logical_bottom + bottom_glyph_overflow,
bottom_glyph_overflow));
LayoutUnit child_overflow_logical_left(std::min(
text_shadow_logical_left + left_glyph_overflow, left_glyph_overflow));
LayoutUnit child_overflow_logical_right(std::max(
text_shadow_logical_right + right_glyph_overflow, right_glyph_overflow));
int enclosing_logical_top_with_overflow =
(text_box->LogicalTop() + child_overflow_logical_top).Floor();
int enclosing_logical_bottom_with_overflow =
(text_box->LogicalBottom() + child_overflow_logical_bottom).Ceil();
int enclosing_logical_left_with_overflow =
(text_box->LogicalLeft() + child_overflow_logical_left).Floor();
int enclosing_logical_right_with_overflow =
(text_box->LogicalRight() + child_overflow_logical_right).Ceil();
LayoutUnit logical_top_visual_overflow =
std::min(LayoutUnit(enclosing_logical_top_with_overflow),
logical_visual_overflow.Y());
LayoutUnit logical_bottom_visual_overflow =
std::max(LayoutUnit(enclosing_logical_bottom_with_overflow),
logical_visual_overflow.MaxY());
LayoutUnit logical_left_visual_overflow =
std::min(LayoutUnit(enclosing_logical_left_with_overflow),
logical_visual_overflow.X());
LayoutUnit logical_right_visual_overflow =
std::max(LayoutUnit(enclosing_logical_right_with_overflow),
logical_visual_overflow.MaxX());
logical_visual_overflow =
LayoutRect(logical_left_visual_overflow, logical_top_visual_overflow,
logical_right_visual_overflow - logical_left_visual_overflow,
logical_bottom_visual_overflow - logical_top_visual_overflow);
if (logical_visual_overflow != text_box->LogicalFrameRect()) if (logical_visual_overflow != text_box->LogicalFrameRect())
text_box->SetLogicalOverflowRect(logical_visual_overflow); text_box->SetLogicalOverflowRect(logical_visual_overflow);
......
...@@ -35,6 +35,13 @@ ...@@ -35,6 +35,13 @@
namespace blink { namespace blink {
void LayoutRectOutsets::ClampNegativeToZero() {
top_ = top_.ClampNegativeToZero();
right_ = right_.ClampNegativeToZero();
bottom_ = bottom_.ClampNegativeToZero();
left_ = left_.ClampNegativeToZero();
}
LayoutRectOutsets LayoutRectOutsets::LineOrientationOutsets( LayoutRectOutsets LayoutRectOutsets::LineOrientationOutsets(
WritingMode writing_mode) const { WritingMode writing_mode) const {
if (!IsHorizontalWritingMode(writing_mode)) if (!IsHorizontalWritingMode(writing_mode))
......
...@@ -83,6 +83,8 @@ class PLATFORM_EXPORT LayoutRectOutsets { ...@@ -83,6 +83,8 @@ class PLATFORM_EXPORT LayoutRectOutsets {
void SetBottom(LayoutUnit value) { bottom_ = value; } void SetBottom(LayoutUnit value) { bottom_ = value; }
void SetLeft(LayoutUnit value) { left_ = value; } void SetLeft(LayoutUnit value) { left_ = value; }
void ClampNegativeToZero();
// Produces a new LayoutRectOutsets in line orientation // Produces a new LayoutRectOutsets in line orientation
// (https://www.w3.org/TR/css-writing-modes-3/#line-orientation), whose // (https://www.w3.org/TR/css-writing-modes-3/#line-orientation), whose
// - |top| is the logical 'over', // - |top| is the logical 'over',
...@@ -115,6 +117,14 @@ inline LayoutRectOutsets& operator+=(LayoutRectOutsets& a, ...@@ -115,6 +117,14 @@ inline LayoutRectOutsets& operator+=(LayoutRectOutsets& a,
return a; return a;
} }
inline LayoutRectOutsets& operator+=(LayoutRectOutsets& a, LayoutUnit b) {
a.SetTop(a.Top() + b);
a.SetRight(a.Right() + b);
a.SetBottom(a.Bottom() + b);
a.SetLeft(a.Left() + b);
return a;
}
inline LayoutRectOutsets operator+(const LayoutRectOutsets& a, inline LayoutRectOutsets operator+(const LayoutRectOutsets& a,
const LayoutRectOutsets& b) { const LayoutRectOutsets& b) {
return LayoutRectOutsets(a.Top() + b.Top(), a.Right() + b.Right(), return LayoutRectOutsets(a.Top() + b.Top(), a.Right() + b.Right(),
...@@ -125,6 +135,14 @@ inline LayoutRectOutsets operator-(const LayoutRectOutsets& a) { ...@@ -125,6 +135,14 @@ inline LayoutRectOutsets operator-(const LayoutRectOutsets& a) {
return LayoutRectOutsets(-a.Top(), -a.Right(), -a.Bottom(), -a.Left()); return LayoutRectOutsets(-a.Top(), -a.Right(), -a.Bottom(), -a.Left());
} }
inline LayoutRectOutsets EnclosingLayoutRectOutsets(
const FloatRectOutsets& rect) {
return LayoutRectOutsets(LayoutUnit::FromFloatCeil(rect.Top()),
LayoutUnit::FromFloatCeil(rect.Right()),
LayoutUnit::FromFloatCeil(rect.Bottom()),
LayoutUnit::FromFloatCeil(rect.Left()));
}
} // namespace blink } // namespace blink
#endif // LayoutRectOutsets_h #endif // LayoutRectOutsets_h
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