Commit e71613a2 authored by Dmitry Gozman's avatar Dmitry Gozman Committed by Commit Bot

Move LineOrientationLayoutRectOutsets to line_orientation_utils

This addition to LayoutRectOutsets is only used for inline layout,
but brings an unnecessary dependency geometry -> text.
Moving utility closer to the usage makes reasoning about deps easier.

Cq-Include-Trybots: master.tryserver.chromium.linux:linux_layout_tests_layout_ng
Change-Id: Ib29fe76da950b1e1316a0d9573fca0b2c93c1c84
Reviewed-on: https://chromium-review.googlesource.com/1062664Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Reviewed-by: default avatarPhilip Rogers <pdr@chromium.org>
Commit-Queue: Dmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#560340}
parent bd0655de
...@@ -1920,6 +1920,7 @@ jumbo_source_set("unit_tests") { ...@@ -1920,6 +1920,7 @@ jumbo_source_set("unit_tests") {
"layout/layout_theme_test.cc", "layout/layout_theme_test.cc",
"layout/layout_view_test.cc", "layout/layout_view_test.cc",
"layout/line/inline_text_box_test.cc", "layout/line/inline_text_box_test.cc",
"layout/line/line_orientation_utils_test.cc",
"layout/map_coordinates_test.cc", "layout/map_coordinates_test.cc",
"layout/min_max_size_test.cc", "layout/min_max_size_test.cc",
"layout/multi_column_fragmentainer_group_test.cc", "layout/multi_column_fragmentainer_group_test.cc",
......
...@@ -268,6 +268,8 @@ blink_core_sources("layout") { ...@@ -268,6 +268,8 @@ blink_core_sources("layout") {
"line/line_breaker.h", "line/line_breaker.h",
"line/line_info.h", "line/line_info.h",
"line/line_layout_state.h", "line/line_layout_state.h",
"line/line_orientation_utils.cc",
"line/line_orientation_utils.h",
"line/line_width.cc", "line/line_width.cc",
"line/line_width.h", "line/line_width.h",
"line/root_inline_box.cc", "line/root_inline_box.cc",
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "third_party/blink/renderer/core/layout/hit_test_result.h" #include "third_party/blink/renderer/core/layout/hit_test_result.h"
#include "third_party/blink/renderer/core/layout/line/glyph_overflow.h" #include "third_party/blink/renderer/core/layout/line/glyph_overflow.h"
#include "third_party/blink/renderer/core/layout/line/inline_text_box.h" #include "third_party/blink/renderer/core/layout/line/inline_text_box.h"
#include "third_party/blink/renderer/core/layout/line/line_orientation_utils.h"
#include "third_party/blink/renderer/core/layout/line/root_inline_box.h" #include "third_party/blink/renderer/core/layout/line/root_inline_box.h"
#include "third_party/blink/renderer/core/paint/box_painter.h" #include "third_party/blink/renderer/core/paint/box_painter.h"
#include "third_party/blink/renderer/core/paint/inline_flow_box_painter.h" #include "third_party/blink/renderer/core/paint/inline_flow_box_painter.h"
...@@ -988,8 +989,8 @@ inline void InlineFlowBox::AddBoxShadowVisualOverflow( ...@@ -988,8 +989,8 @@ inline void InlineFlowBox::AddBoxShadowVisualOverflow(
// Similar to how glyph overflow works, if our lines are flipped, then it's // Similar to how glyph overflow works, if our lines are flipped, then it's
// actually the opposite shadow that applies, since the line is "upside down" // actually the opposite shadow that applies, since the line is "upside down"
// in terms of block coordinates. // in terms of block coordinates.
LayoutRectOutsets logical_outsets( LayoutRectOutsets logical_outsets =
outsets.LineOrientationOutsetsWithFlippedLines(writing_mode)); LineOrientationLayoutRectOutsetsWithFlippedLines(outsets, writing_mode);
LayoutRect shadow_bounds(LogicalFrameRect()); LayoutRect shadow_bounds(LogicalFrameRect());
shadow_bounds.Expand(logical_outsets); shadow_bounds.Expand(logical_outsets);
...@@ -1013,8 +1014,8 @@ inline void InlineFlowBox::AddBorderOutsetVisualOverflow( ...@@ -1013,8 +1014,8 @@ inline void InlineFlowBox::AddBorderOutsetVisualOverflow(
// actually the opposite border that applies, since the line is "upside down" // actually the opposite border that applies, since the line is "upside down"
// in terms of block coordinates. vertical-rl is the flipped line mode. // in terms of block coordinates. vertical-rl is the flipped line mode.
LayoutRectOutsets logical_outsets = LayoutRectOutsets logical_outsets =
style.BorderImageOutsets().LineOrientationOutsetsWithFlippedLines( LineOrientationLayoutRectOutsetsWithFlippedLines(
style.GetWritingMode()); style.BorderImageOutsets(), style.GetWritingMode());
if (!IncludeLogicalLeftEdge()) if (!IncludeLogicalLeftEdge())
logical_outsets.SetLeft(LayoutUnit()); logical_outsets.SetLeft(LayoutUnit());
...@@ -1082,8 +1083,9 @@ inline void InlineFlowBox::AddTextBoxVisualOverflow( ...@@ -1082,8 +1083,9 @@ inline void InlineFlowBox::AddTextBoxVisualOverflow(
if (ShadowList* text_shadow = style.TextShadow()) { if (ShadowList* text_shadow = style.TextShadow()) {
LayoutRectOutsets text_shadow_logical_outsets = LayoutRectOutsets text_shadow_logical_outsets =
LayoutRectOutsets(text_shadow->RectOutsetsIncludingOriginal()) LineOrientationLayoutRectOutsets(
.LineOrientationOutsets(style.GetWritingMode()); LayoutRectOutsets(text_shadow->RectOutsetsIncludingOriginal()),
style.GetWritingMode());
text_shadow_logical_outsets.ClampNegativeToZero(); text_shadow_logical_outsets.ClampNegativeToZero();
visual_rect_outsets += text_shadow_logical_outsets; visual_rect_outsets += text_shadow_logical_outsets;
} }
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/core/layout/line/line_orientation_utils.h"
namespace blink {
LayoutRectOutsets LineOrientationLayoutRectOutsets(
const LayoutRectOutsets& outsets,
WritingMode writing_mode) {
if (!IsHorizontalWritingMode(writing_mode)) {
return LayoutRectOutsets(outsets.Left(), outsets.Bottom(), outsets.Right(),
outsets.Top());
}
return outsets;
}
LayoutRectOutsets LineOrientationLayoutRectOutsetsWithFlippedLines(
const LayoutRectOutsets& original,
WritingMode writing_mode) {
LayoutRectOutsets outsets =
LineOrientationLayoutRectOutsets(original, writing_mode);
if (IsFlippedLinesWritingMode(writing_mode)) {
return LayoutRectOutsets(outsets.Bottom(), outsets.Right(), outsets.Top(),
outsets.Left());
}
return outsets;
}
} // namespace blink
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_LINE_LINE_ORIENTATION_UTILS_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_LINE_LINE_ORIENTATION_UTILS_H_
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/platform/geometry/layout_rect_outsets.h"
#include "third_party/blink/renderer/platform/text/writing_mode.h"
namespace blink {
// Produces a new LayoutRectOutsets in line orientation
// (https://www.w3.org/TR/css-writing-modes-3/#line-orientation), whose
// - |top| is the logical 'over',
// - |right| is the logical 'line right',
// - |bottom| is the logical 'under',
// - |left| is the logical 'line left'.
CORE_EXPORT LayoutRectOutsets
LineOrientationLayoutRectOutsets(const LayoutRectOutsets&, WritingMode);
// The same as |logicalOutsets|, but also adjusting for flipped lines.
CORE_EXPORT LayoutRectOutsets
LineOrientationLayoutRectOutsetsWithFlippedLines(const LayoutRectOutsets&,
WritingMode);
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_LINE_LINE_ORIENTATION_UTILS_H_
...@@ -2,38 +2,42 @@ ...@@ -2,38 +2,42 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "third_party/blink/renderer/platform/geometry/layout_rect_outsets.h" #include "third_party/blink/renderer/core/layout/line/line_orientation_utils.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace blink { namespace blink {
namespace { namespace {
TEST(LayoutRectOutsetsTest, LineOrientationOutsets_Horizontal) { TEST(LineOrientationUtilsTest, LineOrientationLayoutRectOutsets_Horizontal) {
LayoutRectOutsets outsets(1, 2, 3, 4); LayoutRectOutsets outsets(1, 2, 3, 4);
EXPECT_EQ(LayoutRectOutsets(1, 2, 3, 4), EXPECT_EQ(
outsets.LineOrientationOutsets(WritingMode::kHorizontalTb)); LayoutRectOutsets(1, 2, 3, 4),
LineOrientationLayoutRectOutsets(outsets, WritingMode::kHorizontalTb));
} }
TEST(LayoutRectOutsetsTest, LineOrientationOutsets_Vertical) { TEST(LineOrientationUtilsTest, LineOrientationLayoutRectOutsets_Vertical) {
LayoutRectOutsets outsets(1, 2, 3, 4); LayoutRectOutsets outsets(1, 2, 3, 4);
EXPECT_EQ(LayoutRectOutsets(4, 3, 2, 1), EXPECT_EQ(
outsets.LineOrientationOutsets(WritingMode::kVerticalLr)); LayoutRectOutsets(4, 3, 2, 1),
EXPECT_EQ(LayoutRectOutsets(4, 3, 2, 1), LineOrientationLayoutRectOutsets(outsets, WritingMode::kVerticalLr));
outsets.LineOrientationOutsets(WritingMode::kVerticalRl)); EXPECT_EQ(
LayoutRectOutsets(4, 3, 2, 1),
LineOrientationLayoutRectOutsets(outsets, WritingMode::kVerticalRl));
} }
TEST(LayoutRectOutsetsTest, LineOrientationOutsetsWithFlippedLines) { TEST(LineOrientationUtilsTest,
LineOrientationLayoutRectOutsetsWithFlippedLines) {
LayoutRectOutsets outsets(1, 2, 3, 4); LayoutRectOutsets outsets(1, 2, 3, 4);
EXPECT_EQ(LayoutRectOutsets(1, 2, 3, 4), EXPECT_EQ(LayoutRectOutsets(1, 2, 3, 4),
outsets.LineOrientationOutsetsWithFlippedLines( LineOrientationLayoutRectOutsetsWithFlippedLines(
WritingMode::kHorizontalTb)); outsets, WritingMode::kHorizontalTb));
EXPECT_EQ( EXPECT_EQ(LayoutRectOutsets(2, 3, 4, 1),
LayoutRectOutsets(2, 3, 4, 1), LineOrientationLayoutRectOutsetsWithFlippedLines(
outsets.LineOrientationOutsetsWithFlippedLines(WritingMode::kVerticalLr)); outsets, WritingMode::kVerticalLr));
EXPECT_EQ( EXPECT_EQ(LayoutRectOutsets(4, 3, 2, 1),
LayoutRectOutsets(4, 3, 2, 1), LineOrientationLayoutRectOutsetsWithFlippedLines(
outsets.LineOrientationOutsetsWithFlippedLines(WritingMode::kVerticalRl)); outsets, WritingMode::kVerticalRl));
} }
} // namespace } // namespace
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "third_party/blink/renderer/core/editing/position_with_affinity.h" #include "third_party/blink/renderer/core/editing/position_with_affinity.h"
#include "third_party/blink/renderer/core/editing/text_affinity.h" #include "third_party/blink/renderer/core/editing/text_affinity.h"
#include "third_party/blink/renderer/core/layout/layout_text_fragment.h" #include "third_party/blink/renderer/core/layout/layout_text_fragment.h"
#include "third_party/blink/renderer/core/layout/line/line_orientation_utils.h"
#include "third_party/blink/renderer/core/layout/ng/geometry/ng_logical_rect.h" #include "third_party/blink/renderer/core/layout/ng/geometry/ng_logical_rect.h"
#include "third_party/blink/renderer/core/layout/ng/geometry/ng_physical_offset_rect.h" #include "third_party/blink/renderer/core/layout/ng/geometry/ng_physical_offset_rect.h"
#include "third_party/blink/renderer/core/layout/ng/inline/ng_line_height_metrics.h" #include "third_party/blink/renderer/core/layout/ng/inline/ng_line_height_metrics.h"
...@@ -128,8 +129,9 @@ NGPhysicalOffsetRect NGPhysicalTextFragment::SelfVisualRect() const { ...@@ -128,8 +129,9 @@ NGPhysicalOffsetRect NGPhysicalTextFragment::SelfVisualRect() const {
if (ShadowList* text_shadow = style.TextShadow()) { if (ShadowList* text_shadow = style.TextShadow()) {
LayoutRectOutsets text_shadow_logical_outsets = LayoutRectOutsets text_shadow_logical_outsets =
LayoutRectOutsets(text_shadow->RectOutsetsIncludingOriginal()) LineOrientationLayoutRectOutsets(
.LineOrientationOutsets(style.GetWritingMode()); LayoutRectOutsets(text_shadow->RectOutsetsIncludingOriginal()),
style.GetWritingMode());
text_shadow_logical_outsets.ClampNegativeToZero(); text_shadow_logical_outsets.ClampNegativeToZero();
visual_rect.Expand(text_shadow_logical_outsets); visual_rect.Expand(text_shadow_logical_outsets);
} }
......
...@@ -1792,7 +1792,6 @@ jumbo_source_set("blink_platform_unittests_sources") { ...@@ -1792,7 +1792,6 @@ jumbo_source_set("blink_platform_unittests_sources") {
"geometry/geometry_test_helpers.cc", "geometry/geometry_test_helpers.cc",
"geometry/geometry_test_helpers.h", "geometry/geometry_test_helpers.h",
"geometry/int_rect_test.cc", "geometry/int_rect_test.cc",
"geometry/layout_rect_outsets_test.cc",
"geometry/layout_rect_test.cc", "geometry/layout_rect_test.cc",
"geometry/layout_size_test.cc", "geometry/layout_size_test.cc",
"geometry/region_test.cc", "geometry/region_test.cc",
......
...@@ -12,7 +12,6 @@ include_rules = [ ...@@ -12,7 +12,6 @@ include_rules = [
"+third_party/blink/renderer/platform/layout_unit.h", "+third_party/blink/renderer/platform/layout_unit.h",
"+third_party/blink/renderer/platform/platform_export.h", "+third_party/blink/renderer/platform/platform_export.h",
"+third_party/blink/renderer/platform/pod_interval_tree.h", "+third_party/blink/renderer/platform/pod_interval_tree.h",
"+third_party/blink/renderer/platform/text/writing_mode.h",
"+third_party/blink/renderer/platform/wtf", "+third_party/blink/renderer/platform/wtf",
"+ui/gfx/geometry", "+ui/gfx/geometry",
] ]
...@@ -49,19 +49,4 @@ void LayoutRectOutsets::Unite(const LayoutRectOutsets& other) { ...@@ -49,19 +49,4 @@ void LayoutRectOutsets::Unite(const LayoutRectOutsets& other) {
left_ = std::max(left_, other.left_); left_ = std::max(left_, other.left_);
} }
LayoutRectOutsets LayoutRectOutsets::LineOrientationOutsets(
WritingMode writing_mode) const {
if (!IsHorizontalWritingMode(writing_mode))
return LayoutRectOutsets(left_, bottom_, right_, top_);
return *this;
}
LayoutRectOutsets LayoutRectOutsets::LineOrientationOutsetsWithFlippedLines(
WritingMode writing_mode) const {
LayoutRectOutsets outsets = LineOrientationOutsets(writing_mode);
if (IsFlippedLinesWritingMode(writing_mode))
std::swap(outsets.top_, outsets.bottom_);
return outsets;
}
} // namespace blink } // namespace blink
...@@ -36,7 +36,6 @@ ...@@ -36,7 +36,6 @@
#include "third_party/blink/renderer/platform/geometry/layout_size.h" #include "third_party/blink/renderer/platform/geometry/layout_size.h"
#include "third_party/blink/renderer/platform/layout_unit.h" #include "third_party/blink/renderer/platform/layout_unit.h"
#include "third_party/blink/renderer/platform/platform_export.h" #include "third_party/blink/renderer/platform/platform_export.h"
#include "third_party/blink/renderer/platform/text/writing_mode.h"
#include "third_party/blink/renderer/platform/wtf/allocator.h" #include "third_party/blink/renderer/platform/wtf/allocator.h"
namespace blink { namespace blink {
...@@ -93,17 +92,6 @@ class PLATFORM_EXPORT LayoutRectOutsets { ...@@ -93,17 +92,6 @@ class PLATFORM_EXPORT LayoutRectOutsets {
void FlipHorizontally() { std::swap(left_, right_); } void FlipHorizontally() { std::swap(left_, right_); }
// Produces a new LayoutRectOutsets in line orientation
// (https://www.w3.org/TR/css-writing-modes-3/#line-orientation), whose
// - |top| is the logical 'over',
// - |right| is the logical 'line right',
// - |bottom| is the logical 'under',
// - |left| is the logical 'line left'.
LayoutRectOutsets LineOrientationOutsets(WritingMode) const;
// The same as |logicalOutsets|, but also adjusting for flipped lines.
LayoutRectOutsets LineOrientationOutsetsWithFlippedLines(WritingMode) const;
bool operator==(const LayoutRectOutsets other) const { bool operator==(const LayoutRectOutsets other) const {
return Top() == other.Top() && Right() == other.Right() && return Top() == other.Top() && Right() == other.Right() &&
Bottom() == other.Bottom() && Left() == other.Left(); Bottom() == other.Bottom() && Left() == other.Left();
......
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