OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_PRINTING_PRINTED_DOCUMENT_H__ | 5 #ifndef CHROME_BROWSER_PRINTING_PRINTED_DOCUMENT_H__ |
6 #define CHROME_BROWSER_PRINTING_PRINTED_DOCUMENT_H__ | 6 #define CHROME_BROWSER_PRINTING_PRINTED_DOCUMENT_H__ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/lock.h" | 10 #include "base/lock.h" |
11 #include "base/ref_counted.h" | 11 #include "base/ref_counted.h" |
12 #include "base/scoped_ptr.h" | 12 #include "base/scoped_ptr.h" |
13 #include "chrome/browser/printing/print_settings.h" | 13 #include "chrome/browser/printing/print_settings.h" |
| 14 #include "printing/native_metafile.h" |
14 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
15 | 16 |
16 class MessageLoop; | 17 class MessageLoop; |
17 | 18 |
18 namespace gfx { | 19 namespace gfx { |
19 class Emf; | |
20 class Font; | 20 class Font; |
21 } | 21 } |
22 | 22 |
23 namespace printing { | 23 namespace printing { |
24 | 24 |
25 class PrintedPage; | 25 class PrintedPage; |
26 class PrintedPagesSource; | 26 class PrintedPagesSource; |
27 | 27 |
28 // A collection of rendered pages. The settings are immutable. If the print | 28 // A collection of rendered pages. The settings are immutable. If the print |
29 // settings are changed, a new PrintedDocument must be created. | 29 // settings are changed, a new PrintedDocument must be created. |
30 // Warning: May be accessed from many threads at the same time. Only one thread | 30 // Warning: May be accessed from many threads at the same time. Only one thread |
31 // will have write access. Sensible functions are protected by a lock. | 31 // will have write access. Sensible functions are protected by a lock. |
32 // Warning: Once a page is loaded, it cannot be replaced. Pages may be discarded | 32 // Warning: Once a page is loaded, it cannot be replaced. Pages may be discarded |
33 // under low memory conditions. | 33 // under low memory conditions. |
34 class PrintedDocument : public base::RefCountedThreadSafe<PrintedDocument> { | 34 class PrintedDocument : public base::RefCountedThreadSafe<PrintedDocument> { |
35 public: | 35 public: |
36 // The cookie shall be unique and has a specific relationship with its | 36 // The cookie shall be unique and has a specific relationship with its |
37 // originating source and settings. | 37 // originating source and settings. |
38 PrintedDocument(const PrintSettings& settings, | 38 PrintedDocument(const PrintSettings& settings, |
39 PrintedPagesSource* source, | 39 PrintedPagesSource* source, |
40 int cookie); | 40 int cookie); |
41 ~PrintedDocument(); | 41 ~PrintedDocument(); |
42 | 42 |
43 // Sets a page's data. 0-based. Takes emf ownership. | 43 // Sets a page's data. 0-based. Takes metafile ownership. |
44 // Note: locks for a short amount of time. | 44 // Note: locks for a short amount of time. |
45 void SetPage(int page_number, gfx::Emf* emf, double shrink); | 45 void SetPage(int page_number, NativeMetafile* metafile, double shrink); |
46 | 46 |
47 // Retrieves a page. If the page is not available right now, it | 47 // Retrieves a page. If the page is not available right now, it |
48 // requests to have this page be rendered and returns false. | 48 // requests to have this page be rendered and returns false. |
49 // Note: locks for a short amount of time. | 49 // Note: locks for a short amount of time. |
50 bool GetPage(int page_number, scoped_refptr<PrintedPage>* page); | 50 bool GetPage(int page_number, scoped_refptr<PrintedPage>* page); |
51 | 51 |
52 // Draws the page in the context. | 52 // Draws the page in the context. |
53 // Note: locks for a short amount of time in debug only. | 53 // Note: locks for a short amount of time in debug only. |
54 void RenderPrintedPage(const PrintedPage& page, HDC context) const; | 54 void RenderPrintedPage(const PrintedPage& page, HDC context) const; |
55 | 55 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 const std::wstring& time() const { return immutable_.time_; } | 96 const std::wstring& time() const { return immutable_.time_; } |
97 const int cookie() const { return immutable_.cookie_; } | 97 const int cookie() const { return immutable_.cookie_; } |
98 | 98 |
99 // Sets a path where to dump printing output files for debugging. If never set | 99 // Sets a path where to dump printing output files for debugging. If never set |
100 // no files are generated. | 100 // no files are generated. |
101 static void set_debug_dump_path(const std::wstring& debug_dump_path); | 101 static void set_debug_dump_path(const std::wstring& debug_dump_path); |
102 | 102 |
103 static const std::wstring& debug_dump_path(); | 103 static const std::wstring& debug_dump_path(); |
104 | 104 |
105 private: | 105 private: |
106 // Array of EMF data for each print previewed page. | 106 // Array of data for each print previewed page. |
107 typedef std::map<int, scoped_refptr<PrintedPage>> PrintedPages; | 107 typedef std::map<int, scoped_refptr<PrintedPage>> PrintedPages; |
108 | 108 |
109 // Contains all the mutable stuff. All this stuff MUST be accessed with the | 109 // Contains all the mutable stuff. All this stuff MUST be accessed with the |
110 // lock held. | 110 // lock held. |
111 struct Mutable { | 111 struct Mutable { |
112 Mutable(PrintedPagesSource* source); | 112 Mutable(PrintedPagesSource* source); |
113 | 113 |
114 // Source that generates the PrintedPage's (i.e. a TabContents). It will be | 114 // Source that generates the PrintedPage's (i.e. a TabContents). It will be |
115 // set back to NULL if the source is deleted before this object. | 115 // set back to NULL if the source is deleted before this object. |
116 PrintedPagesSource* source_; | 116 PrintedPagesSource* source_; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 | 183 |
184 // All the immutable members. | 184 // All the immutable members. |
185 const Immutable immutable_; | 185 const Immutable immutable_; |
186 | 186 |
187 DISALLOW_EVIL_CONSTRUCTORS(PrintedDocument); | 187 DISALLOW_EVIL_CONSTRUCTORS(PrintedDocument); |
188 }; | 188 }; |
189 | 189 |
190 } // namespace printing | 190 } // namespace printing |
191 | 191 |
192 #endif // CHROME_BROWSER_PRINTING_PRINTED_DOCUMENT_H__ | 192 #endif // CHROME_BROWSER_PRINTING_PRINTED_DOCUMENT_H__ |
OLD | NEW |