2009-08-05 Simon Fraser <simon.fraser@apple.com>
authorsimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 7 Aug 2009 00:32:39 +0000 (00:32 +0000)
committersimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 7 Aug 2009 00:32:39 +0000 (00:32 +0000)
        Reviewed by Darin Adler.

        Implement the matchMedium method on the Media interface described in the CSSOM View Module.
        https://bugs.webkit.org/show_bug.cgi?id=22495

        Add a new Media interface, obtainable via the AbstractView, that can
        evaluate queries via its matchesMedium() method.

        Test: fast/media/matchmedium-query-api.html

        * DerivedSources.cpp:
        * DerivedSources.make:
        * GNUmakefile.am:
        * WebCore.gypi:
        * WebCore.pro:
        * WebCore.vcproj/WebCore.vcproj:
        * WebCore.xcodeproj/project.pbxproj:
        * WebCoreSources.bkl:
        Add Media.* files to the build.

        * css/Media.cpp: Added.
        (WebCore::Media::Media):
        (WebCore::Media::type):
        (WebCore::Media::matchMedium):
        * css/Media.h: Added.
        (WebCore::Media::create):
        (WebCore::Media::document):
        * css/Media.idl: Added.
        Media::matchMedium() uses a MediaQueryEvaluator() to test the query.

        * page/AbstractView.idl:
        * page/DOMWindow.cpp:
        (WebCore::DOMWindow::media):
        * page/DOMWindow.h:
        * page/DOMWindow.idl:
        Add a readonly attribute for Media.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@46874 268f45cc-cd09-0410-ab3c-d52691b4dbfc

22 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/dom/Window/window-properties-expected.txt
LayoutTests/fast/dom/prototype-inheritance-2-expected.txt
LayoutTests/fast/dom/prototype-inheritance-expected.txt
LayoutTests/fast/media/matchmedium-query-api-expected.txt [new file with mode: 0644]
LayoutTests/fast/media/matchmedium-query-api.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/DerivedSources.cpp
WebCore/DerivedSources.make
WebCore/GNUmakefile.am
WebCore/WebCore.gypi
WebCore/WebCore.pro
WebCore/WebCore.vcproj/WebCore.vcproj
WebCore/WebCore.xcodeproj/project.pbxproj
WebCore/WebCoreSources.bkl
WebCore/css/Media.cpp [new file with mode: 0644]
WebCore/css/Media.h [new file with mode: 0644]
WebCore/css/Media.idl [new file with mode: 0644]
WebCore/page/AbstractView.idl
WebCore/page/DOMWindow.cpp
WebCore/page/DOMWindow.h
WebCore/page/DOMWindow.idl

index ef11068..7515788 100644 (file)
@@ -1,3 +1,13 @@
+2009-08-05  Simon Fraser  <simon.fraser@apple.com>
+
+        Reviewed by Darin Adler.
+
+        Implement the matchMedium method on the Media interface described in the CSSOM View Module.
+        https://bugs.webkit.org/show_bug.cgi?id=22495
+
+        * fast/media/matchmedium-query-api-expected.txt: Added.
+        * fast/media/matchmedium-query-api.html: Added.
+
 2009-08-06  Darin Adler  <darin@apple.com>
 
         Reviewed by Mark Rowe.
index 18497df..9a79ba8 100644 (file)
@@ -1691,6 +1691,9 @@ window.locationbar.visible [boolean]
 window.log [function]
 window.logProperties [function]
 window.logValue [function]
+window.media [object Media]
+window.media.matchMedium [function]
+window.media.type [string]
 window.menubar [object BarInfo]
 window.menubar.visible [boolean]
 window.moveBy [function]
index 73c84c1..1378b2e 100644 (file)
@@ -245,9 +245,12 @@ PASS History from inner.history
 PASS HistoryPrototype from inner.history.__proto__
 PASS Location from inner.document.location
 PASS LocationPrototype from inner.document.location.__proto__
+PASS Media from inner.media
+PASS MediaConstructor from inner.media.constructor
 PASS MediaList from inner.document.styleSheets.0.media
 PASS MediaListConstructor from inner.document.styleSheets.0.media.constructor
 PASS MediaListPrototype from inner.document.styleSheets.0.media.__proto__
+PASS MediaPrototype from inner.media.__proto__
 PASS MimeType from inner.clientInformation.mimeTypes.0
 PASS MimeTypeArray from inner.clientInformation.mimeTypes
 PASS MimeTypeArrayConstructor from inner.clientInformation.mimeTypes.constructor
