Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(331)

Side by Side Diff: Source/core/css/MediaValues.cpp

Issue 227043007: CSS Length calculation with MediaValues (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@sizes_parser3
Patch Set: Rebase Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "config.h" 5 #include "config.h"
6 #include "core/css/MediaValues.h" 6 #include "core/css/MediaValues.h"
7 7
8 #include "core/dom/Document.h" 8 #include "core/dom/Document.h"
9 #include "core/dom/Element.h" 9 #include "core/dom/Element.h"
10 #include "core/frame/FrameHost.h" 10 #include "core/frame/FrameHost.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 if (screenIsMonochrome(frame->page()->mainFrame()->view())) 78 if (screenIsMonochrome(frame->page()->mainFrame()->view()))
79 return screenDepthPerComponent(frame->view()); 79 return screenDepthPerComponent(frame->view());
80 return 0; 80 return 0;
81 } 81 }
82 82
83 static int calculateDefaultFontSize(RenderStyle* style) 83 static int calculateDefaultFontSize(RenderStyle* style)
84 { 84 {
85 return style->fontDescription().specifiedSize(); 85 return style->fontDescription().specifiedSize();
86 } 86 }
87 87
88 static int calculateComputedFontSize(RenderStyle* style)
89 {
90 return style->fontDescription().computedSize();
91 }
92
93 static bool calculateHasXHeight(RenderStyle* style)
94 {
95 return style->fontMetrics().hasXHeight();
96 }
97
98 static double calculateXHeight(RenderStyle* style)
99 {
100 return style->fontMetrics().xHeight();
101 }
102
103 static double calculateZeroWidth(RenderStyle* style)
104 {
105 return style->fontMetrics().zeroWidth();
106 }
107
88 static bool calculateScanMediaType(LocalFrame* frame) 108 static bool calculateScanMediaType(LocalFrame* frame)
89 { 109 {
90 ASSERT(frame && frame->view()); 110 ASSERT(frame && frame->view());
91 // Scan only applies to 'tv' media. 111 // Scan only applies to 'tv' media.
92 return equalIgnoringCase(frame->view()->mediaType(), "tv"); 112 return equalIgnoringCase(frame->view()->mediaType(), "tv");
93 } 113 }
94 114
95 static bool calculateScreenMediaType(LocalFrame* frame) 115 static bool calculateScreenMediaType(LocalFrame* frame)
96 { 116 {
97 ASSERT(frame && frame->view()); 117 ASSERT(frame && frame->view());
98 return equalIgnoringCase(frame->view()->mediaType(), "screen"); 118 return equalIgnoringCase(frame->view()->mediaType(), "screen");
99 } 119 }
100 120
101 static bool calculatePrintMediaType(LocalFrame* frame) 121 static bool calculatePrintMediaType(LocalFrame* frame)
102 { 122 {
103 ASSERT(frame && frame->view()); 123 ASSERT(frame && frame->view());
104 return equalIgnoringCase(frame->view()->mediaType(), "print"); 124 return equalIgnoringCase(frame->view()->mediaType(), "print");
105 } 125 }
106 126
107 static bool calculateThreeDEnabled(LocalFrame* frame) 127 static bool calculateThreeDEnabled(LocalFrame* frame)
108 { 128 {
109 ASSERT(frame && frame->contentRenderer() && frame->contentRenderer()->compos itor()); 129 ASSERT(frame && frame->contentRenderer() && frame->contentRenderer()->compos itor());
110 bool threeDEnabled = false; 130 bool threeDEnabled = false;
111 if (RenderView* view = frame->contentRenderer()) 131 if (RenderView* view = frame->contentRenderer())
112 threeDEnabled = view->compositor()->canRender3DTransforms(); 132 threeDEnabled = view->compositor()->canRender3DTransforms();
113 return threeDEnabled; 133 return threeDEnabled;
114 } 134 }
115 135
136 static float calculateEffectiveZoom(RenderStyle* style)
137 {
138 ASSERT(style);
139 return style->effectiveZoom();
140 }
141
116 static MediaValues::PointerDeviceType calculateLeastCapablePrimaryPointerDeviceT ype(LocalFrame* frame) 142 static MediaValues::PointerDeviceType calculateLeastCapablePrimaryPointerDeviceT ype(LocalFrame* frame)
117 { 143 {
118 ASSERT(frame && frame->settings()); 144 ASSERT(frame && frame->settings());
119 if (frame->settings()->deviceSupportsTouch()) 145 if (frame->settings()->deviceSupportsTouch())
120 return MediaValues::TouchPointer; 146 return MediaValues::TouchPointer;
121 147
122 // FIXME: We should also try to determine if we know we have a mouse. 148 // FIXME: We should also try to determine if we know we have a mouse.
123 // When we do this, we'll also need to differentiate between known not to 149 // When we do this, we'll also need to differentiate between known not to
124 // have mouse or touch screen (NoPointer) and unknown (UnknownPointer). 150 // have mouse or touch screen (NoPointer) and unknown (UnknownPointer).
125 // We could also take into account other preferences like accessibility 151 // We could also take into account other preferences like accessibility
126 // settings to decide which of the available pointers should be considered 152 // settings to decide which of the available pointers should be considered
127 // "primary". 153 // "primary".
128 154
129 return MediaValues::UnknownPointer; 155 return MediaValues::UnknownPointer;
130 } 156 }
131 157
132 PassRefPtr<MediaValues> MediaValues::create(MediaValuesMode mode, 158 PassRefPtr<MediaValues> MediaValues::create(MediaValuesMode mode,
133 int viewportWidth, 159 int viewportWidth,
134 int viewportHeight, 160 int viewportHeight,
135 int deviceWidth, 161 int deviceWidth,
136 int deviceHeight, 162 int deviceHeight,
137 float devicePixelRatio, 163 float devicePixelRatio,
138 int colorBitsPerComponent, 164 int colorBitsPerComponent,
139 int monochromeBitsPerComponent, 165 int monochromeBitsPerComponent,
140 PointerDeviceType pointer, 166 PointerDeviceType pointer,
141 int defaultFontSize, 167 int defaultFontSize,
168 int computedFontSize,
169 bool hasXHeight,
170 double xHeight,
171 double zeroWidth,
142 bool threeDEnabled, 172 bool threeDEnabled,
143 bool scanMediaType, 173 bool scanMediaType,
144 bool screenMediaType, 174 bool screenMediaType,
145 bool printMediaType, 175 bool printMediaType,
146 bool strictMode) 176 bool strictMode,
177 float effectiveZoom)
147 { 178 {
148 ASSERT(mode == CachingMode); 179 ASSERT(mode == CachingMode);
149 RefPtr<MediaValues> mediaValues = adoptRef(new MediaValues(0, nullptr, mode) ); 180 RefPtr<MediaValues> mediaValues = adoptRef(new MediaValues(0, nullptr, mode) );
150 mediaValues->m_viewportWidth = viewportWidth; 181 mediaValues->m_viewportWidth = viewportWidth;
151 mediaValues->m_viewportHeight = viewportHeight; 182 mediaValues->m_viewportHeight = viewportHeight;
152 mediaValues->m_deviceWidth = deviceWidth; 183 mediaValues->m_deviceWidth = deviceWidth;
153 mediaValues->m_deviceHeight = deviceHeight; 184 mediaValues->m_deviceHeight = deviceHeight;
154 mediaValues->m_devicePixelRatio = devicePixelRatio; 185 mediaValues->m_devicePixelRatio = devicePixelRatio;
155 mediaValues->m_colorBitsPerComponent = colorBitsPerComponent; 186 mediaValues->m_colorBitsPerComponent = colorBitsPerComponent;
156 mediaValues->m_monochromeBitsPerComponent = monochromeBitsPerComponent; 187 mediaValues->m_monochromeBitsPerComponent = monochromeBitsPerComponent;
157 mediaValues->m_pointer = pointer; 188 mediaValues->m_pointer = pointer;
158 mediaValues->m_defaultFontSize = defaultFontSize; 189 mediaValues->m_defaultFontSize = defaultFontSize;
190 mediaValues->m_computedFontSize = computedFontSize;
191 mediaValues->m_hasXHeight = hasXHeight;
192 mediaValues->m_xHeight = xHeight;
193 mediaValues->m_zeroWidth = zeroWidth;
159 mediaValues->m_threeDEnabled = threeDEnabled; 194 mediaValues->m_threeDEnabled = threeDEnabled;
160 mediaValues->m_scanMediaType = scanMediaType; 195 mediaValues->m_scanMediaType = scanMediaType;
161 mediaValues->m_screenMediaType = screenMediaType; 196 mediaValues->m_screenMediaType = screenMediaType;
162 mediaValues->m_printMediaType = printMediaType; 197 mediaValues->m_printMediaType = printMediaType;
163 mediaValues->m_strictMode = strictMode; 198 mediaValues->m_strictMode = strictMode;
199 mediaValues->m_effectiveZoom = effectiveZoom;
164 200
165 return mediaValues; 201 return mediaValues;
166 } 202 }
167 203
168 PassRefPtr<MediaValues> MediaValues::create(LocalFrame* frame, RenderStyle* styl e, MediaValuesMode mode) 204 PassRefPtr<MediaValues> MediaValues::create(LocalFrame* frame, RenderStyle* styl e, MediaValuesMode mode)
169 { 205 {
170 ASSERT(frame && style); 206 ASSERT(frame && style);
171 RefPtr<MediaValues> mediaValues; 207 RefPtr<MediaValues> mediaValues;
172 mediaValues = adoptRef(new MediaValues(frame, style, mode)); 208 mediaValues = adoptRef(new MediaValues(frame, style, mode));
173 if (mode == CachingMode) { 209 if (mode == CachingMode) {
174 mediaValues->m_viewportWidth = calculateViewportWidth(frame, style); 210 mediaValues->m_viewportWidth = calculateViewportWidth(frame, style);
175 mediaValues->m_viewportHeight = calculateViewportHeight(frame, style), 211 mediaValues->m_viewportHeight = calculateViewportHeight(frame, style);
176 mediaValues->m_deviceWidth = calculateDeviceWidth(frame), 212 mediaValues->m_deviceWidth = calculateDeviceWidth(frame);
177 mediaValues->m_deviceHeight = calculateDeviceHeight(frame), 213 mediaValues->m_deviceHeight = calculateDeviceHeight(frame);
178 mediaValues->m_devicePixelRatio = calculateDevicePixelRatio(frame), 214 mediaValues->m_devicePixelRatio = calculateDevicePixelRatio(frame);
179 mediaValues->m_colorBitsPerComponent = calculateColorBitsPerComponent(fr ame), 215 mediaValues->m_colorBitsPerComponent = calculateColorBitsPerComponent(fr ame);
180 mediaValues->m_monochromeBitsPerComponent = calculateMonochromeBitsPerCo mponent(frame), 216 mediaValues->m_monochromeBitsPerComponent = calculateMonochromeBitsPerCo mponent(frame);
181 mediaValues->m_pointer = calculateLeastCapablePrimaryPointerDeviceType(f rame), 217 mediaValues->m_pointer = calculateLeastCapablePrimaryPointerDeviceType(f rame);
182 mediaValues->m_defaultFontSize = calculateDefaultFontSize(style), 218 mediaValues->m_defaultFontSize = calculateDefaultFontSize(style);
183 mediaValues->m_threeDEnabled = calculateThreeDEnabled(frame), 219 mediaValues->m_computedFontSize = calculateComputedFontSize(style);
184 mediaValues->m_scanMediaType = calculateScanMediaType(frame), 220 mediaValues->m_hasXHeight = calculateHasXHeight(style);
185 mediaValues->m_screenMediaType = calculateScreenMediaType(frame), 221 mediaValues->m_xHeight = calculateXHeight(style);
186 mediaValues->m_printMediaType = calculatePrintMediaType(frame), 222 mediaValues->m_zeroWidth = calculateZeroWidth(style);
223 mediaValues->m_threeDEnabled = calculateThreeDEnabled(frame);
224 mediaValues->m_scanMediaType = calculateScanMediaType(frame);
225 mediaValues->m_screenMediaType = calculateScreenMediaType(frame);
226 mediaValues->m_printMediaType = calculatePrintMediaType(frame);
187 mediaValues->m_strictMode = calculateStrictMode(frame); 227 mediaValues->m_strictMode = calculateStrictMode(frame);
228 mediaValues->m_effectiveZoom = calculateEffectiveZoom(style);
188 229
189 mediaValues->m_style.clear(); 230 mediaValues->m_style.clear();
190 mediaValues->m_frame = 0; 231 mediaValues->m_frame = 0;
191 } 232 }
192 233
193 return mediaValues; 234 return mediaValues;
194 } 235 }
195 236
196 PassRefPtr<MediaValues> MediaValues::create(Document* document, MediaValuesMode mode) 237 PassRefPtr<MediaValues> MediaValues::create(const Document& document, MediaValue sMode mode)
197 { 238 {
198 ASSERT(document); 239 const Document* executingDocument = document.import() ? document.import()->m aster() : &document;
199 Document* executingDocument = document->import() ? document->import()->maste r() : document;
200 ASSERT(executingDocument->frame()); 240 ASSERT(executingDocument->frame());
201 ASSERT(executingDocument->renderer()); 241 ASSERT(executingDocument->renderer());
202 ASSERT(executingDocument->renderer()->style()); 242 ASSERT(executingDocument->renderer()->style());
203 LocalFrame* frame = executingDocument->frame(); 243 LocalFrame* frame = executingDocument->frame();
204 RenderStyle* style = executingDocument->renderer()->style(); 244 RenderStyle* style = executingDocument->renderer()->style();
205 245
206 return MediaValues::create(frame, style, mode); 246 return MediaValues::create(frame, style, mode);
207 } 247 }
208 248
209 PassRefPtr<MediaValues> MediaValues::copy() const 249 PassRefPtr<MediaValues> MediaValues::copy() const
210 { 250 {
211 ASSERT(m_mode == CachingMode && !m_style.get() && !m_frame); 251 ASSERT(m_mode == CachingMode && !m_style.get() && !m_frame);
212 RefPtr<MediaValues> mediaValues = adoptRef(new MediaValues(0, nullptr, m_mod e)); 252 RefPtr<MediaValues> mediaValues = adoptRef(new MediaValues(0, nullptr, m_mod e));
213 mediaValues->m_viewportWidth = m_viewportWidth; 253 mediaValues->m_viewportWidth = m_viewportWidth;
214 mediaValues->m_viewportHeight = m_viewportHeight; 254 mediaValues->m_viewportHeight = m_viewportHeight;
215 mediaValues->m_deviceWidth = m_deviceWidth; 255 mediaValues->m_deviceWidth = m_deviceWidth;
216 mediaValues->m_deviceHeight = m_deviceHeight; 256 mediaValues->m_deviceHeight = m_deviceHeight;
217 mediaValues->m_devicePixelRatio = m_devicePixelRatio; 257 mediaValues->m_devicePixelRatio = m_devicePixelRatio;
218 mediaValues->m_colorBitsPerComponent = m_colorBitsPerComponent; 258 mediaValues->m_colorBitsPerComponent = m_colorBitsPerComponent;
219 mediaValues->m_monochromeBitsPerComponent = m_monochromeBitsPerComponent; 259 mediaValues->m_monochromeBitsPerComponent = m_monochromeBitsPerComponent;
220 mediaValues->m_pointer = m_pointer; 260 mediaValues->m_pointer = m_pointer;
221 mediaValues->m_defaultFontSize = m_defaultFontSize; 261 mediaValues->m_defaultFontSize = m_defaultFontSize;
262 mediaValues->m_computedFontSize = m_computedFontSize;
263 mediaValues->m_hasXHeight = m_hasXHeight;
264 mediaValues->m_xHeight = m_xHeight;
265 mediaValues->m_zeroWidth = m_zeroWidth;
222 mediaValues->m_threeDEnabled = m_threeDEnabled; 266 mediaValues->m_threeDEnabled = m_threeDEnabled;
223 mediaValues->m_scanMediaType = m_scanMediaType; 267 mediaValues->m_scanMediaType = m_scanMediaType;
224 mediaValues->m_screenMediaType = m_screenMediaType; 268 mediaValues->m_screenMediaType = m_screenMediaType;
225 mediaValues->m_printMediaType = m_printMediaType; 269 mediaValues->m_printMediaType = m_printMediaType;
226 mediaValues->m_strictMode = m_strictMode; 270 mediaValues->m_strictMode = m_strictMode;
271 mediaValues->m_effectiveZoom = m_effectiveZoom;
227 272
228 return mediaValues; 273 return mediaValues;
229 } 274 }
230 275
231 bool MediaValues::isSafeToSendToAnotherThread() const 276 bool MediaValues::isSafeToSendToAnotherThread() const
232 { 277 {
233 return (!m_frame && !m_style && m_mode == CachingMode && hasOneRef()); 278 return (!m_frame && !m_style && m_mode == CachingMode && hasOneRef());
234 } 279 }
235 280
236 int MediaValues::viewportWidth() const 281 int MediaValues::viewportWidth() const
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 return m_pointer; 334 return m_pointer;
290 } 335 }
291 336
292 int MediaValues::defaultFontSize() const 337 int MediaValues::defaultFontSize() const
293 { 338 {
294 if (m_mode == DynamicMode) 339 if (m_mode == DynamicMode)
295 return calculateDefaultFontSize(m_style.get()); 340 return calculateDefaultFontSize(m_style.get());
296 return m_defaultFontSize; 341 return m_defaultFontSize;
297 } 342 }
298 343
344 int MediaValues::computedFontSize() const
345 {
346 if (m_mode == DynamicMode)
347 return calculateComputedFontSize(m_style.get());
348 return m_computedFontSize;
349 }
350
351 bool MediaValues::hasXHeight() const
352 {
353 if (m_mode == DynamicMode)
esprehn 2014/04/08 17:40:39 What is DynamicMode? You should use two difference
354 return calculateHasXHeight(m_style.get());
355 return m_hasXHeight;
356 }
357
358 double MediaValues::xHeight() const
359 {
360 if (m_mode == DynamicMode)
eseidel 2014/04/08 16:51:28 I don't understand caching vs. dynamic mode. Why
361 return calculateXHeight(m_style.get());
362 return m_xHeight;
363 }
364
365 double MediaValues::zeroWidth() const
366 {
367 if (m_mode == DynamicMode)
368 return calculateZeroWidth(m_style.get());
369 return m_zeroWidth;
370 }
371
299 bool MediaValues::threeDEnabled() const 372 bool MediaValues::threeDEnabled() const
300 { 373 {
301 if (m_mode == DynamicMode) 374 if (m_mode == DynamicMode)
302 return calculateThreeDEnabled(m_frame); 375 return calculateThreeDEnabled(m_frame);
303 return m_threeDEnabled; 376 return m_threeDEnabled;
304 } 377 }
305 378
306 bool MediaValues::scanMediaType() const 379 bool MediaValues::scanMediaType() const
307 { 380 {
308 if (m_mode == DynamicMode) 381 if (m_mode == DynamicMode)
(...skipping 15 matching lines...) Expand all
324 return m_printMediaType; 397 return m_printMediaType;
325 } 398 }
326 399
327 bool MediaValues::strictMode() const 400 bool MediaValues::strictMode() const
328 { 401 {
329 if (m_mode == DynamicMode) 402 if (m_mode == DynamicMode)
330 return calculateStrictMode(m_frame); 403 return calculateStrictMode(m_frame);
331 return m_strictMode; 404 return m_strictMode;
332 } 405 }
333 406
407 float MediaValues::effectiveZoom() const
408 {
409 if (m_mode == DynamicMode)
410 return calculateEffectiveZoom(m_style.get());
411 return m_effectiveZoom;
412 }
413
334 Document* MediaValues::document() const 414 Document* MediaValues::document() const
335 { 415 {
336 if (!m_frame) 416 if (!m_frame)
337 return 0; 417 return 0;
338 return m_frame->document(); 418 return m_frame->document();
339 } 419 }
340 420
341 } // namespace 421 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698