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

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: 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
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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 { 42 {
43 } 43 }
44 44
45 DeviceOrientationController::~DeviceOrientationController() 45 DeviceOrientationController::~DeviceOrientationController()
46 { 46 {
47 stopUpdating(); 47 stopUpdating();
48 } 48 }
49 49
50 void DeviceOrientationController::didChangeDeviceOrientation(DeviceOrientationDa ta* deviceOrientationData) 50 void DeviceOrientationController::didChangeDeviceOrientation(DeviceOrientationDa ta* deviceOrientationData)
51 { 51 {
52 if (m_overrideOrientationData)
53 return;
52 dispatchDeviceEvent(DeviceOrientationEvent::create(EventTypeNames::deviceori entation, deviceOrientationData)); 54 dispatchDeviceEvent(DeviceOrientationEvent::create(EventTypeNames::deviceori entation, deviceOrientationData));
53 } 55 }
54 56
55 const char* DeviceOrientationController::supplementName() 57 const char* DeviceOrientationController::supplementName()
56 { 58 {
57 return "DeviceOrientationController"; 59 return "DeviceOrientationController";
58 } 60 }
59 61
60 DeviceOrientationController& DeviceOrientationController::from(Document& documen t) 62 DeviceOrientationController& DeviceOrientationController::from(Document& documen t)
61 { 63 {
62 DeviceOrientationController* controller = static_cast<DeviceOrientationContr oller*>(DocumentSupplement::from(document, supplementName())); 64 DeviceOrientationController* controller = static_cast<DeviceOrientationContr oller*>(DocumentSupplement::from(document, supplementName()));
63 if (!controller) { 65 if (!controller) {
64 controller = new DeviceOrientationController(document); 66 controller = new DeviceOrientationController(document);
65 DocumentSupplement::provideTo(document, supplementName(), adoptPtr(contr oller)); 67 DocumentSupplement::provideTo(document, supplementName(), adoptPtr(contr oller));
66 } 68 }
67 return *controller; 69 return *controller;
68 } 70 }
69 71
72 DeviceOrientationData* DeviceOrientationController::lastData()
73 {
74 return m_overrideOrientationData ? m_overrideOrientationData.get() : DeviceO rientationDispatcher::instance().latestDeviceOrientationData();
75 }
76
70 bool DeviceOrientationController::hasLastData() 77 bool DeviceOrientationController::hasLastData()
71 { 78 {
72 return DeviceOrientationDispatcher::instance().latestDeviceOrientationData() ; 79 return lastData();
73 } 80 }
74 81
75 PassRefPtr<Event> DeviceOrientationController::getLastEvent() 82 PassRefPtr<Event> DeviceOrientationController::getLastEvent()
76 { 83 {
77 return DeviceOrientationEvent::create(EventTypeNames::deviceorientation, 84 return DeviceOrientationEvent::create(EventTypeNames::deviceorientation, las tData());
78 DeviceOrientationDispatcher::instance().latestDeviceOrientationData());
79 } 85 }
80 86
81 void DeviceOrientationController::registerWithDispatcher() 87 void DeviceOrientationController::registerWithDispatcher()
82 { 88 {
83 DeviceOrientationDispatcher::instance().addDeviceOrientationController(this) ; 89 DeviceOrientationDispatcher::instance().addDeviceOrientationController(this) ;
84 } 90 }
85 91
86 void DeviceOrientationController::unregisterWithDispatcher() 92 void DeviceOrientationController::unregisterWithDispatcher()
87 { 93 {
88 DeviceOrientationDispatcher::instance().removeDeviceOrientationController(th is); 94 DeviceOrientationDispatcher::instance().removeDeviceOrientationController(th is);
(...skipping 21 matching lines...) Expand all
110 m_hasEventListener = false; 116 m_hasEventListener = false;
111 } 117 }
112 } 118 }
113 119
114 void DeviceOrientationController::didRemoveAllEventListeners(DOMWindow* window) 120 void DeviceOrientationController::didRemoveAllEventListeners(DOMWindow* window)
115 { 121 {
116 stopUpdating(); 122 stopUpdating();
117 m_hasEventListener = false; 123 m_hasEventListener = false;
118 } 124 }
119 125
126 void DeviceOrientationController::setOverride(DeviceOrientationData* deviceOrien tationData)
127 {
128 m_overrideOrientationData.clear();
129 didChangeDeviceOrientation(deviceOrientationData);
130 m_overrideOrientationData = deviceOrientationData;
131 }
132
133 void DeviceOrientationController::clearOverride()
134 {
135 if (!m_overrideOrientationData)
136 return;
137 m_overrideOrientationData.clear();
138 DeviceOrientationData* orientation = lastData();
139 if (orientation)
140 didChangeDeviceOrientation(orientation);
141 }
142
120 } // namespace WebCore 143 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698