summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/editing/layout_selection.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/third_party/blink/renderer/core/editing/layout_selection.cc')
-rw-r--r--chromium/third_party/blink/renderer/core/editing/layout_selection.cc30
1 files changed, 23 insertions, 7 deletions
diff --git a/chromium/third_party/blink/renderer/core/editing/layout_selection.cc b/chromium/third_party/blink/renderer/core/editing/layout_selection.cc
index c8798dae7b6..a93e9e1f1e6 100644
--- a/chromium/third_party/blink/renderer/core/editing/layout_selection.cc
+++ b/chromium/third_party/blink/renderer/core/editing/layout_selection.cc
@@ -36,11 +36,28 @@
#include "third_party/blink/renderer/core/layout/ng/inline/ng_offset_mapping.h"
#include "third_party/blink/renderer/core/layout/ng/inline/ng_physical_line_box_fragment.h"
#include "third_party/blink/renderer/core/layout/ng/inline/ng_physical_text_fragment.h"
+#include "third_party/blink/renderer/core/layout/ng/ng_block_node.h"
#include "third_party/blink/renderer/core/paint/ng/ng_paint_fragment.h"
#include "third_party/blink/renderer/core/paint/paint_layer.h"
+#include "third_party/blink/renderer/platform/fonts/shaping/shape_result_view.h"
namespace blink {
+namespace {
+
+// TODO(yoichio): Share condition between NGOffsetMapping::AcceptsPosition.
+bool ShouldUseLayoutNGTextContent(const Node& node) {
+ LayoutObject* layout_object = node.GetLayoutObject();
+ DCHECK(layout_object);
+ if (layout_object->IsInline())
+ return layout_object->ContainingNGBlockFlow();
+ if (LayoutBlockFlow* block_flow = ToLayoutBlockFlowOrNull(layout_object))
+ return NGBlockNode::CanUseNewLayout(*block_flow);
+ return false;
+}
+
+} // namespace
+
// The current selection to be painted is represented as 2 pairs of
// (Node, offset).
// Each offset represents text offsets on selection edge if it is text.
@@ -464,7 +481,7 @@ static base::Optional<unsigned> GetTextContentOffset(const Position& position) {
#if DCHECK_IS_ON()
DCHECK(IsPositionValidText(position));
#endif
- DCHECK(position.AnchorNode()->GetLayoutObject()->EnclosingNGBlockFlow());
+ DCHECK(ShouldUseLayoutNGTextContent(*position.AnchorNode()));
const NGOffsetMapping* const offset_mapping =
NGOffsetMapping::GetFor(position);
DCHECK(offset_mapping);
@@ -514,13 +531,13 @@ static SelectionPaintRange* ComputeNewPaintRange(
const Node& start_node = *paint_range.start_node;
// If LayoutObject is not in NG, use legacy offset.
const base::Optional<unsigned> start_offset =
- start_node.GetLayoutObject()->EnclosingNGBlockFlow()
+ ShouldUseLayoutNGTextContent(start_node)
? GetTextContentOffsetStart(start_node, paint_range.start_offset)
: paint_range.start_offset;
const Node& end_node = *paint_range.end_node;
const base::Optional<unsigned> end_offset =
- end_node.GetLayoutObject()->EnclosingNGBlockFlow()
+ ShouldUseLayoutNGTextContent(end_node)
? GetTextContentOffsetEnd(end_node, paint_range.end_offset)
: paint_range.end_offset;
@@ -547,7 +564,7 @@ static bool IsLastLineInInlineBlock(const NGPaintFragment& line) {
NGPaintFragment* parent = line.Parent();
if (!parent->PhysicalFragment().IsAtomicInline())
return false;
- return parent->Children().back().get() == &line;
+ return &parent->Children().back() == &line;
}
static bool IsBeforeSoftLineBreak(const NGPaintFragment& fragment) {
@@ -569,9 +586,8 @@ static bool IsBeforeSoftLineBreak(const NGPaintFragment& fragment) {
// Even If |fragment| is before linebreak, if its direction differs to line
// direction, we don't paint line break. See
// paint/selection/text-selection-newline-mixed-ltr-rtl.html.
- const ShapeResult* shape_result =
- ToNGPhysicalTextFragment(fragment.PhysicalFragment()).TextShapeResult();
- return physical_line_box.BaseDirection() == shape_result->Direction();
+ return physical_line_box.BaseDirection() ==
+ fragment.PhysicalFragment().ResolvedDirection();
}
static Text* AssociatedTextNode(const LayoutText& text) {