OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 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 #include "platform/geometry/FloatPoint.h" | 43 #include "platform/geometry/FloatPoint.h" |
44 #include "platform/geometry/FloatQuad.h" | 44 #include "platform/geometry/FloatQuad.h" |
45 #include "platform/geometry/IntPoint.h" | 45 #include "platform/geometry/IntPoint.h" |
46 | 46 |
47 namespace blink { | 47 namespace blink { |
48 | 48 |
49 static const LayoutBlock* enclosingScrollableAncestor( | 49 static const LayoutBlock* enclosingScrollableAncestor( |
50 const LayoutObject* layoutObject) { | 50 const LayoutObject* layoutObject) { |
51 DCHECK(!layoutObject->isLayoutView()); | 51 DCHECK(!layoutObject->isLayoutView()); |
52 | 52 |
53 // Trace up the containingBlocks until we reach either the layoutObject view o
r a scrollable object. | 53 // Trace up the containingBlocks until we reach either the layoutObject view |
| 54 // or a scrollable object. |
54 const LayoutBlock* container = layoutObject->containingBlock(); | 55 const LayoutBlock* container = layoutObject->containingBlock(); |
55 while (!container->hasOverflowClip() && !container->isLayoutView()) | 56 while (!container->hasOverflowClip() && !container->isLayoutView()) |
56 container = container->containingBlock(); | 57 container = container->containingBlock(); |
57 return container; | 58 return container; |
58 } | 59 } |
59 | 60 |
60 static FloatRect toNormalizedRect(const FloatRect& absoluteRect, | 61 static FloatRect toNormalizedRect(const FloatRect& absoluteRect, |
61 const LayoutObject* layoutObject, | 62 const LayoutObject* layoutObject, |
62 const LayoutBlock* container) { | 63 const LayoutBlock* container) { |
63 DCHECK(layoutObject); | 64 DCHECK(layoutObject); |
64 | 65 |
65 DCHECK(container || layoutObject->isLayoutView()); | 66 DCHECK(container || layoutObject->isLayoutView()); |
66 if (!container) | 67 if (!container) |
67 return FloatRect(); | 68 return FloatRect(); |
68 | 69 |
69 // We want to normalize by the max layout overflow size instead of only the vi
sible bounding box. | 70 // We want to normalize by the max layout overflow size instead of only the |
70 // Quads and their enclosing bounding boxes need to be used in order to keep r
esults transform-friendly. | 71 // visible bounding box. Quads and their enclosing bounding boxes need to be |
| 72 // used in order to keep results transform-friendly. |
71 FloatPoint scrolledOrigin; | 73 FloatPoint scrolledOrigin; |
72 | 74 |
73 // For overflow:scroll we need to get where the actual origin is independently
of the scroll. | 75 // For overflow:scroll we need to get where the actual origin is independently |
| 76 // of the scroll. |
74 if (container->hasOverflowClip()) | 77 if (container->hasOverflowClip()) |
75 scrolledOrigin = -IntPoint(container->scrolledContentOffset()); | 78 scrolledOrigin = -IntPoint(container->scrolledContentOffset()); |
76 | 79 |
77 FloatRect overflowRect(scrolledOrigin, | 80 FloatRect overflowRect(scrolledOrigin, |
78 FloatSize(container->maxLayoutOverflow())); | 81 FloatSize(container->maxLayoutOverflow())); |
79 FloatRect containerRect = | 82 FloatRect containerRect = |
80 container->localToAbsoluteQuad(FloatQuad(overflowRect)) | 83 container->localToAbsoluteQuad(FloatQuad(overflowRect)) |
81 .enclosingBoundingBox(); | 84 .enclosingBoundingBox(); |
82 | 85 |
83 if (containerRect.isEmpty()) | 86 if (containerRect.isEmpty()) |
84 return FloatRect(); | 87 return FloatRect(); |
85 | 88 |
86 // Make the coordinates relative to the container enclosing bounding box. | 89 // Make the coordinates relative to the container enclosing bounding box. |
87 // Since we work with rects enclosing quad unions this is still transform-frie
ndly. | 90 // Since we work with rects enclosing quad unions this is still |
| 91 // transform-friendly. |
88 FloatRect normalizedRect = absoluteRect; | 92 FloatRect normalizedRect = absoluteRect; |
89 normalizedRect.moveBy(-containerRect.location()); | 93 normalizedRect.moveBy(-containerRect.location()); |
90 | 94 |
91 // Fixed positions do not make sense in this coordinate system, but need to le
ave consistent tickmarks. | 95 // Fixed positions do not make sense in this coordinate system, but need to |
92 // So, use their position when the view is not scrolled, like an absolute posi
tion. | 96 // leave consistent tickmarks. So, use their position when the view is not |
| 97 // scrolled, like an absolute position. |
93 if (layoutObject->style()->position() == FixedPosition && | 98 if (layoutObject->style()->position() == FixedPosition && |
94 container->isLayoutView()) | 99 container->isLayoutView()) |
95 normalizedRect.moveBy( | 100 normalizedRect.moveBy( |
96 -toLayoutView(container)->frameView()->scrollPosition()); | 101 -toLayoutView(container)->frameView()->scrollPosition()); |
97 | 102 |
98 normalizedRect.scale(1 / containerRect.width(), 1 / containerRect.height()); | 103 normalizedRect.scale(1 / containerRect.width(), 1 / containerRect.height()); |
99 return normalizedRect; | 104 return normalizedRect; |
100 } | 105 } |
101 | 106 |
102 FloatRect findInPageRectFromAbsoluteRect(const FloatRect& inputRect, | 107 FloatRect findInPageRectFromAbsoluteRect(const FloatRect& inputRect, |
103 const LayoutObject* baseLayoutObject) { | 108 const LayoutObject* baseLayoutObject) { |
104 if (!baseLayoutObject || inputRect.isEmpty()) | 109 if (!baseLayoutObject || inputRect.isEmpty()) |
105 return FloatRect(); | 110 return FloatRect(); |
106 | 111 |
107 // Normalize the input rect to its container block. | 112 // Normalize the input rect to its container block. |
108 const LayoutBlock* baseContainer = | 113 const LayoutBlock* baseContainer = |
109 enclosingScrollableAncestor(baseLayoutObject); | 114 enclosingScrollableAncestor(baseLayoutObject); |
110 FloatRect normalizedRect = | 115 FloatRect normalizedRect = |
111 toNormalizedRect(inputRect, baseLayoutObject, baseContainer); | 116 toNormalizedRect(inputRect, baseLayoutObject, baseContainer); |
112 | 117 |
113 // Go up across frames. | 118 // Go up across frames. |
114 for (const LayoutBox* layoutObject = baseContainer; layoutObject;) { | 119 for (const LayoutBox* layoutObject = baseContainer; layoutObject;) { |
115 // Go up the layout tree until we reach the root of the current frame (the L
ayoutView). | 120 // Go up the layout tree until we reach the root of the current frame (the |
| 121 // LayoutView). |
116 while (!layoutObject->isLayoutView()) { | 122 while (!layoutObject->isLayoutView()) { |
117 const LayoutBlock* container = enclosingScrollableAncestor(layoutObject); | 123 const LayoutBlock* container = enclosingScrollableAncestor(layoutObject); |
118 | 124 |
119 // Compose the normalized rects. | 125 // Compose the normalized rects. |
120 FloatRect normalizedBoxRect = toNormalizedRect( | 126 FloatRect normalizedBoxRect = toNormalizedRect( |
121 layoutObject->absoluteBoundingBoxRect(), layoutObject, container); | 127 layoutObject->absoluteBoundingBoxRect(), layoutObject, container); |
122 normalizedRect.scale(normalizedBoxRect.width(), | 128 normalizedRect.scale(normalizedBoxRect.width(), |
123 normalizedBoxRect.height()); | 129 normalizedBoxRect.height()); |
124 normalizedRect.moveBy(normalizedBoxRect.location()); | 130 normalizedRect.moveBy(normalizedBoxRect.location()); |
125 | 131 |
(...skipping 13 matching lines...) Expand all Loading... |
139 FloatRect findInPageRectFromRange(Range* range) { | 145 FloatRect findInPageRectFromRange(Range* range) { |
140 if (!range || !range->firstNode()) | 146 if (!range || !range->firstNode()) |
141 return FloatRect(); | 147 return FloatRect(); |
142 | 148 |
143 return findInPageRectFromAbsoluteRect( | 149 return findInPageRectFromAbsoluteRect( |
144 LayoutObject::absoluteBoundingBoxRectForRange(range), | 150 LayoutObject::absoluteBoundingBoxRectForRange(range), |
145 range->firstNode()->layoutObject()); | 151 range->firstNode()->layoutObject()); |
146 } | 152 } |
147 | 153 |
148 } // namespace blink | 154 } // namespace blink |
OLD | NEW |