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

Side by Side Diff: ui/gfx/insets_base.h

Issue 109433013: Move geometric types to a separate, more lightweight target. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years 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 | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #ifndef UI_GFX_INSETS_BASE_H_
6 #define UI_GFX_INSETS_BASE_H_
7
8 #include "ui/gfx/gfx_export.h"
9
10 namespace gfx {
11
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 {
16 public:
17 Type top() const { return top_; }
18 Type left() const { return left_; }
19 Type bottom() const { return bottom_; }
20 Type right() const { return right_; }
21
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_; }
25
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_; }
29
30 // Returns true if the insets are empty.
31 bool empty() const { return width() == 0 && height() == 0; }
32
33 void Set(Type top, Type left, Type bottom, Type right) {
34 top_ = top;
35 left_ = left;
36 bottom_ = bottom;
37 right_ = right;
38 }
39
40 bool operator==(const Class& insets) const {
41 return top_ == insets.top_ && left_ == insets.left_ &&
42 bottom_ == insets.bottom_ && right_ == insets.right_;
43 }
44
45 bool operator!=(const Class& insets) const {
46 return !(*this == insets);
47 }
48
49 void operator+=(const Class& insets) {
50 top_ += insets.top_;
51 left_ += insets.left_;
52 bottom_ += insets.bottom_;
53 right_ += insets.right_;
54 }
55
56 Class operator-() const {
57 return Class(-top_, -left_, -bottom_, -right_);
58 }
59
60 protected:
61 InsetsBase(Type top, Type left, Type bottom, Type right)
62 : top_(top),
63 left_(left),
64 bottom_(bottom),
65 right_(right) {}
66
67 // Destructor is intentionally made non virtual and protected.
68 // Do not make this public.
69 ~InsetsBase() {}
70
71 private:
72 Type top_;
73 Type left_;
74 Type bottom_;
75 Type right_;
76 };
77
78 } // namespace gfx
79
80 #endif // UI_GFX_INSETS_BASE_H_
OLDNEW
« ui/aura/aura.gyp ('K') | « ui/gfx/insets.cc ('k') | ui/gfx/insets_f.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698