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.
8 #include "core/css/CSSPrimitiveValue.h"
9 #include "wtf/RefCounted.h"
10 #include "wtf/RefPtr.h"
15 class CSSPrimitiveValue;
18 class MediaValues : public RefCounted<MediaValues> {
21 enum MediaValuesMode {
26 enum PointerDeviceType {
33 virtual ~MediaValues() { }
35 static PassRefPtr<MediaValues> createDynamicIfFrameExists(LocalFrame*);
36 virtual PassRefPtr<MediaValues> copy() const = 0;
37 virtual bool isSafeToSendToAnotherThread() const = 0;
39 static bool computeLengthImpl(double value, CSSPrimitiveValue::UnitTypes, unsigned defaultFontSize, unsigned viewportWidth, unsigned viewportHeight, double& result);
41 static bool computeLength(double value, CSSPrimitiveValue::UnitTypes type, unsigned defaultFontSize, unsigned viewportWidth, unsigned viewportHeight, T& result)
44 if (!computeLengthImpl(value, type, defaultFontSize, viewportWidth, viewportHeight, tempResult))
46 result = roundForImpreciseConversion<T>(tempResult);
49 virtual bool computeLength(double value, CSSPrimitiveValue::UnitTypes, int& result) const = 0;
50 virtual bool computeLength(double value, CSSPrimitiveValue::UnitTypes, double& result) const = 0;
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;
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;
88 #endif // MediaValues_h