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

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

Issue 242883002: Remove MediaValues' dependency on RenderStyle (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Modified minimal recalc tests to represent reduced recalc. 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/css/CSSHelper.h"
8 #include "core/css/MediaValuesCached.h" 9 #include "core/css/MediaValuesCached.h"
9 #include "core/css/MediaValuesDynamic.h" 10 #include "core/css/MediaValuesDynamic.h"
10 #include "core/dom/Document.h" 11 #include "core/dom/Document.h"
11 #include "core/dom/Element.h" 12 #include "core/dom/Element.h"
12 #include "core/frame/FrameHost.h" 13 #include "core/frame/FrameHost.h"
13 #include "core/frame/FrameView.h" 14 #include "core/frame/FrameView.h"
14 #include "core/frame/LocalFrame.h" 15 #include "core/frame/LocalFrame.h"
15 #include "core/frame/Settings.h" 16 #include "core/frame/Settings.h"
16 #include "core/html/imports/HTMLImportsController.h"
17 #include "core/page/Page.h" 17 #include "core/page/Page.h"
18 #include "core/rendering/RenderObject.h" 18 #include "core/rendering/RenderObject.h"
19 #include "core/rendering/RenderView.h" 19 #include "core/rendering/RenderView.h"
20 #include "core/rendering/compositing/RenderLayerCompositor.h" 20 #include "core/rendering/compositing/RenderLayerCompositor.h"
21 #include "core/rendering/style/RenderStyle.h" 21 #include "core/rendering/style/RenderStyle.h"
22 #include "platform/PlatformScreen.h" 22 #include "platform/PlatformScreen.h"
23 23
24 namespace WebCore { 24 namespace WebCore {
25 25
26 Document* MediaValues::getExecutingDocument(Document& document) 26 PassRefPtr<MediaValues> MediaValues::createDynamicIfFrameExists(LocalFrame* fram e)
27 { 27 {
28 Document* executingDocument = document.importsController() ? document.import sController()->master() : &document; 28 if (frame)
29 ASSERT(executingDocument); 29 return MediaValuesDynamic::create(frame);
30 ASSERT(executingDocument->renderer()); 30 return MediaValuesCached::create();
31 return executingDocument;
32 } 31 }
33 32
34 int MediaValues::calculateViewportWidth(LocalFrame* frame) const 33 int MediaValues::calculateViewportWidth(LocalFrame* frame) const
35 { 34 {
36 ASSERT(frame && frame->view() && frame->document()); 35 ASSERT(frame && frame->view() && frame->document());
37 int viewportWidth = frame->view()->layoutSize(IncludeScrollbars).width(); 36 int viewportWidth = frame->view()->layoutSize(IncludeScrollbars).width();
38 return adjustForAbsoluteZoom(viewportWidth, frame->document()->renderView()) ; 37 return adjustForAbsoluteZoom(viewportWidth, frame->document()->renderView()) ;
39 } 38 }
40 39
41 int MediaValues::calculateViewportHeight(LocalFrame* frame) const 40 int MediaValues::calculateViewportHeight(LocalFrame* frame) const
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 } 82 }
84 83
85 int MediaValues::calculateMonochromeBitsPerComponent(LocalFrame* frame) const 84 int MediaValues::calculateMonochromeBitsPerComponent(LocalFrame* frame) const
86 { 85 {
87 ASSERT(frame && frame->page() && frame->page()->mainFrame()); 86 ASSERT(frame && frame->page() && frame->page()->mainFrame());
88 if (screenIsMonochrome(frame->page()->mainFrame()->view())) 87 if (screenIsMonochrome(frame->page()->mainFrame()->view()))
89 return screenDepthPerComponent(frame->view()); 88 return screenDepthPerComponent(frame->view());
90 return 0; 89 return 0;
91 } 90 }
92 91
93 int MediaValues::calculateDefaultFontSize(RenderStyle* style) const 92 int MediaValues::calculateDefaultFontSize(LocalFrame* frame) const
94 { 93 {
95 return style->fontDescription().specifiedSize(); 94 return frame->host()->settings().defaultFontSize();
96 }
97
98 int MediaValues::calculateComputedFontSize(RenderStyle* style) const
99 {
100 return style->fontDescription().computedSize();
101 } 95 }
102 96
103 bool MediaValues::calculateScanMediaType(LocalFrame* frame) const 97 bool MediaValues::calculateScanMediaType(LocalFrame* frame) const
104 { 98 {
105 ASSERT(frame && frame->view()); 99 ASSERT(frame && frame->view());
106 // Scan only applies to 'tv' media. 100 // Scan only applies to 'tv' media.
107 return equalIgnoringCase(frame->view()->mediaType(), "tv"); 101 return equalIgnoringCase(frame->view()->mediaType(), "tv");
108 } 102 }
109 103
110 bool MediaValues::calculateScreenMediaType(LocalFrame* frame) const 104 bool MediaValues::calculateScreenMediaType(LocalFrame* frame) const
(...skipping 26 matching lines...) Expand all
137 // FIXME: We should also try to determine if we know we have a mouse. 131 // FIXME: We should also try to determine if we know we have a mouse.
138 // When we do this, we'll also need to differentiate between known not to 132 // When we do this, we'll also need to differentiate between known not to
139 // have mouse or touch screen (NoPointer) and unknown (UnknownPointer). 133 // have mouse or touch screen (NoPointer) and unknown (UnknownPointer).
140 // We could also take into account other preferences like accessibility 134 // We could also take into account other preferences like accessibility
141 // settings to decide which of the available pointers should be considered 135 // settings to decide which of the available pointers should be considered
142 // "primary". 136 // "primary".
143 137
144 return MediaValues::UnknownPointer; 138 return MediaValues::UnknownPointer;
145 } 139 }
146 140
141 bool MediaValues::computeLength(double value, unsigned short type, unsigned defa ultFontSize, unsigned viewportWidth, unsigned viewportHeight, int& result)
142 {
143 // The logic in this function is duplicated from CSSPrimitiveValue::computeL engthDouble
144 // because MediaValues::computeLength needs nearly identical logic, but we h aven't found a way to make
145 // CSSPrimitiveValue::computeLengthDouble more generic (to solve both cases) without hurting performance.
146
147 // FIXME - Unite the logic here with CSSPrimitiveValue in a performant way.
148 int factor = 0;
149 switch (type) {
150 case CSSPrimitiveValue::CSS_EMS:
151 case CSSPrimitiveValue::CSS_REMS:
152 factor = defaultFontSize;
153 break;
154 case CSSPrimitiveValue::CSS_PX:
155 factor = 1;
156 break;
157 case CSSPrimitiveValue::CSS_EXS:
158 // FIXME: We have a bug right now where the zoom will be applied twice t o EX units.
159 // FIXME: We don't seem to be able to cache fontMetrics related values.
160 // Trying to access them is triggering some sort of microtask. Serving t he spec's default instead.
161 factor = defaultFontSize / 2.0;
162 break;
163 case CSSPrimitiveValue::CSS_CHS:
164 // FIXME: We don't seem to be able to cache fontMetrics related values.
165 // Trying to access them is triggering some sort of microtask. Serving t he (future) spec default instead.
166 factor = defaultFontSize / 2.0;
167 break;
168 case CSSPrimitiveValue::CSS_VW:
169 factor = viewportWidth / 100;
170 break;
171 case CSSPrimitiveValue::CSS_VH:
172 factor = viewportHeight / 100;
173 break;
174 case CSSPrimitiveValue::CSS_VMIN:
175 factor = std::min(viewportWidth, viewportHeight) / 100;
176 break;
177 case CSSPrimitiveValue::CSS_VMAX:
178 factor = std::max(viewportWidth, viewportHeight) / 100;
179 break;
180 case CSSPrimitiveValue::CSS_CM:
181 factor = cssPixelsPerCentimeter;
182 break;
183 case CSSPrimitiveValue::CSS_MM:
184 factor = cssPixelsPerMillimeter;
185 break;
186 case CSSPrimitiveValue::CSS_IN:
187 factor = cssPixelsPerInch;
188 break;
189 case CSSPrimitiveValue::CSS_PT:
190 factor = cssPixelsPerPoint;
191 break;
192 case CSSPrimitiveValue::CSS_PC:
193 factor = cssPixelsPerPica;
194 break;
195 default:
196 return false;
197 }
198
199 ASSERT(factor > 0);
200 result = roundForImpreciseConversion<int>(value*factor);
201 return true;
202 }
203
147 } // namespace 204 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698