Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / core / editing / PositionWithAffinity.h
blobb2be25acff9a2faa2026161b87c4cfe5132224e2
1 // Copyright 2014 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./*
5 #ifndef PositionWithAffinity_h
6 #define PositionWithAffinity_h
8 #include "core/CoreExport.h"
9 #include "core/editing/Position.h"
10 #include "core/editing/TextAffinity.h"
12 namespace blink {
14 template <typename Strategy>
15 class CORE_TEMPLATE_CLASS_EXPORT PositionWithAffinityTemplate {
16 DISALLOW_ALLOCATION();
17 public:
18 // TODO(yosin) We should have single parameter constructor not to use
19 // default parameter for avoiding include "TextAffinity.h"
20 PositionWithAffinityTemplate(const PositionAlgorithm<Strategy>&, TextAffinity = TextAffinity::Downstream);
21 PositionWithAffinityTemplate();
22 ~PositionWithAffinityTemplate();
24 TextAffinity affinity() const { return m_affinity; }
25 const PositionAlgorithm<Strategy>& position() const { return m_position; }
27 // Returns true if both |this| and |other| is null or both |m_position|
28 // and |m_affinity| equal.
29 bool operator==(const PositionWithAffinityTemplate& other) const;
30 bool operator!=(const PositionWithAffinityTemplate& other) const { return !operator==(other); }
32 bool isNotNull() const { return m_position.isNotNull(); }
33 bool isNull() const { return m_position.isNull(); }
35 DEFINE_INLINE_TRACE()
37 visitor->trace(m_position);
40 private:
41 PositionAlgorithm<Strategy> m_position;
42 TextAffinity m_affinity;
45 extern template class CORE_EXTERN_TEMPLATE_EXPORT PositionWithAffinityTemplate<EditingStrategy>;
46 extern template class CORE_EXTERN_TEMPLATE_EXPORT PositionWithAffinityTemplate<EditingInComposedTreeStrategy>;
48 using PositionWithAffinity = PositionWithAffinityTemplate<EditingStrategy>;
49 using PositionInComposedTreeWithAffinity = PositionWithAffinityTemplate<EditingInComposedTreeStrategy>;
51 template <typename Strategy>
52 PositionWithAffinityTemplate<Strategy> fromPositionInDOMTree(const PositionWithAffinity&);
54 template <>
55 inline PositionWithAffinity fromPositionInDOMTree<EditingStrategy>(const PositionWithAffinity& positionWithAffinity)
57 return positionWithAffinity;
60 template <>
61 inline PositionInComposedTreeWithAffinity fromPositionInDOMTree<EditingInComposedTreeStrategy>(const PositionWithAffinity& positionWithAffinity)
63 return PositionInComposedTreeWithAffinity(toPositionInComposedTree(positionWithAffinity.position()), positionWithAffinity.affinity());
66 } // namespace blink
68 #endif // PositionWithAffinity_h