Changeset 133884 in webkit


Ignore:
Timestamp:
Nov 8, 2012 5:11:53 AM (11 years ago)
Author:
commit-queue@webkit.org
Message:

Warn in the inspector console when using dpi and dpcm units outside of media="print"
https://bugs.webkit.org/show_bug.cgi?id=100865

Patch by Alexander Shalamov <alexander.shalamov@intel.com> on 2012-11-08
Reviewed by Kenneth Rohde Christiansen.

Source/WebCore:

Added function that prints warning to inspector console whenever dpi or dpcm CSS units
are used for screen media.

Test: fast/media/mq-resolution-dpi-dpcm-warning.html

  • css/CSSStyleSheet.cpp:

(WebCore::CSSStyleSheet::setMediaQueries):

  • css/MediaList.cpp:

(WebCore):
(WebCore::addResolutionWarningMessageToConsole):
(WebCore::reportMediaQueryWarningIfNeeded):

  • css/MediaList.h:

(WebCore):

  • css/MediaQueryMatcher.cpp:

(WebCore::MediaQueryMatcher::matchMedia):

  • css/StyleSheetContents.cpp:

(WebCore::StyleSheetContents::parserAppendRule):

LayoutTests:

Added layout test that checks if warning is printed to console when dpi or dpcm CSS
units are used for resolution media feature.

  • fast/media/mq-resolution-dpi-dpcm-warning-expected.txt: Added.
  • fast/media/mq-resolution-dpi-dpcm-warning.html: Added.

Skip tests for platforms that doesn't support resolution media feature.

  • platform/chromium/TestExpectations:
  • platform/gtk/TestExpectations:
  • platform/mac/TestExpectations:
  • platform/win/TestExpectations:
