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

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

Issue 1756763002: 2016-03-02T18:53:01 LayoutPosition Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 2016-04-25T19:02:18 Created 4 years, 7 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 LayoutPosition_h
6 #define LayoutPosition_h
7
8 #include "core/CoreExport.h"
9 #include "core/editing/Position.h"
10 // TODO(yosin): Once we stop to cache caret rectangle, we should not include
11 // "FloatQuad.h"
12 #include "platform/geometry/FloatQuad.h"
13 #include "wtf/Allocator.h"
14 #include "wtf/Forward.h"
15
16 #include <iosfwd>
17
18 namespace blink {
19
20 class Document;
21 class LayoutObject;
22 class InlineBox;
23 struct InlineBoxPosition;
24 class InlineTextBox;
25 class Text;
26
27 // LayoutPosition represents a position in layout tree.
28 // TODO(yosin): We will replace |RenderedPosition| by |LayoutPosition|. We
29 // should move functions in |RenderedPosition| to |LayoutPosition|.
30 class CORE_EXPORT LayoutPosition final {
31 STACK_ALLOCATED();
32
33 public:
34 LayoutPosition(const LayoutPosition& other);
35 LayoutPosition();
36 ~LayoutPosition();
37
38 bool operator==(const LayoutPosition& other) const;
39 bool operator!=(const LayoutPosition& other) const;
40
41 bool isAfterAnchor() const { return m_anchorType == PositionAnchorType::Afte rAnchor; }
42 bool isBeforeAnchor() const { return m_anchorType == PositionAnchorType::Bef oreAnchor; }
43 bool isBeforeChildren() const { return m_anchorType == PositionAnchorType::B eforeChildren; }
44 bool isNotNull() const { return !isNull(); }
45 bool isNull() const { return !m_layoutObject; }
46 bool isOffsetInAnchor() const { return m_anchorType == PositionAnchorType::O ffsetInAnchor; }
47
48 // DOM Position related functions.
49 bool canBePosition() const;
50 Position toPosition(const Position&) const;
51 PositionInFlatTree toPosition(const PositionInFlatTree&) const;
52
53 static LayoutPosition create(const Position&);
54 static LayoutPosition create(const PositionInFlatTree&);
55
56 // Caret related functions
57 bool canPlaceCaret() const;
58 bool isCaretEquivalent(const LayoutPosition&) const;
59
60 // Text node related functions
61 UChar codeUnitAfter() const;
62
63 // BIDI related functions
64 bool isLeftToRightDirection() const;
65
66 private:
67 friend class LayoutPositionPrinter;
68 friend class LayoutPositionTest;
69 friend class LayoutTreePrinter;
70 friend CORE_EXPORT LayoutPosition nextPositionOf(const LayoutPosition&);
71 friend CORE_EXPORT LayoutPosition previousPositionOf(const LayoutPosition&);
72
73 LayoutPosition(PositionAnchorType, LayoutObject*);
74 LayoutPosition(const InlineBoxPosition&);
75
76 const Document& document() const;
77 bool isTextPosition() const;
78 bool isValid() const;
79
80 // TODO(yosin): Once we have robust |canPlaceCaret()|, we should get rid
81 // of |canPlaceCaretInternal()|.
82 bool canPlaceCaretInternal() const;
83 FloatQuad computeCaretQuad() const;
84 InlineBoxPosition computeInlineBoxPosition() const;
85
86 template <typename Strategy>
87 static LayoutPosition createAlgorithm(const PositionTemplate<Strategy>&);
88
89 template <typename Strategy>
90 PositionTemplate<Strategy> toPositionAlgorithm(const PositionTemplate<Strate gy>&) const;
91
92 static LayoutPosition afterAnchorOf(InlineBox*);
93 static LayoutPosition afterAnchorOf(LayoutObject*);
94 static LayoutPosition beforeAnchorOf(InlineBox*);
95 static LayoutPosition beforeAnchorOf(LayoutObject*);
96 static LayoutPosition beforeChildrenOf(LayoutObject*);
97 static LayoutObject* layoutObjectOf(const InlineBox&);
98 static LayoutPosition previousPositionOf(LayoutObject*);
99
100 // |m_anchorType| is one of |AfterAnchor|, |BeforeAnchor|, |BeforeChildren|,
101 // or |OffsetInAnchor|.
102 PositionAnchorType m_anchorType;
103 InlineBox* m_inlineBox = nullptr;
104 // |m_layoutObject| satisfies following restriction:
105 // - |AfterAnchor| the last node in container.
106 // - |BeforeAnchor| Any |LayoutObject| other than |LayoutText|.
107 // - |BeforeChildren| the element without children
108 // - |OffsetInAnchor| |LayoutText|
109 // Other than |OffsetInAnchor|, |m_layoutObject| can't be |LayoutText|.
110 LayoutObject* m_layoutObject = nullptr;
111 // |m_offsetInBox| holds offset in |m_inlineBox| to zero to
112 // |InlineTextBox::end()+1|. Note: Unlike |std::end()| in
113 // |InlineTextBox::end()| returns maximum offset rather than beyond
114 // maximum.
115 int m_offsetInBox = 0;
116
117 // TODO(yosin): We should measure execution time with and without caret
118 // caret rectangle cache.
119 mutable bool m_hasCaretQuad = false;
120 mutable FloatQuad m_caretQuad;
121
122 #if ENABLE(ASSERT)
123 uint64_t m_domTreeVersion = 0;
124 uint64_t m_styleVersion = 0;
125 #endif
126 };
127
128 // Logical movement with code unit. Caller of these functions should
129 // handle Unicode surrogate pair and Unicode control format characters, e.g.
130 // zero width characters, BiDi markers.
131 CORE_EXPORT LayoutPosition nextPositionOf(const LayoutPosition&);
132 CORE_EXPORT LayoutPosition previousPositionOf(const LayoutPosition&);
133
134 // Physical movement for implementing arrow key. Logical movement depends
135 // on CSS "writing-mode" property and "dir" DOM attribute.
136 // These functions doesn't handle Unicode surrogate pair, Unicode control
137 // format characters, e.g. zero width characters, BiDi markers.
138 CORE_EXPORT LayoutPosition leftPositionOf(const LayoutPosition&);
139 CORE_EXPORT LayoutPosition rightPositionOf(const LayoutPosition&);
140 CORE_EXPORT LayoutPosition upPositionOf(const LayoutPosition&);
141 CORE_EXPORT LayoutPosition downPositionOf(const LayoutPosition&);
142
143 CORE_EXPORT std::ostream& operator<<(std::ostream&, const LayoutPosition&);
144
145 } // namespace blink
146
147 #endif // LayoutPosition_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/Editor.cpp ('k') | third_party/WebKit/Source/core/editing/LayoutPosition.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698