LEFT | RIGHT |
1 /* | 1 /* |
2 * Copyright (C) 2016 Apple Inc. All rights reserved. | 2 * Copyright (C) 2016 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 27 matching lines...) Expand all Loading... |
38 | 38 |
39 class Document; | 39 class Document; |
40 class Element; | 40 class Element; |
41 | 41 |
42 struct IntersectionObserverRegistration { | 42 struct IntersectionObserverRegistration { |
43 RefPtr<IntersectionObserver> observer; | 43 RefPtr<IntersectionObserver> observer; |
44 size_t previousThresholdIndex { std::numeric_limits<size_t>::max() }; | 44 size_t previousThresholdIndex { std::numeric_limits<size_t>::max() }; |
45 bool previousIsIntersecting { false }; | 45 bool previousIsIntersecting { false }; |
46 }; | 46 }; |
47 | 47 |
| 48 struct IntersectionObserverData { |
| 49 // IntersectionObservers for which the element that owns this IntersectionOb
serverData is the root. |
| 50 Vector<IntersectionObserver*> observers; |
| 51 |
| 52 // Intersection observations for which the element that owns this Intersecti
onObserverData is the target. |
| 53 Vector<IntersectionObserverRegistration> registrations; |
| 54 }; |
| 55 |
48 class IntersectionObserver : public RefCounted<IntersectionObserver> { | 56 class IntersectionObserver : public RefCounted<IntersectionObserver> { |
49 public: | 57 public: |
50 struct Init { | 58 struct Init { |
51 RefPtr<Element> root; | 59 Element* root; |
52 String rootMargin; | 60 String rootMargin; |
53 Variant<double, Vector<double>> threshold; | 61 Variant<double, Vector<double>> threshold; |
54 }; | 62 }; |
55 | 63 |
56 static ExceptionOr<Ref<IntersectionObserver>> create(Document&, Ref<Intersec
tionObserverCallback>&&, Init&&); | 64 static ExceptionOr<Ref<IntersectionObserver>> create(Document&, Ref<Intersec
tionObserverCallback>&&, Init&&); |
57 | 65 |
| 66 Element* root() const { return m_root; } |
| 67 String rootMargin() const; |
| 68 |
58 ~IntersectionObserver(); | 69 ~IntersectionObserver(); |
59 | 70 |
60 Document& document() { return m_document; } | 71 Document* trackingDocument() { return m_root ? &m_root->document() : m_impli
citRootDocument; } |
61 | 72 |
62 Element* root() const { return m_root.get(); } | 73 const LengthBox& marginBox() const { return m_rootMargin; } |
63 String rootMargin() const { return m_rootMargin; } | |
64 const LengthBox& marginBox() const { return m_marginBox; } | |
65 const Vector<double>& thresholds() const { return m_thresholds; } | 74 const Vector<double>& thresholds() const { return m_thresholds; } |
66 const Vector<Element*> observationTargets() const { return m_observationTarg
ets; } | 75 const Vector<Element*> observationTargets() const { return m_observationTarg
ets; } |
67 | 76 |
68 // Called from JavaScript API | 77 // Called from JavaScript API |
69 ExceptionOr<void> observe(Element&); | 78 void observe(Element&); |
70 void unobserve(Element&); | 79 void unobserve(Element&); |
71 void disconnect(); | 80 void disconnect(); |
72 | 81 |
73 Vector<Ref<IntersectionObserverEntry>> takeRecords(); | 82 Vector<Ref<IntersectionObserverEntry>> takeRecords(); |
74 | 83 |
75 // Called internally. | 84 // Called internally. |
76 void addObservationTarget(Element&); | 85 void addObservationTarget(Element&); |
77 void removeObservationTarget(Element&); | 86 void removeObservationTarget(Element&); |
78 bool hasObservationTarget(Element&) const; | 87 bool hasObservationTarget(Element&) const; |
79 bool hasObservationTargets() const { return m_observationTargets.size(); } | 88 bool hasObservationTargets() const { return m_observationTargets.size(); } |
| 89 bool createTimestamp(DOMHighResTimeStamp&) const; |
| 90 void rootDestroyed(); |
| 91 void implicitRootDocumentDestroyed(); |
80 | 92 |
81 void appendQueuedEntry(Ref<IntersectionObserverEntry>&&); | 93 void appendQueuedEntry(Ref<IntersectionObserverEntry>&&); |
82 void notify(); | 94 void notify(); |
83 | 95 |
84 private: | 96 private: |
85 IntersectionObserver(Document&, Ref<IntersectionObserverCallback>&&, Init&&,
LengthBox&& marginBox); | 97 IntersectionObserver(Document&, Ref<IntersectionObserverCallback>&&, Init&&,
LengthBox&& marginBox); |
86 | 98 |
87 Document& m_document; | 99 Document* m_implicitRootDocument; |
88 RefPtr<Element> m_root; | 100 Element* m_root; |
89 String m_rootMargin; | 101 LengthBox m_rootMargin; |
90 Vector<double> m_thresholds; | 102 Vector<double> m_thresholds; |
91 Ref<IntersectionObserverCallback> m_callback; | 103 Ref<IntersectionObserverCallback> m_callback; |
92 LengthBox m_marginBox; | 104 LengthBox m_marginBox; |
93 Vector<Element*> m_observationTargets; | 105 Vector<Element*> m_observationTargets; |
94 Vector<Ref<IntersectionObserverEntry>> m_queuedEntries; | 106 Vector<Ref<IntersectionObserverEntry>> m_queuedEntries; |
95 }; | 107 }; |
96 | 108 |
97 } // namespace WebCore | 109 } // namespace WebCore |
98 | 110 |
99 #endif // ENABLE(INTERSECTION_OBSERVER) | 111 #endif // ENABLE(INTERSECTION_OBSERVER) |
LEFT | RIGHT |