• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "core/css/PointerProperties.h"
10 #include "wtf/RefCounted.h"
11 #include "wtf/RefPtr.h"
12 
13 namespace blink {
14 
15 class Document;
16 class CSSPrimitiveValue;
17 class LocalFrame;
18 
19 class MediaValues : public RefCounted<MediaValues> {
20 public:
21 
22     enum MediaValuesMode {
23         CachingMode,
24         DynamicMode
25     };
26 
~MediaValues()27     virtual ~MediaValues() { }
28 
29     static PassRefPtr<MediaValues> createDynamicIfFrameExists(LocalFrame*);
30     virtual PassRefPtr<MediaValues> copy() const = 0;
31     virtual bool isSafeToSendToAnotherThread() const = 0;
32 
33     static bool computeLengthImpl(double value, CSSPrimitiveValue::UnitType, unsigned defaultFontSize, unsigned viewportWidth, unsigned viewportHeight, double& result);
34     template<typename T>
computeLength(double value,CSSPrimitiveValue::UnitType type,unsigned defaultFontSize,unsigned viewportWidth,unsigned viewportHeight,T & result)35     static bool computeLength(double value, CSSPrimitiveValue::UnitType type, unsigned defaultFontSize, unsigned viewportWidth, unsigned viewportHeight, T& result)
36     {
37         double tempResult;
38         if (!computeLengthImpl(value, type, defaultFontSize, viewportWidth, viewportHeight, tempResult))
39             return false;
40         result = roundForImpreciseConversion<T>(tempResult);
41         return true;
42     }
43     virtual bool computeLength(double value, CSSPrimitiveValue::UnitType, int& result) const = 0;
44     virtual bool computeLength(double value, CSSPrimitiveValue::UnitType, double& result) const = 0;
45 
46     virtual int viewportWidth() const = 0;
47     virtual int viewportHeight() const = 0;
48     virtual int deviceWidth() const = 0;
49     virtual int deviceHeight() const = 0;
50     virtual float devicePixelRatio() const = 0;
51     virtual int colorBitsPerComponent() const = 0;
52     virtual int monochromeBitsPerComponent() const = 0;
53     virtual PointerType primaryPointerType() const = 0;
54     virtual int availablePointerTypes() const = 0;
55     virtual HoverType primaryHoverType() const = 0;
56     virtual int availableHoverTypes() const = 0;
57     virtual bool threeDEnabled() const = 0;
58     virtual const String mediaType() const = 0;
59     virtual bool strictMode() const = 0;
60     virtual Document* document() const = 0;
61     virtual bool hasValues() const = 0;
62 
63 protected:
64     int calculateViewportWidth(LocalFrame*) const;
65     int calculateViewportHeight(LocalFrame*) const;
66     int calculateDeviceWidth(LocalFrame*) const;
67     int calculateDeviceHeight(LocalFrame*) const;
68     bool calculateStrictMode(LocalFrame*) const;
69     float calculateDevicePixelRatio(LocalFrame*) const;
70     int calculateColorBitsPerComponent(LocalFrame*) const;
71     int calculateMonochromeBitsPerComponent(LocalFrame*) const;
72     int calculateDefaultFontSize(LocalFrame*) const;
73     const String calculateMediaType(LocalFrame*) const;
74     bool calculateThreeDEnabled(LocalFrame*) const;
75     PointerType calculatePrimaryPointerType(LocalFrame*) const;
76     int calculateAvailablePointerTypes(LocalFrame*) const;
77     HoverType calculatePrimaryHoverType(LocalFrame*) const;
78     int calculateAvailableHoverTypes(LocalFrame*) const;
79     static LocalFrame* frameFrom(Document&);
80 
81 };
82 
83 } // namespace
84 
85 #endif // MediaValues_h
86