| 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/instance.h" | 5 #include "pdf/instance.h" |
| 6 | 6 |
| 7 #include <algorithm> // for min() | 7 #include <algorithm> // for min() |
| 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 750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 761 void Instance::OnPaint(const std::vector<pp::Rect>& paint_rects, | 761 void Instance::OnPaint(const std::vector<pp::Rect>& paint_rects, |
| 762 std::vector<PaintManager::ReadyRect>* ready, | 762 std::vector<PaintManager::ReadyRect>* ready, |
| 763 std::vector<pp::Rect>* pending) { | 763 std::vector<pp::Rect>* pending) { |
| 764 if (image_data_.is_null()) { | 764 if (image_data_.is_null()) { |
| 765 DCHECK(plugin_size_.IsEmpty()); | 765 DCHECK(plugin_size_.IsEmpty()); |
| 766 return; | 766 return; |
| 767 } | 767 } |
| 768 if (first_paint_) { | 768 if (first_paint_) { |
| 769 first_paint_ = false; | 769 first_paint_ = false; |
| 770 pp::Rect rect = pp::Rect(pp::Point(), plugin_size_); | 770 pp::Rect rect = pp::Rect(pp::Point(), plugin_size_); |
| 771 unsigned int color = kBackgroundColorA << 24 | | 771 FillRect(rect, kBackgroundColor); |
| 772 kBackgroundColorR << 16 | | |
| 773 kBackgroundColorG << 8 | | |
| 774 kBackgroundColorB; | |
| 775 FillRect(rect, color); | |
| 776 ready->push_back(PaintManager::ReadyRect(rect, image_data_, true)); | 772 ready->push_back(PaintManager::ReadyRect(rect, image_data_, true)); |
| 777 *pending = paint_rects; | 773 *pending = paint_rects; |
| 778 return; | 774 return; |
| 779 } | 775 } |
| 780 | 776 |
| 781 engine_->PrePaint(); | 777 engine_->PrePaint(); |
| 782 | 778 |
| 783 for (size_t i = 0; i < paint_rects.size(); i++) { | 779 for (size_t i = 0; i < paint_rects.size(); i++) { |
| 784 // Intersect with plugin area since there could be pending invalidates from | 780 // Intersect with plugin area since there could be pending invalidates from |
| 785 // when the plugin area was larger. | 781 // when the plugin area was larger. |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1017 plugin_size_.width() - v_scrollbar_thickness, 0); | 1013 plugin_size_.width() - v_scrollbar_thickness, 0); |
| 1018 int height_without_scrollbar = std::max( | 1014 int height_without_scrollbar = std::max( |
| 1019 plugin_size_.height() - h_scrollbar_thickness, 0); | 1015 plugin_size_.height() - h_scrollbar_thickness, 0); |
| 1020 int left_width = available_area_.x(); | 1016 int left_width = available_area_.x(); |
| 1021 int right_start = available_area_.right(); | 1017 int right_start = available_area_.right(); |
| 1022 int right_width = abs(width_without_scrollbar - available_area_.right()); | 1018 int right_width = abs(width_without_scrollbar - available_area_.right()); |
| 1023 int bottom = std::min(available_area_.bottom(), height_without_scrollbar); | 1019 int bottom = std::min(available_area_.bottom(), height_without_scrollbar); |
| 1024 | 1020 |
| 1025 // Add the left, right, and bottom rectangles. Note: we assume only | 1021 // Add the left, right, and bottom rectangles. Note: we assume only |
| 1026 // horizontal centering. | 1022 // horizontal centering. |
| 1027 BackgroundPart part; | 1023 BackgroundPart part = { |
| 1028 part.color = kBackgroundColorA << 24 | | 1024 pp::Rect(0, 0, left_width, bottom), |
| 1029 kBackgroundColorR << 16 | | 1025 kBackgroundColor |
| 1030 kBackgroundColorG << 8 | | 1026 }; |
| 1031 kBackgroundColorB; | |
| 1032 part.location = pp::Rect(0, 0, left_width, bottom); | |
| 1033 if (!part.location.IsEmpty()) | 1027 if (!part.location.IsEmpty()) |
| 1034 background_parts_.push_back(part); | 1028 background_parts_.push_back(part); |
| 1035 part.location = pp::Rect(right_start, 0, right_width, bottom); | 1029 part.location = pp::Rect(right_start, 0, right_width, bottom); |
| 1036 if (!part.location.IsEmpty()) | 1030 if (!part.location.IsEmpty()) |
| 1037 background_parts_.push_back(part); | 1031 background_parts_.push_back(part); |
| 1038 part.location = pp::Rect( | 1032 part.location = pp::Rect( |
| 1039 0, bottom, width_without_scrollbar, height_without_scrollbar - bottom); | 1033 0, bottom, width_without_scrollbar, height_without_scrollbar - bottom); |
| 1040 if (!part.location.IsEmpty()) | 1034 if (!part.location.IsEmpty()) |
| 1041 background_parts_.push_back(part); | 1035 background_parts_.push_back(part); |
| 1042 | 1036 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1059 int Instance::GetDocumentPixelWidth() const { | 1053 int Instance::GetDocumentPixelWidth() const { |
| 1060 return static_cast<int>(ceil(document_size_.width() * zoom_ * device_scale_)); | 1054 return static_cast<int>(ceil(document_size_.width() * zoom_ * device_scale_)); |
| 1061 } | 1055 } |
| 1062 | 1056 |
| 1063 int Instance::GetDocumentPixelHeight() const { | 1057 int Instance::GetDocumentPixelHeight() const { |
| 1064 return static_cast<int>(ceil(document_size_.height() * | 1058 return static_cast<int>(ceil(document_size_.height() * |
| 1065 zoom_ * | 1059 zoom_ * |
| 1066 device_scale_)); | 1060 device_scale_)); |
| 1067 } | 1061 } |
| 1068 | 1062 |
| 1069 void Instance::FillRect(const pp::Rect& rect, unsigned int color) { | 1063 void Instance::FillRect(const pp::Rect& rect, uint32 color) { |
| 1070 DCHECK(!image_data_.is_null() || rect.IsEmpty()); | 1064 DCHECK(!image_data_.is_null() || rect.IsEmpty()); |
| 1071 unsigned int* buffer_start = static_cast<unsigned int*>(image_data_.data()); | 1065 uint32* buffer_start = static_cast<uint32*>(image_data_.data()); |
| 1072 int stride = image_data_.stride(); | 1066 int stride = image_data_.stride(); |
| 1073 unsigned int* ptr = buffer_start + rect.y() * stride / 4 + rect.x(); | 1067 uint32* ptr = buffer_start + rect.y() * stride / 4 + rect.x(); |
| 1074 int height = rect.height(); | 1068 int height = rect.height(); |
| 1075 int width = rect.width(); | 1069 int width = rect.width(); |
| 1076 for (int y = 0; y < height; ++y) { | 1070 for (int y = 0; y < height; ++y) { |
| 1077 for (int x = 0; x < width; ++x) | 1071 for (int x = 0; x < width; ++x) |
| 1078 *(ptr + x) = color; | 1072 *(ptr + x) = color; |
| 1079 ptr += stride /4; | 1073 ptr += stride / 4; |
| 1080 } | 1074 } |
| 1081 } | 1075 } |
| 1082 | 1076 |
| 1083 void Instance::DocumentSizeUpdated(const pp::Size& size) { | 1077 void Instance::DocumentSizeUpdated(const pp::Size& size) { |
| 1084 document_size_ = size; | 1078 document_size_ = size; |
| 1085 | 1079 |
| 1086 OnGeometryChanged(zoom_, device_scale_); | 1080 OnGeometryChanged(zoom_, device_scale_); |
| 1087 } | 1081 } |
| 1088 | 1082 |
| 1089 void Instance::Invalidate(const pp::Rect& rect) { | 1083 void Instance::Invalidate(const pp::Rect& rect) { |
| (...skipping 1620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2710 return instance_->HasScriptableMethod(name, exception); | 2704 return instance_->HasScriptableMethod(name, exception); |
| 2711 } | 2705 } |
| 2712 | 2706 |
| 2713 pp::Var PDFScriptableObject::Call(const pp::Var& method, | 2707 pp::Var PDFScriptableObject::Call(const pp::Var& method, |
| 2714 const std::vector<pp::Var>& args, | 2708 const std::vector<pp::Var>& args, |
| 2715 pp::Var* exception) { | 2709 pp::Var* exception) { |
| 2716 return instance_->CallScriptableMethod(method, args, exception); | 2710 return instance_->CallScriptableMethod(method, args, exception); |
| 2717 } | 2711 } |
| 2718 | 2712 |
| 2719 } // namespace chrome_pdf | 2713 } // namespace chrome_pdf |
| OLD | NEW |