Disable ExtensionIconSourceTest.IconLoaded* on Mac and Win
[chromium-blink-merge.git] / ui / gfx / size_base.h
blob57e4700b8ebc7ddda87c96fd17a5e02382206560
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_SIZE_BASE_H_
6 #define UI_GFX_SIZE_BASE_H_
8 #include "ui/base/ui_export.h"
10 namespace gfx {
12 // A size has width and height values.
13 template<typename Class, typename Type>
14 class UI_EXPORT SizeBase {
15 public:
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) {
22 set_width(width);
23 set_height(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 ClampToMax(const Class& max) {
39 width_ = width_ <= max.width_ ? width_ : max.width_;
40 height_ = height_ <= max.height_ ? height_ : max.height_;
43 void ClampToMin(const Class& min) {
44 width_ = width_ >= min.width_ ? width_ : min.width_;
45 height_ = height_ >= min.height_ ? height_ : min.height_;
48 bool IsEmpty() const {
49 return (width_ == 0) || (height_ == 0);
52 protected:
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.
60 ~SizeBase() {}
62 private:
63 Type width_;
64 Type height_;
67 } // namespace gfx
69 #endif // UI_GFX_SIZE_BASE_H_