index e778f22..cbc4af5 100644 (file)
@@ -421,6 +421,8 @@ PASS inner.location.isInner is true
 PASS inner.location.constructor.isInner is true
 PASS inner.locationbar.isInner is true
 PASS inner.locationbar.constructor.isInner is true
+PASS inner.media.isInner is true
+PASS inner.media.constructor.isInner is true
 PASS inner.menubar.isInner is true
 PASS inner.menubar.constructor.isInner is true
 FAIL inner.moveBy.isInner should be true. Was false.
diff --git a/LayoutTests/fast/media/matchmedium-query-api-expected.txt b/LayoutTests/fast/media/matchmedium-query-api-expected.txt
new file mode 100644 (file)
index 0000000..6146b03
--- /dev/null
@@ -0,0 +1,15 @@
+Test the media interface: http://dev.w3.org/csswg/cssom-view/#the-media-interface.
+
+"screen" evaluates to true: PASS
+"projection" evaluates to false: PASS
+"all and (color)" evaluates to true: PASS
+"not projection and (color)" evaluates to true: PASS
+"(color)" evaluates to true: PASS
+"(color" evaluates to false: PASS
+"color" evaluates to false: PASS
+"garbage" evaluates to false: PASS
+"(min-device-width: 100px)" evaluates to true: PASS
+"(min-device-width: 50000px)" evaluates to false: PASS
+"(-webkit-animation: 1)" evaluates to true: PASS
+"(-webkit-transform-2d)" evaluates to true: PASS
+
diff --git a/LayoutTests/fast/media/matchmedium-query-api.html b/LayoutTests/fast/media/matchmedium-query-api.html
new file mode 100644 (file)
index 0000000..96353f8
--- /dev/null
@@ -0,0 +1,54 @@
+<html>
+<head>
+<title>Test CSSOM View module: Media interface</title>
+<style type="text/css">
+
+</style>
+<script type="text/javascript" charset="utf-8">
+  if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+  
+  function log(m)
+  {
+    var results = document.getElementById('results');
+    results.innerHTML += m + '<br>';
+  }
+  
+  function testQuery(query, expected)
+  {
+    var isTrue = document.defaultView.media.matchMedium(query);
+
+    var message = '\"' + query + '\" evaluates to ' + (isTrue ? 'true' : 'false');
+    message += (isTrue == expected) ? ': PASS' : ': FAIL';
+    log(message);
+  }
+  
+  function runTests()
+  {
+    testQuery('screen', true);
+    testQuery('projection', false);
+
+    testQuery('all and (color)', true);
+    testQuery('not projection and (color)', true);
+    testQuery('(color)', true);
+    testQuery('(color', false);
+    testQuery('color', false);
+
+    testQuery('garbage', false);
+
+    testQuery('(min-device-width: 100px)', true);
+    testQuery('(min-device-width: 50000px)', false);
+
+    testQuery('(-webkit-animation: 1)', true);
+    testQuery('(-webkit-transform-2d)', true);
+  }
+
+</script>
+</head>
+<body onload="runTests()">
+  <p>Test the media interface: <a href="http://dev.w3.org/csswg/cssom-view/#the-media-interface" title="CSSOM View Module">http://dev.w3.org/csswg/cssom-view/#the-media-interface</a>.</p>
+  <div id="results">
+    
+  </div>
+</body>
+</html>
index 87f3a49..398aebf 100644 (file)
@@ -1,3 +1,42 @@
+2009-08-05  Simon Fraser  <simon.fraser@apple.com>
+
+        Reviewed by Darin Adler.
+
+        Implement the matchMedium method on the Media interface described in the CSSOM View Module.
+        https://bugs.webkit.org/show_bug.cgi?id=22495
+        
+        Add a new Media interface, obtainable via the AbstractView, that can
+        evaluate queries via its matchesMedium() method.
+
+        Test: fast/media/matchmedium-query-api.html
+
+        * DerivedSources.cpp:
+        * DerivedSources.make:
+        * GNUmakefile.am:
+        * WebCore.gypi:
+        * WebCore.pro:
+        * WebCore.vcproj/WebCore.vcproj:
+        * WebCore.xcodeproj/project.pbxproj:
+        * WebCoreSources.bkl:
+        Add Media.* files to the build.
+
+        * css/Media.cpp: Added.
+        (WebCore::Media::Media):
+        (WebCore::Media::type):
+        (WebCore::Media::matchMedium):
+        * css/Media.h: Added.
+        (WebCore::Media::create):
+        (WebCore::Media::document):
+        * css/Media.idl: Added.
+        Media::matchMedium() uses a MediaQueryEvaluator() to test the query.
+
+        * page/AbstractView.idl:
+        * page/DOMWindow.cpp:
+        (WebCore::DOMWindow::media):
+        * page/DOMWindow.h:
+        * page/DOMWindow.idl:
+        Add a readonly attribute for Media.
+
 2009-08-06  Michelangelo De Simone  <micdesim@gmail.com>
 
         Reviewed by Darin Adler.
