summaryrefslogtreecommitdiffstats
path: root/chrome/browser/printing/print_preview_tab_controller.h
diff options
context:
space:
mode:
authorkmadhusu@chromium.org <kmadhusu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-16 20:34:16 +0000
committerkmadhusu@chromium.org <kmadhusu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-16 20:34:16 +0000
commitdbeebd5ee33f26e2f719e87546f51371a63801b5 (patch)
treefd9627decf2a31c88a866ff46139d4e9b302dfb5 /chrome/browser/printing/print_preview_tab_controller.h
parent3cd6bbf33030ba47b73a10d503e97fba3de2095f (diff)
downloadchromium_src-dbeebd5ee33f26e2f719e87546f51371a63801b5.zip
chromium_src-dbeebd5ee33f26e2f719e87546f51371a63801b5.tar.gz
chromium_src-dbeebd5ee33f26e2f719e87546f51371a63801b5.tar.bz2
Implement print preview tab controller.
For print preview, a PP tab should be linked with the tab that initiated the printing operation. If the tab initiates a second printing operation while the first print preview tab is still open, that PP tab should be focused/activated. There may be more than one PP tab open. Hook ctrl+p to show print preview tab. BUG=59653, 57893 TEST=new unittest created. Review URL: http://codereview.chromium.org/4338001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@66319 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/printing/print_preview_tab_controller.h')
-rw-r--r--chrome/browser/printing/print_preview_tab_controller.h87
1 files changed, 87 insertions, 0 deletions
diff --git a/chrome/browser/printing/print_preview_tab_controller.h b/chrome/browser/printing/print_preview_tab_controller.h
new file mode 100644
index 0000000..6eec3f4
--- /dev/null
+++ b/chrome/browser/printing/print_preview_tab_controller.h
@@ -0,0 +1,87 @@
+// Copyright (c) 2010 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_TAB_CONTROLLER_H_
+#define CHROME_BROWSER_PRINTING_PRINT_PREVIEW_TAB_CONTROLLER_H_
+#pragma once
+
+#include <map>
+
+#include "base/ref_counted.h"
+#include "chrome/common/notification_observer.h"
+#include "chrome/common/notification_registrar.h"
+
+class Browser;
+class TabContents;
+
+namespace printing {
+
+// For print preview, a print preview (PP) tab is linked with the initiator tab
+// that initiated the printing operation. If the tab initiates a second
+// printing operation while the first print preview tab is still open, that PP
+// tab is focused/activated. There may be more than one PP tab open. There is a
+// 1:1 relationship between PP tabs and initiating tabs. This class manages PP
+// tabs and initiator tabs.
+class PrintPreviewTabController
+ : public base::RefCounted<PrintPreviewTabController>,
+ public NotificationObserver {
+ public:
+ static PrintPreviewTabController* GetInstance();
+
+ PrintPreviewTabController();
+
+ virtual ~PrintPreviewTabController();
+
+ // Get/Create the print preview tab for |initiator_tab|.
+ // |browser_window_id| is the browser window containing |initiator_tab|.
+ TabContents* GetOrCreatePreviewTab(
+ TabContents* initiator_tab, int browser_window_id);
+
+ // Notification observer implementation.
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details);
+
+ private:
+ friend class base::RefCounted<PrintPreviewTabController>;
+
+ // Returns true if |tab| is a print preview tab.
+ bool IsPrintPreviewTab(TabContents* tab);
+
+ // Returns initiator tab for |preview_tab|.
+ // Returns NULL if no initiator tab exists for |preview_tab|.
+ TabContents* GetInitiatorTab(TabContents* preview_tab);
+
+ // Returns preview tab for |tab|.
+ // Returns |tab| if |tab| is a preview tab.
+ // Returns NULL if no preview tab exists for |tab|.
+ TabContents* GetPrintPreviewForTab(TabContents* tab);
+
+ // Creates a new print preview tab.
+ TabContents* CreatePrintPreviewTab(
+ TabContents* initiator_tab, int browser_window_id);
+
+ // Adds/Removes observers for notifications from |tab|.
+ void AddObservers(TabContents* tab);
+ void RemoveObservers(TabContents* tab);
+
+ // 1:1 relationship between initiator tab and print preview tab.
+ // Key: Preview tab.
+ // Value: Initiator tab.
+ typedef std::map<TabContents*, TabContents*> PrintPreviewTabMap;
+ PrintPreviewTabMap preview_tab_map_;
+
+ // A registrar for listening notifications.
+ NotificationRegistrar registrar_;
+
+ // True if the controller is waiting for a new preview tab via
+ // NavigationType::NEW_PAGE.
+ bool waiting_for_new_preview_page_;
+
+ DISALLOW_COPY_AND_ASSIGN(PrintPreviewTabController);
+};
+
+} // namespace printing
+
+#endif // CHROME_BROWSER_PRINTING_PRINT_PREVIEW_TAB_CONTROLLER_H_