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

Side by Side Diff: Source/core/platform/graphics/LayoutSize.h

Issue 22482004: Add support for the object-fit CSS property. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Code review Created 7 years, 4 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 /* 1 /*
2 * Copyright (c) 2012, Google Inc. All rights reserved. 2 * Copyright (c) 2012, 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 21 matching lines...) Expand all
32 #define LayoutSize_h 32 #define LayoutSize_h
33 33
34 #include "core/platform/LayoutUnit.h" 34 #include "core/platform/LayoutUnit.h"
35 #include "core/platform/graphics/FloatSize.h" 35 #include "core/platform/graphics/FloatSize.h"
36 #include "core/platform/graphics/IntSize.h" 36 #include "core/platform/graphics/IntSize.h"
37 37
38 namespace WebCore { 38 namespace WebCore {
39 39
40 class LayoutPoint; 40 class LayoutPoint;
41 41
42 enum AspectRatioFit {
43 AspectRatioFitShrink,
44 AspectRatioFitGrow
45 };
46
42 class LayoutSize { 47 class LayoutSize {
43 public: 48 public:
44 LayoutSize() : m_width(0), m_height(0) { } 49 LayoutSize() : m_width(0), m_height(0) { }
45 LayoutSize(const IntSize& size) : m_width(size.width()), m_height(size.heigh t()) { } 50 LayoutSize(const IntSize& size) : m_width(size.width()), m_height(size.heigh t()) { }
46 LayoutSize(LayoutUnit width, LayoutUnit height) : m_width(width), m_height(h eight) { } 51 LayoutSize(LayoutUnit width, LayoutUnit height) : m_width(width), m_height(h eight) { }
47 52
48 explicit LayoutSize(const FloatSize& size) : m_width(size.width()), m_height (size.height()) { } 53 explicit LayoutSize(const FloatSize& size) : m_width(size.width()), m_height (size.height()) { }
49 54
50 LayoutUnit width() const { return m_width; } 55 LayoutUnit width() const { return m_width; }
51 LayoutUnit height() const { return m_height; } 56 LayoutUnit height() const { return m_height; }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 m_width = minimumSize.width(); 110 m_width = minimumSize.width();
106 if (m_height < minimumSize.height()) 111 if (m_height < minimumSize.height())
107 m_height = minimumSize.height(); 112 m_height = minimumSize.height();
108 } 113 }
109 114
110 LayoutSize transposedSize() const 115 LayoutSize transposedSize() const
111 { 116 {
112 return LayoutSize(m_height, m_width); 117 return LayoutSize(m_height, m_width);
113 } 118 }
114 119
120 LayoutSize fitToAspectRatio(const LayoutSize& aspectRatio, AspectRatioFit fi t) const
121 {
122 float heightScale = height().toFloat() / aspectRatio.height().toFloat();
123 float widthScale = width().toFloat() / aspectRatio.width().toFloat();
124 if ((widthScale > heightScale) != (fit == AspectRatioFitGrow))
125 return LayoutSize(height() * aspectRatio.width() / aspectRatio.heigh t(), height());
126 return LayoutSize(width(), width() * aspectRatio.height() / aspectRatio. width());
127 }
128
115 private: 129 private:
116 LayoutUnit m_width, m_height; 130 LayoutUnit m_width, m_height;
117 }; 131 };
118 132
119 inline LayoutSize& operator+=(LayoutSize& a, const LayoutSize& b) 133 inline LayoutSize& operator+=(LayoutSize& a, const LayoutSize& b)
120 { 134 {
121 a.setWidth(a.width() + b.width()); 135 a.setWidth(a.width() + b.width());
122 a.setHeight(a.height() + b.height()); 136 a.setHeight(a.height() + b.height());
123 return a; 137 return a;
124 } 138 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 } 180 }
167 181
168 inline LayoutSize roundedLayoutSize(const FloatSize& s) 182 inline LayoutSize roundedLayoutSize(const FloatSize& s)
169 { 183 {
170 return LayoutSize(s); 184 return LayoutSize(s);
171 } 185 }
172 186
173 } // namespace WebCore 187 } // namespace WebCore
174 188
175 #endif // LayoutSize_h 189 #endif // LayoutSize_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698