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

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

Issue 2876363002: Make for statements using C++11 foreach 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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 // Record the old selected objects. These will be used later when we compare 213 // Record the old selected objects. These will be used later when we compare
214 // against the new selected objects. 214 // against the new selected objects.
215 int old_start_pos = selection_start_pos_; 215 int old_start_pos = selection_start_pos_;
216 int old_end_pos = selection_end_pos_; 216 int old_end_pos = selection_end_pos_;
217 217
218 SelectedMap old_selected_map = 218 SelectedMap old_selected_map =
219 CollectSelectedMap(selection_start_, selection_end_, selection_end_pos_, 219 CollectSelectedMap(selection_start_, selection_end_, selection_end_pos_,
220 block_paint_invalidation_mode); 220 block_paint_invalidation_mode);
221 221
222 // Now clear the selection. 222 // Now clear the selection.
223 SelectedObjectMap::iterator old_objects_end = 223 for (auto layout_object : old_selected_map.object_map.Keys())
224 old_selected_map.object_map.end(); 224 layout_object->SetSelectionStateIfNeeded(SelectionNone);
225 for (SelectedObjectMap::iterator i = old_selected_map.object_map.begin();
226 i != old_objects_end; ++i)
227 i->key->SetSelectionStateIfNeeded(SelectionNone);
228 225
229 // set selection start and end 226 // set selection start and end
230 selection_start_ = start; 227 selection_start_ = start;
231 selection_start_pos_ = start_pos; 228 selection_start_pos_ = start_pos;
232 selection_end_ = end; 229 selection_end_ = end;
233 selection_end_pos_ = end_pos; 230 selection_end_pos_ = end_pos;
234 231
235 // Update the selection status of all objects between m_selectionStart and 232 // Update the selection status of all objects between m_selectionStart and
236 // m_selectionEnd 233 // m_selectionEnd
237 if (start && start == end) { 234 if (start && start == end) {
(...skipping 16 matching lines...) Expand all
254 251
255 // Now that the selection state has been updated for the new objects, walk 252 // Now that the selection state has been updated for the new objects, walk
256 // them again and put them in the new objects list. 253 // them again and put them in the new objects list.
257 // TODO(editing-dev): |new_selected_map| doesn't really need to store the 254 // 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 255 // SelectionState, it's just more convenient to have it use the same data
259 // structure as |old_selected_map|. 256 // structure as |old_selected_map|.
260 SelectedMap new_selected_map = 257 SelectedMap new_selected_map =
261 CollectSelectedMap(start, end, end_pos, kPaintInvalidationNewXOROld); 258 CollectSelectedMap(start, end, end_pos, kPaintInvalidationNewXOROld);
262 259
263 // Have any of the old selected objects changed compared to the new selection? 260 // Have any of the old selected objects changed compared to the new selection?
264 for (SelectedObjectMap::iterator i = old_selected_map.object_map.begin(); 261 for (const auto& pair : old_selected_map.object_map) {
265 i != old_objects_end; ++i) { 262 LayoutObject* obj = pair.key;
266 LayoutObject* obj = i->key;
267 SelectionState new_selection_state = obj->GetSelectionState(); 263 SelectionState new_selection_state = obj->GetSelectionState();
268 SelectionState old_selection_state = i->value; 264 SelectionState old_selection_state = pair.value;
269 if (new_selection_state != old_selection_state || 265 if (new_selection_state != old_selection_state ||
270 (selection_start_ == obj && old_start_pos != selection_start_pos_) || 266 (selection_start_ == obj && old_start_pos != selection_start_pos_) ||
271 (selection_end_ == obj && old_end_pos != selection_end_pos_)) { 267 (selection_end_ == obj && old_end_pos != selection_end_pos_)) {
272 obj->SetShouldInvalidateSelection(); 268 obj->SetShouldInvalidateSelection();
273 new_selected_map.object_map.erase(obj); 269 new_selected_map.object_map.erase(obj);
274 } 270 }
275 } 271 }
276 272
277 // Any new objects that remain were not found in the old objects dict, and so 273 // Any new objects that remain were not found in the old objects dict, and so
278 // they need to be updated. 274 // they need to be updated.
279 SelectedObjectMap::iterator new_objects_end = 275 for (auto layout_object : new_selected_map.object_map.Keys())
280 new_selected_map.object_map.end(); 276 layout_object->SetShouldInvalidateSelection();
281 for (SelectedObjectMap::iterator i = new_selected_map.object_map.begin();
282 i != new_objects_end; ++i)
283 i->key->SetShouldInvalidateSelection();
284 277
285 // Have any of the old blocks changed? 278 // Have any of the old blocks changed?
286 SelectedBlockMap::iterator old_blocks_end = old_selected_map.block_map.end(); 279 for (const auto& pair : old_selected_map.block_map) {
287 for (SelectedBlockMap::iterator i = old_selected_map.block_map.begin(); 280 LayoutBlock* block = pair.key;
288 i != old_blocks_end; ++i) {
289 LayoutBlock* block = i->key;
290 SelectionState new_selection_state = block->GetSelectionState(); 281 SelectionState new_selection_state = block->GetSelectionState();
291 SelectionState old_selection_state = i->value; 282 SelectionState old_selection_state = pair.value;
292 if (new_selection_state != old_selection_state) { 283 if (new_selection_state != old_selection_state) {
293 block->SetShouldInvalidateSelection(); 284 block->SetShouldInvalidateSelection();
294 new_selected_map.block_map.erase(block); 285 new_selected_map.block_map.erase(block);
295 } 286 }
296 } 287 }
297 288
298 // Any new blocks that remain were not found in the old blocks dict, and so 289 // Any new blocks that remain were not found in the old blocks dict, and so
299 // they need to be updated. 290 // they need to be updated.
300 SelectedBlockMap::iterator new_blocks_end = new_selected_map.block_map.end(); 291 for (auto layout_object : new_selected_map.block_map.Keys())
301 for (SelectedBlockMap::iterator i = new_selected_map.block_map.begin(); 292 layout_object->SetShouldInvalidateSelection();
302 i != new_blocks_end; ++i)
303 i->key->SetShouldInvalidateSelection();
304 } 293 }
305 294
306 std::pair<int, int> LayoutSelection::SelectionStartEnd() { 295 std::pair<int, int> LayoutSelection::SelectionStartEnd() {
307 Commit(); 296 Commit();
308 return std::make_pair(selection_start_pos_, selection_end_pos_); 297 return std::make_pair(selection_start_pos_, selection_end_pos_);
309 } 298 }
310 299
311 void LayoutSelection::ClearSelection() { 300 void LayoutSelection::ClearSelection() {
312 // For querying Layer::compositingState() 301 // For querying Layer::compositingState()
313 // This is correct, since destroying layout objects needs to cause eager paint 302 // This is correct, since destroying layout objects needs to cause eager paint
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 423
435 o->SetShouldInvalidateSelection(); 424 o->SetShouldInvalidateSelection();
436 } 425 }
437 } 426 }
438 427
439 DEFINE_TRACE(LayoutSelection) { 428 DEFINE_TRACE(LayoutSelection) {
440 visitor->Trace(frame_selection_); 429 visitor->Trace(frame_selection_);
441 } 430 }
442 431
443 } // namespace blink 432 } // 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