OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "printing/printing_context_android.h" | 5 #include "printing/printing_context_android.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
10 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 } | 72 } |
73 | 73 |
74 PrintingContextAndroid::PrintingContextAndroid(Delegate* delegate) | 74 PrintingContextAndroid::PrintingContextAndroid(Delegate* delegate) |
75 : PrintingContext(delegate) { | 75 : PrintingContext(delegate) { |
76 // The constructor is run in the IO thread. | 76 // The constructor is run in the IO thread. |
77 } | 77 } |
78 | 78 |
79 PrintingContextAndroid::~PrintingContextAndroid() { | 79 PrintingContextAndroid::~PrintingContextAndroid() { |
80 } | 80 } |
81 | 81 |
| 82 void PrintingContextAndroid::RequestSystemDialog( |
| 83 const PrintSettingsCallback& callback) { |
| 84 callback_ = callback; |
| 85 |
| 86 JNIEnv* env = base::android::AttachCurrentThread(); |
| 87 if (j_printing_context_.is_null()) { |
| 88 j_printing_context_.Reset(Java_PrintingContext_create( |
| 89 env, |
| 90 reinterpret_cast<intptr_t>(this))); |
| 91 } |
| 92 Java_PrintingContext_showPrintDialog(env, j_printing_context_.obj()); |
| 93 } |
| 94 |
82 void PrintingContextAndroid::AskUserForSettings( | 95 void PrintingContextAndroid::AskUserForSettings( |
83 int max_pages, | 96 int max_pages, |
84 bool has_selection, | 97 bool has_selection, |
85 const PrintSettingsCallback& callback) { | 98 const PrintSettingsCallback& callback) { |
86 // This method is always run in the UI thread. | 99 // This method is always run in the UI thread. |
87 callback_ = callback; | 100 callback_ = callback; |
88 | 101 |
89 JNIEnv* env = base::android::AttachCurrentThread(); | 102 JNIEnv* env = base::android::AttachCurrentThread(); |
90 if (j_printing_context_.is_null()) { | 103 if (j_printing_context_.is_null()) { |
91 j_printing_context_.Reset(Java_PrintingContext_create( | 104 j_printing_context_.Reset(Java_PrintingContext_create( |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 int dpi = Java_PrintingContext_getDpi(env, j_printing_context_.obj()); | 138 int dpi = Java_PrintingContext_getDpi(env, j_printing_context_.obj()); |
126 int width = Java_PrintingContext_getWidth(env, j_printing_context_.obj()); | 139 int width = Java_PrintingContext_getWidth(env, j_printing_context_.obj()); |
127 int height = Java_PrintingContext_getHeight(env, j_printing_context_.obj()); | 140 int height = Java_PrintingContext_getHeight(env, j_printing_context_.obj()); |
128 width = Round(ConvertUnitDouble(width, kInchToMil, 1.0) * dpi); | 141 width = Round(ConvertUnitDouble(width, kInchToMil, 1.0) * dpi); |
129 height = Round(ConvertUnitDouble(height, kInchToMil, 1.0) * dpi); | 142 height = Round(ConvertUnitDouble(height, kInchToMil, 1.0) * dpi); |
130 SetSizes(&settings_, dpi, width, height); | 143 SetSizes(&settings_, dpi, width, height); |
131 | 144 |
132 callback_.Run(OK); | 145 callback_.Run(OK); |
133 } | 146 } |
134 | 147 |
| 148 void PrintingContextAndroid::ShowSystemDialogDone(JNIEnv* env, |
| 149 jobject obj) { |
| 150 callback_.Run(SYSTEM_DIALOG_DONE); |
| 151 } |
| 152 |
135 PrintingContext::Result PrintingContextAndroid::UseDefaultSettings() { | 153 PrintingContext::Result PrintingContextAndroid::UseDefaultSettings() { |
136 DCHECK(!in_print_job_); | 154 DCHECK(!in_print_job_); |
137 | 155 |
138 ResetSettings(); | 156 ResetSettings(); |
139 settings_.set_dpi(kDefaultPdfDpi); | 157 settings_.set_dpi(kDefaultPdfDpi); |
140 gfx::Size physical_size = GetPdfPaperSizeDeviceUnits(); | 158 gfx::Size physical_size = GetPdfPaperSizeDeviceUnits(); |
141 SetSizes(&settings_, kDefaultPdfDpi, physical_size.width(), | 159 SetSizes(&settings_, kDefaultPdfDpi, physical_size.width(), |
142 physical_size.height()); | 160 physical_size.height()); |
143 return OK; | 161 return OK; |
144 } | 162 } |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 // Intentional No-op. | 257 // Intentional No-op. |
240 return NULL; | 258 return NULL; |
241 } | 259 } |
242 | 260 |
243 // static | 261 // static |
244 bool PrintingContextAndroid::RegisterPrintingContext(JNIEnv* env) { | 262 bool PrintingContextAndroid::RegisterPrintingContext(JNIEnv* env) { |
245 return RegisterNativesImpl(env); | 263 return RegisterNativesImpl(env); |
246 } | 264 } |
247 | 265 |
248 } // namespace printing | 266 } // namespace printing |
OLD | NEW |