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

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

Issue 2952973002: Introduce VisibleSelection::CreateWithoutValidationDeprecated() (Closed)
Patch Set: 2017-06-23T09:54:35 Created 3 years, 5 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. All rights reserved. 2 * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 } 466 }
467 467
468 // TODO(yosin) This function breaks the invariant of this class. 468 // TODO(yosin) This function breaks the invariant of this class.
469 // But because we use VisibleSelection to store values in editing commands for 469 // But because we use VisibleSelection to store values in editing commands for
470 // use when undoing the command, we need to be able to create a selection that 470 // use when undoing the command, we need to be able to create a selection that
471 // while currently invalid, will be valid once the changes are undone. This is a 471 // while currently invalid, will be valid once the changes are undone. This is a
472 // design problem. To fix it we either need to change the invariants of 472 // design problem. To fix it we either need to change the invariants of
473 // |VisibleSelection| or create a new class for editing to use that can 473 // |VisibleSelection| or create a new class for editing to use that can
474 // manipulate selections that are not currently valid. 474 // manipulate selections that are not currently valid.
475 template <typename Strategy> 475 template <typename Strategy>
476 void VisibleSelectionTemplate<Strategy>::SetWithoutValidation( 476 VisibleSelectionTemplate<Strategy>
477 VisibleSelectionTemplate<Strategy>::CreateWithoutValidationDeprecated(
477 const PositionTemplate<Strategy>& base, 478 const PositionTemplate<Strategy>& base,
478 const PositionTemplate<Strategy>& extent) { 479 const PositionTemplate<Strategy>& extent,
479 if (base.IsNull() || extent.IsNull()) { 480 TextAffinity affinity) {
480 base_ = extent_ = start_ = end_ = PositionTemplate<Strategy>(); 481 DCHECK(base.IsNotNull());
481 UpdateSelectionType(); 482 DCHECK(extent.IsNotNull());
482 return; 483
484 VisibleSelectionTemplate<Strategy> visible_selection;
485 visible_selection.base_ = base;
486 visible_selection.extent_ = extent;
487 visible_selection.base_is_first_ = base.CompareTo(extent) <= 0;
488 if (visible_selection.base_is_first_) {
489 visible_selection.start_ = base;
490 visible_selection.end_ = extent;
491 } else {
492 visible_selection.start_ = extent;
493 visible_selection.end_ = base;
483 } 494 }
484 495 if (base == extent) {
485 base_ = base; 496 visible_selection.selection_type_ = kCaretSelection;
486 extent_ = extent; 497 visible_selection.affinity_ = affinity;
487 base_is_first_ = base.CompareTo(extent) <= 0; 498 return visible_selection;
488 if (base_is_first_) {
489 start_ = base;
490 end_ = extent;
491 } else {
492 start_ = extent;
493 end_ = base;
494 } 499 }
495 selection_type_ = base == extent ? kCaretSelection : kRangeSelection; 500 // Since |affinity_| for non-|CaretSelection| is always |kDownstream|,
496 if (selection_type_ != kCaretSelection) { 501 // we should keep this invariant. Note: This function can be called with
497 // Since |m_affinity| for non-|CaretSelection| is always |Downstream|, 502 // |affinity_| is |kUpstream|.
498 // we should keep this invariant. Note: This function can be called with 503 visible_selection.selection_type_ = kRangeSelection;
499 // |m_affinity| is |TextAffinity::Upstream|. 504 visible_selection.affinity_ = TextAffinity::kDownstream;
500 affinity_ = TextAffinity::kDownstream; 505 return visible_selection;
501 }
502 } 506 }
503 507
504 template <typename Strategy> 508 template <typename Strategy>
505 void VisibleSelectionTemplate< 509 void VisibleSelectionTemplate<
506 Strategy>::AdjustSelectionToAvoidCrossingShadowBoundaries() { 510 Strategy>::AdjustSelectionToAvoidCrossingShadowBoundaries() {
507 if (base_.IsNull() || start_.IsNull() || base_.IsNull()) 511 if (base_.IsNull() || start_.IsNull() || base_.IsNull())
508 return; 512 return;
509 SelectionAdjuster::AdjustSelectionToAvoidCrossingShadowBoundaries(this); 513 SelectionAdjuster::AdjustSelectionToAvoidCrossingShadowBoundaries(this);
510 } 514 }
511 515
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 776
773 void showTree(const blink::VisibleSelectionInFlatTree& sel) { 777 void showTree(const blink::VisibleSelectionInFlatTree& sel) {
774 sel.ShowTreeForThis(); 778 sel.ShowTreeForThis();
775 } 779 }
776 780
777 void showTree(const blink::VisibleSelectionInFlatTree* sel) { 781 void showTree(const blink::VisibleSelectionInFlatTree* sel) {
778 if (sel) 782 if (sel)
779 sel->ShowTreeForThis(); 783 sel->ShowTreeForThis();
780 } 784 }
781 #endif 785 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698