1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef UI_GFX_GEOMETRY_SIZE_BASE_H_
6 #define UI_GFX_GEOMETRY_SIZE_BASE_H_
8 #include "ui/gfx/gfx_export.h"
12 // A size has width and height values.
13 template<typename Class
, typename Type
>
14 class GFX_EXPORT SizeBase
{
16 Type
width() const { return width_
; }
17 Type
height() const { return height_
; }
19 Type
GetArea() const { return width_
* height_
; }
21 void SetSize(Type width
, Type height
) {
26 void Enlarge(Type width
, Type height
) {
27 set_width(width_
+ width
);
28 set_height(height_
+ height
);
31 void set_width(Type width
) {
32 width_
= width
< 0 ? 0 : width
;
34 void set_height(Type height
) {
35 height_
= height
< 0 ? 0 : height
;
38 void SetToMin(const Class
& other
) {
39 width_
= width_
<= other
.width_
? width_
: other
.width_
;
40 height_
= height_
<= other
.height_
? height_
: other
.height_
;
43 void SetToMax(const Class
& other
) {
44 width_
= width_
>= other
.width_
? width_
: other
.width_
;
45 height_
= height_
>= other
.height_
? height_
: other
.height_
;
48 bool IsEmpty() const {
49 return (width_
== 0) || (height_
== 0);
53 SizeBase(Type width
, Type height
)
54 : width_(width
< 0 ? 0 : width
),
55 height_(height
< 0 ? 0 : height
) {
58 // Destructor is intentionally made non virtual and protected.
59 // Do not make this public.
69 #endif // UI_GFX_GEOMETRY_SIZE_BASE_H_