| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 #include "RenderBox.h" | 42 #include "RenderBox.h" |
| 43 #include "RenderObject.h" | 43 #include "RenderObject.h" |
| 44 #include "RenderPart.h" | 44 #include "RenderPart.h" |
| 45 #include "RenderStyle.h" | 45 #include "RenderStyle.h" |
| 46 #include "RenderView.h" | 46 #include "RenderView.h" |
| 47 | 47 |
| 48 using namespace WebCore; | 48 using namespace WebCore; |
| 49 | 49 |
| 50 namespace WebKit { | 50 namespace WebKit { |
| 51 | 51 |
| 52 static FloatRect toNormalizedRect(const FloatRect& absoluteRect, const RenderObj
ect* renderer) | 52 static const RenderBlock* enclosingScrollableAncestor(const RenderObject* render
er) |
| 53 { |
| 54 ASSERT(!renderer->isRenderView()); |
| 55 |
| 56 // Trace up the containingBlocks until we reach either the render view or a
scrollable object. |
| 57 const RenderBlock* container = renderer->containingBlock(); |
| 58 while (!container->hasOverflowClip() && !container->isRenderView()) |
| 59 container = container->containingBlock(); |
| 60 return container; |
| 61 } |
| 62 |
| 63 static FloatRect toNormalizedRect(const FloatRect& absoluteRect, const RenderObj
ect* renderer, const RenderBlock* container) |
| 53 { | 64 { |
| 54 ASSERT(renderer); | 65 ASSERT(renderer); |
| 55 | 66 |
| 56 const RenderBlock* container = renderer->containingBlock(); | |
| 57 ASSERT(container || renderer->isRenderView()); | 67 ASSERT(container || renderer->isRenderView()); |
| 58 if (!container) | 68 if (!container) |
| 59 return FloatRect(); | 69 return FloatRect(); |
| 60 | 70 |
| 61 // We want to normalize by the max layout overflow size instead of only the
visible bounding box. | 71 // We want to normalize by the max layout overflow size instead of only the
visible bounding box. |
| 62 // Quads and their enclosing bounding boxes need to be used in order to keep
results transform-friendly. | 72 // Quads and their enclosing bounding boxes need to be used in order to keep
results transform-friendly. |
| 63 FloatPoint scrolledOrigin; | 73 FloatPoint scrolledOrigin; |
| 64 | 74 |
| 65 // For overflow:scroll we need to get where the actual origin is independent
ly of the scroll. | 75 // For overflow:scroll we need to get where the actual origin is independent
ly of the scroll. |
| 66 if (container->hasOverflowClip()) | 76 if (container->hasOverflowClip()) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 85 normalizedRect.scale(1 / containerRect.width(), 1 / containerRect.height()); | 95 normalizedRect.scale(1 / containerRect.width(), 1 / containerRect.height()); |
| 86 return normalizedRect; | 96 return normalizedRect; |
| 87 } | 97 } |
| 88 | 98 |
| 89 FloatRect findInPageRectFromAbsoluteRect(const FloatRect& inputRect, const Rende
rObject* baseRenderer) | 99 FloatRect findInPageRectFromAbsoluteRect(const FloatRect& inputRect, const Rende
rObject* baseRenderer) |
| 90 { | 100 { |
| 91 if (!baseRenderer || inputRect.isEmpty()) | 101 if (!baseRenderer || inputRect.isEmpty()) |
| 92 return FloatRect(); | 102 return FloatRect(); |
| 93 | 103 |
| 94 // Normalize the input rect to its container block. | 104 // Normalize the input rect to its container block. |
| 95 FloatRect normalizedRect = toNormalizedRect(inputRect, baseRenderer); | 105 const RenderBlock* baseContainer = enclosingScrollableAncestor(baseRenderer)
; |
| 106 FloatRect normalizedRect = toNormalizedRect(inputRect, baseRenderer, baseCon
tainer); |
| 96 | 107 |
| 97 // Go up across frames. | 108 // Go up across frames. |
| 98 for (const RenderObject* renderer = baseRenderer->containingBlock(); rendere
r; ) { | 109 for (const RenderBox* renderer = baseContainer; renderer; ) { |
| 99 | 110 |
| 100 // Go up the render tree until we reach the root of the current frame (t
he RenderView). | 111 // Go up the render tree until we reach the root of the current frame (t
he RenderView). |
| 101 for (const RenderBlock* container = renderer->containingBlock(); contain
er; | 112 while (!renderer->isRenderView()) { |
| 102 renderer = container, container = container->containingBlock())
{ | 113 const RenderBlock* container = enclosingScrollableAncestor(renderer)
; |
| 103 | 114 |
| 104 // Compose the normalized rects. | 115 // Compose the normalized rects. |
| 105 FloatRect normalizedBoxRect = toNormalizedRect(renderer->absoluteBou
ndingBoxRect(), renderer); | 116 FloatRect normalizedBoxRect = toNormalizedRect(renderer->absoluteBou
ndingBoxRect(), renderer, container); |
| 106 normalizedRect.scale(normalizedBoxRect.width(), normalizedBoxRect.he
ight()); | 117 normalizedRect.scale(normalizedBoxRect.width(), normalizedBoxRect.he
ight()); |
| 107 normalizedRect.moveBy(normalizedBoxRect.location()); | 118 normalizedRect.moveBy(normalizedBoxRect.location()); |
| 108 | 119 |
| 109 if (normalizedRect.isEmpty()) | 120 renderer = container; |
| 110 return normalizedRect; | |
| 111 } | 121 } |
| 112 | 122 |
| 123 ASSERT(renderer->isRenderView()); |
| 124 |
| 113 // Jump to the renderer owning the frame, if any. | 125 // Jump to the renderer owning the frame, if any. |
| 114 ASSERT(renderer->isRenderView()); | |
| 115 renderer = renderer->frame() ? renderer->frame()->ownerRenderer() : 0; | 126 renderer = renderer->frame() ? renderer->frame()->ownerRenderer() : 0; |
| 116 } | 127 } |
| 117 | 128 |
| 118 return normalizedRect; | 129 return normalizedRect; |
| 119 } | 130 } |
| 120 | 131 |
| 121 FloatRect findInPageRectFromRange(Range* range) | 132 FloatRect findInPageRectFromRange(Range* range) |
| 122 { | 133 { |
| 123 if (!range || !range->firstNode()) | 134 if (!range || !range->firstNode()) |
| 124 return FloatRect(); | 135 return FloatRect(); |
| 125 | 136 |
| 126 return findInPageRectFromAbsoluteRect(RenderObject::absoluteBoundingBoxRectF
orRange(range), range->firstNode()->renderer()); | 137 return findInPageRectFromAbsoluteRect(RenderObject::absoluteBoundingBoxRectF
orRange(range), range->firstNode()->renderer()); |
| 127 } | 138 } |
| 128 | 139 |
| 129 } // namespace WebKit | 140 } // namespace WebKit |
| OLD | NEW |