| OLD | NEW |
| 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 #ifndef IntersectionObservation_h | 5 #ifndef IntersectionObservation_h |
| 6 #define IntersectionObservation_h | 6 #define IntersectionObservation_h |
| 7 | 7 |
| 8 #include "core/dom/DOMHighResTimeStamp.h" | 8 #include "core/dom/DOMHighResTimeStamp.h" |
| 9 #include "platform/geometry/LayoutRect.h" | 9 #include "platform/geometry/LayoutRect.h" |
| 10 #include "platform/heap/Handle.h" | 10 #include "platform/heap/Handle.h" |
| 11 | 11 |
| 12 namespace blink { | 12 namespace blink { |
| 13 | 13 |
| 14 class Element; | 14 class Element; |
| 15 class IntersectionObserver; | 15 class IntersectionObserver; |
| 16 | 16 |
| 17 class IntersectionObservation final | 17 class IntersectionObservation |
| 18 : public GarbageCollected<IntersectionObservation> { | 18 : public GarbageCollectedFinalized<IntersectionObservation> { |
| 19 WTF_MAKE_NONCOPYABLE(IntersectionObservation); |
| 20 |
| 19 public: | 21 public: |
| 20 IntersectionObservation(IntersectionObserver&, | 22 IntersectionObservation(IntersectionObserver&, |
| 21 Element&, | 23 Element&, |
| 22 bool shouldReportRootBounds); | 24 bool shouldReportRootBounds); |
| 25 virtual ~IntersectionObservation(); |
| 23 | 26 |
| 24 struct IntersectionGeometry { | 27 struct IntersectionGeometry { |
| 25 LayoutRect targetRect; | 28 LayoutRect targetRect; |
| 26 LayoutRect intersectionRect; | 29 LayoutRect intersectionRect; |
| 27 LayoutRect rootRect; | 30 LayoutRect rootRect; |
| 28 bool doesIntersect; | 31 bool doesIntersect; |
| 29 | 32 |
| 30 IntersectionGeometry() : doesIntersect(false) {} | 33 IntersectionGeometry() : doesIntersect(false) {} |
| 31 }; | 34 }; |
| 32 | 35 |
| 33 IntersectionObserver& observer() const { return *m_observer; } | 36 IntersectionObserver& observer() const { return *m_observer; } |
| 34 Element* target() const { return m_target; } | 37 Element* target() const { return m_target; } |
| 35 unsigned lastThresholdIndex() const { return m_lastThresholdIndex; } | 38 unsigned lastThresholdIndex() const { return m_lastThresholdIndex; } |
| 36 void setLastThresholdIndex(unsigned index) { m_lastThresholdIndex = index; } | 39 void setLastThresholdIndex(unsigned index) { m_lastThresholdIndex = index; } |
| 37 bool shouldReportRootBounds() const { return m_shouldReportRootBounds; } | 40 bool shouldReportRootBounds() const { return m_shouldReportRootBounds; } |
| 38 void computeIntersectionObservations(DOMHighResTimeStamp); | 41 virtual void computeIntersectionObservations(DOMHighResTimeStamp); |
| 39 void disconnect(); | 42 void disconnect(); |
| 40 void clearRootAndRemoveFromTarget(); | 43 void clearRootAndRemoveFromTarget(); |
| 41 | 44 |
| 42 DECLARE_TRACE(); | 45 DECLARE_TRACE(); |
| 43 | 46 |
| 47 protected: |
| 48 bool computeGeometry(IntersectionGeometry&) const; |
| 49 |
| 44 private: | 50 private: |
| 45 void applyRootMargin(LayoutRect&) const; | 51 void applyRootMargin(LayoutRect&) const; |
| 46 void initializeGeometry(IntersectionGeometry&) const; | 52 void initializeGeometry(IntersectionGeometry&) const; |
| 47 void initializeTargetRect(LayoutRect&) const; | 53 void initializeTargetRect(LayoutRect&) const; |
| 48 void initializeRootRect(LayoutRect&) const; | 54 void initializeRootRect(LayoutRect&) const; |
| 49 void clipToRoot(IntersectionGeometry&) const; | 55 void clipToRoot(IntersectionGeometry&) const; |
| 50 void mapTargetRectToTargetFrameCoordinates(LayoutRect&) const; | 56 void mapTargetRectToTargetFrameCoordinates(LayoutRect&) const; |
| 51 void mapRootRectToRootFrameCoordinates(LayoutRect&) const; | 57 void mapRootRectToRootFrameCoordinates(LayoutRect&) const; |
| 52 void mapRootRectToTargetFrameCoordinates(LayoutRect&) const; | 58 void mapRootRectToTargetFrameCoordinates(LayoutRect&) const; |
| 53 bool computeGeometry(IntersectionGeometry&) const; | |
| 54 | 59 |
| 55 Member<IntersectionObserver> m_observer; | 60 Member<IntersectionObserver> m_observer; |
| 56 | 61 |
| 57 WeakMember<Element> m_target; | 62 WeakMember<Element> m_target; |
| 58 | 63 |
| 59 unsigned m_shouldReportRootBounds : 1; | 64 unsigned m_shouldReportRootBounds : 1; |
| 60 unsigned m_lastThresholdIndex : 30; | 65 unsigned m_lastThresholdIndex : 30; |
| 61 }; | 66 }; |
| 62 | 67 |
| 68 class ViewportIntersectionObservation final : public IntersectionObservation { |
| 69 WTF_MAKE_NONCOPYABLE(ViewportIntersectionObservation); |
| 70 |
| 71 public: |
| 72 ViewportIntersectionObservation(IntersectionObserver&, Element&); |
| 73 ~ViewportIntersectionObservation() final; |
| 74 |
| 75 void computeIntersectionObservations(DOMHighResTimeStamp) final; |
| 76 |
| 77 private: |
| 78 LayoutRect m_lastIntersectRect; |
| 79 }; |
| 80 |
| 63 } // namespace blink | 81 } // namespace blink |
| 64 | 82 |
| 65 #endif // IntersectionObservation_h | 83 #endif // IntersectionObservation_h |
| OLD | NEW |