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

Side by Side Diff: Source/modules/device_orientation/DeviceOrientationController.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: Removed m_lastOrientation 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
OLDNEW
1 /* 1 /*
2 * Copyright 2010 Apple Inc. All rights reserved. 2 * Copyright 2010 Apple Inc. All rights reserved.
3 * Copyright (C) 2012 Samsung Electronics. All rights reserved. 3 * Copyright (C) 2012 Samsung Electronics. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright 10 * * Redistributions in binary form must reproduce the above copyright
(...skipping 22 matching lines...) Expand all
33 #include "core/page/Page.h" 33 #include "core/page/Page.h"
34 #include "modules/device_orientation/DeviceOrientationData.h" 34 #include "modules/device_orientation/DeviceOrientationData.h"
35 #include "modules/device_orientation/DeviceOrientationDispatcher.h" 35 #include "modules/device_orientation/DeviceOrientationDispatcher.h"
36 #include "modules/device_orientation/DeviceOrientationEvent.h" 36 #include "modules/device_orientation/DeviceOrientationEvent.h"
37 37
38 namespace WebCore { 38 namespace WebCore {
39 39
40 DeviceOrientationController::DeviceOrientationController(Document& document) 40 DeviceOrientationController::DeviceOrientationController(Document& document)
41 : DeviceSensorEventController(document) 41 : DeviceSensorEventController(document)
42 , DOMWindowLifecycleObserver(document.domWindow()) 42 , DOMWindowLifecycleObserver(document.domWindow())
43 , m_override(nullptr)
timvolodine 2014/03/26 13:20:55 no need for this, it's initialized to 0 anyway by
dgozman 2014/03/26 13:51:58 Done.
43 { 44 {
44 } 45 }
45 46
46 DeviceOrientationController::~DeviceOrientationController() 47 DeviceOrientationController::~DeviceOrientationController()
47 { 48 {
48 stopUpdating(); 49 stopUpdating();
49 } 50 }
50 51
51 void DeviceOrientationController::didChangeDeviceOrientation(DeviceOrientationDa ta* deviceOrientationData) 52 void DeviceOrientationController::didChangeDeviceOrientation(DeviceOrientationDa ta* deviceOrientationData)
52 { 53 {
54 if (m_override)
55 return;
53 dispatchDeviceEvent(DeviceOrientationEvent::create(EventTypeNames::deviceori entation, deviceOrientationData)); 56 dispatchDeviceEvent(DeviceOrientationEvent::create(EventTypeNames::deviceori entation, deviceOrientationData));
54 } 57 }
55 58
56 const char* DeviceOrientationController::supplementName() 59 const char* DeviceOrientationController::supplementName()
57 { 60 {
58 return "DeviceOrientationController"; 61 return "DeviceOrientationController";
59 } 62 }
60 63
61 DeviceOrientationController& DeviceOrientationController::from(Document& documen t) 64 DeviceOrientationController& DeviceOrientationController::from(Document& documen t)
62 { 65 {
63 DeviceOrientationController* controller = static_cast<DeviceOrientationContr oller*>(DocumentSupplement::from(document, supplementName())); 66 DeviceOrientationController* controller = static_cast<DeviceOrientationContr oller*>(DocumentSupplement::from(document, supplementName()));
64 if (!controller) { 67 if (!controller) {
65 controller = new DeviceOrientationController(document); 68 controller = new DeviceOrientationController(document);
66 DocumentSupplement::provideTo(document, supplementName(), adoptPtr(contr oller)); 69 DocumentSupplement::provideTo(document, supplementName(), adoptPtr(contr oller));
67 } 70 }
68 return *controller; 71 return *controller;
69 } 72 }
70 73
74 WebCore::DeviceOrientationData* DeviceOrientationController::lastData()
timvolodine 2014/03/26 13:20:55 no need for WebCore:: prefix also everywhere in th
dgozman 2014/03/26 13:51:58 Done.
75 {
76 return m_override ? m_override.get() : DeviceOrientationDispatcher::instance ().latestDeviceOrientationData();
77 }
78
71 bool DeviceOrientationController::hasLastData() 79 bool DeviceOrientationController::hasLastData()
72 { 80 {
73 return DeviceOrientationDispatcher::instance().latestDeviceOrientationData() ; 81 return lastData();
74 } 82 }
75 83
76 PassRefPtr<Event> DeviceOrientationController::getLastEvent() 84 PassRefPtr<Event> DeviceOrientationController::getLastEvent()
77 { 85 {
78 return DeviceOrientationEvent::create(EventTypeNames::deviceorientation, 86 return DeviceOrientationEvent::create(EventTypeNames::deviceorientation, las tData());
79 DeviceOrientationDispatcher::instance().latestDeviceOrientationData());
80 } 87 }
81 88
82 void DeviceOrientationController::registerWithDispatcher() 89 void DeviceOrientationController::registerWithDispatcher()
83 { 90 {
84 DeviceOrientationDispatcher::instance().addDeviceOrientationController(this) ; 91 DeviceOrientationDispatcher::instance().addDeviceOrientationController(this) ;
85 } 92 }
86 93
87 void DeviceOrientationController::unregisterWithDispatcher() 94 void DeviceOrientationController::unregisterWithDispatcher()
88 { 95 {
89 DeviceOrientationDispatcher::instance().removeDeviceOrientationController(th is); 96 DeviceOrientationDispatcher::instance().removeDeviceOrientationController(th is);
(...skipping 21 matching lines...) Expand all
111 m_hasEventListener = false; 118 m_hasEventListener = false;
112 } 119 }
113 } 120 }
114 121
115 void DeviceOrientationController::didRemoveAllEventListeners(DOMWindow* window) 122 void DeviceOrientationController::didRemoveAllEventListeners(DOMWindow* window)
116 { 123 {
117 stopUpdating(); 124 stopUpdating();
118 m_hasEventListener = false; 125 m_hasEventListener = false;
119 } 126 }
120 127
128 void DeviceOrientationController::setOverride(WebCore::DeviceOrientationData* de viceOrientationData)
129 {
130 m_override = nullptr;
aandrey 2014/03/25 19:59:44 FYI, maybe we should add: if (m_override == device
timvolodine 2014/03/26 13:20:55 hmm not sure about this. you would be comparing po
timvolodine 2014/03/26 13:20:55 a more direct way would be: m_override.clear(), al
dgozman 2014/03/26 13:51:58 Done.
131 didChangeDeviceOrientation(deviceOrientationData);
132 m_override = deviceOrientationData;
133 }
134
135 void DeviceOrientationController::clearOverride()
136 {
137 m_override = nullptr;
aandrey 2014/03/25 19:59:44 FYI, maybe we should add: if (!m_override) ret
timvolodine 2014/03/26 13:20:55 +1 that way clearOverride would not interfere with
dgozman 2014/03/26 13:51:58 I agree. Done.
138 WebCore::DeviceOrientationData* orientation = lastData();
139 if (orientation)
140 didChangeDeviceOrientation(orientation);
141 }
142
121 } // namespace WebCore 143 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698