OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google 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 are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 namespace { | 43 namespace { |
44 | 44 |
45 static const float viewportAnchorRelativeEpsilon = 0.1f; | 45 static const float viewportAnchorRelativeEpsilon = 0.1f; |
46 static const int viewportToNodeMaxRelativeArea = 2; | 46 static const int viewportToNodeMaxRelativeArea = 2; |
47 | 47 |
48 template <typename RectType> | 48 template <typename RectType> |
49 int area(const RectType& rect) { | 49 int area(const RectType& rect) { |
50 return rect.width() * rect.height(); | 50 return rect.width() * rect.height(); |
51 } | 51 } |
52 | 52 |
53 RESULT(Node) findNonEmptyAnchorNode(const IntPoint& point, const IntRect& viewRe
ct, EventHandler* eventHandler) | 53 RESULT(Node) findNonEmptyAnchorNode(const IntPoint& point, const IntRect& viewRe
ct, HANDLE_FORMAL(EventHandler) eventHandler) |
54 { | 54 { |
55 HANDLE(Node) node = eventHandler->hitTestResultAtPoint(point).innerNode(); | 55 HANDLE(Node) node = eventHandler->hitTestResultAtPoint(point).innerNode(); |
56 | 56 |
57 // If the node bounding box is sufficiently large, make a single attempt to | 57 // If the node bounding box is sufficiently large, make a single attempt to |
58 // find a smaller node; the larger the node bounds, the greater the | 58 // find a smaller node; the larger the node bounds, the greater the |
59 // variability under resize. | 59 // variability under resize. |
60 const int maxNodeArea = area(viewRect) * viewportToNodeMaxRelativeArea; | 60 const int maxNodeArea = area(viewRect) * viewportToNodeMaxRelativeArea; |
61 if (node && area(node->boundingBox()) > maxNodeArea) { | 61 if (node && area(node->boundingBox()) > maxNodeArea) { |
62 IntSize pointOffset = viewRect.size(); | 62 IntSize pointOffset = viewRect.size(); |
63 pointOffset.scale(viewportAnchorRelativeEpsilon); | 63 pointOffset.scale(viewportAnchorRelativeEpsilon); |
64 node = eventHandler->hitTestResultAtPoint(point + pointOffset).innerNode
(); | 64 node = eventHandler->hitTestResultAtPoint(point + pointOffset).innerNode
(); |
65 } | 65 } |
66 | 66 |
67 while (node && node->boundingBox().isEmpty()) { | 67 while (node && node->boundingBox().isEmpty()) { |
68 NoHandleScope scope; | 68 NoHandleScope scope; |
69 node = node->parentNode(); | 69 node = node->parentNode(); |
70 } | 70 } |
71 | 71 |
72 return node; | 72 return node; |
73 } | 73 } |
74 | 74 |
75 } // namespace | 75 } // namespace |
76 | 76 |
77 ViewportAnchor::ViewportAnchor(EventHandler* eventHandler) | 77 ViewportAnchor::ViewportAnchor(HANDLE_FORMAL(EventHandler) eventHandler) |
78 : m_eventHandler(eventHandler) { } | 78 : m_eventHandler(DOT_RAW(eventHandler)) { } |
79 | 79 |
80 void ViewportAnchor::setAnchor(const IntRect& viewRect, const FloatSize& anchorI
nViewCoords) | 80 void ViewportAnchor::setAnchor(const IntRect& viewRect, const FloatSize& anchorI
nViewCoords) |
81 { | 81 { |
82 m_viewRect = viewRect; | 82 m_viewRect = viewRect; |
83 m_anchorNode.clear(); | 83 m_anchorNode.clear(); |
84 m_anchorNodeBounds = LayoutRect(); | 84 m_anchorNodeBounds = LayoutRect(); |
85 m_anchorInNodeCoords = FloatSize(); | 85 m_anchorInNodeCoords = FloatSize(); |
86 m_anchorInViewCoords = anchorInViewCoords; | 86 m_anchorInViewCoords = anchorInViewCoords; |
87 | 87 |
88 if (viewRect.isEmpty()) | 88 if (viewRect.isEmpty()) |
89 return; | 89 return; |
90 | 90 |
91 // Preserve origins at the absolute screen origin | 91 // Preserve origins at the absolute screen origin |
92 if (viewRect.location() == IntPoint::zero()) | 92 if (viewRect.location() == IntPoint::zero()) |
93 return; | 93 return; |
94 | 94 |
95 FloatSize anchorOffset = viewRect.size(); | 95 FloatSize anchorOffset = viewRect.size(); |
96 anchorOffset.scale(anchorInViewCoords.width(), anchorInViewCoords.height()); | 96 anchorOffset.scale(anchorInViewCoords.width(), anchorInViewCoords.height()); |
97 const FloatPoint anchorPoint = FloatPoint(viewRect.location()) + anchorOffse
t; | 97 const FloatPoint anchorPoint = FloatPoint(viewRect.location()) + anchorOffse
t; |
98 | 98 |
99 HANDLE(Node) node = findNonEmptyAnchorNode(flooredIntPoint(anchorPoint), vie
wRect, m_eventHandler); | 99 HANDLE(Node) node = findNonEmptyAnchorNode(flooredIntPoint(anchorPoint), vie
wRect, adoptRawResult( m_eventHandler)); |
100 if (!node) | 100 if (!node) |
101 return; | 101 return; |
102 | 102 |
103 m_anchorNode = node; | 103 m_anchorNode = node; |
104 m_anchorNodeBounds = node->boundingBox(); | 104 m_anchorNodeBounds = node->boundingBox(); |
105 m_anchorInNodeCoords = anchorPoint - m_anchorNodeBounds.location(); | 105 m_anchorInNodeCoords = anchorPoint - m_anchorNodeBounds.location(); |
106 m_anchorInNodeCoords.scale(1.f / m_anchorNodeBounds.width(), 1.f / m_anchorN
odeBounds.height()); | 106 m_anchorInNodeCoords.scale(1.f / m_anchorNodeBounds.width(), 1.f / m_anchorN
odeBounds.height()); |
107 } | 107 } |
108 | 108 |
109 IntPoint ViewportAnchor::computeOrigin(const IntSize& currentViewSize) const | 109 IntPoint ViewportAnchor::computeOrigin(const IntSize& currentViewSize) const |
(...skipping 10 matching lines...) Expand all Loading... |
120 anchorOffsetFromNode.scale(m_anchorInNodeCoords.width(), m_anchorInNodeCoord
s.height()); | 120 anchorOffsetFromNode.scale(m_anchorInNodeCoords.width(), m_anchorInNodeCoord
s.height()); |
121 FloatPoint anchorPoint = currentNodeBounds.location() + anchorOffsetFromNode
; | 121 FloatPoint anchorPoint = currentNodeBounds.location() + anchorOffsetFromNode
; |
122 | 122 |
123 // Compute the new origin point relative to the new anchor point | 123 // Compute the new origin point relative to the new anchor point |
124 FloatSize anchorOffsetFromOrigin = currentViewSize; | 124 FloatSize anchorOffsetFromOrigin = currentViewSize; |
125 anchorOffsetFromOrigin.scale(m_anchorInViewCoords.width(), m_anchorInViewCoo
rds.height()); | 125 anchorOffsetFromOrigin.scale(m_anchorInViewCoords.width(), m_anchorInViewCoo
rds.height()); |
126 return flooredIntPoint(anchorPoint - anchorOffsetFromOrigin); | 126 return flooredIntPoint(anchorPoint - anchorOffsetFromOrigin); |
127 } | 127 } |
128 | 128 |
129 } // namespace WebKit | 129 } // namespace WebKit |
OLD | NEW |