Chromium Code Reviews| 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 f661594577ef716c1108aaf48cbcc8102f487974..b501644ae11f78e069fa867b13d241b28e7dc02b 100644 |
| --- a/third_party/WebKit/Source/web/InspectorEmulationAgent.cpp |
| +++ b/third_party/WebKit/Source/web/InspectorEmulationAgent.cpp |
| @@ -4,11 +4,15 @@ |
| #include "web/InspectorEmulationAgent.h" |
| +#include "core/dom/Document.h" |
| +#include "core/dom/DocumentLifecycle.h" |
| #include "core/frame/FrameHost.h" |
| #include "core/frame/FrameView.h" |
| #include "core/frame/Settings.h" |
| +#include "core/inspector/protocol/DOM.h" |
| #include "core/page/Page.h" |
| #include "platform/geometry/DoubleRect.h" |
| +#include "platform/graphics/Color.h" |
| #include "public/platform/Platform.h" |
| #include "public/platform/WebFloatPoint.h" |
| #include "public/platform/WebThread.h" |
| @@ -27,6 +31,10 @@ static const char forcedViewportEnabled[] = "forcedViewportEnabled"; |
| static const char forcedViewportX[] = "forcedViewportX"; |
| static const char forcedViewportY[] = "forcedViewportY"; |
| static const char forcedViewportScale[] = "forcedViewportScale"; |
| +static const char defaultBackgroundColorOverrideRGBA[] = |
| + "defaultBackgroundColorOverrideRGBA"; |
| +static const char defaultBackgroundColorOriginalRGBA[] = |
| + "defaultBackgroundColorOriginalRGBA"; |
| } |
| InspectorEmulationAgent* InspectorEmulationAgent::create( |
| @@ -64,6 +72,16 @@ void InspectorEmulationAgent::restore() { |
| m_state->doubleProperty(EmulationAgentState::forcedViewportY, 0), |
| m_state->doubleProperty(EmulationAgentState::forcedViewportScale, 1)); |
| } |
| + auto rgbaValue = |
| + m_state->get(EmulationAgentState::defaultBackgroundColorOverrideRGBA); |
| + if (rgbaValue) { |
| + blink::protocol::ErrorSupport errors; |
| + auto rgba = protocol::DOM::RGBA::fromValue(rgbaValue, &errors); |
| + if (!errors.hasErrors()) { |
| + setDefaultBackgroundColorOverride( |
| + Maybe<protocol::DOM::RGBA>(std::move(rgba))); |
| + } |
| + } |
| } |
| Response InspectorEmulationAgent::disable() { |
| @@ -72,6 +90,7 @@ Response InspectorEmulationAgent::disable() { |
| setEmulatedMedia(String()); |
| setCPUThrottlingRate(1); |
| resetViewport(); |
| + setDefaultBackgroundColorOverride(Maybe<protocol::DOM::RGBA>()); |
| return Response::OK(); |
| } |
| @@ -169,6 +188,60 @@ void InspectorEmulationAgent::virtualTimeBudgetExpired() { |
| frontend()->virtualTimeBudgetExpired(); |
| } |
| +Response InspectorEmulationAgent::setDefaultBackgroundColorOverride( |
| + Maybe<protocol::DOM::RGBA> color) { |
| + if (!color.isJust()) { |
| + // Reset to the original color if one is set. |
| + auto rgbaValue = |
| + m_state->get(EmulationAgentState::defaultBackgroundColorOriginalRGBA); |
|
dgozman
2017/01/24 20:12:49
You don't have to store original in the state. Ins
Eric Seckler
2017/01/25 10:33:37
Thanks! Done.
|
| + if (rgbaValue) { |
| + blink::protocol::ErrorSupport errors; |
| + auto rgba = protocol::DOM::RGBA::fromValue(rgbaValue, &errors); |
| + if (!errors.hasErrors()) |
| + setBaseBackgroundColor(rgba.get()); |
| + } |
| + |
| + // Clear the state. |
| + m_state->remove(EmulationAgentState::defaultBackgroundColorOverrideRGBA); |
| + m_state->remove(EmulationAgentState::defaultBackgroundColorOriginalRGBA); |
| + |
| + return Response::OK(); |
| + } |
| + |
| + // Save override and original color to state. |
| + blink::protocol::DOM::RGBA* override = color.fromJust(); |
| + m_state->setValue(EmulationAgentState::defaultBackgroundColorOverrideRGBA, |
| + override->toValue()); |
| + if (!m_state->get(EmulationAgentState::defaultBackgroundColorOriginalRGBA)) { |
| + auto original = getBaseBackgroundColor(); |
| + m_state->setValue(EmulationAgentState::defaultBackgroundColorOriginalRGBA, |
| + original->toValue()); |
| + } |
| + |
| + setBaseBackgroundColor(override); |
| + return Response::OK(); |
| +} |
| + |
| +std::unique_ptr<protocol::DOM::RGBA> |
| +InspectorEmulationAgent::getBaseBackgroundColor() { |
| + auto color = webViewImpl()->baseBackgroundColor(); |
| + double alpha = color.alpha() / 255.0f; |
| + return blink::protocol::DOM::RGBA::create() |
| + .setR(color.red()) |
| + .setG(color.green()) |
| + .setB(color.blue()) |
| + .setA(alpha) |
| + .build(); |
| +} |
| + |
| +void InspectorEmulationAgent::setBaseBackgroundColor( |
| + protocol::DOM::RGBA* rgba) { |
| + // Clamping of values is done by Color() constructor. |
| + int alpha = lroundf(255.0f * rgba->getA(1.0f)); |
| + webViewImpl()->setBaseBackgroundColor( |
| + Color(rgba->getR(), rgba->getG(), rgba->getB(), alpha).rgb()); |
| +} |
| + |
| DEFINE_TRACE(InspectorEmulationAgent) { |
| visitor->trace(m_webLocalFrameImpl); |
| InspectorBaseAgent::trace(visitor); |