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

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

Issue 2972863003: Introduce CreateVisibleSelectionWithGranularity() (Closed)
Patch Set: 2017-07-06T16:26:15 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 template <typename Strategy> 43 template <typename Strategy>
44 VisibleSelectionTemplate<Strategy>::VisibleSelectionTemplate() 44 VisibleSelectionTemplate<Strategy>::VisibleSelectionTemplate()
45 : affinity_(TextAffinity::kDownstream), 45 : affinity_(TextAffinity::kDownstream),
46 selection_type_(kNoSelection), 46 selection_type_(kNoSelection),
47 base_is_first_(true), 47 base_is_first_(true),
48 is_directional_(false), 48 is_directional_(false),
49 granularity_(kCharacterGranularity) {} 49 granularity_(kCharacterGranularity) {}
50 50
51 template <typename Strategy> 51 template <typename Strategy>
52 VisibleSelectionTemplate<Strategy>::VisibleSelectionTemplate( 52 VisibleSelectionTemplate<Strategy>::VisibleSelectionTemplate(
53 const SelectionTemplate<Strategy>& selection) 53 const SelectionTemplate<Strategy>& selection,
54 TextGranularity granularity)
54 : base_(selection.Base()), 55 : base_(selection.Base()),
55 extent_(selection.Extent()), 56 extent_(selection.Extent()),
56 affinity_(selection.Affinity()), 57 affinity_(selection.Affinity()),
57 selection_type_(kNoSelection), 58 selection_type_(kNoSelection),
58 is_directional_(selection.IsDirectional()), 59 is_directional_(selection.IsDirectional()),
59 granularity_(selection.Granularity()) { 60 granularity_(granularity) {
60 Validate(granularity_); 61 Validate(granularity_);
61 } 62 }
62 63
63 template <typename Strategy> 64 template <typename Strategy>
64 VisibleSelectionTemplate<Strategy> VisibleSelectionTemplate<Strategy>::Create( 65 VisibleSelectionTemplate<Strategy> VisibleSelectionTemplate<Strategy>::Create(
65 const SelectionTemplate<Strategy>& selection) { 66 const SelectionTemplate<Strategy>& selection) {
66 return VisibleSelectionTemplate(selection); 67 return VisibleSelectionTemplate(selection, selection.Granularity());
67 } 68 }
68 69
69 VisibleSelection CreateVisibleSelection(const SelectionInDOMTree& selection) { 70 VisibleSelection CreateVisibleSelection(const SelectionInDOMTree& selection) {
70 return VisibleSelection::Create(selection); 71 return VisibleSelection::Create(selection);
71 } 72 }
72 73
73 VisibleSelectionInFlatTree CreateVisibleSelection( 74 VisibleSelectionInFlatTree CreateVisibleSelection(
74 const SelectionInFlatTree& selection) { 75 const SelectionInFlatTree& selection) {
75 return VisibleSelectionInFlatTree::Create(selection); 76 return VisibleSelectionInFlatTree::Create(selection);
76 } 77 }
77 78
78 template <typename Strategy> 79 template <typename Strategy>
80 VisibleSelectionTemplate<Strategy>
81 VisibleSelectionTemplate<Strategy>::CreateWithGranularity(
82 const SelectionTemplate<Strategy>& selection,
83 TextGranularity granularity) {
84 return VisibleSelectionTemplate(selection, granularity);
85 }
86
87 VisibleSelection CreateVisibleSelectionWithGranularity(
88 const SelectionInDOMTree& selection,
89 TextGranularity granularity) {
90 return VisibleSelection::CreateWithGranularity(selection, granularity);
91 }
92
93 VisibleSelectionInFlatTree CreateVisibleSelectionWithGranularity(
94 const SelectionInFlatTree& selection,
95 TextGranularity granularity) {
96 return VisibleSelectionInFlatTree::CreateWithGranularity(selection,
97 granularity);
98 }
99
100 template <typename Strategy>
79 static SelectionType ComputeSelectionType( 101 static SelectionType ComputeSelectionType(
80 const PositionTemplate<Strategy>& start, 102 const PositionTemplate<Strategy>& start,
81 const PositionTemplate<Strategy>& end) { 103 const PositionTemplate<Strategy>& end) {
82 if (start.IsNull()) { 104 if (start.IsNull()) {
83 DCHECK(end.IsNull()); 105 DCHECK(end.IsNull());
84 return kNoSelection; 106 return kNoSelection;
85 } 107 }
86 DCHECK(!NeedsLayoutTreeUpdate(start)) << start << ' ' << end; 108 DCHECK(!NeedsLayoutTreeUpdate(start)) << start << ' ' << end;
87 if (start == end) 109 if (start == end)
88 return kCaretSelection; 110 return kCaretSelection;
(...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after
792 814
793 void showTree(const blink::VisibleSelectionInFlatTree& sel) { 815 void showTree(const blink::VisibleSelectionInFlatTree& sel) {
794 sel.ShowTreeForThis(); 816 sel.ShowTreeForThis();
795 } 817 }
796 818
797 void showTree(const blink::VisibleSelectionInFlatTree* sel) { 819 void showTree(const blink::VisibleSelectionInFlatTree* sel) {
798 if (sel) 820 if (sel)
799 sel->ShowTreeForThis(); 821 sel->ShowTreeForThis();
800 } 822 }
801 #endif 823 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698