OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 833 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
844 RectToPPRect(printable_area, &print_settings.printable_area); | 844 RectToPPRect(printable_area, &print_settings.printable_area); |
845 print_settings.dpi = printer_dpi; | 845 print_settings.dpi = printer_dpi; |
846 print_settings.orientation = PP_PRINTORIENTATION_NORMAL; | 846 print_settings.orientation = PP_PRINTORIENTATION_NORMAL; |
847 print_settings.grayscale = PP_FALSE; | 847 print_settings.grayscale = PP_FALSE; |
848 print_settings.format = format; | 848 print_settings.format = format; |
849 num_pages = plugin_print_interface_->Begin(pp_instance(), | 849 num_pages = plugin_print_interface_->Begin(pp_instance(), |
850 &print_settings); | 850 &print_settings); |
851 if (!num_pages) | 851 if (!num_pages) |
852 return 0; | 852 return 0; |
853 current_print_settings_ = print_settings; | 853 current_print_settings_ = print_settings; |
854 #if defined(USE_SKIA) | 854 #if defined(OS_LINUX) || defined(OS_WIN) |
855 canvas_ = NULL; | 855 canvas_ = NULL; |
856 ranges_.clear(); | 856 ranges_.clear(); |
857 #endif // USE_SKIA | 857 #endif // OS_LINUX || OS_WIN |
858 return num_pages; | 858 return num_pages; |
859 } | 859 } |
860 | 860 |
861 bool PluginInstance::PrintPage(int page_number, WebKit::WebCanvas* canvas) { | 861 bool PluginInstance::PrintPage(int page_number, WebKit::WebCanvas* canvas) { |
862 DCHECK(plugin_print_interface_); | 862 DCHECK(plugin_print_interface_); |
863 PP_PrintPageNumberRange_Dev page_range; | 863 PP_PrintPageNumberRange_Dev page_range; |
864 page_range.first_page_number = page_range.last_page_number = page_number; | 864 page_range.first_page_number = page_range.last_page_number = page_number; |
865 #if defined(USE_SKIA) | 865 #if defined(OS_LINUX) || defined(OS_WIN) |
866 // The canvas only has a metafile on it for print preview. | 866 // The canvas only has a metafile on it for print preview. |
867 bool save_for_later = | 867 if (printing::MetafileSkiaWrapper::GetMetafileFromCanvas(canvas)) { |
868 (printing::MetafileSkiaWrapper::GetMetafileFromCanvas(*canvas) != NULL); | |
869 #if defined(OS_MACOSX) || defined(OS_WIN) | |
870 save_for_later = save_for_later && skia::IsPreviewMetafile(*canvas); | |
871 #endif | |
872 if (save_for_later) { | |
873 ranges_.push_back(page_range); | 868 ranges_.push_back(page_range); |
874 canvas_ = canvas; | 869 canvas_ = canvas; |
875 return true; | 870 return true; |
876 } else | 871 } else |
877 #endif // USE_SKIA | 872 #endif // OS_LINUX || OS_WIN |
878 { | 873 { |
879 return PrintPageHelper(&page_range, 1, canvas); | 874 return PrintPageHelper(&page_range, 1, canvas); |
880 } | 875 } |
881 } | 876 } |
882 | 877 |
883 bool PluginInstance::PrintPageHelper(PP_PrintPageNumberRange_Dev* page_ranges, | 878 bool PluginInstance::PrintPageHelper(PP_PrintPageNumberRange_Dev* page_ranges, |
884 int num_ranges, | 879 int num_ranges, |
885 WebKit::WebCanvas* canvas) { | 880 WebKit::WebCanvas* canvas) { |
886 // Keep a reference on the stack. See NOTE above. | 881 // Keep a reference on the stack. See NOTE above. |
887 scoped_refptr<PluginInstance> ref(this); | 882 scoped_refptr<PluginInstance> ref(this); |
(...skipping 11 matching lines...) Expand all Loading... |
899 | 894 |
900 // Now we need to release the print output resource. | 895 // Now we need to release the print output resource. |
901 PluginModule::GetCore()->ReleaseResource(print_output); | 896 PluginModule::GetCore()->ReleaseResource(print_output); |
902 | 897 |
903 return ret; | 898 return ret; |
904 } | 899 } |
905 | 900 |
906 void PluginInstance::PrintEnd() { | 901 void PluginInstance::PrintEnd() { |
907 // Keep a reference on the stack. See NOTE above. | 902 // Keep a reference on the stack. See NOTE above. |
908 scoped_refptr<PluginInstance> ref(this); | 903 scoped_refptr<PluginInstance> ref(this); |
909 #if defined(USE_SKIA) | 904 #if defined(OS_LINUX) || defined(OS_WIN) |
910 if (!ranges_.empty()) | 905 if (!ranges_.empty()) |
911 PrintPageHelper(&(ranges_.front()), ranges_.size(), canvas_.get()); | 906 PrintPageHelper(&(ranges_.front()), ranges_.size(), canvas_.get()); |
912 canvas_ = NULL; | 907 canvas_ = NULL; |
913 ranges_.clear(); | 908 ranges_.clear(); |
914 #endif // USE_SKIA | 909 #endif // OS_LINUX || OS_WIN |
915 | 910 |
916 DCHECK(plugin_print_interface_); | 911 DCHECK(plugin_print_interface_); |
917 if (plugin_print_interface_) | 912 if (plugin_print_interface_) |
918 plugin_print_interface_->End(pp_instance()); | 913 plugin_print_interface_->End(pp_instance()); |
919 | 914 |
920 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); | 915 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); |
921 #if defined(OS_MACOSX) | 916 #if defined(OS_MACOSX) |
922 last_printed_page_ = NULL; | 917 last_printed_page_ = NULL; |
923 #endif // defined(OS_MACOSX) | 918 #endif // defined(OS_MACOSX) |
924 } | 919 } |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1059 if (!render_proc) | 1054 if (!render_proc) |
1060 return false; | 1055 return false; |
1061 #endif // defined(OS_WIN) | 1056 #endif // defined(OS_WIN) |
1062 | 1057 |
1063 bool ret = false; | 1058 bool ret = false; |
1064 #if defined(OS_LINUX) || (defined(OS_MACOSX) && defined(USE_SKIA)) | 1059 #if defined(OS_LINUX) || (defined(OS_MACOSX) && defined(USE_SKIA)) |
1065 // On Linux we just set the final bits in the native metafile | 1060 // On Linux we just set the final bits in the native metafile |
1066 // (NativeMetafile and PreviewMetafile must have compatible formats, | 1061 // (NativeMetafile and PreviewMetafile must have compatible formats, |
1067 // i.e. both PDF for this to work). | 1062 // i.e. both PDF for this to work). |
1068 printing::Metafile* metafile = | 1063 printing::Metafile* metafile = |
1069 printing::MetafileSkiaWrapper::GetMetafileFromCanvas(*canvas); | 1064 printing::MetafileSkiaWrapper::GetMetafileFromCanvas(canvas); |
1070 DCHECK(metafile != NULL); | 1065 DCHECK(metafile != NULL); |
1071 if (metafile) | 1066 if (metafile) |
1072 ret = metafile->InitFromData(mapper.data(), mapper.size()); | 1067 ret = metafile->InitFromData(mapper.data(), mapper.size()); |
1073 #elif defined(OS_MACOSX) | 1068 #elif defined(OS_MACOSX) |
1074 printing::NativeMetafile metafile; | 1069 printing::NativeMetafile metafile; |
1075 // Create a PDF metafile and render from there into the passed in context. | 1070 // Create a PDF metafile and render from there into the passed in context. |
1076 if (metafile.InitFromData(mapper.data(), mapper.size())) { | 1071 if (metafile.InitFromData(mapper.data(), mapper.size())) { |
1077 // Flip the transform. | 1072 // Flip the transform. |
1078 CGContextRef cgContext = canvas; | 1073 CGContextRef cgContext = canvas; |
1079 CGContextSaveGState(cgContext); | 1074 CGContextSaveGState(cgContext); |
1080 CGContextTranslateCTM(cgContext, 0, | 1075 CGContextTranslateCTM(cgContext, 0, |
1081 current_print_settings_.printable_area.size.height); | 1076 current_print_settings_.printable_area.size.height); |
1082 CGContextScaleCTM(cgContext, 1.0, -1.0); | 1077 CGContextScaleCTM(cgContext, 1.0, -1.0); |
1083 CGRect page_rect; | 1078 CGRect page_rect; |
1084 page_rect.origin.x = current_print_settings_.printable_area.point.x; | 1079 page_rect.origin.x = current_print_settings_.printable_area.point.x; |
1085 page_rect.origin.y = current_print_settings_.printable_area.point.y; | 1080 page_rect.origin.y = current_print_settings_.printable_area.point.y; |
1086 page_rect.size.width = current_print_settings_.printable_area.size.width; | 1081 page_rect.size.width = current_print_settings_.printable_area.size.width; |
1087 page_rect.size.height = current_print_settings_.printable_area.size.height; | 1082 page_rect.size.height = current_print_settings_.printable_area.size.height; |
1088 | 1083 |
1089 ret = metafile.RenderPage(1, cgContext, page_rect, true, false, true, true); | 1084 ret = metafile.RenderPage(1, cgContext, page_rect, true, false, true, true); |
1090 CGContextRestoreGState(cgContext); | 1085 CGContextRestoreGState(cgContext); |
1091 } | 1086 } |
1092 #elif defined(OS_WIN) | 1087 #elif defined(OS_WIN) |
1093 printing::Metafile* metafile = | 1088 printing::Metafile* metafile = |
1094 printing::MetafileSkiaWrapper::GetMetafileFromCanvas(*canvas); | 1089 printing::MetafileSkiaWrapper::GetMetafileFromCanvas(canvas); |
1095 if (metafile) { | 1090 if (metafile) { |
1096 // We only have a metafile when doing print preview, so we just want to | 1091 // We only have a metafile when doing print preview, so we just want to |
1097 // pass the PDF off to preview. | 1092 // pass the PDF off to preview. |
1098 ret = metafile->InitFromData(mapper.data(), mapper.size()); | 1093 ret = metafile->InitFromData(mapper.data(), mapper.size()); |
1099 } else { | 1094 } else { |
1100 // On Windows, we now need to render the PDF to the DC that backs the | 1095 // On Windows, we now need to render the PDF to the DC that backs the |
1101 // supplied canvas. | 1096 // supplied canvas. |
1102 HDC dc = skia::BeginPlatformPaint(canvas); | 1097 HDC dc = skia::BeginPlatformPaint(canvas); |
1103 gfx::Size size_in_pixels; | 1098 gfx::Size size_in_pixels; |
1104 size_in_pixels.set_width(printing::ConvertUnit( | 1099 size_in_pixels.set_width(printing::ConvertUnit( |
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1659 } | 1654 } |
1660 | 1655 |
1661 void PluginInstance::DoSetCursor(WebCursorInfo* cursor) { | 1656 void PluginInstance::DoSetCursor(WebCursorInfo* cursor) { |
1662 cursor_.reset(cursor); | 1657 cursor_.reset(cursor); |
1663 if (fullscreen_container_) | 1658 if (fullscreen_container_) |
1664 fullscreen_container_->DidChangeCursor(*cursor); | 1659 fullscreen_container_->DidChangeCursor(*cursor); |
1665 } | 1660 } |
1666 | 1661 |
1667 } // namespace ppapi | 1662 } // namespace ppapi |
1668 } // namespace webkit | 1663 } // namespace webkit |
OLD | NEW |