Title: [143680] trunk/Source/WebCore
Revision
143680
Author
[email protected]
Date
2013-02-21 18:48:49 -0800 (Thu, 21 Feb 2013)

Log Message

Better sizing model for Snapshotted plugins
https://bugs.webkit.org/show_bug.cgi?id=110541

Reviewed by Simon Fraser.

Clarify the way we apply sizing rules to snapshotted plug-ins. In
testing we've found that plug-ins smaller than 40px in either
dimension should never be frozen. Also, larger plugins should
be explicitly marked, because often they are the single dominant
element on the page.

As a drive-by, I removed the flag that indicated whether or not
the label should show automatically. It wasn't being used. This is
all determined from the shadow root and its CSS now.

* html/HTMLPlugInImageElement.cpp:
(WebCore::HTMLPlugInImageElement::HTMLPlugInImageElement): New values for size thresholds.
(WebCore::HTMLPlugInImageElement::createRenderer): Remove call to setShouldShowSnapshotLabelAutomatically.
(WebCore::classNameForShadowRoot): Remove logging and clearly assign sizing classes.
(WebCore::HTMLPlugInImageElement::updateSnapshotInfo): We don't need the page size any more.
(WebCore::HTMLPlugInImageElement::subframeLoaderWillCreatePlugIn): Use new constant names.
* html/HTMLPlugInImageElement.h:
(HTMLPlugInImageElement): Remove setShouldShowSnapshotLabelAutomatically.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (143679 => 143680)


--- trunk/Source/WebCore/ChangeLog	2013-02-22 02:48:09 UTC (rev 143679)
+++ trunk/Source/WebCore/ChangeLog	2013-02-22 02:48:49 UTC (rev 143680)
@@ -1,3 +1,29 @@
+2013-02-21  Dean Jackson  <[email protected]>
+
+        Better sizing model for Snapshotted plugins
+        https://bugs.webkit.org/show_bug.cgi?id=110541
+
+        Reviewed by Simon Fraser.
+
+        Clarify the way we apply sizing rules to snapshotted plug-ins. In
+        testing we've found that plug-ins smaller than 40px in either
+        dimension should never be frozen. Also, larger plugins should
+        be explicitly marked, because often they are the single dominant
+        element on the page.
+
+        As a drive-by, I removed the flag that indicated whether or not
+        the label should show automatically. It wasn't being used. This is
+        all determined from the shadow root and its CSS now.
+
+        * html/HTMLPlugInImageElement.cpp:
+        (WebCore::HTMLPlugInImageElement::HTMLPlugInImageElement): New values for size thresholds.
+        (WebCore::HTMLPlugInImageElement::createRenderer): Remove call to setShouldShowSnapshotLabelAutomatically.
+        (WebCore::classNameForShadowRoot): Remove logging and clearly assign sizing classes.
+        (WebCore::HTMLPlugInImageElement::updateSnapshotInfo): We don't need the page size any more.
+        (WebCore::HTMLPlugInImageElement::subframeLoaderWillCreatePlugIn): Use new constant names.
+        * html/HTMLPlugInImageElement.h:
+        (HTMLPlugInImageElement): Remove setShouldShowSnapshotLabelAutomatically.
+
 2013-02-21  Benjamin Poulain  <[email protected]>
 
         Fix the build after r143664.

Modified: trunk/Source/WebCore/html/HTMLPlugInImageElement.cpp (143679 => 143680)


--- trunk/Source/WebCore/html/HTMLPlugInImageElement.cpp	2013-02-22 02:48:09 UTC (rev 143679)
+++ trunk/Source/WebCore/html/HTMLPlugInImageElement.cpp	2013-02-22 02:48:49 UTC (rev 143680)
@@ -53,13 +53,10 @@
 
 using namespace HTMLNames;
 
-static const int autoStartPlugInSizeDimensionThreshold = 1;
-static const int autoShowLabelSizeWidthThreshold = 400;
-static const int autoShowLabelSizeHeightThreshold = 300;
-
 static const int sizingTinyDimensionThreshold = 40;
 static const int sizingSmallWidthThreshold = 250;
-static const int sizingMediumWidthThreshold = 600;
+static const int sizingMediumWidthThreshold = 450;
+static const int sizingMediumHeightThreshold = 300;
 
 // This delay should not exceed the snapshot delay in PluginView.cpp
 static const double simulatedMouseClickTimerDelay = .75;
