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

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: reverted a comment 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
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::AskUserForSettings( 82 void PrintingContextAndroid::AskUserForSettings(
83 int max_pages, 83 int max_pages,
84 bool has_selection, 84 bool has_selection,
85 bool is_scripted,
85 const PrintSettingsCallback& callback) { 86 const PrintSettingsCallback& callback) {
86 // This method is always run in the UI thread. 87 // This method is always run in the UI thread.
87 callback_ = callback; 88 callback_ = callback;
88 89
89 JNIEnv* env = base::android::AttachCurrentThread(); 90 JNIEnv* env = base::android::AttachCurrentThread();
90 if (j_printing_context_.is_null()) { 91 if (j_printing_context_.is_null()) {
91 j_printing_context_.Reset(Java_PrintingContext_create( 92 j_printing_context_.Reset(Java_PrintingContext_create(
92 env, 93 env,
93 reinterpret_cast<intptr_t>(this))); 94 reinterpret_cast<intptr_t>(this)));
94 } 95 }
95 96
96 Java_PrintingContext_pageCountEstimationDone(env, 97 if (is_scripted) {
97 j_printing_context_.obj(), 98 Java_PrintingContext_showPrintDialog(env, j_printing_context_.obj());
98 max_pages); 99 } else {
100 Java_PrintingContext_pageCountEstimationDone(env,
101 j_printing_context_.obj(),
102 max_pages);
103 }
99 } 104 }
100 105
101 void PrintingContextAndroid::AskUserForSettingsReply(JNIEnv* env, 106 void PrintingContextAndroid::AskUserForSettingsReply(JNIEnv* env,
102 jobject obj, 107 jobject obj,
103 jboolean success) { 108 jboolean success) {
104 if (!success) { 109 if (!success) {
105 // TODO(cimamoglu): Differentiate between FAILED And CANCEL. 110 // TODO(cimamoglu): Differentiate between FAILED And CANCEL.
106 callback_.Run(FAILED); 111 callback_.Run(FAILED);
107 return; 112 return;
108 } 113 }
(...skipping 16 matching lines...) Expand all
125 int dpi = Java_PrintingContext_getDpi(env, j_printing_context_.obj()); 130 int dpi = Java_PrintingContext_getDpi(env, j_printing_context_.obj());
126 int width = Java_PrintingContext_getWidth(env, j_printing_context_.obj()); 131 int width = Java_PrintingContext_getWidth(env, j_printing_context_.obj());
127 int height = Java_PrintingContext_getHeight(env, j_printing_context_.obj()); 132 int height = Java_PrintingContext_getHeight(env, j_printing_context_.obj());
128 width = Round(ConvertUnitDouble(width, kInchToMil, 1.0) * dpi); 133 width = Round(ConvertUnitDouble(width, kInchToMil, 1.0) * dpi);
129 height = Round(ConvertUnitDouble(height, kInchToMil, 1.0) * dpi); 134 height = Round(ConvertUnitDouble(height, kInchToMil, 1.0) * dpi);
130 SetSizes(&settings_, dpi, width, height); 135 SetSizes(&settings_, dpi, width, height);
131 136
132 callback_.Run(OK); 137 callback_.Run(OK);
133 } 138 }
134 139
140 void PrintingContextAndroid::ShowSystemDialogDone(JNIEnv* env,
141 jobject obj) {
Bernhard Bauer 2014/12/15 09:38:02 Nit: Align
dgn 2014/12/15 10:27:06 Done.
142 // Settings are not updated, callback is called only to unblock javascript.
143 callback_.Run(CANCEL);
144 }
145
135 PrintingContext::Result PrintingContextAndroid::UseDefaultSettings() { 146 PrintingContext::Result PrintingContextAndroid::UseDefaultSettings() {
136 DCHECK(!in_print_job_); 147 DCHECK(!in_print_job_);
137 148
138 ResetSettings(); 149 ResetSettings();
139 settings_.set_dpi(kDefaultPdfDpi); 150 settings_.set_dpi(kDefaultPdfDpi);
140 gfx::Size physical_size = GetPdfPaperSizeDeviceUnits(); 151 gfx::Size physical_size = GetPdfPaperSizeDeviceUnits();
141 SetSizes(&settings_, kDefaultPdfDpi, physical_size.width(), 152 SetSizes(&settings_, kDefaultPdfDpi, physical_size.width(),
142 physical_size.height()); 153 physical_size.height());
143 return OK; 154 return OK;
144 } 155 }
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 // Intentional No-op. 250 // Intentional No-op.
240 return NULL; 251 return NULL;
241 } 252 }
242 253
243 // static 254 // static
244 bool PrintingContextAndroid::RegisterPrintingContext(JNIEnv* env) { 255 bool PrintingContextAndroid::RegisterPrintingContext(JNIEnv* env) {
245 return RegisterNativesImpl(env); 256 return RegisterNativesImpl(env);
246 } 257 }
247 258
248 } // namespace printing 259 } // namespace printing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698