OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "modules/screen_orientation/ScreenOrientationInspectorAgent.h" | 5 #include "modules/screen_orientation/ScreenOrientationInspectorAgent.h" |
6 | 6 |
7 #include "core/InspectorTypeBuilder.h" | 7 #include "core/InspectorTypeBuilder.h" |
8 #include "core/frame/LocalFrame.h" | 8 #include "core/frame/LocalFrame.h" |
9 #include "core/inspector/InspectorState.h" | |
10 #include "modules/screen_orientation/ScreenOrientation.h" | 9 #include "modules/screen_orientation/ScreenOrientation.h" |
11 #include "modules/screen_orientation/ScreenOrientationController.h" | 10 #include "modules/screen_orientation/ScreenOrientationController.h" |
12 | 11 |
13 namespace blink { | 12 namespace blink { |
14 | 13 |
15 namespace ScreenOrientationInspectorAgentState { | 14 namespace ScreenOrientationInspectorAgentState { |
16 static const char angle[] = "angle"; | 15 static const char angle[] = "angle"; |
17 static const char type[] = "type"; | 16 static const char type[] = "type"; |
18 static const char overrideEnabled[] = "overrideEnabled"; | 17 static const char overrideEnabled[] = "overrideEnabled"; |
19 } | 18 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 if (type == WebScreenOrientationUndefined) { | 66 if (type == WebScreenOrientationUndefined) { |
68 *error = "Wrong type value"; | 67 *error = "Wrong type value"; |
69 return; | 68 return; |
70 } | 69 } |
71 ScreenOrientationController* controller = ScreenOrientationController::from(
*m_frame); | 70 ScreenOrientationController* controller = ScreenOrientationController::from(
*m_frame); |
72 if (!controller) { | 71 if (!controller) { |
73 *error = "Cannot connect to orientation controller"; | 72 *error = "Cannot connect to orientation controller"; |
74 return; | 73 return; |
75 } | 74 } |
76 m_state->setBoolean(ScreenOrientationInspectorAgentState::overrideEnabled, t
rue); | 75 m_state->setBoolean(ScreenOrientationInspectorAgentState::overrideEnabled, t
rue); |
77 m_state->setLong(ScreenOrientationInspectorAgentState::angle, angle); | 76 m_state->setNumber(ScreenOrientationInspectorAgentState::angle, angle); |
78 m_state->setLong(ScreenOrientationInspectorAgentState::type, type); | 77 m_state->setNumber(ScreenOrientationInspectorAgentState::type, type); |
79 controller->setOverride(type, angle); | 78 controller->setOverride(type, angle); |
80 } | 79 } |
81 | 80 |
82 void ScreenOrientationInspectorAgent::clearScreenOrientationOverride(ErrorString
* error) | 81 void ScreenOrientationInspectorAgent::clearScreenOrientationOverride(ErrorString
* error) |
83 { | 82 { |
84 ScreenOrientationController* controller = ScreenOrientationController::from(
*m_frame); | 83 ScreenOrientationController* controller = ScreenOrientationController::from(
*m_frame); |
85 if (!controller) { | 84 if (!controller) { |
86 *error = "Cannot connect to orientation controller"; | 85 *error = "Cannot connect to orientation controller"; |
87 return; | 86 return; |
88 } | 87 } |
89 m_state->setBoolean(ScreenOrientationInspectorAgentState::overrideEnabled, f
alse); | 88 m_state->setBoolean(ScreenOrientationInspectorAgentState::overrideEnabled, f
alse); |
90 controller->clearOverride(); | 89 controller->clearOverride(); |
91 } | 90 } |
92 | 91 |
93 void ScreenOrientationInspectorAgent::disable(ErrorString*) | 92 void ScreenOrientationInspectorAgent::disable(ErrorString*) |
94 { | 93 { |
95 m_state->setBoolean(ScreenOrientationInspectorAgentState::overrideEnabled, f
alse); | 94 m_state->setBoolean(ScreenOrientationInspectorAgentState::overrideEnabled, f
alse); |
96 if (ScreenOrientationController* controller = ScreenOrientationController::f
rom(*m_frame)) | 95 if (ScreenOrientationController* controller = ScreenOrientationController::f
rom(*m_frame)) |
97 controller->clearOverride(); | 96 controller->clearOverride(); |
98 } | 97 } |
99 | 98 |
100 void ScreenOrientationInspectorAgent::restore() | 99 void ScreenOrientationInspectorAgent::restore() |
101 { | 100 { |
102 if (m_state->getBoolean(ScreenOrientationInspectorAgentState::overrideEnable
d)) { | 101 if (m_state->booleanProperty(ScreenOrientationInspectorAgentState::overrideE
nabled, false)) { |
103 WebScreenOrientationType type = static_cast<WebScreenOrientationType>(m_
state->getLong(ScreenOrientationInspectorAgentState::type)); | 102 long longType = static_cast<long>(WebScreenOrientationUndefined); |
104 int angle = m_state->getLong(ScreenOrientationInspectorAgentState::angle
); | 103 m_state->getNumber(ScreenOrientationInspectorAgentState::type, &longType
); |
| 104 WebScreenOrientationType type = static_cast<WebScreenOrientationType>(lo
ngType); |
| 105 int angle = 0; |
| 106 m_state->getNumber(ScreenOrientationInspectorAgentState::angle, &angle); |
105 if (ScreenOrientationController* controller = ScreenOrientationControlle
r::from(*m_frame)) | 107 if (ScreenOrientationController* controller = ScreenOrientationControlle
r::from(*m_frame)) |
106 controller->setOverride(type, angle); | 108 controller->setOverride(type, angle); |
107 } | 109 } |
108 } | 110 } |
109 | 111 |
110 } // namespace blink | 112 } // namespace blink |
OLD | NEW |