Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / core / css / CSSToLengthConversionData.h
blob6682826da4a65bde4f9c8a20af504f34c79f663a
1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef CSSToLengthConversionData_h
32 #define CSSToLengthConversionData_h
34 #include "core/CoreExport.h"
35 #include "wtf/Allocator.h"
36 #include "wtf/Assertions.h"
37 #include "wtf/MathExtras.h"
38 #include <limits>
40 namespace blink {
42 class ComputedStyle;
43 class LayoutView;
44 class Font;
46 class CORE_EXPORT CSSToLengthConversionData {
47 DISALLOW_ALLOCATION();
48 public:
50 class FontSizes {
51 DISALLOW_ALLOCATION();
52 public:
53 FontSizes() : m_em(0), m_rem(0), m_font(nullptr) { }
54 FontSizes(float em, float rem, const Font*);
55 FontSizes(const ComputedStyle*, const ComputedStyle* rootStyle);
57 float em() const { return m_em; }
58 float rem() const { return m_rem; }
59 float ex() const;
60 float ch() const;
61 private:
62 float m_em;
63 float m_rem;
64 const Font* m_font;
67 class ViewportSize {
68 DISALLOW_ALLOCATION();
69 public:
70 ViewportSize() : m_width(0), m_height(0) { }
71 ViewportSize(double width, double height) : m_width(width), m_height(height) { }
72 explicit ViewportSize(const LayoutView*);
74 double width() const { return m_width; }
75 double height() const { return m_height; }
76 private:
77 double m_width;
78 double m_height;
81 CSSToLengthConversionData() { }
82 CSSToLengthConversionData(const ComputedStyle*, const FontSizes&, const ViewportSize&, float zoom);
83 CSSToLengthConversionData(const ComputedStyle* currStyle, const ComputedStyle* rootStyle, const LayoutView*, float zoom);
85 float zoom() const { return m_zoom; }
87 float emFontSize() const { return m_fontSizes.em(); }
88 float remFontSize() const;
89 float exFontSize() const { return m_fontSizes.ex(); }
90 float chFontSize() const { return m_fontSizes.ch(); }
92 // Accessing these marks the style as having viewport units
93 double viewportWidthPercent() const;
94 double viewportHeightPercent() const;
95 double viewportMinPercent() const;
96 double viewportMaxPercent() const;
98 void setFontSizes(const FontSizes& fontSizes) { m_fontSizes = fontSizes; }
99 void setZoom(float zoom)
101 ASSERT(std::isfinite(zoom) && zoom > 0);
102 m_zoom = zoom;
105 CSSToLengthConversionData copyWithAdjustedZoom(float newZoom) const
107 return CSSToLengthConversionData(m_style, m_fontSizes, m_viewportSize, newZoom);
110 private:
111 const ComputedStyle* m_style;
112 FontSizes m_fontSizes;
113 ViewportSize m_viewportSize;
114 float m_zoom;
117 } // namespace blink
119 #endif