Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: third_party/WebKit/Source/web/InspectorEmulationAgent.cpp

Issue 2237433004: Adds DevTools commands for forced viewport override. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address Dmitry's comments + sync. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "web/InspectorEmulationAgent.h" 5 #include "web/InspectorEmulationAgent.h"
6 6
7 #include "core/frame/FrameHost.h" 7 #include "core/frame/FrameHost.h"
8 #include "core/frame/FrameView.h" 8 #include "core/frame/FrameView.h"
9 #include "core/frame/Settings.h" 9 #include "core/frame/Settings.h"
10 #include "core/page/Page.h" 10 #include "core/page/Page.h"
11 #include "platform/geometry/DoubleRect.h" 11 #include "platform/geometry/DoubleRect.h"
12 #include "public/platform/Platform.h" 12 #include "public/platform/Platform.h"
13 #include "public/platform/WebFloatPoint.h"
13 #include "public/platform/WebThread.h" 14 #include "public/platform/WebThread.h"
14 #include "public/platform/WebViewScheduler.h" 15 #include "public/platform/WebViewScheduler.h"
15 #include "web/DevToolsEmulator.h" 16 #include "web/DevToolsEmulator.h"
16 #include "web/WebLocalFrameImpl.h" 17 #include "web/WebLocalFrameImpl.h"
17 #include "web/WebViewImpl.h" 18 #include "web/WebViewImpl.h"
18 19
19 namespace blink { 20 namespace blink {
20 21
21 namespace EmulationAgentState { 22 namespace EmulationAgentState {
22 static const char scriptExecutionDisabled[] = "scriptExecutionDisabled"; 23 static const char scriptExecutionDisabled[] = "scriptExecutionDisabled";
23 static const char touchEventEmulationEnabled[] = "touchEventEmulationEnabled"; 24 static const char touchEventEmulationEnabled[] = "touchEventEmulationEnabled";
24 static const char emulatedMedia[] = "emulatedMedia"; 25 static const char emulatedMedia[] = "emulatedMedia";
26 static const char forcedViewportEnabled[] = "forcedViewportEnabled";
27 static const char forcedViewportX[] = "forcedViewportX";
28 static const char forcedViewportY[] = "forcedViewportY";
29 static const char forcedViewportScale[] = "forcedViewportScale";
25 } 30 }
26 31
27 InspectorEmulationAgent* InspectorEmulationAgent::create(WebLocalFrameImpl* webL ocalFrameImpl, Client* client) 32 InspectorEmulationAgent* InspectorEmulationAgent::create(WebLocalFrameImpl* webL ocalFrameImpl, Client* client)
28 { 33 {
29 return new InspectorEmulationAgent(webLocalFrameImpl, client); 34 return new InspectorEmulationAgent(webLocalFrameImpl, client);
30 } 35 }
31 36
32 InspectorEmulationAgent::InspectorEmulationAgent(WebLocalFrameImpl* webLocalFram eImpl, Client* client) 37 InspectorEmulationAgent::InspectorEmulationAgent(WebLocalFrameImpl* webLocalFram eImpl, Client* client)
33 : m_webLocalFrameImpl(webLocalFrameImpl) 38 : m_webLocalFrameImpl(webLocalFrameImpl)
34 , m_client(client) 39 , m_client(client)
(...skipping 11 matching lines...) Expand all
46 } 51 }
47 52
48 void InspectorEmulationAgent::restore() 53 void InspectorEmulationAgent::restore()
49 { 54 {
50 ErrorString error; 55 ErrorString error;
51 setScriptExecutionDisabled(&error, m_state->booleanProperty(EmulationAgentSt ate::scriptExecutionDisabled, false)); 56 setScriptExecutionDisabled(&error, m_state->booleanProperty(EmulationAgentSt ate::scriptExecutionDisabled, false));
52 setTouchEmulationEnabled(&error, m_state->booleanProperty(EmulationAgentStat e::touchEventEmulationEnabled, false), protocol::Maybe<String>()); 57 setTouchEmulationEnabled(&error, m_state->booleanProperty(EmulationAgentStat e::touchEventEmulationEnabled, false), protocol::Maybe<String>());
53 String emulatedMedia; 58 String emulatedMedia;
54 m_state->getString(EmulationAgentState::emulatedMedia, &emulatedMedia); 59 m_state->getString(EmulationAgentState::emulatedMedia, &emulatedMedia);
55 setEmulatedMedia(&error, emulatedMedia); 60 setEmulatedMedia(&error, emulatedMedia);
61 if (m_state->booleanProperty(EmulationAgentState::forcedViewportEnabled, fal se)) {
62 forceViewport(&error, m_state->doubleProperty(EmulationAgentState::force dViewportX, 0), m_state->doubleProperty(EmulationAgentState::forcedViewportY, 0) , m_state->doubleProperty(EmulationAgentState::forcedViewportScale, 1));
63 }
56 } 64 }
57 65
58 void InspectorEmulationAgent::disable(ErrorString*) 66 void InspectorEmulationAgent::disable(ErrorString*)
59 { 67 {
60 ErrorString error; 68 ErrorString error;
61 setScriptExecutionDisabled(&error, false); 69 setScriptExecutionDisabled(&error, false);
62 setTouchEmulationEnabled(&error, false, protocol::Maybe<String>()); 70 setTouchEmulationEnabled(&error, false, protocol::Maybe<String>());
63 setEmulatedMedia(&error, String()); 71 setEmulatedMedia(&error, String());
72 resetViewport(&error);
73 }
74
75 void InspectorEmulationAgent::forceViewport(ErrorString* error, double x, double y, double scale)
76 {
77 if (x < 0 || y < 0) {
78 *error = "Coordinates must be non-negative";
79 return;
80 }
81
82 if (scale <= 0) {
83 *error = "Scale must be positive";
84 return;
85 }
86
87 m_state->setBoolean(EmulationAgentState::forcedViewportEnabled, true);
88 m_state->setDouble(EmulationAgentState::forcedViewportX, x);
89 m_state->setDouble(EmulationAgentState::forcedViewportY, y);
90 m_state->setDouble(EmulationAgentState::forcedViewportScale, scale);
91
92 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.
93 webViewImpl()->devToolsEmulator()->forceViewport(position, scale);
94 }
95
96 void InspectorEmulationAgent::resetViewport(ErrorString*)
97 {
98 m_state->setBoolean(EmulationAgentState::forcedViewportEnabled, false);
99 webViewImpl()->devToolsEmulator()->resetViewport();
64 } 100 }
65 101
66 void InspectorEmulationAgent::resetPageScaleFactor(ErrorString*) 102 void InspectorEmulationAgent::resetPageScaleFactor(ErrorString*)
67 { 103 {
68 webViewImpl()->resetScaleStateImmediately(); 104 webViewImpl()->resetScaleStateImmediately();
69 } 105 }
70 106
71 void InspectorEmulationAgent::setPageScaleFactor(ErrorString*, double pageScaleF actor) 107 void InspectorEmulationAgent::setPageScaleFactor(ErrorString*, double pageScaleF actor)
72 { 108 {
73 webViewImpl()->setPageScaleFactor(static_cast<float>(pageScaleFactor)); 109 webViewImpl()->setPageScaleFactor(static_cast<float>(pageScaleFactor));
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 frontend()->virtualTimeBudgetExpired(); 156 frontend()->virtualTimeBudgetExpired();
121 } 157 }
122 158
123 DEFINE_TRACE(InspectorEmulationAgent) 159 DEFINE_TRACE(InspectorEmulationAgent)
124 { 160 {
125 visitor->trace(m_webLocalFrameImpl); 161 visitor->trace(m_webLocalFrameImpl);
126 InspectorBaseAgent::trace(visitor); 162 InspectorBaseAgent::trace(visitor);
127 } 163 }
128 164
129 } // namespace blink 165 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698