- From: Kenneth Christiansen <kenneth.christiansen@openbossa.org>
- Date: Mon, 10 May 2010 14:44:37 -0300
- To: Simon Fraser <smfr@me.com>
- Cc: "L. David Baron" <dbaron@dbaron.org>, Luiz Agostini <luiz.agostini@openbossa.org>, public-webapps@w3.org, www-style@w3.org
Hi Simon, So what you are suggesting is a kind of document.addMediaRuleListener(mediaquery, listener) etc? I think that should be quite easy to implement. Kenneth On Mon, May 10, 2010 at 2:27 PM, Simon Fraser <smfr@me.com> wrote: > On May 10, 2010, at 8:48 AM, L. David Baron wrote: > >> On Friday 2010-05-07 15:31 -0300, Luiz Agostini wrote: >>> The consensus on the W3C Extending CSSOM Views matchMedium with >>> callbacks [1] mailing list was that instead of adding individual DOM >>> events for changes to media features, we should instead make it >>> possible to get notified when a user defined media query has changed. >>> >>> The idea was making it possible to supply a JavaScript function to the >>> styleMedia.matchMedium(...) function. >>> >>> As no exact IDL was proposed, I came up with one myself which I think fits the >>> use-case, and implemented the feature for WebKit. >>> >>> The result of my work became the following IDL, for which I would like >>> comments/feedback: >>> >>> interface MediaChangeListener { >>> void mediaChanged(in boolean queryResult); >>> }; >>> >>> interface StyleMedia { >>> readonly attribute DOMString type; >>> boolean matchMedium(in DOMString mediaquery, in MediaChangeListener >>> listener); >>> }; >> >> This seems reasonable to me, although I wonder if it's worth passing >> a little more information to the listener, such as (a) the original >> query or (b) the window. Would that be useful to authors, or are >> they comfortable stuffing whatever is necessary in a closure? > > This simple callback-based mechanism suffers from various problems (of the type > that add/removeEventListener were designed to solve): > > 1. Unclear behavior when calling matchMedium() a second time for the same query, > with a different callback. > 2. No way to remove a callback > 3. Lack of context on the callback > > I also think that forcing authors to call matchMedium() just in order to get callbacks > when media queries change is not ideal. > > It feels to me like the correct solution would be enhance CSS OM somehow to allow > authors to attach event listeners to CSSMediaRules somehow, so they can get notified > when those @media statements start or stop matching. > > Simon -- Kenneth Rohde Christiansen Technical Lead / Senior Software Engineer Qt Labs Americas, Nokia Technology Institute, INdT Phone +55 81 8895 6002 / E-mail kenneth.christiansen at openbossa.org
Received on Monday, 10 May 2010 17:45:15 UTC