Commit 11434673 authored by tommycli@chromium.org's avatar tommycli@chromium.org

Blink: Pass 'unobscured' rect to WebPlugins.

This is to enable better throttling heuristics for plugins.

The 'unobscured' rect of a plugin is the visible portion of the plugin. It is the same as the 'clip' rect, except it is not clipped to the root window viewport.

That is to say - this still works for below-the-fold-plugins.

BUG=468142

Review URL: https://codereview.chromium.org/1033603007

git-svn-id: svn://svn.chromium.org/blink/trunk@192708 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 88cd64fb
......@@ -2164,12 +2164,17 @@ IntRect FrameView::windowClipRect(IncludeScrollbarsInRect scrollbarInclusion) co
HTMLFrameOwnerElement* ownerElement = m_frame->deprecatedLocalOwner();
FrameView* parentView = ownerElement->document().view();
if (parentView)
clipRect.intersect(parentView->windowClipRectForFrameOwner(ownerElement));
clipRect.intersect(parentView->clipRectsForFrameOwner(ownerElement, nullptr));
return clipRect;
}
IntRect FrameView::windowClipRectForFrameOwner(const HTMLFrameOwnerElement* ownerElement) const
IntRect FrameView::clipRectsForFrameOwner(const HTMLFrameOwnerElement* ownerElement, IntRect* unobscuredRect) const
{
ASSERT(ownerElement);
if (unobscuredRect)
*unobscuredRect = IntRect();
// The renderer can sometimes be null when style="display:none" interacts
// with external content and plugins.
if (!ownerElement->layoutObject())
......@@ -2185,8 +2190,18 @@ IntRect FrameView::windowClipRectForFrameOwner(const HTMLFrameOwnerElement* owne
DisableCompositingQueryAsserts disabler;
// Apply the clip from the layer.
IntRect clipRect = contentsToRootFrame(pixelSnappedIntRect(enclosingLayer->clipper().childrenClipRect()));
return intersection(clipRect, windowClipRect());
IntRect elementRect = contentsToRootFrame(pixelSnappedIntRect(enclosingLayer->clipper().childrenClipRect()));
if (unobscuredRect) {
*unobscuredRect = elementRect;
// If element is not in root frame, clip to the local frame.
// FIXME: Do we need to do this for remote frames?
if (m_frame->deprecatedLocalOwner())
unobscuredRect->intersect(contentsToRootFrame(visibleContentRect()));
}
return intersection(elementRect, windowClipRect());
}
bool FrameView::shouldUseIntegerScrollOffset() const
......
......@@ -154,7 +154,8 @@ public:
void adjustViewSize();
IntRect windowClipRectForFrameOwner(const HTMLFrameOwnerElement*) const;
// |unobscuredRect| receives the clip rect that is not clipped to the root window. It may be nullptr.
IntRect clipRectsForFrameOwner(const HTMLFrameOwnerElement*, IntRect* unobscuredRect) const;
float visibleContentScaleFactor() const { return m_visibleContentScaleFactor; }
void setVisibleContentScaleFactor(float);
......
......@@ -419,11 +419,11 @@ void WebPluginContainerImpl::reportGeometry()
if (!parent() || !m_element->layoutObject())
return;
IntRect windowRect, clipRect;
IntRect windowRect, clipRect, unobscuredRect;
Vector<IntRect> cutOutRects;
calculateGeometry(frameRect(), windowRect, clipRect, cutOutRects);
calculateGeometry(windowRect, clipRect, unobscuredRect, cutOutRects);
m_webPlugin->updateGeometry(windowRect, clipRect, cutOutRects, isVisible());
m_webPlugin->updateGeometry(windowRect, clipRect, unobscuredRect, cutOutRects, isVisible());
if (m_scrollbarGroup) {
m_scrollbarGroup->scrollAnimator()->contentsResized();
......@@ -977,28 +977,13 @@ void WebPluginContainerImpl::focusPlugin()
containingFrame.document()->setFocusedElement(m_element);
}
void WebPluginContainerImpl::calculateGeometry(const IntRect& frameRect,
IntRect& windowRect,
IntRect& clipRect,
Vector<IntRect>& cutOutRects)
void WebPluginContainerImpl::calculateGeometry(IntRect& windowRect, IntRect& clipRect, IntRect& unobscuredRect, Vector<IntRect>& cutOutRects)
{
windowRect = toFrameView(parent())->contentsToRootFrame(frameRect);
windowRect = toFrameView(parent())->contentsToRootFrame(frameRect());
// Calculate a clip-rect so that we don't overlap the scrollbars, etc.
clipRect = windowClipRect();
clipRect.move(-windowRect.x(), -windowRect.y());
getPluginOcclusions(m_element, this->parent(), frameRect, cutOutRects);
// Convert to the plugin position.
for (size_t i = 0; i < cutOutRects.size(); i++)
cutOutRects[i].move(-frameRect.x(), -frameRect.y());
}
IntRect WebPluginContainerImpl::windowClipRect() const
{
// Start by clipping to our bounds.
IntRect clipRect =
convertToContainingWindow(IntRect(0, 0, width(), height()));
clipRect = convertToContainingWindow(IntRect(0, 0, width(), height()));
unobscuredRect = clipRect;
// document().layoutView() can be 0 when we receive messages from the
// plugins while we are destroying a frame.
......@@ -1006,11 +991,19 @@ IntRect WebPluginContainerImpl::windowClipRect() const
if (m_element->layoutObject()->document().layoutView()) {
// Take our element and get the clip rect from the enclosing layer and
// frame view.
clipRect.intersect(
m_element->document().view()->windowClipRectForFrameOwner(m_element));
IntRect elementUnobscuredRect;
IntRect elementWindowClipRect = m_element->document().view()->clipRectsForFrameOwner(m_element, &elementUnobscuredRect);
clipRect.intersect(elementWindowClipRect);
unobscuredRect.intersect(elementUnobscuredRect);
}
return clipRect;
clipRect.move(-windowRect.x(), -windowRect.y());
unobscuredRect.move(-windowRect.x(), -windowRect.y());
getPluginOcclusions(m_element, this->parent(), frameRect(), cutOutRects);
// Convert to the plugin position.
for (size_t i = 0; i < cutOutRects.size(); i++)
cutOutRects[i].move(-frameRect().x(), -frameRect().y());
}
bool WebPluginContainerImpl::pluginShouldPersist() const
......
......@@ -188,11 +188,10 @@ private:
void focusPlugin();
void calculateGeometry(
const IntRect& frameRect,
IntRect& windowRect,
IntRect& clipRect,
IntRect& unobscuredRect,
Vector<IntRect>& cutOutRects);
IntRect windowClipRect() const;
void windowCutOutRects(
const IntRect& frameRect,
Vector<IntRect>& cutOutRects);
......
......@@ -53,7 +53,7 @@ public:
virtual NPObject* scriptableObject() override { return 0; }
virtual bool canProcessDrag() const override { return false; }
virtual void paint(WebCanvas*, const WebRect&) override { }
virtual void updateGeometry(const WebRect& frameRect, const WebRect& clipRect, const WebVector<WebRect>& cutOutsRects, bool isVisible) override { }
virtual void updateGeometry(const WebRect& clientRect, const WebRect& clipRect, const WebRect& windowClipRect, const WebVector<WebRect>& cutOutsRects, bool isVisible) override { }
virtual void updateFocus(bool, WebFocusType) override { }
virtual void updateVisibility(bool) override { }
virtual bool acceptsInputEvents() override { return true; }
......
......@@ -89,10 +89,19 @@ public:
virtual void paint(WebCanvas*, const WebRect&) = 0;
// DEPRECATED. TODO(tommycli): Remove once embedders migrate to the new interface.
virtual void updateGeometry(
const WebRect& windowRect, const WebRect& clipRect,
const WebVector<WebRect>& cutOutsRects, bool isVisible) { }
// Coordinates are relative to the containing window.
virtual void updateGeometry(
const WebRect& frameRect, const WebRect& clipRect,
const WebVector<WebRect>& cutOutsRects, bool isVisible) = 0;
const WebRect& windowRect, const WebRect& clipRect,
const WebRect& unobscuredRect, const WebVector<WebRect>& cutOutsRects,
bool isVisible) {
// TODO(tommycli): This default implementation calls the old, deprecated interface. This method should be pure virtual after the deprecated interface is removed.
updateGeometry(windowRect, clipRect, cutOutsRects, isVisible);
}
virtual void updateFocus(bool focused, WebFocusType) = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment