OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_RENDERER_MOCK_PRINTER_H_ | 5 #ifndef CHROME_RENDERER_MOCK_PRINTER_H_ |
6 #define CHROME_RENDERER_MOCK_PRINTER_H_ | 6 #define CHROME_RENDERER_MOCK_PRINTER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/ref_counted.h" | 13 #include "base/ref_counted.h" |
14 #include "base/scoped_ptr.h" | 14 #include "base/scoped_ptr.h" |
15 #include "printing/image.h" | 15 #include "printing/image.h" |
16 | 16 |
17 struct ViewMsg_Print_Params; | 17 struct ViewMsg_Print_Params; |
18 struct ViewMsg_PrintPages_Params; | 18 struct ViewMsg_PrintPages_Params; |
19 struct ViewHostMsg_DidPrintPage_Params; | 19 struct ViewHostMsg_DidPrintPage_Params; |
20 | 20 |
21 // A class which represents an output page used in the MockPrinter class. | 21 // A class which represents an output page used in the MockPrinter class. |
22 // The MockPrinter class stores output pages in a vector, so, this class | 22 // The MockPrinter class stores output pages in a vector, so, this class |
23 // inherits the base::RefCounted<> class so that the MockPrinter class can use | 23 // inherits the base::RefCounted<> class so that the MockPrinter class can use |
24 // a smart pointer of this object (i.e. scoped_refptr<>). | 24 // a smart pointer of this object (i.e. scoped_refptr<>). |
25 class MockPrinterPage : public base::RefCounted<MockPrinterPage> { | 25 class MockPrinterPage : public base::RefCounted<MockPrinterPage> { |
26 public: | 26 public: |
27 MockPrinterPage(const void* source_data, | 27 MockPrinterPage(const void* source_data, |
28 uint32 source_size, | 28 uint32 source_size, |
29 const printing::Image& image) | 29 const printing::Image& image); |
30 : source_size_(source_size), | |
31 image_(image) { | |
32 // Create copies of the source data | |
33 source_data_.reset(new uint8[source_size]); | |
34 if (source_data_.get()) | |
35 memcpy(source_data_.get(), source_data, source_size); | |
36 } | |
37 | |
38 ~MockPrinterPage() { | |
39 } | |
40 | 30 |
41 int width() const { return image_.size().width(); } | 31 int width() const { return image_.size().width(); } |
42 int height() const { return image_.size().height(); } | 32 int height() const { return image_.size().height(); } |
43 const uint8* source_data() const { return source_data_.get(); } | 33 const uint8* source_data() const { return source_data_.get(); } |
44 uint32 source_size() const { return source_size_; } | 34 uint32 source_size() const { return source_size_; } |
45 const printing::Image& image() const { return image_; } | 35 const printing::Image& image() const { return image_; } |
46 | 36 |
47 private: | 37 private: |
| 38 friend class base::RefCounted<MockPrinterPage>; |
| 39 virtual ~MockPrinterPage(); |
| 40 |
48 uint32 source_size_; | 41 uint32 source_size_; |
49 scoped_array<uint8> source_data_; | 42 scoped_array<uint8> source_data_; |
50 printing::Image image_; | 43 printing::Image image_; |
51 | 44 |
52 DISALLOW_COPY_AND_ASSIGN(MockPrinterPage); | 45 DISALLOW_COPY_AND_ASSIGN(MockPrinterPage); |
53 }; | 46 }; |
54 | 47 |
55 // A class which implements a pseudo-printer object used by the RenderViewTest | 48 // A class which implements a pseudo-printer object used by the RenderViewTest |
56 // class. | 49 // class. |
57 // This class consists of three parts: | 50 // This class consists of three parts: |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 | 122 |
130 // The output of a printing job. | 123 // The output of a printing job. |
131 int number_pages_; | 124 int number_pages_; |
132 int page_number_; | 125 int page_number_; |
133 std::vector<scoped_refptr<MockPrinterPage> > pages_; | 126 std::vector<scoped_refptr<MockPrinterPage> > pages_; |
134 | 127 |
135 DISALLOW_COPY_AND_ASSIGN(MockPrinter); | 128 DISALLOW_COPY_AND_ASSIGN(MockPrinter); |
136 }; | 129 }; |
137 | 130 |
138 #endif // CHROME_RENDERER_MOCK_PRINTER_H_ | 131 #endif // CHROME_RENDERER_MOCK_PRINTER_H_ |
OLD | NEW |