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

Side by Side Diff: Source/core/editing/VisiblePosition.h

Issue 1330563005: Introduce VisiblePositionTemplate template class (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 2015-09-04T10:27:43 Created 5 years, 3 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 | Source/core/editing/VisiblePosition.cpp » ('j') | 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) 2004, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2008 Apple 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 // placed at start of line. 60 // placed at start of line.
61 // 61 //
62 // Example of affinity: 62 // Example of affinity:
63 // abc^def where "^" represent |Position| 63 // abc^def where "^" represent |Position|
64 // When above text line wrapped after "abc" 64 // When above text line wrapped after "abc"
65 // abc| UPSTREAM |VisiblePosition| 65 // abc| UPSTREAM |VisiblePosition|
66 // |def DOWNSTREAM |VisiblePosition| 66 // |def DOWNSTREAM |VisiblePosition|
67 // 67 //
68 // NOTE: UPSTREAM affinity will be used only if pos is at end of a wrapped line, 68 // NOTE: UPSTREAM affinity will be used only if pos is at end of a wrapped line,
69 // otherwise it will be converted to DOWNSTREAM. 69 // otherwise it will be converted to DOWNSTREAM.
70 class CORE_EXPORT VisiblePosition final { 70 template <typename Strategy>
71 class CORE_TEMPLATE_CLASS_EXPORT VisiblePositionTemplate final {
71 DISALLOW_ALLOCATION(); 72 DISALLOW_ALLOCATION();
72 public: 73 public:
73 VisiblePosition(); 74 VisiblePositionTemplate();
74 75
75 // Node: Other than |createVisiblePosition()|, we should not use 76 // Node: Other than |createVisiblePosition()|, we should not use
76 // |createWithoutCanonicalization()|. 77 // |createWithoutCanonicalization()|.
77 static VisiblePosition createWithoutCanonicalization(const PositionWithAffin ity& canonicalized); 78 static VisiblePositionTemplate createWithoutCanonicalization(const PositionW ithAffinityTemplate<Strategy>& canonicalized);
78 79
79 // Intentionally delete |operator==()| and |operator!=()| for reducing 80 // Intentionally delete |operator==()| and |operator!=()| for reducing
80 // compilation error message. 81 // compilation error message.
81 // TODO(yosin) We'll have |equals()| when we have use cases of checking 82 // TODO(yosin) We'll have |equals()| when we have use cases of checking
82 // equality of both position and affinity. 83 // equality of both position and affinity.
83 bool operator==(const VisiblePosition&) const = delete; 84 bool operator==(const VisiblePositionTemplate&) const = delete;
84 bool operator!=(const VisiblePosition&) const = delete; 85 bool operator!=(const VisiblePositionTemplate&) const = delete;
85 86
86 bool isNull() const { return m_positionWithAffinity.isNull(); } 87 bool isNull() const { return m_positionWithAffinity.isNull(); }
87 bool isNotNull() const { return m_positionWithAffinity.isNotNull(); } 88 bool isNotNull() const { return m_positionWithAffinity.isNotNull(); }
88 bool isOrphan() const { return deepEquivalent().isOrphan(); } 89 bool isOrphan() const { return deepEquivalent().isOrphan(); }
89 90
90 Position deepEquivalent() const { return m_positionWithAffinity.position(); } 91 PositionAlgorithm<Strategy> deepEquivalent() const { return m_positionWithAf finity.position(); }
91 Position toParentAnchoredPosition() const { return deepEquivalent().parentAn choredEquivalent(); } 92 PositionAlgorithm<Strategy> toParentAnchoredPosition() const { return deepEq uivalent().parentAnchoredEquivalent(); }
92 PositionWithAffinity toPositionWithAffinity() const { return m_positionWithA ffinity; } 93 PositionWithAffinityTemplate<Strategy> toPositionWithAffinity() const { retu rn m_positionWithAffinity; }
93 TextAffinity affinity() const { return m_positionWithAffinity.affinity(); } 94 TextAffinity affinity() const { return m_positionWithAffinity.affinity(); }
94 95
95 DECLARE_TRACE(); 96 DEFINE_INLINE_TRACE()
97 {
98 visitor->trace(m_positionWithAffinity);
99 }
96 100
97 #ifndef NDEBUG 101 #ifndef NDEBUG
98 void debugPosition(const char* msg = "") const; 102 void debugPosition(const char* msg = "") const;
99 void formatForDebugger(char* buffer, unsigned length) const; 103 void formatForDebugger(char* buffer, unsigned length) const;
100 void showTreeForThis() const; 104 void showTreeForThis() const;
101 #endif 105 #endif
102 106
103 private: 107 private:
104 explicit VisiblePosition(const PositionWithAffinity&); 108 explicit VisiblePositionTemplate(const PositionWithAffinityTemplate<Strategy >&);
105 109
106 PositionWithAffinity m_positionWithAffinity; 110 PositionWithAffinityTemplate<Strategy> m_positionWithAffinity;
107 }; 111 };
108 112
113 extern template class CORE_EXTERN_TEMPLATE_EXPORT VisiblePositionTemplate<Editin gStrategy>;
114
115 using VisiblePosition = VisiblePositionTemplate<EditingStrategy>;
116
109 CORE_EXPORT VisiblePosition createVisiblePosition(const Position&, TextAffinity = VP_DEFAULT_AFFINITY); 117 CORE_EXPORT VisiblePosition createVisiblePosition(const Position&, TextAffinity = VP_DEFAULT_AFFINITY);
110 CORE_EXPORT VisiblePosition createVisiblePosition(const PositionWithAffinity&); 118 CORE_EXPORT VisiblePosition createVisiblePosition(const PositionWithAffinity&);
111 CORE_EXPORT VisiblePosition createVisiblePosition(const PositionInComposedTree&, TextAffinity = VP_DEFAULT_AFFINITY); 119 CORE_EXPORT VisiblePosition createVisiblePosition(const PositionInComposedTree&, TextAffinity = VP_DEFAULT_AFFINITY);
112 120
113 } // namespace blink 121 } // namespace blink
114 122
115 #ifndef NDEBUG 123 #ifndef NDEBUG
116 // Outside the WebCore namespace for ease of invocation from gdb. 124 // Outside the WebCore namespace for ease of invocation from gdb.
117 void showTree(const blink::VisiblePosition*); 125 void showTree(const blink::VisiblePosition*);
118 void showTree(const blink::VisiblePosition&); 126 void showTree(const blink::VisiblePosition&);
119 #endif 127 #endif
120 128
121 #endif // VisiblePosition_h 129 #endif // VisiblePosition_h
OLDNEW
« no previous file with comments | « no previous file | Source/core/editing/VisiblePosition.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698