Location:
trunk
Files:
2 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r133883 r133884  
     12012-11-08  Alexander Shalamov  <alexander.shalamov@intel.com>
     2
     3        Warn in the inspector console when using dpi and dpcm units outside of media="print"
     4        https://bugs.webkit.org/show_bug.cgi?id=100865
     5
     6        Reviewed by Kenneth Rohde Christiansen.
     7
     8        Added layout test that checks if warning is printed to console when dpi or dpcm CSS
     9        units are used for resolution media feature.
     10
     11        * fast/media/mq-resolution-dpi-dpcm-warning-expected.txt: Added.
     12        * fast/media/mq-resolution-dpi-dpcm-warning.html: Added.
     13
     14        Skip tests for platforms that doesn't support resolution media feature.
     15
     16        * platform/chromium/TestExpectations:
     17        * platform/gtk/TestExpectations:
     18        * platform/mac/TestExpectations:
     19        * platform/win/TestExpectations:
     20
    1212012-11-08  Zan Dobersek  <zandobersek@gmail.com>
    222
  • trunk/LayoutTests/platform/chromium/TestExpectations

    r133856 r133884  
    195195# Resolution media query is not yet enabled.
    196196webkit.org/b/85262 fast/media/mq-resolution.html [ Skip ]
     197webkit.org/b/85262 fast/media/mq-resolution-dpi-dpcm-warning.html [ Skip ]
    197198
    198199# CSS image-orientation is not yet enabled.
  • trunk/LayoutTests/platform/gtk/TestExpectations

    r133870 r133884  
    390390# Requires Resolution Media Query support
    391391webkit.org/b/100137 fast/media/mq-resolution.html [ Failure ]
     392webkit.org/b/100137 fast/media/mq-resolution-dpi-dpcm-warning.html [ Failure ]
    392393
    393394# CSS Device Adaptation is not enabled.
  • trunk/LayoutTests/platform/mac/TestExpectations

    r133786 r133884  
    979979# Resolution media query is not yet enabled.
    980980webkit.org/b/85262 fast/media/mq-resolution.html [ Skip ]
     981webkit.org/b/85262 fast/media/mq-resolution-dpi-dpcm-warning.html [ Skip ]
    981982
    982983# CSS image-orientation is not yet enabled.
  • trunk/LayoutTests/platform/win/TestExpectations

    r133695 r133884  
    10381038fast/media/media-query-list-07.html
    10391039fast/media/mq-resolution.html
     1040fast/media/mq-resolution-dpi-dpcm-warning.html
    10401041
    10411042# Need expectations. See https://bugs.webkit.org/show_bug.cgi?id=36461
     
    19971998fast/forms/month-multiple-fields
    19981999fast/forms/time-multiple-fields
    1999 fast/forms/week-multiple-fields
    20002000
    20012001# Require rebaseline after https://bugs.webkit.org/show_bug.cgi?id=84286
  • trunk/Source/WebCore/ChangeLog

    r133881 r133884  
     12012-11-08  Alexander Shalamov  <alexander.shalamov@intel.com>
     2
     3        Warn in the inspector console when using dpi and dpcm units outside of media="print"
     4        https://bugs.webkit.org/show_bug.cgi?id=100865
     5
     6        Reviewed by Kenneth Rohde Christiansen.
     7
     8        Added function that prints warning to inspector console whenever dpi or dpcm CSS units
     9        are used for screen media.
     10
     11        Test: fast/media/mq-resolution-dpi-dpcm-warning.html
     12
     13        * css/CSSStyleSheet.cpp:
     14        (WebCore::CSSStyleSheet::setMediaQueries):
     15        * css/MediaList.cpp:
     16        (WebCore):
     17        (WebCore::addResolutionWarningMessageToConsole):
     18        (WebCore::reportMediaQueryWarningIfNeeded):
     19        * css/MediaList.h:
     20        (WebCore):
     21        * css/MediaQueryMatcher.cpp:
     22        (WebCore::MediaQueryMatcher::matchMedia):
     23        * css/StyleSheetContents.cpp:
     24        (WebCore::StyleSheetContents::parserAppendRule):
     25
    1262012-11-08  Eugene Klyuchnikov  <eustas.bug@gmail.com>
    227
  • trunk/Source/WebCore/css/CSSStyleSheet.cpp

    r130816 r133884  
    206206    if (m_mediaCSSOMWrapper && m_mediaQueries)
    207207        m_mediaCSSOMWrapper->reattach(m_mediaQueries.get());
     208
     209#if ENABLE(RESOLUTION_MEDIA_QUERY)
     210    // Add warning message to inspector whenever dpi/dpcm values are used for "screen" media.
     211    reportMediaQueryWarningIfNeeded(ownerDocument(), m_mediaQueries.get());
     212#endif
    208213}
    209214
  • trunk/Source/WebCore/css/MediaList.cpp

    r129466 r133884  
    2424#include "CSSParser.h"
    2525#include "CSSStyleSheet.h"
     26#include "Console.h"
     27#include "DOMWindow.h"
     28#include "Document.h"
    2629#include "ExceptionCode.h"
     30#include "MediaFeatureNames.h"
    2731#include "MediaQuery.h"
    2832#include "MediaQueryExp.h"
     33#include "ScriptableDocumentParser.h"
    2934#include "WebCoreMemoryInstrumentation.h"
    3035#include <wtf/MemoryInstrumentationVector.h>
     
    298303}
    299304
    300 }
     305#if ENABLE(RESOLUTION_MEDIA_QUERY)
     306static void addResolutionWarningMessageToConsole(Document* document, const String& serializedExpression, const CSSPrimitiveValue* value)
     307{
     308    ASSERT(document);
     309    ASSERT(value);
     310
     311    DEFINE_STATIC_LOCAL(String, mediaQueryMessage, (ASCIILiteral("Consider using 'dppx' units instead of '%replacementUnits%', as in CSS '%replacementUnits%' means dots-per-CSS-%lengthUnit%, not dots-per-physical-%lengthUnit%, so does not correspond to the actual '%replacementUnits%' of a screen. In media query expression: ")));
     312    DEFINE_STATIC_LOCAL(String, mediaValueDPI, (ASCIILiteral("dpi")));
     313    DEFINE_STATIC_LOCAL(String, mediaValueDPCM, (ASCIILiteral("dpcm")));
     314    DEFINE_STATIC_LOCAL(String, lengthUnitInch, (ASCIILiteral("inch")));
     315    DEFINE_STATIC_LOCAL(String, lengthUnitCentimeter, (ASCIILiteral("centimeter")));
     316
     317    String message;
     318    if (value->isDotsPerInch())
     319        message = String(mediaQueryMessage).replace("%replacementUnits%", mediaValueDPI).replace("%lengthUnit%", lengthUnitInch);
     320    else if (value->isDotsPerCentimeter())
     321        message = String(mediaQueryMessage).replace("%replacementUnits%", mediaValueDPCM).replace("%lengthUnit%", lengthUnitCentimeter);
     322    else
     323        ASSERT_NOT_REACHED();
     324
     325    message.append(serializedExpression);
     326
     327    int lineNumber = 1;
     328    ScriptableDocumentParser* parser = document->scriptableDocumentParser();
     329    if (parser)
     330        lineNumber = parser->lineNumber().oneBasedInt();
     331
     332    document->domWindow()->console()->addMessage(HTMLMessageSource, LogMessageType, TipMessageLevel, message, document->url().string(), lineNumber);
     333}
     334
     335void reportMediaQueryWarningIfNeeded(Document* document, const MediaQuerySet* mediaQuerySet)
     336{
     337    if (!mediaQuerySet || !document)
     338        return;
     339
     340    const Vector<OwnPtr<MediaQuery> >& mediaQueries = mediaQuerySet->queryVector();
     341    const size_t queryCount = mediaQueries.size();
     342
     343    if (!queryCount)
     344        return;
     345
     346    for (size_t i = 0; i < queryCount; ++i) {
     347        const MediaQuery* query = mediaQueries[i].get();
     348        String mediaType = query->mediaType();
     349        if (!query->ignored() && !equalIgnoringCase(mediaType, "print")) {
     350            const Vector<OwnPtr<MediaQueryExp> >* exps = query->expressions();
     351            for (size_t j = 0; j < exps->size(); ++j) {
     352                const MediaQueryExp* exp = exps->at(j).get();
     353                if (exp->mediaFeature() == MediaFeatureNames::resolutionMediaFeature || exp->mediaFeature() == MediaFeatureNames::max_resolutionMediaFeature || exp->mediaFeature() == MediaFeatureNames::min_resolutionMediaFeature) {
     354                    CSSValue* cssValue =  exp->value();
     355                    if (cssValue && cssValue->isPrimitiveValue()) {
     356                        CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(cssValue);
     357                        if (primitiveValue->isDotsPerInch() || primitiveValue->isDotsPerCentimeter())
     358                            addResolutionWarningMessageToConsole(document, mediaQuerySet->mediaText(), primitiveValue);
     359                    }
     360                }
     361            }
     362        }
     363    }
     364}
     365#endif
     366
     367}
  • trunk/Source/WebCore/css/MediaList.h

    r128418 r133884  
    3333class CSSRule;
    3434class CSSStyleSheet;
     35class Document;
    3536class MediaList;
    3637class MediaQuery;
     
    121122};
    122123
     124#if ENABLE(RESOLUTION_MEDIA_QUERY)
     125// Adds message to inspector console whenever dpi or dpcm values are used for "screen" media.
     126void reportMediaQueryWarningIfNeeded(Document*, const MediaQuerySet*);
     127#endif
     128
    123129} // namespace
    124130
  • trunk/Source/WebCore/css/MediaQueryMatcher.cpp

    r115215 r133884  
    109109
    110110    RefPtr<MediaQuerySet> media = MediaQuerySet::create(query);
     111#if ENABLE(RESOLUTION_MEDIA_QUERY)
     112    // Add warning message to inspector whenever dpi/dpcm values are used for "screen" media.
     113    reportMediaQueryWarningIfNeeded(m_document, media.get());
     114#endif
    111115    return MediaQueryList::create(this, media, evaluate(media.get()));
    112116}
  • trunk/Source/WebCore/css/StyleSheetContents.cpp

    r133316 r133884  
    2727#include "CachedCSSStyleSheet.h"
    2828#include "Document.h"
     29#include "MediaList.h"
    2930#include "Node.h"
    3031#include "SecurityOrigin.h"
     
    136137        return;
    137138    }
     139
     140#if ENABLE(RESOLUTION_MEDIA_QUERY)
     141    // Add warning message to inspector if dpi/dpcm values are used for screen media.
     142    if (rule->isMediaRule())
     143        reportMediaQueryWarningIfNeeded(singleOwnerDocument(), static_cast<StyleRuleMedia*>(rule.get())->mediaQueries());
     144#endif
     145
    138146    m_childRules.append(rule);
    139147}
Note: See TracChangeset for help on using the changeset viewer.