Diff
Modified: trunk/Source/WebKit/chromium/ChangeLog (112689 => 112690)
--- trunk/Source/WebKit/chromium/ChangeLog 2012-03-30 17:53:28 UTC (rev 112689)
+++ trunk/Source/WebKit/chromium/ChangeLog 2012-03-30 17:54:03 UTC (rev 112690)
@@ -1,3 +1,59 @@
+2012-03-30 Alexander Pavlov <apav...@chromium.org>
+
+ Web Inspector: [Chromium] Implement Chromium-specific part of the device metrics emulation
+ https://bugs.webkit.org/show_bug.cgi?id=82612
+
+ This change implements the Chromium-specific code for overriding the device metrics, such as screen size
+ (by setting the FrameView size) and font zoom factor (necessary for certain emulated devices,)
+ and for painting the gutter overlay covering the WebView area not occupied by the associated FrameView.
+
+ Reviewed by Pavel Feldman.
+
+ * src/InspectorClientImpl.cpp:
+ (WebKit::InspectorClientImpl::canOverrideDeviceMetrics):
+ (WebKit):
+ (WebKit::InspectorClientImpl::overrideDeviceMetrics):
+ (WebKit::InspectorClientImpl::autoZoomPageToFitWidth):
+ * src/InspectorClientImpl.h:
+ (InspectorClientImpl):
+ * src/WebDevToolsAgentImpl.cpp:
+ (OverlayZOrders):
+ (DeviceMetricsSupport):
+ (WebKit::DeviceMetricsSupport::DeviceMetricsSupport):
+ (WebKit::DeviceMetricsSupport::~DeviceMetricsSupport):
+ (WebKit::DeviceMetricsSupport::setDeviceMetrics):
+ (WebKit::DeviceMetricsSupport::autoZoomPageToFitWidth):
+ (WebKit::DeviceMetricsSupport::applySizeOverrideIfNecessary):
+ (WebKit::DeviceMetricsSupport::restore):
+ (WebKit::DeviceMetricsSupport::applySizeOverrideInternal):
+ (WebKit::DeviceMetricsSupport::paintPageOverlay):
+ (WebKit::DeviceMetricsSupport::frameView):
+ (WebKit):
+ (WebKit::WebDevToolsAgentImpl::mainFrameViewCreated):
+ (WebKit::WebDevToolsAgentImpl::metricsOverridden):
+ (WebKit::WebDevToolsAgentImpl::overrideDeviceMetrics):
+ (WebKit::WebDevToolsAgentImpl::autoZoomPageToFitWidth):
+ (WebKit::WebDevToolsAgentImpl::highlight):
+ * src/WebDevToolsAgentImpl.h:
+ (WebCore):
+ (WebKit):
+ (WebDevToolsAgentImpl):
+ * src/WebDevToolsAgentPrivate.h:
+ (WebKit):
+ (WebDevToolsAgentPrivate):
+ * src/WebFrameImpl.cpp:
+ (WebKit::WebFrameImpl::createFrameView):
+ * src/WebViewImpl.cpp:
+ (WebKit::WebViewImpl::WebViewImpl):
+ (WebKit::WebViewImpl::resize):
+ (WebKit::WebViewImpl::setZoomLevel):
+ (WebKit::WebViewImpl::setEmulatedTextZoomFactor):
+ (WebKit):
+ (WebKit::WebViewImpl::updateLayerTreeViewport):
+ * src/WebViewImpl.h:
+ (WebViewImpl):
+ (WebKit::WebViewImpl::emulatedTextZoomFactor):
+
2012-03-30 David Barr <davidb...@chromium.org>
Split up top-level .gitignore and .gitattributes
Modified: trunk/Source/WebKit/chromium/src/InspectorClientImpl.cpp (112689 => 112690)
--- trunk/Source/WebKit/chromium/src/InspectorClientImpl.cpp 2012-03-30 17:53:28 UTC (rev 112689)
+++ trunk/Source/WebKit/chromium/src/InspectorClientImpl.cpp 2012-03-30 17:54:03 UTC (rev 112690)
@@ -128,6 +128,23 @@
agent->clearBrowserCookies();
}
+bool InspectorClientImpl::canOverrideDeviceMetrics()
+{
+ return true;
+}
+
+void InspectorClientImpl::overrideDeviceMetrics(int width, int height, float fontScaleFactor)
+{
+ if (WebDevToolsAgentImpl* agent = devToolsAgent())
+ agent->overrideDeviceMetrics(width, height, fontScaleFactor);
+}
+
+void InspectorClientImpl::autoZoomPageToFitWidth()
+{
+ if (WebDevToolsAgentImpl* agent = devToolsAgent())
+ agent->autoZoomPageToFitWidth();
+}
+
WebDevToolsAgentImpl* InspectorClientImpl::devToolsAgent()
{
return static_cast<WebDevToolsAgentImpl*>(m_inspectedWebView->devToolsAgent());
Modified: trunk/Source/WebKit/chromium/src/InspectorClientImpl.h (112689 => 112690)
--- trunk/Source/WebKit/chromium/src/InspectorClientImpl.h 2012-03-30 17:53:28 UTC (rev 112689)
+++ trunk/Source/WebKit/chromium/src/InspectorClientImpl.h 2012-03-30 17:54:03 UTC (rev 112690)
@@ -63,6 +63,11 @@
virtual void clearBrowserCache();
virtual bool canClearBrowserCookies();
virtual void clearBrowserCookies();
+
+ virtual bool canOverrideDeviceMetrics();
+ virtual void overrideDeviceMetrics(int, int, float);
+ virtual void autoZoomPageToFitWidth();
+
private:
WebDevToolsAgentImpl* devToolsAgent();
Modified: trunk/Source/WebKit/chromium/src/WebDevToolsAgentImpl.cpp (112689 => 112690)
--- trunk/Source/WebKit/chromium/src/WebDevToolsAgentImpl.cpp 2012-03-30 17:53:28 UTC (rev 112689)
+++ trunk/Source/WebKit/chromium/src/WebDevToolsAgentImpl.cpp 2012-03-30 17:54:03 UTC (rev 112690)
@@ -32,6 +32,8 @@
#include "WebDevToolsAgentImpl.h"
#include "ExceptionCode.h"
+#include "Frame.h"
+#include "FrameView.h"
#include "GraphicsContext.h"
#include "InjectedScriptHost.h"
#include "InspectorBackendDispatcher.h"
@@ -68,6 +70,13 @@
using namespace WebCore;
+namespace OverlayZOrders {
+static const int viewportGutter = 97;
+
+// Use 99 as a big z-order number so that highlight is above other overlays.
+static const int highlight = 99;
+}
+
namespace WebKit {
class ClientMessageLoopAdapter : public PageScriptDebugServer::ClientMessageLoop {
@@ -173,6 +182,110 @@
OwnPtr<WebDevToolsAgent::MessageDescriptor> m_descriptor;
};
+class DeviceMetricsSupport : public WebPageOverlay {
+public:
+ DeviceMetricsSupport(WebViewImpl* webView)
+ : m_webView(webView)
+ {
+ m_webView->addPageOverlay(this, OverlayZOrders::viewportGutter);
+ }
+
+ ~DeviceMetricsSupport()
+ {
+ restore();
+ m_webView->removePageOverlay(this);
+ }
+
+ void setDeviceMetrics(int width, int height, float textZoomFactor)
+ {
+ WebCore::FrameView* view = frameView();
+ if (!view)
+ return;
+
+ m_emulatedFrameSize = WebSize(width, height);
+ m_webView->setEmulatedTextZoomFactor(textZoomFactor);
+ applySizeOverrideInternal(view, width, height);
+ autoZoomPageToFitWidth(view->frame());
+
+ m_webView->sendResizeEventAndRepaint();
+ }
+
+ void autoZoomPageToFitWidth(Frame* frame)
+ {
+ if (!frame)
+ return;
+
+ m_webView->setZoomLevel(false, 0);
+
+ float zoomFactor = static_cast<float>(m_emulatedFrameSize.width) / frame->view()->contentsWidth();
+ frame->setPageAndTextZoomFactors(zoomFactor, m_webView->emulatedTextZoomFactor());
+ }
+
+ void applySizeOverrideIfNecessary()
+ {
+ FrameView* view = frameView();
+ if (!view)
+ return;
+
+ applySizeOverrideInternal(view, m_emulatedFrameSize.width, m_emulatedFrameSize.height);
+ }
+
+private:
+ void restore()
+ {
+ m_webView->setZoomLevel(false, 0);
+ m_webView->sendResizeEventAndRepaint();
+ m_webView->setEmulatedTextZoomFactor(1);
+
+ WebCore::FrameView* view = frameView();
+ if (!view)
+ return;
+
+ view->setHorizontalScrollbarLock(false);
+ view->setVerticalScrollbarLock(false);
+ view->setScrollbarModes(ScrollbarAuto, ScrollbarAuto, false, false);
+ view->resize(IntSize(m_webView->size()));
+ }
+
+ void applySizeOverrideInternal(FrameView* frameView, int overrideWidth, int overrideHeight)
+ {
+ frameView->setScrollbarModes(ScrollbarAlwaysOn, ScrollbarAlwaysOn, true, true);
+ if (Scrollbar* verticalBar = frameView->verticalScrollbar())
+ overrideWidth += !verticalBar->isOverlayScrollbar() ? verticalBar->width() : 0;
+ if (Scrollbar* horizontalBar = frameView->horizontalScrollbar())
+ overrideHeight += !horizontalBar->isOverlayScrollbar() ? horizontalBar->height() : 0;
+
+ if (IntSize(overrideWidth, overrideHeight) != frameView->size())
+ frameView->resize(overrideWidth, overrideHeight);
+
+ Document* doc = frameView->frame()->document();
+ doc->recalcStyle(Node::Force);
+ doc->updateLayout();
+ }
+
+ virtual void paintPageOverlay(WebCanvas* canvas)
+ {
+ FrameView* frameView = this->frameView();
+ if (!frameView)
+ return;
+
+ GraphicsContextBuilder builder(canvas);
+ GraphicsContext& gc = builder.context();
+ gc.clipOut(IntRect(IntPoint(), frameView->size()));
+ gc.setFillColor(Color::darkGray, ColorSpaceDeviceRGB);
+ gc.drawRect(IntRect(IntPoint(), m_webView->size()));
+ }
+
+ WebCore::FrameView* frameView()
+ {
+ return m_webView->mainFrameImpl() ? m_webView->mainFrameImpl()->frameView() : 0;
+ }
+
+ WebViewImpl* m_webView;
+ WebSize m_emulatedFrameSize;
+};
+
+
WebDevToolsAgentImpl::WebDevToolsAgentImpl(
WebViewImpl* webViewImpl,
WebDevToolsAgentClient* client)
@@ -231,6 +344,36 @@
proxy->setContextDebugId(m_hostId);
}
+void WebDevToolsAgentImpl::mainFrameViewCreated(WebFrameImpl* webFrame)
+{
+ if (m_metricsSupport)
+ m_metricsSupport->applySizeOverrideIfNecessary();
+}
+
+bool WebDevToolsAgentImpl::metricsOverridden()
+{
+ return !!m_metricsSupport;
+}
+
+void WebDevToolsAgentImpl::overrideDeviceMetrics(int width, int height, float fontScaleFactor)
+{
+ if (!width && !height && fontScaleFactor == 1) {
+ if (m_metricsSupport)
+ m_metricsSupport.clear();
+ return;
+ }
+
+ if (!m_metricsSupport)
+ m_metricsSupport = adoptPtr(new DeviceMetricsSupport(m_webViewImpl));
+ m_metricsSupport->setDeviceMetrics(width, height, fontScaleFactor);
+}
+
+void WebDevToolsAgentImpl::autoZoomPageToFitWidth()
+{
+ if (m_metricsSupport)
+ m_metricsSupport->autoZoomPageToFitWidth(m_webViewImpl->mainFrameImpl()->frame());
+}
+
void WebDevToolsAgentImpl::dispatchOnInspectorBackend(const WebString& message)
{
inspectorController()->dispatchMessageFromFrontend(message);
@@ -282,8 +425,7 @@
void WebDevToolsAgentImpl::highlight()
{
- // Use 99 as a big z-order number so that highlight is above other overlays.
- m_webViewImpl->addPageOverlay(this, 99);
+ m_webViewImpl->addPageOverlay(this, OverlayZOrders::highlight);
}
void WebDevToolsAgentImpl::hideHighlight()
Modified: trunk/Source/WebKit/chromium/src/WebDevToolsAgentImpl.h (112689 => 112690)
--- trunk/Source/WebKit/chromium/src/WebDevToolsAgentImpl.h 2012-03-30 17:53:28 UTC (rev 112689)
+++ trunk/Source/WebKit/chromium/src/WebDevToolsAgentImpl.h 2012-03-30 17:54:03 UTC (rev 112690)
@@ -35,6 +35,7 @@
#include "WebDevToolsAgentPrivate.h"
#include "WebPageOverlay.h"
+#include "platform/WebSize.h"
#include <wtf/Forward.h>
#include <wtf/OwnPtr.h>
@@ -42,6 +43,7 @@
namespace WebCore {
class Document;
class Frame;
+class FrameView;
class GraphicsContext;
class InspectorClient;
class InspectorController;
@@ -50,6 +52,7 @@
namespace WebKit {
+class DeviceMetricsSupport;
class WebDevToolsAgentClient;
class WebFrame;
class WebFrameImpl;
@@ -68,7 +71,9 @@
virtual ~WebDevToolsAgentImpl();
// WebDevToolsAgentPrivate implementation.
- virtual void didClearWindowObject(WebFrameImpl* frame);
+ virtual void didClearWindowObject(WebFrameImpl*);
+ virtual void mainFrameViewCreated(WebFrameImpl*);
+ virtual bool metricsOverridden();
// WebDevToolsAgent implementation.
virtual void attach();
@@ -95,6 +100,9 @@
virtual void clearBrowserCache();
virtual void clearBrowserCookies();
+ virtual void overrideDeviceMetrics(int width, int height, float fontScaleFactor);
+ virtual void autoZoomPageToFitWidth();
+
int hostId() { return m_hostId; }
// WebPageOverlay
@@ -108,6 +116,7 @@
WebDevToolsAgentClient* m_client;
WebViewImpl* m_webViewImpl;
bool m_attached;
+ OwnPtr<DeviceMetricsSupport> m_metricsSupport;
};
} // namespace WebKit
Modified: trunk/Source/WebKit/chromium/src/WebDevToolsAgentPrivate.h (112689 => 112690)
--- trunk/Source/WebKit/chromium/src/WebDevToolsAgentPrivate.h 2012-03-30 17:53:28 UTC (rev 112689)
+++ trunk/Source/WebKit/chromium/src/WebDevToolsAgentPrivate.h 2012-03-30 17:54:03 UTC (rev 112690)
@@ -35,14 +35,22 @@
namespace WebKit {
class WebFrameImpl;
+class WebSize;
class WebDevToolsAgentPrivate : public WebDevToolsAgent {
public:
- // Notifications from FrameLoaderClientImpl:
+ // Notification from FrameLoaderClientImpl:
// The window object for the frame has been cleared of any extra properties
// that may have been set by script from the previously loaded document.
virtual void didClearWindowObject(WebFrameImpl*) = 0;
+
+ // A new FrameView has been created for the specified WebFrame using
+ // the Frame::createView() call.
+ virtual void mainFrameViewCreated(WebFrameImpl*) = 0;
+
+ // Returns true if the device metrics override mode is enabled.
+ virtual bool metricsOverridden() = 0;
};
} // namespace WebKit
Modified: trunk/Source/WebKit/chromium/src/WebFrameImpl.cpp (112689 => 112690)
--- trunk/Source/WebKit/chromium/src/WebFrameImpl.cpp 2012-03-30 17:53:28 UTC (rev 112689)
+++ trunk/Source/WebKit/chromium/src/WebFrameImpl.cpp 2012-03-30 17:54:03 UTC (rev 112690)
@@ -142,6 +142,7 @@
#include "WebDOMEvent.h"
#include "WebDOMEventListener.h"
#include "WebDataSourceImpl.h"
+#include "WebDevToolsAgentPrivate.h"
#include "WebDocument.h"
#include "WebFindOptions.h"
#include "WebFormElement.h"
@@ -2083,6 +2084,9 @@
m_frame->createView(webView->size(), Color::white, webView->isTransparent(), webView->fixedLayoutSize(), isMainFrame ? webView->isFixedLayoutModeEnabled() : 0);
if (webView->shouldAutoResize() && isMainFrame)
m_frame->view()->enableAutoSizeMode(true, webView->minAutoSize(), webView->maxAutoSize());
+
+ if (isMainFrame && webView->devToolsAgentPrivate())
+ webView->devToolsAgentPrivate()->mainFrameViewCreated(this);
}
WebFrameImpl* WebFrameImpl::fromFrame(Frame* frame)
Modified: trunk/Source/WebKit/chromium/src/WebViewImpl.cpp (112689 => 112690)
--- trunk/Source/WebKit/chromium/src/WebViewImpl.cpp 2012-03-30 17:53:28 UTC (rev 112689)
+++ trunk/Source/WebKit/chromium/src/WebViewImpl.cpp 2012-03-30 17:54:03 UTC (rev 112690)
@@ -136,6 +136,7 @@
#include "WebViewClient.h"
#include "WheelEvent.h"
#include "cc/CCProxy.h"
+#include "painting/GraphicsContextBuilder.h"
#include "platform/WebDragData.h"
#include "platform/WebImage.h"
#include "platform/WebKitPlatformSupport.h"
@@ -365,6 +366,7 @@
#endif
, m_deviceOrientationClientProxy(adoptPtr(new DeviceOrientationClientProxy(client ? client->deviceOrientationClient() : 0)))
, m_geolocationClientProxy(adoptPtr(new GeolocationClientProxy(client ? client->geolocationClient() : 0)))
+ , m_emulatedTextZoomFactor(1)
#if ENABLE(MEDIA_STREAM)
, m_userMediaClientImpl(this)
#endif
@@ -1260,8 +1262,11 @@
return;
m_size = newSize;
- if (mainFrameImpl()->frameView())
- mainFrameImpl()->frameView()->resize(m_size.width, m_size.height);
+ if (!devToolsAgentPrivate() || !devToolsAgentPrivate()->metricsOverridden()) {
+ WebFrameImpl* webFrame = mainFrameImpl();
+ if (webFrame->frameView())
+ webFrame->frameView()->resize(newSize.width, newSize.height);
+ }
sendResizeEventAndRepaint();
}
@@ -2218,9 +2223,9 @@
else {
float zoomFactor = static_cast<float>(zoomLevelToZoomFactor(m_zoomLevel));
if (textOnly)
- frame->setPageAndTextZoomFactors(1, zoomFactor);
+ frame->setPageAndTextZoomFactors(1, zoomFactor * m_emulatedTextZoomFactor);
else
- frame->setPageAndTextZoomFactors(zoomFactor, 1);
+ frame->setPageAndTextZoomFactors(zoomFactor, m_emulatedTextZoomFactor);
}
return m_zoomLevel;
}
@@ -2990,6 +2995,14 @@
return shouldUseExternalPopupMenus;
}
+void WebViewImpl::setEmulatedTextZoomFactor(float textZoomFactor)
+{
+ m_emulatedTextZoomFactor = textZoomFactor;
+ Frame* frame = mainFrameImpl()->frame();
+ if (frame)
+ frame->setPageAndTextZoomFactors(frame->pageZoomFactor(), m_emulatedTextZoomFactor);
+}
+
bool WebViewImpl::navigationPolicyFromMouseEvent(unsigned short button,
bool ctrl, bool shift,
bool alt, bool meta,
@@ -3431,7 +3444,7 @@
layerAdjustX = -view->contentsSize().width() + view->visibleContentRect(false).width();
}
m_nonCompositedContentHost->setViewport(visibleRect.size(), view->contentsSize(), scroll, pageScaleFactor(), layerAdjustX);
- m_layerTreeView.setViewportSize(visibleRect.size());
+ m_layerTreeView.setViewportSize(size());
m_layerTreeView.setPageScaleFactorAndLimits(pageScaleFactor(), m_minimumPageScaleFactor, m_maximumPageScaleFactor);
}
Modified: trunk/Source/WebKit/chromium/src/WebViewImpl.h (112689 => 112690)
--- trunk/Source/WebKit/chromium/src/WebViewImpl.h 2012-03-30 17:53:28 UTC (rev 112689)
+++ trunk/Source/WebKit/chromium/src/WebViewImpl.h 2012-03-30 17:54:03 UTC (rev 112690)
@@ -400,6 +400,17 @@
return m_initialNavigationPolicy;
}
+ // Sets the emulated text zoom factor
+ // (may not be 1 in the device metrics emulation mode).
+ void setEmulatedTextZoomFactor(float);
+
+ // Returns the emulated text zoom factor
+ // (which may not be 1 in the device metrics emulation mode).
+ float emulatedTextZoomFactor() const
+ {
+ return m_emulatedTextZoomFactor;
+ }
+
// Determines whether a page should e.g. be opened in a background tab.
// Returns false if it has no opinion, in which case it doesn't set *policy.
static bool navigationPolicyFromMouseEvent(
@@ -492,6 +503,9 @@
void enterFullScreenForElement(WebCore::Element*);
void exitFullScreenForElement(WebCore::Element*);
+ // Exposed for the purpose of overriding device metrics.
+ void sendResizeEventAndRepaint();
+
// Exposed for testing purposes.
bool hasHorizontalScrollbar();
bool hasVerticalScrollbar();
@@ -547,7 +561,6 @@
const WebPoint& screenPoint,
DragAction);
- void sendResizeEventAndRepaint();
void configureAutoResizeMode();
#if USE(ACCELERATED_COMPOSITING)
@@ -725,6 +738,8 @@
OwnPtr<DeviceOrientationClientProxy> m_deviceOrientationClientProxy;
OwnPtr<GeolocationClientProxy> m_geolocationClientProxy;
+ float m_emulatedTextZoomFactor;
+
#if ENABLE(MEDIA_STREAM)
UserMediaClientImpl m_userMediaClientImpl;
#endif