From d7546c4042bb93eb0be113debc9678b3ac7045c7 Mon Sep 17 00:00:00 2001 From: "maruel@chromium.org" Date: Thu, 9 Apr 2009 16:36:44 +0000 Subject: Implement Printer Preference Persistence (Step 1/3) Introduce new "Preferences" for printer overlays were added in PrefNames: - printing.page.header.left - printing.page.header.center - printing.page.header.right - printing.page.footer.left - printing.page.footer.center - printing.page.footer.right The prefs file will look like this: "printing": { "page": { "header": { "left": " ", "center": " ", "right": " " }, "footer": { "left": "{date}", "center": " ", "right": " " } } } The steps for Printer Preferences: Step 1: Introduce some sort of persistence for header/footer which is located in the Preference file. Step 2: Allow PrinterQuery to read those stored preferences and setup PrinterSettings so that it will apply it when printing. Step 3: Create a UI for the print preference, so that the users will easily change those printing settings. NOTE: I tested the following approach while doing a simple Hack with PrintJob (if you see the previous patch), and it works great, with some bad after effect. It was done for testing purposes. So I hope we are going in the right direction. BUG=947 (http://crbug.com/947) Patch contributed by Mohamed Mansour Review: http://codereview.chromium.org/60118/show git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13426 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/printing/page_overlays.cc | 50 ++++++++++++++++++++++- chrome/browser/printing/page_overlays.h | 6 ++- chrome/browser/printing/page_overlays_unittest.cc | 15 ++++++- chrome/common/pref_names.cc | 10 ++++- chrome/common/pref_names.h | 9 +++- 5 files changed, 84 insertions(+), 6 deletions(-) (limited to 'chrome') diff --git a/chrome/browser/printing/page_overlays.cc b/chrome/browser/printing/page_overlays.cc index eb1d3c6..4a20dd6 100644 --- a/chrome/browser/printing/page_overlays.cc +++ b/chrome/browser/printing/page_overlays.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2006-2009 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. @@ -84,6 +84,54 @@ const std::wstring& PageOverlays::GetOverlay(HorizontalPosition x, return EmptyWString(); } +void PageOverlays::SetOverlay(HorizontalPosition x, VerticalPosition y, + std::wstring& input) { + switch (x) { + case LEFT: + switch (y) { + case TOP: + top_left = input; + break; + case BOTTOM: + bottom_left = input; + break; + default: + NOTREACHED(); + break; + } + break; + case CENTER: + switch (y) { + case TOP: + top_center = input; + break; + case BOTTOM: + bottom_center = input; + break; + default: + NOTREACHED(); + break; + } + break; + case RIGHT: + switch (y) { + case TOP: + top_right = input; + break; + case BOTTOM: + bottom_right = input; + break; + default: + NOTREACHED(); + break; + } + break; + default: + NOTREACHED(); + break; + } +} + //static std::wstring PageOverlays::ReplaceVariables(const std::wstring& input, const PrintedDocument& document, diff --git a/chrome/browser/printing/page_overlays.h b/chrome/browser/printing/page_overlays.h index 42e77fc..7663153 100644 --- a/chrome/browser/printing/page_overlays.h +++ b/chrome/browser/printing/page_overlays.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2006-2009 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. @@ -39,6 +39,10 @@ class PageOverlays { const std::wstring& GetOverlay(HorizontalPosition x, VerticalPosition y) const; + // Sets the string of an overlay according to its x,y position. + void SetOverlay(HorizontalPosition x, VerticalPosition y, + std::wstring& input); + // Replaces the variables in |input| with their actual values according to the // properties of the current printed document and the current printed page. static std::wstring ReplaceVariables(const std::wstring& input, diff --git a/chrome/browser/printing/page_overlays_unittest.cc b/chrome/browser/printing/page_overlays_unittest.cc index 04104a8..0710f33 100644 --- a/chrome/browser/printing/page_overlays_unittest.cc +++ b/chrome/browser/printing/page_overlays_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2006-2009 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. @@ -73,4 +73,17 @@ TEST_F(PageOverlaysTest, StringConversion) { EXPECT_EQ(StringPrintf(L"foo%lsbar", kOverlayKeys[i].expected), out) << kOverlayKeys[i].key; } + + // Check if SetOverlay really sets the page overlay. + overlays.SetOverlay(printing::PageOverlays::LEFT, + printing::PageOverlays::TOP, + UTF16ToWide(L"Page {page}")); + input = overlays.GetOverlay(printing::PageOverlays::LEFT, + printing::PageOverlays::TOP); + EXPECT_EQ(input, L"Page {page}"); + + // Replace the variables to see if the page number is correct. + out = printing::PageOverlays::ReplaceVariables(input, *doc.get(), + *page.get()); + EXPECT_EQ(out, L"Page 1"); } diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc index d2608c5..300e6ab 100644 --- a/chrome/common/pref_names.cc +++ b/chrome/common/pref_names.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2006-2009 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. @@ -235,6 +235,14 @@ const wchar_t kBookmarkManagerSplitLocation[] = // Boolean pref to define the default values for using spellchecker. const wchar_t kEnableSpellCheck[] = L"browser.enable_spellchecking"; +// String pref to define the default values for print overlays. +const wchar_t kPrintingPageHeaderLeft[] = L"printing.page.header.left"; +const wchar_t kPrintingPageHeaderCenter[] = L"printing.page.header.center"; +const wchar_t kPrintingPageHeaderRight[] = L"printing.page.header.right"; +const wchar_t kPrintingPageFooterLeft[] = L"printing.page.footer.left"; +const wchar_t kPrintingPageFooterCenter[] = L"printing.page.footer.center"; +const wchar_t kPrintingPageFooterRight[] = L"printing.page.footer.right"; + // *************** LOCAL STATE *************** // These are attached to the machine/installation diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h index f3c2b15..9ca99fa 100644 --- a/chrome/common/pref_names.h +++ b/chrome/common/pref_names.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2006-2009 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. @@ -81,7 +81,12 @@ extern const wchar_t kBookmarkManagerPlacement[]; extern const wchar_t kBookmarkManagerSplitLocation[]; extern const wchar_t kEnableSpellCheck[]; extern const wchar_t kDeleteTimePeriod[]; - +extern const wchar_t kPrintingPageHeaderLeft[]; +extern const wchar_t kPrintingPageHeaderCenter[]; +extern const wchar_t kPrintingPageHeaderRight[]; +extern const wchar_t kPrintingPageFooterLeft[]; +extern const wchar_t kPrintingPageFooterCenter[]; +extern const wchar_t kPrintingPageFooterRight[]; // Local state extern const wchar_t kAvailableProfiles[]; -- cgit v1.1