This commit is contained in:
Cheng Zhao 2014-12-10 14:17:07 -08:00
Родитель 64edede20d
Коммит 409f2b4d0f
8 изменённых файлов: 255 добавлений и 202 удалений

Просмотреть файл

@ -319,7 +319,7 @@
'chromium_src/chrome/renderer/printing/print_web_view_helper.cc',
'chromium_src/chrome/renderer/printing/print_web_view_helper_linux.cc',
'chromium_src/chrome/renderer/printing/print_web_view_helper_mac.mm',
'chromium_src/chrome/renderer/printing/print_web_view_helper_win.cc',
'chromium_src/chrome/renderer/printing/print_web_view_helper_pdf_win.cc',
'chromium_src/chrome/renderer/printing/print_web_view_helper.h',
'chromium_src/chrome/renderer/tts_dispatcher.cc',
'chromium_src/chrome/renderer/tts_dispatcher.h',
@ -476,9 +476,9 @@
'<(libchromiumcontent_library_dir)/libEGL.dll',
'<(libchromiumcontent_library_dir)/libGLESv2.dll',
'<(libchromiumcontent_resources_dir)/icudtl.dat',
'<(libchromiumcontent_resources_dir)/content_resources_200_percent.pak',
'<(libchromiumcontent_resources_dir)/content_shell.pak',
'<(libchromiumcontent_resources_dir)/ui_resources_200_percent.pak',
'<(libchromiumcontent_resources_dir)/webkit_resources_200_percent.pak',
'external_binaries/d3dcompiler_43.dll',
'external_binaries/msvcp120.dll',
'external_binaries/msvcr120.dll',

Просмотреть файл

@ -111,7 +111,7 @@ void AtomMainDelegate::AddDataPackFromPath(
pak_dir.Append(FILE_PATH_LITERAL("ui_resources_200_percent.pak")),
ui::SCALE_FACTOR_200P);
bundle->AddDataPackFromPath(
pak_dir.Append(FILE_PATH_LITERAL("webkit_resources_200_percent.pak")),
pak_dir.Append(FILE_PATH_LITERAL("content_resources_200_percent.pak")),
ui::SCALE_FACTOR_200P);
#endif
}

Просмотреть файл

