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

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

Issue 2910373002: DCHECK instead of return at LayoutSelection::Commit() (Closed)
Patch Set: Created 3 years, 6 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 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 // necessarily valid, and the following steps assume a valid selection. See 325 // necessarily valid, and the following steps assume a valid selection. See
326 // <https://bugs.webkit.org/show_bug.cgi?id=69563> and 326 // <https://bugs.webkit.org/show_bug.cgi?id=69563> and
327 // <rdar://problem/10232866>. 327 // <rdar://problem/10232866>.
328 const VisibleSelectionInFlatTree& selection = 328 const VisibleSelectionInFlatTree& selection =
329 CreateVisibleSelection(CalcVisibleSelection(original_selection)); 329 CreateVisibleSelection(CalcVisibleSelection(original_selection));
330 330
331 if (!selection.IsRange() || frame_selection_->IsHidden()) { 331 if (!selection.IsRange() || frame_selection_->IsHidden()) {
332 ClearSelection(); 332 ClearSelection();
333 return; 333 return;
334 } 334 }
335 335 DCHECK(!selection.IsNone());
336 // Use the rightmost candidate for the start of the selection, and the 336 // Use the rightmost candidate for the start of the selection, and the
337 // leftmost candidate for the end of the selection. Example: foo <a>bar</a>. 337 // leftmost candidate for the end of the selection. Example: foo <a>bar</a>.
338 // Imagine that a line wrap occurs after 'foo', and that 'bar' is selected. 338 // Imagine that a line wrap occurs after 'foo', and that 'bar' is selected.
339 // If we pass [foo, 3] as the start of the selection, the selection painting 339 // If we pass [foo, 3] as the start of the selection, the selection painting
340 // code will think that content on the line containing 'foo' is selected 340 // code will think that content on the line containing 'foo' is selected
341 // and will fill the gap before 'bar'. 341 // and will fill the gap before 'bar'.
342 PositionInFlatTree start_pos = selection.Start(); 342 PositionInFlatTree start_pos = selection.Start();
343 PositionInFlatTree candidate = MostForwardCaretPosition(start_pos); 343 const PositionInFlatTree most_forward_start =
344 if (IsVisuallyEquivalentCandidate(candidate)) 344 MostForwardCaretPosition(start_pos);
345 start_pos = candidate; 345 if (IsVisuallyEquivalentCandidate(most_forward_start))
346 start_pos = most_forward_start;
346 PositionInFlatTree end_pos = selection.end(); 347 PositionInFlatTree end_pos = selection.end();
347 candidate = MostBackwardCaretPosition(end_pos); 348 const PositionInFlatTree most_backward = MostBackwardCaretPosition(end_pos);
348 if (IsVisuallyEquivalentCandidate(candidate)) 349 if (IsVisuallyEquivalentCandidate(most_backward))
349 end_pos = candidate; 350 end_pos = most_backward;
350 351
351 // We can get into a state where the selection endpoints map to the same 352 DCHECK(start_pos.IsNotNull());
352 // |VisiblePosition| when a selection is deleted because we don't yet notify 353 DCHECK(end_pos.IsNotNull());
353 // the |FrameSelection| of text removal.
354 if (start_pos.IsNull() || end_pos.IsNull() ||
355 selection.VisibleStart().DeepEquivalent() ==
356 selection.VisibleEnd().DeepEquivalent())
357 return;
358 DCHECK_LE(start_pos, end_pos); 354 DCHECK_LE(start_pos, end_pos);
359 LayoutObject* start_layout_object = start_pos.AnchorNode()->GetLayoutObject(); 355 LayoutObject* start_layout_object = start_pos.AnchorNode()->GetLayoutObject();
360 LayoutObject* end_layout_object = end_pos.AnchorNode()->GetLayoutObject(); 356 LayoutObject* end_layout_object = end_pos.AnchorNode()->GetLayoutObject();
361 if (!start_layout_object || !end_layout_object) 357 DCHECK(start_layout_object);
362 return; 358 DCHECK(end_layout_object);
363 DCHECK(start_layout_object->View() == end_layout_object->View()); 359 DCHECK(start_layout_object->View() == end_layout_object->View());
364 360
365 const SelectionPaintRange new_range( 361 const SelectionPaintRange new_range(
366 start_layout_object, start_pos.ComputeEditingOffset(), end_layout_object, 362 start_layout_object, start_pos.ComputeEditingOffset(), end_layout_object,
367 end_pos.ComputeEditingOffset()); 363 end_pos.ComputeEditingOffset());
368 // Just return if the selection hasn't changed. 364 // Just return if the selection hasn't changed.
369 if (paint_range_ == new_range) 365 if (paint_range_ == new_range)
370 return; 366 return;
371 367
372 DCHECK(frame_selection_->GetDocument().GetLayoutView()->GetFrameView()); 368 DCHECK(frame_selection_->GetDocument().GetLayoutView()->GetFrameView());
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 440
445 o->SetShouldInvalidateSelection(); 441 o->SetShouldInvalidateSelection();
446 } 442 }
447 } 443 }
448 444
449 DEFINE_TRACE(LayoutSelection) { 445 DEFINE_TRACE(LayoutSelection) {
450 visitor->Trace(frame_selection_); 446 visitor->Trace(frame_selection_);
451 } 447 }
452 448
453 } // namespace blink 449 } // 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