Chromium Code Reviews| Index: third_party/WebKit/Source/core/editing/commands/CompositeEditCommand.cpp |
| diff --git a/third_party/WebKit/Source/core/editing/commands/CompositeEditCommand.cpp b/third_party/WebKit/Source/core/editing/commands/CompositeEditCommand.cpp |
| index 012a9693251f32f8d429ad6c62433ff70c5ff4e7..85350e77fede3c4e050a3301601b01061a3ae195 100644 |
| --- a/third_party/WebKit/Source/core/editing/commands/CompositeEditCommand.cpp |
| +++ b/third_party/WebKit/Source/core/editing/commands/CompositeEditCommand.cpp |
| @@ -1952,6 +1952,43 @@ void CompositeEditCommand::setEndingVisibleSelection( |
| } |
| } |
| +void CompositeEditCommand::shrinkEndingSelectionToFitBody() { |
|
yosin_UTC9
2017/03/17 10:04:11
I would like this function as local function and f
|
| + Position start = endingSelection().visibleStart().deepEquivalent(); |
| + Position end = endingSelection().visibleEnd().deepEquivalent(); |
| + if (start.isNull() || start.isOrphan() || end.isNull() || end.isOrphan()) |
| + return; |
| + HTMLElement* body = start.document()->body(); |
| + if (!body) |
| + return; |
| + Position bodyStart(body, PositionAnchorType::BeforeChildren); |
| + Position bodyEnd(body, PositionAnchorType::AfterChildren); |
| + bool needsToShrink = false; |
| + |
| + if (start < bodyStart) { |
| + start = bodyStart; |
| + needsToShrink = true; |
| + } |
| + if (end < bodyStart) { |
| + end = bodyStart; |
| + needsToShrink = true; |
| + } |
| + if (bodyEnd < start) { |
| + start = bodyEnd; |
| + needsToShrink = true; |
| + } |
| + if (bodyEnd < end) { |
| + end = bodyEnd; |
| + needsToShrink = true; |
| + } |
| + if (!needsToShrink) |
| + return; |
| + SelectionInDOMTree::Builder builder; |
| + builder.collapse(start); |
| + builder.extend(end); |
| + builder.setIsDirectional(endingSelection().isDirectional()); |
| + setEndingSelection(builder.build()); |
| +} |
| + |
| void CompositeEditCommand::setParent(CompositeEditCommand* parent) { |
| EditCommand::setParent(parent); |
| if (!parent) |