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

Side by Side 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: error tests 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "config.h"
6 #include "modules/screen_orientation/ScreenOrientationInspectorAgent.h"
7
8 #include "core/InspectorTypeBuilder.h"
9 #include "core/frame/LocalFrame.h"
10 #include "core/inspector/InspectorState.h"
11 #include "modules/screen_orientation/ScreenOrientation.h"
12 #include "modules/screen_orientation/ScreenOrientationController.h"
13
14 namespace blink {
15
16 namespace ScreenOrientationInspectorAgentState {
17 static const char angle[] = "angle";
18 static const char type[] = "type";
19 static const char overrideEnabled[] = "overrideEnabled";
20 }
21
22 namespace {
23
24 WebScreenOrientationType WebScreenOrientationTypeFromString(const String& type)
25 {
26 if (type == TypeBuilder::getEnumConstantValue(TypeBuilder::ScreenOrientation ::OrientationType::PortraitPrimary))
27 return WebScreenOrientationPortraitPrimary;
28 if (type == TypeBuilder::getEnumConstantValue(TypeBuilder::ScreenOrientation ::OrientationType::PortraitSecondary))
29 return WebScreenOrientationPortraitSecondary;
30 if (type == TypeBuilder::getEnumConstantValue(TypeBuilder::ScreenOrientation ::OrientationType::LandscapePrimary))
31 return WebScreenOrientationLandscapePrimary;
32 if (type == TypeBuilder::getEnumConstantValue(TypeBuilder::ScreenOrientation ::OrientationType::LandscapeSecondary))
33 return WebScreenOrientationLandscapeSecondary;
34 return WebScreenOrientationUndefined;
35 }
36
37 } // namespace
38
39 // static
40 PassOwnPtrWillBeRawPtr<ScreenOrientationInspectorAgent> ScreenOrientationInspect orAgent::create(LocalFrame& frame)
41 {
42 return adoptPtrWillBeNoop(new ScreenOrientationInspectorAgent(frame));
43 }
44
45 ScreenOrientationInspectorAgent::~ScreenOrientationInspectorAgent()
46 {
47 }
48
49 ScreenOrientationInspectorAgent::ScreenOrientationInspectorAgent(LocalFrame& fra me)
50 : InspectorBaseAgent<ScreenOrientationInspectorAgent, InspectorFrontend::Scr eenOrientation>("ScreenOrientation")
51 , m_frame(frame)
52 {
53 }
54
55 ScreenOrientationController& ScreenOrientationInspectorAgent::controller()
56 {
57 return *ScreenOrientationController::from(m_frame);
58 }
59
60 void ScreenOrientationInspectorAgent::setScreenOrientationOverride(ErrorString* error, int angle, const String& typeString)
61 {
62 if (angle < 0 || angle >= 360) {
63 *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
64 return;
65 }
66 WebScreenOrientationType type = WebScreenOrientationTypeFromString(typeStrin g);
67 if (type == WebScreenOrientationUndefined) {
68 *error = "Wrong type value";
69 return;
70 }
71 m_state->setBoolean(ScreenOrientationInspectorAgentState::overrideEnabled, t rue);
72 m_state->setLong(ScreenOrientationInspectorAgentState::angle, angle);
73 m_state->setLong(ScreenOrientationInspectorAgentState::type, type);
74 controller().setOverride(type, angle);
75 }
76
77 void ScreenOrientationInspectorAgent::clearScreenOrientationOverride(ErrorString * error)
78 {
79 m_state->setBoolean(ScreenOrientationInspectorAgentState::overrideEnabled, f alse);
80 controller().clearOverride();
81 }
82
83 void ScreenOrientationInspectorAgent::disable(ErrorString*)
84 {
85 m_state->setBoolean(ScreenOrientationInspectorAgentState::overrideEnabled, f alse);
86 controller().clearOverride();
87 }
88
89 void ScreenOrientationInspectorAgent::restore()
90 {
91 if (m_state->getBoolean(ScreenOrientationInspectorAgentState::overrideEnable d)) {
92 WebScreenOrientationType type = static_cast<WebScreenOrientationType>(m_ state->getLong(ScreenOrientationInspectorAgentState::type));
93 int angle = m_state->getLong(ScreenOrientationInspectorAgentState::angle );
94 controller().setOverride(type, angle);
95 }
96 }
97
98 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698