https://bugs.webkit.org/show_bug.cgi?id=83280
Source/WebCore:
This change adds the "Fit window" option to the Settings pane of Web Inspector, which lets users
resize the FrameView to fit the WebViewImpl size. When the user resizes the browser window
in the device metrics override mode with the option enabled, the FrameView follows
to match WebViewImpl by at least one dimension.
Reviewed by Pavel Feldman.
* English.lproj/localizedStrings.js:
* inspector/Inspector.json:
* inspector/InspectorClient.h:
(WebCore::InspectorClient::overrideDeviceMetrics):
(WebCore::InspectorClient::autoZoomPageToFitWidth):
* inspector/InspectorInstrumentation.cpp:
(WebCore::InspectorInstrumentation::shouldApplyScreenWidthOverrideImpl):
(WebCore):
(WebCore::InspectorInstrumentation::shouldApplyScreenHeightOverrideImpl):
* inspector/InspectorInstrumentation.h:
(InspectorInstrumentation):
(WebCore::InspectorInstrumentation::shouldApplyScreenWidthOverride):
(WebCore):
(WebCore::InspectorInstrumentation::shouldApplyScreenHeightOverride):
* inspector/InspectorPageAgent.cpp:
(PageAgentState):
(WebCore::InspectorPageAgent::restore):
(WebCore::InspectorPageAgent::disable):
(WebCore::InspectorPageAgent::setDeviceMetricsOverride):
(WebCore::InspectorPageAgent::updateViewMetrics):
* inspector/InspectorPageAgent.h:
* inspector/front-end/Settings.js:
* inspector/front-end/SettingsScreen.js:
(WebInspector.SettingsScreen.prototype._createDeviceMetricsElement):
* inspector/front-end/UserAgentSupport.js:
* inspector/front-end/helpScreen.css:
(.help-content input[type=checkbox]):
* page/DOMWindow.cpp:
(WebCore::DOMWindow::innerHeight):
(WebCore::DOMWindow::innerWidth):
Source/WebKit/chromium:
Implement the scaling of the FrameView to the WebViewImpl size, handle WebViewImpl resizes.
Reviewed by Pavel Feldman.
* src/InspectorClientImpl.cpp:
(WebKit::InspectorClientImpl::overrideDeviceMetrics):
* src/InspectorClientImpl.h:
(InspectorClientImpl):
* src/WebDevToolsAgentImpl.cpp:
(WebKit::DeviceMetricsSupport::DeviceMetricsSupport):
(WebKit::DeviceMetricsSupport::setDeviceMetrics):
(WebKit::DeviceMetricsSupport::autoZoomPageToFitWidthOnNavigation):
(DeviceMetricsSupport):
(WebKit::DeviceMetricsSupport::autoZoomPageToFitWidth):
(WebKit::DeviceMetricsSupport::webViewResized):
(WebKit::DeviceMetricsSupport::applySizeOverrideIfNecessary):
(WebKit::DeviceMetricsSupport::ensureOriginalZoomFactor):
(WebKit::DeviceMetricsSupport::restore):
(WebKit::DeviceMetricsSupport::scaledEmulatedFrameSize):
(WebKit::DeviceMetricsSupport::forcedScrollbarDimensions):
(WebKit::DeviceMetricsSupport::applySizeOverrideInternal):
(WebKit::WebDevToolsAgentImpl::webViewResized):
(WebKit):
(WebKit::WebDevToolsAgentImpl::overrideDeviceMetrics):
(WebKit::WebDevToolsAgentImpl::autoZoomPageToFitWidth):
* src/WebDevToolsAgentImpl.h:
(WebDevToolsAgentImpl):
* src/WebDevToolsAgentPrivate.h:
(WebDevToolsAgentPrivate):
* src/WebViewImpl.cpp:
(WebKit::WebViewImpl::resize):
LayoutTests:
Update the test to follow the protocol change and test the "Fit window" parameter.
Reviewed by Pavel Feldman.
* inspector/styles/override-screen-size-expected.txt:
* inspector/styles/override-screen-size.html:
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@113709
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2012-04-09 Alexander Pavlov <apavlov@chromium.org>
+
+ Web Inspector: [Device Metrics] Introduce the "Fit window" option
+ https://bugs.webkit.org/show_bug.cgi?id=83280
+
+ Update the test to follow the protocol change and test the "Fit window" parameter.
+
+ Reviewed by Pavel Feldman.
+
+ * inspector/styles/override-screen-size-expected.txt:
+ * inspector/styles/override-screen-size.html:
+
2012-04-10 Ádám Kallai <kadam@inf.u-szeged.hu>
[Qt] Gardening after r113701.
Tests that screen dimension overrides affect media rules, body dimensions, and window.screen.
-Override: 480x960
-Screen from page: 480x960
-Body from page: 480x960
+Override: 480x800
+Screen from page: 480x800
+Window from page: 480x800
+Body from page: 480x800
Main style:
[expanded]
element.style { ()
display: block;
-Override: 960x480
-Screen from page: 960x480
-Body from page: 960x480
+Override: 800x480
+Screen from page: 800x480
+Window from page: 800x480
+Body from page: 800x480
Main style:
[expanded]
element.style { ()
display: block;
-Override: 10000001x960 => ERROR
-Override: -1x960 => ERROR
+Override: 10000001x800 => ERROR
+Override: -1x800 => ERROR
Override: 480x10000001 => ERROR
Override: 480x-1 => ERROR
Current dimensions:
-Screen from page: 960x480
-Body from page: 960x480
+Screen from page: 800x480
+Window from page: 800x480
+Body from page: 800x480
Disable PageAgent:
Screen size same as original - OK
Enable PageAgent:
{
return JSON.stringify({
screen: window.screen.width + "x" + window.screen.height,
+ inner: window.innerWidth + "x" + window.innerHeight,
body: document.body.offsetWidth + "x" + document.body.offsetHeight
});
}
function step0()
{
- overrideAndDumpData(480, 960, step1);
+ overrideAndDumpData(480, 800, step1);
}
function step1()
}
// Disable overrides.
- PageAgent.setDeviceMetricsOverride(0, 0, 1, overrideCallback);
+ PageAgent.setDeviceMetricsOverride(0, 0, 1, true, overrideCallback);
}
function step2()
{
- overrideAndDumpData(960, 480, step3);
+ overrideAndDumpData(800, 480, step3);
}
function step3()
{
- applyOverride(exceededDimension, 960, step4);
+ applyOverride(exceededDimension, 800, step4);
}
function step4()
{
- applyOverride(-1, 960, step5);
+ applyOverride(-1, 800, step5);
}
function step5()
InspectorTest.addResult("Enable PageAgent:");
PageAgent.enable();
InspectorTest.evaluateInPage("getSizes()", callback);
-
}
function applyOverride(width, height, userCallback)
InspectorTest.addResult("Override: " + width + "x" + height + " => ERROR");
userCallback();
}
- PageAgent.setDeviceMetricsOverride(width, height, 1, callback);
+ PageAgent.setDeviceMetricsOverride(width, height, 1, true, callback);
}
function overrideAndDumpData(width, height, callback)
{
var result = JSON.parse(jsonResult.value);
InspectorTest.addResult("Screen from page: " + result.screen);
+ InspectorTest.addResult("Window from page: " + result.inner);
InspectorTest.addResult("Body from page: " + result.body);
callback();
}
+2012-04-09 Alexander Pavlov <apavlov@chromium.org>
+
+ Web Inspector: [Device Metrics] Introduce the "Fit window" option
+ https://bugs.webkit.org/show_bug.cgi?id=83280
+
+ This change adds the "Fit window" option to the Settings pane of Web Inspector, which lets users
+ resize the FrameView to fit the WebViewImpl size. When the user resizes the browser window
+ in the device metrics override mode with the option enabled, the FrameView follows
+ to match WebViewImpl by at least one dimension.
+
+ Reviewed by Pavel Feldman.
+
+ * English.lproj/localizedStrings.js:
+ * inspector/Inspector.json:
+ * inspector/InspectorClient.h:
+ (WebCore::InspectorClient::overrideDeviceMetrics):
+ (WebCore::InspectorClient::autoZoomPageToFitWidth):
+ * inspector/InspectorInstrumentation.cpp:
+ (WebCore::InspectorInstrumentation::shouldApplyScreenWidthOverrideImpl):
+ (WebCore):
+ (WebCore::InspectorInstrumentation::shouldApplyScreenHeightOverrideImpl):
+ * inspector/InspectorInstrumentation.h:
+ (InspectorInstrumentation):
+ (WebCore::InspectorInstrumentation::shouldApplyScreenWidthOverride):
+ (WebCore):
+ (WebCore::InspectorInstrumentation::shouldApplyScreenHeightOverride):
+ * inspector/InspectorPageAgent.cpp:
+ (PageAgentState):
+ (WebCore::InspectorPageAgent::restore):
+ (WebCore::InspectorPageAgent::disable):
+ (WebCore::InspectorPageAgent::setDeviceMetricsOverride):
+ (WebCore::InspectorPageAgent::updateViewMetrics):
+ * inspector/InspectorPageAgent.h:
+ * inspector/front-end/Settings.js:
+ * inspector/front-end/SettingsScreen.js:
+ (WebInspector.SettingsScreen.prototype._createDeviceMetricsElement):
+ * inspector/front-end/UserAgentSupport.js:
+ * inspector/front-end/helpScreen.css:
+ (.help-content input[type=checkbox]):
+ * page/DOMWindow.cpp:
+ (WebCore::DOMWindow::innerHeight):
+ (WebCore::DOMWindow::innerWidth):
+
2012-04-10 Ilya Tikhonovsky <loislo@chromium.org>
Web Inspector: use maxJSObjectId that is provided by back-end.
"parameters": [
{ "name": "width", "type": "integer", "description": "Overriding width value in pixels (minimum 0, maximum 10000000). 0 disables the override." },
{ "name": "height", "type": "integer", "description": "Overriding height value in pixels (minimum 0, maximum 10000000). 0 disables the override." },
- { "name": "fontScaleFactor", "type": "number", "description": "Overriding font scale factor value (must be positive). 1 disables the override." }
+ { "name": "fontScaleFactor", "type": "number", "description": "Overriding font scale factor value (must be positive). 1 disables the override." },
+ { "name": "fitWindow", "type": "boolean", "description": "Whether a view that exceeds the available browser window area should be scaled down to fit." }
],
"hidden": true
},
virtual void clearBrowserCookies() { }
virtual bool canOverrideDeviceMetrics() { return false; }
- virtual void overrideDeviceMetrics(int /*width*/, int /*height*/, float /*fontScaleFactor*/) {
+ virtual void overrideDeviceMetrics(int /*width*/, int /*height*/, float /*fontScaleFactor*/, bool /*fitWindow*/)
+ {
// FIXME: Platforms may want to implement this (see https://bugs.webkit.org/show_bug.cgi?id=82886).
}
- virtual void autoZoomPageToFitWidth() {
+ virtual void autoZoomPageToFitWidth()
+ {
// FIXME: Platforms may want to implement this (see https://bugs.webkit.org/show_bug.cgi?id=82886).
}
pageAgent->applyScreenHeightOverride(height);
}
+bool InspectorInstrumentation::shouldApplyScreenWidthOverrideImpl(InstrumentingAgents* instrumentingAgents)
+{
+ if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent()) {
+ long width = 0;
+ pageAgent->applyScreenWidthOverride(&width);
+ return !!width;
+ }
+ return false;
+}
+
+bool InspectorInstrumentation::shouldApplyScreenHeightOverrideImpl(InstrumentingAgents* instrumentingAgents)
+{
+ if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent()) {
+ long height = 0;
+ pageAgent->applyScreenHeightOverride(&height);
+ return !!height;
+ }
+ return false;
+}
+
void InspectorInstrumentation::willSendRequestImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, DocumentLoader* loader, ResourceRequest& request, const ResourceResponse& redirectResponse)
{
if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
static void applyUserAgentOverride(Frame*, String*);
static void applyScreenWidthOverride(Frame*, long*);
static void applyScreenHeightOverride(Frame*, long*);
+ static bool shouldApplyScreenWidthOverride(Frame*);
+ static bool shouldApplyScreenHeightOverride(Frame*);
static void willSendRequest(Frame*, unsigned long identifier, DocumentLoader*, ResourceRequest&, const ResourceResponse& redirectResponse);
static void continueAfterPingLoader(Frame*, unsigned long identifier, DocumentLoader*, ResourceRequest&, const ResourceResponse&);
static void markResourceAsCached(Page*, unsigned long identifier);
static void applyUserAgentOverrideImpl(InstrumentingAgents*, String*);
static void applyScreenWidthOverrideImpl(InstrumentingAgents*, long*);
static void applyScreenHeightOverrideImpl(InstrumentingAgents*, long*);
+ static bool shouldApplyScreenWidthOverrideImpl(InstrumentingAgents*);
+ static bool shouldApplyScreenHeightOverrideImpl(InstrumentingAgents*);
static void willSendRequestImpl(InstrumentingAgents*, unsigned long identifier, DocumentLoader*, ResourceRequest&, const ResourceResponse& redirectResponse);
static void continueAfterPingLoaderImpl(InstrumentingAgents*, unsigned long identifier, DocumentLoader*, ResourceRequest&, const ResourceResponse&);
static void markResourceAsCachedImpl(InstrumentingAgents*, unsigned long identifier);
#endif
}
+inline bool InspectorInstrumentation::shouldApplyScreenWidthOverride(Frame* frame)
+{
+#if ENABLE(INSPECTOR)
+ FAST_RETURN_IF_NO_FRONTENDS(false);
+ if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame))
+ return shouldApplyScreenWidthOverrideImpl(instrumentingAgents);
+#endif
+ return false;
+}
+
+inline bool InspectorInstrumentation::shouldApplyScreenHeightOverride(Frame* frame)
+{
+#if ENABLE(INSPECTOR)
+ FAST_RETURN_IF_NO_FRONTENDS(false);
+ if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame))
+ return shouldApplyScreenHeightOverrideImpl(instrumentingAgents);
+#endif
+ return false;
+}
+
inline void InspectorInstrumentation::willSendRequest(Frame* frame, unsigned long identifier, DocumentLoader* loader, ResourceRequest& request, const ResourceResponse& redirectResponse)
{
#if ENABLE(INSPECTOR)
static const char pageAgentScreenWidthOverride[] = "pageAgentScreenWidthOverride";
static const char pageAgentScreenHeightOverride[] = "pageAgentScreenHeightOverride";
static const char pageAgentFontScaleFactorOverride[] = "pageAgentFontScaleFactorOverride";
+static const char pageAgentFitWindow[] = "pageAgentFitWindow";
static const char showPaintRects[] = "showPaintRects";
}
int width = static_cast<int>(m_state->getLong(PageAgentState::pageAgentScreenWidthOverride));
int height = static_cast<int>(m_state->getLong(PageAgentState::pageAgentScreenHeightOverride));
double fontScaleFactor = m_state->getDouble(PageAgentState::pageAgentFontScaleFactorOverride);
- updateViewMetrics(width, height, fontScaleFactor);
+ bool fitWindow = m_state->getBoolean(PageAgentState::pageAgentFitWindow);
+ updateViewMetrics(width, height, fontScaleFactor, fitWindow);
}
}
m_state->setLong(PageAgentState::pageAgentScreenWidthOverride, 0);
m_state->setLong(PageAgentState::pageAgentScreenHeightOverride, 0);
m_state->setDouble(PageAgentState::pageAgentFontScaleFactorOverride, 1);
- updateViewMetrics(0, 0, 1);
+ m_state->setBoolean(PageAgentState::pageAgentFitWindow, false);
+ updateViewMetrics(0, 0, 1, false);
}
void InspectorPageAgent::addScriptToEvaluateOnLoad(ErrorString*, const String& source, String* identifier)
*result = m_client->canOverrideDeviceMetrics();
}
-void InspectorPageAgent::setDeviceMetricsOverride(ErrorString* errorString, const int width, const int height, double fontScaleFactor)
+void InspectorPageAgent::setDeviceMetricsOverride(ErrorString* errorString, int width, int height, double fontScaleFactor, bool fitWindow)
{
const static long maxDimension = 10000000;
int currentWidth = static_cast<int>(m_state->getLong(PageAgentState::pageAgentScreenWidthOverride));
int currentHeight = static_cast<int>(m_state->getLong(PageAgentState::pageAgentScreenHeightOverride));
double currentFontScaleFactor = m_state->getDouble(PageAgentState::pageAgentFontScaleFactorOverride);
+ bool currentFitWindow = m_state->getBoolean(PageAgentState::pageAgentFitWindow);
- if (width == currentWidth && height == currentHeight && fontScaleFactor == currentFontScaleFactor)
+ if (width == currentWidth && height == currentHeight && fontScaleFactor == currentFontScaleFactor && fitWindow == currentFitWindow)
return;
m_state->setLong(PageAgentState::pageAgentScreenWidthOverride, width);
m_state->setLong(PageAgentState::pageAgentScreenHeightOverride, height);
m_state->setDouble(PageAgentState::pageAgentFontScaleFactorOverride, fontScaleFactor);
+ m_state->setBoolean(PageAgentState::pageAgentFitWindow, fitWindow);
- updateViewMetrics(width, height, fontScaleFactor);
+ updateViewMetrics(width, height, fontScaleFactor, fitWindow);
}
void InspectorPageAgent::setShowPaintRects(ErrorString*, bool show)
return result;
}
-void InspectorPageAgent::updateViewMetrics(int width, int height, double fontScaleFactor)
+void InspectorPageAgent::updateViewMetrics(int width, int height, double fontScaleFactor, bool fitWindow)
{
- m_client->overrideDeviceMetrics(width, height, static_cast<float>(fontScaleFactor));
+ m_client->overrideDeviceMetrics(width, height, static_cast<float>(fontScaleFactor), fitWindow);
Document* document = mainFrame()->document();
document->styleSelectorChanged(RecalcStyleImmediately);
virtual void searchInResources(ErrorString*, const String&, const bool* caseSensitive, const bool* isRegex, RefPtr<TypeBuilder::Array<TypeBuilder::Page::SearchResult> >&);
virtual void setDocumentContent(ErrorString*, const String& frameId, const String& html);
virtual void canOverrideDeviceMetrics(ErrorString*, bool*);
- virtual void setDeviceMetricsOverride(ErrorString*, int width, int height, double fontScaleFactor);
+ virtual void setDeviceMetricsOverride(ErrorString*, int width, int height, double fontScaleFactor, bool fitWindow);
virtual void setShowPaintRects(ErrorString*, bool show);
// InspectorInstrumentation API
private:
InspectorPageAgent(InstrumentingAgents*, Page*, InspectorState*, InjectedScriptManager*, InspectorClient*);
- void updateViewMetrics(int, int, double);
+ void updateViewMetrics(int, int, double, bool);
PassRefPtr<TypeBuilder::Page::Frame> buildObjectForFrame(Frame*);
PassRefPtr<TypeBuilder::Page::FrameResourceTree> buildObjectForFrameTree(Frame*);
this.overrideUserAgent = this.createSetting("overrideUserAgent", "");
this.userAgent = this.createSetting("userAgent", "");
this.deviceMetrics = this.createSetting("deviceMetrics", "");
+ this.deviceFitWindow = this.createSetting("deviceFitWindow", false);
this.showScriptFolders = this.createSetting("showScriptFolders", true);
this.dockToRight = this.createSetting("dockToRight", false);
this.emulateTouchEvents = this.createSetting("emulateTouchEvents", false);
return right ? this._rightColumnElement : this._leftColumnElement;
},
- _createCheckboxSetting: function(name, setting)
+ /**
+ * @param {boolean=} omitParagraphElement
+ */
+ _createCheckboxSetting: function(name, setting, omitParagraphElement)
{
var input = document.createElement("input");
input.type = "checkbox";
input.name = name;
input.checked = setting.get();
+
function listener()
{
setting.set(input.checked);
}
input.addEventListener("click", listener, false);
- var p = document.createElement("p");
var label = document.createElement("label");
label.appendChild(input);
label.appendChild(document.createTextNode(name));
+ if (omitParagraphElement)
+ return label;
+
+ var p = document.createElement("p");
p.appendChild(label);
return p;
},
cellElement.appendChild(document.createTextNode(WebInspector.UIString("Font scale factor:")));
cellElement = rowElement.createChild("td");
this._fontScaleFactorOverrideElement = createInput.call(this, cellElement, "metrics-override-font-scale", String(metrics.fontScaleFactor || 1));
+
+ rowElement = tableElement.createChild("tr");
+ cellElement = rowElement.createChild("td");
+ cellElement.colspan = 2;
+ cellElement.appendChild(this._createCheckboxSetting(WebInspector.UIString("Fit window"), WebInspector.settings.deviceFitWindow, true));
+
return fieldsetElement;
}
}
WebInspector.UserAgentSupport = function()
{
if (WebInspector.settings.deviceMetrics.get())
- this._deviceMetricsSettingChanged();
- WebInspector.settings.deviceMetrics.addChangeListener(this._deviceMetricsSettingChanged, this);
+ this._deviceMetricsChanged();
+ WebInspector.settings.deviceMetrics.addChangeListener(this._deviceMetricsChanged, this);
+ WebInspector.settings.deviceFitWindow.addChangeListener(this._deviceMetricsChanged, this);
}
/**
}
WebInspector.UserAgentSupport.prototype = {
- _deviceMetricsSettingChanged: function()
+ _deviceMetricsChanged: function()
{
var metrics = WebInspector.UserAgentSupport.DeviceMetrics.parseSetting(WebInspector.settings.deviceMetrics.get());
if (metrics.isValid())
- PageAgent.setDeviceMetricsOverride(metrics.width, metrics.height, metrics.fontScaleFactor);
+ PageAgent.setDeviceMetricsOverride(metrics.width, metrics.height, metrics.fontScaleFactor, WebInspector.settings.deviceFitWindow.get());
}
}
\ No newline at end of file
.help-content input[type=checkbox] {
height: 13px;
width: 13px;
- margin-right: 0;
+ margin-left: 0;
margin-right: 4px;
}
if (!view)
return 0;
- long height = view->visibleContentRect(/* includeScrollbars */ true).height();
- InspectorInstrumentation::applyScreenHeightOverride(m_frame, &height);
- return view->mapFromLayoutToCSSUnits(static_cast<int>(height));
+ // If the device height is overridden, do not include the horizontal scrollbar into the innerHeight (since it is absent on the real device).
+ bool includeScrollbars = !InspectorInstrumentation::shouldApplyScreenHeightOverride(m_frame);
+ return view->mapFromLayoutToCSSUnits(static_cast<int>(view->visibleContentRect(includeScrollbars).height()));
}
int DOMWindow::innerWidth() const
if (!view)
return 0;
- long width = view->visibleContentRect(/* includeScrollbars */ true).width();
- InspectorInstrumentation::applyScreenWidthOverride(m_frame, &width);
- return view->mapFromLayoutToCSSUnits(static_cast<int>(width));
+ // If the device width is overridden, do not include the vertical scrollbar into the innerWidth (since it is absent on the real device).
+ bool includeScrollbars = !InspectorInstrumentation::shouldApplyScreenWidthOverride(m_frame);
+ return view->mapFromLayoutToCSSUnits(static_cast<int>(view->visibleContentRect(includeScrollbars).width()));
}
int DOMWindow::screenX() const
+2012-04-09 Alexander Pavlov <apavlov@chromium.org>
+
+ Web Inspector: [Device Metrics] Introduce the "Fit window" option
+ https://bugs.webkit.org/show_bug.cgi?id=83280
+
+ Implement the scaling of the FrameView to the WebViewImpl size, handle WebViewImpl resizes.
+
+ Reviewed by Pavel Feldman.
+
+ * src/InspectorClientImpl.cpp:
+ (WebKit::InspectorClientImpl::overrideDeviceMetrics):
+ * src/InspectorClientImpl.h:
+ (InspectorClientImpl):
+ * src/WebDevToolsAgentImpl.cpp:
+ (WebKit::DeviceMetricsSupport::DeviceMetricsSupport):
+ (WebKit::DeviceMetricsSupport::setDeviceMetrics):
+ (WebKit::DeviceMetricsSupport::autoZoomPageToFitWidthOnNavigation):
+ (DeviceMetricsSupport):
+ (WebKit::DeviceMetricsSupport::autoZoomPageToFitWidth):
+ (WebKit::DeviceMetricsSupport::webViewResized):
+ (WebKit::DeviceMetricsSupport::applySizeOverrideIfNecessary):
+ (WebKit::DeviceMetricsSupport::ensureOriginalZoomFactor):
+ (WebKit::DeviceMetricsSupport::restore):
+ (WebKit::DeviceMetricsSupport::scaledEmulatedFrameSize):
+ (WebKit::DeviceMetricsSupport::forcedScrollbarDimensions):
+ (WebKit::DeviceMetricsSupport::applySizeOverrideInternal):
+ (WebKit::WebDevToolsAgentImpl::webViewResized):
+ (WebKit):
+ (WebKit::WebDevToolsAgentImpl::overrideDeviceMetrics):
+ (WebKit::WebDevToolsAgentImpl::autoZoomPageToFitWidth):
+ * src/WebDevToolsAgentImpl.h:
+ (WebDevToolsAgentImpl):
+ * src/WebDevToolsAgentPrivate.h:
+ (WebDevToolsAgentPrivate):
+ * src/WebViewImpl.cpp:
+ (WebKit::WebViewImpl::resize):
+
2012-04-09 Kent Tamura <tkent@chromium.org>
[Chromium] Remove unused variable, WebViewImpl::m_lastMousePosition.
return true;
}
-void InspectorClientImpl::overrideDeviceMetrics(int width, int height, float fontScaleFactor)
+void InspectorClientImpl::overrideDeviceMetrics(int width, int height, float fontScaleFactor, bool fitWindow)
{
if (WebDevToolsAgentImpl* agent = devToolsAgent())
- agent->overrideDeviceMetrics(width, height, fontScaleFactor);
+ agent->overrideDeviceMetrics(width, height, fontScaleFactor, fitWindow);
}
void InspectorClientImpl::autoZoomPageToFitWidth()
virtual void clearBrowserCookies();
virtual bool canOverrideDeviceMetrics();
- virtual void overrideDeviceMetrics(int, int, float);
+ virtual void overrideDeviceMetrics(int, int, float, bool);
virtual void autoZoomPageToFitWidth();
private:
#include "WebViewClient.h"
#include "WebViewImpl.h"
#include <wtf/CurrentTime.h>
+#include <wtf/MathExtras.h>
#include <wtf/Noncopyable.h>
#include <wtf/OwnPtr.h>
using namespace WebCore;
+using namespace std;
namespace OverlayZOrders {
static const int viewportGutter = 97;
public:
DeviceMetricsSupport(WebViewImpl* webView)
: m_webView(webView)
+ , m_fitWindow(false)
+ , m_originalZoomFactor(0)
{
m_webView->addPageOverlay(this, OverlayZOrders::viewportGutter);
}
m_webView->removePageOverlay(this);
}
- void setDeviceMetrics(int width, int height, float textZoomFactor)
+ void setDeviceMetrics(int width, int height, float textZoomFactor, bool fitWindow)
{
WebCore::FrameView* view = frameView();
if (!view)
return;
m_emulatedFrameSize = WebSize(width, height);
+ m_fitWindow = fitWindow;
+ m_originalZoomFactor = 0;
m_webView->setEmulatedTextZoomFactor(textZoomFactor);
- applySizeOverrideInternal(view, width, height);
+ applySizeOverrideInternal(view, FitWindowAllowed);
autoZoomPageToFitWidth(view->frame());
m_webView->sendResizeEventAndRepaint();
}
+ void autoZoomPageToFitWidthOnNavigation(Frame* frame)
+ {
+ FrameView* frameView = frame->view();
+ applySizeOverrideInternal(frameView, FitWindowNotAllowed);
+ m_originalZoomFactor = 0;
+ applySizeOverrideInternal(frameView, FitWindowAllowed);
+ autoZoomPageToFitWidth(frame);
+ }
+
void autoZoomPageToFitWidth(Frame* frame)
{
if (!frame)
return;
- m_webView->setZoomLevel(false, 0);
+ frame->setTextZoomFactor(m_webView->emulatedTextZoomFactor());
+ WebSize scaledFrameSize = scaledEmulatedFrameSize(frame->view());
+ ensureOriginalZoomFactor(frame->view());
+ double sizeRatio = static_cast<double>(scaledFrameSize.width) / m_emulatedFrameSize.width;
+ frame->setPageAndTextZoomFactors(sizeRatio * m_originalZoomFactor, m_webView->emulatedTextZoomFactor());
+ Document* doc = frame->document();
+ doc->styleSelectorChanged(RecalcStyleImmediately);
+ doc->updateLayout();
+ }
- float zoomFactor = static_cast<float>(m_emulatedFrameSize.width) / frame->view()->contentsWidth();
- frame->setPageAndTextZoomFactors(zoomFactor, m_webView->emulatedTextZoomFactor());
+ void webViewResized()
+ {
+ if (!m_fitWindow)
+ return;
+
+ applySizeOverrideIfNecessary();
+ autoZoomPageToFitWidth(m_webView->mainFrameImpl()->frame());
}
void applySizeOverrideIfNecessary()
if (!view)
return;
- applySizeOverrideInternal(view, m_emulatedFrameSize.width, m_emulatedFrameSize.height);
+ applySizeOverrideInternal(view, FitWindowAllowed);
}
private:
+ enum FitWindowFlag { FitWindowAllowed, FitWindowNotAllowed };
+
+ void ensureOriginalZoomFactor(FrameView* frameView)
+ {
+ if (m_originalZoomFactor)
+ return;
+
+ m_webView->setPageScaleFactor(1, WebPoint());
+ m_webView->setZoomLevel(false, 0);
+ WebSize scaledEmulatedSize = scaledEmulatedFrameSize(frameView);
+ m_originalZoomFactor = static_cast<double>(scaledEmulatedSize.width) / frameView->contentsWidth();
+ }
+
void restore()
{
m_webView->setZoomLevel(false, 0);
- m_webView->sendResizeEventAndRepaint();
m_webView->setEmulatedTextZoomFactor(1);
WebCore::FrameView* view = frameView();
- if (!view)
+ if (!view) {
+ m_webView->sendResizeEventAndRepaint();
return;
+ }
view->setHorizontalScrollbarLock(false);
view->setVerticalScrollbarLock(false);
view->setScrollbarModes(ScrollbarAuto, ScrollbarAuto, false, false);
view->resize(IntSize(m_webView->size()));
+ m_webView->sendResizeEventAndRepaint();
+ }
+
+ WebSize scaledEmulatedFrameSize(FrameView* frameView)
+ {
+ if (!m_fitWindow)
+ return m_emulatedFrameSize;
+
+ WebSize scrollbarDimensions = forcedScrollbarDimensions(frameView);
+
+ int overrideWidth = m_emulatedFrameSize.width;
+ int overrideHeight = m_emulatedFrameSize.height;
+
+ WebSize webViewSize = m_webView->size();
+ int availableViewWidth = webViewSize.width - scrollbarDimensions.width;
+ int availableViewHeight = webViewSize.height - scrollbarDimensions.height;
+
+ double widthRatio = static_cast<double>(overrideWidth) / availableViewWidth;
+ double heightRatio = static_cast<double>(overrideHeight) / availableViewHeight;
+ double dimensionRatio = max(widthRatio, heightRatio);
+ overrideWidth = static_cast<int>(ceil(static_cast<double>(overrideWidth) / dimensionRatio));
+ overrideHeight = static_cast<int>(ceil(static_cast<double>(overrideHeight) / dimensionRatio));
+
+ return WebSize(overrideWidth, overrideHeight);
}
- void applySizeOverrideInternal(FrameView* frameView, int overrideWidth, int overrideHeight)
+ WebSize forcedScrollbarDimensions(FrameView* frameView)
{
frameView->setScrollbarModes(ScrollbarAlwaysOn, ScrollbarAlwaysOn, true, true);
+
+ int verticalScrollbarWidth = 0;
+ int horizontalScrollbarHeight = 0;
if (Scrollbar* verticalBar = frameView->verticalScrollbar())
- overrideWidth += !verticalBar->isOverlayScrollbar() ? verticalBar->width() : 0;
+ verticalScrollbarWidth = !verticalBar->isOverlayScrollbar() ? verticalBar->width() : 0;
if (Scrollbar* horizontalBar = frameView->horizontalScrollbar())
- overrideHeight += !horizontalBar->isOverlayScrollbar() ? horizontalBar->height() : 0;
+ horizontalScrollbarHeight = !horizontalBar->isOverlayScrollbar() ? horizontalBar->height() : 0;
+ return WebSize(verticalScrollbarWidth, horizontalScrollbarHeight);
+ }
+
+ void applySizeOverrideInternal(FrameView* frameView, FitWindowFlag fitWindowFlag)
+ {
+ WebSize scrollbarDimensions = forcedScrollbarDimensions(frameView);
+
+ WebSize effectiveEmulatedSize = (fitWindowFlag == FitWindowAllowed) ? scaledEmulatedFrameSize(frameView) : m_emulatedFrameSize;
+ int overrideWidth = effectiveEmulatedSize.width + scrollbarDimensions.width;
+ int overrideHeight = effectiveEmulatedSize.height + scrollbarDimensions.height;
if (IntSize(overrideWidth, overrideHeight) != frameView->size())
frameView->resize(overrideWidth, overrideHeight);
Document* doc = frameView->frame()->document();
- doc->recalcStyle(Node::Force);
+ doc->styleSelectorChanged(RecalcStyleImmediately);
doc->updateLayout();
}
WebViewImpl* m_webView;
WebSize m_emulatedFrameSize;
+ bool m_fitWindow;
+ double m_originalZoomFactor;
};
return !!m_metricsSupport;
}
-void WebDevToolsAgentImpl::overrideDeviceMetrics(int width, int height, float fontScaleFactor)
+void WebDevToolsAgentImpl::webViewResized()
+{
+ if (m_metricsSupport)
+ m_metricsSupport->webViewResized();
+}
+
+void WebDevToolsAgentImpl::overrideDeviceMetrics(int width, int height, float fontScaleFactor, bool fitWindow)
{
if (!width && !height) {
if (m_metricsSupport)
if (!m_metricsSupport)
m_metricsSupport = adoptPtr(new DeviceMetricsSupport(m_webViewImpl));
- m_metricsSupport->setDeviceMetrics(width, height, fontScaleFactor);
+ m_metricsSupport->setDeviceMetrics(width, height, fontScaleFactor, fitWindow);
}
void WebDevToolsAgentImpl::autoZoomPageToFitWidth()
{
if (m_metricsSupport)
- m_metricsSupport->autoZoomPageToFitWidth(m_webViewImpl->mainFrameImpl()->frame());
+ m_metricsSupport->autoZoomPageToFitWidthOnNavigation(m_webViewImpl->mainFrameImpl()->frame());
}
void WebDevToolsAgentImpl::dispatchOnInspectorBackend(const WebString& message)
virtual void didClearWindowObject(WebFrameImpl*);
virtual void mainFrameViewCreated(WebFrameImpl*);
virtual bool metricsOverridden();
+ virtual void webViewResized();
// WebDevToolsAgent implementation.
virtual void attach();
virtual void clearBrowserCache();
virtual void clearBrowserCookies();
- virtual void overrideDeviceMetrics(int width, int height, float fontScaleFactor);
+ virtual void overrideDeviceMetrics(int width, int height, float fontScaleFactor, bool fitWindow);
virtual void autoZoomPageToFitWidth();
int hostId() { return m_hostId; }
// Returns true if the device metrics override mode is enabled.
virtual bool metricsOverridden() = 0;
+
+ // WebViewImpl has been resized.
+ virtual void webViewResized() = 0;
};
} // namespace WebKit
return;
m_size = newSize;
- if (!devToolsAgentPrivate() || !devToolsAgentPrivate()->metricsOverridden()) {
+ WebDevToolsAgentPrivate* agentPrivate = devToolsAgentPrivate();
+ if (agentPrivate && agentPrivate->metricsOverridden())
+ agentPrivate->webViewResized();
+ else {
WebFrameImpl* webFrame = mainFrameImpl();
if (webFrame->frameView())
webFrame->frameView()->resize(newSize.width, newSize.height);