summaryrefslogtreecommitdiffstats
path: root/WebKit/android/nav/CachedLayer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'WebKit/android/nav/CachedLayer.cpp')
-rw-r--r--WebKit/android/nav/CachedLayer.cpp94
1 files changed, 87 insertions, 7 deletions
diff --git a/WebKit/android/nav/CachedLayer.cpp b/WebKit/android/nav/CachedLayer.cpp
index 2f6e20a..c4293a5 100644
--- a/WebKit/android/nav/CachedLayer.cpp
+++ b/WebKit/android/nav/CachedLayer.cpp
@@ -46,23 +46,79 @@ IntRect CachedLayer::adjustBounds(const LayerAndroid* root,
return bounds;
}
FloatRect temp = bounds;
+ // First, remove the original offset from the bounds.
+ temp.move(-mOffset.x(), -mOffset.y());
+
+ // Now, add in the original scroll position. This moves the node to the
+ // original location within the layer.
+ temp.move(mScrollOffset.x(), mScrollOffset.y());
+
+ // Next, add in the new position of the layer (could be different due to a
+ // fixed position layer).
const FloatPoint& position = aLayer->getPosition();
temp.move(position.x(), position.y());
+
+ // Add in any layer translation.
const FloatPoint& translation = aLayer->translation();
temp.move(translation.x(), translation.y());
+
+ // Move the bounds by the layer's internal scroll position.
+ const SkPoint& scroll = aLayer->scrollPosition();
+ temp.move(SkScalarToFloat(-scroll.fX), SkScalarToFloat(-scroll.fY));
+
IntRect result = enclosingIntRect(temp);
+
+ // Finally, clip the result to the foreground (this includes the object's
+ // border which does not scroll).
+ IntRect clip(aLayer->foregroundClip());
+ clip.move(position.x(), position.y());
+ result.intersect(clip);
+
DBG_NAV_LOGD("root=%p aLayer=%p [%d]"
- " bounds=(%d,%d,w=%d,h=%d) pos=(%g,%g) trans=(%g,%g)"
- " result=(%d,%d,w=%d,h=%d) offset=(%d,%d)",
+ " bounds=(%d,%d,w=%d,h=%d) trans=(%g,%g)"
+ " pos=(%f,%f)"
+ " offset=(%d,%d) clip=(%d,%d,w=%d,h=%d)"
+ " scroll=(%d,%d) origScroll=(%d,%d)"
+ " result=(%d,%d,w=%d,h=%d)",
root, aLayer, aLayer->uniqueId(),
bounds.x(), bounds.y(), bounds.width(), bounds.height(),
- position.x(), position.y(), translation.x(), translation.y(),
- result.x(), result.y(), result.width(), result.height(),
- mOffset.x(), mOffset.y());
- result.move(-mOffset.x(), -mOffset.y());
+ translation.x(), translation.y(), position.x(), position.y(),
+ mOffset.x(), mOffset.y(),
+ clip.x(), clip.y(), clip.width(), clip.height(),
+ SkScalarRound(scroll.fX), SkScalarRound(scroll.fY),
+ mScrollOffset.x(), mScrollOffset.y(),
+ result.x(), result.y(), result.width(), result.height());
return result;
}
+IntRect CachedLayer::unadjustBounds(const LayerAndroid* root,
+ const IntRect& bounds) const
+{
+ const LayerAndroid* aLayer = layer(root);
+ if (!aLayer)
+ return bounds;
+
+ IntRect temp = bounds;
+ // Remove the new position (i.e. fixed position elements).
+ const FloatPoint& position = aLayer->getPosition();
+ temp.move(-position.x(), -position.y());
+
+ // Remove any layer translation.
+ const FloatPoint& translation = aLayer->translation();
+ temp.move(-translation.x(), -translation.y());
+
+ // Move the bounds by the internal scroll position.
+ const SkPoint& scroll = aLayer->scrollPosition();
+ temp.move(SkScalarRound(scroll.fX), SkScalarRound(scroll.fY));
+
+ // Move it back to the original offset.
+ temp.move(mOffset.x(), mOffset.y());
+
+ // Move the bounds by the original scroll.
+ temp.move(-mScrollOffset.x(), -mScrollOffset.y());
+ return temp;
+}
+
const LayerAndroid* CachedLayer::layer(const LayerAndroid* root) const
{
if (!root || mLayer)
@@ -71,10 +127,34 @@ const LayerAndroid* CachedLayer::layer(const LayerAndroid* root) const
}
// return bounds relative to enclosing layer as recorded when walking the dom
-IntRect CachedLayer::localBounds(const IntRect& bounds) const
+IntRect CachedLayer::localBounds(const LayerAndroid* root,
+ const IntRect& bounds) const
{
IntRect temp = bounds;
+ // Remove the original offset from the bounds.
temp.move(-mOffset.x(), -mOffset.y());
+
+ // We add in the original scroll position in order to position the node
+ // relative to the current internal scroll position.
+ temp.move(mScrollOffset.x(), mScrollOffset.y());
+
+ const LayerAndroid* aLayer = layer(root);
+ if (aLayer) {
+ // Move the bounds by the scroll position of the layer.
+ const SkPoint& scroll = aLayer->scrollPosition();
+ temp.move(SkScalarToFloat(-scroll.fX), SkScalarToFloat(-scroll.fY));
+
+ // Clip by the layer's foreground bounds. Since the bounds have
+ // already be moved local to the layer, no need to move the foreground
+ // clip.
+ temp.intersect(IntRect(aLayer->foregroundClip()));
+ }
+
+ DBG_NAV_LOGD("bounds=(%d,%d,w=%d,h=%d) offset=(%d,%d)"
+ " result=(%d,%d,w=%d,h=%d)", bounds.x(), bounds.y(),
+ bounds.width(), bounds.height(), mOffset.x(), mOffset.y(),
+ temp.x(), temp.y(), temp.width(), temp.height());
+
return temp;
}