summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-13 16:36:04 +0000
committertfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-13 16:36:04 +0000
commitcbdb7a3175ae70d64bb46b1e6f2fb8bfb64cb7cc (patch)
tree713881dd03a318f5151af2fe37a1ab89f2d68273
parent304594c8ca8ca017c317dc74cc10d1a3656a14db (diff)
downloadchromium_src-cbdb7a3175ae70d64bb46b1e6f2fb8bfb64cb7cc.zip
chromium_src-cbdb7a3175ae70d64bb46b1e6f2fb8bfb64cb7cc.tar.gz
chromium_src-cbdb7a3175ae70d64bb46b1e6f2fb8bfb64cb7cc.tar.bz2
ui/gfx: Use template for Insets and remove duplicates.
TEST=ui_unittests R=sky@chromium.org, danakj@chromium.org Review URL: https://codereview.chromium.org/11366179 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@167400 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chrome_browser_main.cc4
-rw-r--r--chrome/browser/ui/gtk/extensions/extension_keybinding_registry_gtk.cc2
-rw-r--r--ui/gfx/insets.cc24
-rw-r--r--ui/gfx/insets.h89
-rw-r--r--ui/gfx/insets_base.h80
-rw-r--r--ui/gfx/insets_f.cc11
-rw-r--r--ui/gfx/insets_f.h71
-rw-r--r--ui/gfx/size.h2
-rw-r--r--ui/gfx/size_base.h4
-rw-r--r--ui/gfx/size_f.h1
-rw-r--r--ui/ui.gyp3
11 files changed, 150 insertions, 141 deletions
diff --git a/chrome/browser/chrome_browser_main.cc b/chrome/browser/chrome_browser_main.cc
index 32cb4b1..97f54259 100644
--- a/chrome/browser/chrome_browser_main.cc
+++ b/chrome/browser/chrome_browser_main.cc
@@ -4,6 +4,10 @@
#include "chrome/browser/chrome_browser_main.h"
+#if defined(TOOLKIT_GTK)
+#include <gtk/gtk.h>
+#endif
+
#include <algorithm>
#include <string>
#include <vector>
diff --git a/chrome/browser/ui/gtk/extensions/extension_keybinding_registry_gtk.cc b/chrome/browser/ui/gtk/extensions/extension_keybinding_registry_gtk.cc
index 126b647..a251c9d 100644
--- a/chrome/browser/ui/gtk/extensions/extension_keybinding_registry_gtk.cc
+++ b/chrome/browser/ui/gtk/extensions/extension_keybinding_registry_gtk.cc
@@ -4,6 +4,8 @@
#include "chrome/browser/ui/gtk/extensions/extension_keybinding_registry_gtk.h"
+#include <gtk/gtk.h>
+
#include "chrome/browser/extensions/api/commands/command_service.h"
#include "chrome/browser/extensions/api/commands/command_service_factory.h"
#include "chrome/browser/extensions/extension_service.h"
diff --git a/ui/gfx/insets.cc b/ui/gfx/insets.cc
index 3a33965..78b2b29 100644
--- a/ui/gfx/insets.cc
+++ b/ui/gfx/insets.cc
@@ -4,13 +4,35 @@
#include "ui/gfx/insets.h"
+#if defined(TOOLKIT_GTK)
+#include <gtk/gtk.h>
+#endif
+
#include "base/stringprintf.h"
namespace gfx {
+template class InsetsBase<Insets, int>;
+
+Insets::Insets() : InsetsBase<Insets, int>(0, 0, 0, 0) {}
+
+Insets::Insets(int top, int left, int bottom, int right)
+ : InsetsBase<Insets, int>(top, left, bottom, right) {}
+
+#if defined(TOOLKIT_GTK)
+Insets::Insets(const GtkBorder& border)
+ : InsetsBase<Insets, int>(border.top,
+ border.left,
+ border.bottom,
+ border.right) {
+}
+#endif
+
+Insets::~Insets() {}
+
std::string Insets::ToString() const {
// Print members in the same order of the constructor parameters.
- return StringPrintf("%d,%d,%d,%d", top_, left_, bottom_, right_);
+ return base::StringPrintf("%d,%d,%d,%d", top(), left(), bottom(), right());
}
} // namespace gfx
diff --git a/ui/gfx/insets.h b/ui/gfx/insets.h
index 1ee439b..31e9f53 100644
--- a/ui/gfx/insets.h
+++ b/ui/gfx/insets.h
@@ -9,101 +9,44 @@
#include "build/build_config.h"
#include "ui/base/ui_export.h"
+#include "ui/gfx/insets_base.h"
#if defined(TOOLKIT_GTK)
-#include <gtk/gtk.h>
+typedef struct _GtkBorder GtkBorder;
#endif
namespace gfx {
-//
-// An insets represents the borders of a container (the space the container must
-// leave at each of its edges).
-//
-
-class UI_EXPORT Insets {
+// An integer versin of gfx::Insets.
+class UI_EXPORT Insets : public InsetsBase<Insets, int> {
public:
- Insets() : top_(0), left_(0), bottom_(0), right_(0) {}
- Insets(int top, int left, int bottom, int right)
- : top_(top),
- left_(left),
- bottom_(bottom),
- right_(right) {}
+ Insets();
+ Insets(int top, int left, int bottom, int right);
#if defined(TOOLKIT_GTK)
- explicit Insets(const GtkBorder& border)
- : top_(border.top),
- left_(border.left),
- bottom_(border.bottom),
- right_(border.right) {}
+ explicit Insets(const GtkBorder& border);
#endif
- ~Insets() {}
-
- int top() const { return top_; }
- int left() const { return left_; }
- int bottom() const { return bottom_; }
- int right() const { return right_; }
-
- // Returns the total width taken up by the insets, which is the sum of the
- // left and right insets.
- int width() const { return left_ + right_; }
-
- // Returns the total height taken up by the insets, which is the sum of the
- // top and bottom insets.
- int height() const { return top_ + bottom_; }
+ ~Insets();
Insets Scale(float scale) const {
return Scale(scale, scale);
}
Insets Scale(float x_scale, float y_scale) const {
- return Insets(static_cast<int>(top_ * y_scale),
- static_cast<int>(left_ * x_scale),
- static_cast<int>(bottom_ * y_scale),
- static_cast<int>(right_ * x_scale));
- }
-
- // Returns true if the insets are empty.
- bool empty() const { return width() == 0 && height() == 0; }
-
- void Set(int top, int left, int bottom, int right) {
- top_ = top;
- left_ = left;
- bottom_ = bottom;
- right_ = right;
- }
-
- bool operator==(const Insets& insets) const {
- return top_ == insets.top_ && left_ == insets.left_ &&
- bottom_ == insets.bottom_ && right_ == insets.right_;
- }
-
- bool operator!=(const Insets& insets) const {
- return !(*this == insets);
- }
-
- Insets& operator+=(const Insets& insets) {
- top_ += insets.top_;
- left_ += insets.left_;
- bottom_ += insets.bottom_;
- right_ += insets.right_;
- return *this;
- }
-
- Insets operator-() const {
- return Insets(-top_, -left_, -bottom_, -right_);
+ return Insets(static_cast<int>(top() * y_scale),
+ static_cast<int>(left() * x_scale),
+ static_cast<int>(bottom() * y_scale),
+ static_cast<int>(right() * x_scale));
}
// Returns a string representation of the insets.
std::string ToString() const;
-
- private:
- int top_;
- int left_;
- int bottom_;
- int right_;
};
+#if !defined(COMPILER_MSVC)
+extern template class InsetsBase<Insets, int>;
+#endif
+
} // namespace gfx
#endif // UI_GFX_INSETS_H_
diff --git a/ui/gfx/insets_base.h b/ui/gfx/insets_base.h
new file mode 100644
index 0000000..bf0b483
--- /dev/null
+++ b/ui/gfx/insets_base.h
@@ -0,0 +1,80 @@
+// Copyright 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef UI_GFX_INSETS_BASE_H_
+#define UI_GFX_INSETS_BASE_H_
+
+#include "ui/base/ui_export.h"
+
+namespace gfx {
+
+// An insets represents the borders of a container (the space the container must
+// leave at each of its edges).
+template<typename Class, typename Type>
+class UI_EXPORT InsetsBase {
+ public:
+ Type top() const { return top_; }
+ Type left() const { return left_; }
+ Type bottom() const { return bottom_; }
+ Type right() const { return right_; }
+
+ // Returns the total width taken up by the insets, which is the sum of the
+ // left and right insets.
+ Type width() const { return left_ + right_; }
+
+ // Returns the total height taken up by the insets, which is the sum of the
+ // top and bottom insets.
+ Type height() const { return top_ + bottom_; }
+
+ // Returns true if the insets are empty.
+ bool empty() const { return width() == 0 && height() == 0; }
+
+ void Set(Type top, Type left, Type bottom, Type right) {
+ top_ = top;
+ left_ = left;
+ bottom_ = bottom;
+ right_ = right;
+ }
+
+ bool operator==(const Class& insets) const {
+ return top_ == insets.top_ && left_ == insets.left_ &&
+ bottom_ == insets.bottom_ && right_ == insets.right_;
+ }
+
+ bool operator!=(const Class& insets) const {
+ return !(*this == insets);
+ }
+
+ void operator+=(const Class& insets) {
+ top_ += insets.top_;
+ left_ += insets.left_;
+ bottom_ += insets.bottom_;
+ right_ += insets.right_;
+ }
+
+ Class operator-() const {
+ return Class(-top_, -left_, -bottom_, -right_);
+ }
+
+ protected:
+ InsetsBase(Type top, Type left, Type bottom, Type right)
+ : top_(top),
+ left_(left),
+ bottom_(bottom),
+ right_(right) {}
+
+ // Destructor is intentionally made non virtual and protected.
+ // Do not make this public.
+ ~InsetsBase() {}
+
+ private:
+ Type top_;
+ Type left_;
+ Type bottom_;
+ Type right_;
+};
+
+} // namespace gfx
+
+#endif // UI_GFX_INSETS_BASE_H_
diff --git a/ui/gfx/insets_f.cc b/ui/gfx/insets_f.cc
index 54aa131..7965dca 100644
--- a/ui/gfx/insets_f.cc
+++ b/ui/gfx/insets_f.cc
@@ -8,9 +8,18 @@
namespace gfx {
+template class InsetsBase<InsetsF, float>;
+
+InsetsF::InsetsF() : InsetsBase<InsetsF, float>(0, 0, 0, 0) {}
+
+InsetsF::InsetsF(float top, float left, float bottom, float right)
+ : InsetsBase<InsetsF, float>(top, left, bottom, right) {}
+
+InsetsF::~InsetsF() {}
+
std::string InsetsF::ToString() const {
// Print members in the same order of the constructor parameters.
- return StringPrintf("%f,%f,%f,%f", top_, left_, bottom_, right_);
+ return base::StringPrintf("%f,%f,%f,%f", top(), left(), bottom(), right());
}
} // namespace gfx
diff --git a/ui/gfx/insets_f.h b/ui/gfx/insets_f.h
index 3bb6783..d447d94 100644
--- a/ui/gfx/insets_f.h
+++ b/ui/gfx/insets_f.h
@@ -9,76 +9,25 @@
#include "build/build_config.h"
#include "ui/base/ui_export.h"
+#include "ui/gfx/insets_base.h"
namespace gfx {
-// A floating versino of gfx::Insets. This is copied, instead of using
-// template, to avoid conflict with m19 branch.
-// TODO(oshima): Merge this to ui/gfx/insets.h using template.
-class UI_EXPORT InsetsF {
+// A floating versin of gfx::Insets.
+class UI_EXPORT InsetsF : public InsetsBase<InsetsF, float> {
public:
- InsetsF() : top_(0), left_(0), bottom_(0), right_(0) {}
- InsetsF(float top, float left, float bottom, float right)
- : top_(top),
- left_(left),
- bottom_(bottom),
- right_(right) {}
- ~InsetsF() {}
-
- float top() const { return top_; }
- float left() const { return left_; }
- float bottom() const { return bottom_; }
- float right() const { return right_; }
-
- // Returns the total width taken up by the insets, which is the sum of the
- // left and right insets.
- float width() const { return left_ + right_; }
-
- // Returns the total height taken up by the insets, which is the sum of the
- // top and bottom insets.
- float height() const { return top_ + bottom_; }
-
- // Returns true if the insets are empty.
- bool empty() const { return width() == 0 && height() == 0; }
-
- void Set(float top, float left, float bottom, float right) {
- top_ = top;
- left_ = left;
- bottom_ = bottom;
- right_ = right;
- }
-
- bool operator==(const InsetsF& insets) const {
- return top_ == insets.top_ && left_ == insets.left_ &&
- bottom_ == insets.bottom_ && right_ == insets.right_;
- }
-
- bool operator!=(const InsetsF& insets) const {
- return !(*this == insets);
- }
-
- InsetsF& operator+=(const InsetsF& insets) {
- top_ += insets.top_;
- left_ += insets.left_;
- bottom_ += insets.bottom_;
- right_ += insets.right_;
- return *this;
- }
-
- InsetsF operator-() const {
- return InsetsF(-top_, -left_, -bottom_, -right_);
- }
+ InsetsF();
+ InsetsF(float top, float left, float bottom, float right);
+ ~InsetsF();
// Returns a string representation of the insets.
std::string ToString() const;
-
- private:
- float top_;
- float left_;
- float bottom_;
- float right_;
};
+#if !defined(COMPILER_MSVC)
+extern template class InsetsBase<InsetsF, float>;
+#endif
+
} // namespace gfx
#endif // UI_GFX_INSETS_F_H_
diff --git a/ui/gfx/size.h b/ui/gfx/size.h
index a525251..edfc1fc 100644
--- a/ui/gfx/size.h
+++ b/ui/gfx/size.h
@@ -7,7 +7,7 @@
#include <string>
-#include "build/build_config.h"
+#include "base/compiler_specific.h"
#include "ui/base/ui_export.h"
#include "ui/gfx/size_base.h"
#include "ui/gfx/size_f.h"
diff --git a/ui/gfx/size_base.h b/ui/gfx/size_base.h
index 33051a3..3d171f1 100644
--- a/ui/gfx/size_base.h
+++ b/ui/gfx/size_base.h
@@ -5,10 +5,6 @@
#ifndef UI_GFX_SIZE_BASE_H_
#define UI_GFX_SIZE_BASE_H_
-#include <string>
-
-#include "base/compiler_specific.h"
-#include "build/build_config.h"
#include "ui/base/ui_export.h"
namespace gfx {
diff --git a/ui/gfx/size_f.h b/ui/gfx/size_f.h
index 4580501..98d2e0c 100644
--- a/ui/gfx/size_f.h
+++ b/ui/gfx/size_f.h
@@ -7,6 +7,7 @@
#include <string>
+#include "base/compiler_specific.h"
#include "ui/base/ui_export.h"
#include "ui/gfx/size_base.h"
diff --git a/ui/ui.gyp b/ui/ui.gyp
index c003637..82c8757 100644
--- a/ui/ui.gyp
+++ b/ui/ui.gyp
@@ -420,6 +420,9 @@
'gfx/image/image_util_ios.mm',
'gfx/insets.cc',
'gfx/insets.h',
+ 'gfx/insets_base.h',
+ 'gfx/insets_f.cc',
+ 'gfx/insets_f.h',
'gfx/interpolated_transform.cc',
'gfx/interpolated_transform.h',
'gfx/mac/nsimage_cache.h',