| OLD | NEW |
| 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 958 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 969 | 969 |
| 970 pp::CompletionCallback callback = | 970 pp::CompletionCallback callback = |
| 971 print_callback_factory_.NewCallback(&OutOfProcessInstance::OnPrint); | 971 print_callback_factory_.NewCallback(&OutOfProcessInstance::OnPrint); |
| 972 pp::Module::Get()->core()->CallOnMainThread(0, callback); | 972 pp::Module::Get()->core()->CallOnMainThread(0, callback); |
| 973 } | 973 } |
| 974 | 974 |
| 975 void OutOfProcessInstance::OnPrint(int32_t) { | 975 void OutOfProcessInstance::OnPrint(int32_t) { |
| 976 pp::PDF::Print(this); | 976 pp::PDF::Print(this); |
| 977 } | 977 } |
| 978 | 978 |
| 979 void OutOfProcessInstance::SetPrintPresetOptionsFromDocument() { |
| 980 PP_PrintPresetOptions_Dev print_options; |
| 981 print_options.is_scaling_disabled = PP_FromBool(IsPrintScalingDisabled()); |
| 982 print_options.copies = engine_->GetCopiesToPrint(); |
| 983 |
| 984 pp::Printing_Dev::SetPrintPresetOptionsFromDocument(print_options); |
| 985 } |
| 986 |
| 979 void OutOfProcessInstance::SubmitForm(const std::string& url, | 987 void OutOfProcessInstance::SubmitForm(const std::string& url, |
| 980 const void* data, | 988 const void* data, |
| 981 int length) { | 989 int length) { |
| 982 pp::URLRequestInfo request(this); | 990 pp::URLRequestInfo request(this); |
| 983 request.SetURL(url); | 991 request.SetURL(url); |
| 984 request.SetMethod("POST"); | 992 request.SetMethod("POST"); |
| 985 request.AppendDataToBody(reinterpret_cast<const char*>(data), length); | 993 request.AppendDataToBody(reinterpret_cast<const char*>(data), length); |
| 986 | 994 |
| 987 pp::CompletionCallback callback = | 995 pp::CompletionCallback callback = |
| 988 form_factory_.NewCallback(&OutOfProcessInstance::FormDidOpen); | 996 form_factory_.NewCallback(&OutOfProcessInstance::FormDidOpen); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1062 | 1070 |
| 1063 DCHECK(document_load_state_ == LOAD_STATE_LOADING); | 1071 DCHECK(document_load_state_ == LOAD_STATE_LOADING); |
| 1064 document_load_state_ = LOAD_STATE_COMPLETE; | 1072 document_load_state_ = LOAD_STATE_COMPLETE; |
| 1065 UserMetricsRecordAction("PDF.LoadSuccess"); | 1073 UserMetricsRecordAction("PDF.LoadSuccess"); |
| 1066 | 1074 |
| 1067 // Note: If we are in print preview mode the scroll location is retained | 1075 // Note: If we are in print preview mode the scroll location is retained |
| 1068 // across document loads so we don't want to scroll again and override it. | 1076 // across document loads so we don't want to scroll again and override it. |
| 1069 if (IsPrintPreview()) { | 1077 if (IsPrintPreview()) { |
| 1070 AppendBlankPrintPreviewPages(); | 1078 AppendBlankPrintPreviewPages(); |
| 1071 OnGeometryChanged(0, 0); | 1079 OnGeometryChanged(0, 0); |
| 1080 // Set print preset options from pdf document. |
| 1081 SetPrintPresetOptionsFromDocument(); |
| 1072 } | 1082 } |
| 1073 | 1083 |
| 1074 pp::VarDictionary message; | 1084 pp::VarDictionary message; |
| 1075 message.Set(pp::Var(kType), pp::Var(kJSLoadProgressType)); | 1085 message.Set(pp::Var(kType), pp::Var(kJSLoadProgressType)); |
| 1076 message.Set(pp::Var(kJSProgressPercentage), pp::Var(100)) ; | 1086 message.Set(pp::Var(kJSProgressPercentage), pp::Var(100)) ; |
| 1077 PostMessage(message); | 1087 PostMessage(message); |
| 1078 | 1088 |
| 1079 if (!full_) | 1089 if (!full_) |
| 1080 return; | 1090 return; |
| 1081 | 1091 |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1360 pp::Point OutOfProcessInstance::BoundScrollOffsetToDocument( | 1370 pp::Point OutOfProcessInstance::BoundScrollOffsetToDocument( |
| 1361 const pp::Point& scroll_offset) { | 1371 const pp::Point& scroll_offset) { |
| 1362 int max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); | 1372 int max_x = document_size_.width() * zoom_ - plugin_dip_size_.width(); |
| 1363 int x = std::max(std::min(scroll_offset.x(), max_x), 0); | 1373 int x = std::max(std::min(scroll_offset.x(), max_x), 0); |
| 1364 int max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); | 1374 int max_y = document_size_.height() * zoom_ - plugin_dip_size_.height(); |
| 1365 int y = std::max(std::min(scroll_offset.y(), max_y), 0); | 1375 int y = std::max(std::min(scroll_offset.y(), max_y), 0); |
| 1366 return pp::Point(x, y); | 1376 return pp::Point(x, y); |
| 1367 } | 1377 } |
| 1368 | 1378 |
| 1369 } // namespace chrome_pdf | 1379 } // namespace chrome_pdf |
| OLD | NEW |