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/MediaValuesCached.h" | 5 #include "core/css/MediaValuesCached.h" |
6 | 6 |
7 #include "core/css/CSSPrimitiveValue.h" | 7 #include "core/css/CSSPrimitiveValue.h" |
8 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
9 #include "core/frame/LocalFrame.h" | 9 #include "core/frame/LocalFrame.h" |
10 #include "core/layout/LayoutObject.h" | 10 #include "core/layout/LayoutObject.h" |
11 | 11 |
12 namespace blink { | 12 namespace blink { |
13 | 13 |
14 MediaValuesCached::MediaValuesCachedData::MediaValuesCachedData(Document& docume nt) | |
15 : MediaValuesCached::MediaValuesCachedData() | |
16 { | |
17 ASSERT(isMainThread()); | |
18 LocalFrame* frame = MediaValues::frameFrom(document); | |
19 // FIXME - Added an assert here so we can better understand when a frame is present without its view(). | |
Yoav Weiss
2016/02/01 09:29:30
I think we can now safely conclude that this doesn
haraken
2016/02/01 11:09:16
FIXME => TODO(hiroshige)
hiroshige
2016/02/06 10:08:44
Done. I'll create another CL.
Is this because Iss
| |
20 ASSERT(!frame || frame->view()); | |
21 if (frame && frame->view()) { | |
22 ASSERT(frame->document() && frame->document()->layoutView()); | |
23 | |
24 // In case that frame is missing (e.g. for images that their document do es not have a frame) | |
25 // We simply leave the MediaValues object with the default MediaValuesCa chedData values. | |
26 viewportWidth = MediaValues::calculateViewportWidth(frame); | |
27 viewportHeight = MediaValues::calculateViewportHeight(frame); | |
28 deviceWidth = MediaValues::calculateDeviceWidth(frame); | |
29 deviceHeight = MediaValues::calculateDeviceHeight(frame); | |
30 devicePixelRatio = MediaValues::calculateDevicePixelRatio(frame); | |
31 colorBitsPerComponent = MediaValues::calculateColorBitsPerComponent(fram e); | |
32 monochromeBitsPerComponent = MediaValues::calculateMonochromeBitsPerComp onent(frame); | |
33 primaryPointerType = MediaValues::calculatePrimaryPointerType(frame); | |
34 availablePointerTypes = MediaValues::calculateAvailablePointerTypes(fram e); | |
35 primaryHoverType = MediaValues::calculatePrimaryHoverType(frame); | |
36 availableHoverTypes = MediaValues::calculateAvailableHoverTypes(frame); | |
37 defaultFontSize = MediaValues::calculateDefaultFontSize(frame); | |
38 threeDEnabled = MediaValues::calculateThreeDEnabled(frame); | |
39 strictMode = MediaValues::calculateStrictMode(frame); | |
40 displayMode = MediaValues::calculateDisplayMode(frame); | |
41 mediaType = MediaValues::calculateMediaType(frame); | |
42 } | |
43 } | |
44 | |
14 PassRefPtrWillBeRawPtr<MediaValuesCached> MediaValuesCached::create() | 45 PassRefPtrWillBeRawPtr<MediaValuesCached> MediaValuesCached::create() |
15 { | 46 { |
16 return adoptRefWillBeNoop(new MediaValuesCached()); | 47 return adoptRefWillBeNoop(new MediaValuesCached()); |
17 } | 48 } |
18 | 49 |
19 PassRefPtrWillBeRawPtr<MediaValuesCached> MediaValuesCached::create(MediaValuesC achedData& data) | 50 PassRefPtrWillBeRawPtr<MediaValuesCached> MediaValuesCached::create(const MediaV aluesCachedData& data) |
20 { | 51 { |
21 return adoptRefWillBeNoop(new MediaValuesCached(data)); | 52 return adoptRefWillBeNoop(new MediaValuesCached(data)); |
22 } | 53 } |
23 | 54 |
24 PassRefPtrWillBeRawPtr<MediaValuesCached> MediaValuesCached::create(Document& do cument) | |
25 { | |
26 return MediaValuesCached::create(frameFrom(document)); | |
27 } | |
28 | |
29 PassRefPtrWillBeRawPtr<MediaValuesCached> MediaValuesCached::create(LocalFrame* frame) | |
30 { | |
31 // FIXME - Added an assert here so we can better understand when a frame is present without its view(). | |
32 ASSERT(!frame || frame->view()); | |
33 if (!frame || !frame->view()) | |
34 return adoptRefWillBeNoop(new MediaValuesCached()); | |
35 ASSERT(frame->document() && frame->document()->layoutView()); | |
36 return adoptRefWillBeNoop(new MediaValuesCached(frame)); | |
37 } | |
38 | |
39 MediaValuesCached::MediaValuesCached() | 55 MediaValuesCached::MediaValuesCached() |
40 { | 56 { |
41 } | 57 } |
42 | 58 |
43 MediaValuesCached::MediaValuesCached(LocalFrame* frame) | |
44 { | |
45 ASSERT(isMainThread()); | |
46 ASSERT(frame); | |
47 // In case that frame is missing (e.g. for images that their document does n ot have a frame) | |
48 // We simply leave the MediaValues object with the default MediaValuesCached Data values. | |
49 m_data.viewportWidth = calculateViewportWidth(frame); | |
50 m_data.viewportHeight = calculateViewportHeight(frame); | |
51 m_data.deviceWidth = calculateDeviceWidth(frame); | |
52 m_data.deviceHeight = calculateDeviceHeight(frame); | |
53 m_data.devicePixelRatio = calculateDevicePixelRatio(frame); | |
54 m_data.colorBitsPerComponent = calculateColorBitsPerComponent(frame); | |
55 m_data.monochromeBitsPerComponent = calculateMonochromeBitsPerComponent(fram e); | |
56 m_data.primaryPointerType = calculatePrimaryPointerType(frame); | |
57 m_data.availablePointerTypes = calculateAvailablePointerTypes(frame); | |
58 m_data.primaryHoverType = calculatePrimaryHoverType(frame); | |
59 m_data.availableHoverTypes = calculateAvailableHoverTypes(frame); | |
60 m_data.defaultFontSize = calculateDefaultFontSize(frame); | |
61 m_data.threeDEnabled = calculateThreeDEnabled(frame); | |
62 m_data.strictMode = calculateStrictMode(frame); | |
63 m_data.displayMode = calculateDisplayMode(frame); | |
64 const String mediaType = calculateMediaType(frame); | |
65 if (!mediaType.isEmpty()) | |
66 m_data.mediaType = mediaType.isolatedCopy(); | |
67 } | |
68 | |
69 MediaValuesCached::MediaValuesCached(const MediaValuesCachedData& data) | 59 MediaValuesCached::MediaValuesCached(const MediaValuesCachedData& data) |
70 : m_data(data) | 60 : m_data(data) |
71 { | 61 { |
72 } | 62 } |
73 | 63 |
74 PassRefPtrWillBeRawPtr<MediaValues> MediaValuesCached::copy() const | 64 PassRefPtrWillBeRawPtr<MediaValues> MediaValuesCached::copy() const |
75 { | 65 { |
76 return adoptRefWillBeNoop(new MediaValuesCached(m_data)); | 66 return adoptRefWillBeNoop(new MediaValuesCached(m_data)); |
77 } | 67 } |
78 | 68 |
79 bool MediaValuesCached::computeLength(double value, CSSPrimitiveValue::UnitType type, int& result) const | 69 bool MediaValuesCached::computeLength(double value, CSSPrimitiveValue::UnitType type, int& result) const |
80 { | 70 { |
81 return MediaValues::computeLength(value, type, m_data.defaultFontSize, m_dat a.viewportWidth, m_data.viewportHeight, result); | 71 return MediaValues::computeLength(value, type, m_data.defaultFontSize, m_dat a.viewportWidth, m_data.viewportHeight, result); |
82 } | 72 } |
83 | 73 |
84 bool MediaValuesCached::computeLength(double value, CSSPrimitiveValue::UnitType type, double& result) const | 74 bool MediaValuesCached::computeLength(double value, CSSPrimitiveValue::UnitType type, double& result) const |
85 { | 75 { |
86 return MediaValues::computeLength(value, type, m_data.defaultFontSize, m_dat a.viewportWidth, m_data.viewportHeight, result); | 76 return MediaValues::computeLength(value, type, m_data.defaultFontSize, m_dat a.viewportWidth, m_data.viewportHeight, result); |
87 } | 77 } |
88 | 78 |
89 bool MediaValuesCached::isSafeToSendToAnotherThread() const | |
90 { | |
91 #if ENABLE(OILPAN) | |
92 // Oilpan objects are safe to send to another thread as long as the thread | |
93 // does not outlive the thread used for creation. MediaValues are | |
94 // allocated on the main thread and may be passed to the parser thread, | |
95 // so this should be safe. | |
96 return true; | |
97 #else | |
98 return hasOneRef(); | |
99 #endif | |
100 } | |
101 | |
102 double MediaValuesCached::viewportWidth() const | 79 double MediaValuesCached::viewportWidth() const |
103 { | 80 { |
104 return m_data.viewportWidth; | 81 return m_data.viewportWidth; |
105 } | 82 } |
106 | 83 |
107 double MediaValuesCached::viewportHeight() const | 84 double MediaValuesCached::viewportHeight() const |
108 { | 85 { |
109 return m_data.viewportHeight; | 86 return m_data.viewportHeight; |
110 } | 87 } |
111 | 88 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
188 { | 165 { |
189 m_data.viewportWidth = width; | 166 m_data.viewportWidth = width; |
190 } | 167 } |
191 | 168 |
192 void MediaValuesCached::setViewportHeight(double height) | 169 void MediaValuesCached::setViewportHeight(double height) |
193 { | 170 { |
194 m_data.viewportHeight = height; | 171 m_data.viewportHeight = height; |
195 } | 172 } |
196 | 173 |
197 } // namespace blink | 174 } // namespace blink |
OLD | NEW |