Home | History | Annotate | Download | only in css
      1 // Copyright 2014 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef MediaValues_h
      6 #define MediaValues_h
      7 
      8 #include "core/css/CSSPrimitiveValue.h"
      9 #include "wtf/RefCounted.h"
     10 #include "wtf/RefPtr.h"
     11 
     12 namespace WebCore {
     13 
     14 class Document;
     15 class CSSPrimitiveValue;
     16 class LocalFrame;
     17 
     18 class MediaValues : public RefCounted<MediaValues> {
     19 public:
     20 
     21     enum MediaValuesMode {
     22         CachingMode,
     23         DynamicMode
     24     };
     25 
     26     enum PointerDeviceType {
     27         TouchPointer,
     28         MousePointer,
     29         NoPointer,
     30         UnknownPointer
     31     };
     32 
     33     virtual ~MediaValues() { }
     34 
     35     static PassRefPtr<MediaValues> createDynamicIfFrameExists(LocalFrame*);
     36     virtual PassRefPtr<MediaValues> copy() const = 0;
     37     virtual bool isSafeToSendToAnotherThread() const = 0;
     38 
     39     static bool computeLengthImpl(double value, CSSPrimitiveValue::UnitType, unsigned defaultFontSize, unsigned viewportWidth, unsigned viewportHeight, double& result);
     40     template<typename T>
     41     static bool computeLength(double value, CSSPrimitiveValue::UnitType type, unsigned defaultFontSize, unsigned viewportWidth, unsigned viewportHeight, T& result)
     42     {
     43         double tempResult;
     44         if (!computeLengthImpl(value, type, defaultFontSize, viewportWidth, viewportHeight, tempResult))
     45             return false;
     46         result = roundForImpreciseConversion<T>(tempResult);
     47         return true;
     48     }
     49     virtual bool computeLength(double value, CSSPrimitiveValue::UnitType, int& result) const = 0;
     50     virtual bool computeLength(double value, CSSPrimitiveValue::UnitType, double& result) const = 0;
     51 
     52     virtual int viewportWidth() const = 0;
     53     virtual int viewportHeight() const = 0;
     54     virtual int deviceWidth() const = 0;
     55     virtual int deviceHeight() const = 0;
     56     virtual float devicePixelRatio() const = 0;
     57     virtual int colorBitsPerComponent() const = 0;
     58     virtual int monochromeBitsPerComponent() const = 0;
     59     virtual PointerDeviceType pointer() const = 0;
     60     virtual bool threeDEnabled() const = 0;
     61     virtual bool scanMediaType() const = 0;
     62     virtual bool screenMediaType() const = 0;
     63     virtual bool printMediaType() const = 0;
     64     virtual bool strictMode() const = 0;
     65     virtual Document* document() const = 0;
     66     virtual bool hasValues() const = 0;
     67 
     68 protected:
     69     int calculateViewportWidth(LocalFrame*) const;
     70     int calculateViewportHeight(LocalFrame*) const;
     71     int calculateDeviceWidth(LocalFrame*) const;
     72     int calculateDeviceHeight(LocalFrame*) const;
     73     bool calculateStrictMode(LocalFrame*) const;
     74     float calculateDevicePixelRatio(LocalFrame*) const;
     75     int calculateColorBitsPerComponent(LocalFrame*) const;
     76     int calculateMonochromeBitsPerComponent(LocalFrame*) const;
     77     int calculateDefaultFontSize(LocalFrame*) const;
     78     bool calculateScanMediaType(LocalFrame*) const;
     79     bool calculateScreenMediaType(LocalFrame*) const;
     80     bool calculatePrintMediaType(LocalFrame*) const;
     81     bool calculateThreeDEnabled(LocalFrame*) const;
     82     MediaValues::PointerDeviceType calculateLeastCapablePrimaryPointerDeviceType(LocalFrame*) const;
     83 
     84 };
     85 
     86 } // namespace
     87 
     88 #endif // MediaValues_h
     89