| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/device_orientation/DeviceOrientationInspectorAgent.h" | 5 #include "modules/device_orientation/DeviceOrientationInspectorAgent.h" |
| 6 | 6 |
| 7 #include "core/frame/LocalFrame.h" | 7 #include "core/frame/LocalFrame.h" |
| 8 #include "core/inspector/InspectorState.h" | |
| 9 #include "core/page/Page.h" | 8 #include "core/page/Page.h" |
| 10 | 9 |
| 11 #include "modules/device_orientation/DeviceOrientationController.h" | 10 #include "modules/device_orientation/DeviceOrientationController.h" |
| 12 #include "modules/device_orientation/DeviceOrientationData.h" | 11 #include "modules/device_orientation/DeviceOrientationData.h" |
| 13 | 12 |
| 14 namespace blink { | 13 namespace blink { |
| 15 | 14 |
| 16 namespace DeviceOrientationInspectorAgentState { | 15 namespace DeviceOrientationInspectorAgentState { |
| 17 static const char alpha[] = "alpha"; | 16 static const char alpha[] = "alpha"; |
| 18 static const char beta[] = "beta"; | 17 static const char beta[] = "beta"; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 44 | 43 |
| 45 DeviceOrientationController& DeviceOrientationInspectorAgent::controller() | 44 DeviceOrientationController& DeviceOrientationInspectorAgent::controller() |
| 46 { | 45 { |
| 47 ASSERT(toLocalFrame(m_page->mainFrame())->document()); | 46 ASSERT(toLocalFrame(m_page->mainFrame())->document()); |
| 48 return DeviceOrientationController::from(*m_page->deprecatedLocalMainFrame()
->document()); | 47 return DeviceOrientationController::from(*m_page->deprecatedLocalMainFrame()
->document()); |
| 49 } | 48 } |
| 50 | 49 |
| 51 void DeviceOrientationInspectorAgent::setDeviceOrientationOverride(ErrorString*
error, double alpha, double beta, double gamma) | 50 void DeviceOrientationInspectorAgent::setDeviceOrientationOverride(ErrorString*
error, double alpha, double beta, double gamma) |
| 52 { | 51 { |
| 53 m_state->setBoolean(DeviceOrientationInspectorAgentState::overrideEnabled, t
rue); | 52 m_state->setBoolean(DeviceOrientationInspectorAgentState::overrideEnabled, t
rue); |
| 54 m_state->setDouble(DeviceOrientationInspectorAgentState::alpha, alpha); | 53 m_state->setNumber(DeviceOrientationInspectorAgentState::alpha, alpha); |
| 55 m_state->setDouble(DeviceOrientationInspectorAgentState::beta, beta); | 54 m_state->setNumber(DeviceOrientationInspectorAgentState::beta, beta); |
| 56 m_state->setDouble(DeviceOrientationInspectorAgentState::gamma, gamma); | 55 m_state->setNumber(DeviceOrientationInspectorAgentState::gamma, gamma); |
| 57 controller().setOverride(DeviceOrientationData::create(alpha, beta, gamma)); | 56 controller().setOverride(DeviceOrientationData::create(alpha, beta, gamma)); |
| 58 } | 57 } |
| 59 | 58 |
| 60 void DeviceOrientationInspectorAgent::clearDeviceOrientationOverride(ErrorString
* error) | 59 void DeviceOrientationInspectorAgent::clearDeviceOrientationOverride(ErrorString
* error) |
| 61 { | 60 { |
| 62 m_state->setBoolean(DeviceOrientationInspectorAgentState::overrideEnabled, f
alse); | 61 m_state->setBoolean(DeviceOrientationInspectorAgentState::overrideEnabled, f
alse); |
| 63 controller().clearOverride(); | 62 controller().clearOverride(); |
| 64 } | 63 } |
| 65 | 64 |
| 66 void DeviceOrientationInspectorAgent::disable(ErrorString*) | 65 void DeviceOrientationInspectorAgent::disable(ErrorString*) |
| 67 { | 66 { |
| 68 m_state->setBoolean(DeviceOrientationInspectorAgentState::overrideEnabled, f
alse); | 67 m_state->setBoolean(DeviceOrientationInspectorAgentState::overrideEnabled, f
alse); |
| 69 controller().clearOverride(); | 68 controller().clearOverride(); |
| 70 } | 69 } |
| 71 | 70 |
| 72 void DeviceOrientationInspectorAgent::restore() | 71 void DeviceOrientationInspectorAgent::restore() |
| 73 { | 72 { |
| 74 if (m_state->getBoolean(DeviceOrientationInspectorAgentState::overrideEnable
d)) { | 73 if (m_state->booleanProperty(DeviceOrientationInspectorAgentState::overrideE
nabled, false)) { |
| 75 double alpha = m_state->getDouble(DeviceOrientationInspectorAgentState::
alpha); | 74 double alpha = 0; |
| 76 double beta = m_state->getDouble(DeviceOrientationInspectorAgentState::b
eta); | 75 m_state->getNumber(DeviceOrientationInspectorAgentState::alpha, &alpha); |
| 77 double gamma = m_state->getDouble(DeviceOrientationInspectorAgentState::
gamma); | 76 double beta = 0; |
| 77 m_state->getNumber(DeviceOrientationInspectorAgentState::beta, &beta); |
| 78 double gamma = 0; |
| 79 m_state->getNumber(DeviceOrientationInspectorAgentState::gamma, &gamma); |
| 78 controller().setOverride(DeviceOrientationData::create(alpha, beta, gamm
a)); | 80 controller().setOverride(DeviceOrientationData::create(alpha, beta, gamm
a)); |
| 79 } | 81 } |
| 80 } | 82 } |
| 81 | 83 |
| 82 void DeviceOrientationInspectorAgent::didCommitLoadForLocalFrame(LocalFrame* fra
me) | 84 void DeviceOrientationInspectorAgent::didCommitLoadForLocalFrame(LocalFrame* fra
me) |
| 83 { | 85 { |
| 84 // FIXME(dgozman): adapt this for out-of-process iframes. | 86 // FIXME(dgozman): adapt this for out-of-process iframes. |
| 85 if (frame != m_page->mainFrame()) | 87 if (frame != m_page->mainFrame()) |
| 86 return; | 88 return; |
| 87 | 89 |
| 88 // New document in main frame - apply override there. | 90 // New document in main frame - apply override there. |
| 89 // No need to cleanup previous one, as it's already gone. | 91 // No need to cleanup previous one, as it's already gone. |
| 90 restore(); | 92 restore(); |
| 91 } | 93 } |
| 92 | 94 |
| 93 } // namespace blink | 95 } // namespace blink |
| OLD | NEW |