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

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

Issue 2643723008: [devtools] Add a command to emulate the default background color. (Closed)
Patch Set: Force lifecycle update to CompositingCleanPlusScrolling. Created 3 years, 10 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/inspector/protocol/DOM.h"
10 #include "core/page/Page.h" 11 #include "core/page/Page.h"
11 #include "platform/geometry/DoubleRect.h" 12 #include "platform/geometry/DoubleRect.h"
13 #include "platform/graphics/Color.h"
12 #include "public/platform/Platform.h" 14 #include "public/platform/Platform.h"
13 #include "public/platform/WebFloatPoint.h" 15 #include "public/platform/WebFloatPoint.h"
14 #include "public/platform/WebThread.h" 16 #include "public/platform/WebThread.h"
15 #include "public/platform/WebViewScheduler.h" 17 #include "public/platform/WebViewScheduler.h"
16 #include "web/DevToolsEmulator.h" 18 #include "web/DevToolsEmulator.h"
17 #include "web/WebLocalFrameImpl.h" 19 #include "web/WebLocalFrameImpl.h"
18 #include "web/WebViewImpl.h" 20 #include "web/WebViewImpl.h"
19 21
20 namespace blink { 22 namespace blink {
21 23
22 namespace EmulationAgentState { 24 namespace EmulationAgentState {
23 static const char scriptExecutionDisabled[] = "scriptExecutionDisabled"; 25 static const char scriptExecutionDisabled[] = "scriptExecutionDisabled";
24 static const char touchEventEmulationEnabled[] = "touchEventEmulationEnabled"; 26 static const char touchEventEmulationEnabled[] = "touchEventEmulationEnabled";
25 static const char emulatedMedia[] = "emulatedMedia"; 27 static const char emulatedMedia[] = "emulatedMedia";
26 static const char forcedViewportEnabled[] = "forcedViewportEnabled"; 28 static const char forcedViewportEnabled[] = "forcedViewportEnabled";
27 static const char forcedViewportX[] = "forcedViewportX"; 29 static const char forcedViewportX[] = "forcedViewportX";
28 static const char forcedViewportY[] = "forcedViewportY"; 30 static const char forcedViewportY[] = "forcedViewportY";
29 static const char forcedViewportScale[] = "forcedViewportScale"; 31 static const char forcedViewportScale[] = "forcedViewportScale";
32 static const char defaultBackgroundColorOverrideRGBA[] =
33 "defaultBackgroundColorOverrideRGBA";
30 } 34 }
31 35
32 InspectorEmulationAgent* InspectorEmulationAgent::create( 36 InspectorEmulationAgent* InspectorEmulationAgent::create(
33 WebLocalFrameImpl* webLocalFrameImpl, 37 WebLocalFrameImpl* webLocalFrameImpl,
34 Client* client) { 38 Client* client) {
35 return new InspectorEmulationAgent(webLocalFrameImpl, client); 39 return new InspectorEmulationAgent(webLocalFrameImpl, client);
36 } 40 }
37 41
38 InspectorEmulationAgent::InspectorEmulationAgent( 42 InspectorEmulationAgent::InspectorEmulationAgent(
39 WebLocalFrameImpl* webLocalFrameImpl, 43 WebLocalFrameImpl* webLocalFrameImpl,
(...skipping 17 matching lines...) Expand all
57 m_state->getString(EmulationAgentState::emulatedMedia, &emulatedMedia); 61 m_state->getString(EmulationAgentState::emulatedMedia, &emulatedMedia);
58 setEmulatedMedia(emulatedMedia); 62 setEmulatedMedia(emulatedMedia);
59 if (m_state->booleanProperty(EmulationAgentState::forcedViewportEnabled, 63 if (m_state->booleanProperty(EmulationAgentState::forcedViewportEnabled,
60 false)) { 64 false)) {
61 forceViewport( 65 forceViewport(
62 66
63 m_state->doubleProperty(EmulationAgentState::forcedViewportX, 0), 67 m_state->doubleProperty(EmulationAgentState::forcedViewportX, 0),
64 m_state->doubleProperty(EmulationAgentState::forcedViewportY, 0), 68 m_state->doubleProperty(EmulationAgentState::forcedViewportY, 0),
65 m_state->doubleProperty(EmulationAgentState::forcedViewportScale, 1)); 69 m_state->doubleProperty(EmulationAgentState::forcedViewportScale, 1));
66 } 70 }
71 auto rgbaValue =
72 m_state->get(EmulationAgentState::defaultBackgroundColorOverrideRGBA);
73 if (rgbaValue) {
74 blink::protocol::ErrorSupport errors;
75 auto rgba = protocol::DOM::RGBA::fromValue(rgbaValue, &errors);
76 if (!errors.hasErrors()) {
77 setDefaultBackgroundColorOverride(
78 Maybe<protocol::DOM::RGBA>(std::move(rgba)));
79 }
80 }
67 } 81 }
68 82
69 Response InspectorEmulationAgent::disable() { 83 Response InspectorEmulationAgent::disable() {
70 setScriptExecutionDisabled(false); 84 setScriptExecutionDisabled(false);
71 setTouchEmulationEnabled(false, Maybe<String>()); 85 setTouchEmulationEnabled(false, Maybe<String>());
72 setEmulatedMedia(String()); 86 setEmulatedMedia(String());
73 setCPUThrottlingRate(1); 87 setCPUThrottlingRate(1);
74 resetViewport(); 88 resetViewport();
89 setDefaultBackgroundColorOverride(Maybe<protocol::DOM::RGBA>());
75 return Response::OK(); 90 return Response::OK();
76 } 91 }
77 92
78 Response InspectorEmulationAgent::forceViewport(double x, 93 Response InspectorEmulationAgent::forceViewport(double x,
79 double y, 94 double y,
80 double scale) { 95 double scale) {
81 if (x < 0 || y < 0) 96 if (x < 0 || y < 0)
82 return Response::Error("Coordinates must be non-negative"); 97 return Response::Error("Coordinates must be non-negative");
83 98
84 if (scale <= 0) 99 if (scale <= 0)
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 } 177 }
163 return Response::OK(); 178 return Response::OK();
164 } 179 }
165 180
166 void InspectorEmulationAgent::virtualTimeBudgetExpired() { 181 void InspectorEmulationAgent::virtualTimeBudgetExpired() {
167 m_webLocalFrameImpl->view()->scheduler()->setVirtualTimePolicy( 182 m_webLocalFrameImpl->view()->scheduler()->setVirtualTimePolicy(
168 WebViewScheduler::VirtualTimePolicy::PAUSE); 183 WebViewScheduler::VirtualTimePolicy::PAUSE);
169 frontend()->virtualTimeBudgetExpired(); 184 frontend()->virtualTimeBudgetExpired();
170 } 185 }
171 186
187 Response InspectorEmulationAgent::setDefaultBackgroundColorOverride(
188 Maybe<protocol::DOM::RGBA> color) {
189 if (!color.isJust()) {
190 // Clear the override and state.
191 webViewImpl()->setBaseBackgroundColorOverride(Color::transparent);
192 m_state->remove(EmulationAgentState::defaultBackgroundColorOverrideRGBA);
193 return Response::OK();
194 }
195
196 blink::protocol::DOM::RGBA* rgba = color.fromJust();
197 m_state->setValue(EmulationAgentState::defaultBackgroundColorOverrideRGBA,
198 rgba->toValue());
199 // Clamping of values is done by Color() constructor.
200 int alpha = lroundf(255.0f * rgba->getA(1.0f));
201 webViewImpl()->setBaseBackgroundColorOverride(
202 Color(rgba->getR(), rgba->getG(), rgba->getB(), alpha).rgb());
203 return Response::OK();
204 }
205
172 DEFINE_TRACE(InspectorEmulationAgent) { 206 DEFINE_TRACE(InspectorEmulationAgent) {
173 visitor->trace(m_webLocalFrameImpl); 207 visitor->trace(m_webLocalFrameImpl);
174 InspectorBaseAgent::trace(visitor); 208 InspectorBaseAgent::trace(visitor);
175 } 209 }
176 210
177 } // namespace blink 211 } // 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