@ -39,9 +39,6 @@ int WinFrameView::NonClientHitTest(const gfx::Point& point) {
return FramelessView::NonClientHitTest(point);
}
void WinFrameView::SizeConstraintsChanged() override {
}
gfx::Size WinFrameView::GetMinimumSize() const {
gfx::Size size = FramelessView::GetMinimumSize();
return gfx::win::DIPToScreenSize(size);

Просмотреть файл

@ -18,7 +18,6 @@ class WinFrameView : public FramelessView {
gfx::Rect GetWindowBoundsForClientBounds(
const gfx::Rect& client_bounds) const override;
int NonClientHitTest(const gfx::Point& point) override;
void SizeConstraintsChanged() override;
// views::View:
gfx::Size GetMinimumSize() const override;

Просмотреть файл

@ -0,0 +1,250 @@
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/renderer/printing/print_web_view_helper.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/process/process_handle.h"
#include "chrome/common/print_messages.h"
#include "content/public/renderer/render_thread.h"
#include "printing/metafile_skia_wrapper.h"
#include "printing/page_size_margins.h"
#include "printing/pdf_metafile_skia.h"
#include "printing/units.h"
#include "skia/ext/platform_device.h"
#include "skia/ext/vector_canvas.h"
#include "third_party/WebKit/public/web/WebLocalFrame.h"
namespace printing {
using blink::WebFrame;
#if 0
bool PrintWebViewHelper::RenderPreviewPage(
int page_number,
const PrintMsg_Print_Params& print_params) {
PrintMsg_PrintPage_Params page_params;
page_params.params = print_params;
page_params.page_number = page_number;
scoped_ptr<PdfMetafileSkia> draft_metafile;
PdfMetafileSkia* initial_render_metafile = print_preview_context_.metafile();
if (print_preview_context_.IsModifiable() && is_print_ready_metafile_sent_) {
draft_metafile.reset(new PdfMetafileSkia);
initial_render_metafile = draft_metafile.get();
}
base::TimeTicks begin_time = base::TimeTicks::Now();
PrintPageInternal(page_params,
print_preview_context_.prepared_frame(),
initial_render_metafile,
NULL,
NULL);
print_preview_context_.RenderedPreviewPage(
base::TimeTicks::Now() - begin_time);
if (draft_metafile.get()) {
draft_metafile->FinishDocument();
} else if (print_preview_context_.IsModifiable() &&
print_preview_context_.generate_draft_pages()) {
DCHECK(!draft_metafile.get());
draft_metafile =
print_preview_context_.metafile()->GetMetafileForCurrentPage();
}
return PreviewPageRendered(page_number, draft_metafile.get());
}
#endif
bool PrintWebViewHelper::PrintPagesNative(blink::WebFrame* frame,
int page_count) {
PdfMetafileSkia metafile;
if (!metafile.Init())
return false;
const PrintMsg_PrintPages_Params& params = *print_pages_params_;
std::vector<int> printed_pages;
if (params.pages.empty()) {
for (int i = 0; i < page_count; ++i) {
printed_pages.push_back(i);
}
} else {
// TODO(vitalybuka): redesign to make more code cross platform.
for (size_t i = 0; i < params.pages.size(); ++i) {
if (params.pages[i] >= 0 && params.pages[i] < page_count) {
printed_pages.push_back(params.pages[i]);
}
}
}
if (printed_pages.empty())
return false;
std::vector<gfx::Size> page_size_in_dpi(printed_pages.size());
std::vector<gfx::Rect> content_area_in_dpi(printed_pages.size());
PrintMsg_PrintPage_Params page_params;
page_params.params = params.params;
for (size_t i = 0; i < printed_pages.size(); ++i) {
page_params.page_number = printed_pages[i];
PrintPageInternal(page_params,
frame,
&metafile,
&page_size_in_dpi[i],
&content_area_in_dpi[i]);
}
// blink::printEnd() for PDF should be called before metafile is closed.
FinishFramePrinting();
metafile.FinishDocument();
// Get the size of the resulting metafile.
uint32 buf_size = metafile.GetDataSize();
DCHECK_GT(buf_size, 0u);
PrintHostMsg_DidPrintPage_Params printed_page_params;
printed_page_params.data_size = 0;
printed_page_params.document_cookie = params.params.document_cookie;
printed_page_params.page_size = params.params.page_size;
printed_page_params.content_area = params.params.printable_area;
{
base::SharedMemory shared_buf;
// Allocate a shared memory buffer to hold the generated metafile data.
if (!shared_buf.CreateAndMapAnonymous(buf_size)) {
NOTREACHED() << "Buffer allocation failed";
return false;
}
// Copy the bits into shared memory.
if (!metafile.GetData(shared_buf.memory(), buf_size)) {
NOTREACHED() << "GetData() failed";
shared_buf.Unmap();
return false;
}
shared_buf.GiveToProcess(base::GetCurrentProcessHandle(),
&printed_page_params.metafile_data_handle);
shared_buf.Unmap();
printed_page_params.data_size = buf_size;
Send(new PrintHostMsg_DuplicateSection(
routing_id(),
printed_page_params.metafile_data_handle,
&printed_page_params.metafile_data_handle));
}
for (size_t i = 0; i < printed_pages.size(); ++i) {
printed_page_params.page_number = printed_pages[i];
printed_page_params.page_size = page_size_in_dpi[i];
printed_page_params.content_area = content_area_in_dpi[i];
Send(new PrintHostMsg_DidPrintPage(routing_id(), printed_page_params));
printed_page_params.metafile_data_handle = INVALID_HANDLE_VALUE;
}
return true;
}
void PrintWebViewHelper::PrintPageInternal(
const PrintMsg_PrintPage_Params& params,
WebFrame* frame,
PdfMetafileSkia* metafile,
gfx::Size* page_size_in_dpi,
gfx::Rect* content_area_in_dpi) {
PageSizeMargins page_layout_in_points;
double css_scale_factor = 1.0f;
ComputePageLayoutInPointsForCss(frame, params.page_number, params.params,
ignore_css_margins_, &css_scale_factor,
&page_layout_in_points);
gfx::Size page_size;
gfx::Rect content_area;
GetPageSizeAndContentAreaFromPageLayout(page_layout_in_points, &page_size,
&content_area);
int dpi = static_cast<int>(params.params.dpi);
// Calculate the actual page size and content area in dpi.
if (page_size_in_dpi) {
*page_size_in_dpi =
gfx::Size(static_cast<int>(ConvertUnitDouble(
page_size.width(), kPointsPerInch, dpi)),
static_cast<int>(ConvertUnitDouble(
page_size.height(), kPointsPerInch, dpi)));
}
if (content_area_in_dpi) {
// Output PDF matches paper size and should be printer edge to edge.
*content_area_in_dpi =
gfx::Rect(0, 0, page_size_in_dpi->width(), page_size_in_dpi->height());
}
gfx::Rect canvas_area =
content_area;
#if 0
params.params.display_header_footer ? gfx::Rect(page_size) : content_area;
#endif
float webkit_page_shrink_factor =
frame->getPrintPageShrink(params.page_number);
float scale_factor = css_scale_factor * webkit_page_shrink_factor;
SkBaseDevice* device = metafile->StartPageForVectorCanvas(page_size,
canvas_area,
scale_factor);
if (!device)
return;
// The printPage method take a reference to the canvas we pass down, so it
// can't be a stack object.
skia::RefPtr<skia::VectorCanvas> canvas =
skia::AdoptRef(new skia::VectorCanvas(device));
MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile);
skia::SetIsDraftMode(*canvas, is_print_ready_metafile_sent_);
#if 0
if (params.params.display_header_footer) {
// |page_number| is 0-based, so 1 is added.
PrintHeaderAndFooter(canvas.get(),
params.page_number + 1,
print_preview_context_.total_page_count(),
*frame,
scale_factor,
page_layout_in_points,
params.params);
}
#endif
float webkit_scale_factor = RenderPageContent(frame,
params.page_number,
canvas_area,
content_area,
scale_factor,
canvas.get());
DCHECK_GT(webkit_scale_factor, 0.0f);
// Done printing. Close the device context to retrieve the compiled metafile.
if (!metafile->FinishPage())
NOTREACHED() << "metafile failed";
}
bool PrintWebViewHelper::CopyMetafileDataToSharedMem(
PdfMetafileSkia* metafile,
base::SharedMemoryHandle* shared_mem_handle) {
uint32 buf_size = metafile->GetDataSize();
base::SharedMemory shared_buf;
// Allocate a shared memory buffer to hold the generated metafile data.
if (!shared_buf.CreateAndMapAnonymous(buf_size)) {
NOTREACHED() << "Buffer allocation failed";
return false;
}
// Copy the bits into shared memory.
if (!metafile->GetData(shared_buf.memory(), buf_size)) {
NOTREACHED() << "GetData() failed";
shared_buf.Unmap();
return false;
}
shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle);
shared_buf.Unmap();
Send(new PrintHostMsg_DuplicateSection(routing_id(), *shared_mem_handle,
shared_mem_handle));
return true;
}
} // namespace printing

