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

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

Issue 705783002: Decouple font unit conversion in computeLengthDouble from RenderStyle. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 1 month 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 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 18 matching lines...) Expand all
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "core/css/CSSToLengthConversionData.h" 32 #include "core/css/CSSToLengthConversionData.h"
33 33
34 #include "core/rendering/RenderView.h" 34 #include "core/rendering/RenderView.h"
35 #include "core/rendering/style/RenderStyle.h" 35 #include "core/rendering/style/RenderStyle.h"
36 36
37 namespace blink { 37 namespace blink {
38 38
39 CSSToLengthConversionData::CSSToLengthConversionData(const RenderStyle* style, c onst RenderStyle* rootStyle, const RenderView* renderView, float zoom, bool comp utingFontSize) 39 CSSToLengthFontSizes::CSSToLengthFontSizes(float em, float rem, const Font* font )
40 : m_em(em)
41 , m_rem(rem)
42 , m_font(font)
43 {
44 // FIXME: Improve RAII of StyleResolverState to use const Font&.
45 ASSERT(m_font);
46 }
47
48 CSSToLengthFontSizes::CSSToLengthFontSizes(const RenderStyle* style, const Rende rStyle* rootStyle)
49 : CSSToLengthFontSizes(style->computedFontSize(), rootStyle ? rootStyle->com putedFontSize() : 1.0f, &style->font())
Timothy Loh 2014/11/06 16:24:00 I think we should always have a root style? https
andersr 2014/11/07 10:43:11 Done.
andersr 2014/11/10 11:49:57 Looks like we don't always have it. Let's fix that
50 {
51 }
52
53 float CSSToLengthFontSizes::ex() const
54 {
55 ASSERT(m_font);
56 // FIXME: We have a bug right now where the zoom will be applied twice to EX units.
57 // We really need to compute EX using fontMetrics for the original specified Size and not use
58 // our actual constructed rendering font.
59 if (!m_font->fontMetrics().hasXHeight())
60 return m_em / 2.0f;
61 return m_font->fontMetrics().xHeight();
62 }
63
64 float CSSToLengthFontSizes::ch() const
65 {
66 ASSERT(m_font);
67 return m_font->fontMetrics().zeroWidth();
68 }
69
70 CSSToLengthViewportSize::CSSToLengthViewportSize(const RenderView* renderView)
71 : m_width(renderView ? renderView->layoutViewportWidth() : 0)
72 , m_height(renderView ? renderView->layoutViewportHeight() : 0)
73 {
74 }
75
76 CSSToLengthConversionData::CSSToLengthConversionData(const RenderStyle* style, c onst CSSToLengthFontSizes& fontSizes, const CSSToLengthViewportSize& viewportSiz e, float zoom)
40 : m_style(style) 77 : m_style(style)
41 , m_rootStyle(rootStyle) 78 , m_fontSizes(fontSizes)
42 , m_viewportWidth(renderView ? renderView->layoutViewportWidth() : 0) 79 , m_viewportSize(viewportSize)
43 , m_viewportHeight(renderView ? renderView->layoutViewportHeight() : 0)
44 , m_zoom(zoom) 80 , m_zoom(zoom)
45 , m_useEffectiveZoom(false)
46 , m_computingFontSize(computingFontSize)
47 { 81 {
82 ASSERT(m_style);
48 ASSERT(zoom > 0); 83 ASSERT(zoom > 0);
49 } 84 }
50 85
51 CSSToLengthConversionData::CSSToLengthConversionData(const RenderStyle* style, c onst RenderStyle* rootStyle, const RenderView* renderView, bool computingFontSiz e) 86 CSSToLengthConversionData::CSSToLengthConversionData(const RenderStyle* style, c onst RenderStyle* rootStyle, const RenderView* renderView, float zoom)
52 : m_style(style) 87 : CSSToLengthConversionData(style, CSSToLengthFontSizes(style, rootStyle), C SSToLengthViewportSize(renderView), zoom)
53 , m_rootStyle(rootStyle)
54 , m_viewportWidth(renderView ? renderView->layoutViewportWidth() : 0)
55 , m_viewportHeight(renderView ? renderView->layoutViewportHeight() : 0)
56 , m_useEffectiveZoom(true)
57 , m_computingFontSize(computingFontSize)
58 { 88 {
59 } 89 }
60 90
61 CSSToLengthConversionData::CSSToLengthConversionData(const RenderStyle* style, c onst RenderStyle* rootStyle, float viewportWidth, float viewportHeight, float zo om, bool computingFontSize)
62 : m_style(style)
63 , m_rootStyle(rootStyle)
64 , m_viewportWidth(viewportWidth)
65 , m_viewportHeight(viewportHeight)
66 , m_zoom(zoom)
67 , m_useEffectiveZoom(false)
68 , m_computingFontSize(computingFontSize)
69 {
70 ASSERT(zoom > 0);
71 }
72
73 float CSSToLengthConversionData::zoom() const
74 {
75 if (m_useEffectiveZoom)
76 return m_style ? m_style->effectiveZoom() : 1;
77 return m_zoom;
78 }
79
80 double CSSToLengthConversionData::viewportWidthPercent() const 91 double CSSToLengthConversionData::viewportWidthPercent() const
81 { 92 {
82 m_style->setHasViewportUnits(); 93 m_style->setHasViewportUnits();
83 return m_viewportWidth / 100; 94 return m_viewportSize.width() / 100;
84 } 95 }
85 double CSSToLengthConversionData::viewportHeightPercent() const 96 double CSSToLengthConversionData::viewportHeightPercent() const
86 { 97 {
87 m_style->setHasViewportUnits(); 98 m_style->setHasViewportUnits();
88 return m_viewportHeight / 100; 99 return m_viewportSize.height() / 100;
89 } 100 }
90 double CSSToLengthConversionData::viewportMinPercent() const 101 double CSSToLengthConversionData::viewportMinPercent() const
91 { 102 {
92 m_style->setHasViewportUnits(); 103 m_style->setHasViewportUnits();
93 return std::min(m_viewportWidth, m_viewportHeight) / 100; 104 return std::min(m_viewportSize.width(), m_viewportSize.height()) / 100;
94 } 105 }
95 double CSSToLengthConversionData::viewportMaxPercent() const 106 double CSSToLengthConversionData::viewportMaxPercent() const
96 { 107 {
97 m_style->setHasViewportUnits(); 108 m_style->setHasViewportUnits();
98 return std::max(m_viewportWidth, m_viewportHeight) / 100; 109 return std::max(m_viewportSize.width(), m_viewportSize.height()) / 100;
99 } 110 }
100 111
101 } // namespace blink 112 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698