Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(41)

Side by Side Diff: printing/printing_context_android.cc

Issue 740983002: Implement window.print() on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Handle printing disabled or not supported Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 LOG(INFO) << "DGN - PrintingContextAndroid::ShowSystemDialogDone";
151 callback_.Run(SYSTEM_DIALOG_DONE);
dgn 2014/11/28 11:51:15 Returning OK works, but will make functions run in
152 }
153
135 PrintingContext::Result PrintingContextAndroid::UseDefaultSettings() { 154 PrintingContext::Result PrintingContextAndroid::UseDefaultSettings() {
136 DCHECK(!in_print_job_); 155 DCHECK(!in_print_job_);
137 156
138 ResetSettings(); 157 ResetSettings();
139 settings_.set_dpi(kDefaultPdfDpi); 158 settings_.set_dpi(kDefaultPdfDpi);
140 gfx::Size physical_size = GetPdfPaperSizeDeviceUnits(); 159 gfx::Size physical_size = GetPdfPaperSizeDeviceUnits();
141 SetSizes(&settings_, kDefaultPdfDpi, physical_size.width(), 160 SetSizes(&settings_, kDefaultPdfDpi, physical_size.width(),
142 physical_size.height()); 161 physical_size.height());
143 return OK; 162 return OK;
144 } 163 }
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 // Intentional No-op. 258 // Intentional No-op.
240 return NULL; 259 return NULL;
241 } 260 }
242 261
243 // static 262 // static
244 bool PrintingContextAndroid::RegisterPrintingContext(JNIEnv* env) { 263 bool PrintingContextAndroid::RegisterPrintingContext(JNIEnv* env) {
245 return RegisterNativesImpl(env); 264 return RegisterNativesImpl(env);
246 } 265 }
247 266
248 } // namespace printing 267 } // namespace printing
OLDNEW
« printing/print_job_constants.h ('K') | « printing/printing_context_android.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698