| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/css/MediaValuesDynamic.h" | 5 #include "core/css/MediaValuesDynamic.h" |
| 6 | 6 |
| 7 #include "core/css/CSSHelper.h" | 7 #include "core/css/CSSHelper.h" |
| 8 #include "core/css/CSSPrimitiveValue.h" | 8 #include "core/css/CSSPrimitiveValue.h" |
| 9 #include "core/css/CSSToLengthConversionData.h" | 9 #include "core/css/CSSToLengthConversionData.h" |
| 10 #include "core/css/MediaValuesCached.h" | 10 #include "core/css/MediaValuesCached.h" |
| 11 #include "core/dom/Document.h" | 11 #include "core/dom/Document.h" |
| 12 #include "core/frame/LocalFrame.h" | 12 #include "core/frame/LocalFrame.h" |
| 13 | 13 |
| 14 namespace blink { | 14 namespace blink { |
| 15 | 15 |
| 16 PassRefPtrWillBeRawPtr<MediaValues> MediaValuesDynamic::create(Document& documen
t) | 16 PassRefPtrWillBeRawPtr<MediaValues> MediaValuesDynamic::create(Document& documen
t) |
| 17 { | 17 { |
| 18 return MediaValuesDynamic::create(frameFrom(document)); | 18 return MediaValuesDynamic::create(frameFrom(document)); |
| 19 } | 19 } |
| 20 | 20 |
| 21 PassRefPtrWillBeRawPtr<MediaValues> MediaValuesDynamic::create(LocalFrame* frame
) | 21 PassRefPtrWillBeRawPtr<MediaValues> MediaValuesDynamic::create(LocalFrame* frame
) |
| 22 { | 22 { |
| 23 if (!frame || !frame->view() || !frame->document() || !frame->document()->la
youtView()) | 23 if (!frame || !frame->view() || !frame->document() || !frame->document()->la
youtView()) |
| 24 return MediaValuesCached::create(); | 24 return MediaValuesCached::create(); |
| 25 return adoptRefWillBeNoop(new MediaValuesDynamic(frame)); | 25 return adoptRefWillBeNoop(new MediaValuesDynamic(frame)); |
| 26 } | 26 } |
| 27 | 27 |
| 28 MediaValuesDynamic::MediaValuesDynamic(LocalFrame* frame) | 28 MediaValuesDynamic::MediaValuesDynamic(LocalFrame* frame) |
| 29 : m_frame(frame) | 29 : m_frame(frame) |
| 30 , m_viewportDimensionsOverridden(false) |
| 31 , m_viewportWidthOverride(0) |
| 32 , m_viewportHeightOverride(0) |
| 33 { |
| 34 ASSERT(m_frame); |
| 35 } |
| 36 |
| 37 MediaValuesDynamic::MediaValuesDynamic(LocalFrame* frame, bool overriddenViewpor
tDimensions, double viewportWidth, double viewportHeight) |
| 38 : m_frame(frame) |
| 39 , m_viewportDimensionsOverridden(overriddenViewportDimensions) |
| 40 , m_viewportWidthOverride(viewportWidth) |
| 41 , m_viewportHeightOverride(viewportHeight) |
| 30 { | 42 { |
| 31 ASSERT(m_frame); | 43 ASSERT(m_frame); |
| 32 } | 44 } |
| 33 | 45 |
| 34 PassRefPtrWillBeRawPtr<MediaValues> MediaValuesDynamic::copy() const | 46 PassRefPtrWillBeRawPtr<MediaValues> MediaValuesDynamic::copy() const |
| 35 { | 47 { |
| 36 return adoptRefWillBeNoop(new MediaValuesDynamic(m_frame)); | 48 return adoptRefWillBeNoop(new MediaValuesDynamic(m_frame, m_viewportDimensio
nsOverridden, m_viewportWidthOverride, m_viewportHeightOverride)); |
| 37 } | 49 } |
| 38 | 50 |
| 39 bool MediaValuesDynamic::computeLength(double value, CSSPrimitiveValue::UnitType
type, int& result) const | 51 bool MediaValuesDynamic::computeLength(double value, CSSPrimitiveValue::UnitType
type, int& result) const |
| 40 { | 52 { |
| 41 return MediaValues::computeLength(value, | 53 return MediaValues::computeLength(value, |
| 42 type, | 54 type, |
| 43 calculateDefaultFontSize(m_frame), | 55 calculateDefaultFontSize(m_frame), |
| 44 calculateViewportWidth(m_frame), | 56 calculateViewportWidth(m_frame), |
| 45 calculateViewportHeight(m_frame), | 57 calculateViewportHeight(m_frame), |
| 46 result); | 58 result); |
| 47 } | 59 } |
| 48 | 60 |
| 49 bool MediaValuesDynamic::computeLength(double value, CSSPrimitiveValue::UnitType
type, double& result) const | 61 bool MediaValuesDynamic::computeLength(double value, CSSPrimitiveValue::UnitType
type, double& result) const |
| 50 { | 62 { |
| 51 return MediaValues::computeLength(value, | 63 return MediaValues::computeLength(value, |
| 52 type, | 64 type, |
| 53 calculateDefaultFontSize(m_frame), | 65 calculateDefaultFontSize(m_frame), |
| 54 calculateViewportWidth(m_frame), | 66 calculateViewportWidth(m_frame), |
| 55 calculateViewportHeight(m_frame), | 67 calculateViewportHeight(m_frame), |
| 56 result); | 68 result); |
| 57 } | 69 } |
| 58 | 70 |
| 59 double MediaValuesDynamic::viewportWidth() const | 71 double MediaValuesDynamic::viewportWidth() const |
| 60 { | 72 { |
| 73 if (m_viewportDimensionsOverridden) |
| 74 return m_viewportWidthOverride; |
| 61 return calculateViewportWidth(m_frame); | 75 return calculateViewportWidth(m_frame); |
| 62 } | 76 } |
| 63 | 77 |
| 64 double MediaValuesDynamic::viewportHeight() const | 78 double MediaValuesDynamic::viewportHeight() const |
| 65 { | 79 { |
| 80 if (m_viewportDimensionsOverridden) |
| 81 return m_viewportHeightOverride; |
| 66 return calculateViewportHeight(m_frame); | 82 return calculateViewportHeight(m_frame); |
| 67 } | 83 } |
| 68 | 84 |
| 69 int MediaValuesDynamic::deviceWidth() const | 85 int MediaValuesDynamic::deviceWidth() const |
| 70 { | 86 { |
| 71 return calculateDeviceWidth(m_frame); | 87 return calculateDeviceWidth(m_frame); |
| 72 } | 88 } |
| 73 | 89 |
| 74 int MediaValuesDynamic::deviceHeight() const | 90 int MediaValuesDynamic::deviceHeight() const |
| 75 { | 91 { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 { | 156 { |
| 141 return m_frame; | 157 return m_frame; |
| 142 } | 158 } |
| 143 | 159 |
| 144 DEFINE_TRACE(MediaValuesDynamic) | 160 DEFINE_TRACE(MediaValuesDynamic) |
| 145 { | 161 { |
| 146 visitor->trace(m_frame); | 162 visitor->trace(m_frame); |
| 147 MediaValues::trace(visitor); | 163 MediaValues::trace(visitor); |
| 148 } | 164 } |
| 149 | 165 |
| 166 void MediaValuesDynamic::overrideViewportDimensions(double width, double height) |
| 167 { |
| 168 m_viewportDimensionsOverridden = true; |
| 169 m_viewportWidthOverride = width; |
| 170 m_viewportHeightOverride = height; |
| 171 } |
| 172 |
| 150 } // namespace blink | 173 } // namespace blink |
| OLD | NEW |