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

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

Issue 2882963002: Introduce MarkSetSelectionState() in LayoutSelection::SetSelection() (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 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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 } 179 }
180 } 180 }
181 } 181 }
182 182
183 runner = GetNextOrPrevLayoutObjectBasedOnDirection( 183 runner = GetNextOrPrevLayoutObjectBasedOnDirection(
184 runner, stop, continue_exploring, exploring_backwards); 184 runner, stop, continue_exploring, exploring_backwards);
185 } 185 }
186 return selected_map; 186 return selected_map;
187 } 187 }
188 188
189 // Update the selection status of all LayoutObjects between |start| and |end|.
190 static void SetSelectionState(LayoutObject* start,
191 LayoutObject* end,
192 int end_pos) {
193 if (start && start == end) {
194 start->SetSelectionStateIfNeeded(SelectionBoth);
195 } else {
196 if (start)
197 start->SetSelectionStateIfNeeded(SelectionStart);
198 if (end)
199 end->SetSelectionStateIfNeeded(SelectionEnd);
200 }
201
202 LayoutObject* const stop = LayoutObjectAfterPosition(end, end_pos);
203 for (LayoutObject* runner = start; runner && runner != stop;
204 runner = runner->NextInPreOrder()) {
205 if (runner != start && runner != end && runner->CanBeSelectionLeaf())
206 runner->SetSelectionStateIfNeeded(SelectionInside);
207 }
208 }
209
189 void LayoutSelection::SetSelection( 210 void LayoutSelection::SetSelection(
190 LayoutObject* start, 211 LayoutObject* start,
191 int start_pos, 212 int start_pos,
192 LayoutObject* end, 213 LayoutObject* end,
193 int end_pos, 214 int end_pos,
194 SelectionPaintInvalidationMode block_paint_invalidation_mode) { 215 SelectionPaintInvalidationMode block_paint_invalidation_mode) {
195 // This code makes no assumptions as to if the layout tree is up to date or 216 // This code makes no assumptions as to if the layout tree is up to date or
196 // not and will not try to update it. Currently clearSelection calls this 217 // not and will not try to update it. Currently clearSelection calls this
197 // (intentionally) without updating the layout tree as it doesn't care. 218 // (intentionally) without updating the layout tree as it doesn't care.
198 // Other callers may want to force recalc style before calling this. 219 // Other callers may want to force recalc style before calling this.
(...skipping 26 matching lines...) Expand all
225 for (SelectedObjectMap::iterator i = old_selected_map.object_map.begin(); 246 for (SelectedObjectMap::iterator i = old_selected_map.object_map.begin();
226 i != old_objects_end; ++i) 247 i != old_objects_end; ++i)
227 i->key->SetSelectionStateIfNeeded(SelectionNone); 248 i->key->SetSelectionStateIfNeeded(SelectionNone);
228 249
229 // set selection start and end 250 // set selection start and end
230 selection_start_ = start; 251 selection_start_ = start;
231 selection_start_pos_ = start_pos; 252 selection_start_pos_ = start_pos;
232 selection_end_ = end; 253 selection_end_ = end;
233 selection_end_pos_ = end_pos; 254 selection_end_pos_ = end_pos;
234 255
235 // Update the selection status of all objects between m_selectionStart and 256 SetSelectionState(start, end, end_pos);
236 // m_selectionEnd
237 if (start && start == end) {
238 start->SetSelectionStateIfNeeded(SelectionBoth);
239 } else {
240 if (start)
241 start->SetSelectionStateIfNeeded(SelectionStart);
242 if (end)
243 end->SetSelectionStateIfNeeded(SelectionEnd);
244 }
245
246 LayoutObject* o = start;
247 LayoutObject* const stop = LayoutObjectAfterPosition(end, end_pos);
248
249 while (o && o != stop) {
250 if (o != start && o != end && o->CanBeSelectionLeaf())
251 o->SetSelectionStateIfNeeded(SelectionInside);
252 o = o->NextInPreOrder();
253 }
254 257
255 // Now that the selection state has been updated for the new objects, walk 258 // Now that the selection state has been updated for the new objects, walk
256 // them again and put them in the new objects list. 259 // them again and put them in the new objects list.
257 // TODO(editing-dev): |new_selected_map| doesn't really need to store the 260 // TODO(editing-dev): |new_selected_map| doesn't really need to store the
258 // SelectionState, it's just more convenient to have it use the same data 261 // SelectionState, it's just more convenient to have it use the same data
259 // structure as |old_selected_map|. 262 // structure as |old_selected_map|.
260 SelectedMap new_selected_map = 263 SelectedMap new_selected_map =
261 CollectSelectedMap(start, end, end_pos, kPaintInvalidationNewXOROld); 264 CollectSelectedMap(start, end, end_pos, kPaintInvalidationNewXOROld);
262 265
263 // Have any of the old selected objects changed compared to the new selection? 266 // Have any of the old selected objects changed compared to the new selection?
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 437
435 o->SetShouldInvalidateSelection(); 438 o->SetShouldInvalidateSelection();
436 } 439 }
437 } 440 }
438 441
439 DEFINE_TRACE(LayoutSelection) { 442 DEFINE_TRACE(LayoutSelection) {
440 visitor->Trace(frame_selection_); 443 visitor->Trace(frame_selection_);
441 } 444 }
442 445
443 } // namespace blink 446 } // 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