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

Side by Side Diff: Source/modules/device_orientation/DeviceOrientationInspectorAgent.cpp

Issue 209333008: [DevTools] Support device orientation override on device with sensors. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebaselined test Created 6 years, 9 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
« no previous file with comments | « Source/modules/device_orientation/DeviceOrientationInspectorAgent.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "config.h" 5 #include "config.h"
6 #include "modules/device_orientation/DeviceOrientationInspectorAgent.h" 6 #include "modules/device_orientation/DeviceOrientationInspectorAgent.h"
7 7
8 #include "core/dom/Document.h" 8 #include "core/dom/Document.h"
9 #include "core/frame/LocalFrame.h" 9 #include "core/frame/LocalFrame.h"
10 #include "core/inspector/InspectorController.h" 10 #include "core/inspector/InspectorController.h"
11 #include "core/inspector/InspectorState.h"
11 #include "core/page/Page.h" 12 #include "core/page/Page.h"
12 13
13 #include "modules/device_orientation/DeviceOrientationController.h" 14 #include "modules/device_orientation/DeviceOrientationController.h"
14 #include "modules/device_orientation/DeviceOrientationData.h" 15 #include "modules/device_orientation/DeviceOrientationData.h"
15 16
16 namespace WebCore { 17 namespace WebCore {
17 18
19 namespace DeviceOrientationInspectorAgentState {
20 static const char alpha[] = "alpha";
timvolodine 2014/03/27 00:04:30 I think you need to indent this, because the scope
dgozman 2014/03/27 09:30:33 There are similar namespaces in the code without a
21 static const char beta[] = "beta";
22 static const char gamma[] = "gamma";
23 static const char overrideEnabled[] = "overrideEnabled";
24 }
25
18 void DeviceOrientationInspectorAgent::provideTo(Page& page) 26 void DeviceOrientationInspectorAgent::provideTo(Page& page)
19 { 27 {
20 OwnPtr<DeviceOrientationInspectorAgent> deviceOrientationAgent(adoptPtr(new DeviceOrientationInspectorAgent(page))); 28 OwnPtr<DeviceOrientationInspectorAgent> deviceOrientationAgent(adoptPtr(new DeviceOrientationInspectorAgent(page)));
21 page.inspectorController().registerModuleAgent(deviceOrientationAgent.releas e()); 29 page.inspectorController().registerModuleAgent(deviceOrientationAgent.releas e());
22 } 30 }
23 31
24 DeviceOrientationInspectorAgent::~DeviceOrientationInspectorAgent() 32 DeviceOrientationInspectorAgent::~DeviceOrientationInspectorAgent()
25 { 33 {
26 } 34 }
27 35
28 DeviceOrientationInspectorAgent::DeviceOrientationInspectorAgent(Page& page) 36 DeviceOrientationInspectorAgent::DeviceOrientationInspectorAgent(Page& page)
29 : InspectorBaseAgent<DeviceOrientationInspectorAgent>("DeviceOrientation") 37 : InspectorBaseAgent<DeviceOrientationInspectorAgent>("DeviceOrientation")
30 , m_page(page) 38 , m_page(page)
31 { 39 {
32 } 40 }
33 41
42 DeviceOrientationController& DeviceOrientationInspectorAgent::controller()
43 {
44 ASSERT(m_page.mainFrame()->document());
45 return DeviceOrientationController::from(*m_page.mainFrame()->document());
46 }
47
34 void DeviceOrientationInspectorAgent::setDeviceOrientationOverride(ErrorString* error, double alpha, double beta, double gamma) 48 void DeviceOrientationInspectorAgent::setDeviceOrientationOverride(ErrorString* error, double alpha, double beta, double gamma)
35 { 49 {
36 ASSERT(m_page.mainFrame()->document()); 50 m_state->setBoolean(DeviceOrientationInspectorAgentState::overrideEnabled, t rue);
37 DeviceOrientationController& controller = DeviceOrientationController::from( *m_page.mainFrame()->document()); 51 m_state->setDouble(DeviceOrientationInspectorAgentState::alpha, alpha);
38 controller.didChangeDeviceOrientation(DeviceOrientationData::create(true, al pha, true, beta, true, gamma).get()); 52 m_state->setDouble(DeviceOrientationInspectorAgentState::beta, beta);
53 m_state->setDouble(DeviceOrientationInspectorAgentState::gamma, gamma);
54 controller().setOverride(DeviceOrientationData::create(true, alpha, true, be ta, true, gamma).get());
39 } 55 }
40 56
41 void DeviceOrientationInspectorAgent::clearDeviceOrientationOverride(ErrorString * error) 57 void DeviceOrientationInspectorAgent::clearDeviceOrientationOverride(ErrorString * error)
42 { 58 {
43 setDeviceOrientationOverride(error, 0, 0, 0); 59 m_state->setBoolean(DeviceOrientationInspectorAgentState::overrideEnabled, f alse);
60 controller().clearOverride();
61 }
62
63 void DeviceOrientationInspectorAgent::clearFrontend()
64 {
65 m_state->setBoolean(DeviceOrientationInspectorAgentState::overrideEnabled, f alse);
66 controller().clearOverride();
67 }
68
69 void DeviceOrientationInspectorAgent::restore()
70 {
71 if (m_state->getBoolean(DeviceOrientationInspectorAgentState::overrideEnable d)) {
72 double alpha = m_state->getDouble(DeviceOrientationInspectorAgentState:: alpha);
73 double beta = m_state->getDouble(DeviceOrientationInspectorAgentState::b eta);
74 double gamma = m_state->getDouble(DeviceOrientationInspectorAgentState:: gamma);
75 controller().setOverride(DeviceOrientationData::create(true, alpha, true , beta, true, gamma).get());
76 }
77 }
78
79 void DeviceOrientationInspectorAgent::didCommitLoadForMainFrame()
80 {
81 // New document in main frame - apply override there.
82 // No need to cleanup previous one, as it's already gone.
83 restore();
44 } 84 }
45 85
46 } // namespace WebCore 86 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/modules/device_orientation/DeviceOrientationInspectorAgent.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698