Closed Bug 512237 Opened 15 years ago Closed 15 years ago

Device Orientation issues

Categories

(Core :: Widget: Cocoa, defect)

All
macOS
defect
Not set
major

Tracking

()

RESOLVED FIXED
Tracking Status
status1.9.2 --- beta1-fixed

People

(Reporter: dougt, Assigned: dougt)

References

Details

Attachments

(1 file, 5 obsolete files)

+++ This bug was initially created as a clone of Bug #511902 +++ Created an attachment (id=395856) patch v.1 (cocoa widget implementation) Implementation for cocoa. Smaug made these suggestions (which probably can apply to all implementations) * AccelerationChanged shouldn't be called if acceleration hasn't changed. * Currently it seems that mUpdateTimer just runs every 200ms. That should be 50ms or something to get smoother animations.
Summary: Device Orientation Support - cocoa → Device Orientation issues - cocoa
(In reply to comment #0) > * AccelerationChanged shouldn't be called if acceleration hasn't changed. But when an event listener is added, there should be MozOrientation event soon. > * Currently it seems that mUpdateTimer just runs every 200ms. That should be > 50ms or something to get smoother animations. As the XXX comment in the code says, there could be a pref for this.
Attached patch patch v.1 (obsolete) — Splinter Review
Attached patch patch v.2 (obsolete) — Splinter Review
We may want to push the filtering into the platform specific code, but for now it should be fine here.
Attachment #396674 - Attachment is obsolete: true
Attachment #396682 - Flags: review?(Olli.Pettay)
The patch looks ok, but there is still one case to handle, I think. When adding a MozOrientation listener first time to a window, perhaps that window should get an event pretty soon so that it can get the initial values for the orientation. Does that make sense?
i do not think it matters that much because we get events pretty fast from the hardware. If we increased the delta to something like 0.1 or .2, then we would have to consider the case you are talking about.
Attachment #396682 - Flags: review?(Olli.Pettay) → review+
Comment on attachment 396682 [details] [diff] [review] patch v.2 > void > nsAccelerometer::AccelerationChanged(double x, double y, double z) > { >+ >+ if ( PR_ABS(mLastX - x) < .01 && >+ PR_ABS(mLastY - y) < .01 && >+ PR_ABS(mLastZ - z) < .01 ) >+ return; Extra space after ( and before ) >+ >+ mLastX = x; mLastY = y; mLastZ = z; >+ Put these to separate lines. >-protected: >+ double mLastX, mLastY, mLastZ; And these too.
(In reply to comment #5) > i do not think it matters that much because we get events pretty fast from the > hardware. Well, some hardware may not provide results so fast. So if the the previous value has been cached, and user doesn't move the device at all, it may take long time before there is an orientation change which is above the change threshold.
So, please fix that too.
Attached patch patch v.3 (obsolete) — Splinter Review
ensures that all new listeners get the latest data when they are added.
Attachment #396682 - Attachment is obsolete: true
Attachment #396687 - Flags: review?(Olli.Pettay)
Comment on attachment 396687 [details] [diff] [review] patch v.3 >@@ -144,16 +152,17 @@ NS_IMETHODIMP nsAccelerometer::AddListen > { > if (mStarted == PR_FALSE) { > startDisconnectTimer(); > Startup(); > mStarted = PR_TRUE; > } > > mListeners.AppendObject(aListener); >+ AccelerationChanged(mLastX, mLastY, mLastZ, PR_FALSE); > return NS_OK; > } > > NS_IMETHODIMP nsAccelerometer::RemoveListener(nsIAccelerationListener *aListener) > { > mListeners.RemoveObject(aListener); > return NS_OK; > } >@@ -162,28 +171,41 @@ NS_IMETHODIMP nsAccelerometer::AddWindow > { > if (mStarted == PR_FALSE) { > startDisconnectTimer(); > Startup(); > mStarted = PR_TRUE; > } > > mWindowListeners.AppendObject(aWindow); >+ AccelerationChanged(mLastX, mLastY, mLastZ, PR_FALSE); > return NS_OK; > } > Sorry to be such a nitpicker, but is that really a safe time to dispatch an event? Perhaps you could have something like "ResetCachedValues()", which would force the next (asynchronous) AccelerationChanged?
no problem about nitpicking; that is what this process is for. Are you worried that the listener will be called before AddEventListener returns?
Blocks: 512345
(In reply to comment #11) > Are you worried that the listener will be called before AddEventListener > returns? Well, for example about that. Calling the listener asynchronously would be good. Adding some reset flag should be trivial.
I mean some flag which cause the next timer run to call AccelerationChanged.
Attachment #396687 - Flags: review?(Olli.Pettay)
Attached patch patch v.4 (obsolete) — Splinter Review
This adds a new timer that fires 10ms after the event listener is added (hopeful enough time for us to recv data) ensuring that data is passed to new listeners.
Attachment #396687 - Attachment is obsolete: true
Attachment #396878 - Flags: review?(Olli.Pettay)
Attached patch patch v.5 (without timer) (obsolete) — Splinter Review
Attachment #396878 - Attachment is obsolete: true
Attachment #396885 - Flags: review?(Olli.Pettay)
Attachment #396878 - Flags: review?(Olli.Pettay)
[02:18] <smaug> dougt: this is not really about this bug... but the reason for StartDisconnectTimer is to not shutdown immediately? [02:19] <smaug> dougt: could we start that in RemoveListener if there are no listeners [02:20] <smaug> dougt: in RemoveListener/RemoveWindowListener if mListeners.Count() == 0 && mWindowListeners.Count() [02:20] <smaug> dougt: and if someone adds a new listener, cancel that timer [02:22] <smaug> dougt: I'm assuming here that the reason to not shutdown immediately is to prevent activate/deactivate accelerometer all the time
Summary: Device Orientation issues - cocoa → Device Orientation issues
Attached patch patch v.6Splinter Review
Attachment #396885 - Attachment is obsolete: true
Attachment #396902 - Flags: review?(Olli.Pettay)
Attachment #396885 - Flags: review?(Olli.Pettay)
Comment on attachment 396902 [details] [diff] [review] patch v.6 > void > nsAccelerometer::AccelerationChanged(double x, double y, double z) > { >+ if (x > 1 || y > 1 || z > 1 || x < -1 || y < -1 || z < -1) >+ return; >+ >+ if (!mNewListener) { >+ if (PR_ABS(mLastX - x) < .01 && >+ PR_ABS(mLastY - y) < .01 && >+ PR_ABS(mLastZ - z) < .01) >+ return; >+ } >+ >+ mLastX = x; >+ mLastY = y; >+ mLastZ = z; >+ You need to set mNewListener to PR_FALSE here.
Attachment #396902 - Flags: review?(Olli.Pettay) → review+
Status: NEW → RESOLVED
Closed: 15 years ago
Resolution: --- → FIXED
Attachment #396902 - Flags: approval1.9.2?
Attachment #396902 - Flags: approval1.9.2? → approval1.9.2+
Product: Core → Core Graveyard
Component: Widget: Mac → Widget: Cocoa
Product: Core Graveyard → Core
QA Contact: mac → cocoa
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: