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

Side by Side Diff: third_party/WebKit/Source/core/editing/LayoutSelection.cpp

Issue 2970653003: Make CalcSelection return EphemeralRange. (Closed)
Patch Set: update 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights
4 * reserved. 4 * reserved.
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 const VisibleSelectionInFlatTree& selection) { 113 const VisibleSelectionInFlatTree& selection) {
114 if (!frame_selection.ShouldShowBlockCursor()) 114 if (!frame_selection.ShouldShowBlockCursor())
115 return false; 115 return false;
116 if (selection.GetSelectionType() != SelectionType::kCaretSelection) 116 if (selection.GetSelectionType() != SelectionType::kCaretSelection)
117 return false; 117 return false;
118 if (IsLogicalEndOfLine(selection.VisibleEnd())) 118 if (IsLogicalEndOfLine(selection.VisibleEnd()))
119 return false; 119 return false;
120 return true; 120 return true;
121 } 121 }
122 122
123 static VisibleSelectionInFlatTree CalcSelection( 123 static EphemeralRangeInFlatTree CalcSelection(
124 const FrameSelection& frame_selection) { 124 const FrameSelection& frame_selection) {
125 const VisibleSelectionInFlatTree& original_selection = 125 const VisibleSelectionInFlatTree& original_selection =
126 frame_selection.ComputeVisibleSelectionInFlatTree(); 126 frame_selection.ComputeVisibleSelectionInFlatTree();
127 127
128 if (!ShouldShowBlockCursor(frame_selection, original_selection)) 128 if (!ShouldShowBlockCursor(frame_selection, original_selection))
129 return original_selection; 129 return {original_selection.Start(), original_selection.End()};
130 130
131 const PositionInFlatTree end_position = NextPositionOf( 131 const PositionInFlatTree end_position = NextPositionOf(
132 original_selection.Start(), PositionMoveType::kGraphemeCluster); 132 original_selection.Start(), PositionMoveType::kGraphemeCluster);
133 return CreateVisibleSelection( 133 const VisibleSelectionInFlatTree& block_cursor = CreateVisibleSelection(
134 SelectionInFlatTree::Builder() 134 SelectionInFlatTree::Builder()
135 .SetBaseAndExtent(original_selection.Start(), end_position) 135 .SetBaseAndExtent(original_selection.Start(), end_position)
136 .Build()); 136 .Build());
137 return {block_cursor.Start(), block_cursor.End()};
137 } 138 }
138 139
139 // Objects each have a single selection rect to examine. 140 // Objects each have a single selection rect to examine.
140 using SelectedObjectMap = HashMap<LayoutObject*, SelectionState>; 141 using SelectedObjectMap = HashMap<LayoutObject*, SelectionState>;
141 // Blocks contain selected objects and fill gaps between them, either on the 142 // Blocks contain selected objects and fill gaps between them, either on the
142 // left, right, or in between lines and blocks. 143 // left, right, or in between lines and blocks.
143 // In order to get the visual rect right, we have to examine left, middle, and 144 // In order to get the visual rect right, we have to examine left, middle, and
144 // right rects individually, since otherwise the union of those rects might 145 // right rects individually, since otherwise the union of those rects might
145 // remain the same even when changes have occurred. 146 // remain the same even when changes have occurred.
146 using SelectedBlockMap = HashMap<LayoutBlock*, SelectionState>; 147 using SelectedBlockMap = HashMap<LayoutBlock*, SelectionState>;
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 paint_range_ = SelectionPaintRange(); 291 paint_range_ = SelectionPaintRange();
291 } 292 }
292 293
293 static SelectionPaintRange CalcSelectionPaintRange( 294 static SelectionPaintRange CalcSelectionPaintRange(
294 const FrameSelection& frame_selection) { 295 const FrameSelection& frame_selection) {
295 const SelectionInDOMTree& selection_in_dom = 296 const SelectionInDOMTree& selection_in_dom =
296 frame_selection.GetSelectionInDOMTree(); 297 frame_selection.GetSelectionInDOMTree();
297 if (selection_in_dom.IsNone()) 298 if (selection_in_dom.IsNone())
298 return SelectionPaintRange(); 299 return SelectionPaintRange();
299 300
300 const VisibleSelectionInFlatTree& selection = CalcSelection(frame_selection); 301 const EphemeralRangeInFlatTree& selection = CalcSelection(frame_selection);
301 if (!selection.IsRange() || frame_selection.IsHidden()) 302 if (selection.IsCollapsed() || frame_selection.IsHidden())
302 return SelectionPaintRange(); 303 return SelectionPaintRange();
303 304
304 DCHECK(!selection.IsNone()); 305 const PositionInFlatTree start_pos = selection.StartPosition();
305 const PositionInFlatTree start_pos = selection.Start(); 306 const PositionInFlatTree end_pos = selection.EndPosition();
306 const PositionInFlatTree end_pos = selection.End();
307 DCHECK_LE(start_pos, end_pos); 307 DCHECK_LE(start_pos, end_pos);
308 LayoutObject* start_layout_object = start_pos.AnchorNode()->GetLayoutObject(); 308 LayoutObject* start_layout_object = start_pos.AnchorNode()->GetLayoutObject();
309 LayoutObject* end_layout_object = end_pos.AnchorNode()->GetLayoutObject(); 309 LayoutObject* end_layout_object = end_pos.AnchorNode()->GetLayoutObject();
310 DCHECK(start_layout_object); 310 DCHECK(start_layout_object);
311 DCHECK(end_layout_object); 311 DCHECK(end_layout_object);
312 DCHECK(start_layout_object->View() == end_layout_object->View()); 312 DCHECK(start_layout_object->View() == end_layout_object->View());
313 313
314 return SelectionPaintRange(start_layout_object, 314 return SelectionPaintRange(start_layout_object,
315 start_pos.ComputeEditingOffset(), 315 start_pos.ComputeEditingOffset(),
316 end_layout_object, end_pos.ComputeEditingOffset()); 316 end_layout_object, end_pos.ComputeEditingOffset());
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 378
379 runner->SetShouldInvalidateSelection(); 379 runner->SetShouldInvalidateSelection();
380 } 380 }
381 } 381 }
382 382
383 DEFINE_TRACE(LayoutSelection) { 383 DEFINE_TRACE(LayoutSelection) {
384 visitor->Trace(frame_selection_); 384 visitor->Trace(frame_selection_);
385 } 385 }
386 386
387 } // namespace blink 387 } // namespace blink
OLDNEW
« 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