diff options
author | maruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-20 17:55:55 +0000 |
---|---|---|
committer | maruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-20 17:55:55 +0000 |
commit | 4ae30d08d2df7fdb8b236b6c650a1a29a84ee562 (patch) | |
tree | 97a77e2c9bbab02533378c88aa3311cd2353562b /chrome/browser | |
parent | de4024067816c20a69189c1e0d7728aa2cf16d66 (diff) | |
download | chromium_src-4ae30d08d2df7fdb8b236b6c650a1a29a84ee562.zip chromium_src-4ae30d08d2df7fdb8b236b6c650a1a29a84ee562.tar.gz chromium_src-4ae30d08d2df7fdb8b236b6c650a1a29a84ee562.tar.bz2 |
Move units to new module printing. Add printing_unittests on Windows too. Make test_shell and chrome_dll dependent on printing.
Review URL: http://codereview.chromium.org/21475
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10105 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/browser.scons | 2 | ||||
-rw-r--r-- | chrome/browser/browser.vcproj | 24 | ||||
-rw-r--r-- | chrome/browser/printing/print_settings.cc | 20 | ||||
-rw-r--r-- | chrome/browser/printing/printed_document.cc | 2 | ||||
-rw-r--r-- | chrome/browser/printing/units.cc | 43 | ||||
-rw-r--r-- | chrome/browser/printing/units.h | 28 | ||||
-rw-r--r-- | chrome/browser/printing/units_unittest.cc | 54 |
7 files changed, 22 insertions, 151 deletions
diff --git a/chrome/browser/browser.scons b/chrome/browser/browser.scons index b3fbc7f..1d2d6df 100644 --- a/chrome/browser/browser.scons +++ b/chrome/browser/browser.scons @@ -369,8 +369,6 @@ input_files = ChromeFileList([ 'printing/printed_pages_source.h', 'printing/printer_query.cc', 'printing/printer_query.h', - 'printing/units.cc', - 'printing/units.h', 'printing/win_printing_context.cc', 'printing/win_printing_context.h', ]), diff --git a/chrome/browser/browser.vcproj b/chrome/browser/browser.vcproj index 11070f7..bd61f95 100644 --- a/chrome/browser/browser.vcproj +++ b/chrome/browser/browser.vcproj @@ -410,14 +410,6 @@ > </File> <File - RelativePath=".\process_singleton_win.cc" - > - </File> - <File - RelativePath=".\process_singleton.h" - > - </File> - <File RelativePath=".\meta_table_helper.cc" > </File> @@ -466,6 +458,14 @@ > </File> <File + RelativePath=".\process_singleton.h" + > + </File> + <File + RelativePath=".\process_singleton_win.cc" + > + </File> + <File RelativePath=".\profile.cc" > </File> @@ -1406,14 +1406,6 @@ > </File> <File - RelativePath=".\printing\units.cc" - > - </File> - <File - RelativePath=".\printing\units.h" - > - </File> - <File RelativePath=".\printing\win_printing_context.cc" > </File> diff --git a/chrome/browser/printing/print_settings.cc b/chrome/browser/printing/print_settings.cc index e98b06e..6f3f156 100644 --- a/chrome/browser/printing/print_settings.cc +++ b/chrome/browser/printing/print_settings.cc @@ -6,8 +6,8 @@ #include "base/atomic_sequence_num.h" #include "base/logging.h" -#include "chrome/browser/printing/units.h" #include "chrome/common/render_messages.h" +#include "printing/units.h" namespace printing { @@ -65,7 +65,8 @@ void PrintSettings::Init(HDC hdc, GetDeviceCaps(hdc, HORZRES), GetDeviceCaps(hdc, VERTRES)); // Hard-code text_height = 0.5cm = ~1/5 of inch - page_setup_pixels_.Init(physical_size_pixels, printable_area_pixels, + page_setup_pixels_.Init(physical_size_pixels, + printable_area_pixels, ConvertUnit(500, kHundrethsMMPerInch, dpi_)); // Initialize page_setup_cmm_. @@ -104,16 +105,21 @@ void PrintSettings::UpdateMarginsMetric(const PageMargins& new_margins) { // Converts the margins in dpi unit and apply those too. PageMargins pixels_margins; - pixels_margins.header = ConvertUnit(new_margins.header, kHundrethsMMPerInch, + pixels_margins.header = ConvertUnit(new_margins.header, + kHundrethsMMPerInch, dpi_); - pixels_margins.footer = ConvertUnit(new_margins.footer, kHundrethsMMPerInch, + pixels_margins.footer = ConvertUnit(new_margins.footer, + kHundrethsMMPerInch, dpi_); - pixels_margins.left = ConvertUnit(new_margins.left, kHundrethsMMPerInch, + pixels_margins.left = ConvertUnit(new_margins.left, + kHundrethsMMPerInch, dpi_); pixels_margins.top = ConvertUnit(new_margins.top, kHundrethsMMPerInch, dpi_); - pixels_margins.right = ConvertUnit(new_margins.right, kHundrethsMMPerInch, + pixels_margins.right = ConvertUnit(new_margins.right, + kHundrethsMMPerInch, dpi_); - pixels_margins.bottom = ConvertUnit(new_margins.bottom, kHundrethsMMPerInch, + pixels_margins.bottom = ConvertUnit(new_margins.bottom, + kHundrethsMMPerInch, dpi_); page_setup_pixels_.SetRequestedMargins(pixels_margins); } diff --git a/chrome/browser/printing/printed_document.cc b/chrome/browser/printing/printed_document.cc index 21535b2..589085b 100644 --- a/chrome/browser/printing/printed_document.cc +++ b/chrome/browser/printing/printed_document.cc @@ -12,13 +12,13 @@ #include "chrome/browser/printing/page_overlays.h" #include "chrome/browser/printing/printed_pages_source.h" #include "chrome/browser/printing/printed_page.h" -#include "chrome/browser/printing/units.h" #include "chrome/common/gfx/chrome_font.h" #include "chrome/common/gfx/emf.h" #include "chrome/common/gfx/text_elider.h" #include "chrome/common/time_format.h" #include "chrome/common/notification_service.h" #include "chrome/common/win_util.h" +#include "printing/units.h" #include "skia/ext/platform_device.h" using base::Time; diff --git a/chrome/browser/printing/units.cc b/chrome/browser/printing/units.cc deleted file mode 100644 index 9d48676..0000000 --- a/chrome/browser/printing/units.cc +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (c) 2006-2008 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. - -#include "chrome/browser/printing/units.h" - -#include "base/logging.h" - -namespace printing { - -int ConvertUnit(int value, int old_unit, int new_unit) { - DCHECK_GT(new_unit, 0); - DCHECK_GT(old_unit, 0); - // With integer arithmetic, to divide a value with correct rounding, you need - // to add half of the divisor value to the dividend value. You need to do the - // reverse with negative number. - if (value >= 0) { - return ((value * new_unit) + (old_unit / 2)) / old_unit; - } else { - return ((value * new_unit) - (old_unit / 2)) / old_unit; - } -} - -double ConvertUnitDouble(double value, double old_unit, double new_unit) { - DCHECK_GT(new_unit, 0); - DCHECK_GT(old_unit, 0); - return value * new_unit / old_unit; -} - -int ConvertMilliInchToHundredThousanthMeter(int milli_inch) { - // 1" == 25.4 mm - // 1" == 25400 um - // 0.001" == 25.4 um - // 0.001" == 2.54 cmm - return ConvertUnit(milli_inch, 100, 254); -} - -int ConvertHundredThousanthMeterToMilliInch(int cmm) { - return ConvertUnit(cmm, 254, 100); -} - -} // namespace printing - diff --git a/chrome/browser/printing/units.h b/chrome/browser/printing/units.h deleted file mode 100644 index aad3795..0000000 --- a/chrome/browser/printing/units.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) 2006-2008 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 CHROME_BROWSER_PRINTING_UNITS_H__ -#define CHROME_BROWSER_PRINTING_UNITS_H__ - -namespace printing { - -// Length of a thousanth of inches in 0.01mm unit. -const int kHundrethsMMPerInch = 2540; - -// Converts from one unit system to another using integer arithmetics. -int ConvertUnit(int value, int old_unit, int new_unit); - -// Converts from one unit system to another using doubles. -double ConvertUnitDouble(double value, double old_unit, double new_unit); - -// Converts from 0.001 inch unit to 0.00001 meter. -int ConvertMilliInchToHundredThousanthMeter(int milli_inch); - -// Converts from 0.00001 meter unit to 0.001 inch. -int ConvertHundredThousanthMeterToMilliInch(int cmm); - -} // namespace printing - -#endif // CHROME_BROWSER_PRINTING_UNITS_H__ - diff --git a/chrome/browser/printing/units_unittest.cc b/chrome/browser/printing/units_unittest.cc deleted file mode 100644 index ff85cb6..0000000 --- a/chrome/browser/printing/units_unittest.cc +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright (c) 2006-2008 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. - -#include "chrome/browser/printing/units.h" -#include "testing/gtest/include/gtest/gtest.h" -#include "testing/gtest/include/gtest/gtest-spi.h" - -using namespace printing; - -TEST(UnitsTest, Convertions) { - EXPECT_EQ(100, ConvertUnit(100, 100, 100)); - EXPECT_EQ(-100, ConvertUnit(-100, 100, 100)); - EXPECT_EQ(0, ConvertUnit(0, 100, 100)); - EXPECT_EQ(99, ConvertUnit(99, 100, 100)); - EXPECT_EQ(101, ConvertUnit(101, 100, 100)); - EXPECT_EQ(99900, ConvertUnit(999, 10, 1000)); - EXPECT_EQ(100100, ConvertUnit(1001, 10, 1000)); - - // Rounding. - EXPECT_EQ(10, ConvertUnit(999, 1000, 10)); - EXPECT_EQ(10, ConvertUnit(950, 1000, 10)); - EXPECT_EQ(9, ConvertUnit(949, 1000, 10)); - EXPECT_EQ(10, ConvertUnit(1001, 1000, 10)); - EXPECT_EQ(10, ConvertUnit(1049, 1000, 10)); - EXPECT_EQ(11, ConvertUnit(1050, 1000, 10)); - EXPECT_EQ(-10, ConvertUnit(-999, 1000, 10)); - EXPECT_EQ(-10, ConvertUnit(-950, 1000, 10)); - EXPECT_EQ(-9, ConvertUnit(-949, 1000, 10)); - EXPECT_EQ(-10, ConvertUnit(-1001, 1000, 10)); - EXPECT_EQ(-10, ConvertUnit(-1049, 1000, 10)); - EXPECT_EQ(-11, ConvertUnit(-1050, 1000, 10)); - - EXPECT_EQ(0, ConvertUnit(2, 1000000000, 1)); - EXPECT_EQ(2000000000, ConvertUnit(2, 1, 1000000000)); - EXPECT_EQ(4000000000U, - static_cast<unsigned int>(ConvertUnit(2, 1, 2000000000))); - - EXPECT_EQ(100, ConvertUnitDouble(100, 100, 100)); - EXPECT_EQ(-100, ConvertUnitDouble(-100, 100, 100)); - EXPECT_EQ(0, ConvertUnitDouble(0, 100, 100)); - EXPECT_EQ(0.000002, ConvertUnitDouble(2, 1000, 0.001)); - EXPECT_EQ(2000000, ConvertUnitDouble(2, 0.001, 1000)); - - EXPECT_EQ(kHundrethsMMPerInch, ConvertMilliInchToHundredThousanthMeter(1000)); - EXPECT_EQ(-kHundrethsMMPerInch, - ConvertMilliInchToHundredThousanthMeter(-1000)); - EXPECT_EQ(0, ConvertMilliInchToHundredThousanthMeter(0)); - EXPECT_EQ(1000, ConvertHundredThousanthMeterToMilliInch(kHundrethsMMPerInch)); - EXPECT_EQ(-1000, - ConvertHundredThousanthMeterToMilliInch(-kHundrethsMMPerInch)); - EXPECT_EQ(0, ConvertHundredThousanthMeterToMilliInch(0)); -} - |