summaryrefslogtreecommitdiffstats
path: root/ui/gfx
diff options
context:
space:
mode:
authordanakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-10 09:34:28 +0000
committerdanakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-10 09:34:28 +0000
commit01a15a710b6ffb772bdf8e3827e9f1395d29d814 (patch)
treee0bf4c1332ac22b7cc939be4b08f2bdafa732a9c /ui/gfx
parentbcf7636d116fe67fd79d9acca753b1b18f380654 (diff)
downloadchromium_src-01a15a710b6ffb772bdf8e3827e9f1395d29d814.zip
chromium_src-01a15a710b6ffb772bdf8e3827e9f1395d29d814.tar.gz
chromium_src-01a15a710b6ffb772bdf8e3827e9f1395d29d814.tar.bz2
ui: Make gfx::Size::Scale() mutate the class. Add gfx::ScaleSize() similar to Rect/Point.
Covered by existing unit tests. R=sky BUG=160158 Review URL: https://chromiumcodereview.appspot.com/11377068 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@167077 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx')
-rw-r--r--ui/gfx/canvas.cc6
-rw-r--r--ui/gfx/display.cc4
-rw-r--r--ui/gfx/image/image_skia_operations.cc2
-rw-r--r--ui/gfx/rect_f.h4
-rw-r--r--ui/gfx/size.h8
-rw-r--r--ui/gfx/size_f.cc6
-rw-r--r--ui/gfx/size_f.h14
7 files changed, 24 insertions, 20 deletions
diff --git a/ui/gfx/canvas.cc b/ui/gfx/canvas.cc
index bf41bc1..eb11b37 100644
--- a/ui/gfx/canvas.cc
+++ b/ui/gfx/canvas.cc
@@ -29,8 +29,8 @@ Canvas::Canvas(const gfx::Size& size,
: scale_factor_(scale_factor),
owned_canvas_(NULL),
canvas_(NULL) {
- gfx::Size pixel_size = gfx::ToFlooredSize(size.Scale(
- ui::GetScaleFactorScale(scale_factor)));
+ gfx::Size pixel_size = gfx::ToFlooredSize(
+ gfx::ScaleSize(size, ui::GetScaleFactorScale(scale_factor)));
owned_canvas_.reset(new skia::PlatformCanvas(pixel_size.width(),
pixel_size.height(),
is_opaque));
@@ -77,7 +77,7 @@ void Canvas::RecreateBackingCanvas(const gfx::Size& size,
bool is_opaque) {
scale_factor_ = scale_factor;
gfx::Size pixel_size = gfx::ToFlooredSize(
- size.Scale(ui::GetScaleFactorScale(scale_factor)));
+ gfx::ScaleSize(size, ui::GetScaleFactorScale(scale_factor)));
owned_canvas_.reset(new skia::PlatformCanvas(pixel_size.width(),
pixel_size.height(),
is_opaque));
diff --git a/ui/gfx/display.cc b/ui/gfx/display.cc
index e647f65..ef3f250 100644
--- a/ui/gfx/display.cc
+++ b/ui/gfx/display.cc
@@ -89,7 +89,7 @@ void Display::SetScaleAndBounds(
bounds_in_pixel_ = bounds_in_pixel;
#endif
bounds_ = gfx::Rect(gfx::ToFlooredSize(
- bounds_in_pixel.size().Scale(1.0f / device_scale_factor_)));
+ gfx::ScaleSize(bounds_in_pixel.size(), 1.0f / device_scale_factor_)));
UpdateWorkAreaFromInsets(insets);
}
@@ -109,7 +109,7 @@ void Display::UpdateWorkAreaFromInsets(const gfx::Insets& insets) {
}
gfx::Size Display::GetSizeInPixel() const {
- return gfx::ToFlooredSize(size().Scale(device_scale_factor_));
+ return gfx::ToFlooredSize(gfx::ScaleSize(size(), device_scale_factor_));
}
std::string Display::ToString() const {
diff --git a/ui/gfx/image/image_skia_operations.cc b/ui/gfx/image/image_skia_operations.cc
index a2395da..75848c3 100644
--- a/ui/gfx/image/image_skia_operations.cc
+++ b/ui/gfx/image/image_skia_operations.cc
@@ -327,7 +327,7 @@ class ResizeSource : public ImageSkiaSource {
const float scale = ui::GetScaleFactorScale(scale_factor);
const Size target_pixel_size = gfx::ToFlooredSize(
- target_dip_size_.Scale(scale));
+ gfx::ScaleSize(target_dip_size_, scale));
const SkBitmap resized = skia::ImageOperations::Resize(
image_rep.sk_bitmap(),
resize_method_,
diff --git a/ui/gfx/rect_f.h b/ui/gfx/rect_f.h
index 7595091..2bc367c 100644
--- a/ui/gfx/rect_f.h
+++ b/ui/gfx/rect_f.h
@@ -28,7 +28,7 @@ class UI_EXPORT RectF
~RectF();
- /// Scales the rectangle by |scale|.
+ // Scales the rectangle by |scale|.
void Scale(float scale) {
Scale(scale, scale);
}
@@ -36,7 +36,7 @@ class UI_EXPORT RectF
void Scale(float x_scale, float y_scale) {
set_origin(ScalePoint(origin(), x_scale, y_scale));
- SizeF new_size = size().Scale(x_scale, y_scale);
+ SizeF new_size = gfx::ScaleSize(size(), x_scale, y_scale);
new_size.ClampToNonNegative();
set_size(new_size);
}
diff --git a/ui/gfx/size.h b/ui/gfx/size.h
index 4425207..a525251 100644
--- a/ui/gfx/size.h
+++ b/ui/gfx/size.h
@@ -47,14 +47,6 @@ class UI_EXPORT Size : public SizeBase<Size, int> {
return SizeF(width(), height());
}
- SizeF Scale(float scale) const WARN_UNUSED_RESULT {
- return Scale(scale, scale);
- }
-
- SizeF Scale(float x_scale, float y_scale) const WARN_UNUSED_RESULT {
- return SizeF(width() * x_scale, height() * y_scale);
- }
-
std::string ToString() const;
};
diff --git a/ui/gfx/size_f.cc b/ui/gfx/size_f.cc
index 96c1867..03c34ec 100644
--- a/ui/gfx/size_f.cc
+++ b/ui/gfx/size_f.cc
@@ -24,4 +24,10 @@ std::string SizeF::ToString() const {
return base::StringPrintf("%fx%f", width(), height());
}
+SizeF ScaleSize(const SizeF& s, float x_scale, float y_scale) {
+ SizeF scaled_s(s);
+ scaled_s.Scale(x_scale, y_scale);
+ return scaled_s;
+}
+
} // namespace gfx
diff --git a/ui/gfx/size_f.h b/ui/gfx/size_f.h
index f9ac6bd..4580501 100644
--- a/ui/gfx/size_f.h
+++ b/ui/gfx/size_f.h
@@ -19,12 +19,12 @@ class UI_EXPORT SizeF : public SizeBase<SizeF, float> {
SizeF(float width, float height);
~SizeF();
- SizeF Scale(float scale) const WARN_UNUSED_RESULT {
- return Scale(scale, scale);
+ void Scale(float scale) {
+ Scale(scale, scale);
}
- SizeF Scale(float x_scale, float y_scale) const WARN_UNUSED_RESULT {
- return SizeF(width() * x_scale, height() * y_scale);
+ void Scale(float x_scale, float y_scale) {
+ SetSize(width() * x_scale, height() * y_scale);
}
std::string ToString() const;
@@ -38,6 +38,12 @@ inline bool operator!=(const SizeF& lhs, const SizeF& rhs) {
return !(lhs == rhs);
}
+UI_EXPORT SizeF ScaleSize(const SizeF& p, float x_scale, float y_scale);
+
+inline SizeF ScaleSize(const SizeF& p, float scale) {
+ return ScaleSize(p, scale, scale);
+}
+
#if !defined(COMPILER_MSVC)
extern template class SizeBase<SizeF, float>;
#endif