| 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 "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 5 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/linked_ptr.h" | 10 #include "base/memory/linked_ptr.h" |
| (...skipping 1119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1130 return GetPreferredPrintOutputFormat(&format); | 1130 return GetPreferredPrintOutputFormat(&format); |
| 1131 } | 1131 } |
| 1132 | 1132 |
| 1133 bool PluginInstance::IsPrintScalingDisabled() { | 1133 bool PluginInstance::IsPrintScalingDisabled() { |
| 1134 DCHECK(plugin_print_interface_); | 1134 DCHECK(plugin_print_interface_); |
| 1135 if (!plugin_print_interface_) | 1135 if (!plugin_print_interface_) |
| 1136 return false; | 1136 return false; |
| 1137 return plugin_print_interface_->IsScalingDisabled(pp_instance()) == PP_TRUE; | 1137 return plugin_print_interface_->IsScalingDisabled(pp_instance()) == PP_TRUE; |
| 1138 } | 1138 } |
| 1139 | 1139 |
| 1140 int PluginInstance::PrintBegin(const gfx::Rect& printable_area, | 1140 int PluginInstance::PrintBegin(const gfx::Rect& content_area, |
| 1141 const gfx::Rect& printable_area, |
| 1142 const gfx::Size& paper_size, |
| 1143 bool fit_to_paper_size, |
| 1141 int printer_dpi) { | 1144 int printer_dpi) { |
| 1142 // Keep a reference on the stack. See NOTE above. | 1145 // Keep a reference on the stack. See NOTE above. |
| 1143 scoped_refptr<PluginInstance> ref(this); | 1146 scoped_refptr<PluginInstance> ref(this); |
| 1144 PP_PrintOutputFormat_Dev format; | 1147 PP_PrintOutputFormat_Dev format; |
| 1145 if (!GetPreferredPrintOutputFormat(&format)) { | 1148 if (!GetPreferredPrintOutputFormat(&format)) { |
| 1146 // PrintBegin should not have been called since SupportsPrintInterface | 1149 // PrintBegin should not have been called since SupportsPrintInterface |
| 1147 // would have returned false; | 1150 // would have returned false; |
| 1148 NOTREACHED(); | 1151 NOTREACHED(); |
| 1149 return 0; | 1152 return 0; |
| 1150 } | 1153 } |
| 1151 | 1154 |
| 1152 int num_pages = 0; | 1155 int num_pages = 0; |
| 1153 PP_PrintSettings_Dev print_settings; | 1156 PP_PrintSettings_Dev print_settings; |
| 1154 print_settings.printable_area = PP_FromGfxRect(printable_area); | 1157 print_settings.printable_area = PP_FromGfxRect(printable_area); |
| 1158 print_settings.content_area = PP_FromGfxRect(content_area); |
| 1159 print_settings.paper_size = PP_FromGfxSize(paper_size); |
| 1155 print_settings.dpi = printer_dpi; | 1160 print_settings.dpi = printer_dpi; |
| 1156 print_settings.orientation = PP_PRINTORIENTATION_NORMAL; | 1161 print_settings.orientation = PP_PRINTORIENTATION_NORMAL; |
| 1157 print_settings.grayscale = PP_FALSE; | 1162 print_settings.grayscale = PP_FALSE; |
| 1163 print_settings.fit_to_paper_size = PP_FromBool(fit_to_paper_size); |
| 1158 print_settings.format = format; | 1164 print_settings.format = format; |
| 1159 num_pages = plugin_print_interface_->Begin(pp_instance(), | 1165 num_pages = plugin_print_interface_->Begin(pp_instance(), |
| 1160 &print_settings); | 1166 &print_settings); |
| 1161 if (!num_pages) | 1167 if (!num_pages) |
| 1162 return 0; | 1168 return 0; |
| 1163 current_print_settings_ = print_settings; | 1169 current_print_settings_ = print_settings; |
| 1164 #if defined(USE_SKIA) | 1170 #if defined(USE_SKIA) |
| 1165 canvas_ = NULL; | 1171 canvas_ = NULL; |
| 1166 ranges_.clear(); | 1172 ranges_.clear(); |
| 1167 #endif // USE_SKIA | 1173 #endif // USE_SKIA |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1449 if (metafile) | 1455 if (metafile) |
| 1450 ret = metafile->InitFromData(mapper.data(), mapper.size()); | 1456 ret = metafile->InitFromData(mapper.data(), mapper.size()); |
| 1451 #elif defined(OS_MACOSX) | 1457 #elif defined(OS_MACOSX) |
| 1452 printing::NativeMetafile metafile; | 1458 printing::NativeMetafile metafile; |
| 1453 // Create a PDF metafile and render from there into the passed in context. | 1459 // Create a PDF metafile and render from there into the passed in context. |
| 1454 if (metafile.InitFromData(mapper.data(), mapper.size())) { | 1460 if (metafile.InitFromData(mapper.data(), mapper.size())) { |
| 1455 // Flip the transform. | 1461 // Flip the transform. |
| 1456 CGContextRef cgContext = canvas; | 1462 CGContextRef cgContext = canvas; |
| 1457 CGContextSaveGState(cgContext); | 1463 CGContextSaveGState(cgContext); |
| 1458 CGContextTranslateCTM(cgContext, 0, | 1464 CGContextTranslateCTM(cgContext, 0, |
| 1459 current_print_settings_.printable_area.size.height); | 1465 current_print_settings_.content_area.size.height); |
| 1460 CGContextScaleCTM(cgContext, 1.0, -1.0); | 1466 CGContextScaleCTM(cgContext, 1.0, -1.0); |
| 1461 CGRect page_rect; | 1467 CGRect page_rect; |
| 1462 page_rect.origin.x = current_print_settings_.printable_area.point.x; | 1468 page_rect.origin.x = current_print_settings_.printable_area.point.x; |
| 1463 page_rect.origin.y = current_print_settings_.printable_area.point.y; | 1469 page_rect.origin.y = current_print_settings_.printable_area.point.y; |
| 1464 page_rect.size.width = current_print_settings_.printable_area.size.width; | 1470 page_rect.size.width = current_print_settings_.printable_area.size.width; |
| 1465 page_rect.size.height = current_print_settings_.printable_area.size.height; | 1471 page_rect.size.height = current_print_settings_.printable_area.size.height; |
| 1466 | 1472 |
| 1467 ret = metafile.RenderPage(1, cgContext, page_rect, true, false, true, true); | 1473 ret = metafile.RenderPage(1, cgContext, page_rect, true, false, true, true); |
| 1468 CGContextRestoreGState(cgContext); | 1474 CGContextRestoreGState(cgContext); |
| 1469 } | 1475 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1522 | 1528 |
| 1523 const SkBitmap* bitmap = image->GetMappedBitmap(); | 1529 const SkBitmap* bitmap = image->GetMappedBitmap(); |
| 1524 if (!bitmap) | 1530 if (!bitmap) |
| 1525 return false; | 1531 return false; |
| 1526 | 1532 |
| 1527 // Draw the printed image into the supplied canvas. | 1533 // Draw the printed image into the supplied canvas. |
| 1528 SkIRect src_rect; | 1534 SkIRect src_rect; |
| 1529 src_rect.set(0, 0, bitmap->width(), bitmap->height()); | 1535 src_rect.set(0, 0, bitmap->width(), bitmap->height()); |
| 1530 SkRect dest_rect; | 1536 SkRect dest_rect; |
| 1531 dest_rect.set( | 1537 dest_rect.set( |
| 1532 SkIntToScalar(current_print_settings_.printable_area.point.x), | 1538 SkIntToScalar(current_print_settings_.content_area.point.x), |
| 1533 SkIntToScalar(current_print_settings_.printable_area.point.y), | 1539 SkIntToScalar(current_print_settings_.content_area.point.y), |
| 1534 SkIntToScalar(current_print_settings_.printable_area.point.x + | 1540 SkIntToScalar(current_print_settings_.content_area.point.x + |
| 1535 current_print_settings_.printable_area.size.width), | 1541 current_print_settings_.content_area.size.width), |
| 1536 SkIntToScalar(current_print_settings_.printable_area.point.y + | 1542 SkIntToScalar(current_print_settings_.content_area.point.y + |
| 1537 current_print_settings_.printable_area.size.height)); | 1543 current_print_settings_.content_area.size.height)); |
| 1538 bool draw_to_canvas = true; | 1544 bool draw_to_canvas = true; |
| 1539 gfx::Rect dest_rect_gfx; | 1545 gfx::Rect dest_rect_gfx; |
| 1540 dest_rect_gfx.set_x(current_print_settings_.printable_area.point.x); | 1546 dest_rect_gfx.set_x(current_print_settings_.content_area.point.x); |
| 1541 dest_rect_gfx.set_y(current_print_settings_.printable_area.point.y); | 1547 dest_rect_gfx.set_y(current_print_settings_.content_area.point.y); |
| 1542 dest_rect_gfx.set_width(current_print_settings_.printable_area.size.width); | 1548 dest_rect_gfx.set_width(current_print_settings_.content_area.size.width); |
| 1543 dest_rect_gfx.set_height(current_print_settings_.printable_area.size.height); | 1549 dest_rect_gfx.set_height(current_print_settings_.content_area.size.height); |
| 1544 | 1550 |
| 1545 #if defined(OS_WIN) | 1551 #if defined(OS_WIN) |
| 1546 // Since this is a raster output, the size of the bitmap can be | 1552 // Since this is a raster output, the size of the bitmap can be |
| 1547 // huge (especially at high printer DPIs). On Windows, this can | 1553 // huge (especially at high printer DPIs). On Windows, this can |
| 1548 // result in a HUGE EMF (on Mac and Linux the output goes to PDF | 1554 // result in a HUGE EMF (on Mac and Linux the output goes to PDF |
| 1549 // which appears to Flate compress the bitmap). So, if this bitmap | 1555 // which appears to Flate compress the bitmap). So, if this bitmap |
| 1550 // is larger than 20 MB, we save the bitmap as a JPEG into the EMF | 1556 // is larger than 20 MB, we save the bitmap as a JPEG into the EMF |
| 1551 // DC. Note: We chose JPEG over PNG because JPEG compression seems | 1557 // DC. Note: We chose JPEG over PNG because JPEG compression seems |
| 1552 // way faster (about 4 times faster). | 1558 // way faster (about 4 times faster). |
| 1553 static const int kCompressionThreshold = 20 * 1024 * 1024; | 1559 static const int kCompressionThreshold = 20 * 1024 * 1024; |
| 1554 if (bitmap->getSize() > kCompressionThreshold) { | 1560 if (bitmap->getSize() > kCompressionThreshold) { |
| 1555 DrawJPEGToPlatformDC(*bitmap, dest_rect_gfx, canvas); | 1561 DrawJPEGToPlatformDC(*bitmap, dest_rect_gfx, canvas); |
| 1556 draw_to_canvas = false; | 1562 draw_to_canvas = false; |
| 1557 } | 1563 } |
| 1558 #endif // defined(OS_WIN) | 1564 #endif // defined(OS_WIN) |
| 1559 #if defined(OS_MACOSX) && !defined(USE_SKIA) | 1565 #if defined(OS_MACOSX) && !defined(USE_SKIA) |
| 1560 draw_to_canvas = false; | 1566 draw_to_canvas = false; |
| 1561 DrawSkBitmapToCanvas(*bitmap, canvas, dest_rect_gfx, | 1567 DrawSkBitmapToCanvas(*bitmap, canvas, dest_rect_gfx, |
| 1562 current_print_settings_.printable_area.size.height); | 1568 current_print_settings_.content_area.size.height); |
| 1563 // See comments in the header file. | 1569 // See comments in the header file. |
| 1564 last_printed_page_ = image; | 1570 last_printed_page_ = image; |
| 1565 #else // defined(OS_MACOSX) && !defined(USE_SKIA) | 1571 #else // defined(OS_MACOSX) && !defined(USE_SKIA) |
| 1566 if (draw_to_canvas) | 1572 if (draw_to_canvas) |
| 1567 canvas->drawBitmapRect(*bitmap, &src_rect, dest_rect); | 1573 canvas->drawBitmapRect(*bitmap, &src_rect, dest_rect); |
| 1568 #endif // defined(OS_MACOSX) && !defined(USE_SKIA) | 1574 #endif // defined(OS_MACOSX) && !defined(USE_SKIA) |
| 1569 return true; | 1575 return true; |
| 1570 } | 1576 } |
| 1571 | 1577 |
| 1572 #if defined(OS_WIN) | 1578 #if defined(OS_WIN) |
| (...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2185 screen_size_for_fullscreen_ = gfx::Size(); | 2191 screen_size_for_fullscreen_ = gfx::Size(); |
| 2186 WebElement element = container_->element(); | 2192 WebElement element = container_->element(); |
| 2187 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); | 2193 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); |
| 2188 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); | 2194 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); |
| 2189 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); | 2195 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); |
| 2190 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); | 2196 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); |
| 2191 } | 2197 } |
| 2192 | 2198 |
| 2193 } // namespace ppapi | 2199 } // namespace ppapi |
| 2194 } // namespace webkit | 2200 } // namespace webkit |
| OLD | NEW |