@@ -73,7 +70,6 @@
     , m_needsWidgetUpdate(!createdByParser)
     , m_shouldPreferPlugInsForImages(preferPlugInsForImagesOption == ShouldPreferPlugInsForImages)
     , m_needsDocumentActivationCallbacks(false)
-    , m_shouldShowSnapshotLabelAutomatically(false)
     , m_simulatedMouseClickTimer(this, &HTMLPlugInImageElement::simulatedMouseClickTimerFired, simulatedMouseClickTimerDelay)
     , m_swapRendererTimer(this, &HTMLPlugInImageElement::swapRendererTimerFired)
 {
@@ -157,8 +153,6 @@
     if (displayState() == DisplayingSnapshot) {
         RenderSnapshottedPlugIn* renderSnapshottedPlugIn = new (arena) RenderSnapshottedPlugIn(this);
         renderSnapshottedPlugIn->updateSnapshot(m_snapshotImage);
-        if (m_shouldShowSnapshotLabelAutomatically)
-            renderSnapshottedPlugIn->setShouldShowLabelAutomatically();
         return renderSnapshottedPlugIn;
     }
 
@@ -296,34 +290,25 @@
     }
 }
 
-static AtomicString classNameForShadowRootSize(const IntSize& viewContentsSize, const Node* node)
+static AtomicString classNameForShadowRoot(const Node* node)
 {
     DEFINE_STATIC_LOCAL(const AtomicString, plugInTinySizeClassName, ("tiny", AtomicString::ConstructFromLiteral));
     DEFINE_STATIC_LOCAL(const AtomicString, plugInSmallSizeClassName, ("small", AtomicString::ConstructFromLiteral));
     DEFINE_STATIC_LOCAL(const AtomicString, plugInMediumSizeClassName, ("medium", AtomicString::ConstructFromLiteral));
     DEFINE_STATIC_LOCAL(const AtomicString, plugInLargeSizeClassName, ("large", AtomicString::ConstructFromLiteral));
 
-    LayoutRect plugInClipRect = node->renderer()->absoluteClippedOverflowRect();
-    LayoutRect viewContentsRect(LayoutPoint::zero(), LayoutSize(viewContentsSize));
-    if (!viewContentsRect.contains(plugInClipRect)) {
-        LOG(Plugins, "%p Plug-in rect: (%d %d, %d %d) not contained in document of size %d %d", node, plugInClipRect.pixelSnappedX(), plugInClipRect.pixelSnappedY(), plugInClipRect.pixelSnappedWidth(), plugInClipRect.pixelSnappedHeight(), viewContentsSize.width(), viewContentsSize.height());
-        return nullAtom;
-    }
+    RenderBox* renderBox = static_cast<RenderBox*>(node->renderer());
+    LayoutUnit width = renderBox->contentWidth();
+    LayoutUnit height = renderBox->contentHeight();
 
-    if (plugInClipRect.pixelSnappedWidth() < sizingTinyDimensionThreshold || plugInClipRect.pixelSnappedHeight() < sizingTinyDimensionThreshold) {
-        LOG(Plugins, "%p Tiny Size: %d %d", node, plugInClipRect.pixelSnappedWidth(), plugInClipRect.pixelSnappedHeight());
+    if (width < sizingTinyDimensionThreshold || height < sizingTinyDimensionThreshold)
         return plugInTinySizeClassName;
-    }
 
-    if (plugInClipRect.pixelSnappedWidth() < sizingSmallWidthThreshold) {
-        LOG(Plugins, "%p Small Size: %d %d", node, plugInClipRect.pixelSnappedWidth(), plugInClipRect.pixelSnappedHeight());
+    if (width < sizingSmallWidthThreshold)
         return plugInSmallSizeClassName;
-    }
 
-    if (plugInClipRect.pixelSnappedWidth() < sizingMediumWidthThreshold) {
-        LOG(Plugins, "%p Medium Size: %d %d", node, plugInClipRect.pixelSnappedWidth(), plugInClipRect.pixelSnappedHeight());
+    if (width < sizingMediumWidthThreshold || height < sizingMediumHeightThreshold)
         return plugInMediumSizeClassName;
-    }
 
     return plugInLargeSizeClassName;
 }
