On 01/26/2012 10:33 PM, Chris Jones wrote:
> ----- Original Message -----
>> From: "Mounir Lamouri" <
mou...@lamouri.fr>
>> To: "Chris Jones" <
cjo...@mozilla.com>
>> Cc:
pba...@zynga.com, "Chris Pearce" <
cpe...@mozilla.com>, "Boris Zbarsky" <
bzba...@MIT.EDU>,
di...@apple.com,
>>
dev-w...@lists.mozilla.org
>> Sent: Thursday, January 26, 2012 6:08:11 AM
>> Subject: Re: Screen orientation API proposal
>>
>> On 01/26/2012 08:30 AM, Chris Jones wrote:
>>> ----- Original Message -----
>>>> From: "Mounir Lamouri" <
mou...@lamouri.fr>
>>>> To:
dev-w...@lists.mozilla.org
>>>> Cc:
pba...@zynga.com, "Chris Pearce" <
cpe...@mozilla.com>,
>>>> "Boris Zbarsky" <
bzba...@MIT.EDU>,
di...@apple.com
>>>> Sent: Wednesday, January 25, 2012 3:56:35 PM
>>>> Subject: Re: Screen orientation API proposal
>>>>
>>>> interface ScreenLockRequest {
>>>> readonly attribute DOMString readyState; // "processing" or
>>>> "done"
>>>> readonly attribute DOMError? error;
>>>> attribute EventListener onsuccess;
>>>> attribute EventListener onerror;
>>>> attribute ScreenLock? result;
>>>> }
>>>>
>>>> interface ScreenLock {
>>>> void unlock();
>>>> }
>>>>
>>>
>>> Is there any reason for these to be separate interfaces? I would
>>> find it more convenient to have unlock() on the request object,
>>> and just ignore the unlock() if the request failed or the lock had
>>> already been released.
>>
>> That would break the purpose of Request objects and result attribute.
>
> What's the purpose of the result attribute? I think you're begging the question.
DOMRequest.result is set when the request is done. When a result appear
and an action can finally be done with it.
> When discussing examples of this pattern with jlebar, I argued that it's not more code than global lock()/unlock(). With these separate interfaces, it is.
>
> window.screen.lockOrientation("portrait");
> //...
> window.screen.unlockOrientation();
>
> vs.
>
> var lock;
> var req = window.screen.requestOrientationLock("portrait");
> req.onsuccess = function () { lock = req.result; };
> //...
> if (lock)
> lock.unlock();
>
> So I withdraw my argument. Sorry jlebar!
>
> I'm not seeing concrete reasons for separating the two interfaces. Would like to see them.
It's indeed shorter to right the first code, however, the interface
design is worse because you can try to unlock something that is not
locked. For example:
window.screen.lockOrientation("portrait");
window.screen.unlockOrientation();
Will not work because lockOrientation() is async and unlockOrientation
is going to unlock nothing. The author might thing it could work. The
author might even run into race conditions if there is something between
lock and unlock and locking is sometimes done before unlock being called.
However, this design seems cleaner:
var req = window.screen.lockOrientation("portrait");
req.onsuccess = function() { req.result.unlock(); };
Because whatever happens, the author just can't call unlock if a lock
have not happen yet. It's less error-prone, thus clean.
>>> Another case is most relevant to pages launched within browser
>>> chrome. For the reasons Dean brought up earlier, a browser might
>>> disallow orientation lock for in-chrome pages. But they would
>>> likely want to allow orientation lock for pages that go to
>>> full-screen (up to the UA still). However, when transitioning
>>> from full-screen to not-full-screen, the page transitions from an
>>> orientation-lock-allowed state to -disallowed state. On that
>>> transition, the UA might want to drop all orientation locks. This
>>> may or may not need to specified.
>>>
>>> The spec *should* mention that any/all orientation locks can be
>>> dropped, at any time. I don't know if a notification of this is
>>> absolutely needed, but if we find a use case it would be pretty
>>> easy to fire an "onerror" callback to a lock object, or something
>>> else.
>>
>> Sending an error event to the Request object wouldn't be doable.
>> Request
>> objects receive one event (success or error) and at that point, their
>> state shouldn't change. At least, not being reverted.
>> I think we might need something to let the author know the lock has
>> been
>> removed mostly because removing the lock is going to be UA specific
>> neither specs nor authors can predict when UA are going to do that.
>>
>
> I don't have a use case in mind yet for authors reacting to revoked locks. What would they do? But your proposal sounds OK, whichever interface it goes on. We can also add that in a later spec.
In addition, we could imagine that with unlock() being in ScreenLock
object, we could always send a unlock event when unlock happens like:
req.result.onunlock = function() { alert("unlocked"); };
req.result.unlock();
This design seems nicer because if we unlock with unlock() or if the
unlock happens because of the UA forcing it, the same event handler can
be used.
In addition, we could easily throw an exception if unlock is called
after the unlock event being sent.
Sorry for the late reply and I might be repeating arguments because of
that. You have to blame the DOM Bindings work week ;)
Cheers,
--
Mounir