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/MediaValues.h" | 5 #include "core/css/MediaValues.h" |
6 | 6 |
7 #include "core/css/CSSHelper.h" | 7 #include "core/css/CSSHelper.h" |
8 #include "core/css/MediaValuesCached.h" | 8 #include "core/css/MediaValuesCached.h" |
9 #include "core/css/MediaValuesDynamic.h" | 9 #include "core/css/MediaValuesDynamic.h" |
10 #include "core/dom/Document.h" | 10 #include "core/dom/Document.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 | 24 |
25 namespace blink { | 25 namespace blink { |
26 | 26 |
27 PassRefPtrWillBeRawPtr<MediaValues> MediaValues::createDynamicIfFrameExists(Loca
lFrame* frame) | 27 PassRefPtrWillBeRawPtr<MediaValues> MediaValues::createDynamicIfFrameExists(Loca
lFrame* frame) |
28 { | 28 { |
29 if (frame) | 29 if (frame) |
30 return MediaValuesDynamic::create(frame); | 30 return MediaValuesDynamic::create(frame); |
31 return MediaValuesCached::create(); | 31 return MediaValuesCached::create(); |
32 } | 32 } |
33 | 33 |
34 double MediaValues::calculateViewportWidth(LocalFrame* frame) | 34 double MediaValues::calculateViewportWidth(LocalFrame* frame) const |
35 { | 35 { |
36 ASSERT(frame && frame->view() && frame->document()); | 36 ASSERT(frame && frame->view() && frame->document()); |
37 int viewportWidth = frame->view()->layoutSize(IncludeScrollbars).width(); | 37 int viewportWidth = frame->view()->layoutSize(IncludeScrollbars).width(); |
38 return adjustDoubleForAbsoluteZoom(viewportWidth, *frame->document()->layout
View()); | 38 return adjustDoubleForAbsoluteZoom(viewportWidth, *frame->document()->layout
View()); |
39 } | 39 } |
40 | 40 |
41 double MediaValues::calculateViewportHeight(LocalFrame* frame) | 41 double MediaValues::calculateViewportHeight(LocalFrame* frame) const |
42 { | 42 { |
43 ASSERT(frame && frame->view() && frame->document()); | 43 ASSERT(frame && frame->view() && frame->document()); |
44 int viewportHeight = frame->view()->layoutSize(IncludeScrollbars).height(); | 44 int viewportHeight = frame->view()->layoutSize(IncludeScrollbars).height(); |
45 return adjustDoubleForAbsoluteZoom(viewportHeight, *frame->document()->layou
tView()); | 45 return adjustDoubleForAbsoluteZoom(viewportHeight, *frame->document()->layou
tView()); |
46 } | 46 } |
47 | 47 |
48 int MediaValues::calculateDeviceWidth(LocalFrame* frame) | 48 int MediaValues::calculateDeviceWidth(LocalFrame* frame) const |
49 { | 49 { |
50 ASSERT(frame && frame->view() && frame->settings() && frame->host()); | 50 ASSERT(frame && frame->view() && frame->settings() && frame->host()); |
51 int deviceWidth = frame->host()->chromeClient().screenInfo().rect.width; | 51 int deviceWidth = frame->host()->chromeClient().screenInfo().rect.width; |
52 if (frame->settings()->reportScreenSizeInPhysicalPixelsQuirk()) | 52 if (frame->settings()->reportScreenSizeInPhysicalPixelsQuirk()) |
53 deviceWidth = lroundf(deviceWidth * frame->host()->deviceScaleFactor()); | 53 deviceWidth = lroundf(deviceWidth * frame->host()->deviceScaleFactor()); |
54 return deviceWidth; | 54 return deviceWidth; |
55 } | 55 } |
56 | 56 |
57 int MediaValues::calculateDeviceHeight(LocalFrame* frame) | 57 int MediaValues::calculateDeviceHeight(LocalFrame* frame) const |
58 { | 58 { |
59 ASSERT(frame && frame->view() && frame->settings() && frame->host()); | 59 ASSERT(frame && frame->view() && frame->settings() && frame->host()); |
60 int deviceHeight = frame->host()->chromeClient().screenInfo().rect.height; | 60 int deviceHeight = frame->host()->chromeClient().screenInfo().rect.height; |
61 if (frame->settings()->reportScreenSizeInPhysicalPixelsQuirk()) | 61 if (frame->settings()->reportScreenSizeInPhysicalPixelsQuirk()) |
62 deviceHeight = lroundf(deviceHeight * frame->host()->deviceScaleFactor()
); | 62 deviceHeight = lroundf(deviceHeight * frame->host()->deviceScaleFactor()
); |
63 return deviceHeight; | 63 return deviceHeight; |
64 } | 64 } |
65 | 65 |
66 bool MediaValues::calculateStrictMode(LocalFrame* frame) | 66 bool MediaValues::calculateStrictMode(LocalFrame* frame) const |
67 { | 67 { |
68 ASSERT(frame && frame->document()); | 68 ASSERT(frame && frame->document()); |
69 return !frame->document()->inQuirksMode(); | 69 return !frame->document()->inQuirksMode(); |
70 } | 70 } |
71 | 71 |
72 float MediaValues::calculateDevicePixelRatio(LocalFrame* frame) | 72 float MediaValues::calculateDevicePixelRatio(LocalFrame* frame) const |
73 { | 73 { |
74 return frame->devicePixelRatio(); | 74 return frame->devicePixelRatio(); |
75 } | 75 } |
76 | 76 |
77 int MediaValues::calculateColorBitsPerComponent(LocalFrame* frame) | 77 int MediaValues::calculateColorBitsPerComponent(LocalFrame* frame) const |
78 { | 78 { |
79 ASSERT(frame && frame->page() && frame->page()->mainFrame()); | 79 ASSERT(frame && frame->page() && frame->page()->mainFrame()); |
80 if (!frame->page()->mainFrame()->isLocalFrame() | 80 if (!frame->page()->mainFrame()->isLocalFrame() |
81 || frame->host()->chromeClient().screenInfo().isMonochrome) | 81 || frame->host()->chromeClient().screenInfo().isMonochrome) |
82 return 0; | 82 return 0; |
83 return frame->host()->chromeClient().screenInfo().depthPerComponent; | 83 return frame->host()->chromeClient().screenInfo().depthPerComponent; |
84 } | 84 } |
85 | 85 |
86 int MediaValues::calculateMonochromeBitsPerComponent(LocalFrame* frame) | 86 int MediaValues::calculateMonochromeBitsPerComponent(LocalFrame* frame) const |
87 { | 87 { |
88 ASSERT(frame && frame->page() && frame->page()->mainFrame()); | 88 ASSERT(frame && frame->page() && frame->page()->mainFrame()); |
89 if (!frame->page()->mainFrame()->isLocalFrame() | 89 if (!frame->page()->mainFrame()->isLocalFrame() |
90 || !frame->host()->chromeClient().screenInfo().isMonochrome) | 90 || !frame->host()->chromeClient().screenInfo().isMonochrome) |
91 return 0; | 91 return 0; |
92 return frame->host()->chromeClient().screenInfo().depthPerComponent; | 92 return frame->host()->chromeClient().screenInfo().depthPerComponent; |
93 } | 93 } |
94 | 94 |
95 int MediaValues::calculateDefaultFontSize(LocalFrame* frame) | 95 int MediaValues::calculateDefaultFontSize(LocalFrame* frame) const |
96 { | 96 { |
97 return frame->host()->settings().defaultFontSize(); | 97 return frame->host()->settings().defaultFontSize(); |
98 } | 98 } |
99 | 99 |
100 const String MediaValues::calculateMediaType(LocalFrame* frame) | 100 const String MediaValues::calculateMediaType(LocalFrame* frame) const |
101 { | 101 { |
102 ASSERT(frame); | 102 ASSERT(frame); |
103 if (!frame->view()) | 103 if (!frame->view()) |
104 return emptyAtom; | 104 return emptyAtom; |
105 return frame->view()->mediaType(); | 105 return frame->view()->mediaType(); |
106 } | 106 } |
107 | 107 |
108 WebDisplayMode MediaValues::calculateDisplayMode(LocalFrame* frame) | 108 WebDisplayMode MediaValues::calculateDisplayMode(LocalFrame* frame) const |
109 { | 109 { |
110 ASSERT(frame); | 110 ASSERT(frame); |
111 WebDisplayMode mode = frame->host()->settings().displayModeOverride(); | 111 WebDisplayMode mode = frame->host()->settings().displayModeOverride(); |
112 | 112 |
113 if (mode != WebDisplayModeUndefined) | 113 if (mode != WebDisplayModeUndefined) |
114 return mode; | 114 return mode; |
115 | 115 |
116 if (!frame->view()) | 116 if (!frame->view()) |
117 return WebDisplayModeBrowser; | 117 return WebDisplayModeBrowser; |
118 | 118 |
119 return frame->view()->displayMode(); | 119 return frame->view()->displayMode(); |
120 } | 120 } |
121 | 121 |
122 bool MediaValues::calculateThreeDEnabled(LocalFrame* frame) | 122 bool MediaValues::calculateThreeDEnabled(LocalFrame* frame) const |
123 { | 123 { |
124 ASSERT(frame && frame->contentLayoutObject() && frame->contentLayoutObject()
->compositor()); | 124 ASSERT(frame && frame->contentLayoutObject() && frame->contentLayoutObject()
->compositor()); |
125 bool threeDEnabled = false; | 125 bool threeDEnabled = false; |
126 if (LayoutView* view = frame->contentLayoutObject()) | 126 if (LayoutView* view = frame->contentLayoutObject()) |
127 threeDEnabled = view->compositor()->hasAcceleratedCompositing(); | 127 threeDEnabled = view->compositor()->hasAcceleratedCompositing(); |
128 return threeDEnabled; | 128 return threeDEnabled; |
129 } | 129 } |
130 | 130 |
131 PointerType MediaValues::calculatePrimaryPointerType(LocalFrame* frame) | 131 PointerType MediaValues::calculatePrimaryPointerType(LocalFrame* frame) const |
132 { | 132 { |
133 ASSERT(frame && frame->settings()); | 133 ASSERT(frame && frame->settings()); |
134 return frame->settings()->primaryPointerType(); | 134 return frame->settings()->primaryPointerType(); |
135 } | 135 } |
136 | 136 |
137 int MediaValues::calculateAvailablePointerTypes(LocalFrame* frame) | 137 int MediaValues::calculateAvailablePointerTypes(LocalFrame* frame) const |
138 { | 138 { |
139 ASSERT(frame && frame->settings()); | 139 ASSERT(frame && frame->settings()); |
140 return frame->settings()->availablePointerTypes(); | 140 return frame->settings()->availablePointerTypes(); |
141 } | 141 } |
142 | 142 |
143 HoverType MediaValues::calculatePrimaryHoverType(LocalFrame* frame) | 143 HoverType MediaValues::calculatePrimaryHoverType(LocalFrame* frame) const |
144 { | 144 { |
145 ASSERT(frame && frame->settings()); | 145 ASSERT(frame && frame->settings()); |
146 return frame->settings()->primaryHoverType(); | 146 return frame->settings()->primaryHoverType(); |
147 } | 147 } |
148 | 148 |
149 int MediaValues::calculateAvailableHoverTypes(LocalFrame* frame) | 149 int MediaValues::calculateAvailableHoverTypes(LocalFrame* frame) const |
150 { | 150 { |
151 ASSERT(frame && frame->settings()); | 151 ASSERT(frame && frame->settings()); |
152 return frame->settings()->availableHoverTypes(); | 152 return frame->settings()->availableHoverTypes(); |
153 } | 153 } |
154 | 154 |
155 bool MediaValues::computeLengthImpl(double value, CSSPrimitiveValue::UnitType ty
pe, unsigned defaultFontSize, double viewportWidth, double viewportHeight, doubl
e& result) | 155 bool MediaValues::computeLengthImpl(double value, CSSPrimitiveValue::UnitType ty
pe, unsigned defaultFontSize, double viewportWidth, double viewportHeight, doubl
e& result) |
156 { | 156 { |
157 // The logic in this function is duplicated from CSSToLengthConversionData::
zoomedComputedPixels() | 157 // The logic in this function is duplicated from CSSToLengthConversionData::
zoomedComputedPixels() |
158 // because MediaValues::computeLength() needs nearly identical logic, but we
haven't found a way to make | 158 // because MediaValues::computeLength() needs nearly identical logic, but we
haven't found a way to make |
159 // CSSToLengthConversionData::zoomedComputedPixels() more generic (to solve
both cases) without hurting performance. | 159 // CSSToLengthConversionData::zoomedComputedPixels() more generic (to solve
both cases) without hurting performance. |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 } | 217 } |
218 | 218 |
219 LocalFrame* MediaValues::frameFrom(Document& document) | 219 LocalFrame* MediaValues::frameFrom(Document& document) |
220 { | 220 { |
221 Document* executingDocument = document.importsController() ? document.import
sController()->master() : &document; | 221 Document* executingDocument = document.importsController() ? document.import
sController()->master() : &document; |
222 ASSERT(executingDocument); | 222 ASSERT(executingDocument); |
223 return executingDocument->frame(); | 223 return executingDocument->frame(); |
224 } | 224 } |
225 | 225 |
226 } // namespace blink | 226 } // namespace blink |
OLD | NEW |