index 3998016..b0311e2 100644 (file)
 #include "JSJavaScriptCallFrame.cpp"
 #include "JSKeyboardEvent.cpp"
 #include "JSLocation.cpp"
+#include "JSMedia.cpp"
 #include "JSMediaError.cpp"
 #include "JSMediaList.cpp"
 #include "JSMessageChannel.cpp"
index ddacedf..41cc5e7 100644 (file)
@@ -176,6 +176,7 @@ DOM_CLASSES = \
     InspectorBackend \
     KeyboardEvent \
     Location \
+    Media \
     MediaError \
     MediaList \
     MessageChannel \
index b34370e..aa7a0f2 100644 (file)
@@ -99,6 +99,7 @@ IDL_BINDINGS += \
        WebCore/css/CSSVariablesDeclaration.idl \
        WebCore/css/CSSVariablesRule.idl \
        WebCore/css/Counter.idl \
+       WebCore/css/Media.idl \
        WebCore/css/MediaList.idl \
        WebCore/css/RGBColor.idl \
        WebCore/css/Rect.idl \
@@ -579,6 +580,8 @@ webcore_sources += \
        WebCore/css/FontValue.h \
        WebCore/css/MediaFeatureNames.cpp \
        WebCore/css/MediaFeatureNames.h \
+       WebCore/css/Media.cpp \
+       WebCore/css/Media.h \
        WebCore/css/MediaList.cpp \
        WebCore/css/MediaList.h \
        WebCore/css/MediaQuery.cpp \
index d153c1f..39e746c 100644 (file)
@@ -20,6 +20,7 @@
             'css/CSSVariablesDeclaration.idl',
             'css/CSSVariablesRule.idl',
             'css/Counter.idl',
+            'css/Media.idl',
             'css/MediaList.idl',
             'css/RGBColor.idl',
             'css/Rect.idl',
             'css/FontValue.h',
             'css/MediaFeatureNames.cpp',
             'css/MediaFeatureNames.h',
+            'css/Media.cpp',
+            'css/Media.h',
             'css/MediaList.cpp',
             'css/MediaList.h',
             'css/MediaQuery.cpp',
index 910ae65..a0b8389 100644 (file)
@@ -286,6 +286,7 @@ IDL_BINDINGS += \
     css/CSSValueList.idl \
     css/CSSVariablesDeclaration.idl \
     css/CSSVariablesRule.idl \
+    css/Media.idl \
     css/MediaList.idl \
     css/RGBColor.idl \
     css/Rect.idl \
@@ -608,6 +609,7 @@ SOURCES += \
     css/FontFamilyValue.cpp \
     css/FontValue.cpp \
     css/MediaFeatureNames.cpp \
+    css/Media.cpp \
     css/MediaList.cpp \
     css/MediaQuery.cpp \
     css/MediaQueryEvaluator.cpp \
@@ -1266,6 +1268,7 @@ HEADERS += \
     css/FontFamilyValue.h \
     css/FontValue.h \
     css/MediaFeatureNames.h \
+    css/Media.h \
     css/MediaList.h \
     css/MediaQueryEvaluator.h \
     css/MediaQueryExp.h \
index 67b7c2e..116af6d 100644 (file)
                                >\r
                        </File>\r
                        <File\r
+                               RelativePath="$(WebKitOutputDir)\obj\$(ProjectName)\DerivedSources\JSMedia.h"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="$(WebKitOutputDir)\obj\$(ProjectName)\DerivedSources\JSMedia.cpp"\r
+                               >\r
+                       </File>\r
+                       <File\r
                                RelativePath="$(WebKitOutputDir)\obj\$(ProjectName)\DerivedSources\JSMediaError.cpp"\r
                                >\r
                                <FileConfiguration\r
                                >\r
                        </File>\r
                        <File\r
