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 6f340cb9567d7c609e8ddb6d78853bf3ed5be11e..14c36b75139ec017309a5a0a6215f191ec8e013d 100644 |
--- a/third_party/WebKit/Source/web/InspectorEmulationAgent.cpp |
+++ b/third_party/WebKit/Source/web/InspectorEmulationAgent.cpp |
@@ -10,6 +10,7 @@ |
#include "core/page/Page.h" |
#include "platform/geometry/DoubleRect.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" |
@@ -22,6 +23,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) |
@@ -53,6 +58,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*) |
@@ -61,6 +69,34 @@ 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); |
+ |
+ WebFloatPoint position(x, y); |
dgozman
2016/09/17 01:22:28
nit: can inline below as WebFloatPoint(x, y)
Eric Seckler
2016/09/22 12:43:00
Done.
|
+ webViewImpl()->devToolsEmulator()->forceViewport(position, scale); |
+} |
+ |
+void InspectorEmulationAgent::resetViewport(ErrorString*) |
+{ |
+ m_state->setBoolean(EmulationAgentState::forcedViewportEnabled, false); |
+ webViewImpl()->devToolsEmulator()->resetViewport(); |
} |
void InspectorEmulationAgent::resetPageScaleFactor(ErrorString*) |