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

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

Issue 21256002: Fire null Device Motion events only once. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 } 62 }
63 63
64 void DeviceMotionDispatcher::startListening() 64 void DeviceMotionDispatcher::startListening()
65 { 65 {
66 WebKit::Platform::current()->setDeviceMotionListener(this); 66 WebKit::Platform::current()->setDeviceMotionListener(this);
67 } 67 }
68 68
69 void DeviceMotionDispatcher::stopListening() 69 void DeviceMotionDispatcher::stopListening()
70 { 70 {
71 WebKit::Platform::current()->setDeviceMotionListener(0); 71 WebKit::Platform::current()->setDeviceMotionListener(0);
72 m_lastDeviceMotionData.clear();
72 } 73 }
73 74
74 void DeviceMotionDispatcher::didChangeDeviceMotion(const WebKit::WebDeviceMotion Data& motion) 75 void DeviceMotionDispatcher::didChangeDeviceMotion(const WebKit::WebDeviceMotion Data& motion)
75 { 76 {
76 m_lastDeviceMotionData = DeviceMotionData::create(motion); 77 m_lastDeviceMotionData = DeviceMotionData::create(motion);
77 bool needsPurge = false; 78
78 for (size_t i = 0; i < m_controllers.size(); ++i) { 79 m_isDispatching = true;
abarth-chromium 2013/07/31 00:56:19 Consider using TemporaryChange rather than manuall
timvolodine 2013/07/31 13:59:00 Done.
80 // Don't fire controllers removed or added during event dispatch.
81 size_t end = m_controllers.size();
abarth-chromium 2013/07/31 00:56:19 end -> length or size We use the term |end| to re
timvolodine 2013/07/31 13:59:00 changed to size. Actually I was basing myself on E
82 for (size_t i = 0; i < end; ++i) {
79 if (m_controllers[i]) 83 if (m_controllers[i])
80 static_cast<DeviceMotionController*>(m_controllers[i])->didChangeDev iceMotion(m_lastDeviceMotionData.get()); 84 static_cast<DeviceMotionController*>(m_controllers[i])->didChangeDev iceMotion(m_lastDeviceMotionData.get());
81 else
82 needsPurge = true;
83 } 85 }
86 m_isDispatching = false;
84 87
85 if (needsPurge) 88 if (m_needsPurge)
86 purgeControllers(); 89 purgeControllers();
87 } 90 }
88 91
89 DeviceMotionData* DeviceMotionDispatcher::latestDeviceMotionData() 92 DeviceMotionData* DeviceMotionDispatcher::latestDeviceMotionData()
90 { 93 {
91 return m_lastDeviceMotionData.get(); 94 return m_lastDeviceMotionData.get();
92 } 95 }
93 96
94 } // namespace WebCore 97 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698