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

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: 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_lastOrientation(nullptr)
44 , m_override(nullptr)
43 { 45 {
44 } 46 }
45 47
46 DeviceOrientationController::~DeviceOrientationController() 48 DeviceOrientationController::~DeviceOrientationController()
47 { 49 {
48 stopUpdating(); 50 stopUpdating();
49 } 51 }
50 52
51 void DeviceOrientationController::didChangeDeviceOrientation(DeviceOrientationDa ta* deviceOrientationData) 53 void DeviceOrientationController::didChangeDeviceOrientation(DeviceOrientationDa ta* deviceOrientationData)
52 { 54 {
55 if (m_override) {
56 m_lastOrientation = deviceOrientationData;
57 return;
timvolodine 2014/03/25 15:06:33 hmm so I guess we don't fire overrides at regular
dgozman 2014/03/25 17:50:30 Done.
58 }
53 dispatchDeviceEvent(DeviceOrientationEvent::create(EventTypeNames::deviceori entation, deviceOrientationData)); 59 dispatchDeviceEvent(DeviceOrientationEvent::create(EventTypeNames::deviceori entation, deviceOrientationData));
54 } 60 }
55 61
56 const char* DeviceOrientationController::supplementName() 62 const char* DeviceOrientationController::supplementName()
57 { 63 {
58 return "DeviceOrientationController"; 64 return "DeviceOrientationController";
59 } 65 }
60 66
61 DeviceOrientationController& DeviceOrientationController::from(Document& documen t) 67 DeviceOrientationController& DeviceOrientationController::from(Document& documen t)
62 { 68 {
63 DeviceOrientationController* controller = static_cast<DeviceOrientationContr oller*>(DocumentSupplement::from(document, supplementName())); 69 DeviceOrientationController* controller = static_cast<DeviceOrientationContr oller*>(DocumentSupplement::from(document, supplementName()));
64 if (!controller) { 70 if (!controller) {
65 controller = new DeviceOrientationController(document); 71 controller = new DeviceOrientationController(document);
66 DocumentSupplement::provideTo(document, supplementName(), adoptPtr(contr oller)); 72 DocumentSupplement::provideTo(document, supplementName(), adoptPtr(contr oller));
67 } 73 }
68 return *controller; 74 return *controller;
69 } 75 }
70 76
77 WebCore::DeviceOrientationData* DeviceOrientationController::lastData()
78 {
79 return m_override ? m_override.get() : DeviceOrientationDispatcher::instance ().latestDeviceOrientationData();
80 }
81
71 bool DeviceOrientationController::hasLastData() 82 bool DeviceOrientationController::hasLastData()
72 { 83 {
73 return DeviceOrientationDispatcher::instance().latestDeviceOrientationData() ; 84 return lastData();
74 } 85 }
75 86
76 PassRefPtr<Event> DeviceOrientationController::getLastEvent() 87 PassRefPtr<Event> DeviceOrientationController::getLastEvent()
77 { 88 {
78 return DeviceOrientationEvent::create(EventTypeNames::deviceorientation, 89 return DeviceOrientationEvent::create(EventTypeNames::deviceorientation, las tData());
79 DeviceOrientationDispatcher::instance().latestDeviceOrientationData());
80 } 90 }
81 91
82 void DeviceOrientationController::registerWithDispatcher() 92 void DeviceOrientationController::registerWithDispatcher()
83 { 93 {
84 DeviceOrientationDispatcher::instance().addDeviceOrientationController(this) ; 94 DeviceOrientationDispatcher::instance().addDeviceOrientationController(this) ;
85 } 95 }
86 96
87 void DeviceOrientationController::unregisterWithDispatcher() 97 void DeviceOrientationController::unregisterWithDispatcher()
88 { 98 {
89 DeviceOrientationDispatcher::instance().removeDeviceOrientationController(th is); 99 DeviceOrientationDispatcher::instance().removeDeviceOrientationController(th is);
(...skipping 21 matching lines...) Expand all
111 m_hasEventListener = false; 121 m_hasEventListener = false;
112 } 122 }
113 } 123 }
114 124
115 void DeviceOrientationController::didRemoveAllEventListeners(DOMWindow* window) 125 void DeviceOrientationController::didRemoveAllEventListeners(DOMWindow* window)
116 { 126 {
117 stopUpdating(); 127 stopUpdating();
118 m_hasEventListener = false; 128 m_hasEventListener = false;
119 } 129 }
120 130
131 void DeviceOrientationController::setOverride(WebCore::DeviceOrientationData* de viceOrientationData)
132 {
133 if (!m_override)
134 m_lastOrientation = DeviceOrientationDispatcher::instance().latestDevice OrientationData();
135 m_override = nullptr;
136 didChangeDeviceOrientation(deviceOrientationData);
137 m_override = deviceOrientationData;
138 }
139
140 void DeviceOrientationController::clearOverride()
141 {
142 m_override = nullptr;
143 if (m_lastOrientation)
timvolodine 2014/03/25 15:06:33 could you use lastData() here instead of m_lastOri
dgozman 2014/03/25 17:50:30 Done.
144 didChangeDeviceOrientation(m_lastOrientation.get());
145 m_lastOrientation = nullptr;
146 }
147
121 } // namespace WebCore 148 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698