Chromium Code Reviews| Index: third_party/WebKit/Source/core/editing/FrameSelection.cpp |
| diff --git a/third_party/WebKit/Source/core/editing/FrameSelection.cpp b/third_party/WebKit/Source/core/editing/FrameSelection.cpp |
| index 0c0c97180de781399fa076ce5f323a3945d93950..0b95867ff1f02d03e177a2e96250e07893974532 100644 |
| --- a/third_party/WebKit/Source/core/editing/FrameSelection.cpp |
| +++ b/third_party/WebKit/Source/core/editing/FrameSelection.cpp |
| @@ -964,34 +964,37 @@ void FrameSelection::RevealSelection(const ScrollAlignment& alignment, |
| // Calculation of absolute caret bounds requires clean layout. |
| GetDocument().UpdateStyleAndLayoutIgnorePendingStylesheets(); |
| - LayoutRect rect; |
| + const VisibleSelection& selection = ComputeVisibleSelectionInDOMTree(); |
| + const Position& start = selection.Start(); |
| + DCHECK(start.AnchorNode()); |
| + if (!start.AnchorNode() || !start.AnchorNode()->GetLayoutObject()) |
| + return; |
| - switch (ComputeVisibleSelectionInDOMTree().GetSelectionType()) { |
| + LayoutRect rect; |
|
yosin_UTC9
2017/07/07 05:12:51
Let's move this switch-statement into a function i
|
| + switch (selection.GetSelectionType()) { |
| case kNoSelection: |
| return; |
| case kCaretSelection: |
| rect = LayoutRect(AbsoluteCaretBounds()); |
| break; |
| - case kRangeSelection: |
| + case kRangeSelection: { |
| rect = LayoutRect( |
| reveal_extent_option == kRevealExtent |
| - ? AbsoluteCaretBoundsOf(CreateVisiblePosition( |
| - ComputeVisibleSelectionInDOMTree().Extent())) |
| + ? AbsoluteCaretBoundsOf(CreateVisiblePosition(selection.Extent())) |
| : AbsoluteSelectionBoundsOf(ComputeVisibleSelectionInFlatTree())); |
| break; |
| + } |
| } |
| - Position start = ComputeVisibleSelectionInDOMTree().Start(); |
| - DCHECK(start.AnchorNode()); |
| - if (start.AnchorNode() && start.AnchorNode()->GetLayoutObject()) { |
| - // FIXME: This code only handles scrolling the startContainer's layer, but |
| - // the selection rect could intersect more than just that. |
| - if (DocumentLoader* document_loader = frame_->Loader().GetDocumentLoader()) |
| - document_loader->GetInitialScrollState().was_scrolled_by_user = true; |
| - if (start.AnchorNode()->GetLayoutObject()->ScrollRectToVisible( |
| - rect, alignment, alignment)) |
| - UpdateAppearance(); |
| - } |
| + // FIXME: This code only handles scrolling the startContainer's layer, but |
| + // the selection rect could intersect more than just that. |
| + if (DocumentLoader* document_loader = frame_->Loader().GetDocumentLoader()) |
| + document_loader->GetInitialScrollState().was_scrolled_by_user = true; |
| + if (!start.AnchorNode()->GetLayoutObject()->ScrollRectToVisible( |
| + rect, alignment, alignment)) |
| + return; |
| + |
| + UpdateAppearance(); |
| } |
| void FrameSelection::SetSelectionFromNone() { |