Diff
Modified: trunk/Source/WebKit/chromium/ChangeLog (101758 => 101759)
--- trunk/Source/WebKit/chromium/ChangeLog 2011-12-02 08:55:48 UTC (rev 101758)
+++ trunk/Source/WebKit/chromium/ChangeLog 2011-12-02 08:58:21 UTC (rev 101759)
@@ -1,3 +1,46 @@
+2011-12-01 David Levin <[email protected]>
+
+ [chromium] Add WebKit API's to support the autosize algorithm in renderer process.
+ https://bugs.webkit.org/show_bug.cgi?id=73058
+
+ Reviewed by Darin Fisher.
+
+ * public/WebView.h: Expose the auto-resize method.
+ * public/WebWidgetClient.h:
+ (WebKit::WebWidgetClient::didAutoResize):
+ * src/WebFrameImpl.cpp:
+ (WebKit::WebFrameImpl::createFrameView): Set the auto-resize
+ state on the new view.
+ * src/WebViewImpl.cpp:
+ (WebKit::WebViewImpl::WebViewImpl):
+ (WebKit::WebViewImpl::resize): Extracted sendResizeEventAndRepaint, so
+ that it can be used by layoutUpdated.
+ (WebKit::WebViewImpl::queueBothResizeEventAndPaint): Ditto.
+ (WebKit::WebViewImpl::hasHorizontalScrollbar): Added for testing purposes.
+ (WebKit::WebViewImpl::hasVerticalScrollbar): Ditto.
+ (WebKit::WebViewImpl::enableAutoResizeMode): Set-up auto-resize.
+ (WebKit::WebViewImpl::layoutUpdated): Handle the auto-resize case by
+ sending events and invalidation.
+ * src/WebViewImpl.h: Expose the aut-reosize information.
+ (WebKit::WebViewImpl::shouldAutoResize):
+ (WebKit::WebViewImpl::minAutoSize):
+ (WebKit::WebViewImpl::maxAutoSize):
+ * tests/FrameTestHelpers.cpp:
+ (WebKit::FrameTestHelpers::createWebViewAndLoad): Added the ability to
+ specify the WebViewClient.
+ * tests/FrameTestHelpers.h: Ditto.
+ * tests/WebViewTest.cpp: Added a simple test for auto-resize.
+ (WebKit::TestData::setWebView):
+ (WebKit::TestData::setSize): Capture the new size.
+ (WebKit::TestData::hasHorizontalScrollbar):
+ (WebKit::TestData::hasVerticalScrollbar):
+ (WebKit::TestData::width):
+ (WebKit::TestData::height):
+ (WebKit::AutoResizeWebViewClient::didAutoResize): Handle the resize event.
+ (WebKit::AutoResizeWebViewClient::testData):
+ (WebKit::TEST_F): The actual test.
+ * tests/data/specify_size.html: Added.
+
2011-12-02 Xiyuan Xia <[email protected]>
[Chromium] Support adding/removing page overlay to WebView
Modified: trunk/Source/WebKit/chromium/public/WebView.h (101758 => 101759)
--- trunk/Source/WebKit/chromium/public/WebView.h 2011-12-02 08:55:48 UTC (rev 101758)
+++ trunk/Source/WebKit/chromium/public/WebView.h 2011-12-02 08:58:21 UTC (rev 101759)
@@ -250,6 +250,16 @@
virtual void setFixedLayoutSize(const WebSize&) = 0;
+ // Auto-Resize -----------------------------------------------------------
+
+ // In auto-resize mode, the view is automatically adjusted to fit the html
+ // content within the given bounds.
+ virtual void enableAutoResizeMode(
+ bool enable,
+ const WebSize& minSize,
+ const WebSize& maxSize) = 0;
+
+
// Media ---------------------------------------------------------------
// Performs the specified action on the node at the given location.
Modified: trunk/Source/WebKit/chromium/public/WebWidgetClient.h (101758 => 101759)
--- trunk/Source/WebKit/chromium/public/WebWidgetClient.h 2011-12-02 08:55:48 UTC (rev 101758)
+++ trunk/Source/WebKit/chromium/public/WebWidgetClient.h 2011-12-02 08:58:21 UTC (rev 101759)
@@ -41,6 +41,7 @@
class WebString;
class WebWidget;
struct WebCursorInfo;
+struct WebSize;
class WebWidgetClient {
public:
@@ -51,6 +52,9 @@
// scrolled by the specified dx and dy amounts.
virtual void didScrollRect(int dx, int dy, const WebRect& clipRect) { }
+ // Called when the Widget has changed size as a result of an auto-resize.
+ virtual void didAutoResize(const WebSize& newSize) { }
+
// Called when the compositor is enabled or disabled.
// The WebCompositor identifier can be used on the compositor thread to get access
// to the WebCompositor instance associated with this WebWidget.
Modified: trunk/Source/WebKit/chromium/src/WebFrameImpl.cpp (101758 => 101759)
--- trunk/Source/WebKit/chromium/src/WebFrameImpl.cpp 2011-12-02 08:55:48 UTC (rev 101758)
+++ trunk/Source/WebKit/chromium/src/WebFrameImpl.cpp 2011-12-02 08:58:21 UTC (rev 101759)
@@ -2083,6 +2083,8 @@
WebViewImpl* webView = viewImpl();
m_frame->createView(webView->size(), Color::white, webView->isTransparent(), webView->fixedLayoutSize(), webView->isFixedLayoutModeEnabled());
+ if (webView->shouldAutoResize())
+ m_frame->view()->enableAutoSizeMode(true, webView->minAutoSize(), webView->maxAutoSize());
#if ENABLE(GESTURE_RECOGNIZER)
webView->resetGestureRecognizer();
Modified: trunk/Source/WebKit/chromium/src/WebViewImpl.cpp (101758 => 101759)
--- trunk/Source/WebKit/chromium/src/WebViewImpl.cpp 2011-12-02 08:55:48 UTC (rev 101758)
+++ trunk/Source/WebKit/chromium/src/WebViewImpl.cpp 2011-12-02 08:58:21 UTC (rev 101759)
@@ -56,6 +56,7 @@
#include "Extensions3D.h"
#include "FocusController.h"
#include "FontDescription.h"
+#include "Frame.h"
#include "FrameLoader.h"
#include "FrameSelection.h"
#include "FrameTree.h"
@@ -334,6 +335,7 @@
, m_dragClientImpl(this)
, m_editorClientImpl(this)
, m_inspectorClientImpl(this)
+ , m_shouldAutoResize(false)
, m_observedNewNavigation(false)
#ifndef NDEBUG
, m_newNavigationLoader(0)
@@ -1041,25 +1043,15 @@
void WebViewImpl::resize(const WebSize& newSize)
{
+ ASSERT(!m_shouldAutoResize);
if (m_size == newSize)
return;
m_size = newSize;
- if (mainFrameImpl()->frameView()) {
+ if (mainFrameImpl()->frameView())
mainFrameImpl()->frameView()->resize(m_size.width, m_size.height);
- mainFrameImpl()->frame()->eventHandler()->sendResizeEvent();
- }
- if (m_client) {
- if (isAcceleratedCompositingActive()) {
-#if USE(ACCELERATED_COMPOSITING)
- updateLayerTreeViewport();
-#endif
- } else {
- WebRect damagedRect(0, 0, m_size.width, m_size.height);
- m_client->didInvalidateRect(damagedRect);
- }
- }
+ sendResizeEventAndRepaint();
}
void WebViewImpl::willEndLiveResize()
@@ -1299,6 +1291,16 @@
m_client->exitFullScreen();
}
+bool WebViewImpl::hasHorizontalScrollbar()
+{
+ return mainFrameImpl()->frameView()->horizontalScrollbar();
+}
+
+bool WebViewImpl::hasVerticalScrollbar()
+{
+ return mainFrameImpl()->frameView()->verticalScrollbar();
+}
+
const WebInputEvent* WebViewImpl::m_currentInputEvent = 0;
bool WebViewImpl::handleInputEvent(const WebInputEvent& inputEvent)
@@ -2050,6 +2052,17 @@
#endif
}
+void WebViewImpl::enableAutoResizeMode(bool enable, const WebSize& minSize, const WebSize& maxSize)
+{
+ m_shouldAutoResize = enable;
+ m_minAutoSize = minSize;
+ m_maxAutoSize = maxSize;
+ if (!mainFrameImpl() || !mainFrameImpl()->frame() || !mainFrameImpl()->frame()->view())
+ return;
+
+ mainFrameImpl()->frame()->view()->enableAutoSizeMode(m_shouldAutoResize, m_minAutoSize, m_maxAutoSize);
+}
+
void WebViewImpl::setPageScaleFactorLimits(float minPageScale, float maxPageScale)
{
m_minimumPageScaleFactor = min(max(minPageScale, minPageScaleFactor), maxPageScaleFactor) * deviceScaleFactor();
@@ -2295,6 +2308,25 @@
return m_dragOperation;
}
+void WebViewImpl::sendResizeEventAndRepaint()
+{
+ if (mainFrameImpl()->frameView()) {
+ // Enqueues the resize event.
+ mainFrameImpl()->frame()->eventHandler()->sendResizeEvent();
+ }
+
+ if (m_client) {
+ if (isAcceleratedCompositingActive()) {
+#if USE(ACCELERATED_COMPOSITING)
+ updateLayerTreeViewport();
+#endif
+ } else {
+ WebRect damagedRect(0, 0, m_size.width, m_size.height);
+ m_client->didInvalidateRect(damagedRect);
+ }
+ }
+}
+
unsigned long WebViewImpl::createUniqueIdentifierForRequest()
{
if (m_page)
@@ -2548,6 +2580,15 @@
if (!m_client || webframe != mainFrameImpl())
return;
+ if (m_shouldAutoResize && mainFrameImpl()->frame() && mainFrameImpl()->frame()->view()) {
+ WebSize frameSize = mainFrameImpl()->frame()->view()->frameRect().size();
+ if (frameSize != m_size) {
+ m_size = frameSize;
+ m_client->didAutoResize(m_size);
+ sendResizeEventAndRepaint();
+ }
+ }
+
m_client->didUpdateLayout();
}
Modified: trunk/Source/WebKit/chromium/src/WebViewImpl.h (101758 => 101759)
--- trunk/Source/WebKit/chromium/src/WebViewImpl.h 2011-12-02 08:55:48 UTC (rev 101758)
+++ trunk/Source/WebKit/chromium/src/WebViewImpl.h 2011-12-02 08:58:21 UTC (rev 101759)
@@ -176,6 +176,10 @@
virtual void enableFixedLayoutMode(bool enable);
virtual WebSize fixedLayoutSize() const;
virtual void setFixedLayoutSize(const WebSize&);
+ virtual void enableAutoResizeMode(
+ bool enable,
+ const WebSize& minSize,
+ const WebSize& maxSize);
virtual void performMediaPlayerAction(
const WebMediaPlayerAction& action,
const WebPoint& location);
@@ -340,6 +344,21 @@
return m_contextMenuAllowed;
}
+ bool shouldAutoResize() const
+ {
+ return m_shouldAutoResize;
+ }
+
+ WebCore::IntSize minAutoSize() const
+ {
+ return m_minAutoSize;
+ }
+
+ WebCore::IntSize maxAutoSize() const
+ {
+ return m_maxAutoSize;
+ }
+
// Set the disposition for how this webview is to be initially shown.
void setInitialNavigationPolicy(WebNavigationPolicy policy)
{
@@ -437,6 +456,10 @@
void enterFullScreenForElement(WebCore::Element*);
void exitFullScreenForElement(WebCore::Element*);
+ // Exposed for testing purposes.
+ bool hasHorizontalScrollbar();
+ bool hasVerticalScrollbar();
+
private:
float computePageScaleFactorWithinLimits(float scale);
WebPoint clampOffsetAtScale(const WebPoint& offset, float scale);
@@ -479,6 +502,8 @@
const WebPoint& screenPoint,
DragAction);
+ void sendResizeEventAndRepaint();
+
#if USE(ACCELERATED_COMPOSITING)
void setIsAcceleratedCompositingActive(bool);
void doComposite();
@@ -499,6 +524,12 @@
InspectorClientImpl m_inspectorClientImpl;
WebSize m_size;
+ // If true, automatically resize the render view around its content.
+ bool m_shouldAutoResize;
+ // The lower bound on the size when auto-resizing.
+ WebCore::IntSize m_minAutoSize;
+ // The upper bound on the size when auto-resizing.
+ WebCore::IntSize m_maxAutoSize;
WebPoint m_lastMousePosition;
OwnPtr<WebCore::Page> m_page;
Modified: trunk/Source/WebKit/chromium/tests/FrameTestHelpers.cpp (101758 => 101759)
--- trunk/Source/WebKit/chromium/tests/FrameTestHelpers.cpp 2011-12-02 08:55:48 UTC (rev 101758)
+++ trunk/Source/WebKit/chromium/tests/FrameTestHelpers.cpp 2011-12-02 08:58:21 UTC (rev 101759)
@@ -84,11 +84,13 @@
return &client;
}
-WebView* createWebViewAndLoad(const std::string& url, bool enableJavascript, WebFrameClient* webFrameClient)
+WebView* createWebViewAndLoad(const std::string& url, bool enableJavascript, WebFrameClient* webFrameClient, WebViewClient* webViewClient)
{
if (!webFrameClient)
webFrameClient = defaultWebFrameClient();
- WebView* webView = WebView::create(defaultWebViewClient());
+ if (!webViewClient)
+ webViewClient = defaultWebViewClient();
+ WebView* webView = WebView::create(webViewClient);
webView->settings()->setJavaScriptEnabled(enableJavascript);
webView->initializeMainFrame(webFrameClient);
Modified: trunk/Source/WebKit/chromium/tests/FrameTestHelpers.h (101758 => 101759)
--- trunk/Source/WebKit/chromium/tests/FrameTestHelpers.h 2011-12-02 08:55:48 UTC (rev 101758)
+++ trunk/Source/WebKit/chromium/tests/FrameTestHelpers.h 2011-12-02 08:58:21 UTC (rev 101759)
@@ -38,6 +38,7 @@
class WebFrame;
class WebFrameClient;
class WebView;
+class WebViewClient;
namespace FrameTestHelpers {
@@ -45,7 +46,7 @@
void loadFrame(WebFrame*, const std::string& url);
-WebView* createWebViewAndLoad(const std::string& url, bool enableJavascript = false, WebFrameClient* = 0);
+WebView* createWebViewAndLoad(const std::string& url, bool enableJavascript = false, WebFrameClient* = 0, WebViewClient* = 0);
} // namespace FrameTestHelpers
} // namespace WebKit
Modified: trunk/Source/WebKit/chromium/tests/WebViewTest.cpp (101758 => 101759)
--- trunk/Source/WebKit/chromium/tests/WebViewTest.cpp 2011-12-02 08:55:48 UTC (rev 101758)
+++ trunk/Source/WebKit/chromium/tests/WebViewTest.cpp 2011-12-02 08:58:21 UTC (rev 101759)
@@ -33,10 +33,15 @@
#include "Document.h"
#include "FrameTestHelpers.h"
+#include "FrameView.h"
#include "HTMLDocument.h"
#include "WebDocument.h"
#include "WebFrame.h"
+#include "WebFrameClient.h"
#include "WebFrameImpl.h"
+#include "WebSize.h"
+#include "WebViewClient.h"
+#include "WebViewImpl.h"
#include <gtest/gtest.h>
#include <webkit/support/webkit_support.h>
@@ -44,6 +49,32 @@
namespace {
+class TestData {
+public:
+ void setWebView(WebView* webView) { m_webView = static_cast<WebViewImpl*>(webView); }
+ void setSize(const WebSize& newSize) { m_size = newSize; }
+ bool hasHorizontalScrollbar() const { return m_webView->hasHorizontalScrollbar(); }
+ bool hasVerticalScrollbar() const { return m_webView->hasVerticalScrollbar(); }
+ int width() const { return m_size.width; }
+ int height() const { return m_size.height; }
+
+private:
+ WebSize m_size;
+ WebViewImpl* m_webView;
+};
+
+class AutoResizeWebViewClient : public WebViewClient {
+public:
+ // WebViewClient methods
+ virtual void didAutoResize(const WebSize& newSize) { m_testData.setSize(newSize); }
+
+ // Local methods
+ TestData& testData() { return m_testData; }
+
+private:
+ TestData m_testData;
+};
+
class WebViewTest : public testing::Test {
public:
WebViewTest()
@@ -79,4 +110,35 @@
webView->close();
}
+TEST_F(WebViewTest, AutoResizeMinimumSize)
+{
+ AutoResizeWebViewClient client;
+ FrameTestHelpers::registerMockedURLLoad(m_baseURL, "specify_size.html");
+ WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "specify_size.html", true, 0, &client);
+ client.testData().setWebView(webView);
+ FrameTestHelpers::loadFrame(webView->mainFrame(), "_javascript_:document.getElementById('sizer').style.height = '56px';");
+ FrameTestHelpers::loadFrame(webView->mainFrame(), "_javascript_:document.getElementById('sizer').style.width = '91px';");
+
+ WebFrameImpl* frame = static_cast<WebFrameImpl*>(webView->mainFrame());
+ WebCore::FrameView* frameView = frame->frame()->view();
+ EXPECT_FALSE(frameView->layoutPending());
+ EXPECT_FALSE(frameView->needsLayout());
+
+ WebSize minSize(91, 56);
+ WebSize maxSize(403, 302);
+ webView->enableAutoResizeMode(true, minSize, maxSize);
+ EXPECT_TRUE(frameView->layoutPending());
+ EXPECT_TRUE(frameView->needsLayout());
+ frameView->layout();
+
+ EXPECT_TRUE(frame->frame()->document()->isHTMLDocument());
+
+ EXPECT_EQ(91, client.testData().width());
+ EXPECT_EQ(56, client.testData().height());
+ EXPECT_FALSE(client.testData().hasHorizontalScrollbar());
+ EXPECT_FALSE(client.testData().hasVerticalScrollbar());
+
+ webView->close();
}
+
+}
Added: trunk/Source/WebKit/chromium/tests/data/specify_size.html (0 => 101759)
--- trunk/Source/WebKit/chromium/tests/data/specify_size.html (rev 0)
+++ trunk/Source/WebKit/chromium/tests/data/specify_size.html 2011-12-02 08:58:21 UTC (rev 101759)
@@ -0,0 +1,6 @@
+<!doctype html>
+<html>
+<body style='margin:0px'>
+<img id='sizer' src=''/>
+</body>
+</html>
Property changes on: trunk/Source/WebKit/chromium/tests/data/specify_size.html
___________________________________________________________________
Added: svn:eol-style