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

Unified 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, 8 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/editing/LayoutPosition.h
diff --git a/third_party/WebKit/Source/core/editing/LayoutPosition.h b/third_party/WebKit/Source/core/editing/LayoutPosition.h
new file mode 100644
index 0000000000000000000000000000000000000000..80ed05281c03365ad391e1913988639acaf6f526
--- /dev/null
+++ b/third_party/WebKit/Source/core/editing/LayoutPosition.h
@@ -0,0 +1,147 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef LayoutPosition_h
+#define LayoutPosition_h
+
+#include "core/CoreExport.h"
+#include "core/editing/Position.h"
+// TODO(yosin): Once we stop to cache caret rectangle, we should not include
+// "FloatQuad.h"
+#include "platform/geometry/FloatQuad.h"
+#include "wtf/Allocator.h"
+#include "wtf/Forward.h"
+
+#include <iosfwd>
+
+namespace blink {
+
+class Document;
+class LayoutObject;
+class InlineBox;
+struct InlineBoxPosition;
+class InlineTextBox;
+class Text;
+
+// LayoutPosition represents a position in layout tree.
+// TODO(yosin): We will replace |RenderedPosition| by |LayoutPosition|. We
+// should move functions in |RenderedPosition| to |LayoutPosition|.
+class CORE_EXPORT LayoutPosition final {
+ STACK_ALLOCATED();
+
+public:
+ LayoutPosition(const LayoutPosition& other);
+ LayoutPosition();
+ ~LayoutPosition();
+
+ bool operator==(const LayoutPosition& other) const;
+ bool operator!=(const LayoutPosition& other) const;
+
+ bool isAfterAnchor() const { return m_anchorType == PositionAnchorType::AfterAnchor; }
+ bool isBeforeAnchor() const { return m_anchorType == PositionAnchorType::BeforeAnchor; }
+ bool isBeforeChildren() const { return m_anchorType == PositionAnchorType::BeforeChildren; }
+ bool isNotNull() const { return !isNull(); }
+ bool isNull() const { return !m_layoutObject; }
+ bool isOffsetInAnchor() const { return m_anchorType == PositionAnchorType::OffsetInAnchor; }
+
+ // DOM Position related functions.
+ bool canBePosition() const;
+ Position toPosition(const Position&) const;
+ PositionInFlatTree toPosition(const PositionInFlatTree&) const;
+
+ static LayoutPosition create(const Position&);
+ static LayoutPosition create(const PositionInFlatTree&);
+
+ // Caret related functions
+ bool canPlaceCaret() const;
+ bool isCaretEquivalent(const LayoutPosition&) const;
+
+ // Text node related functions
+ UChar codeUnitAfter() const;
+
+ // BIDI related functions
+ bool isLeftToRightDirection() const;
+
+private:
+ friend class LayoutPositionPrinter;
+ friend class LayoutPositionTest;
+ friend class LayoutTreePrinter;
+ friend CORE_EXPORT LayoutPosition nextPositionOf(const LayoutPosition&);
+ friend CORE_EXPORT LayoutPosition previousPositionOf(const LayoutPosition&);
+
+ LayoutPosition(PositionAnchorType, LayoutObject*);
+ LayoutPosition(const InlineBoxPosition&);
+
+ const Document& document() const;
+ bool isTextPosition() const;
+ bool isValid() const;
+
+ // TODO(yosin): Once we have robust |canPlaceCaret()|, we should get rid
+ // of |canPlaceCaretInternal()|.
+ bool canPlaceCaretInternal() const;
+ FloatQuad computeCaretQuad() const;
+ InlineBoxPosition computeInlineBoxPosition() const;
+
+ template <typename Strategy>
+ static LayoutPosition createAlgorithm(const PositionTemplate<Strategy>&);
+
+ template <typename Strategy>
+ PositionTemplate<Strategy> toPositionAlgorithm(const PositionTemplate<Strategy>&) const;
+
+ static LayoutPosition afterAnchorOf(InlineBox*);
+ static LayoutPosition afterAnchorOf(LayoutObject*);
+ static LayoutPosition beforeAnchorOf(InlineBox*);
+ static LayoutPosition beforeAnchorOf(LayoutObject*);
+ static LayoutPosition beforeChildrenOf(LayoutObject*);
+ static LayoutObject* layoutObjectOf(const InlineBox&);
+ static LayoutPosition previousPositionOf(LayoutObject*);
+
+ // |m_anchorType| is one of |AfterAnchor|, |BeforeAnchor|, |BeforeChildren|,
+ // or |OffsetInAnchor|.
+ PositionAnchorType m_anchorType;
+ InlineBox* m_inlineBox = nullptr;
+ // |m_layoutObject| satisfies following restriction:
+ // - |AfterAnchor| the last node in container.
+ // - |BeforeAnchor| Any |LayoutObject| other than |LayoutText|.
+ // - |BeforeChildren| the element without children
+ // - |OffsetInAnchor| |LayoutText|
+ // Other than |OffsetInAnchor|, |m_layoutObject| can't be |LayoutText|.
+ LayoutObject* m_layoutObject = nullptr;
+ // |m_offsetInBox| holds offset in |m_inlineBox| to zero to
+ // |InlineTextBox::end()+1|. Note: Unlike |std::end()| in
+ // |InlineTextBox::end()| returns maximum offset rather than beyond
+ // maximum.
+ int m_offsetInBox = 0;
+
+ // TODO(yosin): We should measure execution time with and without caret
+ // caret rectangle cache.
+ mutable bool m_hasCaretQuad = false;
+ mutable FloatQuad m_caretQuad;
+
+#if ENABLE(ASSERT)
+ uint64_t m_domTreeVersion = 0;
+ uint64_t m_styleVersion = 0;
+#endif
+};
+
+// Logical movement with code unit. Caller of these functions should
+// handle Unicode surrogate pair and Unicode control format characters, e.g.
+// zero width characters, BiDi markers.
+CORE_EXPORT LayoutPosition nextPositionOf(const LayoutPosition&);
+CORE_EXPORT LayoutPosition previousPositionOf(const LayoutPosition&);
+
+// Physical movement for implementing arrow key. Logical movement depends
+// on CSS "writing-mode" property and "dir" DOM attribute.
+// These functions doesn't handle Unicode surrogate pair, Unicode control
+// format characters, e.g. zero width characters, BiDi markers.
+CORE_EXPORT LayoutPosition leftPositionOf(const LayoutPosition&);
+CORE_EXPORT LayoutPosition rightPositionOf(const LayoutPosition&);
+CORE_EXPORT LayoutPosition upPositionOf(const LayoutPosition&);
+CORE_EXPORT LayoutPosition downPositionOf(const LayoutPosition&);
+
+CORE_EXPORT std::ostream& operator<<(std::ostream&, const LayoutPosition&);
+
+} // namespace blink
+
+#endif // LayoutPosition_h
« 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