Chromium Code Reviews| Index: Source/modules/screen_orientation/ScreenOrientationInspectorAgent.cpp |
| diff --git a/Source/modules/screen_orientation/ScreenOrientationInspectorAgent.cpp b/Source/modules/screen_orientation/ScreenOrientationInspectorAgent.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e590bdf95dda3088d446a6c14447857924c3a566 |
| --- /dev/null |
| +++ b/Source/modules/screen_orientation/ScreenOrientationInspectorAgent.cpp |
| @@ -0,0 +1,98 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "config.h" |
| +#include "modules/screen_orientation/ScreenOrientationInspectorAgent.h" |
| + |
| +#include "core/InspectorTypeBuilder.h" |
| +#include "core/frame/LocalFrame.h" |
| +#include "core/inspector/InspectorState.h" |
| +#include "modules/screen_orientation/ScreenOrientation.h" |
| +#include "modules/screen_orientation/ScreenOrientationController.h" |
| + |
| +namespace blink { |
| + |
| +namespace ScreenOrientationInspectorAgentState { |
| +static const char angle[] = "angle"; |
| +static const char type[] = "type"; |
| +static const char overrideEnabled[] = "overrideEnabled"; |
| +} |
| + |
| +namespace { |
| + |
| +WebScreenOrientationType WebScreenOrientationTypeFromString(const String& type) |
| +{ |
| + if (type == TypeBuilder::getEnumConstantValue(TypeBuilder::ScreenOrientation::OrientationType::PortraitPrimary)) |
| + return WebScreenOrientationPortraitPrimary; |
| + if (type == TypeBuilder::getEnumConstantValue(TypeBuilder::ScreenOrientation::OrientationType::PortraitSecondary)) |
| + return WebScreenOrientationPortraitSecondary; |
| + if (type == TypeBuilder::getEnumConstantValue(TypeBuilder::ScreenOrientation::OrientationType::LandscapePrimary)) |
| + return WebScreenOrientationLandscapePrimary; |
| + if (type == TypeBuilder::getEnumConstantValue(TypeBuilder::ScreenOrientation::OrientationType::LandscapeSecondary)) |
| + return WebScreenOrientationLandscapeSecondary; |
| + return WebScreenOrientationUndefined; |
| +} |
| + |
| +} // namespace |
| + |
| +// static |
| +PassOwnPtrWillBeRawPtr<ScreenOrientationInspectorAgent> ScreenOrientationInspectorAgent::create(LocalFrame& frame) |
| +{ |
| + return adoptPtrWillBeNoop(new ScreenOrientationInspectorAgent(frame)); |
| +} |
| + |
| +ScreenOrientationInspectorAgent::~ScreenOrientationInspectorAgent() |
| +{ |
| +} |
| + |
| +ScreenOrientationInspectorAgent::ScreenOrientationInspectorAgent(LocalFrame& frame) |
| + : InspectorBaseAgent<ScreenOrientationInspectorAgent, InspectorFrontend::ScreenOrientation>("ScreenOrientation") |
| + , m_frame(frame) |
| +{ |
| +} |
| + |
| +ScreenOrientationController& ScreenOrientationInspectorAgent::controller() |
| +{ |
| + return *ScreenOrientationController::from(m_frame); |
| +} |
| + |
| +void ScreenOrientationInspectorAgent::setScreenOrientationOverride(ErrorString* error, int angle, const String& typeString) |
| +{ |
| + if (angle < 0 || angle >= 360) { |
| + *error = "Angle should be in [0; 360) interval"; |
|
mlamouri (slow - plz ping)
2015/06/26 10:10:53
nit: what's [x; y) notation? it seems to me that i
dgozman
2015/06/26 10:18:39
Those are equivalent, it's just more natural for m
|
| + return; |
| + } |
| + WebScreenOrientationType type = WebScreenOrientationTypeFromString(typeString); |
| + if (type == WebScreenOrientationUndefined) { |
| + *error = "Wrong type value"; |
| + return; |
| + } |
| + m_state->setBoolean(ScreenOrientationInspectorAgentState::overrideEnabled, true); |
| + m_state->setLong(ScreenOrientationInspectorAgentState::angle, angle); |
| + m_state->setLong(ScreenOrientationInspectorAgentState::type, type); |
| + controller().setOverride(type, angle); |
| +} |
| + |
| +void ScreenOrientationInspectorAgent::clearScreenOrientationOverride(ErrorString* error) |
| +{ |
| + m_state->setBoolean(ScreenOrientationInspectorAgentState::overrideEnabled, false); |
| + controller().clearOverride(); |
| +} |
| + |
| +void ScreenOrientationInspectorAgent::disable(ErrorString*) |
| +{ |
| + m_state->setBoolean(ScreenOrientationInspectorAgentState::overrideEnabled, false); |
| + controller().clearOverride(); |
| +} |
| + |
| +void ScreenOrientationInspectorAgent::restore() |
| +{ |
| + if (m_state->getBoolean(ScreenOrientationInspectorAgentState::overrideEnabled)) { |
| + WebScreenOrientationType type = static_cast<WebScreenOrientationType>(m_state->getLong(ScreenOrientationInspectorAgentState::type)); |
| + int angle = m_state->getLong(ScreenOrientationInspectorAgentState::angle); |
| + controller().setOverride(type, angle); |
| + } |
| +} |
| + |
| +} // namespace blink |