Closed
Bug 542058
Opened 15 years ago
Closed 14 years ago
implement window.matchMedia API for matching CSS media queries (like window.evaluateMediaQuery proposal and earlier window.styleMedia.matchMedium draft spec)
Categories
(Core :: DOM: CSS Object Model, defect, P4)
Core
DOM: CSS Object Model
Tracking
()
RESOLVED
FIXED
mozilla6
People
(Reporter: dbaron, Assigned: dbaron)
References
Details
(Keywords: dev-doc-complete)
Attachments
(4 files, 1 obsolete file)
1.24 KB,
text/html; charset=UTF-8
|
Details | |
13.49 KB,
patch
|
bzbarsky
:
review+
|
Details | Diff | Splinter Review |
4.58 KB,
patch
|
bzbarsky
:
review+
|
Details | Diff | Splinter Review |
42.19 KB,
patch
|
bzbarsky
:
review+
|
Details | Diff | Splinter Review |
We should implement a DOM API for matching CSS media queries. This would be useful both for our chrome (e.g., would make bug 498312 easier and more accurate) and useful for Web authors.
It's already possible by adding style sheets and then querying computed style, but it's quite a bit of work (and probably slow for many uses).
There are two proposals I've seen for such an API:
http://webkit.org/specs/MediaQueriesExtensions.html#DOM-Window has a proposal for window.evaluateMediaQuery()
http://dev.w3.org/csswg/cssom-view/#dom-media-matchmedium has a proposal for window.media.matchMedium()
It looks like trunk WebKit (including chromium) has implemented window.media.matchMedium, which I think means the first proposal is obsolete. (And I hope the rest of that document is obsolete too.)
Assignee | ||
Comment 1•15 years ago
|
||
Comment 2•15 years ago
|
||
It is now http://dev.w3.org/csswg/cssom-view/#dom-stylemedia-matchmedium
I didn't know it was already implemented, but Apple told me they are updating because they agree the renaming will help avoid clashes.
Assignee | ||
Comment 3•15 years ago
|
||
One addition that could be useful here is a way to register a callback when the result of evaluating a query changes. (We already have code to optimize such things for CSS's use of media queries, and it requires much less notification than callbacks whenever the value of any media feature changes.)
Comment 4•15 years ago
|
||
Would that not be expensive? Anyway, put it forward on www-style?
Comment 5•15 years ago
|
||
This feature interests a lot of web dev and it would be really useful for mobile development.
Updated•15 years ago
|
Summary: implement window.media.matchMedium API for matching CSS media queries (like window.evaluateMediaQuery proposal) → implement window.styleMedia.matchMedium API for matching CSS media queries (like window.evaluateMediaQuery proposal)
Assignee | ||
Comment 6•15 years ago
|
||
There's a thread on www-style from May through to the present about this, with subject "[cssom-view] addMediumListener / removeMediumListener".
Assignee | ||
Updated•14 years ago
|
QA Contact: general → style-system
Assignee | ||
Comment 7•14 years ago
|
||
Looks like the spec is now window.matchMedia(), returning an object, rather like what I suggested in the thread in comment 6.
Assignee | ||
Updated•14 years ago
|
Summary: implement window.styleMedia.matchMedium API for matching CSS media queries (like window.evaluateMediaQuery proposal) → implement window.matchMedia API for matching CSS media queries (like window.evaluateMediaQuery proposal and earlier window.styleMedia.matchMedium draft spec)
Assignee | ||
Updated•14 years ago
|
Assignee: nobody → dbaron
Priority: -- → P4
Target Milestone: --- → mozilla6
Assignee | ||
Comment 8•14 years ago
|
||
Assignee | ||
Comment 9•14 years ago
|
||
Current work in progress (remaining work is in the TODOs at the top):
http://hg.mozilla.org/users/dbaron_mozilla.com/patches/raw-file/70e160bb8023/window-matchMedia
Updated•14 years ago
|
Keywords: dev-doc-needed
Assignee | ||
Comment 10•14 years ago
|
||
Attachment #527481 -
Flags: review?(bzbarsky)
Assignee | ||
Comment 11•14 years ago
|
||
Attachment #527482 -
Flags: review?(bzbarsky)
Assignee | ||
Comment 12•14 years ago
|
||
Attachment #527483 -
Flags: review?(bzbarsky)
Assignee | ||
Comment 13•14 years ago
|
||
I added a few more code comments to document interesting things.
Attachment #527483 -
Attachment is obsolete: true
Attachment #527490 -
Flags: review?(bzbarsky)
Attachment #527483 -
Flags: review?(bzbarsky)
Comment 14•14 years ago
|
||
Comment on attachment 527481 [details] [diff] [review]
patch 1: given infallible malloc, stop checking for failed CSS parser allocation
r=me
Attachment #527481 -
Flags: review?(bzbarsky) → review+
Comment 15•14 years ago
|
||
Comment on attachment 527482 [details] [diff] [review]
patch 2: allow null media query cache key where needed
r=me
Attachment #527482 -
Flags: review?(bzbarsky) → review+
Comment 16•14 years ago
|
||
Comment on attachment 527490 [details] [diff] [review]
patch 3: implement and test window.matchMedia()
>+ // Note that we intentionally send the notifications in the order
>+ // (a) media query lists in the order created and (b) each list's
>+ // listeners in the order added.
That first "in the order" bit doesn't really make sense with what follows.... rephrase?
r=me with that nit.
Attachment #527490 -
Flags: review?(bzbarsky) → review+
Assignee | ||
Comment 17•14 years ago
|
||
Rephrased as:
// Note that we intentionally send the notifications to media query
// lists in the order they were created and, for each list, to the
// listeners in the order added.
Assignee | ||
Comment 18•14 years ago
|
||
https://hg.mozilla.org/mozilla-central/rev/1cd6b2cce8a8
https://hg.mozilla.org/mozilla-central/rev/183330b5a008
https://hg.mozilla.org/mozilla-central/rev/1b37bbdb15b7
Status: NEW → RESOLVED
Closed: 14 years ago
Resolution: --- → FIXED
Assignee | ||
Comment 19•14 years ago
|
||
Oh, and in order to fix a test failure, I made one other change before landing, which was to change the IsSafeToRunScript assertion into:
if (!nsContentUtils::IsSafeToRunScript()) {
NS_ABORT_IF_FALSE(mDocument->IsBeingUsedAsImage(),
"How did we get here? Are we failing to notify "
"listeners that we should notify?");
return;
}
since we do get MediaFeatureValuesChanged notifications in image documents when it's not safe to run script, since their flush implementation allows flushes through when it isn't.
Comment 20•14 years ago
|
||
It just occurred to me... should we be calling this MozMatchMedia?
Assignee | ||
Comment 21•14 years ago
|
||
Blogged at: http://dbaron.org/log/20110422-matchMedia
Regarding prefixes: I'm generally somewhat skeptical about prefixing DOM APIs, especially ones in draft specs. But do you think we should? (And, fwiw, WebKit is currently shipping with the previous draft proposal, window.styleMedia, unprefixed.)
Comment 22•14 years ago
|
||
We have prefixed some DOM APIs but not others. I personally am in favor of it, because if things change drastically it makes it easier to clarify documentation.
Comment 23•14 years ago
|
||
FWIW, Chrome 12 is shipping with window.matchMedia and window.styleMedia, both unprefixed. It doesn't seem worth it to prefix here.
Comment 24•14 years ago
|
||
(In reply to comment #23)
> FWIW, Chrome 12 is shipping with window.matchMedia and window.styleMedia, both
> unprefixed. It doesn't seem worth it to prefix here.
Isn't window.styleMedia obsolete? Seems like a bad example for introducing bleeding-edge stuff non-prefixed...
Comment 25•14 years ago
|
||
Documentation added:
https://developer.mozilla.org/en/DOM/MediaQueryList
https://developer.mozilla.org/en/DOM/MediaQueryListListener
https://developer.mozilla.org/en/DOM/window.matchMedia
https://developer.mozilla.org/en/CSS/Using_media_queries_from_code
These pages have been updated with links to the new articles as appropriate:
https://developer.mozilla.org/en/DOM/window
https://developer.mozilla.org/en/CSS/Media_queries
https://developer.mozilla.org/en/Firefox_6_for_developers#DOM
Keywords: dev-doc-needed → dev-doc-complete
marked sec-review-needed and assigned to Jesse to make fuzzer modifications
Keywords: sec-review-needed
Whiteboard: [sr:jesse]
Updated•13 years ago
|
Whiteboard: [sr:jesse] → [secr:jesse]
Updated•13 years ago
|
Whiteboard: [secr:jesse] → [sec-assigned:jesse]
Updated•12 years ago
|
Flags: sec-review?(jruderman)
Keywords: sec-review-needed
Updated•12 years ago
|
Flags: sec-review?(jruderman)
Whiteboard: [sec-assigned:jesse]
You need to log in
before you can comment on or make changes to this bug.
Description
•