https://bugs.webkit.org/show_bug.cgi?id=82827
Source/WebCore:
This change implements the inspector backend for the device metrics override feature,
as well as the respective InspectorClient capability detection.
When a navigation occurs in the override mode, the page auto-zooming ("fit width")
is initiated upon the first layout after the DOMContentLoaded event.
Reviewed by Pavel Feldman.
* inspector/Inspector.json:
* inspector/InspectorClient.h:
(WebCore::InspectorClient::canOverrideDeviceMetrics):
(WebCore::InspectorClient::overrideDeviceMetrics):
(WebCore::InspectorClient::autoZoomPageToFitWidth):
(InspectorClient):
* inspector/InspectorInstrumentation.cpp:
(WebCore::InspectorInstrumentation::didLayoutImpl):
* inspector/InspectorPageAgent.cpp:
(PageAgentState):
(WebCore::InspectorPageAgent::InspectorPageAgent):
(WebCore::InspectorPageAgent::restore):
(WebCore::InspectorPageAgent::disable):
(WebCore::InspectorPageAgent::canOverrideDeviceMetrics):
(WebCore):
(WebCore::InspectorPageAgent::setDeviceMetricsOverride):
(WebCore::InspectorPageAgent::domContentEventFired):
(WebCore::InspectorPageAgent::loadEventFired):
(WebCore::InspectorPageAgent::didLayout):
(WebCore::InspectorPageAgent::updateViewMetrics):
* inspector/InspectorPageAgent.h:
* inspector/InspectorState.cpp:
(WebCore::InspectorState::getDouble):
(WebCore):
* inspector/InspectorState.h:
(InspectorState):
(WebCore::InspectorState::setDouble):
LayoutTests:
Follow the Web Inspector Protocol change.
Reviewed by Pavel Feldman.
* inspector/styles/override-screen-size.html:
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@112864
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2012-03-31 Alexander Pavlov <apavlov@chromium.org>
+
+ Web Inspector: Implement backend for device metrics emulation
+ https://bugs.webkit.org/show_bug.cgi?id=82827
+
+ Follow the Web Inspector Protocol change.
+
+ Reviewed by Pavel Feldman.
+
+ * inspector/styles/override-screen-size.html:
+
2012-04-02 Sheriff Bot <webkit.review.bot@gmail.com>
Unreviewed, rolling out r112813 and r112837.
}
// Disable overrides.
- PageAgent.setScreenSizeOverride(0, 0, overrideCallback);
+ PageAgent.setDeviceMetricsOverride(0, 0, 1, overrideCallback);
}
function step2()
InspectorTest.addResult("Override: " + width + "x" + height + " => ERROR");
userCallback();
}
- PageAgent.setScreenSizeOverride(width, height, callback);
+ PageAgent.setDeviceMetricsOverride(width, height, 1, callback);
}
function overrideAndDumpData(width, height, callback)
+2012-03-31 Alexander Pavlov <apavlov@chromium.org>
+
+ Web Inspector: Implement backend for device metrics emulation
+ https://bugs.webkit.org/show_bug.cgi?id=82827
+
+ This change implements the inspector backend for the device metrics override feature,
+ as well as the respective InspectorClient capability detection.
+ When a navigation occurs in the override mode, the page auto-zooming ("fit width")
+ is initiated upon the first layout after the DOMContentLoaded event.
+
+ Reviewed by Pavel Feldman.
+
+ * inspector/Inspector.json:
+ * inspector/InspectorClient.h:
+ (WebCore::InspectorClient::canOverrideDeviceMetrics):
+ (WebCore::InspectorClient::overrideDeviceMetrics):
+ (WebCore::InspectorClient::autoZoomPageToFitWidth):
+ (InspectorClient):
+ * inspector/InspectorInstrumentation.cpp:
+ (WebCore::InspectorInstrumentation::didLayoutImpl):
+ * inspector/InspectorPageAgent.cpp:
+ (PageAgentState):
+ (WebCore::InspectorPageAgent::InspectorPageAgent):
+ (WebCore::InspectorPageAgent::restore):
+ (WebCore::InspectorPageAgent::disable):
+ (WebCore::InspectorPageAgent::canOverrideDeviceMetrics):
+ (WebCore):
+ (WebCore::InspectorPageAgent::setDeviceMetricsOverride):
+ (WebCore::InspectorPageAgent::domContentEventFired):
+ (WebCore::InspectorPageAgent::loadEventFired):
+ (WebCore::InspectorPageAgent::didLayout):
+ (WebCore::InspectorPageAgent::updateViewMetrics):
+ * inspector/InspectorPageAgent.h:
+ * inspector/InspectorState.cpp:
+ (WebCore::InspectorState::getDouble):
+ (WebCore):
+ * inspector/InspectorState.h:
+ (InspectorState):
+ (WebCore::InspectorState::setDouble):
+
2012-04-02 Sheriff Bot <webkit.review.bot@gmail.com>
Unreviewed, rolling out r112813 and r112837.
"hidden": true
},
{
- "name": "setScreenSizeOverride",
- "description": "Overrides the values of window.screen.width, window.screen.height, window.innerWidth, window.innerHeight, and \"device-width\"/\"device-height\"-related CSS media query results",
+ "name": "canOverrideDeviceMetrics",
+ "description": "Checks whether <code>setDeviceMetricsOverride</code> can be invoked.",
+ "returns": [
+ { "name": "result", "type": "boolean", "description": "If true, <code>setDeviceMetricsOverride</code> can safely be invoked on the agent." }
+ ],
+ "hidden": true
+ },
+ {
+ "name": "setDeviceMetricsOverride",
+ "description": "Overrides the values of device screen dimensions (window.screen.width, window.screen.height, window.innerWidth, window.innerHeight, and \"device-width\"/\"device-height\"-related CSS media query results) and the font scale factor.",
"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": "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." }
],
"hidden": true
},
virtual bool canClearBrowserCookies() { return false; }
virtual void clearBrowserCookies() { }
+ virtual bool canOverrideDeviceMetrics() { return false; }
+ virtual void overrideDeviceMetrics(int /*width*/, int /*height*/, float /*fontScaleFactor*/) {
+ // FIXME: Platforms may want to implement this (see https://bugs.webkit.org/show_bug.cgi?id=82886).
+ }
+ virtual void autoZoomPageToFitWidth() {
+ // FIXME: Platforms may want to implement this (see https://bugs.webkit.org/show_bug.cgi?id=82886).
+ }
+
bool doDispatchMessageOnFrontendPage(Page* frontendPage, const String& message);
};
void InspectorInstrumentation::didLayoutImpl(const InspectorInstrumentationCookie& cookie)
{
+ if (!cookie.first)
+ return;
+
if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie))
timelineAgent->didLayout();
+
+ if (InspectorPageAgent* pageAgent = cookie.first->inspectorPageAgent())
+ pageAgent->didLayout();
}
InspectorInstrumentationCookie InspectorInstrumentation::willLoadXHRImpl(InstrumentingAgents* instrumentingAgents, XMLHttpRequest* request)
static const char pageAgentScriptsToEvaluateOnLoad[] = "pageAgentScriptsToEvaluateOnLoad";
static const char pageAgentScreenWidthOverride[] = "pageAgentScreenWidthOverride";
static const char pageAgentScreenHeightOverride[] = "pageAgentScreenHeightOverride";
+static const char pageAgentFontScaleFactorOverride[] = "pageAgentFontScaleFactorOverride";
static const char showPaintRects[] = "showPaintRects";
}
, m_client(client)
, m_frontend(0)
, m_lastScriptIdentifier(0)
- , m_originalUseFixedLayout(false)
, m_lastPaintContext(0)
+ , m_didLoadEventFire(false)
{
}
// When restoring the agent, override values are restored into the FrameView.
int width = static_cast<int>(m_state->getLong(PageAgentState::pageAgentScreenWidthOverride));
int height = static_cast<int>(m_state->getLong(PageAgentState::pageAgentScreenHeightOverride));
- updateFrameViewFixedLayout(width, height);
+ double fontScaleFactor = m_state->getDouble(PageAgentState::pageAgentFontScaleFactorOverride);
+ updateViewMetrics(width, height, fontScaleFactor);
}
}
// When disabling the agent, reset the override values.
m_state->setLong(PageAgentState::pageAgentScreenWidthOverride, 0);
m_state->setLong(PageAgentState::pageAgentScreenHeightOverride, 0);
- updateFrameViewFixedLayout(0, 0);
+ m_state->setDouble(PageAgentState::pageAgentFontScaleFactorOverride, 1);
+ updateViewMetrics(0, 0, 1);
}
void InspectorPageAgent::addScriptToEvaluateOnLoad(ErrorString*, const String& source, String* identifier)
DOMPatchSupport::patchDocument(document, html);
}
-void InspectorPageAgent::setScreenSizeOverride(ErrorString* errorString, const int width, const int height)
+void InspectorPageAgent::canOverrideDeviceMetrics(ErrorString*, bool* result)
+{
+ *result = m_client->canOverrideDeviceMetrics();
+}
+
+void InspectorPageAgent::setDeviceMetricsOverride(ErrorString* errorString, const int width, const int height, double fontScaleFactor)
{
const static long maxDimension = 10000000;
return;
}
+ if (!width ^ !height) {
+ *errorString = "Both width and height must be either zero or non-zero at once";
+ return;
+ }
+
+ if (fontScaleFactor <= 0) {
+ *errorString = "fontScaleFactor must be positive";
+ return;
+ }
+
// These two always fit an int.
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);
- if (width == currentWidth && height == currentHeight)
+ if (width == currentWidth && height == currentHeight && fontScaleFactor == currentFontScaleFactor)
return;
m_state->setLong(PageAgentState::pageAgentScreenWidthOverride, width);
m_state->setLong(PageAgentState::pageAgentScreenHeightOverride, height);
+ m_state->setDouble(PageAgentState::pageAgentFontScaleFactorOverride, fontScaleFactor);
- updateFrameViewFixedLayout(width, height);
+ updateViewMetrics(width, height, fontScaleFactor);
}
void InspectorPageAgent::setShowPaintRects(ErrorString*, bool show)
void InspectorPageAgent::domContentEventFired()
{
- m_frontend->domContentEventFired(currentTime());
+ m_didLoadEventFire = true;
+ m_frontend->domContentEventFired(currentTime());
}
void InspectorPageAgent::loadEventFired()
{
- m_frontend->loadEventFired(currentTime());
+ m_frontend->loadEventFired(currentTime());
}
void InspectorPageAgent::frameNavigated(DocumentLoader* loader)
m_lastPaintContext = 0;
}
+void InspectorPageAgent::didLayout()
+{
+ if (!m_didLoadEventFire)
+ return;
+
+ m_didLoadEventFire = false;
+ int currentWidth = static_cast<int>(m_state->getLong(PageAgentState::pageAgentScreenWidthOverride));
+ int currentHeight = static_cast<int>(m_state->getLong(PageAgentState::pageAgentScreenHeightOverride));
+
+ if (currentWidth && currentHeight)
+ m_client->autoZoomPageToFitWidth();
+}
+
PassRefPtr<TypeBuilder::Page::Frame> InspectorPageAgent::buildObjectForFrame(Frame* frame)
{
RefPtr<TypeBuilder::Page::Frame> frameObject = TypeBuilder::Page::Frame::create()
return result;
}
-void InspectorPageAgent::updateFrameViewFixedLayout(int width, int height)
+void InspectorPageAgent::updateViewMetrics(int width, int height, double fontScaleFactor)
{
- if (!width && !height)
- clearFrameViewFixedLayout();
- else
- setFrameViewFixedLayout(width, height);
+ m_client->overrideDeviceMetrics(width, height, static_cast<float>(fontScaleFactor));
Document* document = mainFrame()->document();
document->styleSelectorChanged(RecalcStyleImmediately);
InspectorInstrumentation::mediaQueryResultChanged(document);
}
-void InspectorPageAgent::clearFrameViewFixedLayout()
-{
- if (m_originalFixedLayoutSize) {
- // Turning off existing overrides (no-op otherwise) - revert the affected FrameView to the remembered fixed layout settings.
- mainFrame()->view()->setFixedLayoutSize(*m_originalFixedLayoutSize);
- m_originalFixedLayoutSize.clear();
- mainFrame()->view()->setUseFixedLayout(m_originalUseFixedLayout);
- }
-}
-
-void InspectorPageAgent::setFrameViewFixedLayout(int width, int height)
-{
- if (!m_originalFixedLayoutSize) {
- // Turning on the overrides (none currently exist) - remember existing fixed layout for the affected FrameView.
- m_originalFixedLayoutSize = adoptPtr(new IntSize(mainFrame()->view()->fixedLayoutSize()));
- m_originalUseFixedLayout = mainFrame()->view()->useFixedLayout();
- }
-
- mainFrame()->view()->setFixedLayoutSize(IntSize(width, height));
- mainFrame()->view()->setUseFixedLayout(true);
-}
-
} // namespace WebCore
#endif // ENABLE(INSPECTOR)
virtual void searchInResource(ErrorString*, const String& frameId, const String& url, const String& query, const bool* optionalCaseSensitive, const bool* optionalIsRegex, RefPtr<TypeBuilder::Array<TypeBuilder::Page::SearchMatch> >&);
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 setScreenSizeOverride(ErrorString*, int width, int height);
+ virtual void canOverrideDeviceMetrics(ErrorString*, bool*);
+ virtual void setDeviceMetricsOverride(ErrorString*, int width, int height, double fontScaleFactor);
virtual void setShowPaintRects(ErrorString*, bool show);
// InspectorInstrumentation API
void applyScreenHeightOverride(long*);
void willPaint(GraphicsContext*, const LayoutRect&);
void didPaint();
+ void didLayout();
// Inspector Controller API
virtual void setFrontend(InspectorFrontend*);
private:
InspectorPageAgent(InstrumentingAgents*, Page*, InspectorState*, InjectedScriptManager*, InspectorClient*);
- void updateFrameViewFixedLayout(int, int);
- void setFrameViewFixedLayout(int, int);
- void clearFrameViewFixedLayout();
+ void updateViewMetrics(int, int, double);
PassRefPtr<TypeBuilder::Page::Frame> buildObjectForFrame(Frame*);
PassRefPtr<TypeBuilder::Page::FrameResourceTree> buildObjectForFrameTree(Frame*);
HashMap<Frame*, String> m_frameToIdentifier;
HashMap<String, Frame*> m_identifierToFrame;
HashMap<DocumentLoader*, String> m_loaderToIdentifier;
- OwnPtr<IntSize> m_originalFixedLayoutSize;
- bool m_originalUseFixedLayout;
GraphicsContext* m_lastPaintContext;
LayoutRect m_lastPaintRect;
+ bool m_didLoadEventFire;
};
return value;
}
+double InspectorState::getDouble(const String& propertyName)
+{
+ InspectorObject::iterator it = m_properties->find(propertyName);
+ double value = 0;
+ if (it != m_properties->end())
+ it->second->asNumber(&value);
+ return value;
+}
+
PassRefPtr<InspectorObject> InspectorState::getObject(const String& propertyName)
{
InspectorObject::iterator it = m_properties->find(propertyName);
bool getBoolean(const String& propertyName);
String getString(const String& propertyName);
long getLong(const String& propertyName);
+ double getDouble(const String& propertyName);
PassRefPtr<InspectorObject> getObject(const String& propertyName);
void setBoolean(const String& propertyName, bool value) { setValue(propertyName, InspectorBasicValue::create(value)); }
void setString(const String& propertyName, const String& value) { setValue(propertyName, InspectorString::create(value)); }
void setLong(const String& propertyName, long value) { setValue(propertyName, InspectorBasicValue::create((double)value)); }
+ void setDouble(const String& propertyName, double value) { setValue(propertyName, InspectorBasicValue::create(value)); }
void setObject(const String& propertyName, PassRefPtr<InspectorObject> value) { setValue(propertyName, value); }
private: