Index: third_party/WebKit/Source/web/InspectorEmulationAgent.cpp |
diff --git a/third_party/WebKit/Source/web/InspectorEmulationAgent.cpp b/third_party/WebKit/Source/web/InspectorEmulationAgent.cpp |
index 6f5c53ed71d7a2b8efe9a0e4b56311ca6fd258c8..38c9a3c3af8102c8c1c3fe0449a5b5733b633806 100644 |
--- a/third_party/WebKit/Source/web/InspectorEmulationAgent.cpp |
+++ b/third_party/WebKit/Source/web/InspectorEmulationAgent.cpp |
@@ -11,6 +11,7 @@ |
#include "platform/geometry/DoubleRect.h" |
#include "platform/scheduler/CancellableTaskFactory.h" |
#include "public/platform/Platform.h" |
+#include "public/platform/WebFloatPoint.h" |
#include "public/platform/WebThread.h" |
#include "public/platform/WebViewScheduler.h" |
#include "web/DevToolsEmulator.h" |
@@ -23,6 +24,10 @@ namespace EmulationAgentState { |
static const char scriptExecutionDisabled[] = "scriptExecutionDisabled"; |
static const char touchEventEmulationEnabled[] = "touchEventEmulationEnabled"; |
static const char emulatedMedia[] = "emulatedMedia"; |
+static const char forcedViewportEnabled[] = "forcedViewportEnabled"; |
+static const char forcedViewportX[] = "forcedViewportX"; |
+static const char forcedViewportY[] = "forcedViewportY"; |
+static const char forcedViewportScale[] = "forcedViewportScale"; |
} |
InspectorEmulationAgent* InspectorEmulationAgent::create(WebLocalFrameImpl* webLocalFrameImpl, Client* client) |
@@ -54,6 +59,9 @@ void InspectorEmulationAgent::restore() |
String emulatedMedia; |
m_state->getString(EmulationAgentState::emulatedMedia, &emulatedMedia); |
setEmulatedMedia(&error, emulatedMedia); |
+ if (m_state->booleanProperty(EmulationAgentState::forcedViewportEnabled, false)) { |
+ forceViewport(&error, m_state->doubleProperty(EmulationAgentState::forcedViewportX, 0), m_state->doubleProperty(EmulationAgentState::forcedViewportY, 0), m_state->doubleProperty(EmulationAgentState::forcedViewportScale, 1)); |
+ } |
} |
void InspectorEmulationAgent::disable(ErrorString*) |
@@ -62,6 +70,33 @@ void InspectorEmulationAgent::disable(ErrorString*) |
setScriptExecutionDisabled(&error, false); |
setTouchEmulationEnabled(&error, false, protocol::Maybe<String>()); |
setEmulatedMedia(&error, String()); |
+ resetViewport(&error); |
+} |
+ |
+void InspectorEmulationAgent::forceViewport(ErrorString* error, double x, double y, double scale) |
+{ |
+ if (x < 0 || y < 0) { |
+ *error = "Coordinates must be non-negative"; |
+ return; |
+ } |
+ |
+ if (scale <= 0) { |
+ *error = "Scale must be positive"; |
+ return; |
+ } |
+ |
+ m_state->setBoolean(EmulationAgentState::forcedViewportEnabled, true); |
+ m_state->setDouble(EmulationAgentState::forcedViewportX, x); |
+ m_state->setDouble(EmulationAgentState::forcedViewportY, y); |
+ m_state->setDouble(EmulationAgentState::forcedViewportScale, scale); |
+ |
+ webViewImpl()->devToolsEmulator()->forceViewport(WebFloatPoint(x, y), scale); |
+} |
+ |
+void InspectorEmulationAgent::resetViewport(ErrorString*) |
+{ |
+ m_state->setBoolean(EmulationAgentState::forcedViewportEnabled, false); |
+ webViewImpl()->devToolsEmulator()->resetViewport(); |
} |
void InspectorEmulationAgent::resetPageScaleFactor(ErrorString*) |