| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/cssom/CSSStyleImageValue.h" | 5 #include "core/css/cssom/CSSStyleImageValue.h" |
| 6 | 6 |
| 7 namespace blink { | 7 namespace blink { |
| 8 | 8 |
| 9 double CSSStyleImageValue::intrinsicWidth(bool& isNull) | 9 double CSSStyleImageValue::intrinsicWidth(bool& isNull) const |
| 10 { | 10 { |
| 11 isNull = isCachePending(); | 11 isNull = isCachePending(); |
| 12 if (isNull) | 12 if (isNull) |
| 13 return 0; | 13 return 0; |
| 14 return imageLayoutSize().width().toDouble(); | 14 return imageLayoutSize().width().toDouble(); |
| 15 } | 15 } |
| 16 | 16 |
| 17 double CSSStyleImageValue::intrinsicHeight(bool& isNull) | 17 double CSSStyleImageValue::intrinsicHeight(bool& isNull) const |
| 18 { | 18 { |
| 19 isNull = isCachePending(); | 19 isNull = isCachePending(); |
| 20 if (isNull) | 20 if (isNull) |
| 21 return 0; | 21 return 0; |
| 22 return imageLayoutSize().height().toDouble(); | 22 return imageLayoutSize().height().toDouble(); |
| 23 } | 23 } |
| 24 | 24 |
| 25 double CSSStyleImageValue::intrinsicRatio(bool& isNull) | 25 double CSSStyleImageValue::intrinsicRatio(bool& isNull) |
| 26 { | 26 { |
| 27 isNull = isCachePending(); | 27 isNull = isCachePending(); |
| 28 if (isNull) { | 28 if (isNull) { |
| 29 return 0; | 29 return 0; |
| 30 } | 30 } |
| 31 if (intrinsicHeight(isNull) == 0) { | 31 if (intrinsicHeight(isNull) == 0) { |
| 32 isNull = true; | 32 isNull = true; |
| 33 return 0; | 33 return 0; |
| 34 } | 34 } |
| 35 return intrinsicWidth(isNull) / intrinsicHeight(isNull); | 35 return intrinsicWidth(isNull) / intrinsicHeight(isNull); |
| 36 } | 36 } |
| 37 | 37 |
| 38 FloatSize CSSStyleImageValue::elementSize(const FloatSize& defaultObjectSize) co
nst |
| 39 { |
| 40 bool notUsed; |
| 41 return FloatSize(intrinsicWidth(notUsed), intrinsicHeight(notUsed)); |
| 42 } |
| 43 |
| 44 bool CSSStyleImageValue::isAccelerated() const |
| 45 { |
| 46 return image() && image()->isTextureBacked(); |
| 47 } |
| 48 |
| 49 int CSSStyleImageValue::sourceHeight() |
| 50 { |
| 51 bool notUsed; |
| 52 return intrinsicHeight(notUsed); |
| 53 } |
| 54 |
| 55 int CSSStyleImageValue::sourceWidth() |
| 56 { |
| 57 bool notUsed; |
| 58 return intrinsicWidth(notUsed); |
| 59 } |
| 60 |
| 61 PassRefPtr<Image> CSSStyleImageValue::image() const |
| 62 { |
| 63 if (isCachePending()) |
| 64 return nullptr; |
| 65 // cachedImage can be null if image is StyleInvalidImage |
| 66 ImageResource* cachedImage = m_imageValue->cachedImage()->cachedImage(); |
| 67 if (cachedImage) { |
| 68 // getImage() returns the nullImage() if the image is not available yet |
| 69 return cachedImage->getImage()->imageForDefaultFrame(); |
| 70 } |
| 71 return nullptr; |
| 72 } |
| 73 |
| 38 } // namespace blink | 74 } // namespace blink |
| OLD | NEW |