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

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: Restore test Created 5 years, 5 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 void ScreenOrientationInspectorAgent::setScreenOrientationOverride(ErrorString* error, int angle, const String& typeString)
56 {
57 if (angle < 0 || angle >= 360) {
58 *error = "Angle should be in [0; 360) interval";
59 return;
60 }
61 WebScreenOrientationType type = WebScreenOrientationTypeFromString(typeStrin g);
62 if (type == WebScreenOrientationUndefined) {
63 *error = "Wrong type value";
64 return;
65 }
66 ScreenOrientationController* controller = ScreenOrientationController::from( m_frame);
67 if (!controller) {
68 *error = "Cannot connect to orientation controller";
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 ScreenOrientationController* controller = ScreenOrientationController::from( m_frame);
80 if (!controller) {
81 *error = "Cannot connect to orientation controller";
82 return;
83 }
84 m_state->setBoolean(ScreenOrientationInspectorAgentState::overrideEnabled, f alse);
85 controller->clearOverride();
86 }
87
88 void ScreenOrientationInspectorAgent::disable(ErrorString*)
89 {
90 m_state->setBoolean(ScreenOrientationInspectorAgentState::overrideEnabled, f alse);
91 if (ScreenOrientationController* controller = ScreenOrientationController::f rom(m_frame))
92 controller->clearOverride();
93 }
94
95 void ScreenOrientationInspectorAgent::restore()
96 {
97 if (m_state->getBoolean(ScreenOrientationInspectorAgentState::overrideEnable d)) {
98 WebScreenOrientationType type = static_cast<WebScreenOrientationType>(m_ state->getLong(ScreenOrientationInspectorAgentState::type));
99 int angle = m_state->getLong(ScreenOrientationInspectorAgentState::angle );
100 if (ScreenOrientationController* controller = ScreenOrientationControlle r::from(m_frame))
101 controller->setOverride(type, angle);
102 }
103 }
104
105 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/screen_orientation/ScreenOrientationInspectorAgent.h ('k') | Source/web/WebDevToolsAgentImpl.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698