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

Side by Side Diff: third_party/WebKit/Source/core/editing/Selection.h

Issue 2393403002: Introduce Selection class (Closed)
Patch Set: 2016-10-06T15:27:59 Created 4 years, 2 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
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef Selection_h
6 #define Selection_h
7
8 #include "base/macros.h"
9 #include "core/CoreExport.h"
10 #include "core/editing/EphemeralRange.h"
11 #include "core/editing/Position.h"
12 #include "core/editing/PositionWithAffinity.h"
13 #include "core/editing/TextAffinity.h"
14 #include "core/editing/TextGranularity.h"
15 #include "wtf/Allocator.h"
16 #include <iosfwd>
17
18 namespace blink {
19
20 // SelectionTemplate represents selection for using constructing
21 // |VisibleSeleciton| and parameter/return value. |SelectionTemplate| is
22 // pseudo immutable object, you can't change members.
Xiaocheng 2016/10/06 08:02:33 I can't understand the first sentence... Please re
yosin_UTC9 2016/10/07 08:46:57 Done.
23 //
24 // To construct |SelectionTemplate| object, please use |Builder| class.
25 template <typename Strategy>
26 class CORE_EXPORT SelectionTemplate final {
27 DISALLOW_NEW();
28
29 public:
30 // |Builder| is a helper class for constructing |SelectionTemplate| object.
yoichio 2016/10/06 08:52:17 Who use this class and how does?
yosin_UTC9 2016/10/07 08:46:57 We'll use |Builder| class everywhere we construct
31 class CORE_EXPORT Builder final {
32 DISALLOW_NEW();
33
34 public:
35 explicit Builder(const SelectionTemplate&);
36 Builder();
37
38 SelectionTemplate build() const;
39
40 // Move selection to |base|. |base| can't be null.
yoichio 2016/10/07 04:30:40 How about naming |setBase| and |setExtent| so that
yosin_UTC9 2016/10/07 08:46:57 No, we don't want to have base=null, extent=non-nu
yoichio 2016/10/07 09:32:13 setBase(base).setExtent(extent) doesn't work? We c
41 Builder& collapse(const PositionTemplate<Strategy>& base);
42 Builder& collapse(const PositionWithAffinityTemplate<Strategy>& base);
43
44 // Extend selection to |extent|. It is error if selection is none.
45 Builder& extend(const PositionTemplate<Strategy>& extent);
46
47 Builder& setBaseAndExtent(const EphemeralRangeTemplate<Strategy>&);
48
49 // |extent| can not be null if |base| isn't null.
50 Builder& setBaseAndExtent(const PositionTemplate<Strategy>& base,
51 const PositionTemplate<Strategy>& extent);
52
53 // Both |base| and |extent| can be null.
Xiaocheng 2016/10/06 08:02:33 I would prefer changing the comment to "|extent| c
yosin_UTC9 2016/10/07 08:46:57 Done.
54 Builder& setBaseAndExtentDeprecated(
55 const PositionTemplate<Strategy>& base,
56 const PositionTemplate<Strategy>& extent);
57
58 Builder& setAffinity(TextAffinity);
59 Builder& setGranularity(TextGranularity);
60 Builder& setHasTrailingWhitespace(bool);
61 Builder& setIsDirectional(bool);
62
63 private:
64 SelectionTemplate m_selection;
65
66 DISALLOW_COPY_AND_ASSIGN(Builder);
67 };
68
69 SelectionTemplate(const SelectionTemplate& other);
70 SelectionTemplate();
71
72 SelectionTemplate& operator=(const SelectionTemplate&) = default;
73
74 bool operator==(const SelectionTemplate&) const;
75 bool operator!=(const SelectionTemplate&) const;
76
77 const PositionTemplate<Strategy>& base() const;
78 const PositionTemplate<Strategy>& extent() const;
79 TextAffinity affinity() const { return m_affinity; }
80 TextGranularity granularity() const { return m_granularity; }
81 bool hasTrailingWhitespace() const { return m_hasTrailingWhitespace; }
82 bool isDirectional() const { return m_isDirectional; }
83 bool isNone() const { return m_base.isNull(); }
84
85 void assertValid() const;
86 void assertValidFor(const Document&) const;
87
88 DEFINE_INLINE_TRACE() {
89 visitor->trace(m_base);
90 visitor->trace(m_extent);
91 }
92
93 void printTo(std::ostream*, const char* type) const;
94
95 private:
96 friend class SelectionEditor;
97
98 Document* document() const;
99
100 PositionTemplate<Strategy> m_base;
101 PositionTemplate<Strategy> m_extent;
102 TextAffinity m_affinity = TextAffinity::Downstream;
103 TextGranularity m_granularity = CharacterGranularity;
104 bool m_hasTrailingWhitespace = false;
105 bool m_isDirectional = false;
106 #if ENABLE(ASSERT)
tkent 2016/10/07 00:13:27 ENABLE(ASSERT) -> DCHECK_IS_ON()
yosin_UTC9 2016/10/07 08:46:57 Done.
107 uint64_t m_domTreeVersion;
108 #endif
109 };
110
111 extern template class CORE_EXTERN_TEMPLATE_EXPORT
112 SelectionTemplate<EditingStrategy>;
113 extern template class CORE_EXTERN_TEMPLATE_EXPORT
114 SelectionTemplate<EditingInFlatTreeStrategy>;
115
116 using Selection = SelectionTemplate<EditingStrategy>;
117 using SelectionInFlatTree = SelectionTemplate<EditingInFlatTreeStrategy>;
118
119 CORE_EXPORT std::ostream& operator<<(std::ostream&, const Selection&);
120 CORE_EXPORT std::ostream& operator<<(std::ostream&, const SelectionInFlatTree&);
121
122 } // namespace blink
123
124 #endif // Selection_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698