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

Unified Diff: Source/modules/screen_orientation/ScreenOrientationInspectorAgent.cpp

Issue 1195793008: [DevTools] Implement screen orientation override. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
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..cd9e2918b42ab1daff1cfbeb7c35a7a62182f9c4
--- /dev/null
+++ b/Source/modules/screen_orientation/ScreenOrientationInspectorAgent.cpp
@@ -0,0 +1,107 @@
+// 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 < -360 || angle > 360) {
+ *error = "Angle should be between -360 and 360";
mlamouri (slow - plz ping) 2015/06/24 16:51:06 No, it should be between in [ 0; 360 [ (ie. >=0 &&
dgozman 2015/06/25 12:21:26 Fixed.
+ 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);
+ }
+}
+
+void ScreenOrientationInspectorAgent::didCommitLoadForLocalFrame(LocalFrame* frame)
+{
+ if (*frame == m_frame) {
+ // New document in main frame - apply override there.
+ // No need to cleanup previous one, as it's already gone.
mlamouri (slow - plz ping) 2015/06/24 16:51:06 I'm confused. What are you trying to do here?
dgozman 2015/06/25 12:21:26 That is a leftover from Page-based solution. Remov
+ restore();
+ }
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698