| 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 // TODO rename; requires setPendingPrint to be called |
| 83 void PrintingContextAndroid::RequestSystemDialog( |
| 84 const PrintSettingsCallback& callback) { |
| 85 callback_ = callback; |
| 86 |
| 87 JNIEnv* env = base::android::AttachCurrentThread(); |
| 88 if (j_printing_context_.is_null()) { |
| 89 j_printing_context_.Reset(Java_PrintingContext_create( |
| 90 env, |
| 91 reinterpret_cast<intptr_t>(this))); |
| 92 } |
| 93 Java_PrintingContext_showPrintDialog(env, j_printing_context_.obj()); |
| 94 } |
| 95 |
| 82 void PrintingContextAndroid::AskUserForSettings( | 96 void PrintingContextAndroid::AskUserForSettings( |
| 83 int max_pages, | 97 int max_pages, |
| 84 bool has_selection, | 98 bool has_selection, |
| 85 const PrintSettingsCallback& callback) { | 99 const PrintSettingsCallback& callback) { |
| 86 // This method is always run in the UI thread. | 100 // This method is always run in the UI thread. |
| 87 callback_ = callback; | 101 callback_ = callback; |
| 88 | 102 |
| 89 JNIEnv* env = base::android::AttachCurrentThread(); | 103 JNIEnv* env = base::android::AttachCurrentThread(); |
| 90 if (j_printing_context_.is_null()) { | 104 if (j_printing_context_.is_null()) { |
| 91 j_printing_context_.Reset(Java_PrintingContext_create( | 105 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()); | 139 int dpi = Java_PrintingContext_getDpi(env, j_printing_context_.obj()); |
| 126 int width = Java_PrintingContext_getWidth(env, j_printing_context_.obj()); | 140 int width = Java_PrintingContext_getWidth(env, j_printing_context_.obj()); |
| 127 int height = Java_PrintingContext_getHeight(env, j_printing_context_.obj()); | 141 int height = Java_PrintingContext_getHeight(env, j_printing_context_.obj()); |
| 128 width = Round(ConvertUnitDouble(width, kInchToMil, 1.0) * dpi); | 142 width = Round(ConvertUnitDouble(width, kInchToMil, 1.0) * dpi); |
| 129 height = Round(ConvertUnitDouble(height, kInchToMil, 1.0) * dpi); | 143 height = Round(ConvertUnitDouble(height, kInchToMil, 1.0) * dpi); |
| 130 SetSizes(&settings_, dpi, width, height); | 144 SetSizes(&settings_, dpi, width, height); |
| 131 | 145 |
| 132 callback_.Run(OK); | 146 callback_.Run(OK); |
| 133 } | 147 } |
| 134 | 148 |
| 149 void PrintingContextAndroid::ShowSystemDialogDone(JNIEnv* env, |
| 150 jobject obj) { |
| 151 LOG(INFO) << "DGN - PrintingContextAndroid::ShowSystemDialogDone"; |
| 152 callback_.Run(SYSTEM_DIALOG_DONE); |
| 153 } |
| 154 |
| 135 PrintingContext::Result PrintingContextAndroid::UseDefaultSettings() { | 155 PrintingContext::Result PrintingContextAndroid::UseDefaultSettings() { |
| 136 DCHECK(!in_print_job_); | 156 DCHECK(!in_print_job_); |
| 137 | 157 |
| 138 ResetSettings(); | 158 ResetSettings(); |
| 139 settings_.set_dpi(kDefaultPdfDpi); | 159 settings_.set_dpi(kDefaultPdfDpi); |
| 140 gfx::Size physical_size = GetPdfPaperSizeDeviceUnits(); | 160 gfx::Size physical_size = GetPdfPaperSizeDeviceUnits(); |
| 141 SetSizes(&settings_, kDefaultPdfDpi, physical_size.width(), | 161 SetSizes(&settings_, kDefaultPdfDpi, physical_size.width(), |
| 142 physical_size.height()); | 162 physical_size.height()); |
| 143 return OK; | 163 return OK; |
| 144 } | 164 } |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 // Intentional No-op. | 259 // Intentional No-op. |
| 240 return NULL; | 260 return NULL; |
| 241 } | 261 } |
| 242 | 262 |
| 243 // static | 263 // static |
| 244 bool PrintingContextAndroid::RegisterPrintingContext(JNIEnv* env) { | 264 bool PrintingContextAndroid::RegisterPrintingContext(JNIEnv* env) { |
| 245 return RegisterNativesImpl(env); | 265 return RegisterNativesImpl(env); |
| 246 } | 266 } |
| 247 | 267 |
| 248 } // namespace printing | 268 } // namespace printing |
| OLD | NEW |