Просмотреть файл

@ -1,193 +0,0 @@
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/renderer/printing/print_web_view_helper.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/metrics/histogram.h"
#include "base/process/process_handle.h"
#include "base/win/scoped_gdi_object.h"
#include "base/win/scoped_hdc.h"
#include "base/win/scoped_select_object.h"
#include "chrome/common/print_messages.h"
#include "printing/metafile.h"
#include "printing/metafile_impl.h"
#include "printing/metafile_skia_wrapper.h"
#include "printing/page_size_margins.h"
#include "printing/units.h"
#include "skia/ext/platform_device.h"
#include "skia/ext/refptr.h"
#include "skia/ext/vector_canvas.h"
#include "third_party/WebKit/public/web/WebLocalFrame.h"
#include "ui/gfx/gdi_util.h"
#include "ui/gfx/point.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/size.h"
namespace printing {
using blink::WebFrame;
void PrintWebViewHelper::PrintPageInternal(
const PrintMsg_PrintPage_Params& params,
const gfx::Size& canvas_size,
WebFrame* frame) {
// Generate a memory-based metafile. It will use the current screen's DPI.
// Each metafile contains a single page.
scoped_ptr<NativeMetafile> metafile(new NativeMetafile);
metafile->Init();
DCHECK(metafile->context());
skia::InitializeDC(metafile->context());
int page_number = params.page_number;
// Calculate the dpi adjustment.
// Browser will render context using desired_dpi, so we need to calculate
// adjustment factor to play content on the printer DC later during the
// actual printing.
double actual_shrink = static_cast<float>(params.params.desired_dpi /
params.params.dpi);
gfx::Size page_size_in_dpi;
gfx::Rect content_area_in_dpi;
// Render page for printing.
RenderPage(params.params, page_number, frame, false, metafile.get(),
&actual_shrink, &page_size_in_dpi, &content_area_in_dpi);
// Close the device context to retrieve the compiled metafile.
if (!metafile->FinishDocument())
NOTREACHED();
if (!params.params.supports_alpha_blend && metafile->IsAlphaBlendUsed()) {
scoped_ptr<NativeMetafile> raster_metafile(
metafile->RasterizeAlphaBlend());
if (raster_metafile.get())
metafile.swap(raster_metafile);
}
// Get the size of the compiled metafile.
uint32 buf_size = metafile->GetDataSize();
DCHECK_GT(buf_size, 128u);
PrintHostMsg_DidPrintPage_Params page_params;
page_params.data_size = buf_size;
page_params.metafile_data_handle = NULL;
page_params.page_number = page_number;
page_params.document_cookie = params.params.document_cookie;
page_params.actual_shrink = actual_shrink;
page_params.page_size = page_size_in_dpi;
page_params.content_area = content_area_in_dpi;
if (!CopyMetafileDataToSharedMem(metafile.get(),
&(page_params.metafile_data_handle))) {
page_params.data_size = 0;
}
Send(new PrintHostMsg_DidPrintPage(routing_id(), page_params));
}
void PrintWebViewHelper::RenderPage(
const PrintMsg_Print_Params& params, int page_number, WebFrame* frame,
bool is_preview, Metafile* metafile, double* actual_shrink,
gfx::Size* page_size_in_dpi, gfx::Rect* content_area_in_dpi) {
PageSizeMargins page_layout_in_points;
double css_scale_factor = 1.0f;
ComputePageLayoutInPointsForCss(frame, page_number, params,
ignore_css_margins_, &css_scale_factor,
&page_layout_in_points);
gfx::Size page_size;
gfx::Rect content_area;
GetPageSizeAndContentAreaFromPageLayout(page_layout_in_points, &page_size,
&content_area);
int dpi = static_cast<int>(params.dpi);
// Calculate the actual page size and content area in dpi.
if (page_size_in_dpi) {
*page_size_in_dpi = gfx::Size(
static_cast<int>(ConvertUnitDouble(page_size.width(), kPointsPerInch,
dpi)),
static_cast<int>(ConvertUnitDouble(page_size.height(), kPointsPerInch,
dpi)));
}
if (content_area_in_dpi) {
*content_area_in_dpi = gfx::Rect(
static_cast<int>(ConvertUnitDouble(content_area.x(), kPointsPerInch,
dpi)),
static_cast<int>(ConvertUnitDouble(content_area.y(), kPointsPerInch,
dpi)),
static_cast<int>(ConvertUnitDouble(content_area.width(), kPointsPerInch,
dpi)),
static_cast<int>(ConvertUnitDouble(content_area.height(),
kPointsPerInch, dpi)));
}
float webkit_page_shrink_factor = frame->getPrintPageShrink(page_number);
float scale_factor = css_scale_factor * webkit_page_shrink_factor;
gfx::Rect canvas_area = content_area;
SkBaseDevice* device = metafile->StartPageForVectorCanvas(
page_size, canvas_area, scale_factor);
DCHECK(device);
// The printPage method may take a reference to the canvas we pass down, so it
// can't be a stack object.
skia::RefPtr<skia::VectorCanvas> canvas =
skia::AdoptRef(new skia::VectorCanvas(device));
float webkit_scale_factor = RenderPageContent(frame, page_number, canvas_area,
content_area, scale_factor,
canvas.get());
if (*actual_shrink <= 0 || webkit_scale_factor <= 0) {
NOTREACHED() << "Printing page " << page_number << " failed.";
} else {
// While rendering certain plugins (PDF) to metafile, we might need to
// set custom scale factor. Update |actual_shrink| with custom scale
// if it is set on canvas.
// TODO(gene): We should revisit this solution for the next versions.
// Consider creating metafile of the right size (or resizable)
// https://code.google.com/p/chromium/issues/detail?id=126037
if (!MetafileSkiaWrapper::GetCustomScaleOnCanvas(
*canvas, actual_shrink)) {
// Update the dpi adjustment with the "page |actual_shrink|" calculated in
// webkit.
*actual_shrink /= (webkit_scale_factor * css_scale_factor);
}
}
bool result = metafile->FinishPage();
DCHECK(result);
}
bool PrintWebViewHelper::CopyMetafileDataToSharedMem(
Metafile* metafile, base::SharedMemoryHandle* shared_mem_handle) {
uint32 buf_size = metafile->GetDataSize();
base::SharedMemory shared_buf;
if (buf_size >= kMetafileMaxSize) {
NOTREACHED() << "Buffer too large: " << buf_size;
return false;
}
// Allocate a shared memory buffer to hold the generated metafile data.
if (!shared_buf.CreateAndMapAnonymous(buf_size)) {
NOTREACHED() << "Buffer allocation failed";
return false;
}
// Copy the bits into shared memory.
if (!metafile->GetData(shared_buf.memory(), buf_size)) {
NOTREACHED() << "GetData() failed";
shared_buf.Unmap();
return false;
}
shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle);
shared_buf.Unmap();
Send(new PrintHostMsg_DuplicateSection(routing_id(), *shared_mem_handle,
shared_mem_handle));
return true;
}
} // namespace printing

Просмотреть файл

@ -43,9 +43,9 @@ TARGET_BINARIES = {
'libGLESv2.dll',
'msvcp120.dll',
'msvcr120.dll',
'content_resources_200_percent.pak',
'ui_resources_200_percent.pak',
'vccorlib120.dll',
'webkit_resources_200_percent.pak',
'xinput1_3.dll',
],
'linux': [

2
vendor/brightray поставляемый

@ -1 +1 @@
Subproject commit fc681b2568eb8b1fe22b1d0611ead326d6d6d374
Subproject commit d70727848e4658ced013aee69dc073a8fcccfcaa