diff options
author | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-29 02:36:26 +0000 |
---|---|---|
committer | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-29 02:36:26 +0000 |
commit | c48bee274f6c6869430bdda4ce771c8cdabf736f (patch) | |
tree | 7ce89dceab0e9dd2d2a7f7426a429f68201a8782 /chrome/browser/ui/webui | |
parent | e555f205eb8931da7fdf0f4cb4a01a24c3e2bf8a (diff) | |
download | chromium_src-c48bee274f6c6869430bdda4ce771c8cdabf736f.zip chromium_src-c48bee274f6c6869430bdda4ce771c8cdabf736f.tar.gz chromium_src-c48bee274f6c6869430bdda4ce771c8cdabf736f.tar.bz2 |
Print Preview: Implement basic settings.
BUG=57902
TEST=Run with --enable-print-preview, make sure orientation and color settings work.
Review URL: http://codereview.chromium.org/6736014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@79655 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui/webui')
-rw-r--r-- | chrome/browser/ui/webui/print_preview_handler.cc | 43 | ||||
-rw-r--r-- | chrome/browser/ui/webui/print_preview_handler.h | 15 |
2 files changed, 56 insertions, 2 deletions
diff --git a/chrome/browser/ui/webui/print_preview_handler.cc b/chrome/browser/ui/webui/print_preview_handler.cc index 45f316b..b828070 100644 --- a/chrome/browser/ui/webui/print_preview_handler.cc +++ b/chrome/browser/ui/webui/print_preview_handler.cc @@ -15,9 +15,13 @@ #include "content/browser/renderer_host/render_view_host.h" #include "content/browser/tab_contents/tab_contents.h" #include "printing/backend/print_backend.h" +#include "printing/print_job_constants.h" namespace { +const bool kColorDefaultValue = false; +const bool kLandscapeDefaultValue = false; + TabContents* GetInitiatorTab(TabContents* preview_tab) { printing::PrintPreviewTabController* tab_controller = printing::PrintPreviewTabController::GetInstance(); @@ -26,6 +30,8 @@ TabContents* GetInitiatorTab(TabContents* preview_tab) { return tab_controller->GetInitiatorTab(preview_tab); } +// Get the print job settings dictionary from |args|. The caller takes +// ownership of the returned DictionaryValue. Returns NULL on failure. DictionaryValue* GetSettingsDictionary(const ListValue* args) { std::string json_str; if (!args->GetString(0, &json_str)) { @@ -100,7 +106,10 @@ class EnumeratePrintersTaskProxy }; PrintPreviewHandler::PrintPreviewHandler() - : print_backend_(printing::PrintBackend::CreateInstance(NULL)) { + : print_backend_(printing::PrintBackend::CreateInstance(NULL)), + need_to_generate_preview_(true), + color_(kColorDefaultValue), + landscape_(kLandscapeDefaultValue) { } PrintPreviewHandler::~PrintPreviewHandler() { @@ -131,7 +140,17 @@ void PrintPreviewHandler::HandleGetPreview(const ListValue* args) { scoped_ptr<DictionaryValue> settings(GetSettingsDictionary(args)); if (!settings.get()) return; - initiator_tab->render_view_host()->PrintPreview(*settings); + + // Handle settings that do not require print preview regeneration. + ProcessColorSetting(*settings); + + // Handle settings that require print preview regeneration. + ProcessLandscapeSetting(*settings); + + if (need_to_generate_preview_) { + initiator_tab->render_view_host()->PrintPreview(*settings); + need_to_generate_preview_ = false; + } } void PrintPreviewHandler::HandlePrint(const ListValue* args) { @@ -150,3 +169,23 @@ void PrintPreviewHandler::HandlePrint(const ListValue* args) { void PrintPreviewHandler::SendPrinterList(const ListValue& printers) { web_ui_->CallJavascriptFunction("setPrinters", printers); } + +void PrintPreviewHandler::ProcessColorSetting(const DictionaryValue& settings) { + bool color = kColorDefaultValue; + settings.GetBoolean(printing::kSettingColor, &color); + if (color != color_) { + color_ = color; + FundamentalValue color_value(color_); + web_ui_->CallJavascriptFunction("setColor", color_value); + } +} + +void PrintPreviewHandler::ProcessLandscapeSetting( + const DictionaryValue& settings) { + bool landscape = kLandscapeDefaultValue; + settings.GetBoolean(printing::kSettingLandscape, &landscape); + if (landscape != landscape_) { + landscape_ = landscape; + need_to_generate_preview_ = true; + } +} diff --git a/chrome/browser/ui/webui/print_preview_handler.h b/chrome/browser/ui/webui/print_preview_handler.h index 9f11707..108234e 100644 --- a/chrome/browser/ui/webui/print_preview_handler.h +++ b/chrome/browser/ui/webui/print_preview_handler.h @@ -43,9 +43,24 @@ class PrintPreviewHandler : public WebUIMessageHandler, // Send the list of printers to the Web UI. void SendPrinterList(const ListValue& printers); + // Helper function to process the color setting in the dictionary. + void ProcessColorSetting(const DictionaryValue& settings); + + // Helper function to process the landscape setting in the dictionary. + void ProcessLandscapeSetting(const DictionaryValue& settings); + // Pointer to current print system. scoped_refptr<printing::PrintBackend> print_backend_; + // Set to true if we need to generate a new print preview. + bool need_to_generate_preview_; + + // Set to true if the preview should be in color. + bool color_; + + // Set to true if the preview should be landscape. + bool landscape_; + DISALLOW_COPY_AND_ASSIGN(PrintPreviewHandler); }; |