Chromium Code Reviews| Index: third_party/WebKit/Source/core/editing/DOMSelection.cpp |
| diff --git a/third_party/WebKit/Source/core/editing/DOMSelection.cpp b/third_party/WebKit/Source/core/editing/DOMSelection.cpp |
| index fd59dced6fe22cd8f6fb1b08cf23cbcbe70d51bb..d473161afba0f1e496fda0842d1b9f6079b6c2fb 100644 |
| --- a/third_party/WebKit/Source/core/editing/DOMSelection.cpp |
| +++ b/third_party/WebKit/Source/core/editing/DOMSelection.cpp |
| @@ -224,7 +224,9 @@ unsigned DOMSelection::rangeCount() const { |
| if (isSelectionOfDocument()) |
| return 1; |
| // In ShadowRoot, we need to try adjustment. |
| - return createRangeFromSelectionEditor() ? 1 : 0; |
| + if (createRangeFromSelectionEditor().isNotNull()) |
|
yosin_UTC9
2017/03/28 07:04:31
nit: I prefer using "?:" as original
return creat
yoichio
2017/03/28 09:32:51
New early-return follows above early returns of 1
|
| + return 1; |
| + return 0; |
| } |
| // https://www.w3.org/TR/selection-api/#dom-selection-collapse |
| @@ -530,7 +532,7 @@ Range* DOMSelection::getRangeAt(unsigned index, |
| if (Range* cachedRange = documentCachedRange()) |
| return cachedRange; |
| - Range* range = createRangeFromSelectionEditor(); |
| + Range* range = createRange(createRangeFromSelectionEditor()); |
| cacheRangeIfSelectionOfDocument(range); |
| return range; |
| } |
| @@ -539,23 +541,24 @@ Range* DOMSelection::primaryRangeOrNull() const { |
| return rangeCount() > 0 ? getRangeAt(0, ASSERT_NO_EXCEPTION) : nullptr; |
| } |
| -Range* DOMSelection::createRangeFromSelectionEditor() const { |
| +EphemeralRange DOMSelection::createRangeFromSelectionEditor() const { |
| const VisibleSelection& selection = visibleSelection(); |
| const Position& anchor = blink::anchorPosition(selection); |
| if (isSelectionOfDocument() && !anchor.anchorNode()->isInShadowTree()) |
| - return createRange(firstEphemeralRangeOf(selection)); |
| + return firstEphemeralRangeOf(selection); |
| + |
| + Node* const anchorNode = shadowAdjustedNode(anchor); |
| + if (!anchorNode) // crbug.com/595100 |
| + return EphemeralRange(); |
| - Node* const node = shadowAdjustedNode(anchor); |
| - if (!node) // crbug.com/595100 |
| - return nullptr; |
| const Position& focus = focusPosition(selection); |
| - if (!selection.isBaseFirst()) { |
| - return Range::create(*anchor.document(), shadowAdjustedNode(focus), |
| - shadowAdjustedOffset(focus), node, |
| - shadowAdjustedOffset(anchor)); |
| - } |
| - return Range::create(*anchor.document(), node, shadowAdjustedOffset(anchor), |
| - shadowAdjustedNode(focus), shadowAdjustedOffset(focus)); |
| + const Position shadowAdjustedFocus = |
| + Position(shadowAdjustedNode(focus), shadowAdjustedOffset(focus)); |
| + const Position shadowAdjustedAnchor = |
| + Position(anchorNode, shadowAdjustedOffset(anchor)); |
| + if (selection.isBaseFirst()) |
| + return EphemeralRange(shadowAdjustedAnchor, shadowAdjustedFocus); |
| + return EphemeralRange(shadowAdjustedFocus, shadowAdjustedAnchor); |
| } |
| bool DOMSelection::isSelectionOfDocument() const { |