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

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)
yosin_UTC9 2017/05/16 01:38:14 Oops, sorry my comment was wrong, according to lay
yoichio 2017/05/16 01:48:07 This code can be increased but I want this CL only
194 start->SetSelectionStateIfNeeded(SelectionBoth);
195 else if (start)
196 start->SetSelectionStateIfNeeded(SelectionStart);
197 else if (end)
198 end->SetSelectionStateIfNeeded(SelectionEnd);
199
200 LayoutObject* const stop = LayoutObjectAfterPosition(end, end_pos);
201 for (LayoutObject* runner = start; runner && runner != stop;
202 runner = runner->NextInPreOrder()) {
203 if (runner != start && runner != end && runner->CanBeSelectionLeaf())
yosin_UTC9 2017/05/16 01:38:14 nit: better to use early continue style. if (runn
yoichio 2017/05/16 01:48:07 Acknowledged.
204 runner->SetSelectionStateIfNeeded(SelectionInside);
205 }
206 }
207
189 void LayoutSelection::SetSelection( 208 void LayoutSelection::SetSelection(
190 LayoutObject* start, 209 LayoutObject* start,
191 int start_pos, 210 int start_pos,
192 LayoutObject* end, 211 LayoutObject* end,
193 int end_pos, 212 int end_pos,
194 SelectionPaintInvalidationMode block_paint_invalidation_mode) { 213 SelectionPaintInvalidationMode block_paint_invalidation_mode) {
195 // This code makes no assumptions as to if the layout tree is up to date or 214 // 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 215 // not and will not try to update it. Currently clearSelection calls this
197 // (intentionally) without updating the layout tree as it doesn't care. 216 // (intentionally) without updating the layout tree as it doesn't care.
198 // Other callers may want to force recalc style before calling this. 217 // 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(); 244 for (SelectedObjectMap::iterator i = old_selected_map.object_map.begin();
226 i != old_objects_end; ++i) 245 i != old_objects_end; ++i)
227 i->key->SetSelectionStateIfNeeded(SelectionNone); 246 i->key->SetSelectionStateIfNeeded(SelectionNone);
228 247
229 // set selection start and end 248 // set selection start and end
230 selection_start_ = start; 249 selection_start_ = start;
231 selection_start_pos_ = start_pos; 250 selection_start_pos_ = start_pos;
232 selection_end_ = end; 251 selection_end_ = end;
233 selection_end_pos_ = end_pos; 252 selection_end_pos_ = end_pos;
234 253
235 // Update the selection status of all objects between m_selectionStart and 254 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 255
255 // Now that the selection state has been updated for the new objects, walk 256 // Now that the selection state has been updated for the new objects, walk
256 // them again and put them in the new objects list. 257 // them again and put them in the new objects list.
257 // TODO(editing-dev): |new_selected_map| doesn't really need to store the 258 // 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 259 // SelectionState, it's just more convenient to have it use the same data
259 // structure as |old_selected_map|. 260 // structure as |old_selected_map|.
260 SelectedMap new_selected_map = 261 SelectedMap new_selected_map =
261 CollectSelectedMap(start, end, end_pos, kPaintInvalidationNewXOROld); 262 CollectSelectedMap(start, end, end_pos, kPaintInvalidationNewXOROld);
262 263
263 // Have any of the old selected objects changed compared to the new selection? 264 // 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 435
435 o->SetShouldInvalidateSelection(); 436 o->SetShouldInvalidateSelection();
436 } 437 }
437 } 438 }
438 439
439 DEFINE_TRACE(LayoutSelection) { 440 DEFINE_TRACE(LayoutSelection) {
440 visitor->Trace(frame_selection_); 441 visitor->Trace(frame_selection_);
441 } 442 }
442 443
443 } // namespace blink 444 } // 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