@@ -335,7 +320,7 @@
         return;
 
     Element* shadowContainer = static_cast<Element*>(root->firstChild());
-    shadowContainer->setAttribute(classAttr, classNameForShadowRootSize(document()->page()->mainFrame()->view()->contentsSize(), this));   
+    shadowContainer->setAttribute(classAttr, classNameForShadowRoot(this));
 }
 
 void HTMLPlugInImageElement::didAddUserAgentShadowRoot(ShadowRoot* root)
@@ -419,25 +404,6 @@
     m_pendingClickEventFromSnapshot = nullptr;
 }
 
-static bool shouldPlugInShowLabelAutomatically(const IntSize& viewContentsSize, const Node* node)
-{
-    LayoutRect plugInClipRect = node->renderer()->absoluteClippedOverflowRect();
-    LayoutRect viewContentsRect(LayoutPoint::zero(), LayoutSize(viewContentsSize));
-    if (!viewContentsRect.contains(plugInClipRect)) {
-        LOG(Plugins, "%p Plug-in rect: (%d %d, %d %d) not contained in document of size %d %d", node, plugInClipRect.pixelSnappedX(), plugInClipRect.pixelSnappedY(), plugInClipRect.pixelSnappedWidth(), plugInClipRect.pixelSnappedHeight(), viewContentsSize.width(), viewContentsSize.height());
-        return false;
-    }
-
-    if (plugInClipRect.pixelSnappedWidth() < autoShowLabelSizeWidthThreshold
-        || plugInClipRect.pixelSnappedHeight() < autoShowLabelSizeHeightThreshold) {
-        LOG(Plugins, "%p Size: %d %d", node, plugInClipRect.pixelSnappedWidth(), plugInClipRect.pixelSnappedHeight());
-        return false;
-    }
-
-    LOG(Plugins, "%p Auto-show label", node);
-    return true;
-}
-
 void HTMLPlugInImageElement::subframeLoaderWillCreatePlugIn(const KURL& url)
 {
     if (!document()->page()
@@ -457,7 +423,7 @@
     LayoutRect rect = toRenderEmbeddedObject(renderer())->contentBoxRect();
     int width = rect.width();
     int height = rect.height();
-    if (!width || !height || (width <= autoStartPlugInSizeDimensionThreshold && height <= autoStartPlugInSizeDimensionThreshold)) {
+    if (!width || !height || (width <= sizingTinyDimensionThreshold || height <= sizingTinyDimensionThreshold)) {
         LOG(Plugins, "%p Plug-in is %dx%d, set to play", this, width, height);
         return;
     }
@@ -476,9 +442,6 @@
         return;
     }
 
-    if (shouldPlugInShowLabelAutomatically(document()->page()->mainFrame()->view()->contentsSize(), this))
-        setShouldShowSnapshotLabelAutomatically();
-
     LOG(Plugins, "%p Plug-in hash %x is %dx%d, origin is not auto-start, set to wait for snapshot", this, m_plugInOriginHash, width, height);
     // We may have got to this point by restarting a snapshotted plug-in, in which case we don't want to
     // reset the display state.

Modified: trunk/Source/WebCore/html/HTMLPlugInImageElement.h (143679 => 143680)


--- trunk/Source/WebCore/html/HTMLPlugInImageElement.h	2013-02-22 02:48:09 UTC (rev 143679)
+++ trunk/Source/WebCore/html/HTMLPlugInImageElement.h	2013-02-22 02:48:49 UTC (rev 143680)
@@ -111,12 +111,9 @@
 
     void swapRendererTimerFired(Timer<HTMLPlugInImageElement>*);
 
-    void setShouldShowSnapshotLabelAutomatically() { m_shouldShowSnapshotLabelAutomatically = true; }
-
     bool m_needsWidgetUpdate;
     bool m_shouldPreferPlugInsForImages;
     bool m_needsDocumentActivationCallbacks;
-    bool m_shouldShowSnapshotLabelAutomatically;
     RefPtr<RenderStyle> m_customStyleForPageCache;
     RefPtr<MouseEvent> m_pendingClickEventFromSnapshot;
     DeferrableOneShotTimer<HTMLPlugInImageElement> m_simulatedMouseClickTimer;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to