Web Inspector: [Device Metrics] Introduce the "Fit window" option
authorapavlov@chromium.org <apavlov@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 10 Apr 2012 12:29:15 +0000 (12:29 +0000)
committerapavlov@chromium.org <apavlov@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 10 Apr 2012 12:29:15 +0000 (12:29 +0000)
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

23 files changed:
LayoutTests/ChangeLog
LayoutTests/inspector/styles/override-screen-size-expected.txt
LayoutTests/inspector/styles/override-screen-size.html
Source/WebCore/ChangeLog
Source/WebCore/English.lproj/localizedStrings.js
Source/WebCore/inspector/Inspector.json
Source/WebCore/inspector/InspectorClient.h
Source/WebCore/inspector/InspectorInstrumentation.cpp
Source/WebCore/inspector/InspectorInstrumentation.h
Source/WebCore/inspector/InspectorPageAgent.cpp
Source/WebCore/inspector/InspectorPageAgent.h
Source/WebCore/inspector/front-end/Settings.js
Source/WebCore/inspector/front-end/SettingsScreen.js
Source/WebCore/inspector/front-end/UserAgentSupport.js
Source/WebCore/inspector/front-end/helpScreen.css
Source/WebCore/page/DOMWindow.cpp
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/src/InspectorClientImpl.cpp
Source/WebKit/chromium/src/InspectorClientImpl.h
Source/WebKit/chromium/src/WebDevToolsAgentImpl.cpp
Source/WebKit/chromium/src/WebDevToolsAgentImpl.h
Source/WebKit/chromium/src/WebDevToolsAgentPrivate.h
Source/WebKit/chromium/src/WebViewImpl.cpp

index 9ef3e59..cb0a674 100644 (file)
@@ -1,3 +1,15 @@
+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.
index 3fe27dc..d7e3e73 100644 (file)
@@ -1,8 +1,9 @@
 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  { ()
@@ -19,9 +20,10 @@ div  { (user agent stylesheet)
 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  { ()
@@ -32,13 +34,14 @@ div  { (user agent stylesheet)
 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:
index 71c2b59..fad26d7 100644 (file)
@@ -33,6 +33,7 @@ function getSizes()
 {
     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
     });
 }
@@ -57,7 +58,7 @@ function test()
 
     function step0()
     {
-        overrideAndDumpData(480, 960, step1);
+        overrideAndDumpData(480, 800, step1);
     }
 
     function step1()
@@ -77,22 +78,22 @@ function test()
         }
 
         // 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()
@@ -142,7 +143,6 @@ function test()
         InspectorTest.addResult("Enable PageAgent:");
         PageAgent.enable();
         InspectorTest.evaluateInPage("getSizes()", callback);
-
     }
 
     function applyOverride(width, height, userCallback)
@@ -153,7 +153,7 @@ function test()
                 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)
@@ -180,6 +180,7 @@ function test()
         {
             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();
         }
index 3169d48..388e9d0 100644 (file)
@@ -1,3 +1,46 @@
+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.
index 7e81d37..50da95a 100644 (file)
Binary files a/Source/WebCore/English.lproj/localizedStrings.js and b/Source/WebCore/English.lproj/localizedStrings.js differ
index 27e7827..9add3b6 100644 (file)
                 "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
             },
index 612acd6..b998dbc 100644 (file)
@@ -57,10 +57,12 @@ public:
     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).
     }
 
index 95a451e..c8aace0 100644 (file)
@@ -540,6 +540,26 @@ void InspectorInstrumentation::applyScreenHeightOverrideImpl(InstrumentingAgents
         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())
index a95e71e..e450b9a 100644 (file)
@@ -139,6 +139,8 @@ public:
     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);
@@ -293,6 +295,8 @@ private:
     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);
@@ -884,6 +888,26 @@ inline void InspectorInstrumentation::applyScreenHeightOverride(Frame* frame, lo
 #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)
index 82c01b9..e4d6e1d 100644 (file)
@@ -85,6 +85,7 @@ static const char pageAgentScriptsToEvaluateOnLoad[] = "pageAgentScriptsToEvalua
 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";
 }
 
@@ -338,7 +339,8 @@ void InspectorPageAgent::restore()
         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);
     }
 }
 
@@ -357,7 +359,8 @@ void InspectorPageAgent::disable(ErrorString*)
     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)
