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