1 // Copyright 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_INSETS_BASE_H_
6 #define UI_GFX_INSETS_BASE_H_
8 #include "ui/gfx/gfx_export.h"
12 // An insets represents the borders of a container (the space the container must
13 // leave at each of its edges).
14 template<typename Class
, typename Type
>
15 class GFX_EXPORT InsetsBase
{
17 Type
top() const { return top_
; }
18 Type
left() const { return left_
; }
19 Type
bottom() const { return bottom_
; }
20 Type
right() const { return right_
; }
22 // Returns the total width taken up by the insets, which is the sum of the
23 // left and right insets.
24 Type
width() const { return left_
+ right_
; }
26 // Returns the total height taken up by the insets, which is the sum of the
27 // top and bottom insets.
28 Type
height() const { return top_
+ bottom_
; }
30 // Returns true if the insets are empty.
31 bool empty() const { return width() == 0 && height() == 0; }
33 void Set(Type top
, Type left
, Type bottom
, Type right
) {
40 bool operator==(const Class
& insets
) const {
41 return top_
== insets
.top_
&& left_
== insets
.left_
&&
42 bottom_
== insets
.bottom_
&& right_
== insets
.right_
;
45 bool operator!=(const Class
& insets
) const {
46 return !(*this == insets
);
49 void operator+=(const Class
& insets
) {
51 left_
+= insets
.left_
;
52 bottom_
+= insets
.bottom_
;
53 right_
+= insets
.right_
;
56 Class
operator-() const {
57 return Class(-top_
, -left_
, -bottom_
, -right_
);
61 InsetsBase(Type top
, Type left
, Type bottom
, Type right
)
67 // Destructor is intentionally made non virtual and protected.
68 // Do not make this public.
80 #endif // UI_GFX_INSETS_BASE_H_