diff options
author | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-12 19:55:04 +0000 |
---|---|---|
committer | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-12 19:55:04 +0000 |
commit | f22ff88946f2298ca25b2f43c560aaf9887cb39a (patch) | |
tree | e6e96f18a5dcf60a7211dafc6c61ce33222d6cf8 | |
parent | ccbca9e7c4a4bf30e0decbd841ddbefe27e5a89c (diff) | |
download | chromium_src-f22ff88946f2298ca25b2f43c560aaf9887cb39a.zip chromium_src-f22ff88946f2298ca25b2f43c560aaf9887cb39a.tar.gz chromium_src-f22ff88946f2298ca25b2f43c560aaf9887cb39a.tar.bz2 |
Merge 113943 - Print preview: Disable the right context menu items in print preview.
BUG=106876,106915
TEST=see bug
Review URL: http://codereview.chromium.org/8879046
TBR=thestig@chromium.org
Review URL: http://codereview.chromium.org/8905016
git-svn-id: svn://svn.chromium.org/chrome/branches/963/src@114061 0039d316-1c4b-4281-b951-d872f2087c98
5 files changed, 100 insertions, 0 deletions
diff --git a/chrome/browser/printing/print_preview_context_menu_observer.cc b/chrome/browser/printing/print_preview_context_menu_observer.cc new file mode 100644 index 0000000..305a8b1 --- /dev/null +++ b/chrome/browser/printing/print_preview_context_menu_observer.cc @@ -0,0 +1,53 @@ +// 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. + +#include "chrome/browser/printing/print_preview_context_menu_observer.h" + +#include "base/logging.h" +#include "chrome/app/chrome_command_ids.h" +#include "chrome/browser/printing/print_preview_tab_controller.h" + +PrintPreviewContextMenuObserver::PrintPreviewContextMenuObserver( + TabContentsWrapper* tab) : tab_(tab) { +} + +PrintPreviewContextMenuObserver::~PrintPreviewContextMenuObserver() { +} + +bool PrintPreviewContextMenuObserver::IsPrintPreviewTab() { + printing::PrintPreviewTabController* controller = + printing::PrintPreviewTabController::GetInstance(); + if (!controller) + return false; + return !!controller->GetPrintPreviewForTab(tab_); +} + +bool PrintPreviewContextMenuObserver::IsCommandIdSupported(int command_id) { + switch (command_id) { + case IDC_PRINT: + case IDC_VIEW_SOURCE: + case IDC_CONTENT_CONTEXT_VIEWFRAMESOURCE: + case IDC_CONTENT_CONTEXT_VIEWPAGEINFO: + case IDC_CONTENT_CONTEXT_SEARCHWEBFOR: + return IsPrintPreviewTab(); + + default: + return false; + } +} + +bool PrintPreviewContextMenuObserver::IsCommandIdEnabled(int command_id) { + switch (command_id) { + case IDC_PRINT: + case IDC_VIEW_SOURCE: + case IDC_CONTENT_CONTEXT_VIEWFRAMESOURCE: + case IDC_CONTENT_CONTEXT_VIEWPAGEINFO: + case IDC_CONTENT_CONTEXT_SEARCHWEBFOR: + return false; + + default: + NOTREACHED(); + return true; + } +} diff --git a/chrome/browser/printing/print_preview_context_menu_observer.h b/chrome/browser/printing/print_preview_context_menu_observer.h new file mode 100644 index 0000000..b43e8e1 --- /dev/null +++ b/chrome/browser/printing/print_preview_context_menu_observer.h @@ -0,0 +1,32 @@ +// 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. + +#ifndef CHROME_BROWSER_PRINTING_PRINT_PREVIEW_CONTEXT_MENU_OBSERVER_H_ +#define CHROME_BROWSER_PRINTING_PRINT_PREVIEW_CONTEXT_MENU_OBSERVER_H_ +#pragma once + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "chrome/browser/tab_contents/render_view_context_menu_observer.h" + +class TabContentsWrapper; + +class PrintPreviewContextMenuObserver : public RenderViewContextMenuObserver { + public: + explicit PrintPreviewContextMenuObserver(TabContentsWrapper* tab); + virtual ~PrintPreviewContextMenuObserver(); + + // RenderViewContextMenuObserver implementation. + virtual bool IsCommandIdSupported(int command_id) OVERRIDE; + virtual bool IsCommandIdEnabled(int command_id) OVERRIDE; + + private: + bool IsPrintPreviewTab(); + + TabContentsWrapper* tab_; + + DISALLOW_COPY_AND_ASSIGN(PrintPreviewContextMenuObserver); +}; + +#endif // CHROME_BROWSER_PRINTING_PRINT_PREVIEW_CONTEXT_MENU_OBSERVER_H_ diff --git a/chrome/browser/tab_contents/render_view_context_menu.cc b/chrome/browser/tab_contents/render_view_context_menu.cc index 0725e56..10a3734 100644 --- a/chrome/browser/tab_contents/render_view_context_menu.cc +++ b/chrome/browser/tab_contents/render_view_context_menu.cc @@ -30,6 +30,7 @@ #include "chrome/browser/prefs/incognito_mode_prefs.h" #include "chrome/browser/prefs/pref_member.h" #include "chrome/browser/prefs/pref_service.h" +#include "chrome/browser/printing/print_preview_context_menu_observer.h" #include "chrome/browser/printing/print_preview_tab_controller.h" #include "chrome/browser/printing/print_view_manager.h" #include "chrome/browser/profiles/profile.h" @@ -597,6 +598,14 @@ void RenderViewContextMenu::InitMenu() { AppendAllExtensionItems(); AppendDeveloperItems(); + + if (!print_preview_menu_observer_.get()) { + TabContentsWrapper* wrapper = + TabContentsWrapper::GetCurrentWrapperForContents(source_tab_contents_); + print_preview_menu_observer_.reset( + new PrintPreviewContextMenuObserver(wrapper)); + } + observers_.AddObserver(print_preview_menu_observer_.get()); } void RenderViewContextMenu::LookUpInDictionary() { diff --git a/chrome/browser/tab_contents/render_view_context_menu.h b/chrome/browser/tab_contents/render_view_context_menu.h index 4286615..d042316 100644 --- a/chrome/browser/tab_contents/render_view_context_menu.h +++ b/chrome/browser/tab_contents/render_view_context_menu.h @@ -23,6 +23,7 @@ #include "webkit/glue/window_open_disposition.h" class ExtensionMenuItem; +class PrintPreviewContextMenuObserver; class Profile; class RenderViewHost; class TabContents; @@ -268,6 +269,9 @@ class RenderViewContextMenu : public ui::SimpleMenuModel::Delegate, // An observer that handles a 'spell-checker options' submenu. scoped_ptr<SpellCheckerSubMenuObserver> spellchecker_submenu_observer_; + // An observer that disables menu items when print preview is active. + scoped_ptr<PrintPreviewContextMenuObserver> print_preview_menu_observer_; + // Our observers. mutable ObserverList<RenderViewContextMenuObserver> observers_; diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index aba2a8b..45c3972 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1943,6 +1943,8 @@ 'browser/printing/print_job_worker.cc', 'browser/printing/print_job_worker.h', 'browser/printing/print_job_worker_owner.h', + 'browser/printing/print_preview_context_menu_observer.cc', + 'browser/printing/print_preview_context_menu_observer.h', 'browser/printing/print_preview_data_service.cc', 'browser/printing/print_preview_data_service.h', 'browser/printing/print_preview_message_handler.cc', |