@@ -644,7 +647,7 @@ void InspectorPageAgent::canOverrideDeviceMetrics(ErrorString*, bool* result)
     *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;
 
@@ -667,15 +670,17 @@ void InspectorPageAgent::setDeviceMetricsOverride(ErrorString* errorString, cons
     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)
@@ -909,9 +914,9 @@ PassRefPtr<TypeBuilder::Page::FrameResourceTree> InspectorPageAgent::buildObject
     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);
index 43e152d..b81c65d 100644 (file)
@@ -103,7 +103,7 @@ public:
     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
@@ -135,7 +135,7 @@ public:
 
 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*);
index 9342cb5..9365c0a 100644 (file)
@@ -88,6 +88,7 @@ WebInspector.Settings = function()
     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);
index 5d3e4b7..3841c39 100644 (file)
@@ -148,22 +148,29 @@ WebInspector.SettingsScreen.prototype = {
         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;
     },
@@ -518,6 +525,12 @@ WebInspector.SettingsScreen.prototype = {
         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;
     }
 }
index ddf7dac..504752e 100644 (file)
@@ -34,8 +34,9 @@
 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);
 }
 
 /**
@@ -163,10 +164,10 @@ WebInspector.UserAgentSupport.DeviceMetrics.prototype = {
 }
 
 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
index ec0cbef..eee315f 100644 (file)
@@ -203,7 +203,7 @@ body.platform-mac .help-key {
 .help-content input[type=checkbox] {
     height: 13px;
     width: 13px;
-    margin-right: 0;
+    margin-left: 0;
     margin-right: 4px;
 }
 
index 1a8ad71..371af6c 100644 (file)
@@ -1077,9 +1077,9 @@ int DOMWindow::innerHeight() const
     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
@@ -1091,9 +1091,9 @@ 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
index 501577d..000c8d4 100644 (file)
@@ -1,3 +1,40 @@
+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.
index 627055b..28a1881 100644 (file)
@@ -133,10 +133,10 @@ bool InspectorClientImpl::canOverrideDeviceMetrics()
     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()
index 5ccec81..afd86e5 100644 (file)
@@ -65,7 +65,7 @@ public:
     virtual void clearBrowserCookies();
 
     virtual bool canOverrideDeviceMetrics();
-    virtual void overrideDeviceMetrics(int, int, float);
+    virtual void overrideDeviceMetrics(int, int, float, bool);
     virtual void autoZoomPageToFitWidth();
 
 private:
index f742c63..9e18475 100644 (file)
 #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;
@@ -186,6 +188,8 @@ class DeviceMetricsSupport : public WebPageOverlay {
 public:
     DeviceMetricsSupport(WebViewImpl* webView)
         : m_webView(webView)
+        , m_fitWindow(false)
+        , m_originalZoomFactor(0)
     {
         m_webView->addPageOverlay(this, OverlayZOrders::viewportGutter);
     }
@@ -196,29 +200,53 @@ public:
         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()
@@ -227,39 +255,90 @@ public:
         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();
     }
 
@@ -283,6 +362,8 @@ private:
 
     WebViewImpl* m_webView;
     WebSize m_emulatedFrameSize;
+    bool m_fitWindow;
+    double m_originalZoomFactor;
 };
 
 
@@ -355,7 +436,13 @@ bool WebDevToolsAgentImpl::metricsOverridden()
     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)
@@ -365,13 +452,13 @@ void WebDevToolsAgentImpl::overrideDeviceMetrics(int width, int height, float fo
 
     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)
index 98806a4..bf267ca 100644 (file)
@@ -74,6 +74,7 @@ public:
     virtual void didClearWindowObject(WebFrameImpl*);
     virtual void mainFrameViewCreated(WebFrameImpl*);
     virtual bool metricsOverridden();
+    virtual void webViewResized();
 
     // WebDevToolsAgent implementation.
     virtual void attach();
@@ -100,7 +101,7 @@ public:
     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; }
index 929b64a..e864c89 100644 (file)
@@ -51,6 +51,9 @@ public:
 
     // Returns true if the device metrics override mode is enabled.
     virtual bool metricsOverridden() = 0;
+
+    // WebViewImpl has been resized.
+    virtual void webViewResized() = 0;
 };
 
 } // namespace WebKit
index 95056f6..63ebfa0 100644 (file)
@@ -1277,7 +1277,10 @@ void WebViewImpl::resize(const WebSize& newSize)
         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);