summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkmadhusu@chromium.org <kmadhusu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-26 17:59:01 +0000
committerkmadhusu@chromium.org <kmadhusu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-26 17:59:01 +0000
commit0996e9bc586a81931048ac78c8b8200914320a80 (patch)
tree4bd3e4ac4539262c6efbed7cde6390b46628d944
parent7e52ea6b9fef37ceb75f55ec6a1485d107889d0b (diff)
downloadchromium_src-0996e9bc586a81931048ac78c8b8200914320a80.zip
chromium_src-0996e9bc586a81931048ac78c8b8200914320a80.tar.gz
chromium_src-0996e9bc586a81931048ac78c8b8200914320a80.tar.bz2
PrintPreview: Make ctrl-shift-p start the native print flow.
+ Added PrintPreviewUITest.AdvancedPrintCommandEnabled BUG=93819 TEST=Open a tab. Press ctrl+shift+p to start native print workflow. Review URL: http://codereview.chromium.org/7721001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@98450 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/app/chrome_command_ids.h1
-rw-r--r--chrome/app/chrome_dll.rc1
-rw-r--r--chrome/app/generated_resources.grd4
-rw-r--r--chrome/browser/global_keyboard_shortcuts_mac.mm3
-rw-r--r--chrome/browser/printing/print_view_manager.cc20
-rw-r--r--chrome/browser/printing/print_view_manager.h5
-rw-r--r--chrome/browser/ui/browser.cc13
-rw-r--r--chrome/browser/ui/browser.h1
-rw-r--r--chrome/browser/ui/gtk/accelerators_gtk.cc2
-rw-r--r--chrome/browser/ui/views/accelerator_table_gtk.cc1
-rw-r--r--chrome/browser/ui/webui/print_preview_data_source.cc20
-rw-r--r--chrome/browser/ui/webui/print_preview_handler.cc4
-rw-r--r--chrome/browser/ui/webui/print_preview_handler.h4
-rw-r--r--chrome/browser/ui/webui/print_preview_ui.cc4
-rw-r--r--chrome/browser/ui/webui/print_preview_ui.h3
-rw-r--r--chrome/browser/ui/webui/print_preview_ui_uitest.cc37
16 files changed, 118 insertions, 5 deletions
diff --git a/chrome/app/chrome_command_ids.h b/chrome/app/chrome_command_ids.h
index 5cd38a9..fc60f2e 100644
--- a/chrome/app/chrome_command_ids.h
+++ b/chrome/app/chrome_command_ids.h
@@ -69,6 +69,7 @@
#define IDC_SAVE_PAGE 35004
#define IDC_ENCODING_MENU 35005
#define IDC_EMAIL_PAGE_LOCATION 35006
+#define IDC_ADVANCED_PRINT 35007
// When adding a new encoding to this list, be sure to append it to the
// EncodingMenuController::kValidEncodingIds array in
diff --git a/chrome/app/chrome_dll.rc b/chrome/app/chrome_dll.rc
index b617864..cc25a5b 100644
--- a/chrome/app/chrome_dll.rc
+++ b/chrome/app/chrome_dll.rc
@@ -33,6 +33,7 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
// pick those up in the WM_APPCOMMAND message.
IDR_MAINFRAME ACCELERATORS
BEGIN
+ "P", IDC_ADVANCED_PRINT, VIRTKEY, CONTROL, SHIFT
VK_LEFT, IDC_BACK, VIRTKEY, ALT
VK_BACK, IDC_BACK, VIRTKEY
"D", IDC_BOOKMARK_PAGE, VIRTKEY, CONTROL
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd
index 21343e9..bd2a725 100644
--- a/chrome/app/generated_resources.grd
+++ b/chrome/app/generated_resources.grd
@@ -6015,8 +6015,8 @@ Keep your key file in a safe place. You will need it to create new versions of y
<message name="IDS_PRINT_PREVIEW_PAGE_LABEL_PLURAL" desc="Label shown in the print preview summary.">
pages
</message>
- <message name="IDS_PRINT_PREVIEW_SYSTEM_DIALOG_OPTION" desc="Option allowing the user to access advanced printer settings using the native print system dialog instead of printing through the print preview mechanism.">
- Advanced…
+ <message name="IDS_PRINT_PREVIEW_SYSTEM_DIALOG_OPTION" desc="Option allowing the user to access advanced printer settings using the native print system dialog instead of printing through the print preview mechanism. Shortcut key is not translated">
+ Print using system dialog… <ph name="SHORTCUT_KEY">$1<ex>(Shift+Ctrl+P)</ex></ph>
</message>
<message name="IDS_PRINT_PREVIEW_PAGE_RANGE_INSTRUCTION" desc="Instruction shown when the user enters an invalid page range.">
Invalid page range, use <ph name="EXAMPLE_PAGE_RANGE">$1<ex>e.g. 1-5, 8, 11-13</ex></ph>
diff --git a/chrome/browser/global_keyboard_shortcuts_mac.mm b/chrome/browser/global_keyboard_shortcuts_mac.mm
index 131519b..91990d8 100644
--- a/chrome/browser/global_keyboard_shortcuts_mac.mm
+++ b/chrome/browser/global_keyboard_shortcuts_mac.mm
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 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.
@@ -81,6 +81,7 @@ const KeyboardShortcutData* GetBrowserKeyboardShortcutTable(
{false, false, false, false, kVK_Delete, 0, IDC_BACK},
{false, true, false, false, kVK_Delete, 0, IDC_FORWARD},
{true, true, false, false, 0, 'c', IDC_DEV_TOOLS_INSPECT},
+ {true, true, false, false, 0, 'p', IDC_ADVANCED_PRINT},
};
*num_entries = arraysize(keyboard_shortcuts);
diff --git a/chrome/browser/printing/print_view_manager.cc b/chrome/browser/printing/print_view_manager.cc
index c9b8767..b86573f 100644
--- a/chrome/browser/printing/print_view_manager.cc
+++ b/chrome/browser/printing/print_view_manager.cc
@@ -88,6 +88,26 @@ bool PrintViewManager::PrintForSystemDialogNow() {
return PrintNowInternal(new PrintMsg_PrintForSystemDialog(routing_id()));
}
+bool PrintViewManager::AdvancedPrintNow() {
+ printing::PrintPreviewTabController* tab_controller =
+ printing::PrintPreviewTabController::GetInstance();
+ if (!tab_controller)
+ return false;
+ TabContents* print_preview_tab =
+ tab_controller->GetPrintPreviewForTab(tab_contents());
+ if (print_preview_tab) {
+ // Preview tab exist for current tab or current tab is preview tab.
+ if (!print_preview_tab->web_ui())
+ return false;
+ PrintPreviewUI* print_preview_ui =
+ static_cast<PrintPreviewUI*>(print_preview_tab->web_ui());
+ print_preview_ui->OnShowSystemDialog();
+ return true;
+ } else {
+ return PrintNow();
+ }
+}
+
bool PrintViewManager::PrintPreviewNow() {
return PrintNowInternal(new PrintMsg_InitiatePrintPreview(routing_id()));
}
diff --git a/chrome/browser/printing/print_view_manager.h b/chrome/browser/printing/print_view_manager.h
index a31087a..ec396e4 100644
--- a/chrome/browser/printing/print_view_manager.h
+++ b/chrome/browser/printing/print_view_manager.h
@@ -46,6 +46,11 @@ class PrintViewManager : public NotificationObserver,
// dialog from print preview.
bool PrintForSystemDialogNow();
+ // Same as PrintNow(), but for the case where a user press "ctrl+shift+p" to
+ // show the native system dialog. This can happen from both initiator tab and
+ // preview tab.
+ bool AdvancedPrintNow();
+
// Initiate print preview of the current document by first notifying the
// renderer. Since this happens asynchronous, the print preview tab creation
// will not be completed on the return of this function. Returns false if
diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc
index 8d3dea9..66990b1 100644
--- a/chrome/browser/ui/browser.cc
+++ b/chrome/browser/ui/browser.cc
@@ -61,6 +61,7 @@
#include "chrome/browser/prefs/incognito_mode_prefs.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/printing/cloud_print/cloud_print_setup_flow.h"
+#include "chrome/browser/printing/print_preview_tab_controller.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sessions/restore_tab_helper.h"
#include "chrome/browser/sessions/session_service.h"
@@ -1794,6 +1795,10 @@ void Browser::Print() {
GetSelectedTabContentsWrapper()->print_view_manager()->PrintNow();
}
+void Browser::AdvancedPrint() {
+ GetSelectedTabContentsWrapper()->print_view_manager()->AdvancedPrintNow();
+}
+
void Browser::ToggleEncodingAutoDetect() {
UserMetrics::RecordAction(UserMetricsAction("AutoDetectChange"));
encoding_auto_detect_.SetValue(!encoding_auto_detect_.GetValue());
@@ -2588,6 +2593,7 @@ void Browser::ExecuteCommandWithDisposition(
case IDC_VIEW_SOURCE: ViewSelectedSource(); break;
case IDC_EMAIL_PAGE_LOCATION: EmailPageLocation(); break;
case IDC_PRINT: Print(); break;
+ case IDC_ADVANCED_PRINT: AdvancedPrint(); break;
case IDC_ENCODING_AUTO_DETECT: ToggleEncodingAutoDetect(); break;
case IDC_ENCODING_UTF8:
case IDC_ENCODING_UTF16LE:
@@ -4377,13 +4383,20 @@ void Browser::UpdateCommandsForContentRestrictionState() {
void Browser::UpdatePrintingState(int content_restrictions) {
bool enabled = true;
+ bool selected_tab_is_preview_tab = false;
if (content_restrictions & CONTENT_RESTRICTION_PRINT) {
enabled = false;
+ selected_tab_is_preview_tab =
+ printing::PrintPreviewTabController::IsPrintPreviewTab(
+ GetSelectedTabContents());
} else if (g_browser_process->local_state()) {
enabled = g_browser_process->local_state()->
GetBoolean(prefs::kPrintingEnabled);
}
command_updater_.UpdateCommandEnabled(IDC_PRINT, enabled);
+ command_updater_.UpdateCommandEnabled(IDC_ADVANCED_PRINT,
+ selected_tab_is_preview_tab ? true :
+ enabled);
}
void Browser::UpdateReloadStopState(bool is_loading, bool force) {
diff --git a/chrome/browser/ui/browser.h b/chrome/browser/ui/browser.h
index 144b28c..df08d1e5 100644
--- a/chrome/browser/ui/browser.h
+++ b/chrome/browser/ui/browser.h
@@ -531,6 +531,7 @@ class Browser : public TabHandlerDelegate,
// TODO(port): port these, and re-merge the two function declaration lists.
// Page-related commands.
void Print();
+ void AdvancedPrint();
void EmailPageLocation();
void ToggleEncodingAutoDetect();
void OverrideEncoding(int encoding_id);
diff --git a/chrome/browser/ui/gtk/accelerators_gtk.cc b/chrome/browser/ui/gtk/accelerators_gtk.cc
index b068e272..313efff 100644
--- a/chrome/browser/ui/gtk/accelerators_gtk.cc
+++ b/chrome/browser/ui/gtk/accelerators_gtk.cc
@@ -154,6 +154,8 @@ const struct AcceleratorMapping {
{ GDK_o, IDC_OPEN_FILE, GDK_CONTROL_MASK },
{ GDK_f, IDC_FIND, GDK_CONTROL_MASK },
{ GDK_p, IDC_PRINT, GDK_CONTROL_MASK },
+ { GDK_p, IDC_ADVANCED_PRINT,
+ GdkModifierType(GDK_CONTROL_MASK | GDK_SHIFT_MASK) },
{ GDK_b, IDC_SHOW_BOOKMARK_BAR,
GdkModifierType(GDK_CONTROL_MASK | GDK_SHIFT_MASK) },
{ GDK_o, IDC_SHOW_BOOKMARK_MANAGER,
diff --git a/chrome/browser/ui/views/accelerator_table_gtk.cc b/chrome/browser/ui/views/accelerator_table_gtk.cc
index a4c475b..5a21723 100644
--- a/chrome/browser/ui/views/accelerator_table_gtk.cc
+++ b/chrome/browser/ui/views/accelerator_table_gtk.cc
@@ -95,6 +95,7 @@ const AcceleratorMapping kAcceleratorMap[] = {
{ ui::VKEY_N, false, true, false, IDC_NEW_WINDOW },
{ ui::VKEY_O, false, true, false, IDC_OPEN_FILE },
{ ui::VKEY_P, false, true, false, IDC_PRINT},
+ { ui::VKEY_P, true, true, false, IDC_ADVANCED_PRINT},
{ ui::VKEY_R, false, true, false, IDC_RELOAD },
{ ui::VKEY_R, true, true, false, IDC_RELOAD_IGNORING_CACHE },
#if !defined(OS_CHROMEOS)
diff --git a/chrome/browser/ui/webui/print_preview_data_source.cc b/chrome/browser/ui/webui/print_preview_data_source.cc
index ed9bf95..d445113 100644
--- a/chrome/browser/ui/webui/print_preview_data_source.cc
+++ b/chrome/browser/ui/webui/print_preview_data_source.cc
@@ -23,6 +23,19 @@
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
+namespace{
+
+#if defined(OS_MACOSX)
+// U+0028 U+21E7 U+2318 U+0050 U+0029 in UTF8
+const char kAdvancedPrintShortcut[] = "\x28\xE2\x8C\x98\xE2\x87\xA7\x50\x29";
+#elif defined(OS_WIN)
+const char kAdvancedPrintShortcut[] = "(Ctrl+Shift+P)";
+#else
+const char kAdvancedPrintShortcut[] = "(Shift+Ctrl+P)";
+#endif
+
+}; // namespace
+
PrintPreviewDataSource::PrintPreviewDataSource()
: ChromeWebUIDataSource(chrome::kChromeUIPrintHost) {
@@ -77,8 +90,11 @@ PrintPreviewDataSource::PrintPreviewDataSource()
IDS_PRINT_PREVIEW_PAGE_LABEL_SINGULAR);
AddLocalizedString("printPreviewPageLabelPlural",
IDS_PRINT_PREVIEW_PAGE_LABEL_PLURAL);
- AddLocalizedString("systemDialogOption",
- IDS_PRINT_PREVIEW_SYSTEM_DIALOG_OPTION);
+ const string16 shortcut_text(UTF8ToUTF16(kAdvancedPrintShortcut));
+ AddString("systemDialogOption", l10n_util::GetStringFUTF16(
+ IDS_PRINT_PREVIEW_SYSTEM_DIALOG_OPTION,
+ shortcut_text));
+
AddLocalizedString("pageRangeInstruction",
IDS_PRINT_PREVIEW_PAGE_RANGE_INSTRUCTION);
AddLocalizedString("copiesInstruction", IDS_PRINT_PREVIEW_COPIES_INSTRUCTION);
diff --git a/chrome/browser/ui/webui/print_preview_handler.cc b/chrome/browser/ui/webui/print_preview_handler.cc
index b9c55e6..b416380 100644
--- a/chrome/browser/ui/webui/print_preview_handler.cc
+++ b/chrome/browser/ui/webui/print_preview_handler.cc
@@ -895,6 +895,10 @@ void PrintPreviewHandler::OnPrintPreviewFailed() {
ReportUserActionHistogram(PREVIEW_FAILED);
}
+void PrintPreviewHandler::ShowSystemDialog() {
+ HandleShowSystemDialog(NULL);
+}
+
void PrintPreviewHandler::FileSelected(const FilePath& path,
int index, void* params) {
PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_);
diff --git a/chrome/browser/ui/webui/print_preview_handler.h b/chrome/browser/ui/webui/print_preview_handler.h
index abee16c..d872f3b 100644
--- a/chrome/browser/ui/webui/print_preview_handler.h
+++ b/chrome/browser/ui/webui/print_preview_handler.h
@@ -58,6 +58,10 @@ class PrintPreviewHandler : public WebUIMessageHandler,
// Called when print preview failed.
void OnPrintPreviewFailed();
+ // Called when the user press ctrl+shift+p to display the native system
+ // dialog.
+ void ShowSystemDialog();
+
private:
friend class PrintSystemTaskProxy;
diff --git a/chrome/browser/ui/webui/print_preview_ui.cc b/chrome/browser/ui/webui/print_preview_ui.cc
index 007fc27..208d207 100644
--- a/chrome/browser/ui/webui/print_preview_ui.cc
+++ b/chrome/browser/ui/webui/print_preview_ui.cc
@@ -146,6 +146,10 @@ void PrintPreviewUI::OnPrintPreviewRequest(int request_id) {
g_print_preview_request_id_map.Get().Set(preview_ui_addr_str_, request_id);
}
+void PrintPreviewUI::OnShowSystemDialog() {
+ CallJavascriptFunction("onSystemDialogLinkClicked");
+}
+
void PrintPreviewUI::OnDidGetPreviewPageCount(
const PrintHostMsg_DidGetPreviewPageCount_Params& params) {
DCHECK_GT(params.page_count, 0);
diff --git a/chrome/browser/ui/webui/print_preview_ui.h b/chrome/browser/ui/webui/print_preview_ui.h
index 73f7c3e..589f441 100644
--- a/chrome/browser/ui/webui/print_preview_ui.h
+++ b/chrome/browser/ui/webui/print_preview_ui.h
@@ -58,6 +58,9 @@ class PrintPreviewUI : public ChromeWebUI {
// Notifies the Web UI of a print preview request with |request_id|.
void OnPrintPreviewRequest(int request_id);
+ // Notifies the Web UI to show the system dialog.
+ void OnShowSystemDialog();
+
// Notifies the Web UI about the page count of the request preview.
void OnDidGetPreviewPageCount(
const PrintHostMsg_DidGetPreviewPageCount_Params& params);
diff --git a/chrome/browser/ui/webui/print_preview_ui_uitest.cc b/chrome/browser/ui/webui/print_preview_ui_uitest.cc
index 3d5ddf6..a8bba38 100644
--- a/chrome/browser/ui/webui/print_preview_ui_uitest.cc
+++ b/chrome/browser/ui/webui/print_preview_ui_uitest.cc
@@ -72,4 +72,41 @@ TEST_F(PrintPreviewUITest, PrintCommandDisabled) {
ASSERT_FALSE(enabled);
}
+TEST_F(PrintPreviewUITest, AdvancedPrintCommandEnabled) {
+ scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
+ ASSERT_TRUE(browser.get());
+
+ // Go to the about:blank page.
+ NavigateToURL(GURL(chrome::kAboutBlankURL));
+
+ // Make sure there is 1 tab and print is enabled. Create print preview tab.
+ int tab_count;
+ ASSERT_TRUE(browser->GetTabCount(&tab_count));
+ ASSERT_EQ(1, tab_count);
+ bool enabled;
+ ASSERT_TRUE(browser->IsMenuCommandEnabled(IDC_PRINT, &enabled));
+ ASSERT_TRUE(enabled);
+
+ // Make sure advanced print command (Ctrl+Shift+p) is enabled.
+ enabled = false;
+ ASSERT_TRUE(browser->IsMenuCommandEnabled(IDC_ADVANCED_PRINT, &enabled));
+ ASSERT_TRUE(enabled);
+
+ ASSERT_TRUE(browser->RunCommand(IDC_PRINT));
+
+ // Make sure there are 2 tabs and print is disabled.
+ ASSERT_TRUE(browser->GetTabCount(&tab_count));
+ ASSERT_EQ(2, tab_count);
+ scoped_refptr<TabProxy> tab = browser->GetActiveTab();
+ ASSERT_TRUE(tab.get());
+ AssertIsPrintPage(tab);
+ ASSERT_TRUE(browser->IsMenuCommandEnabled(IDC_PRINT, &enabled));
+ ASSERT_FALSE(enabled);
+
+ // Make sure advanced print command (Ctrl+Shift+p) is enabled on preview tab.
+ enabled = false;
+ ASSERT_TRUE(browser->IsMenuCommandEnabled(IDC_ADVANCED_PRINT, &enabled));
+ ASSERT_TRUE(enabled);
+}
+
} // namespace