+                               RelativePath="..\css\Media.cpp"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\css\Media.h"\r
+                               >\r
+                       </File>\r
+                       <File\r
                                RelativePath="..\css\MediaFeatureNames.cpp"\r
                                >\r
                        </File>\r
index 98acbe4..3939721 100644 (file)
                0FCF332F0F2B9A25004B6795 /* WebLayer.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FCF332B0F2B9A25004B6795 /* WebLayer.h */; };
                0FD723820EC8BD9300CA5DD7 /* FloatQuad.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FD723800EC8BD9300CA5DD7 /* FloatQuad.h */; settings = {ATTRIBUTES = (Private, ); }; };
                0FD723830EC8BD9300CA5DD7 /* FloatQuad.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0FD723810EC8BD9300CA5DD7 /* FloatQuad.cpp */; };
+               0FF5025B102BA9010066F39A /* DOMMedia.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FF50259102BA9010066F39A /* DOMMedia.h */; };
+               0FF5025C102BA9010066F39A /* DOMMedia.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0FF5025A102BA9010066F39A /* DOMMedia.mm */; };
+               0FF50263102BA92C0066F39A /* DOMMediaInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FF50262102BA92B0066F39A /* DOMMediaInternal.h */; };
+               0FF50269102BA9430066F39A /* JSMedia.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0FF50267102BA9430066F39A /* JSMedia.cpp */; };
+               0FF5026A102BA9430066F39A /* JSMedia.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FF50268102BA9430066F39A /* JSMedia.h */; };
+               0FF50271102BA96A0066F39A /* Media.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0FF5026E102BA9660066F39A /* Media.cpp */; };
+               0FF50272102BA96A0066F39A /* Media.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FF5026F102BA96A0066F39A /* Media.h */; };
                1402645E0AFDC19B005919E2 /* LoggingMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1402645D0AFDC19B005919E2 /* LoggingMac.mm */; };
                1403B99709EB13AF00797C7F /* DOMWindow.h in Headers */ = {isa = PBXBuildFile; fileRef = 1403B99509EB13AF00797C7F /* DOMWindow.h */; settings = {ATTRIBUTES = (Private, ); }; };
                1403B99809EB13AF00797C7F /* DOMWindow.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1403B99609EB13AF00797C7F /* DOMWindow.cpp */; };
                0FCF332B0F2B9A25004B6795 /* WebLayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebLayer.h; sourceTree = "<group>"; };
                0FD723800EC8BD9300CA5DD7 /* FloatQuad.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FloatQuad.h; sourceTree = "<group>"; };
                0FD723810EC8BD9300CA5DD7 /* FloatQuad.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FloatQuad.cpp; sourceTree = "<group>"; };
+               0FF50259102BA9010066F39A /* DOMMedia.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOMMedia.h; sourceTree = "<group>"; };
+               0FF5025A102BA9010066F39A /* DOMMedia.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DOMMedia.mm; sourceTree = "<group>"; };
+               0FF50262102BA92B0066F39A /* DOMMediaInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOMMediaInternal.h; sourceTree = "<group>"; };
+               0FF50267102BA9430066F39A /* JSMedia.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSMedia.cpp; sourceTree = "<group>"; };
+               0FF50268102BA9430066F39A /* JSMedia.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSMedia.h; sourceTree = "<group>"; };
+               0FF5026E102BA9660066F39A /* Media.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Media.cpp; sourceTree = "<group>"; };
+               0FF5026F102BA96A0066F39A /* Media.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Media.h; sourceTree = "<group>"; };
+               0FF50270102BA96A0066F39A /* Media.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Media.idl; sourceTree = "<group>"; };
                1402645D0AFDC19B005919E2 /* LoggingMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = LoggingMac.mm; sourceTree = "<group>"; };
                1403B90C09EB124500797C7F /* DOMWindow.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = DOMWindow.idl; sourceTree = "<group>"; };
                1403B99509EB13AF00797C7F /* DOMWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOMWindow.h; sourceTree = "<group>"; };
                850657040AAB476C002D15C0 /* StyleSheets */ = {
                        isa = PBXGroup;
                        children = (
+                               0FF50259102BA9010066F39A /* DOMMedia.h */,
+                               0FF5025A102BA9010066F39A /* DOMMedia.mm */,
                                850656F80AAB4763002D15C0 /* DOMMediaList.h */,
                                850656F90AAB4763002D15C0 /* DOMMediaList.mm */,
                                850656FA0AAB4763002D15C0 /* DOMStyleSheet.h */,
                                85E711800AC5D5350053270F /* DOMHTMLTitleElementInternal.h */,
                                85E711810AC5D5350053270F /* DOMHTMLUListElementInternal.h */,
                                85989DC50ACC8BBD00A0BC51 /* DOMKeyboardEventInternal.h */,
+                               0FF50262102BA92B0066F39A /* DOMMediaInternal.h */,
                                85E711820AC5D5350053270F /* DOMMediaListInternal.h */,
                                75793ED20D0CE85B007FC0AC /* DOMMessageEventInternal.h */,
                                E1ADEDD40E76BD60004A1A5E /* DOMMessagePortInternal.h */,
                                BC686C790E0C330100DE8A08 /* JSCSSVariablesDeclaration.h */,
                                BC686C7A0E0C330100DE8A08 /* JSCSSVariablesRule.cpp */,
                                BC686C7B0E0C330100DE8A08 /* JSCSSVariablesRule.h */,
+                               0FF50267102BA9430066F39A /* JSMedia.cpp */,
+                               0FF50268102BA9430066F39A /* JSMedia.h */,
                                BC3C39B40C0D3D8D005F4D7A /* JSMediaList.cpp */,
                                BC3C39B50C0D3D8D005F4D7A /* JSMediaList.h */,
                                BCFE2F0F0C1B58370020235F /* JSRect.cpp */,
                                07AFE5900F1446BD00841617 /* mediaControlsQT.css */,
                                4E19591F0A39DABA00220FE5 /* MediaFeatureNames.cpp */,
                                4E1959200A39DABA00220FE5 /* MediaFeatureNames.h */,
+                               0FF5026E102BA9660066F39A /* Media.cpp */,
+                               0FF5026F102BA96A0066F39A /* Media.h */,
+                               0FF50270102BA96A0066F39A /* Media.idl */,
                                A8EA80010A19516E00A8EF5F /* MediaList.cpp */,
                                A8EA80060A19516E00A8EF5F /* MediaList.h */,
                                85C56C5B0AA87AFD00D95755 /* MediaList.idl */,
                                93F199ED08245E59001E9ABC /* XSLTProcessor.h in Headers */,
                                E1BE512E0CF6C512002EA959 /* XSLTUnicodeSort.h in Headers */,
                                97DD4D870FDF4D6E00ECF9A4 /* XSSAuditor.h in Headers */,
+                               0FF5025B102BA9010066F39A /* DOMMedia.h in Headers */,
+                               0FF50263102BA92C0066F39A /* DOMMediaInternal.h in Headers */,
+                               0FF5026A102BA9430066F39A /* JSMedia.h in Headers */,
+                               0FF50272102BA96A0066F39A /* Media.h in Headers */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                                93F19B0408245E59001E9ABC /* XSLTProcessor.cpp in Sources */,
                                E1BE512D0CF6C512002EA959 /* XSLTUnicodeSort.cpp in Sources */,
                                97DD4D860FDF4D6E00ECF9A4 /* XSSAuditor.cpp in Sources */,
+                               0FF5025C102BA9010066F39A /* DOMMedia.mm in Sources */,
+                               0FF50269102BA9430066F39A /* JSMedia.cpp in Sources */,
+                               0FF50271102BA96A0066F39A /* Media.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index b6ab7a9..192da2e 100644 (file)
@@ -218,6 +218,7 @@ This file contains the list of files needed to build WebCore.
         css/FontFamilyValue.cpp
         css/FontValue.cpp
         css/MediaFeatureNames.cpp
+        css/Media.cpp
         css/MediaList.cpp
         css/MediaQuery.cpp
         css/MediaQueryEvaluator.cpp
@@ -358,6 +359,7 @@ This file contains the list of files needed to build WebCore.
         DerivedSources/WebCore/JSJavaScriptCallFrame.cpp
         DerivedSources/WebCore/JSKeyboardEvent.cpp
         DerivedSources/WebCore/JSLocation.cpp
+        DerivedSources/WebCore/JSMedia.cpp
         DerivedSources/WebCore/JSMediaList.cpp
         DerivedSources/WebCore/JSMessageChannel.cpp
         DerivedSources/WebCore/JSMessageEvent.cpp
diff --git a/WebCore/css/Media.cpp b/WebCore/css/Media.cpp
new file mode 100644 (file)
index 0000000..57c4aac
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2009 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#include "config.h"
+
+#include "Media.h"
+#include "CSSStyleSelector.h"
+#include "Frame.h"
+#include "FrameView.h"
+#include "MediaList.h"
+#include "MediaQueryEvaluator.h"
+
+namespace WebCore {
+
+Media::Media(DOMWindow* window)
+    : m_window(window)
+{
+}
+
+String Media::type() const
+{
+    Frame* frame = m_window->frame();
+    FrameView* view = frame ? frame->view() : 0;
+    if (view)
+        return view->mediaType();
+
+    return String();
+}
+
+bool Media::matchMedium(const String& query) const
+{
+    Document* document = m_window->document();
+    Frame* frame = m_window->frame();
+
+    CSSStyleSelector* styleSelector = document->styleSelector();
+    Element* docElement = document->documentElement();
+    if (!styleSelector || !docElement || !frame)
+        return false;
+
+    RefPtr<RenderStyle> rootStyle = styleSelector->styleForElement(docElement, 0 /*defaultParent*/, false /*allowSharing*/, true /*resolveForRootDefault*/);
+    RefPtr<MediaList> media = MediaList::create();
+
+    ExceptionCode ec = 0;
+    media->setMediaText(query, ec);
+    if (ec)
+        return false;
+
+    MediaQueryEvaluator screenEval(type(), frame, rootStyle.get());
+    return screenEval.eval(media.get());
+}
+
+} // namespace WebCore
diff --git a/WebCore/css/Media.h b/WebCore/css/Media.h
new file mode 100644 (file)
index 0000000..0d7b504
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2009 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#ifndef Media_h
+#define Media_h
+
+#include "DOMWindow.h"
+
+namespace WebCore {
+
+class Media : public RefCounted<Media> {
+public:
+    static PassRefPtr<Media> create(DOMWindow* window)
+    {
+        return adoptRef(new Media(window));
+    }
+    
+    Document* document() const { return m_window->document(); }
+
+    String type() const;
+
+    bool matchMedium(const String&) const;
+    
+private:
+    Media(DOMWindow*);
+
+    RefPtr<DOMWindow> m_window;
+};
+
+} // namespace
+
+#endif // Media_h
diff --git a/WebCore/css/Media.idl b/WebCore/css/Media.idl
new file mode 100644 (file)
index 0000000..b01d712
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2009 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+module view {
+    interface [
+        GenerateConstructor,
+    ] Media {
+        readonly attribute DOMString type;
+        boolean matchMedium(in DOMString mediaquery);
+    };
+}
index 5b7ce89..36865de 100644 (file)
@@ -31,6 +31,7 @@ module views {
         ObjCCustomImplementation
     ] AbstractView {
         readonly attribute Document document;
+        readonly attribute Media media;
     };
 
 }
