Changeset 14779 in webkit


Ignore:
Timestamp:
Jun 9, 2006, 10:09:08 AM (19 years ago)
Author:
bdakin
Message:

Reviewed by Hyatt. Tweaked by Maciej. Tweaks reviewed by Beth.
Landed by Beth.

CSS3 Media Queries implementation.
<http://bugzilla.opendarwin.org/show_bug.cgi?id=4127>

  • WebCore.xcodeproj/project.pbxproj:
  • bindings/js/kjs_css.cpp: (KJS::DOMMediaList::put): (KJS::KJS::DOMMediaListProtoFunc::callAsFunction):
  • bindings/objc/DOMCSS.mm: (-[DOMMediaList setMediaText:]): (-[DOMMediaList deleteMedium:]): (-[DOMMediaList appendMedium:]):
  • css/CSSGrammar.y:
  • css/MediaFeatureNames.cpp: Added. (WebCore::MediaFeatureNames::init):
  • css/MediaFeatureNames.h: Added.
  • css/MediaList.cpp: (WebCore::MediaList::MediaList): (WebCore::MediaList::~MediaList): (WebCore::parseMediaDescriptor): (WebCore::MediaList::deleteMedium): (WebCore::MediaList::mediaText): (WebCore::MediaList::setMediaText): (WebCore::MediaList::item): (WebCore::MediaList::appendMedium): (WebCore::MediaList::appendMediaQuery):
  • css/MediaList.h: (WebCore::MediaList::MediaList): (WebCore::MediaList::length): (WebCore::MediaList::mediaQueries):
  • css/MediaQuery.cpp: Added. (WebCore::MediaQuery::MediaQuery): (WebCore::MediaQuery::~MediaQuery): (WebCore::MediaQuery::operator==): (WebCore::MediaQuery::cssText):
  • css/MediaQuery.h: Added. (WebCore::MediaQuery::): (WebCore::MediaQuery::restrictor): (WebCore::MediaQuery::expressions): (WebCore::MediaQuery::mediaType): (WebCore::MediaQuery::append):
  • css/MediaQueryEvaluator.cpp: Added. (WebCore::): (WebCore::MediaQueryEvaluator): (WebCore::MediaQueryEvaluator::~MediaQueryEvaluator): (WebCore::MediaQueryEvaluator::mediaTypeMatch): (WebCore::applyRestrictor): (WebCore::MediaQueryEvaluator::eval): (WebCore::parseAspectRatio): (WebCore::cmpvalue): (WebCore::numberValue): (WebCore::colorMediaFeatureEval): (WebCore::monochromeMediaFeatureEval): (WebCore::device_aspect_ratioMediaFeatureEval): (WebCore::gridMediaFeatureEval): (WebCore::device_heightMediaFeatureEval): (WebCore::device_widthMediaFeatureEval): (WebCore::heightMediaFeatureEval): (WebCore::widthMediaFeatureEval): (WebCore::min_colorMediaFeatureEval): (WebCore::max_colorMediaFeatureEval): (WebCore::min_monochromeMediaFeatureEval): (WebCore::max_monochromeMediaFeatureEval): (WebCore::min_device_aspect_ratioMediaFeatureEval): (WebCore::max_device_aspect_ratioMediaFeatureEval): (WebCore::min_heightMediaFeatureEval): (WebCore::max_heightMediaFeatureEval): (WebCore::min_widthMediaFeatureEval): (WebCore::max_widthMediaFeatureEval): (WebCore::min_device_heightMediaFeatureEval): (WebCore::max_device_heightMediaFeatureEval): (WebCore::min_device_widthMediaFeatureEval): (WebCore::max_device_widthMediaFeatureEval): (WebCore::createFunctionMap):
  • css/MediaQueryEvaluator.h: Added.
  • css/MediaQueryExp.cpp: Added. (WebCore::MediaQueryExp::MediaQueryExp): (WebCore::MediaQueryExp::~MediaQueryExp):
  • css/MediaQueryExp.h: Added. (WebCore::MediaQueryExp::mediaFeature): (WebCore::MediaQueryExp::value): (WebCore::MediaQueryExp::operator==):
  • css/StyleSheet.cpp: (WebCore::StyleSheet::setMedia):
  • css/cssparser.cpp: (WebCore::CSSParser::CSSParser): (WebCore::CSSParser::~CSSParser): (WebCore::CSSParser::setupParser): (WebCore::CSSParser::parseMediaQuery): (WebCore::CSSParser::createFloatingMediaQueryExp): (WebCore::CSSParser::sinkFloatingMediaQueryExp): (WebCore::CSSParser::createFloatingMediaQueryExpList): (WebCore::CSSParser::sinkFloatingMediaQueryExpList): (WebCore::CSSParser::createFloatingMediaQuery): (WebCore::CSSParser::sinkFloatingMediaQuery):
  • css/cssparser.h:
  • css/cssstyleselector.cpp: (WebCore::CSSStyleSelector::CSSStyleSelector): (WebCore::CSSStyleSelector::init): (WebCore::CSSStyleSelector::~CSSStyleSelector): (WebCore::CSSStyleSelector::loadDefaultStyle): (WebCore::CSSStyleSelector::matchUARules): (WebCore::CSSStyleSelector::styleForElement): (WebCore::CSSStyleSelector::pseudoStyleForElement): (WebCore::CSSStyleSelector::updateFont): (WebCore::CSSStyleSelector::cacheBorderAndBackground): (WebCore::CSSStyleSelector::styleRulesForElement): (WebCore::CSSRuleSet::addRulesFromSheet):
  • css/cssstyleselector.h:
  • css/maketokenizer:
  • css/tokenizer.flex:
  • dom/DOMImplementation.cpp: (WebCore::DOMImplementation::createCSSStyleSheet):
  • html/HTMLLinkElement.cpp: (WebCore::HTMLLinkElement::process): (WebCore::HTMLLinkElement::setStyleSheet):
  • html/HTMLStyleElement.cpp: (WebCore::HTMLStyleElement::childrenChanged):
  • ksvg2/svg/SVGDOMImplementation.cpp: (SVGDOMImplementation::createCSSStyleSheet):
  • ksvg2/svg/SVGStyleElement.cpp: (WebCore::SVGStyleElement::childrenChanged):
  • page/Frame.cpp: (WebCore::Frame::Frame):
  • platform/Screen.h:
  • platform/mac/ScreenMac.mm: (WebCore::screenDepthPerComponent): (WebCore::screenIsMonochrome):
