Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / platform / LayoutUnit.h
1 /*
2  * Copyright (c) 2012, Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
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.
17  *
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.
29  */
30
31 #ifndef LayoutUnit_h
32 #define LayoutUnit_h
33
34 #include "wtf/Assertions.h"
35 #include "wtf/MathExtras.h"
36 #include "wtf/SaturatedArithmetic.h"
37 #include <limits.h>
38 #include <limits>
39 #include <stdlib.h>
40
41 namespace blink {
42
43 #if !ERROR_DISABLED
44
45 #define REPORT_OVERFLOW(doesOverflow) ((void)0)
46
47 #else
48
49 #define REPORT_OVERFLOW(doesOverflow) do \
50     if (!(doesOverflow)) { \
51         WTFReportError(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, "!(%s)", #doesOverflow); \
52     } \
53 while (0)
54
55 #endif
56
57 static const int kLayoutUnitFractionalBits = 6;
58 static const int kFixedPointDenominator = 1 << kLayoutUnitFractionalBits;
59
60 const int intMaxForLayoutUnit = INT_MAX / kFixedPointDenominator;
61 const int intMinForLayoutUnit = INT_MIN / kFixedPointDenominator;
62
63 class LayoutUnit {
64 public:
65     LayoutUnit() : m_value(0) { }
66     LayoutUnit(int value) { setValue(value); }
67     LayoutUnit(unsigned short value) { setValue(value); }
68     LayoutUnit(unsigned value) { setValue(value); }
69     LayoutUnit(unsigned long value) { m_value = clampTo<int>(value * kFixedPointDenominator); }
70     LayoutUnit(unsigned long long value) { m_value = clampTo<int>(value * kFixedPointDenominator); }
71     LayoutUnit(float value) { m_value = clampTo<int>(value * kFixedPointDenominator); }
72     LayoutUnit(double value) { m_value = clampTo<int>(value * kFixedPointDenominator); }
73
74     static LayoutUnit fromFloatCeil(float value)
75     {
76         LayoutUnit v;
77         v.m_value = clampTo<int>(ceilf(value * kFixedPointDenominator));
78         return v;
79     }
80
81     static LayoutUnit fromFloatFloor(float value)
82     {
83         LayoutUnit v;
84         v.m_value = clampTo<int>(floorf(value * kFixedPointDenominator));
85         return v;
86     }
87
88     static LayoutUnit fromFloatRound(float value)
89     {
90         if (value >= 0)
91             return clamp(value + epsilon() / 2.0f);
92         return clamp(value - epsilon() / 2.0f);
93     }
94
95     int toInt() const { return m_value / kFixedPointDenominator; }
96     float toFloat() const { return static_cast<float>(m_value) / kFixedPointDenominator; }
97     double toDouble() const { return static_cast<double>(m_value) / kFixedPointDenominator; }
98     float ceilToFloat() const
99     {
100         float floatValue = toFloat();
101         if (static_cast<int>(floatValue * kFixedPointDenominator) == m_value)
102             return floatValue;
103         if (floatValue > 0)
104             return nextafterf(floatValue, std::numeric_limits<float>::max());
105         return nextafterf(floatValue, std::numeric_limits<float>::min());
106     }
107     unsigned toUnsigned() const { REPORT_OVERFLOW(m_value >= 0); return toInt(); }
108
109     operator int() const { return toInt(); }
110     operator unsigned() const { return toUnsigned(); }
111     operator double() const { return toDouble(); }
112     operator bool() const { return m_value; }
113
114     LayoutUnit operator++(int)
115     {
116         m_value += kFixedPointDenominator;
117         return *this;
118     }
119
120     inline int rawValue() const { return m_value; }
121     inline void setRawValue(int value) { m_value = value; }
122     void setRawValue(long long value)
123     {
124         REPORT_OVERFLOW(value > std::numeric_limits<int>::min() && value < std::numeric_limits<int>::max());
125         m_value = static_cast<int>(value);
126     }
127
128     LayoutUnit abs() const
129     {
130         LayoutUnit returnValue;
131         returnValue.setRawValue(::abs(m_value));
132         return returnValue;
133     }
134     int ceil() const
135     {
136         if (UNLIKELY(m_value >= INT_MAX - kFixedPointDenominator + 1))
137             return intMaxForLayoutUnit;
138
139         if (m_value >= 0)
140             return (m_value + kFixedPointDenominator - 1) / kFixedPointDenominator;
141         return toInt();
142     }
143     ALWAYS_INLINE int round() const
144     {
145         return saturatedAddition(rawValue(), kFixedPointDenominator / 2) >> kLayoutUnitFractionalBits;
146     }
147
148     int floor() const
149     {
150         if (UNLIKELY(m_value <= INT_MIN + kFixedPointDenominator - 1))
151             return intMinForLayoutUnit;
152
153         return m_value >> kLayoutUnitFractionalBits;
154     }
155
156     LayoutUnit fraction() const
157     {
158         // Add the fraction to the size (as opposed to the full location) to avoid overflows.
159         // Compute fraction using the mod operator to preserve the sign of the value as it may affect rounding.
160         LayoutUnit fraction;
161         fraction.setRawValue(rawValue() % kFixedPointDenominator);
162         return fraction;
163     }
164
165     bool mightBeSaturated() const
166     {
167         return rawValue() == std::numeric_limits<int>::max()
168             || rawValue() == std::numeric_limits<int>::min();
169     }
170
171     static float epsilon() { return 1.0f / kFixedPointDenominator; }
172
173     static const LayoutUnit max()
174     {
175         LayoutUnit m;
176         m.m_value = std::numeric_limits<int>::max();
177         return m;
178     }
179     static const LayoutUnit min()
180     {
181         LayoutUnit m;
182         m.m_value = std::numeric_limits<int>::min();
183         return m;
184     }
185
186     // Versions of max/min that are slightly smaller/larger than max/min() to allow for roinding without overflowing.
187     static const LayoutUnit nearlyMax()
188     {
189         LayoutUnit m;
190         m.m_value = std::numeric_limits<int>::max() - kFixedPointDenominator / 2;
191         return m;
192     }
193     static const LayoutUnit nearlyMin()
194     {
195         LayoutUnit m;
196         m.m_value = std::numeric_limits<int>::min() + kFixedPointDenominator / 2;
197         return m;
198     }
199
200     static LayoutUnit clamp(double value)
201     {
202         return clampTo<LayoutUnit>(value, LayoutUnit::min(), LayoutUnit::max());
203     }
204
205 private:
206     static bool isInBounds(int value)
207     {
208         return ::abs(value) <= std::numeric_limits<int>::max() / kFixedPointDenominator;
209     }
210     static bool isInBounds(unsigned value)
211     {
212         return value <= static_cast<unsigned>(std::numeric_limits<int>::max()) / kFixedPointDenominator;
213     }
214     static bool isInBounds(double value)
215     {
216         return ::fabs(value) <= std::numeric_limits<int>::max() / kFixedPointDenominator;
217     }
218
219     ALWAYS_INLINE void setValue(int value)
220     {
221         m_value = saturatedSet(value, kLayoutUnitFractionalBits);
222     }
223
224     inline void setValue(unsigned value)
225     {
226         m_value = saturatedSet(value, kLayoutUnitFractionalBits);
227     }
228
229     int m_value;
230 };
231
232 inline bool operator<=(const LayoutUnit& a, const LayoutUnit& b)
233 {
234     return a.rawValue() <= b.rawValue();
235 }
236
237 inline bool operator<=(const LayoutUnit& a, float b)
238 {
239     return a.toFloat() <= b;
240 }
241
242 inline bool operator<=(const LayoutUnit& a, int b)
243 {
244     return a <= LayoutUnit(b);
245 }
246
247 inline bool operator<=(const float a, const LayoutUnit& b)
248 {
249     return a <= b.toFloat();
250 }
251
252 inline bool operator<=(const int a, const LayoutUnit& b)
253 {
254     return LayoutUnit(a) <= b;
255 }
256
257 inline bool operator>=(const LayoutUnit& a, const LayoutUnit& b)
258 {
259     return a.rawValue() >= b.rawValue();
260 }
261
262 inline bool operator>=(const LayoutUnit& a, int b)
263 {
264     return a >= LayoutUnit(b);
265 }
266
267 inline bool operator>=(const float a, const LayoutUnit& b)
268 {
269     return a >= b.toFloat();
270 }
271
272 inline bool operator>=(const LayoutUnit& a, float b)
273 {
274     return a.toFloat() >= b;
275 }
276
277 inline bool operator>=(const int a, const LayoutUnit& b)
278 {
279     return LayoutUnit(a) >= b;
280 }
281
282 inline bool operator<(const LayoutUnit& a, const LayoutUnit& b)
283 {
284     return a.rawValue() < b.rawValue();
285 }
286
287 inline bool operator<(const LayoutUnit& a, int b)
288 {
289     return a < LayoutUnit(b);
290 }
291
292 inline bool operator<(const LayoutUnit& a, float b)
293 {
294     return a.toFloat() < b;
295 }
296
297 inline bool operator<(const LayoutUnit& a, double b)
298 {
299     return a.toDouble() < b;
300 }
301
302 inline bool operator<(const int a, const LayoutUnit& b)
303 {
304     return LayoutUnit(a) < b;
305 }
306
307 inline bool operator<(const float a, const LayoutUnit& b)
308 {
309     return a < b.toFloat();
310 }
311
312 inline bool operator>(const LayoutUnit& a, const LayoutUnit& b)
313 {
314     return a.rawValue() > b.rawValue();
315 }
316
317 inline bool operator>(const LayoutUnit& a, double b)
318 {
319     return a.toDouble() > b;
320 }
321
322 inline bool operator>(const LayoutUnit& a, float b)
323 {
324     return a.toFloat() > b;
325 }
326
327 inline bool operator>(const LayoutUnit& a, int b)
328 {
329     return a > LayoutUnit(b);
330 }
331
332 inline bool operator>(const int a, const LayoutUnit& b)
333 {
334     return LayoutUnit(a) > b;
335 }
336
337 inline bool operator>(const float a, const LayoutUnit& b)
338 {
339     return a > b.toFloat();
340 }
341
342 inline bool operator>(const double a, const LayoutUnit& b)
343 {
344     return a > b.toDouble();
345 }
346
347 inline bool operator!=(const LayoutUnit& a, const LayoutUnit& b)
348 {
349     return a.rawValue() != b.rawValue();
350 }
351
352 inline bool operator!=(const LayoutUnit& a, float b)
353 {
354     return a != LayoutUnit(b);
355 }
356
357 inline bool operator!=(const int a, const LayoutUnit& b)
358 {
359     return LayoutUnit(a) != b;
360 }
361
362 inline bool operator!=(const LayoutUnit& a, int b)
363 {
364     return a != LayoutUnit(b);
365 }
366
367 inline bool operator==(const LayoutUnit& a, const LayoutUnit& b)
368 {
369     return a.rawValue() == b.rawValue();
370 }
371
372 inline bool operator==(const LayoutUnit& a, int b)
373 {
374     return a == LayoutUnit(b);
375 }
376
377 inline bool operator==(const int a, const LayoutUnit& b)
378 {
379     return LayoutUnit(a) == b;
380 }
381
382 inline bool operator==(const LayoutUnit& a, float b)
383 {
384     return a.toFloat() == b;
385 }
386
387 inline bool operator==(const float a, const LayoutUnit& b)
388 {
389     return a == b.toFloat();
390 }
391
392 // For multiplication that's prone to overflow, this bounds it to LayoutUnit::max() and ::min()
393 inline LayoutUnit boundedMultiply(const LayoutUnit& a, const LayoutUnit& b)
394 {
395     int64_t result = static_cast<int64_t>(a.rawValue()) * static_cast<int64_t>(b.rawValue()) / kFixedPointDenominator;
396     int32_t high = static_cast<int32_t>(result >> 32);
397     int32_t low = static_cast<int32_t>(result);
398     uint32_t saturated = (static_cast<uint32_t>(a.rawValue() ^ b.rawValue()) >> 31) + std::numeric_limits<int>::max();
399     // If the higher 32 bits does not match the lower 32 with sign extension the operation overflowed.
400     if (high != low >> 31)
401         result = saturated;
402
403     LayoutUnit returnVal;
404     returnVal.setRawValue(static_cast<int>(result));
405     return returnVal;
406 }
407
408 inline LayoutUnit operator*(const LayoutUnit& a, const LayoutUnit& b)
409 {
410     return boundedMultiply(a, b);
411 }
412
413 inline double operator*(const LayoutUnit& a, double b)
414 {
415     return a.toDouble() * b;
416 }
417
418 inline float operator*(const LayoutUnit& a, float b)
419 {
420     return a.toFloat() * b;
421 }
422
423 inline LayoutUnit operator*(const LayoutUnit& a, int b)
424 {
425     return a * LayoutUnit(b);
426 }
427
428 inline LayoutUnit operator*(const LayoutUnit& a, unsigned short b)
429 {
430     return a * LayoutUnit(b);
431 }
432
433 inline LayoutUnit operator*(const LayoutUnit& a, unsigned b)
434 {
435     return a * LayoutUnit(b);
436 }
437
438 inline LayoutUnit operator*(const LayoutUnit& a, unsigned long b)
439 {
440     return a * LayoutUnit(b);
441 }
442
443 inline LayoutUnit operator*(const LayoutUnit& a, unsigned long long b)
444 {
445     return a * LayoutUnit(b);
446 }
447
448 inline LayoutUnit operator*(unsigned short a, const LayoutUnit& b)
449 {
450     return LayoutUnit(a) * b;
451 }
452
453 inline LayoutUnit operator*(unsigned a, const LayoutUnit& b)
454 {
455     return LayoutUnit(a) * b;
456 }
457
458 inline LayoutUnit operator*(unsigned long a, const LayoutUnit& b)
459 {
460     return LayoutUnit(a) * b;
461 }
462
463 inline LayoutUnit operator*(unsigned long long a, const LayoutUnit& b)
464 {
465     return LayoutUnit(a) * b;
466 }
467
468 inline LayoutUnit operator*(const int a, const LayoutUnit& b)
469 {
470     return LayoutUnit(a) * b;
471 }
472
473 inline float operator*(const float a, const LayoutUnit& b)
474 {
475     return a * b.toFloat();
476 }
477
478 inline double operator*(const double a, const LayoutUnit& b)
479 {
480     return a * b.toDouble();
481 }
482
483 inline LayoutUnit operator/(const LayoutUnit& a, const LayoutUnit& b)
484 {
485     LayoutUnit returnVal;
486     long long rawVal = static_cast<long long>(kFixedPointDenominator) * a.rawValue() / b.rawValue();
487     returnVal.setRawValue(clampTo<int>(rawVal));
488     return returnVal;
489 }
490
491 inline float operator/(const LayoutUnit& a, float b)
492 {
493     return a.toFloat() / b;
494 }
495
496 inline double operator/(const LayoutUnit& a, double b)
497 {
498     return a.toDouble() / b;
499 }
500
501 inline LayoutUnit operator/(const LayoutUnit& a, int b)
502 {
503     return a / LayoutUnit(b);
504 }
505
506 inline LayoutUnit operator/(const LayoutUnit& a, unsigned short b)
507 {
508     return a / LayoutUnit(b);
509 }
510
511 inline LayoutUnit operator/(const LayoutUnit& a, unsigned b)
512 {
513     return a / LayoutUnit(b);
514 }
515
516 inline LayoutUnit operator/(const LayoutUnit& a, unsigned long b)
517 {
518     return a / LayoutUnit(b);
519 }
520
521 inline LayoutUnit operator/(const LayoutUnit& a, unsigned long long b)
522 {
523     return a / LayoutUnit(b);
524 }
525
526 inline float operator/(const float a, const LayoutUnit& b)
527 {
528     return a / b.toFloat();
529 }
530
531 inline double operator/(const double a, const LayoutUnit& b)
532 {
533     return a / b.toDouble();
534 }
535
536 inline LayoutUnit operator/(const int a, const LayoutUnit& b)
537 {
538     return LayoutUnit(a) / b;
539 }
540
541 inline LayoutUnit operator/(unsigned short a, const LayoutUnit& b)
542 {
543     return LayoutUnit(a) / b;
544 }
545
546 inline LayoutUnit operator/(unsigned a, const LayoutUnit& b)
547 {
548     return LayoutUnit(a) / b;
549 }
550
551 inline LayoutUnit operator/(unsigned long a, const LayoutUnit& b)
552 {
553     return LayoutUnit(a) / b;
554 }
555
556 inline LayoutUnit operator/(unsigned long long a, const LayoutUnit& b)
557 {
558     return LayoutUnit(a) / b;
559 }
560
561 ALWAYS_INLINE LayoutUnit operator+(const LayoutUnit& a, const LayoutUnit& b)
562 {
563     LayoutUnit returnVal;
564     returnVal.setRawValue(saturatedAddition(a.rawValue(), b.rawValue()));
565     return returnVal;
566 }
567
568 inline LayoutUnit operator+(const LayoutUnit& a, int b)
569 {
570     return a + LayoutUnit(b);
571 }
572
573 inline float operator+(const LayoutUnit& a, float b)
574 {
575     return a.toFloat() + b;
576 }
577
578 inline double operator+(const LayoutUnit& a, double b)
579 {
580     return a.toDouble() + b;
581 }
582
583 inline LayoutUnit operator+(const int a, const LayoutUnit& b)
584 {
585     return LayoutUnit(a) + b;
586 }
587
588 inline float operator+(const float a, const LayoutUnit& b)
589 {
590     return a + b.toFloat();
591 }
592
593 inline double operator+(const double a, const LayoutUnit& b)
594 {
595     return a + b.toDouble();
596 }
597
598 ALWAYS_INLINE LayoutUnit operator-(const LayoutUnit& a, const LayoutUnit& b)
599 {
600     LayoutUnit returnVal;
601     returnVal.setRawValue(saturatedSubtraction(a.rawValue(), b.rawValue()));
602     return returnVal;
603 }
604
605 inline LayoutUnit operator-(const LayoutUnit& a, int b)
606 {
607     return a - LayoutUnit(b);
608 }
609
610 inline LayoutUnit operator-(const LayoutUnit& a, unsigned b)
611 {
612     return a - LayoutUnit(b);
613 }
614
615 inline float operator-(const LayoutUnit& a, float b)
616 {
617     return a.toFloat() - b;
618 }
619
620 inline double operator-(const LayoutUnit& a, double b)
621 {
622     return a.toDouble() - b;
623 }
624
625 inline LayoutUnit operator-(const int a, const LayoutUnit& b)
626 {
627     return LayoutUnit(a) - b;
628 }
629
630 inline float operator-(const float a, const LayoutUnit& b)
631 {
632     return a - b.toFloat();
633 }
634
635 inline LayoutUnit operator-(const LayoutUnit& a)
636 {
637     LayoutUnit returnVal;
638     returnVal.setRawValue(-a.rawValue());
639     return returnVal;
640 }
641
642 // For returning the remainder after a division with integer results.
643 inline LayoutUnit intMod(const LayoutUnit& a, const LayoutUnit& b)
644 {
645     // This calculates the modulo so that: a = static_cast<int>(a / b) * b + intMod(a, b).
646     LayoutUnit returnVal;
647     returnVal.setRawValue(a.rawValue() % b.rawValue());
648     return returnVal;
649 }
650
651 inline LayoutUnit operator%(const LayoutUnit& a, const LayoutUnit& b)
652 {
653     // This calculates the modulo so that: a = (a / b) * b + a % b.
654     LayoutUnit returnVal;
655     long long rawVal = (static_cast<long long>(kFixedPointDenominator) * a.rawValue()) % b.rawValue();
656     returnVal.setRawValue(rawVal / kFixedPointDenominator);
657     return returnVal;
658 }
659
660 inline LayoutUnit operator%(const LayoutUnit& a, int b)
661 {
662     return a % LayoutUnit(b);
663 }
664
665 inline LayoutUnit operator%(int a, const LayoutUnit& b)
666 {
667     return LayoutUnit(a) % b;
668 }
669
670 inline LayoutUnit& operator+=(LayoutUnit& a, const LayoutUnit& b)
671 {
672     a.setRawValue(saturatedAddition(a.rawValue(), b.rawValue()));
673     return a;
674 }
675
676 inline LayoutUnit& operator+=(LayoutUnit& a, int b)
677 {
678     a = a + b;
679     return a;
680 }
681
682 inline LayoutUnit& operator+=(LayoutUnit& a, float b)
683 {
684     a = a + b;
685     return a;
686 }
687
688 inline float& operator+=(float& a, const LayoutUnit& b)
689 {
690     a = a + b;
691     return a;
692 }
693
694 inline LayoutUnit& operator-=(LayoutUnit& a, int b)
695 {
696     a = a - b;
697     return a;
698 }
699
700 inline LayoutUnit& operator-=(LayoutUnit& a, const LayoutUnit& b)
701 {
702     a.setRawValue(saturatedSubtraction(a.rawValue(), b.rawValue()));
703     return a;
704 }
705
706 inline LayoutUnit& operator-=(LayoutUnit& a, float b)
707 {
708     a = a - b;
709     return a;
710 }
711
712 inline float& operator-=(float& a, const LayoutUnit& b)
713 {
714     a = a - b;
715     return a;
716 }
717
718 inline LayoutUnit& operator*=(LayoutUnit& a, const LayoutUnit& b)
719 {
720     a = a * b;
721     return a;
722 }
723 // operator*=(LayoutUnit& a, int b) is supported by the operator above plus LayoutUnit(int).
724
725 inline LayoutUnit& operator*=(LayoutUnit& a, float b)
726 {
727     a = a * b;
728     return a;
729 }
730
731 inline float& operator*=(float& a, const LayoutUnit& b)
732 {
733     a = a * b;
734     return a;
735 }
736
737 inline LayoutUnit& operator/=(LayoutUnit& a, const LayoutUnit& b)
738 {
739     a = a / b;
740     return a;
741 }
742 // operator/=(LayoutUnit& a, int b) is supported by the operator above plus LayoutUnit(int).
743
744 inline LayoutUnit& operator/=(LayoutUnit& a, float b)
745 {
746     a = a / b;
747     return a;
748 }
749
750 inline float& operator/=(float& a, const LayoutUnit& b)
751 {
752     a = a / b;
753     return a;
754 }
755
756 inline int snapSizeToPixel(LayoutUnit size, LayoutUnit location)
757 {
758     LayoutUnit fraction = location.fraction();
759     return (fraction + size).round() - fraction.round();
760 }
761
762 inline int roundToInt(LayoutUnit value)
763 {
764     return value.round();
765 }
766
767 inline int floorToInt(LayoutUnit value)
768 {
769     return value.floor();
770 }
771
772 inline LayoutUnit absoluteValue(const LayoutUnit& value)
773 {
774     return value.abs();
775 }
776
777 inline LayoutUnit layoutMod(const LayoutUnit& numerator, const LayoutUnit& denominator)
778 {
779     return numerator % denominator;
780 }
781
782 inline bool isIntegerValue(const LayoutUnit value)
783 {
784     return value.toInt() == value;
785 }
786
787 inline LayoutUnit clampToLayoutUnit(LayoutUnit value, LayoutUnit min, LayoutUnit max)
788 {
789     if (value >= max)
790         return max;
791     if (value <= min)
792         return min;
793     return value;
794 }
795
796 } // namespace blink
797
798 #endif // LayoutUnit_h