0

ui/gfx: Add ToString() function to Size class.

So we don't need to override operator<< for Size class.

R=sky@chromium.org

Review URL: http://codereview.chromium.org/8038024

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@102998 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
tfarina@chromium.org
2011-09-27 20:05:30 +00:00
parent a8f55faf9b
commit 047470cd5b
5 changed files with 53 additions and 40 deletions

@ -86,9 +86,9 @@ class PrintingLayoutTest : public PrintingTest<UITest> {
Image png_content(png);
double diff_emf = emf_content.PercentageDifferent(test_content);
EXPECT_EQ(0., diff_emf) << verification_name <<
L" original size:" << emf_content.size() <<
L" result size:" << test_content.size();
EXPECT_EQ(0., diff_emf) << WideToUTF8(verification_name) <<
" original size:" << emf_content.size().ToString() <<
" result size:" << test_content.size().ToString();
if (diff_emf) {
// Backup the result emf file.
file_util::CopyFile(test_result, FilePath(
@ -98,9 +98,9 @@ class PrintingLayoutTest : public PrintingTest<UITest> {
// This verification is only to know that the EMF rendering stays
// immutable.
double diff_png = emf_content.PercentageDifferent(png_content);
EXPECT_EQ(0., diff_png) << verification_name <<
L" original size:" << emf_content.size() <<
L" result size:" << test_content.size();
EXPECT_EQ(0., diff_png) << WideToUTF8(verification_name) <<
" original size:" << emf_content.size().ToString() <<
" result size:" << test_content.size().ToString();
if (diff_png) {
// Backup the rendered emf file to detect the rendering difference.
emf_content.SaveToPng(FilePath(verification_file + L"_rendering.png"));

@ -1,4 +1,4 @@
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Copyright (c) 2011 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.
@ -67,25 +67,31 @@ TEST(PageSetupTest, Random) {
effective_margins.top);
// Test values.
EXPECT_EQ(page_size, setup.physical_size()) << seed << " " << page_size <<
" " << printable_area << " " << kTextHeight;
EXPECT_EQ(overlay_area, setup.overlay_area()) << seed << " " << page_size <<
" " << printable_area << " " << kTextHeight;
EXPECT_EQ(content_area, setup.content_area()) << seed << " " << page_size <<
" " << printable_area << " " << kTextHeight;
EXPECT_EQ(page_size, setup.physical_size()) << seed << " " <<
page_size.ToString() << " " << printable_area << " " << kTextHeight;
EXPECT_EQ(overlay_area, setup.overlay_area()) << seed << " " <<
page_size.ToString() << " " << printable_area << " " << kTextHeight;
EXPECT_EQ(content_area, setup.content_area()) << seed << " " <<
page_size.ToString() << " " << printable_area << " " << kTextHeight;
EXPECT_EQ(effective_margins.header, setup.effective_margins().header) <<
seed << " " << page_size << " " << printable_area << " " << kTextHeight;
seed << " " << page_size.ToString() << " " << printable_area <<
" " << kTextHeight;
EXPECT_EQ(effective_margins.footer, setup.effective_margins().footer) <<
seed << " " << page_size << " " << printable_area << " " << kTextHeight;
seed << " " << page_size.ToString() << " " << printable_area <<
" " << kTextHeight;
EXPECT_EQ(effective_margins.left, setup.effective_margins().left) << seed <<
" " << page_size << " " << printable_area << " " << kTextHeight;
" " << page_size.ToString() << " " << printable_area <<
" " << kTextHeight;
EXPECT_EQ(effective_margins.top, setup.effective_margins().top) << seed <<
" " << page_size << " " << printable_area << " " << kTextHeight;
" " << page_size.ToString() << " " << printable_area <<
" " << kTextHeight;
EXPECT_EQ(effective_margins.right, setup.effective_margins().right) << seed <<
" " << page_size << " " << printable_area << " " << kTextHeight;
" " << page_size.ToString() << " " << printable_area <<
" " << kTextHeight;
EXPECT_EQ(effective_margins.bottom, setup.effective_margins().bottom) <<
seed << " " << page_size << " " << printable_area << " " << kTextHeight;
seed << " " << page_size.ToString() << " " << printable_area <<
" " << kTextHeight;
}
TEST(PageSetupTest, HardCoded) {
@ -124,23 +130,29 @@ TEST(PageSetupTest, HardCoded) {
gfx::Rect content_area(4, 6, 92, 88);
// Test values.
EXPECT_EQ(page_size, setup.physical_size()) << " " << page_size <<
" " << printable_area << " " << kTextHeight;
EXPECT_EQ(overlay_area, setup.overlay_area()) << " " << page_size <<
" " << printable_area << " " << kTextHeight;
EXPECT_EQ(content_area, setup.content_area()) << " " << page_size <<
EXPECT_EQ(page_size, setup.physical_size()) << " " << page_size.ToString() <<
" " << printable_area << " " << kTextHeight;
EXPECT_EQ(overlay_area, setup.overlay_area()) << " " <<
page_size.ToString() << " " << printable_area << " " << kTextHeight;
EXPECT_EQ(content_area, setup.content_area()) << " " <<
page_size.ToString() << " " << printable_area << " " << kTextHeight;
EXPECT_EQ(effective_margins.header, setup.effective_margins().header) <<
" " << page_size << " " << printable_area << " " << kTextHeight;
" " << page_size.ToString() << " " <<
printable_area << " " << kTextHeight;
EXPECT_EQ(effective_margins.footer, setup.effective_margins().footer) <<
" " << page_size << " " << printable_area << " " << kTextHeight;
" " << page_size.ToString() << " " << printable_area <<
" " << kTextHeight;
EXPECT_EQ(effective_margins.left, setup.effective_margins().left) <<
" " << page_size << " " << printable_area << " " << kTextHeight;
" " << page_size.ToString() << " " << printable_area <<
" " << kTextHeight;
EXPECT_EQ(effective_margins.top, setup.effective_margins().top) <<
" " << page_size << " " << printable_area << " " << kTextHeight;
" " << page_size.ToString() << " " << printable_area <<
" " << kTextHeight;
EXPECT_EQ(effective_margins.right, setup.effective_margins().right) <<
" " << page_size << " " << printable_area << " " << kTextHeight;
" " << page_size.ToString() << " " << printable_area <<
" " << kTextHeight;
EXPECT_EQ(effective_margins.bottom, setup.effective_margins().bottom) <<
" " << page_size << " " << printable_area << " " << kTextHeight;
" " << page_size.ToString() << " " << printable_area <<
" " << kTextHeight;
}

@ -274,7 +274,7 @@ bool Rect::SharesEdgeWith(const gfx::Rect& rect) const {
}
std::ostream& operator<<(std::ostream& out, const gfx::Rect& r) {
return out << r.origin().ToString() << " " << r.size();
return out << r.origin().ToString() << " " << r.size().ToString();
}
} // namespace gfx

@ -1,4 +1,4 @@
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Copyright (c) 2011 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.
@ -10,12 +10,13 @@
#include <CoreGraphics/CGGeometry.h>
#endif
#include <ostream>
#include "base/logging.h"
#include "base/stringprintf.h"
namespace gfx {
Size::Size() : width_(0), height_(0) {}
Size::Size(int width, int height) {
set_width(width);
set_height(height);
@ -63,8 +64,8 @@ void Size::set_height(int height) {
height_ = height;
}
std::ostream& operator<<(std::ostream& out, const gfx::Size& s) {
return out << s.width() << "x" << s.height();
std::string Size::ToString() const {
return base::StringPrintf("%dx%d", width_, height_);
}
} // namespace gfx

@ -6,7 +6,7 @@
#define UI_GFX_SIZE_H_
#pragma once
#include <iosfwd>
#include <string>
#include "build/build_config.h"
#include "ui/base/ui_export.h"
@ -22,7 +22,7 @@ namespace gfx {
// A size has width and height values.
class UI_EXPORT Size {
public:
Size() : width_(0), height_(0) {}
Size();
Size(int width, int height);
#if defined(OS_MACOSX)
explicit Size(const CGSize& s);
@ -71,13 +71,13 @@ class UI_EXPORT Size {
CGSize ToCGSize() const;
#endif
std::string ToString() const;
private:
int width_;
int height_;
};
UI_EXPORT std::ostream& operator<<(std::ostream& out, const gfx::Size& s);
} // namespace gfx
#endif // UI_GFX_SIZE_H_