index e8f9004..4bf8b2a 100644 (file)
@@ -51,6 +51,7 @@
 #include "History.h"
 #include "InspectorController.h"
 #include "Location.h"
+#include "Media.h"
 #include "MessageEvent.h"
 #include "Navigator.h"
 #include "Page.h"
@@ -1002,6 +1003,11 @@ Document* DOMWindow::document() const
     return m_frame->document();
 }
 
+PassRefPtr<Media> DOMWindow::media() const
+{
+    return Media::create(const_cast<DOMWindow*>(this));
+}
+
 PassRefPtr<CSSStyleDeclaration> DOMWindow::getComputedStyle(Element* elt, const String&) const
 {
     if (!elt)
index eac936f..9ee537d 100644 (file)
@@ -52,6 +52,7 @@ namespace WebCore {
     class Frame;
     class History;
     class Location;
+    class Media;
     class MessagePort;
     class Navigator;
     class Node;
@@ -171,6 +172,8 @@ namespace WebCore {
 
         // DOM Level 2 AbstractView Interface
         Document* document() const;
+        // CSSOM View Module
+        PassRefPtr<Media> media() const;
 
         // DOM Level 2 Style Interface
         PassRefPtr<CSSStyleDeclaration> getComputedStyle(Element*, const String& pseudoElt) const;
index e1c9ff0..e960bb8 100644 (file)
@@ -139,6 +139,9 @@ module window {
         // DOM Level 2 AbstractView Interface
         readonly attribute Document document;
 
+        // CSSOM View Module
+        readonly attribute Media media;
+
         // DOM Level 2 Style Interface
         CSSStyleDeclaration getComputedStyle(in Element element,
                                              in DOMString pseudoElement);