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

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

Issue 21256002: Fire null Device Motion events only once. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: fixed comments Created 7 years, 4 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 (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
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 10 * * Redistributions in binary form must reproduce the above
(...skipping 16 matching lines...) Expand all
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "modules/device_orientation/DeviceOrientationDispatcher.h" 32 #include "modules/device_orientation/DeviceOrientationDispatcher.h"
33 33
34 #include "modules/device_orientation/DeviceOrientationData.h" 34 #include "modules/device_orientation/DeviceOrientationData.h"
35 #include "modules/device_orientation/NewDeviceOrientationController.h" 35 #include "modules/device_orientation/NewDeviceOrientationController.h"
36 #include "public/platform/Platform.h" 36 #include "public/platform/Platform.h"
37 #include "wtf/TemporaryChange.h"
37 38
38 namespace WebCore { 39 namespace WebCore {
39 40
40 DeviceOrientationDispatcher& DeviceOrientationDispatcher::instance() 41 DeviceOrientationDispatcher& DeviceOrientationDispatcher::instance()
41 { 42 {
42 DEFINE_STATIC_LOCAL(DeviceOrientationDispatcher, deviceOrientationDispatcher , ()); 43 DEFINE_STATIC_LOCAL(DeviceOrientationDispatcher, deviceOrientationDispatcher , ());
43 return deviceOrientationDispatcher; 44 return deviceOrientationDispatcher;
44 } 45 }
45 46
46 DeviceOrientationDispatcher::DeviceOrientationDispatcher() 47 DeviceOrientationDispatcher::DeviceOrientationDispatcher()
(...skipping 15 matching lines...) Expand all
62 } 63 }
63 64
64 void DeviceOrientationDispatcher::startListening() 65 void DeviceOrientationDispatcher::startListening()
65 { 66 {
66 WebKit::Platform::current()->setDeviceOrientationListener(this); 67 WebKit::Platform::current()->setDeviceOrientationListener(this);
67 } 68 }
68 69
69 void DeviceOrientationDispatcher::stopListening() 70 void DeviceOrientationDispatcher::stopListening()
70 { 71 {
71 WebKit::Platform::current()->setDeviceOrientationListener(0); 72 WebKit::Platform::current()->setDeviceOrientationListener(0);
73 m_lastDeviceOrientationData.clear();
72 } 74 }
73 75
74 void DeviceOrientationDispatcher::didChangeDeviceOrientation(const WebKit::WebDe viceOrientationData& motion) 76 void DeviceOrientationDispatcher::didChangeDeviceOrientation(const WebKit::WebDe viceOrientationData& motion)
75 { 77 {
76 m_lastDeviceOrientationData = DeviceOrientationData::create(motion); 78 m_lastDeviceOrientationData = DeviceOrientationData::create(motion);
77 bool needsPurge = false; 79
78 for (size_t i = 0; i < m_controllers.size(); ++i) { 80 {
79 if (m_controllers[i]) 81 TemporaryChange<bool> changeIsDispatching(m_isDispatching, true);
80 static_cast<NewDeviceOrientationController*>(m_controllers[i])->didC hangeDeviceOrientation(m_lastDeviceOrientationData.get()); 82 // Don't fire controllers removed or added during event dispatch.
81 else 83 size_t size = m_controllers.size();
82 needsPurge = true; 84 for (size_t i = 0; i < size; ++i) {
85 if (m_controllers[i])
86 static_cast<NewDeviceOrientationController*>(m_controllers[i])-> didChangeDeviceOrientation(m_lastDeviceOrientationData.get());
87 }
83 } 88 }
84 89
85 if (needsPurge) 90 if (m_needsPurge)
86 purgeControllers(); 91 purgeControllers();
87 } 92 }
88 93
89 DeviceOrientationData* DeviceOrientationDispatcher::latestDeviceOrientationData( ) 94 DeviceOrientationData* DeviceOrientationDispatcher::latestDeviceOrientationData( )
90 { 95 {
91 return m_lastDeviceOrientationData.get(); 96 return m_lastDeviceOrientationData.get();
92 } 97 }
93 98
94 } // namespace WebCore 99 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698