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

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

Issue 2895193002: Cleanup traversing in LayoutSelection.cpp::CollectSelectedMap() (Closed)
Patch Set: nit 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 | « 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/LayoutSelection.cpp
diff --git a/third_party/WebKit/Source/core/editing/LayoutSelection.cpp b/third_party/WebKit/Source/core/editing/LayoutSelection.cpp
index 0b628863e698c6c3fa22fe9b1db0b81bcce8e299..246bcc16393e720d879acdbf1487bba42866bff4 100644
--- a/third_party/WebKit/Source/core/editing/LayoutSelection.cpp
+++ b/third_party/WebKit/Source/core/editing/LayoutSelection.cpp
@@ -100,31 +100,6 @@ static LayoutObject* LayoutObjectAfterPosition(LayoutObject* object,
return child ? child : object->NextInPreOrderAfterChildren();
}
-// When exploring the LayoutTree looking for the nodes involved in the
-// Selection, sometimes it's required to change the traversing direction because
-// the "start" position is below the "end" one.
-static inline LayoutObject* GetNextOrPrevLayoutObjectBasedOnDirection(
- const LayoutObject* o,
- const LayoutObject* stop,
- bool& continue_exploring,
- bool& exploring_backwards) {
- LayoutObject* next;
- if (exploring_backwards) {
- next = o->PreviousInPreOrder();
- continue_exploring = next && !(next)->IsLayoutView();
- } else {
- next = o->NextInPreOrder();
- continue_exploring = next && next != stop;
- exploring_backwards = !next && (next != stop);
- if (exploring_backwards) {
- next = stop->PreviousInPreOrder();
- continue_exploring = next && !next->IsLayoutView();
- }
- }
-
- return next;
-}
-
// Objects each have a single selection rect to examine.
using SelectedObjectMap = HashMap<LayoutObject*, SelectionState>;
// Blocks contain selected objects and fill gaps between them, either on the
@@ -155,33 +130,31 @@ static SelectedMap CollectSelectedMap(
LayoutSelection::SelectionPaintInvalidationMode
block_paint_invalidation_mode) {
SelectedMap selected_map;
- LayoutObject* runner = selection_start;
+
LayoutObject* const stop =
LayoutObjectAfterPosition(selection_end, selection_end_pos);
- bool exploring_backwards = false;
- bool continue_exploring = runner && (runner != stop);
- while (continue_exploring) {
- if ((runner->CanBeSelectionLeaf() || runner == selection_start ||
- runner == selection_end) &&
- runner->GetSelectionState() != SelectionNone) {
- // Blocks are responsible for painting line gaps and margin gaps. They
- // must be examined as well.
- selected_map.object_map.Set(runner, runner->GetSelectionState());
- if (block_paint_invalidation_mode ==
- LayoutSelection::kPaintInvalidationNewXOROld) {
- LayoutBlock* containing_block = runner->ContainingBlock();
- while (containing_block && !containing_block->IsLayoutView()) {
- SelectedBlockMap::AddResult result = selected_map.block_map.insert(
- containing_block, containing_block->GetSelectionState());
- if (!result.is_new_entry)
- break;
- containing_block = containing_block->ContainingBlock();
- }
+ for (LayoutObject* runner = selection_start; runner && (runner != stop);
+ runner = runner->NextInPreOrder()) {
+ if (!runner->CanBeSelectionLeaf() && runner != selection_start &&
+ runner != selection_end)
+ continue;
+ if (runner->GetSelectionState() == SelectionNone)
+ continue;
+
+ // Blocks are responsible for painting line gaps and margin gaps. They
+ // must be examined as well.
+ selected_map.object_map.Set(runner, runner->GetSelectionState());
+ if (block_paint_invalidation_mode ==
+ LayoutSelection::kPaintInvalidationNewXOROld) {
+ LayoutBlock* containing_block = runner->ContainingBlock();
+ while (containing_block && !containing_block->IsLayoutView()) {
+ SelectedBlockMap::AddResult result = selected_map.block_map.insert(
+ containing_block, containing_block->GetSelectionState());
+ if (!result.is_new_entry)
+ break;
+ containing_block = containing_block->ContainingBlock();
}
}
-
- runner = GetNextOrPrevLayoutObjectBasedOnDirection(
- runner, stop, continue_exploring, exploring_backwards);
}
return selected_map;
}
@@ -346,6 +319,7 @@ void LayoutSelection::Commit() {
selection.VisibleStart().DeepEquivalent() ==
selection.VisibleEnd().DeepEquivalent())
return;
+ DCHECK_LE(start_pos, end_pos);
LayoutObject* start_layout_object = start_pos.AnchorNode()->GetLayoutObject();
LayoutObject* end_layout_object = end_pos.AnchorNode()->GetLayoutObject();
if (!start_layout_object || !end_layout_object)
« 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