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

Side by Side Diff: third_party/WebKit/Source/core/dom/StaticRange.h

Issue 2793093002: [InputEvent] Update spec link for StaticRange.idl and use unsigned offset (Closed)
Patch Set: Created 3 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // https://discourse.wicg.io/t/proposal-staticrange-to-be-used-instead-of-range- for-new-apis/1472
6
7 #ifndef StaticRange_h 5 #ifndef StaticRange_h
8 #define StaticRange_h 6 #define StaticRange_h
9 7
10 #include "bindings/core/v8/ScriptWrappable.h" 8 #include "bindings/core/v8/ScriptWrappable.h"
11 #include "core/CoreExport.h" 9 #include "core/CoreExport.h"
12 #include "core/dom/Range.h" 10 #include "core/dom/Range.h"
13 #include "core/editing/EphemeralRange.h" 11 #include "core/editing/EphemeralRange.h"
14 #include "platform/heap/Handle.h" 12 #include "platform/heap/Handle.h"
15 13
16 namespace blink { 14 namespace blink {
17 15
18 class Document; 16 class Document;
19 class ExceptionState; 17 class ExceptionState;
20 18
21 class CORE_EXPORT StaticRange final : public GarbageCollected<StaticRange>, 19 class CORE_EXPORT StaticRange final : public GarbageCollected<StaticRange>,
22 public ScriptWrappable { 20 public ScriptWrappable {
23 DEFINE_WRAPPERTYPEINFO(); 21 DEFINE_WRAPPERTYPEINFO();
24 22
25 public: 23 public:
26 static StaticRange* create(Document& document) { 24 static StaticRange* create(Document& document) {
27 return new StaticRange(document); 25 return new StaticRange(document);
28 } 26 }
29 static StaticRange* create(Document& document, 27 static StaticRange* create(Document& document,
30 Node* startContainer, 28 Node* startContainer,
31 int startOffset, 29 unsigned startOffset,
32 Node* endContainer, 30 Node* endContainer,
33 int endOffset) { 31 unsigned endOffset) {
34 return new StaticRange(document, startContainer, startOffset, endContainer, 32 return new StaticRange(document, startContainer, startOffset, endContainer,
35 endOffset); 33 endOffset);
36 } 34 }
37 static StaticRange* create(const Range* range) { 35 static StaticRange* create(const Range* range) {
38 return new StaticRange(range->ownerDocument(), range->startContainer(), 36 return new StaticRange(range->ownerDocument(), range->startContainer(),
39 range->startOffset(), range->endContainer(), 37 range->startOffset(), range->endContainer(),
40 range->endOffset()); 38 range->endOffset());
41 } 39 }
42 static StaticRange* create(const EphemeralRange& range) { 40 static StaticRange* create(const EphemeralRange& range) {
43 DCHECK(!range.isNull()); 41 DCHECK(!range.isNull());
44 return new StaticRange(range.document(), 42 return new StaticRange(range.document(),
45 range.startPosition().computeContainerNode(), 43 range.startPosition().computeContainerNode(),
46 range.startPosition().computeOffsetInContainerNode(), 44 range.startPosition().computeOffsetInContainerNode(),
47 range.endPosition().computeContainerNode(), 45 range.endPosition().computeContainerNode(),
48 range.endPosition().computeOffsetInContainerNode()); 46 range.endPosition().computeOffsetInContainerNode());
49 } 47 }
50 48
51 Node* startContainer() const { return m_startContainer.get(); } 49 Node* startContainer() const { return m_startContainer.get(); }
52 void setStartContainer(Node* startContainer) { 50 void setStartContainer(Node* startContainer) {
53 m_startContainer = startContainer; 51 m_startContainer = startContainer;
54 } 52 }
55 53
56 int startOffset() const { return m_startOffset; } 54 unsigned startOffset() const { return m_startOffset; }
57 void setStartOffset(int startOffset) { m_startOffset = startOffset; } 55 void setStartOffset(unsigned startOffset) { m_startOffset = startOffset; }
58 56
59 Node* endContainer() const { return m_endContainer.get(); } 57 Node* endContainer() const { return m_endContainer.get(); }
60 void setEndContainer(Node* endContainer) { m_endContainer = endContainer; } 58 void setEndContainer(Node* endContainer) { m_endContainer = endContainer; }
61 59
62 int endOffset() const { return m_endOffset; } 60 unsigned endOffset() const { return m_endOffset; }
63 void setEndOffset(int endOffset) { m_endOffset = endOffset; } 61 void setEndOffset(unsigned endOffset) { m_endOffset = endOffset; }
64 62
65 bool collapsed() const { 63 bool collapsed() const {
66 return m_startContainer == m_endContainer && m_startOffset == m_endOffset; 64 return m_startContainer == m_endContainer && m_startOffset == m_endOffset;
67 } 65 }
68 66
69 void setStart(Node* container, int offset); 67 void setStart(Node* container, unsigned offset);
70 void setEnd(Node* container, int offset); 68 void setEnd(Node* container, unsigned offset);
71 69
72 Range* toRange(ExceptionState& = ASSERT_NO_EXCEPTION) const; 70 Range* toRange(ExceptionState& = ASSERT_NO_EXCEPTION) const;
73 71
74 DECLARE_TRACE(); 72 DECLARE_TRACE();
75 73
76 private: 74 private:
77 explicit StaticRange(Document&); 75 explicit StaticRange(Document&);
78 StaticRange(Document&, 76 StaticRange(Document&,
79 Node* startContainer, 77 Node* startContainer,
80 int startOffset, 78 unsigned startOffset,
81 Node* endContainer, 79 Node* endContainer,
82 int endOffset); 80 unsigned endOffset);
83 81
84 Member<Document> m_ownerDocument; // Required by |toRange()|. 82 Member<Document> m_ownerDocument; // Required by |toRange()|.
85 Member<Node> m_startContainer; 83 Member<Node> m_startContainer;
86 int m_startOffset; 84 unsigned m_startOffset;
87 Member<Node> m_endContainer; 85 Member<Node> m_endContainer;
88 int m_endOffset; 86 unsigned m_endOffset;
89 }; 87 };
90 88
91 using StaticRangeVector = HeapVector<Member<StaticRange>>; 89 using StaticRangeVector = HeapVector<Member<StaticRange>>;
92 90
93 } // namespace blink 91 } // namespace blink
94 92
95 #endif // StaticRange_h 93 #endif // StaticRange_h
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/dom/StaticRange.cpp » ('j') | third_party/WebKit/Source/core/dom/StaticRange.idl » ('J')

Powered by Google App Engine
This is Rietveld 408576698