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

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

Issue 2916803003: Extract SelectionPaintRange calculation from LayoutSelection::Commit() (Closed)
Patch Set: update Created 3 years, 7 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 | « third_party/WebKit/Source/core/editing/LayoutSelection.h ('k') | 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/LayoutSelection.cpp
diff --git a/third_party/WebKit/Source/core/editing/LayoutSelection.cpp b/third_party/WebKit/Source/core/editing/LayoutSelection.cpp
index 2467fa86c10c5a12a722b27791feae251433bad8..82cebfdfae3761413b1cffcd40e1803790a64dba 100644
--- a/third_party/WebKit/Source/core/editing/LayoutSelection.cpp
+++ b/third_party/WebKit/Source/core/editing/LayoutSelection.cpp
@@ -79,15 +79,16 @@ LayoutSelection::LayoutSelection(FrameSelection& frame_selection)
has_pending_selection_(false),
paint_range_(SelectionPaintRange()) {}
-SelectionInFlatTree LayoutSelection::CalcVisibleSelection(
- const VisibleSelectionInFlatTree& original_selection) const {
+static SelectionInFlatTree CalcSelection(
+ const VisibleSelectionInFlatTree& original_selection,
+ bool should_show_blok_cursor) {
const PositionInFlatTree& start = original_selection.Start();
const PositionInFlatTree& end = original_selection.end();
SelectionType selection_type = original_selection.GetSelectionType();
const TextAffinity affinity = original_selection.Affinity();
bool paint_block_cursor =
- frame_selection_->ShouldShowBlockCursor() &&
+ should_show_blok_cursor &&
selection_type == SelectionType::kCaretSelection &&
!IsLogicalEndOfLine(CreateVisiblePosition(end, affinity));
if (EnclosingTextControl(start.ComputeContainerNode())) {
@@ -315,25 +316,22 @@ void LayoutSelection::ClearSelection() {
paint_range_ = SelectionPaintRange();
}
-void LayoutSelection::Commit() {
- if (!HasPendingSelection())
- return;
- has_pending_selection_ = false;
-
+static SelectionPaintRange CalcSelectionPaintRange(
+ const FrameSelection& frame_selection) {
const VisibleSelectionInFlatTree& original_selection =
- frame_selection_->ComputeVisibleSelectionInFlatTree();
-
+ frame_selection.ComputeVisibleSelectionInFlatTree();
// Construct a new VisibleSolution, since visibleSelection() is not
// necessarily valid, and the following steps assume a valid selection. See
// <https://bugs.webkit.org/show_bug.cgi?id=69563> and
// <rdar://problem/10232866>.
+ const SelectionInFlatTree& new_selection = CalcSelection(
+ original_selection, frame_selection.ShouldShowBlockCursor());
const VisibleSelectionInFlatTree& selection =
- CreateVisibleSelection(CalcVisibleSelection(original_selection));
+ CreateVisibleSelection(new_selection);
+
+ if (!selection.IsRange() || frame_selection.IsHidden())
+ return SelectionPaintRange();
- if (!selection.IsRange() || frame_selection_->IsHidden()) {
- ClearSelection();
- return;
- }
DCHECK(!selection.IsNone());
// Use the rightmost candidate for the start of the selection, and the
// leftmost candidate for the end of the selection. Example: foo <a>bar</a>.
@@ -360,9 +358,22 @@ void LayoutSelection::Commit() {
DCHECK(end_layout_object);
DCHECK(start_layout_object->View() == end_layout_object->View());
- const SelectionPaintRange new_range(
- start_layout_object, start_pos.ComputeEditingOffset(), end_layout_object,
- end_pos.ComputeEditingOffset());
+ return SelectionPaintRange(start_layout_object,
+ start_pos.ComputeEditingOffset(),
+ end_layout_object, end_pos.ComputeEditingOffset());
+}
+
+void LayoutSelection::Commit() {
+ if (!HasPendingSelection())
+ return;
+ has_pending_selection_ = false;
+
+ const SelectionPaintRange& new_range =
+ CalcSelectionPaintRange(*frame_selection_);
+ if (new_range.IsNull()) {
+ ClearSelection();
+ return;
+ }
// Just return if the selection hasn't changed.
if (paint_range_ == new_range)
return;
« no previous file with comments | « third_party/WebKit/Source/core/editing/LayoutSelection.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698