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

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: Adress 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 "platform/scheduler/CancellableTaskFactory.h" 12 #include "platform/scheduler/CancellableTaskFactory.h"
13 #include "public/platform/Platform.h" 13 #include "public/platform/Platform.h"
14 #include "public/platform/WebFloatPoint.h"
14 #include "public/platform/WebThread.h" 15 #include "public/platform/WebThread.h"
15 #include "public/platform/WebViewScheduler.h" 16 #include "public/platform/WebViewScheduler.h"
16 #include "web/DevToolsEmulator.h" 17 #include "web/DevToolsEmulator.h"
17 #include "web/WebLocalFrameImpl.h" 18 #include "web/WebLocalFrameImpl.h"
18 #include "web/WebViewImpl.h" 19 #include "web/WebViewImpl.h"
19 20
20 namespace blink { 21 namespace blink {
21 22
22 namespace EmulationAgentState { 23 namespace EmulationAgentState {
23 static const char scriptExecutionDisabled[] = "scriptExecutionDisabled"; 24 static const char scriptExecutionDisabled[] = "scriptExecutionDisabled";
24 static const char touchEventEmulationEnabled[] = "touchEventEmulationEnabled"; 25 static const char touchEventEmulationEnabled[] = "touchEventEmulationEnabled";
25 static const char emulatedMedia[] = "emulatedMedia"; 26 static const char emulatedMedia[] = "emulatedMedia";
27 static const char forcedViewportEnabled[] = "forcedViewportEnabled";
28 static const char forcedViewportX[] = "forcedViewportX";
29 static const char forcedViewportY[] = "forcedViewportY";
30 static const char forcedViewportScale[] = "forcedViewportScale";
26 } 31 }
27 32
28 InspectorEmulationAgent* InspectorEmulationAgent::create(WebLocalFrameImpl* webL ocalFrameImpl, Client* client) 33 InspectorEmulationAgent* InspectorEmulationAgent::create(WebLocalFrameImpl* webL ocalFrameImpl, Client* client)
29 { 34 {
30 return new InspectorEmulationAgent(webLocalFrameImpl, client); 35 return new InspectorEmulationAgent(webLocalFrameImpl, client);
31 } 36 }
32 37
33 InspectorEmulationAgent::InspectorEmulationAgent(WebLocalFrameImpl* webLocalFram eImpl, Client* client) 38 InspectorEmulationAgent::InspectorEmulationAgent(WebLocalFrameImpl* webLocalFram eImpl, Client* client)
34 : m_webLocalFrameImpl(webLocalFrameImpl) 39 : m_webLocalFrameImpl(webLocalFrameImpl)
35 , m_client(client) 40 , m_client(client)
(...skipping 11 matching lines...) Expand all
47 } 52 }
48 53
49 void InspectorEmulationAgent::restore() 54 void InspectorEmulationAgent::restore()
50 { 55 {
51 ErrorString error; 56 ErrorString error;
52 setScriptExecutionDisabled(&error, m_state->booleanProperty(EmulationAgentSt ate::scriptExecutionDisabled, false)); 57 setScriptExecutionDisabled(&error, m_state->booleanProperty(EmulationAgentSt ate::scriptExecutionDisabled, false));
53 setTouchEmulationEnabled(&error, m_state->booleanProperty(EmulationAgentStat e::touchEventEmulationEnabled, false), protocol::Maybe<String>()); 58 setTouchEmulationEnabled(&error, m_state->booleanProperty(EmulationAgentStat e::touchEventEmulationEnabled, false), protocol::Maybe<String>());
54 String emulatedMedia; 59 String emulatedMedia;
55 m_state->getString(EmulationAgentState::emulatedMedia, &emulatedMedia); 60 m_state->getString(EmulationAgentState::emulatedMedia, &emulatedMedia);
56 setEmulatedMedia(&error, emulatedMedia); 61 setEmulatedMedia(&error, emulatedMedia);
62 if (m_state->booleanProperty(EmulationAgentState::forcedViewportEnabled, fal se)) {
63 forceViewport(&error, m_state->doubleProperty(EmulationAgentState::force dViewportX, 0), m_state->doubleProperty(EmulationAgentState::forcedViewportY, 0) , m_state->doubleProperty(EmulationAgentState::forcedViewportScale, 1));
64 }
57 } 65 }
58 66
59 void InspectorEmulationAgent::disable(ErrorString*) 67 void InspectorEmulationAgent::disable(ErrorString*)
60 { 68 {
61 ErrorString error; 69 ErrorString error;
62 setScriptExecutionDisabled(&error, false); 70 setScriptExecutionDisabled(&error, false);
63 setTouchEmulationEnabled(&error, false, protocol::Maybe<String>()); 71 setTouchEmulationEnabled(&error, false, protocol::Maybe<String>());
64 setEmulatedMedia(&error, String()); 72 setEmulatedMedia(&error, String());
73 resetViewport(&error);
74 }
75
76 void InspectorEmulationAgent::forceViewport(ErrorString* error, double x, double y, double scale)
77 {
78 if (x < 0 || y < 0) {
79 *error = "Coordinates must be non-negative";
80 return;
81 }
82
83 if (scale <= 0) {
84 *error = "Scale must be positive";
85 return;
86 }
87
88 m_state->setBoolean(EmulationAgentState::forcedViewportEnabled, true);
89 m_state->setDouble(EmulationAgentState::forcedViewportX, x);
90 m_state->setDouble(EmulationAgentState::forcedViewportY, y);
91 m_state->setDouble(EmulationAgentState::forcedViewportScale, scale);
92
93 webViewImpl()->devToolsEmulator()->forceViewport(WebFloatPoint(x, y), scale) ;
94 }
95
96 void InspectorEmulationAgent::resetViewport(ErrorString*)
97 {
98 m_state->setBoolean(EmulationAgentState::forcedViewportEnabled, false);
99 webViewImpl()->devToolsEmulator()->resetViewport();
65 } 100 }
66 101
67 void InspectorEmulationAgent::resetPageScaleFactor(ErrorString*) 102 void InspectorEmulationAgent::resetPageScaleFactor(ErrorString*)
68 { 103 {
69 webViewImpl()->resetScaleStateImmediately(); 104 webViewImpl()->resetScaleStateImmediately();
70 } 105 }
71 106
72 void InspectorEmulationAgent::setPageScaleFactor(ErrorString*, double pageScaleF actor) 107 void InspectorEmulationAgent::setPageScaleFactor(ErrorString*, double pageScaleF actor)
73 { 108 {
74 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
121 frontend()->virtualTimeBudgetExpired(); 156 frontend()->virtualTimeBudgetExpired();
122 } 157 }
123 158
124 DEFINE_TRACE(InspectorEmulationAgent) 159 DEFINE_TRACE(InspectorEmulationAgent)
125 { 160 {
126 visitor->trace(m_webLocalFrameImpl); 161 visitor->trace(m_webLocalFrameImpl);
127 InspectorBaseAgent::trace(visitor); 162 InspectorBaseAgent::trace(visitor);
128 } 163 }
129 164
130 } // namespace blink 165 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/InspectorEmulationAgent.h ('k') | third_party/WebKit/Source/web/WebViewImpl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698