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

Side by Side Diff: pdf/out_of_process_instance.cc

Issue 375253002: [Chrome] Support NumCopies print preset (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review feedback (oop proxy, out-param) Created 6 years, 3 months 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "pdf/out_of_process_instance.h" 5 #include "pdf/out_of_process_instance.h"
6 6
7 #include <algorithm> // for min/max() 7 #include <algorithm> // for min/max()
8 #define _USE_MATH_DEFINES // for M_PI 8 #define _USE_MATH_DEFINES // for M_PI
9 #include <cmath> // for log() and pow() 9 #include <cmath> // for log() and pow()
10 #include <math.h> 10 #include <math.h>
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 // Rotation (Page -> Plugin) 127 // Rotation (Page -> Plugin)
128 const char kJSRotateClockwiseType[] = "rotateClockwise"; 128 const char kJSRotateClockwiseType[] = "rotateClockwise";
129 const char kJSRotateCounterclockwiseType[] = "rotateCounterclockwise"; 129 const char kJSRotateCounterclockwiseType[] = "rotateCounterclockwise";
130 130
131 const int kFindResultCooldownMs = 100; 131 const int kFindResultCooldownMs = 100;
132 132
133 const double kMinZoom = 0.01; 133 const double kMinZoom = 0.01;
134 134
135 namespace { 135 namespace {
136 136
137 static const char kPPPPdfInterface[] = PPP_PDF_INTERFACE_1; 137 static const char kPPPPdfInterface[] = PPP_PDF_INTERFACE_1_1;
138 138
139 PP_Var GetLinkAtPosition(PP_Instance instance, PP_Point point) { 139 PP_Var GetLinkAtPosition(PP_Instance instance, PP_Point point) {
140 pp::Var var; 140 pp::Var var;
141 void* object = pp::Instance::GetPerInstanceObject(instance, kPPPPdfInterface); 141 void* object = pp::Instance::GetPerInstanceObject(instance, kPPPPdfInterface);
142 if (object) { 142 if (object) {
143 var = static_cast<OutOfProcessInstance*>(object)->GetLinkAtPosition( 143 var = static_cast<OutOfProcessInstance*>(object)->GetLinkAtPosition(
144 pp::Point(point)); 144 pp::Point(point));
145 } 145 }
146 return var.Detach(); 146 return var.Detach();
147 } 147 }
148 148
149 void Transform(PP_Instance instance, PP_PrivatePageTransformType type) { 149 void Transform(PP_Instance instance, PP_PrivatePageTransformType type) {
150 void* object = 150 void* object =
151 pp::Instance::GetPerInstanceObject(instance, kPPPPdfInterface); 151 pp::Instance::GetPerInstanceObject(instance, kPPPPdfInterface);
152 if (object) { 152 if (object) {
153 OutOfProcessInstance* obj_instance = 153 OutOfProcessInstance* obj_instance =
154 static_cast<OutOfProcessInstance*>(object); 154 static_cast<OutOfProcessInstance*>(object);
155 switch (type) { 155 switch (type) {
156 case PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CW: 156 case PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CW:
157 obj_instance->RotateClockwise(); 157 obj_instance->RotateClockwise();
158 break; 158 break;
159 case PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CCW: 159 case PP_PRIVATEPAGETRANSFORMTYPE_ROTATE_90_CCW:
160 obj_instance->RotateCounterclockwise(); 160 obj_instance->RotateCounterclockwise();
161 break; 161 break;
162 } 162 }
163 } 163 }
164 } 164 }
165 165
166 PP_Bool GetPrintPresetOptionsFromDocument(PP_Instance instance,
167 PP_PrintPresetOptions_Dev* options) {
168 void* object = pp::Instance::GetPerInstanceObject(instance, kPPPPdfInterface);
169 PP_Bool ret = PP_FALSE;
170 if (object) {
171 OutOfProcessInstance* obj_instance =
172 static_cast<OutOfProcessInstance*>(object);
173 ret = obj_instance->GetPrintPresetOptionsFromDocument(options);
174 }
175 return ret;
176 }
177
166 const PPP_Pdf ppp_private = { 178 const PPP_Pdf ppp_private = {
167 &GetLinkAtPosition, 179 &GetLinkAtPosition,
168 &Transform 180 &Transform,
181 &GetPrintPresetOptionsFromDocument
169 }; 182 };
170 183
171 int ExtractPrintPreviewPageIndex(const std::string& src_url) { 184 int ExtractPrintPreviewPageIndex(const std::string& src_url) {
172 // Sample |src_url| format: chrome://print/id/page_index/print.pdf 185 // Sample |src_url| format: chrome://print/id/page_index/print.pdf
173 std::vector<std::string> url_substr; 186 std::vector<std::string> url_substr;
174 base::SplitString(src_url.substr(strlen(kChromePrint)), '/', &url_substr); 187 base::SplitString(src_url.substr(strlen(kChromePrint)), '/', &url_substr);
175 if (url_substr.size() != 3) 188 if (url_substr.size() != 3)
176 return -1; 189 return -1;
177 190
178 if (url_substr[2] != "print.pdf") 191 if (url_substr[2] != "print.pdf")
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 } 549 }
537 550
538 if (!stop_scrolling_) { 551 if (!stop_scrolling_) {
539 pp::Point scroll_offset( 552 pp::Point scroll_offset(
540 BoundScrollOffsetToDocument(view.GetScrollOffset())); 553 BoundScrollOffsetToDocument(view.GetScrollOffset()));
541 engine_->ScrolledToXPosition(scroll_offset.x() * device_scale_); 554 engine_->ScrolledToXPosition(scroll_offset.x() * device_scale_);
542 engine_->ScrolledToYPosition(scroll_offset.y() * device_scale_); 555 engine_->ScrolledToYPosition(scroll_offset.y() * device_scale_);
543 } 556 }
544 } 557 }
545 558
559 PP_Bool OutOfProcessInstance::GetPrintPresetOptionsFromDocument(
560 PP_PrintPresetOptions_Dev* options) {
561 options->is_scaling_disabled = PP_FromBool(IsPrintScalingDisabled());
562 options->copies = engine_->GetCopiesToPrint();
563
564 return PP_TRUE;
raymes 2014/09/24 04:54:39 Same here.
Nikhil 2014/09/29 11:15:30 Acknowledged.
565 }
566
546 pp::Var OutOfProcessInstance::GetLinkAtPosition( 567 pp::Var OutOfProcessInstance::GetLinkAtPosition(
547 const pp::Point& point) { 568 const pp::Point& point) {
548 pp::Point offset_point(point); 569 pp::Point offset_point(point);
549 ScalePoint(device_scale_, &offset_point); 570 ScalePoint(device_scale_, &offset_point);
550 offset_point.set_x(offset_point.x() - available_area_.x()); 571 offset_point.set_x(offset_point.x() - available_area_.x());
551 return engine_->GetLinkAtPosition(offset_point); 572 return engine_->GetLinkAtPosition(offset_point);
552 } 573 }
553 574
554 pp::Var OutOfProcessInstance::GetSelectedText(bool html) { 575 pp::Var OutOfProcessInstance::GetSelectedText(bool html) {
555 if (html || !engine_->HasPermission(PDFEngine::PERMISSION_COPY)) 576 if (html || !engine_->HasPermission(PDFEngine::PERMISSION_COPY))
(...skipping 810 matching lines...) Expand 10 before | Expand all | Expand 10 after
1366 pp::Point OutOfProcessInstance::BoundScrollOffsetToDocument( 1387 pp::Point OutOfProcessInstance::BoundScrollOffsetToDocument(
1367 const pp::Point& scroll_offset) { 1388 const pp::Point& scroll_offset) {
1368 int max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); 1389 int max_x = document_size_.width() * zoom_ - plugin_dip_size_.width();
1369 int x = std::max(std::min(scroll_offset.x(), max_x), 0); 1390 int x = std::max(std::min(scroll_offset.x(), max_x), 0);
1370 int max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); 1391 int max_y = document_size_.height() * zoom_ - plugin_dip_size_.height();
1371 int y = std::max(std::min(scroll_offset.y(), max_y), 0); 1392 int y = std::max(std::min(scroll_offset.y(), max_y), 0);
1372 return pp::Point(x, y); 1393 return pp::Point(x, y);
1373 } 1394 }
1374 1395
1375 } // namespace chrome_pdf 1396 } // namespace chrome_pdf
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698