OSDN Git Service

Ensure plugin content does not shift when gaining focus.
authorDerek Sollenberger <djsollen@google.com>
Wed, 2 Mar 2011 20:44:58 +0000 (15:44 -0500)
committerDerek Sollenberger <djsollen@google.com>
Wed, 2 Mar 2011 20:50:45 +0000 (15:50 -0500)
bug: 3477581
Change-Id: Ia7bbaaca405db33dbefaa8f6f00e9250580e5f7b

WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp
WebCore/platform/graphics/android/MediaLayer.cpp
WebCore/platform/graphics/android/MediaLayer.h

index 48badf8..7963ae0 100644 (file)
@@ -25,6 +25,7 @@
 #include "GraphicsContext.h"
 #include "Image.h"
 #include "Length.h"
+#include "MediaLayer.h"
 #include "PlatformBridge.h"
 #include "PlatformGraphicsContext.h"
 #include "RenderLayerBacking.h"
@@ -321,6 +322,19 @@ void GraphicsLayerAndroid::setSize(const FloatSize& size)
         return;
     MLOG("(%x) setSize (%.2f,%.2f)", this, size.width(), size.height());
     GraphicsLayer::setSize(size);
+
+    // If it is a media layer the size may have changed as a result of the media
+    // element (e.g. plugin) gaining focus. Therefore, we must sync the size of
+    // the focus' outline so that our UI thread can draw accordingly.
+    if (m_contentLayer->isMedia() && m_client) {
+        RenderLayer* layer = renderLayerFromClient(m_client);
+        RenderBox* box = layer->renderBox();
+        int outline = box->view()->maximalOutlineSize();
+        static_cast<MediaLayer*>(m_contentLayer)->setOutlineSize(outline);
+        LOG("Media Outline: %d %p %p %p", outline, m_client, layer, box);
+        LOG("Media Size: %g,%g", size.width(), size.height());
+    }
+
     m_contentLayer->setSize(size.width(), size.height());
     askForSync();
 }
index 9bc2a3e..fbcd494 100644 (file)
@@ -49,6 +49,7 @@ MediaLayer::MediaLayer(jobject weakWebViewRef) : LayerAndroid(false)
 
     m_currentTextureInfo = 0;
     m_isContentInverted = false;
+    m_outlineSize = 0;
     XLOG("Creating Media Layer %p", this);
 }
 
@@ -61,6 +62,7 @@ MediaLayer::MediaLayer(const MediaLayer& layer) : LayerAndroid(layer)
 
     m_currentTextureInfo = 0;
     m_isContentInverted = layer.m_isContentInverted;
+    m_outlineSize = layer.m_outlineSize;
     XLOG("Creating Media Layer Copy %p -> %p", &layer, this);
 }
 
@@ -73,7 +75,13 @@ MediaLayer::~MediaLayer()
 
 bool MediaLayer::drawGL(SkMatrix& matrix)
 {
-    TilesManager::instance()->shader()->clip(drawClip());
+    // when the plugin gains focus webkit applies an outline to the widget,
+    // which causes the layer to expand to accommodate the outline. Therefore,
+    // we shrink the clip by the outline's dimensions to ensure the plugin does
+    // not draw outside of its bounds.
+    FloatRect clip = drawClip();
+    clip.inflate(-m_outlineSize);
+    TilesManager::instance()->shader()->clip(clip);
 
     // check to see if we need to create a video texture
     m_videoTexture->initNativeWindowIfNeeded();
index 15bd6d8..203ef93 100644 (file)
@@ -49,6 +49,7 @@ public:
     TextureInfo* getCurrentTextureInfo() const { return m_currentTextureInfo; }
 
     void invertContents(bool invertContent) { m_isContentInverted = invertContent; }
+    void setOutlineSize(int size) { m_outlineSize = size; }
 
     // functions to manipulate secondary layers for video playback
     ANativeWindow* acquireNativeWindowForVideo();
@@ -62,6 +63,7 @@ private:
     TextureInfo* m_currentTextureInfo;
 
     bool m_isContentInverted;
+    int m_outlineSize;
 
     // Video texture variables
     VideoTexture* m_videoTexture;