Location:
trunk
Files:
234 added
23 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r14777 r14779  
     12006-06-09  Kimmo Kinnunen  <kimmo.t.kinnunen@nokia.com>
     2
     3        Reviewed by Hyatt.
     4
     5        Test cases for CSS3 Media Queries implementation.
     6        <http://bugzilla.opendarwin.org/show_bug.cgi?id=4127>
     7
     8        * fast/media/import-p-green.css: Added.
     9        * fast/media/import-p-red.css: Added.
     10        * fast/media/media-descriptor-syntax-01-expected.checksum: Added.
     11        * fast/media/media-descriptor-syntax-01-expected.png: Added.
     12        * fast/media/media-descriptor-syntax-01-expected.txt: Added.
     13        * fast/media/media-descriptor-syntax-01.html: Added.
     14        * fast/media/media-descriptor-syntax-02-expected.checksum: Added.
     15        * fast/media/media-descriptor-syntax-02-expected.png: Added.
     16        * fast/media/media-descriptor-syntax-02-expected.txt: Added.
     17        * fast/media/media-descriptor-syntax-02.html: Added.
     18        * fast/media/media-descriptor-syntax-03-expected.checksum: Added.
     19        * fast/media/media-descriptor-syntax-03-expected.png: Added.
     20        * fast/media/media-descriptor-syntax-03-expected.txt: Added.
     21        * fast/media/media-descriptor-syntax-03.html: Added.
     22        * fast/media/media-descriptor-syntax-04-expected.checksum: Added.
     23        * fast/media/media-descriptor-syntax-04-expected.png: Added.
     24        * fast/media/media-descriptor-syntax-04-expected.txt: Added.
     25        * fast/media/media-descriptor-syntax-04.html: Added.
     26        * fast/media/media-descriptor-syntax-05-expected.checksum: Added.
     27        * fast/media/media-descriptor-syntax-05-expected.png: Added.
     28        * fast/media/media-descriptor-syntax-05-expected.txt: Added.
     29        * fast/media/media-descriptor-syntax-05.html: Added.
     30        * fast/media/media-descriptor-syntax-06-expected.checksum: Added.
     31        * fast/media/media-descriptor-syntax-06-expected.png: Added.
     32        * fast/media/media-descriptor-syntax-06-expected.txt: Added.
     33        * fast/media/media-descriptor-syntax-06.html: Added.
     34        * fast/media/media-type-syntax-01-expected.checksum: Added.
     35        * fast/media/media-type-syntax-01-expected.png: Added.
     36        * fast/media/media-type-syntax-01-expected.txt: Added.
     37        * fast/media/media-type-syntax-01.html: Added.
     38        * fast/media/media-type-syntax-02-expected.checksum: Added.
     39        * fast/media/media-type-syntax-02-expected.png: Added.
     40        * fast/media/media-type-syntax-02-expected.txt: Added.
     41        * fast/media/media-type-syntax-02.html: Added.
     42        * fast/media/mq-compound-query-01-expected.checksum: Added.
     43        * fast/media/mq-compound-query-01-expected.png: Added.
     44        * fast/media/mq-compound-query-01-expected.txt: Added.
     45        * fast/media/mq-compound-query-01.html: Added.
     46        * fast/media/mq-compound-query-02-expected.checksum: Added.
     47        * fast/media/mq-compound-query-02-expected.png: Added.
     48        * fast/media/mq-compound-query-02-expected.txt: Added.
     49        * fast/media/mq-compound-query-02.html: Added.
     50        * fast/media/mq-compound-query-03-expected.checksum: Added.
     51        * fast/media/mq-compound-query-03-expected.png: Added.
     52        * fast/media/mq-compound-query-03-expected.txt: Added.
     53        * fast/media/mq-compound-query-03.html: Added.
     54        * fast/media/mq-compound-query-04-expected.checksum: Added.
     55        * fast/media/mq-compound-query-04-expected.png: Added.
     56        * fast/media/mq-compound-query-04-expected.txt: Added.
     57        * fast/media/mq-compound-query-04.html: Added.
     58        * fast/media/mq-compound-query-05-expected.checksum: Added.
     59        * fast/media/mq-compound-query-05-expected.png: Added.
     60        * fast/media/mq-compound-query-05-expected.txt: Added.
     61        * fast/media/mq-compound-query-05.html: Added.
     62        * fast/media/mq-grid-01-expected.checksum: Added.
     63        * fast/media/mq-grid-01-expected.png: Added.
     64        * fast/media/mq-grid-01-expected.txt: Added.
     65        * fast/media/mq-grid-01.html: Added.
     66        * fast/media/mq-grid-02-expected.checksum: Added.
     67        * fast/media/mq-grid-02-expected.png: Added.
     68        * fast/media/mq-grid-02-expected.txt: Added.
     69        * fast/media/mq-grid-02.html: Added.
     70        * fast/media/mq-invalid-media-feature-01-expected.checksum: Added.
     71        * fast/media/mq-invalid-media-feature-01-expected.png: Added.
     72        * fast/media/mq-invalid-media-feature-01-expected.txt: Added.
     73        * fast/media/mq-invalid-media-feature-01.html: Added.
     74        * fast/media/mq-invalid-media-feature-02-expected.checksum: Added.
     75        * fast/media/mq-invalid-media-feature-02-expected.png: Added.
     76        * fast/media/mq-invalid-media-feature-02-expected.txt: Added.
     77        * fast/media/mq-invalid-media-feature-02.html: Added.
     78        * fast/media/mq-invalid-media-feature-03-expected.checksum: Added.
     79        * fast/media/mq-invalid-media-feature-03-expected.png: Added.
     80        * fast/media/mq-invalid-media-feature-03-expected.txt: Added.
     81        * fast/media/mq-invalid-media-feature-03.html: Added.
     82        * fast/media/mq-invalid-media-feature-04-expected.checksum: Added.
     83        * fast/media/mq-invalid-media-feature-04-expected.png: Added.
     84        * fast/media/mq-invalid-media-feature-04-expected.txt: Added.
     85        * fast/media/mq-invalid-media-feature-04.html: Added.
     86        * fast/media/mq-invalid-syntax-01-expected.checksum: Added.
     87        * fast/media/mq-invalid-syntax-01-expected.png: Added.
     88        * fast/media/mq-invalid-syntax-01-expected.txt: Added.
     89        * fast/media/mq-invalid-syntax-01.html: Added.
     90        * fast/media/mq-invalid-syntax-02-expected.checksum: Added.
     91        * fast/media/mq-invalid-syntax-02-expected.png: Added.
     92        * fast/media/mq-invalid-syntax-02-expected.txt: Added.
     93        * fast/media/mq-invalid-syntax-02.html: Added.
     94        * fast/media/mq-invalid-syntax-03-expected.checksum: Added.
     95        * fast/media/mq-invalid-syntax-03-expected.png: Added.
     96        * fast/media/mq-invalid-syntax-03-expected.txt: Added.
     97        * fast/media/mq-invalid-syntax-03.html: Added.
     98        * fast/media/mq-invalid-syntax-04-expected.checksum: Added.
     99        * fast/media/mq-invalid-syntax-04-expected.png: Added.
     100        * fast/media/mq-invalid-syntax-04-expected.txt: Added.
     101        * fast/media/mq-invalid-syntax-04.html: Added.
     102        * fast/media/mq-invalid-syntax-05-expected.checksum: Added.
     103        * fast/media/mq-invalid-syntax-05-expected.png: Added.
     104        * fast/media/mq-invalid-syntax-05-expected.txt: Added.
     105        * fast/media/mq-invalid-syntax-05.html: Added.
     106        * fast/media/mq-js-media-except-01-expected.checksum: Added.
     107        * fast/media/mq-js-media-except-01-expected.png: Added.
     108        * fast/media/mq-js-media-except-01-expected.txt: Added.
     109        * fast/media/mq-js-media-except-01.html: Added.
     110        * fast/media/mq-js-media-except-02-expected.checksum: Added.
     111        * fast/media/mq-js-media-except-02-expected.png: Added.
     112        * fast/media/mq-js-media-except-02-expected.txt: Added.
     113        * fast/media/mq-js-media-except-02.html: Added.
     114        * fast/media/mq-js-media-except-03-expected.checksum: Added.
     115        * fast/media/mq-js-media-except-03-expected.png: Added.
     116        * fast/media/mq-js-media-except-03-expected.txt: Added.
     117        * fast/media/mq-js-media-except-03.html: Added.
     118        * fast/media/mq-js-media-forward-syntax-expected.checksum: Added.
     119        * fast/media/mq-js-media-forward-syntax-expected.png: Added.
     120        * fast/media/mq-js-media-forward-syntax-expected.txt: Added.
     121        * fast/media/mq-js-media-forward-syntax.html: Added.
     122        * fast/media/mq-js-stylesheet-media-01-expected.checksum: Added.
     123        * fast/media/mq-js-stylesheet-media-01-expected.png: Added.
     124        * fast/media/mq-js-stylesheet-media-01-expected.txt: Added.
     125        * fast/media/mq-js-stylesheet-media-01.html: Added.
     126        * fast/media/mq-js-stylesheet-media-02-expected.checksum: Added.
     127        * fast/media/mq-js-stylesheet-media-02-expected.png: Added.
     128        * fast/media/mq-js-stylesheet-media-02-expected.txt: Added.
     129        * fast/media/mq-js-stylesheet-media-02.html: Added.
     130        * fast/media/mq-js-stylesheet-media-03-expected.checksum: Added.
     131        * fast/media/mq-js-stylesheet-media-03-expected.png: Added.
     132        * fast/media/mq-js-stylesheet-media-03-expected.txt: Added.
     133        * fast/media/mq-js-stylesheet-media-03.html: Added.
     134        * fast/media/mq-js-stylesheet-media-04-expected.checksum: Added.
     135        * fast/media/mq-js-stylesheet-media-04-expected.png: Added.
     136        * fast/media/mq-js-stylesheet-media-04-expected.txt: Added.
     137        * fast/media/mq-js-stylesheet-media-04.html: Added.
     138        * fast/media/mq-min-constraint-expected.checksum: Added.
     139        * fast/media/mq-min-constraint-expected.png: Added.
     140        * fast/media/mq-min-constraint-expected.txt: Added.
     141        * fast/media/mq-min-constraint.html: Added.
     142        * fast/media/mq-relative-constraints-02-expected.checksum: Added.
     143        * fast/media/mq-relative-constraints-02-expected.png: Added.
     144        * fast/media/mq-relative-constraints-02-expected.txt: Added.
     145        * fast/media/mq-relative-constraints-02.html: Added.
     146        * fast/media/mq-relative-constraints-03-expected.checksum: Added.
     147        * fast/media/mq-relative-constraints-03-expected.png: Added.
     148        * fast/media/mq-relative-constraints-03-expected.txt: Added.
     149        * fast/media/mq-relative-constraints-03.html: Added.
     150        * fast/media/mq-relative-constraints-04-expected.checksum: Added.
     151        * fast/media/mq-relative-constraints-04-expected.png: Added.
     152        * fast/media/mq-relative-constraints-04-expected.txt: Added.
     153        * fast/media/mq-relative-constraints-04.html: Added.
     154        * fast/media/mq-relative-constraints-05-expected.checksum: Added.
     155        * fast/media/mq-relative-constraints-05-expected.png: Added.
     156        * fast/media/mq-relative-constraints-05-expected.txt: Added.
     157        * fast/media/mq-relative-constraints-05.html: Added.
     158        * fast/media/mq-relative-constraints-06-expected.checksum: Added.
     159        * fast/media/mq-relative-constraints-06-expected.png: Added.
     160        * fast/media/mq-relative-constraints-06-expected.txt: Added.
     161        * fast/media/mq-relative-constraints-06.html: Added.
     162        * fast/media/mq-relative-constraints-07-expected.checksum: Added.
     163        * fast/media/mq-relative-constraints-07-expected.png: Added.
     164        * fast/media/mq-relative-constraints-07-expected.txt: Added.
     165        * fast/media/mq-relative-constraints-07.html: Added.
     166        * fast/media/mq-relative-constraints-08-expected.checksum: Added.
     167        * fast/media/mq-relative-constraints-08-expected.png: Added.
     168        * fast/media/mq-relative-constraints-08-expected.txt: Added.
     169        * fast/media/mq-relative-constraints-08.html: Added.
     170        * fast/media/mq-relative-constraints-09-expected.checksum: Added.
     171        * fast/media/mq-relative-constraints-09-expected.png: Added.
     172        * fast/media/mq-relative-constraints-09-expected.txt: Added.
     173        * fast/media/mq-relative-constraints-09.html: Added.
     174        * fast/media/mq-simple-neg-query-01-expected.checksum: Added.
     175        * fast/media/mq-simple-neg-query-01-expected.png: Added.
     176        * fast/media/mq-simple-neg-query-01-expected.txt: Added.
     177        * fast/media/mq-simple-neg-query-01.html: Added.
     178        * fast/media/mq-simple-neg-query-02-expected.checksum: Added.
     179        * fast/media/mq-simple-neg-query-02-expected.png: Added.
     180        * fast/media/mq-simple-neg-query-02-expected.txt: Added.
     181        * fast/media/mq-simple-neg-query-02.html: Added.
     182        * fast/media/mq-simple-neg-query-03-expected.checksum: Added.
     183        * fast/media/mq-simple-neg-query-03-expected.png: Added.
     184        * fast/media/mq-simple-neg-query-03-expected.txt: Added.
     185        * fast/media/mq-simple-neg-query-03.html: Added.
     186        * fast/media/mq-simple-neg-query-04-expected.checksum: Added.
     187        * fast/media/mq-simple-neg-query-04-expected.png: Added.
     188        * fast/media/mq-simple-neg-query-04-expected.txt: Added.
     189        * fast/media/mq-simple-neg-query-04.html: Added.
     190        * fast/media/mq-simple-neg-query-05-expected.checksum: Added.
     191        * fast/media/mq-simple-neg-query-05-expected.png: Added.
     192        * fast/media/mq-simple-neg-query-05-expected.txt: Added.
     193        * fast/media/mq-simple-neg-query-05.html: Added.
     194        * fast/media/mq-simple-query-01-expected.checksum: Added.
     195        * fast/media/mq-simple-query-01-expected.png: Added.
     196        * fast/media/mq-simple-query-01-expected.txt: Added.
     197        * fast/media/mq-simple-query-01.html: Added.
     198        * fast/media/mq-simple-query-02-expected.checksum: Added.
     199        * fast/media/mq-simple-query-02-expected.png: Added.
     200        * fast/media/mq-simple-query-02-expected.txt: Added.
     201        * fast/media/mq-simple-query-02.html: Added.
     202        * fast/media/mq-simple-query-03-expected.checksum: Added.
     203        * fast/media/mq-simple-query-03-expected.png: Added.
     204        * fast/media/mq-simple-query-03-expected.txt: Added.
     205        * fast/media/mq-simple-query-03.html: Added.
     206        * fast/media/mq-simple-query-04-expected.checksum: Added.
     207        * fast/media/mq-simple-query-04-expected.png: Added.
     208        * fast/media/mq-simple-query-04-expected.txt: Added.
     209        * fast/media/mq-simple-query-04.html: Added.
     210        * fast/media/mq-simple-query-05-expected.checksum: Added.
     211        * fast/media/mq-simple-query-05-expected.png: Added.
     212        * fast/media/mq-simple-query-05-expected.txt: Added.
     213        * fast/media/mq-simple-query-05.html: Added.
     214        * fast/media/mq-valueless-expected.checksum: Added.
     215        * fast/media/mq-valueless-expected.png: Added.
     216        * fast/media/mq-valueless-expected.txt: Added.
     217        * fast/media/mq-valueless.html: Added.
     218        * fast/media/mq-width-absolute-01-expected.checksum: Added.
     219        * fast/media/mq-width-absolute-01-expected.png: Added.
     220        * fast/media/mq-width-absolute-01-expected.txt: Added.
     221        * fast/media/mq-width-absolute-01.html: Added.
     222        * fast/media/mq-width-absolute-02-expected.checksum: Added.
     223        * fast/media/mq-width-absolute-02-expected.png: Added.
     224        * fast/media/mq-width-absolute-02-expected.txt: Added.
     225        * fast/media/mq-width-absolute-02.html: Added.
     226        * fast/media/mq-width-absolute-03-expected.checksum: Added.
     227        * fast/media/mq-width-absolute-03-expected.png: Added.
     228        * fast/media/mq-width-absolute-03-expected.txt: Added.
     229        * fast/media/mq-width-absolute-03.html: Added.
     230        * fast/media/mq-width-absolute-04-expected.checksum: Added.
     231        * fast/media/mq-width-absolute-04-expected.png: Added.
     232        * fast/media/mq-width-absolute-04-expected.txt: Added.
     233        * fast/media/mq-width-absolute-04.html: Added.
     234
    12352006-06-08  Justin Garcia  <justin.garcia@apple.com>
    2236
  • trunk/WebCore/ChangeLog

    r14778 r14779  
     12006-06-09  Kimmo Kinnunen  <kimmo.t.kinnunen@nokia.com>
     2
     3        Reviewed by Hyatt. Tweaked by Maciej. Tweaks reviewed by Beth.
     4        Landed by Beth.
     5
     6        CSS3 Media Queries implementation.
     7        <http://bugzilla.opendarwin.org/show_bug.cgi?id=4127>
     8
     9        * WebCore.xcodeproj/project.pbxproj:
     10        * bindings/js/kjs_css.cpp:
     11        (KJS::DOMMediaList::put):
     12        (KJS::KJS::DOMMediaListProtoFunc::callAsFunction):
     13        * bindings/objc/DOMCSS.mm:
     14        (-[DOMMediaList setMediaText:]):
     15        (-[DOMMediaList deleteMedium:]):
     16        (-[DOMMediaList appendMedium:]):
     17        * css/CSSGrammar.y:
     18        * css/MediaFeatureNames.cpp: Added.
     19        (WebCore::MediaFeatureNames::init):
     20        * css/MediaFeatureNames.h: Added.
     21        * css/MediaList.cpp:
     22        (WebCore::MediaList::MediaList):
     23        (WebCore::MediaList::~MediaList):
     24        (WebCore::parseMediaDescriptor):
     25        (WebCore::MediaList::deleteMedium):
     26        (WebCore::MediaList::mediaText):
     27        (WebCore::MediaList::setMediaText):
     28        (WebCore::MediaList::item):
     29        (WebCore::MediaList::appendMedium):
     30        (WebCore::MediaList::appendMediaQuery):
     31        * css/MediaList.h:
     32        (WebCore::MediaList::MediaList):
     33        (WebCore::MediaList::length):
     34        (WebCore::MediaList::mediaQueries):
     35        * css/MediaQuery.cpp: Added.
     36        (WebCore::MediaQuery::MediaQuery):
     37        (WebCore::MediaQuery::~MediaQuery):
     38        (WebCore::MediaQuery::operator==):
     39        (WebCore::MediaQuery::cssText):
     40        * css/MediaQuery.h: Added.
     41        (WebCore::MediaQuery::):
     42        (WebCore::MediaQuery::restrictor):
     43        (WebCore::MediaQuery::expressions):
     44        (WebCore::MediaQuery::mediaType):
     45        (WebCore::MediaQuery::append):
     46        * css/MediaQueryEvaluator.cpp: Added.
     47        (WebCore::):
     48        (WebCore::MediaQueryEvaluator):
     49        (WebCore::MediaQueryEvaluator::~MediaQueryEvaluator):
     50        (WebCore::MediaQueryEvaluator::mediaTypeMatch):
     51        (WebCore::applyRestrictor):
     52        (WebCore::MediaQueryEvaluator::eval):
     53        (WebCore::parseAspectRatio):
     54        (WebCore::cmpvalue):
     55        (WebCore::numberValue):
     56        (WebCore::colorMediaFeatureEval):
     57        (WebCore::monochromeMediaFeatureEval):
     58        (WebCore::device_aspect_ratioMediaFeatureEval):
     59        (WebCore::gridMediaFeatureEval):
     60        (WebCore::device_heightMediaFeatureEval):
     61        (WebCore::device_widthMediaFeatureEval):
     62        (WebCore::heightMediaFeatureEval):
     63        (WebCore::widthMediaFeatureEval):
     64        (WebCore::min_colorMediaFeatureEval):
     65        (WebCore::max_colorMediaFeatureEval):
     66        (WebCore::min_monochromeMediaFeatureEval):
     67        (WebCore::max_monochromeMediaFeatureEval):
     68        (WebCore::min_device_aspect_ratioMediaFeatureEval):
     69        (WebCore::max_device_aspect_ratioMediaFeatureEval):
     70        (WebCore::min_heightMediaFeatureEval):
     71        (WebCore::max_heightMediaFeatureEval):
     72        (WebCore::min_widthMediaFeatureEval):
     73        (WebCore::max_widthMediaFeatureEval):
     74        (WebCore::min_device_heightMediaFeatureEval):
     75        (WebCore::max_device_heightMediaFeatureEval):
     76        (WebCore::min_device_widthMediaFeatureEval):
     77        (WebCore::max_device_widthMediaFeatureEval):
     78        (WebCore::createFunctionMap):
     79        * css/MediaQueryEvaluator.h: Added.
     80        * css/MediaQueryExp.cpp: Added.
     81        (WebCore::MediaQueryExp::MediaQueryExp):
     82        (WebCore::MediaQueryExp::~MediaQueryExp):
     83        * css/MediaQueryExp.h: Added.
     84        (WebCore::MediaQueryExp::mediaFeature):
     85        (WebCore::MediaQueryExp::value):
     86        (WebCore::MediaQueryExp::operator==):
     87        * css/StyleSheet.cpp:
     88        (WebCore::StyleSheet::setMedia):
     89        * css/cssparser.cpp:
     90        (WebCore::CSSParser::CSSParser):
     91        (WebCore::CSSParser::~CSSParser):
     92        (WebCore::CSSParser::setupParser):
     93        (WebCore::CSSParser::parseMediaQuery):
     94        (WebCore::CSSParser::createFloatingMediaQueryExp):
     95        (WebCore::CSSParser::sinkFloatingMediaQueryExp):
     96        (WebCore::CSSParser::createFloatingMediaQueryExpList):
     97        (WebCore::CSSParser::sinkFloatingMediaQueryExpList):
     98        (WebCore::CSSParser::createFloatingMediaQuery):
     99        (WebCore::CSSParser::sinkFloatingMediaQuery):
     100        * css/cssparser.h:
     101        * css/cssstyleselector.cpp:
     102        (WebCore::CSSStyleSelector::CSSStyleSelector):
     103        (WebCore::CSSStyleSelector::init):
     104        (WebCore::CSSStyleSelector::~CSSStyleSelector):
     105        (WebCore::CSSStyleSelector::loadDefaultStyle):
     106        (WebCore::CSSStyleSelector::matchUARules):
     107        (WebCore::CSSStyleSelector::styleForElement):
     108        (WebCore::CSSStyleSelector::pseudoStyleForElement):
     109        (WebCore::CSSStyleSelector::updateFont):
     110        (WebCore::CSSStyleSelector::cacheBorderAndBackground):
     111        (WebCore::CSSStyleSelector::styleRulesForElement):
     112        (WebCore::CSSRuleSet::addRulesFromSheet):
     113        * css/cssstyleselector.h:
     114        * css/maketokenizer:
     115        * css/tokenizer.flex:
     116        * dom/DOMImplementation.cpp:
     117        (WebCore::DOMImplementation::createCSSStyleSheet):
     118        * html/HTMLLinkElement.cpp:
     119        (WebCore::HTMLLinkElement::process):
     120        (WebCore::HTMLLinkElement::setStyleSheet):
     121        * html/HTMLStyleElement.cpp:
     122        (WebCore::HTMLStyleElement::childrenChanged):
     123        * ksvg2/svg/SVGDOMImplementation.cpp:
     124        (SVGDOMImplementation::createCSSStyleSheet):
     125        * ksvg2/svg/SVGStyleElement.cpp:
     126        (WebCore::SVGStyleElement::childrenChanged):
     127        * page/Frame.cpp:
     128        (WebCore::Frame::Frame):
     129        * platform/Screen.h:
     130        * platform/mac/ScreenMac.mm:
     131        (WebCore::screenDepthPerComponent):
     132        (WebCore::screenIsMonochrome):
     133
    11342006-06-08  Justin Garcia  <justin.garcia@apple.com>
    2135
  • trunk/WebCore/WebCore.xcodeproj/project.pbxproj

    r14777 r14779  
    151151                1AE2AEE60A1D2A7500B42B25 /* JSHTMLBlockquoteElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AE2AEE40A1D2A7500B42B25 /* JSHTMLBlockquoteElement.cpp */; };
    152152                1AE2AEE70A1D2A7500B42B25 /* JSHTMLBlockquoteElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AE2AEE50A1D2A7500B42B25 /* JSHTMLBlockquoteElement.h */; };
     153                4E1959210A39DABA00220FE5 /* MediaFeatureNames.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4E19591F0A39DABA00220FE5 /* MediaFeatureNames.cpp */; };
     154                4E1959220A39DABA00220FE5 /* MediaFeatureNames.h in Headers */ = {isa = PBXBuildFile; fileRef = 4E1959200A39DABA00220FE5 /* MediaFeatureNames.h */; };
     155                4E1959290A39DACC00220FE5 /* MediaQuery.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4E1959230A39DACC00220FE5 /* MediaQuery.cpp */; };
     156                4E19592A0A39DACC00220FE5 /* MediaQuery.h in Headers */ = {isa = PBXBuildFile; fileRef = 4E1959240A39DACC00220FE5 /* MediaQuery.h */; };
     157                4E19592B0A39DACC00220FE5 /* MediaQueryEvaluator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4E1959250A39DACC00220FE5 /* MediaQueryEvaluator.cpp */; };
     158                4E19592C0A39DACC00220FE5 /* MediaQueryEvaluator.h in Headers */ = {isa = PBXBuildFile; fileRef = 4E1959260A39DACC00220FE5 /* MediaQueryEvaluator.h */; };
     159                4E19592D0A39DACC00220FE5 /* MediaQueryExp.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4E1959270A39DACC00220FE5 /* MediaQueryExp.cpp */; };
     160                4E19592E0A39DACC00220FE5 /* MediaQueryExp.h in Headers */ = {isa = PBXBuildFile; fileRef = 4E1959280A39DACC00220FE5 /* MediaQueryExp.h */; };
    153161                5126E6BB0A2E3B12005C29FA /* IconDatabase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5126E6B90A2E3B12005C29FA /* IconDatabase.cpp */; };
    154162                5126E6BC0A2E3B12005C29FA /* IconDatabase.h in Headers */ = {isa = PBXBuildFile; fileRef = 5126E6BA0A2E3B12005C29FA /* IconDatabase.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    17361744                2D90660C0665D937006B6F1A /* ClipboardMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ClipboardMac.mm; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
    17371745                4758C44308C5F217009BAF05 /* KCanvasPath.cpp */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; path = KCanvasPath.cpp; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
     1746                4E19591F0A39DABA00220FE5 /* MediaFeatureNames.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = MediaFeatureNames.cpp; sourceTree = "<group>"; };
     1747                4E1959200A39DABA00220FE5 /* MediaFeatureNames.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = MediaFeatureNames.h; sourceTree = "<group>"; };
     1748                4E1959230A39DACC00220FE5 /* MediaQuery.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = MediaQuery.cpp; sourceTree = "<group>"; };
     1749                4E1959240A39DACC00220FE5 /* MediaQuery.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = MediaQuery.h; sourceTree = "<group>"; };
     1750                4E1959250A39DACC00220FE5 /* MediaQueryEvaluator.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = MediaQueryEvaluator.cpp; sourceTree = "<group>"; };
     1751                4E1959260A39DACC00220FE5 /* MediaQueryEvaluator.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = MediaQueryEvaluator.h; sourceTree = "<group>"; };
     1752                4E1959270A39DACC00220FE5 /* MediaQueryExp.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = MediaQueryExp.cpp; sourceTree = "<group>"; };
     1753                4E1959280A39DACC00220FE5 /* MediaQueryExp.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = MediaQueryExp.h; sourceTree = "<group>"; };
    17381754                5126E6B90A2E3B12005C29FA /* IconDatabase.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = IconDatabase.cpp; sourceTree = "<group>"; };
    17391755                5126E6BA0A2E3B12005C29FA /* IconDatabase.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = IconDatabase.h; sourceTree = "<group>"; };
     
    50585074                        isa = PBXGroup;
    50595075                        children = (
     5076                                4E1959230A39DACC00220FE5 /* MediaQuery.cpp */,
     5077                                4E1959240A39DACC00220FE5 /* MediaQuery.h */,
     5078                                4E1959250A39DACC00220FE5 /* MediaQueryEvaluator.cpp */,
     5079                                4E1959260A39DACC00220FE5 /* MediaQueryEvaluator.h */,
     5080                                4E1959270A39DACC00220FE5 /* MediaQueryExp.cpp */,
     5081                                4E1959280A39DACC00220FE5 /* MediaQueryExp.h */,
     5082                                4E19591F0A39DABA00220FE5 /* MediaFeatureNames.cpp */,
     5083                                4E1959200A39DABA00220FE5 /* MediaFeatureNames.h */,
    50605084                                A80E6CDA0A1989CA007FB8C5 /* Counter.h */,
    50615085                                930705C709E0C95F00B17FE4 /* Counter.idl */,
     
    62086232                                5126E6BF0A2E3B29005C29FA /* WebCoreIconDatabaseBridge.h in Headers */,
    62096233                                D07DEABA0A36554A00CA30F8 /* InsertListCommand.h in Headers */,
     6234                                4E1959220A39DABA00220FE5 /* MediaFeatureNames.h in Headers */,
     6235                                4E19592A0A39DACC00220FE5 /* MediaQuery.h in Headers */,
     6236                                4E19592C0A39DACC00220FE5 /* MediaQueryEvaluator.h in Headers */,
     6237                                4E19592E0A39DACC00220FE5 /* MediaQueryExp.h in Headers */,
    62106238                        );
    62116239                        runOnlyForDeploymentPostprocessing = 0;
     
    70457073                                5126E6C00A2E3B29005C29FA /* WebCoreIconDatabaseBridge.mm in Sources */,
    70467074                                D07DEAB90A36554A00CA30F8 /* InsertListCommand.cpp in Sources */,
     7075                                4E1959210A39DABA00220FE5 /* MediaFeatureNames.cpp in Sources */,
     7076                                4E1959290A39DACC00220FE5 /* MediaQuery.cpp in Sources */,
     7077                                4E19592B0A39DACC00220FE5 /* MediaQueryEvaluator.cpp in Sources */,
     7078                                4E19592D0A39DACC00220FE5 /* MediaQueryExp.cpp in Sources */,
    70477079                        );
    70487080                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/WebCore/bindings/js/kjs_css.cpp

    r14735 r14779  
    531531void DOMMediaList::put(ExecState* exec, const Identifier &propertyName, JSValue* value, int attr)
    532532{
     533  DOMExceptionTranslator exception(exec);
    533534  MediaList &mediaList = *m_impl;
    534535  if (propertyName == "mediaText")
    535     mediaList.setMediaText(value->toString(exec));
     536    mediaList.setMediaText(value->toString(exec), exception);
    536537  else
    537538    DOMObject::put(exec, propertyName, value, attr);
     
    547548  if (!thisObj->inherits(&KJS::DOMMediaList::info))
    548549    return throwError(exec, TypeError);
    549   MediaList &mediaList = *static_cast<DOMMediaList*>(thisObj)->impl();
     550  DOMExceptionTranslator exception(exec);
     551  MediaList& mediaList = *static_cast<DOMMediaList *>(thisObj)->impl();
    550552  switch (id) {
    551553    case DOMMediaList::Item:
    552554      return jsStringOrNull(mediaList.item(args[0]->toInt32(exec)));
    553555    case DOMMediaList::DeleteMedium:
    554       mediaList.deleteMedium(args[0]->toString(exec));
     556      mediaList.deleteMedium(args[0]->toString(exec), exception);
    555557      return jsUndefined();
    556558    case DOMMediaList::AppendMedium:
    557       mediaList.appendMedium(args[0]->toString(exec));
     559      mediaList.appendMedium(args[0]->toString(exec), exception);
    558560      return jsUndefined();
    559561    default:
  • trunk/WebCore/bindings/objc/DOMCSS.mm

    r14407 r14779  
    334334- (void)setMediaText:(NSString *)mediaText
    335335{
    336     [self _mediaList]->setMediaText(mediaText);
     336    ExceptionCode ec = 0;
     337    [self _mediaList]->setMediaText(mediaText, ec);
     338    raiseOnDOMError(ec);
    337339}
    338340
     
    349351- (void)deleteMedium:(NSString *)oldMedium
    350352{
    351     [self _mediaList]->deleteMedium(oldMedium);
     353    ExceptionCode ec = 0;
     354    [self _mediaList]->deleteMedium(oldMedium, ec);
     355    raiseOnDOMError(ec);
    352356}
    353357
    354358- (void)appendMedium:(NSString *)newMedium
    355359{
    356     [self _mediaList]->appendMedium(newMedium);
     360    ExceptionCode ec = 0;
     361    [self _mediaList]->appendMedium(newMedium, ec);
     362    raiseOnDOMError(ec);
    357363}
    358364
  • trunk/WebCore/css/CSSGrammar.y

    r14408 r14779  
    3939#include <stdlib.h>
    4040#include <string.h>
     41#include "MediaQuery.h"
     42#include "MediaQueryExp.h"
    4143
    4244#if SVG_SUPPORT
     
    140142    Value value;
    141143    ValueList* valueList;
     144
     145    MediaQuery* mediaQuery;
     146    MediaQueryExp* mediaQueryExp;
     147    Vector<MediaQueryExp*>* mediaQueryExpList;
     148    MediaQuery::Restrictor mediaQueryRestrictor;
    142149}
    143150
     
    182189%token WEBKIT_DECLS_SYM
    183190%token WEBKIT_VALUE_SYM
     191%token WEBKIT_MEDIAQUERY_SYM
    184192
    185193%token IMPORTANT_SYM
     194%token MEDIA_ONLY
     195%token MEDIA_NOT
     196%token MEDIA_AND
    186197
    187198%token <val> QEMS
     
    232243%type <string> hexcolor
    233244
     245%type <string> media_feature
    234246%type <mediaList> media_list
    235247%type <mediaList> maybe_media_list
     248%type <mediaQuery> media_query
     249%type <mediaQueryRestrictor> maybe_media_restrictor
     250%type <valueList> maybe_media_value
     251%type <mediaQueryExp> media_query_exp
     252%type <mediaQueryExpList> media_query_exp_list
     253%type <mediaQueryExpList> maybe_media_query_exp_list
    236254
    237255%type <ruleList> ruleset_list
     
    273291  | webkit_decls maybe_space
    274292  | webkit_value maybe_space
     293  | webkit_mediaquery maybe_space
    275294  ;
    276295
     
    301320;
    302321
     322webkit_mediaquery:
     323     WEBKIT_MEDIAQUERY_SYM WHITESPACE maybe_space media_query '}' {
     324         CSSParser* p = static_cast<CSSParser*>(parser);
     325         p->mediaQuery = p->sinkFloatingMediaQuery($4);
     326     }
     327;
     328
    303329maybe_space:
    304330    /* empty */ %prec UNIMPORTANT_TOK
     
    384410;
    385411
     412media_feature:
     413    IDENT maybe_space {
     414        $$ = $1;
     415    }
     416    ;
     417
     418maybe_media_value:
     419    /*empty*/ {
     420        $$ = 0;
     421    }
     422    | ':' maybe_space expr maybe_space {
     423        $$ = $3;
     424    }
     425    ;
     426
     427media_query_exp:
     428    MEDIA_AND maybe_space '(' maybe_space media_feature maybe_space maybe_media_value ')' maybe_space {
     429        $5.lower();
     430        $$ = static_cast<CSSParser*>(parser)->createFloatingMediaQueryExp(atomicString($5), $7);
     431    }
     432    ;
     433
     434media_query_exp_list:
     435    media_query_exp {
     436      CSSParser* p = static_cast<CSSParser*>(parser);
     437      $$ = p->createFloatingMediaQueryExpList();
     438      $$->append(p->sinkFloatingMediaQueryExp($1));
     439    }
     440    | media_query_exp_list media_query_exp {
     441      $$ = $1;
     442      $$->append(static_cast<CSSParser*>(parser)->sinkFloatingMediaQueryExp($2));
     443    }
     444    ;
     445
     446maybe_media_query_exp_list:
     447    /*empty*/ {
     448        $$ = static_cast<CSSParser*>(parser)->createFloatingMediaQueryExpList();
     449    }
     450    | media_query_exp_list
     451    ;
     452
     453maybe_media_restrictor:
     454    /*empty*/ {
     455        $$ = MediaQuery::None;
     456    }
     457    | MEDIA_ONLY {
     458        $$ = MediaQuery::Only;
     459    }
     460    | MEDIA_NOT {
     461        $$ = MediaQuery::Not;
     462    }
     463    ;
     464
     465media_query:
     466    maybe_media_restrictor maybe_space medium maybe_media_query_exp_list {
     467        CSSParser* p = static_cast<CSSParser*>(parser);
     468        $3.lower();
     469        $$ = p->createFloatingMediaQuery($1, domString($3), p->sinkFloatingMediaQueryExpList($4));
     470    }
     471    ;
     472
    386473maybe_media_list:
    387474     /* empty */ {
     
    389476     }
    390477     | media_list
    391 ;
    392 
     478     ;
    393479
    394480media_list:
    395     medium {
    396         $$ = static_cast<CSSParser*>(parser)->createMediaList();
    397         $$->appendMedium(domString($1).lower());
    398     }
    399     | media_list ',' maybe_space medium {
     481    media_query {
     482        CSSParser* p = static_cast<CSSParser*>(parser);
     483        $$ = p->createMediaList();
     484        $$->appendMediaQuery(p->sinkFloatingMediaQuery($1));
     485    }
     486    | media_list ',' maybe_space media_query {
    400487        $$ = $1;
    401488        if ($$)
    402             $$->appendMedium(domString($4).lower());
     489            $$->appendMediaQuery(static_cast<CSSParser*>(parser)->sinkFloatingMediaQuery($4));
    403490    }
    404491    | media_list error {
  • trunk/WebCore/css/MediaList.cpp

    r14407 r14779  
    2626#include "CSSStyleSheet.h"
    2727#include "DeprecatedStringList.h"
     28#include "ExceptionCode.h"
     29#include "MediaQuery.h"
     30#include "cssparser.h"
     31
    2832
    2933namespace WebCore {
    3034
    31 MediaList::MediaList(CSSStyleSheet* parentSheet)
     35/* MediaList is used to store 3 types of media related entities which mean the same:
     36 * Media Queries, Media Types and Media Descriptors.
     37 * Currently MediaList always tries to parse media queries and if parsing fails,
     38 * tries to fallback to Media Descriptors if m_fallback flag is set.
     39 * Slight problem with syntax error handling:
     40 * CSS 2.1 Spec (http://www.w3.org/TR/CSS21/media.html)
     41 * specifies that failing media type parsing is a syntax error
     42 * CSS 3 Media Queries Spec (http://www.w3.org/TR/css3-mediaqueries/)
     43 * specifies that failing media query is a syntax error
     44 * HTML 4.01 spec (http://www.w3.org/TR/REC-html40/present/styles.html#adef-media)
     45 * specifies that Media Descriptors should be parsed with forward-compatible syntax
     46 * DOM Level 2 Style Sheet spec (http://www.w3.org/TR/DOM-Level-2-Style/)
     47 * talks about MediaList.mediaText and refers
     48 *   -  to Media Descriptors of HTML 4.0 in context of StyleSheet
     49 *   -  to Media Types of CSS 2.0 in context of CSSMediaRule and CSSImportRule
     50 *
     51 * These facts create situation where same (illegal) media specification may result in
     52 * different parses depending on whether it is media attr of style element or part of
     53 * css @media rule.
     54 * <style media="screen and resolution > 40dpi"> ..</style> will be enabled on screen devices where as
     55 * @media screen and resolution > 40dpi {..} will not.
     56 * This gets more counter-intuitive in JavaScript:
     57 * document.styleSheets[0].media.mediaText = "screen and resolution > 40dpi" will be ok and
     58 * enabled, while
     59 * document.styleSheets[0].cssRules[0].media.mediaText = "screen and resolution > 40dpi" will
     60 * throw SYNTAX_ERR exception.
     61 */
     62
     63MediaList::MediaList(CSSStyleSheet* parentSheet, bool fallbackToDescriptor)
    3264    : StyleBase(parentSheet)
    33 {
    34 }
    35 
    36 MediaList::MediaList(CSSStyleSheet* parentSheet, const String& media)
     65    , m_fallback(fallbackToDescriptor)
     66{
     67}
     68
     69MediaList::MediaList(CSSStyleSheet* parentSheet, const String& media, bool fallbackToDescriptor)
    3770    : StyleBase(parentSheet)
    38 {
    39     setMediaText(media);
    40 }
    41 
    42 MediaList::MediaList(CSSRule* parentRule, const String& media)
     71    , m_fallback(fallbackToDescriptor)
     72{
     73    ExceptionCode ec = 0;
     74    setMediaText(media, ec);
     75    // FIXME: parsing can fail. The problem with failing constructor is that
     76    // we would need additional flag saying MediaList is not valid
     77    // Parse can fail only when fallbackToDescriptor == false, i.e when HTML4 media descriptor
     78    // forward-compatible syntax is not in use.
     79    // DOMImplementationCSS seems to mandate that media descriptors are used
     80    // for both html and svg, even though svg:style doesn't use media descriptors
     81    // Currently the only places where parsing can fail are
     82    // creating <svg:style>, creating css media / import rules from js
     83    if (ec)
     84        setMediaText("invalid", ec);
     85}
     86
     87MediaList::MediaList(CSSRule* parentRule, const String& media, bool fallbackToDescriptor)
    4388    : StyleBase(parentRule)
    44 {
    45     setMediaText(media);
    46 }
    47 
    48 bool MediaList::contains(const String& medium) const
    49 {
    50     return m_lstMedia.count() == 0 || m_lstMedia.contains(medium) || m_lstMedia.contains("all");
     89    , m_fallback(fallbackToDescriptor)
     90{
     91    ExceptionCode ec = 0;
     92    setMediaText(media, ec);
     93    //FIXME: parsing can fail.
     94    if (ec)
     95        setMediaText("invalid", ec);
     96}
     97
     98MediaList::~MediaList()
     99{
     100    deleteAllValues(m_queries);
    51101}
    52102
     
    61111}
    62112
    63 void MediaList::deleteMedium(const String& oldMedium)
    64 {
    65     for (DeprecatedValueList<String>::Iterator it = m_lstMedia.begin(); it != m_lstMedia.end(); ++it) {
    66         if ((*it) == oldMedium) {
    67             m_lstMedia.remove(it);
    68             return;
     113static String parseMediaDescriptor(const String& s)
     114{
     115    int len = s.length();
     116
     117    // http://www.w3.org/TR/REC-html40/types.html#type-media-descriptors
     118    // "Each entry is truncated just before the first character that isn't a
     119    // US ASCII letter [a-zA-Z] (ISO 10646 hex 41-5a, 61-7a), digit [0-9] (hex 30-39),
     120    // or hyphen (hex 2d)."
     121    int i;
     122    unsigned short c;
     123    for (i = 0; i < len; ++i) {
     124        c = s[i];
     125        if (! ((c >= 'a' && c <= 'z')
     126            || (c >= 'A' && c <= 'Z')
     127            || (c >= '1' && c <= '9')
     128            || (c == '-')))
     129            break;
     130    }
     131    return s.left(i);
     132}
     133
     134void MediaList::deleteMedium(const String& oldMedium, ExceptionCode& ec)
     135{
     136    MediaList tempMediaList;
     137    CSSParser p(true);
     138
     139    MediaQuery* oldQuery = 0;
     140    bool deleteOldQuery = false;
     141
     142    if (p.parseMediaQuery(&tempMediaList, oldMedium)) {
     143        if (tempMediaList.m_queries.size() > 0)
     144            oldQuery = tempMediaList.m_queries[0];
     145    } else if (m_fallback) {
     146        String medium = parseMediaDescriptor(oldMedium);
     147        if (!medium.isNull()) {
     148            oldQuery = new MediaQuery(MediaQuery::None, medium, 0);
     149            deleteOldQuery = true;
    69150        }
    70151    }
     152
     153    // DOM Style Sheets spec doesn't allow SYNTAX_ERR to be thrown in deleteMedium
     154    ec = NOT_FOUND_ERR;
     155
     156    if (oldQuery) {
     157        for(size_t i = 0; i < m_queries.size(); ++i) {
     158            MediaQuery* a = m_queries[i];
     159            if (*a == *oldQuery) {
     160                m_queries.remove(i);
     161                delete a;
     162                ec = 0;
     163                break;
     164            }
     165        }
     166        if (deleteOldQuery)
     167            delete oldQuery;
     168    }
    71169}
    72170
    73171WebCore::String MediaList::mediaText() const
    74172{
    75     String text = "";
    76     for (DeprecatedValueList<String>::ConstIterator it = m_lstMedia.begin(); it != m_lstMedia.end(); ++it) {
    77         if (text.length() > 0)
     173    String text("");
     174
     175    bool first = true;
     176    for (size_t i = 0; i < m_queries.size(); ++i) {
     177        if (!first)
    78178            text += ", ";
    79         text += *it;
    80     }
     179        else
     180            first = false;
     181        text += m_queries[i]->cssText();
     182    }
     183
    81184    return text;
    82185}
    83186
    84 void MediaList::setMediaText(const WebCore::String& value)
    85 {
    86     m_lstMedia.clear();
     187void MediaList::setMediaText(const WebCore::String& value,  ExceptionCode& ec)
     188{
     189    MediaList tempMediaList;
     190    CSSParser p(true);
     191
    87192    DeprecatedStringList list = DeprecatedStringList::split(',', value.deprecatedString());
    88193    for (DeprecatedStringList::Iterator it = list.begin(); it != list.end(); ++it) {
    89194        String medium = (*it).stripWhiteSpace();
    90         if (!medium.isEmpty())
    91             m_lstMedia.append(medium);
    92     }
    93 }
    94 
    95 }
     195        if (!medium.isEmpty()) {
     196            if (!p.parseMediaQuery(&tempMediaList, medium)) {
     197                if (m_fallback) {
     198                    String mediaDescriptor = parseMediaDescriptor(medium);
     199                    if (!mediaDescriptor.isNull())
     200                        tempMediaList.m_queries.append(new MediaQuery(MediaQuery::None, mediaDescriptor, 0));
     201                } else {
     202                    ec = SYNTAX_ERR;
     203                    return;
     204                }
     205            }         
     206        } else if (!m_fallback) {
     207            ec = SYNTAX_ERR;
     208            return;
     209        }           
     210    }
     211    // ",,,," falls straight through, but is not valid unless fallback
     212    if (!m_fallback && list.begin() == list.end()) {
     213        String s = value.deprecatedString().stripWhiteSpace();
     214        if (!s.isEmpty()) {
     215            ec = SYNTAX_ERR;
     216            return;
     217            }
     218    }
     219   
     220    ec = 0;
     221    deleteAllValues(m_queries);
     222    m_queries = tempMediaList.m_queries;
     223    tempMediaList.m_queries.clear();
     224}
     225
     226String MediaList::item(unsigned index) const
     227{
     228    if (index < m_queries.size()) {
     229        MediaQuery* query = m_queries[index];
     230        return query->cssText();
     231    }
     232
     233    return String();
     234}
     235
     236void MediaList::appendMedium(const String& newMedium, ExceptionCode& ec)
     237{
     238    ec = INVALID_CHARACTER_ERR;
     239    CSSParser p(true);
     240    if (p.parseMediaQuery(this, newMedium)) {
     241        ec = 0;
     242    } else if (m_fallback) {
     243        String medium = parseMediaDescriptor(newMedium);
     244        if (!medium.isNull()) {
     245            m_queries.append(new MediaQuery(MediaQuery::None, medium, 0));
     246            ec = 0;
     247        }
     248    }
     249}
     250
     251void MediaList::appendMediaQuery(MediaQuery* mediaQuery)
     252{
     253    m_queries.append(mediaQuery);
     254}
     255
     256}
  • trunk/WebCore/css/MediaList.h

    r14408 r14779  
    2525
    2626#include "StyleBase.h"
    27 #include "DeprecatedValueList.h"
     27#include <wtf/Vector.h>
    2828#include "PlatformString.h"
    2929
    3030namespace WebCore {
    31 
     31typedef int ExceptionCode;
    3232class CSSStyleSheet;
     33class MediaQuery;
    3334class CSSRule;
    3435
     
    3637{
    3738public:
    38     MediaList() : StyleBase(0) {}
    39     MediaList(CSSStyleSheet* parentSheet);
    40     MediaList(CSSStyleSheet* parentSheet, const String& media);
    41     MediaList(CSSRule* parentRule, const String& media);
     39    MediaList(bool fallbackToDescription = false) : StyleBase(0), m_fallback(fallbackToDescription) {}
     40    MediaList(CSSStyleSheet* parentSheet, bool fallbackToDescription = false);
     41    MediaList(CSSStyleSheet* parentSheet, const String& media, bool fallbackToDescription = false);
     42    MediaList(CSSRule* parentRule, const String& media, bool fallbackToDescription = false);
     43    ~MediaList();
    4244
    4345    virtual bool isMediaList() { return true; }
     
    4547    CSSStyleSheet* parentStyleSheet() const;
    4648    CSSRule* parentRule() const;
    47     unsigned length() const { return m_lstMedia.count(); }
    48     String item(unsigned index) const { return m_lstMedia[index]; }
    49     void deleteMedium(const String& oldMedium);
    50     void appendMedium(const String& newMedium) { m_lstMedia.append(newMedium); }
     49    unsigned length() const { return (unsigned) m_queries.size(); }
     50    String item(unsigned index) const;
     51    void deleteMedium(const String& oldMedium, ExceptionCode&);
     52    void appendMedium(const String& newMedium, ExceptionCode&);
    5153
    5254    String mediaText() const;
    53     void setMediaText(const String&);
     55    void setMediaText(const String&, ExceptionCode&xo);
    5456
    55     /**
    56      * Check if the list contains either the requested medium, or the
    57      * catch-all "all" media type. Returns true when found, false otherwise.
    58      * Since not specifying media types should be treated as "all" according
    59      * to DOM specs, an empty list always returns true.
    60      *
    61      * _NOT_ part of the DOM!
    62      */
    63     bool contains(const String& medium) const;
     57    void appendMediaQuery(MediaQuery* mediaQuery);
     58    const Vector<MediaQuery*>* mediaQueries() const { return &m_queries; }
    6459
    6560protected:
    66     DeprecatedValueList<String> m_lstMedia;
     61    Vector<MediaQuery*> m_queries;
     62    bool m_fallback; // true if failed media query parsing should fallback to media description parsing
    6763};
    6864
  • trunk/WebCore/css/StyleSheet.cpp

    r14401 r14779  
    6565void StyleSheet::setMedia(MediaList* media)
    6666{
     67    if (m_media)
     68        m_media->setParent(0);
     69
    6770    m_media = media;
     71    m_media->setParent(this);
    6872}
    6973
  • trunk/WebCore/css/cssparser.cpp

    r14763 r14779  
    5151#include "ShadowValue.h"
    5252#include "csshelper.h"
     53#include "MediaQueryExp.h"
    5354
    5455#define YYDEBUG 0
     
    9495
    9596CSSParser::CSSParser(bool strictParsing)
     97    : m_floatingMediaQuery(0)
     98    , m_floatingMediaQueryExp(0)
     99    , m_floatingMediaQueryExpList(0)
    96100{
    97101#ifdef CSS_DEBUG
     
    130134    fastFree(data);
    131135
     136    if (m_floatingMediaQueryExpList) {
     137        deleteAllValues(*m_floatingMediaQueryExpList);
     138        delete m_floatingMediaQueryExpList;
     139    }
     140    delete m_floatingMediaQueryExp;
     141    delete m_floatingMediaQuery;
    132142    deleteAllValues(m_floatingSelectors);
    133143    deleteAllValues(m_floatingValueLists);
     
    152162{
    153163    int length = string.length() + strlen(prefix) + strlen(suffix) + 2;
     164
     165    if (data)
     166        fastFree(data);
    154167   
    155168    data = static_cast<UChar*>(fastMalloc(length * sizeof(UChar)));
     
    289302        declaration->addParsedProperties(parsedProperties, numParsedProperties);
    290303        clearProperties();
     304    }
     305
     306    return ok;
     307}
     308
     309bool CSSParser::parseMediaQuery(MediaList* queries, const String& string)
     310{
     311    if (string.isEmpty() || string.isNull()) {
     312        return true;
     313    }
     314
     315    mediaQuery = 0;
     316    // can't use { because tokenizer state switches from mediaquery to initial state when it sees { token.
     317    // instead insert one " " (which is WHITESPACE in CSSGrammar.y)
     318    setupParser ("@-webkit-mediaquery ", string, "} ");
     319
     320    CSSParser* old = currentParser;
     321    currentParser = this;
     322    cssyyparse(this);
     323    currentParser = old;
     324
     325    bool ok = false;
     326    if (mediaQuery) {
     327        ok = true;
     328        queries->appendMediaQuery(mediaQuery);
     329        mediaQuery = 0;
    291330    }
    292331
     
    28692908}
    28702909
     2910MediaQueryExp* CSSParser::createFloatingMediaQueryExp(const AtomicString& mediaFeature, ValueList* values)
     2911{
     2912    delete m_floatingMediaQueryExp;
     2913    m_floatingMediaQueryExp = new MediaQueryExp(mediaFeature, values);
     2914    return m_floatingMediaQueryExp;
     2915}
     2916
     2917MediaQueryExp* CSSParser::sinkFloatingMediaQueryExp(MediaQueryExp* e)
     2918{
     2919    ASSERT(e == m_floatingMediaQueryExp);
     2920    m_floatingMediaQueryExp = 0;
     2921    return e;
     2922}
     2923
     2924Vector<MediaQueryExp*>* CSSParser::createFloatingMediaQueryExpList()
     2925{
     2926    if (m_floatingMediaQueryExpList) {
     2927        deleteAllValues(*m_floatingMediaQueryExpList);
     2928        delete m_floatingMediaQueryExpList;
     2929    }
     2930    m_floatingMediaQueryExpList = new Vector<MediaQueryExp*>;
     2931    return m_floatingMediaQueryExpList;
     2932}
     2933
     2934Vector<MediaQueryExp*>* CSSParser::sinkFloatingMediaQueryExpList(Vector<MediaQueryExp*>* l)
     2935{
     2936    ASSERT(l == m_floatingMediaQueryExpList);
     2937    m_floatingMediaQueryExpList = 0;
     2938    return l;
     2939}
     2940
     2941MediaQuery* CSSParser::createFloatingMediaQuery(MediaQuery::Restrictor r, const String& mediaType, Vector<MediaQueryExp*>* exprs)
     2942{
     2943    delete m_floatingMediaQuery;
     2944    m_floatingMediaQuery = new MediaQuery(r, mediaType, exprs);
     2945    return m_floatingMediaQuery;
     2946}
     2947
     2948MediaQuery* CSSParser::sinkFloatingMediaQuery(MediaQuery* mq)
     2949{
     2950    ASSERT(mq == m_floatingMediaQuery);
     2951    m_floatingMediaQuery = 0;
     2952    return mq;
     2953}
     2954
    28712955MediaList* CSSParser::createMediaList()
    28722956{
     
    29483032#define yyterminate() yyTok = END_TOKEN; return yyTok
    29493033#define YY_FATAL_ERROR(a)
     3034// The line below is needed to build the tokenizer with conditon stack.
     3035// The macro is used in the tokenizer grammar with lines containing
     3036// BEGIN(mediaqueries) and BEGIN(initial). yy_start acts as index to
     3037// tokenizer transition table, and 'mediaqueries' and 'initial' are
     3038// offset multipliers that specify which transitions are active
     3039// in the tokenizer during in each condition (tokenizer state)
     3040#define BEGIN yy_start = 1 + 2 *
    29503041
    29513042#include "tokenizer.cpp"
  • trunk/WebCore/css/cssparser.h

    r14352 r14779  
    2828#include <wtf/HashSet.h>
    2929#include <wtf/Vector.h>
     30#include "MediaQuery.h"
    3031
    3132namespace WebCore {
     
    4445    class StyleBase;
    4546    class StyleList;
     47    class MediaList;
     48    class MediaQueryExp;
     49
    4650
    4751    struct ParseString {
     
    111115        bool parseColor(CSSMutableStyleDeclaration*, const String&);
    112116        bool parseDeclaration(CSSMutableStyleDeclaration*, const String&);
     117        bool parseMediaQuery(MediaList*, const String&);
    113118
    114119        static CSSParser* current() { return currentParser; }
     
    178183        CSSRule* createStyleRule(CSSSelector*);
    179184
     185        MediaQueryExp* createFloatingMediaQueryExp(const AtomicString&, ValueList*);
     186        MediaQueryExp* sinkFloatingMediaQueryExp(MediaQueryExp*);
     187        Vector<MediaQueryExp*>* createFloatingMediaQueryExpList();
     188        Vector<MediaQueryExp*>* sinkFloatingMediaQueryExpList(Vector<MediaQueryExp*>*);
     189        MediaQuery* createFloatingMediaQuery(MediaQuery::Restrictor, const String&, Vector<MediaQueryExp*>*);
     190        MediaQuery* sinkFloatingMediaQuery(MediaQuery*);
     191
    180192    public:
    181193        bool strict;
     
    184196        StyleList* styleElement;
    185197        RefPtr<CSSRule> rule;
     198        MediaQuery* mediaQuery;
    186199        ValueList* valueList;
    187200        CSSProperty** parsedProperties;
     
    226239        HashSet<ValueList*> m_floatingValueLists;
    227240        HashSet<Function*> m_floatingFunctions;
     241
     242        MediaQuery* m_floatingMediaQuery;
     243        MediaQueryExp* m_floatingMediaQueryExp;
     244        Vector<MediaQueryExp*>* m_floatingMediaQueryExpList;
    228245
    229246        // defines units allowed for a certain property, used in parseUnit
  • trunk/WebCore/css/cssstyleselector.cpp

    r14763 r14779  
    4949#include "KWQKHTMLSettings.h"
    5050#include "MediaList.h"
     51#include "MediaQueryEvaluator.h"
    5152#include "Pair.h"
    5253#include "RectImpl.h"
     
    173174    typedef HashMap<AtomicStringImpl*, CSSRuleDataList*> AtomRuleMap;
    174175   
    175     void addRulesFromSheet(CSSStyleSheet* sheet, const String &medium = "screen");
     176    void addRulesFromSheet(CSSStyleSheet* sheet, MediaQueryEvaluator* medium);
    176177   
    177178    void addRule(CSSStyleRule* rule, CSSSelector* sel);
     
    215216    if (!defaultStyle)
    216217        loadDefaultStyle();
    217     m_mediaType = view ? view->mediaType() : String("all");
    218218
    219219    m_userStyle = 0;
    220220    m_userSheet = 0;
     221
     222    // construct document root element default style. this is needed
     223    // to evaluate media queries that contain relative constraints, like "screen and (max-width: 10em)"
     224    // This is here instead of constructor, because when constructor is run,
     225    // document doesn't have documentElement
     226    // NOTE: this assumes that element that gets passed to styleForElement -call
     227    // is always from the document that owns the style selector
     228    if (view)
     229        m_medium = new MediaQueryEvaluator(view->mediaType());
     230    else
     231        m_medium = new MediaQueryEvaluator("all");
     232
     233    Element* root = doc->documentElement();
     234
     235    if (root)
     236        m_rootDefaultStyle = styleForElement(root, 0, false, true); // dont ref, because the RenderStyle is allocated from global heap
     237
     238    if (m_rootDefaultStyle && view) {
     239        delete m_medium;
     240        m_medium = new MediaQueryEvaluator(view->mediaType(), view, m_rootDefaultStyle);
     241    }
     242
    221243
    222244    // FIXME: This sucks! The user sheet is reparsed every time!
     
    226248
    227249        m_userStyle = new CSSRuleSet();
    228         m_userStyle->addRulesFromSheet(m_userSheet, m_mediaType);
     250        m_userStyle->addRulesFromSheet(m_userSheet, m_medium);
    229251    }
    230252
     
    235257    for (; it.current(); ++it)
    236258        if (it.current()->isCSSStyleSheet() && !it.current()->disabled())
    237             m_authorStyle->addRulesFromSheet(static_cast<CSSStyleSheet*>(it.current()), m_mediaType);
    238 
    239     m_ruleList = 0;
    240     m_collectRulesOnly = false;
     259            m_authorStyle->addRulesFromSheet(static_cast<CSSStyleSheet*>(it.current()), m_medium);
     260
    241261}
    242262
     
    248268        loadDefaultStyle();
    249269    FrameView *view = sheet->doc()->view();
    250     m_mediaType =  view ? view->mediaType() : String("all");
     270
     271    if (view)
     272        m_medium = new MediaQueryEvaluator(view->mediaType());
     273    else
     274        m_medium = new MediaQueryEvaluator("all");
     275
     276    Element* root = sheet->doc()->documentElement();
     277    if (root)
     278        m_rootDefaultStyle = styleForElement(root, 0, false, true);
     279
     280    if (m_rootDefaultStyle && view) {
     281        delete m_medium;
     282        m_medium = new MediaQueryEvaluator(view->mediaType(), view, m_rootDefaultStyle);
     283    }
    251284
    252285    m_authorStyle = new CSSRuleSet();
    253     m_authorStyle->addRulesFromSheet(sheet, m_mediaType);
     286    m_authorStyle->addRulesFromSheet(sheet, m_medium);
    254287}
    255288
     
    259292    settings = 0;
    260293    m_matchedRuleCount = m_matchedDeclCount = m_tmpRuleCount = 0;
     294    m_ruleList = 0;
     295    m_collectRulesOnly = false;
     296    m_rootDefaultStyle = 0;
     297    m_medium = 0;
    261298}
    262299
     
    280317CSSStyleSelector::~CSSStyleSelector()
    281318{
     319    delete m_medium;
     320    ::delete m_rootDefaultStyle;
     321
    282322    delete m_authorStyle;
    283323    delete m_userStyle;
     
    308348    defaultQuirksStyle = new CSSRuleSet;
    309349
     350    MediaQueryEvaluator screenEval("screen");
     351    MediaQueryEvaluator printEval("print");
     352
    310353    // Strict-mode rules.
    311354    defaultSheet = parseUASheet(html4UserAgentStyleSheet);
    312     defaultStyle->addRulesFromSheet(defaultSheet, "screen");
    313     defaultPrintStyle->addRulesFromSheet(defaultSheet, "print");
     355    defaultStyle->addRulesFromSheet(defaultSheet, &screenEval);
     356    defaultPrintStyle->addRulesFromSheet(defaultSheet, &printEval);
    314357
    315358#if SVG_SUPPORT
    316359    // SVG rules.
    317360    svgSheet = parseUASheet(svgUserAgentStyleSheet);
    318     defaultStyle->addRulesFromSheet(svgSheet, "screen");
    319     defaultPrintStyle->addRulesFromSheet(svgSheet, "print");
     361    defaultStyle->addRulesFromSheet(svgSheet, &screenEval);
     362    defaultPrintStyle->addRulesFromSheet(svgSheet, &printEval);
    320363#endif
    321364
    322365    // Quirks-mode rules.
    323366    quirksSheet = parseUASheet(quirksUserAgentStyleSheet);
    324     defaultQuirksStyle->addRulesFromSheet(quirksSheet, "screen");
     367    defaultQuirksStyle->addRulesFromSheet(quirksSheet, &screenEval);
    325368}
    326369
     
    701744}
    702745
    703 
    704 RenderStyle* CSSStyleSelector::styleForElement(Element* e, RenderStyle* defaultParent, bool allowSharing)
     746void CSSStyleSelector::matchUARules(int& firstUARule, int& lastUARule)
     747{
     748    // 1. First we match rules from the user agent sheet.
     749    matchRules(defaultStyle, firstUARule, lastUARule);
     750
     751    // 2. In quirks mode, we match rules from the quirks user agent sheet.
     752    if (!strictParsing)
     753        matchRules(defaultQuirksStyle, firstUARule, lastUARule);
     754
     755    // 3. If our medium is print, then we match rules from the print sheet.
     756    if (m_medium->mediaTypeMatch("print"))
     757        matchRules(defaultPrintStyle, firstUARule, lastUARule);
     758}
     759
     760// If resolveForRootDefault is true, style based on user agent style sheet only. This is used in media queries, where
     761// relative units are interpreted according to document root element style, styled only with UA stylesheet
     762
     763RenderStyle* CSSStyleSelector::styleForElement(Element* e, RenderStyle* defaultParent, bool allowSharing, bool resolveForRootDefault)
    705764{
    706765    if (allowSharing && !e->document()->haveStylesheetsLoaded()) {
     
    729788    initForStyleResolve(e, defaultParent);
    730789
    731     style = new (e->document()->renderArena()) RenderStyle();
    732     style->ref();
     790    if (resolveForRootDefault) {
     791        style = ::new RenderStyle();
     792        // don't ref, because we want to delete this, but we cannot unref it
     793    } else {
     794        style = new (e->document()->renderArena()) RenderStyle();
     795        style->ref();
     796    }
    733797    if (parentStyle)
    734798        style->inheritFrom(parentStyle);
    735799    else
    736800        parentStyle = style;
    737    
    738     // 1. First we match rules from the user agent sheet.
     801
    739802    int firstUARule = -1, lastUARule = -1;
    740     matchRules(defaultStyle, firstUARule, lastUARule);
    741    
    742     // 2. In quirks mode, we match rules from the quirks user agent sheet.
    743     if (!strictParsing)
    744         matchRules(defaultQuirksStyle, firstUARule, lastUARule);
    745    
    746     // 3. If our medium is print, then we match rules from the print sheet.
    747     if (m_mediaType == "print")
    748         matchRules(defaultPrintStyle, firstUARule, lastUARule);
    749 
    750     // 4. Now we check user sheet rules.
    751803    int firstUserRule = -1, lastUserRule = -1;
    752     matchRules(m_userStyle, firstUserRule, lastUserRule);
    753 
    754     // 5. Now check author rules, beginning first with presentational attributes
    755     // mapped from HTML.
    756804    int firstAuthorRule = -1, lastAuthorRule = -1;
    757     if (styledElement) {
    758         // Ask if the HTML element has mapped attributes.
    759         if (styledElement->hasMappedAttributes()) {
    760             // Walk our attribute list and add in each decl.
    761             const NamedMappedAttrMap* map = styledElement->mappedAttributes();
    762             for (unsigned i = 0; i < map->length(); i++) {
    763                 MappedAttribute* attr = map->attributeItem(i);
    764                 if (attr->decl()) {
    765                     if (firstAuthorRule == -1) firstAuthorRule = m_matchedDeclCount;
    766                     lastAuthorRule = m_matchedDeclCount;
    767                     addMatchedDeclaration(attr->decl());
     805    matchUARules(firstUARule, lastUARule);
     806
     807    if (!resolveForRootDefault) {
     808        // 4. Now we check user sheet rules.
     809        matchRules(m_userStyle, firstUserRule, lastUserRule);
     810
     811        // 5. Now check author rules, beginning first with presentational attributes
     812        // mapped from HTML.
     813        if (styledElement) {
     814            // Ask if the HTML element has mapped attributes.
     815            if (styledElement->hasMappedAttributes()) {
     816                // Walk our attribute list and add in each decl.
     817                const NamedMappedAttrMap* map = styledElement->mappedAttributes();
     818                for (unsigned i = 0; i < map->length(); i++) {
     819                    MappedAttribute* attr = map->attributeItem(i);
     820                    if (attr->decl()) {
     821                        if (firstAuthorRule == -1) firstAuthorRule = m_matchedDeclCount;
     822                        lastAuthorRule = m_matchedDeclCount;
     823                        addMatchedDeclaration(attr->decl());
     824                    }
    768825                }
    769826            }
    770         }
    771 
    772         // Now we check additional mapped declarations.
    773         // Tables and table cells share an additional mapped rule that must be applied
    774         // after all attributes, since their mapped style depends on the values of multiple attributes.
    775         CSSMutableStyleDeclaration* attributeDecl = styledElement->additionalAttributeStyleDecl();
    776         if (attributeDecl) {
    777             if (firstAuthorRule == -1) firstAuthorRule = m_matchedDeclCount;
    778             lastAuthorRule = m_matchedDeclCount;
    779             addMatchedDeclaration(attributeDecl);
    780         }
    781     }
    782    
    783     // 6. Check the rules in author sheets next.
    784     matchRules(m_authorStyle, firstAuthorRule, lastAuthorRule);
    785    
    786     // 7. Now check our inline style attribute.
    787     if (styledElement) {
    788         CSSMutableStyleDeclaration* inlineDecl = styledElement->inlineStyleDecl();
    789         if (inlineDecl) {
    790             if (firstAuthorRule == -1) firstAuthorRule = m_matchedDeclCount;
    791             lastAuthorRule = m_matchedDeclCount;
    792             addMatchedDeclaration(inlineDecl);
    793         }
    794     }
    795    
     827
     828            // Now we check additional mapped declarations.
     829            // Tables and table cells share an additional mapped rule that must be applied
     830            // after all attributes, since their mapped style depends on the values of multiple attributes.
     831            CSSMutableStyleDeclaration* attributeDecl = styledElement->additionalAttributeStyleDecl();
     832            if (attributeDecl) {
     833                if (firstAuthorRule == -1) firstAuthorRule = m_matchedDeclCount;
     834                lastAuthorRule = m_matchedDeclCount;
     835                addMatchedDeclaration(attributeDecl);
     836            }
     837        }
     838   
     839        // 6. Check the rules in author sheets next.
     840        matchRules(m_authorStyle, firstAuthorRule, lastAuthorRule);
     841   
     842        // 7. Now check our inline style attribute.
     843        if (styledElement) {
     844            CSSMutableStyleDeclaration* inlineDecl = styledElement->inlineStyleDecl();
     845            if (inlineDecl) {
     846                if (firstAuthorRule == -1) firstAuthorRule = m_matchedDeclCount;
     847                lastAuthorRule = m_matchedDeclCount;
     848                addMatchedDeclaration(inlineDecl);
     849            }
     850        }
     851    }
     852
    796853    // Now we have all of the matched rules in the appropriate order.  Walk the rules and apply
    797854    // high-priority properties first, i.e., those properties that other properties depend on.
     
    799856    // and (4) normal important.
    800857    applyDeclarations(true, false, 0, m_matchedDeclCount-1);
    801     applyDeclarations(true, true, firstAuthorRule, lastAuthorRule);
    802     applyDeclarations(true, true, firstUserRule, lastUserRule);
     858    if (!resolveForRootDefault) {
     859        applyDeclarations(true, true, firstAuthorRule, lastAuthorRule);
     860        applyDeclarations(true, true, firstUserRule, lastUserRule);
     861    }
    803862    applyDeclarations(true, true, firstUARule, lastUARule);
    804863   
    805864    // If our font got dirtied, go ahead and update it now.
    806     if (fontDirty) {
    807         checkForTextSizeAdjust();
    808         checkForGenericFamilyChange(style, parentStyle);
    809         style->font().update();
    810         fontDirty = false;
    811     }
     865    if (fontDirty)
     866        updateFont();
    812867   
    813868    // Now do the normal priority UA properties.
     
    815870   
    816871    // Cache our border and background so that we can examine them later.
    817     m_hasUAAppearance = style->hasAppearance();
    818     if (m_hasUAAppearance) {
    819         m_borderData = style->border();
    820         m_backgroundData = *style->backgroundLayers();
    821         m_backgroundColor = style->backgroundColor();
    822     }
     872    cacheBorderAndBackground();
    823873   
    824874    // Now do the author and user normal priority properties and all the !important properties.
    825     applyDeclarations(false, false, lastUARule+1, m_matchedDeclCount-1);
    826     applyDeclarations(false, true, firstAuthorRule, lastAuthorRule);
    827     applyDeclarations(false, true, firstUserRule, lastUserRule);
     875    if (!resolveForRootDefault) {
     876        applyDeclarations(false, false, lastUARule+1, m_matchedDeclCount-1);
     877        applyDeclarations(false, true, firstAuthorRule, lastAuthorRule);
     878        applyDeclarations(false, true, firstUserRule, lastUserRule);
     879    }
    828880    applyDeclarations(false, true, firstUARule, lastUARule);
    829881   
    830882    // If our font got dirtied by one of the non-essential font props,
    831883    // go ahead and update it a second time.
    832     if (fontDirty) {
    833         checkForTextSizeAdjust();
    834         checkForGenericFamilyChange(style, parentStyle);
    835         style->font().update();
    836         fontDirty = false;
    837     }
     884    if (fontDirty)
     885        updateFont();
    838886   
    839887    // Clean up our style object's display and text decorations (among other fixups).
     
    884932   
    885933    // If our font got dirtied, go ahead and update it now.
    886     if (fontDirty) {
    887         checkForTextSizeAdjust();
    888         checkForGenericFamilyChange(style, parentStyle);
    889         style->font().update();
    890         fontDirty = false;
    891     }
     934    if (fontDirty)
     935        updateFont();
    892936   
    893937    // Now do the normal priority properties.
     
    895939   
    896940    // Cache our border and background so that we can examine them later.
    897     m_hasUAAppearance = style->hasAppearance();
    898     if (m_hasUAAppearance) {
    899         m_borderData = style->border();
    900         m_backgroundData = *style->backgroundLayers();
    901         m_backgroundColor = style->backgroundColor();
    902     }
     941    cacheBorderAndBackground();
    903942   
    904943    applyDeclarations(false, false, lastUARule+1, m_matchedDeclCount-1);
     
    909948    // If our font got dirtied by one of the non-essential font props,
    910949    // go ahead and update it a second time.
    911     if (fontDirty) {
    912         checkForTextSizeAdjust();
    913         checkForGenericFamilyChange(style, parentStyle);
    914         style->font().update();
    915         fontDirty = false;
    916     }
    917    
     950    if (fontDirty)
     951        updateFont();
    918952    // Clean up our style object's display and text decorations (among other fixups).
    919953    adjustRenderStyle(style, 0);
     
    10391073}
    10401074
     1075void CSSStyleSelector::updateFont()
     1076{
     1077    checkForTextSizeAdjust();
     1078    checkForGenericFamilyChange(style, parentStyle);
     1079    style->font().update();
     1080    fontDirty = false;
     1081}
     1082
     1083void CSSStyleSelector::cacheBorderAndBackground()
     1084{
     1085    m_hasUAAppearance = style->hasAppearance();
     1086    if (m_hasUAAppearance) {
     1087        m_borderData = style->border();
     1088        m_backgroundData = *style->backgroundLayers();
     1089        m_backgroundColor = style->backgroundColor();
     1090    }
     1091}
     1092
    10411093RefPtr<CSSRuleList> CSSStyleSelector::styleRulesForElement(Element* e, bool authorOnly)
    10421094{
     
    10501102   
    10511103    if (!authorOnly) {
     1104        int firstUARule = -1, lastUARule = -1;
    10521105        // First we match rules from the user agent sheet.
    1053         int firstUARule = -1, lastUARule = -1;
    1054         matchRules(defaultStyle, firstUARule, lastUARule);
    1055        
    1056         // In quirks mode, we match rules from the quirks user agent sheet.
    1057         if (!strictParsing)
    1058             matchRules(defaultQuirksStyle, firstUARule, lastUARule);
    1059        
    1060         // If our medium is print, then we match rules from the print sheet.
    1061         if (m_mediaType == "print")
    1062             matchRules(defaultPrintStyle, firstUARule, lastUARule);
     1106        matchUARules(firstUARule, lastUARule);
    10631107
    10641108        // Now we check user sheet rules.
     
    15891633}
    15901634
    1591 void CSSRuleSet::addRulesFromSheet(CSSStyleSheet *sheet, const String &medium)
     1635void CSSRuleSet::addRulesFromSheet(CSSStyleSheet* sheet,  MediaQueryEvaluator* medium)
    15921636{
    15931637    if (!sheet || !sheet->isCSSStyleSheet())
     
    15961640    // No media implies "all", but if a media list exists it must
    15971641    // contain our current medium
    1598     if (sheet->media() && !sheet->media()->contains(medium))
     1642    if (sheet->media() && !medium->eval(sheet->media()))
    15991643        return; // the style sheet doesn't apply
    16001644
     
    16101654        else if(item->isImportRule()) {
    16111655            CSSImportRule* import = static_cast<CSSImportRule*>(item);
    1612             if (!import->media() || import->media()->contains(medium))
     1656            if (!import->media() || medium->eval(import->media()))
    16131657                addRulesFromSheet(import->styleSheet(), medium);
    16141658        }
     
    16171661            CSSRuleList* rules = r->cssRules();
    16181662
    1619             if ((!r->media() || r->media()->contains(medium)) && rules) {
     1663            if ((!r->media() || medium->eval(r->media())) && rules) {
    16201664                // Traverse child elements of the @media rule.
    16211665                for (unsigned j = 0; j < rules->length(); j++) {
  • trunk/WebCore/css/cssstyleselector.h

    r14433 r14779  
    4545class CSSStyleSheet;
    4646class CSSValue;
     47class MediaQueryEvaluator;
    4748class Document;
    4849class Element;
     
    9495        void initElementAndPseudoState(Element* e);
    9596        void initForStyleResolve(Element* e, RenderStyle* parentStyle);
    96         RenderStyle *styleForElement(Element*, RenderStyle* parentStyle=0, bool allowSharing=true);
     97        RenderStyle *styleForElement(Element*, RenderStyle* parentStyle=0, bool allowSharing=true, bool resolveForRootDefault=false);
    9798        RenderStyle* pseudoStyleForElement(RenderStyle::PseudoId, Element*, RenderStyle* parentStyle=0);
    9899
     
    178179    private:
    179180        void init();
    180        
     181
     182        void matchUARules(int& firstUARule, int& lastUARule);
     183        void updateFont();
     184        void cacheBorderAndBackground();
     185         
    181186        void mapBackgroundAttachment(BackgroundLayer* layer, CSSValue* value);
    182187        void mapBackgroundClip(BackgroundLayer* layer, CSSValue* value);
     
    204209        bool m_collectRulesOnly;
    205210
    206         String m_mediaType;
     211        MediaQueryEvaluator* m_medium;
     212        RenderStyle* m_rootDefaultStyle;
    207213
    208214        RenderStyle::PseudoId dynamicPseudo;
  • trunk/WebCore/css/maketokenizer

    r14274 r14779  
    5454}
    5555
     56# media query, tokenizer state support
     57while (<>) {
     58  last if /yytext/;
     59}
     60while (<>) {
     61  last if not (/define/ || /line/) ;
     62  print;
     63}
     64
    5665while (<>) {
    5766    last if /^YY_DECL/;
  • trunk/WebCore/css/tokenizer.flex

    r14352 r14779  
    22%option noyywrap
    33%option 8bit
     4%option stack
     5%s mediaquery
    46
    57h               [0-9a-fA-F]
     
    3537"$="                    {yyTok = ENDSWITH; return yyTok;}
    3638"*="                    {yyTok = CONTAINS; return yyTok;}
     39<mediaquery>"not"       {yyTok = MEDIA_NOT; return yyTok;}
     40<mediaquery>"only"      {yyTok = MEDIA_ONLY; return yyTok;}
     41<mediaquery>"and"       {yyTok = MEDIA_AND; return yyTok;}
    3742
    3843{string}                {yyTok = STRING; return yyTok;}
     
    4247"#"{name}               {yyTok = HASH; return yyTok;}
    4348
    44 "@import"               {yyTok = IMPORT_SYM; return yyTok;}
     49"@import"               {BEGIN(mediaquery); yyTok = IMPORT_SYM; return yyTok;}
    4550"@page"                 {yyTok = PAGE_SYM; return yyTok;}
    46 "@media"                {yyTok = MEDIA_SYM; return yyTok;}
     51"@media"                {BEGIN(mediaquery); yyTok = MEDIA_SYM; return yyTok;}
    4752"@font-face"            {yyTok = FONT_FACE_SYM; return yyTok;}
    4853"@charset"              {yyTok = CHARSET_SYM; return yyTok;}
     
    5156"@-webkit-decls"   {yyTok = WEBKIT_DECLS_SYM; return yyTok; }
    5257"@-webkit-value"   {yyTok = WEBKIT_VALUE_SYM; return yyTok; }
     58"@-webkit-mediaquery"   {BEGIN(mediaquery); yyTok = WEBKIT_MEDIAQUERY_SYM; return yyTok; }
    5359
    5460"!"{w}"important"         {yyTok = IMPORTANT_SYM; return yyTok;}
     
    8288U\+{h}{1,6}-{h}{1,6}    {yyTok = UNICODERANGE; return yyTok;}
    8389
     90<mediaquery>"{"         |
     91<mediaquery>";"         {BEGIN(INITIAL); yyTok = *yytext; return yyTok; }
    8492.                       {yyTok = *yytext; return yyTok;}
    8593
  • trunk/WebCore/dom/DOMImplementation.cpp

    r14729 r14779  
    167167    CSSStyleSheet* const nullSheet = 0;
    168168    RefPtr<CSSStyleSheet> sheet = new CSSStyleSheet(nullSheet);
    169     sheet->setMedia(new MediaList(sheet.get(), media));
     169    sheet->setMedia(new MediaList(sheet.get(), media, true));
    170170    return sheet.release();
    171171}
  • trunk/WebCore/html/HTMLLinkElement.cpp

    r14714 r14779  
    3333#include "MediaList.h"
    3434#include "csshelper.h"
     35#include "MediaQueryEvaluator.h"
    3536
    3637namespace WebCore {
     
    169170        // ### there may be in some situations e.g. for an editor or script to manipulate
    170171        // also, don't load style sheets for standalone documents
    171         if (m_media.isNull() || m_media.contains("screen") || m_media.contains("all") || m_media.contains("print")) {
     172        MediaQueryEvaluator allEval(true);
     173        MediaQueryEvaluator screenEval("screen", true);
     174        MediaQueryEvaluator printEval("print", true);
     175        RefPtr<MediaList> media = new MediaList((CSSStyleSheet*)0, m_media, true);
     176        if (allEval.eval(media.get()) || screenEval.eval(media.get()) || printEval.eval(media.get())) {
    172177
    173178            // Add ourselves as a pending sheet, but only if we aren't an alternate
     
    212217    m_sheet->parseString(sheetStr, !document()->inCompatMode());
    213218
    214     MediaList* media = new MediaList(m_sheet.get(), m_media);
    215     m_sheet->setMedia(media);
     219    RefPtr<MediaList> media = new MediaList((CSSStyleSheet*)0, m_media, true);
     220    m_sheet->setMedia(media.get());
    216221
    217222    m_loading = false;
  • trunk/WebCore/html/HTMLStyleElement.cpp

    r14401 r14779  
    2828#include "HTMLNames.h"
    2929#include "MediaList.h"
     30#include "MediaQueryEvaluator.h"
    3031
    3132namespace WebCore {
     
    8485
    8586    m_loading = false;
    86     if ((m_type.isEmpty() || m_type == "text/css") // Type must be empty or CSS
    87          && (m_media.isNull() || m_media.contains("screen") || m_media.contains("all") || m_media.contains("print"))) {
    88         document()->addPendingSheet();
    89         m_loading = true;
    90         m_sheet = new CSSStyleSheet(this);
    91         m_sheet->parseString(text, !document()->inCompatMode());
    92         MediaList* media = new MediaList(m_sheet.get(), m_media);
    93         m_sheet->setMedia(media);
    94         m_loading = false;
     87    if (m_type.isEmpty() || m_type == "text/css") { // Type must be empty or CSS
     88        RefPtr<MediaList> media = new MediaList((CSSStyleSheet*)0, m_media, true);
     89        MediaQueryEvaluator screenEval("screen", true);
     90        MediaQueryEvaluator printEval("print", true);
     91        if (screenEval.eval(media.get()) || printEval.eval(media.get())) {
     92            document()->addPendingSheet();
     93            m_loading = true;
     94            m_sheet = new CSSStyleSheet(this);
     95            m_sheet->parseString(text, !document()->inCompatMode());
     96            m_sheet->setMedia(media.get());
     97            m_loading = false;
     98        }
    9599    }
    96100
  • trunk/WebCore/ksvg2/svg/SVGDOMImplementation.cpp

    r14729 r14779  
    192192    RefPtr<CSSStyleSheet> sheet = new CSSStyleSheet(parent);
    193193    //sheet->setTitle(title);
    194     sheet->setMedia(new MediaList(sheet.get(), media));
     194    // http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-DOMImplementationCSS says
     195    // that media descriptors should be used, even though svg:style has only
     196    // css media types. Hence the third parameter (true).
     197    sheet->setMedia(new MediaList(sheet.get(), media, true));
    195198    return sheet.release();
    196199}
  • trunk/WebCore/ksvg2/svg/SVGStyleElement.cpp

    r14401 r14779  
    3131#include "ExceptionCode.h"
    3232#include "MediaList.h"
     33#include "MediaQueryEvaluator.h"
    3334#include "PlatformString.h"
    3435
     
    9798
    9899    m_loading = false;
    99     const AtomicString& _media = media();
    100     if ((type().isEmpty() || type() == "text/css") && (_media.isNull() || _media.contains("screen") || _media.contains("all") || _media.contains("print"))) {
     100    MediaQueryEvaluator screenEval("screen", true);
     101    MediaQueryEvaluator printEval("print", true);   
     102    RefPtr<MediaList> mediaList = new MediaList((CSSStyleSheet*)0, media());
     103    if ((type().isEmpty() || type() == "text/css") && (screenEval.eval(mediaList.get()) || printEval.eval(mediaList.get()))) {
    101104        ownerDocument()->addPendingSheet();
    102105
     
    105108        m_sheet = new CSSStyleSheet(this);
    106109        m_sheet->parseString(textContent()); // SVG css is always parsed in strict mode
    107 
    108         MediaList* mediaList = new MediaList(m_sheet.get(), _media);
    109         m_sheet->setMedia(mediaList);
     110       
     111        m_sheet->setMedia(mediaList.get());
    110112        m_loading = false;
    111113    }
  • trunk/WebCore/page/Frame.cpp

    r14777 r14779  
    5151#include "HTMLGenericFormElement.h"
    5252#include "HTMLNames.h"
     53#include "MediaFeatureNames.h"
    5354#include "HTMLObjectElement.h"
    5455#include "ImageDocument.h"
     
    152153    HTMLNames::init();
    153154    QualifiedName::init();
     155    MediaFeatureNames::init();
    154156
    155157#if SVG_SUPPORT
  • trunk/WebCore/platform/Screen.h

    r14643 r14779  
    3333
    3434    int screenDepth(Widget*);
     35    int screenDepthPerComponent(Widget*);
     36    bool screenIsMonochrome(Widget*);
    3537    FloatRect screenRect(Widget*);
    3638    FloatRect usableScreenRect(Widget*);
  • trunk/WebCore/platform/mac/ScreenMac.mm

    r14678 r14779  
    8787}
    8888
     89int screenDepthPerComponent(Widget* widget)
     90{
     91   return NSBitsPerSampleFromDepth([screen(widget) depth]);
     92}
     93
     94bool screenIsMonochrome(Widget* widget)
     95{
     96    NSScreen* s = screen(widget);
     97    NSDictionary* dd = [s deviceDescription];
     98    NSString* colorSpaceName = [dd objectForKey:NSDeviceColorSpaceName];
     99    return colorSpaceName == NSCalibratedWhiteColorSpace
     100        || colorSpaceName == NSCalibratedBlackColorSpace
     101        || colorSpaceName == NSDeviceWhiteColorSpace
     102        || colorSpaceName == NSDeviceBlackColorSpace;
     103}
     104
    89105// These methods scale between window and WebView coordinates because JavaScript/DOM operations
    90106// assume that the WebView and the window share the same coordinate system.
Note: See TracChangeset for help on using the changeset viewer.