Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(113)

Unified Diff: third_party/WebKit/Source/core/editing/FrameSelection.cpp

Issue 2972153002: Refactor FrameSelection::RevealSelection (Closed)
Patch Set: clang fix Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..957a1cea29401d0508397db92584584083e4ac6c 100644
--- a/third_party/WebKit/Source/core/editing/FrameSelection.cpp
+++ b/third_party/WebKit/Source/core/editing/FrameSelection.cpp
@@ -964,34 +964,39 @@ void FrameSelection::RevealSelection(const ScrollAlignment& alignment,
// Calculation of absolute caret bounds requires clean layout.
GetDocument().UpdateStyleAndLayoutIgnorePendingStylesheets();
- LayoutRect rect;
+ const VisibleSelection& selection = ComputeVisibleSelectionInDOMTree();
+ if (selection.GetSelectionType() == kNoSelection)
+ return;
- switch (ComputeVisibleSelectionInDOMTree().GetSelectionType()) {
- case kNoSelection:
- return;
+ LayoutRect rect;
+ switch (selection.GetSelectionType()) {
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;
+ }
+ default:
+ NOTREACHED();
+ break;
}
- Position start = ComputeVisibleSelectionInDOMTree().Start();
+ // 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;
+ const Position& start = selection.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();
- }
+ DCHECK(start.AnchorNode()->GetLayoutObject());
+ if (!start.AnchorNode()->GetLayoutObject()->ScrollRectToVisible(
+ rect, alignment, alignment))
+ return;
+
+ UpdateAppearance();
}
void FrameSelection::SetSelectionFromNone() {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698