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 #include "config.h" 6 #include "core/css/MediaValuesDynamic.h" 7 8 #include "core/css/CSSHelper.h" 9 #include "core/css/CSSPrimitiveValue.h" 10 #include "core/css/CSSToLengthConversionData.h" 11 #include "core/css/MediaValuesCached.h" 12 #include "core/dom/Document.h" 13 #include "core/frame/LocalFrame.h" 14 15 namespace blink { 16 17 PassRefPtr<MediaValues> MediaValuesDynamic::create(Document& document) 18 { 19 return MediaValuesDynamic::create(frameFrom(document)); 20 } 21 22 PassRefPtr<MediaValues> MediaValuesDynamic::create(LocalFrame* frame) 23 { 24 if (!frame || !frame->view() || !frame->document() || !frame->document()->renderView()) 25 return MediaValuesCached::create(); 26 return adoptRef(new MediaValuesDynamic(frame)); 27 } 28 29 MediaValuesDynamic::MediaValuesDynamic(LocalFrame* frame) 30 : m_frame(frame) 31 { 32 ASSERT(m_frame); 33 } 34 35 PassRefPtr<MediaValues> MediaValuesDynamic::copy() const 36 { 37 return adoptRef(new MediaValuesDynamic(m_frame)); 38 } 39 40 bool MediaValuesDynamic::computeLength(double value, CSSPrimitiveValue::UnitType type, int& result) const 41 { 42 return MediaValues::computeLength(value, 43 type, 44 calculateDefaultFontSize(m_frame), 45 calculateViewportWidth(m_frame), 46 calculateViewportHeight(m_frame), 47 result); 48 } 49 50 bool MediaValuesDynamic::computeLength(double value, CSSPrimitiveValue::UnitType type, double& result) const 51 { 52 return MediaValues::computeLength(value, 53 type, 54 calculateDefaultFontSize(m_frame), 55 calculateViewportWidth(m_frame), 56 calculateViewportHeight(m_frame), 57 result); 58 } 59 60 bool MediaValuesDynamic::isSafeToSendToAnotherThread() const 61 { 62 return false; 63 } 64 65 int MediaValuesDynamic::viewportWidth() const 66 { 67 return calculateViewportWidth(m_frame); 68 } 69 70 int MediaValuesDynamic::viewportHeight() const 71 { 72 return calculateViewportHeight(m_frame); 73 } 74 75 int MediaValuesDynamic::deviceWidth() const 76 { 77 return calculateDeviceWidth(m_frame); 78 } 79 80 int MediaValuesDynamic::deviceHeight() const 81 { 82 return calculateDeviceHeight(m_frame); 83 } 84 85 float MediaValuesDynamic::devicePixelRatio() const 86 { 87 return calculateDevicePixelRatio(m_frame); 88 } 89 90 int MediaValuesDynamic::colorBitsPerComponent() const 91 { 92 return calculateColorBitsPerComponent(m_frame); 93 } 94 95 int MediaValuesDynamic::monochromeBitsPerComponent() const 96 { 97 return calculateMonochromeBitsPerComponent(m_frame); 98 } 99 100 PointerType MediaValuesDynamic::primaryPointerType() const 101 { 102 return calculatePrimaryPointerType(m_frame); 103 } 104 105 int MediaValuesDynamic::availablePointerTypes() const 106 { 107 return calculateAvailablePointerTypes(m_frame); 108 } 109 110 HoverType MediaValuesDynamic::primaryHoverType() const 111 { 112 return calculatePrimaryHoverType(m_frame); 113 } 114 115 int MediaValuesDynamic::availableHoverTypes() const 116 { 117 return calculateAvailableHoverTypes(m_frame); 118 } 119 120 bool MediaValuesDynamic::threeDEnabled() const 121 { 122 return calculateThreeDEnabled(m_frame); 123 } 124 125 const String MediaValuesDynamic::mediaType() const 126 { 127 return calculateMediaType(m_frame); 128 } 129 130 bool MediaValuesDynamic::strictMode() const 131 { 132 return calculateStrictMode(m_frame); 133 } 134 135 Document* MediaValuesDynamic::document() const 136 { 137 return m_frame->document(); 138 } 139 140 bool MediaValuesDynamic::hasValues() const 141 { 142 return m_frame; 143 } 144 145 } // namespace 146