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

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: PPP_Pdf changes 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_2;
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 ret = static_cast<OutOfProcessInstance*>(object)
172 ->GetPrintPresetOptionsFromDocument(options);
dmichael (off chromium) 2014/09/22 18:11:51 ditto, style looks off. just make an obj_instance
Nikhil 2014/09/23 10:32:28 Done.
173 return ret;
174 }
175
166 const PPP_Pdf ppp_private = { 176 const PPP_Pdf ppp_private = {
167 &GetLinkAtPosition, 177 &GetLinkAtPosition,
168 &Transform 178 &Transform,
179 &GetPrintPresetOptionsFromDocument
169 }; 180 };
170 181
171 int ExtractPrintPreviewPageIndex(const std::string& src_url) { 182 int ExtractPrintPreviewPageIndex(const std::string& src_url) {
172 // Sample |src_url| format: chrome://print/id/page_index/print.pdf 183 // Sample |src_url| format: chrome://print/id/page_index/print.pdf
173 std::vector<std::string> url_substr; 184 std::vector<std::string> url_substr;
174 base::SplitString(src_url.substr(strlen(kChromePrint)), '/', &url_substr); 185 base::SplitString(src_url.substr(strlen(kChromePrint)), '/', &url_substr);
175 if (url_substr.size() != 3) 186 if (url_substr.size() != 3)
176 return -1; 187 return -1;
177 188
178 if (url_substr[2] != "print.pdf") 189 if (url_substr[2] != "print.pdf")
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 } 547 }
537 548
538 if (!stop_scrolling_) { 549 if (!stop_scrolling_) {
539 pp::Point scroll_offset( 550 pp::Point scroll_offset(
540 BoundScrollOffsetToDocument(view.GetScrollOffset())); 551 BoundScrollOffsetToDocument(view.GetScrollOffset()));
541 engine_->ScrolledToXPosition(scroll_offset.x() * device_scale_); 552 engine_->ScrolledToXPosition(scroll_offset.x() * device_scale_);
542 engine_->ScrolledToYPosition(scroll_offset.y() * device_scale_); 553 engine_->ScrolledToYPosition(scroll_offset.y() * device_scale_);
543 } 554 }
544 } 555 }
545 556
557 PP_Bool OutOfProcessInstance::GetPrintPresetOptionsFromDocument(
558 PP_PrintPresetOptions_Dev& options) {
559 options.is_scaling_disabled = PP_FromBool(IsPrintScalingDisabled());
560 options.copies = engine_->GetCopiesToPrint();
561
562 return PP_TRUE;
563 }
564
546 pp::Var OutOfProcessInstance::GetLinkAtPosition( 565 pp::Var OutOfProcessInstance::GetLinkAtPosition(
547 const pp::Point& point) { 566 const pp::Point& point) {
548 pp::Point offset_point(point); 567 pp::Point offset_point(point);
549 ScalePoint(device_scale_, &offset_point); 568 ScalePoint(device_scale_, &offset_point);
550 offset_point.set_x(offset_point.x() - available_area_.x()); 569 offset_point.set_x(offset_point.x() - available_area_.x());
551 return engine_->GetLinkAtPosition(offset_point); 570 return engine_->GetLinkAtPosition(offset_point);
552 } 571 }
553 572
554 pp::Var OutOfProcessInstance::GetSelectedText(bool html) { 573 pp::Var OutOfProcessInstance::GetSelectedText(bool html) {
555 if (html || !engine_->HasPermission(PDFEngine::PERMISSION_COPY)) 574 if (html || !engine_->HasPermission(PDFEngine::PERMISSION_COPY))
(...skipping 810 matching lines...) Expand 10 before | Expand all | Expand 10 after
1366 pp::Point OutOfProcessInstance::BoundScrollOffsetToDocument( 1385 pp::Point OutOfProcessInstance::BoundScrollOffsetToDocument(
1367 const pp::Point& scroll_offset) { 1386 const pp::Point& scroll_offset) {
1368 int max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); 1387 int max_x = document_size_.width() * zoom_ - plugin_dip_size_.width();
1369 int x = std::max(std::min(scroll_offset.x(), max_x), 0); 1388 int x = std::max(std::min(scroll_offset.x(), max_x), 0);
1370 int max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); 1389 int max_y = document_size_.height() * zoom_ - plugin_dip_size_.height();
1371 int y = std::max(std::min(scroll_offset.y(), max_y), 0); 1390 int y = std::max(std::min(scroll_offset.y(), max_y), 0);
1372 return pp::Point(x, y); 1391 return pp::Point(x, y);
1373 } 1392 }
1374 1393
1375 } // namespace chrome_pdf 1394 } // namespace chrome_pdf
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698