Skip to content

Commit

Permalink
PrintPreview: Remove |page_number| from StartPageForVectorCanvas func…
Browse files Browse the repository at this point in the history
…tion and |page_slot| from PrintMsg_PrintPage_Params.

We will not add preview pages to the complete metafile in out of order fashion.

BUG=none
TEST=print preview works after code changes.

Review URL: http://codereview.chromium.org/7549001

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@95092 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
kmadhusu@chromium.org committed Aug 2, 2011
1 parent 1c78d78 commit 534c4fb
Show file tree
Hide file tree
Showing 15 changed files with 30 additions and 67 deletions.
5 changes: 0 additions & 5 deletions chrome/common/print_messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ IPC_STRUCT_BEGIN(PrintMsg_PrintPage_Params)
// The page number is the indicator of the square that should be rendered
// according to the layout specified in PrintMsg_Print_Params.
IPC_STRUCT_MEMBER(int, page_number)

// The page number in the resulting document. If the user is only printing
// page 2, |page_number| above will 1, but |page_slot| will be 0, as it's the
// first page in the final document.
IPC_STRUCT_MEMBER(int, page_slot)
IPC_STRUCT_END()

IPC_STRUCT_BEGIN(PrintMsg_PrintPages_Params)
Expand Down
8 changes: 0 additions & 8 deletions chrome/renderer/print_web_view_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -582,15 +582,13 @@ bool PrintWebViewHelper::PrintPages(const PrintMsg_PrintPages_Params& params,
if (params.pages.empty()) {
for (int i = 0; i < page_count; ++i) {
page_params.page_number = i;
page_params.page_slot = i;
PrintPageInternal(page_params, canvas_size, frame);
}
} else {
for (size_t i = 0; i < params.pages.size(); ++i) {
if (params.pages[i] >= page_count)
break;
page_params.page_number = params.pages[i];
page_params.page_slot = i;
PrintPageInternal(page_params, canvas_size, frame);
}
}
Expand Down Expand Up @@ -1094,12 +1092,6 @@ bool PrintWebViewHelper::PrintPreviewContext::IsModifiable() const {
return mime != "application/pdf";
}

int PrintWebViewHelper::PrintPreviewContext::GetPageSlotForPage(
int page_number) const {
int page_slot = rendered_pages_[page_number].second;
return page_slot == -1 ? page_number : page_slot;
}

WebKit::WebFrame* PrintWebViewHelper::PrintPreviewContext::frame() const {
return frame_;
}
Expand Down
10 changes: 2 additions & 8 deletions chrome/renderer/print_web_view_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,11 @@ class PrintWebViewHelper : public RenderViewObserver,
// Platform specific helper function for rendering page(s) to |metafile|.
#if defined(OS_WIN)
void RenderPage(const PrintMsg_Print_Params& params, float* scale_factor,
int page_number, int page_slot, bool is_preview,
WebKit::WebFrame* frame,
int page_number, bool is_preview, WebKit::WebFrame* frame,
scoped_ptr<printing::Metafile>* metafile);
#elif defined(OS_MACOSX)
void RenderPage(const gfx::Size& page_size, const gfx::Rect& content_area,
const float& scale_factor, int page_number, int page_slot,
const float& scale_factor, int page_number,
WebKit::WebFrame* frame, printing::Metafile* metafile);
#elif defined(OS_POSIX)
bool RenderPages(const PrintMsg_PrintPages_Params& params,
Expand Down Expand Up @@ -341,11 +340,6 @@ class PrintWebViewHelper : public RenderViewObserver,
bool IsBusy() const;
bool IsModifiable() const;

// Return the page slot in the final document for |page_number|. i.e. if
// the user selected just page 3, the page slot would be 0, since it is
// the first page in the resulting document.
int GetPageSlotForPage(int page_number) const;

// Getters
WebKit::WebFrame* frame() const;
WebKit::WebNode* node() const;
Expand Down
6 changes: 1 addition & 5 deletions chrome/renderer/print_web_view_helper_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ void PrintWebViewHelper::RenderPreviewPage(int page_number) {
PrintMsg_PrintPage_Params page_params;
page_params.params = print_preview_context_.print_params();
page_params.page_number = page_number;
page_params.page_slot =
print_preview_context_.GetPageSlotForPage(page_number);

base::TimeTicks begin_time = base::TimeTicks::Now();
PrintPageInternal(page_params,
Expand Down Expand Up @@ -162,13 +160,11 @@ bool PrintWebViewHelper::RenderPages(const PrintMsg_PrintPages_Params& params,
if (params.pages.empty()) {
for (int i = 0; i < *page_count; ++i) {
page_params.page_number = i;
page_params.page_slot = i;
PrintPageInternal(page_params, canvas_size, frame, metafile);
}
} else {
for (size_t i = 0; i < params.pages.size(); ++i) {
page_params.page_number = params.pages[i];
page_params.page_slot = i;
PrintPageInternal(page_params, canvas_size, frame, metafile);
}
}
Expand Down Expand Up @@ -202,7 +198,7 @@ void PrintWebViewHelper::PrintPageInternal(
page_layout_in_points.content_height);

SkDevice* device = metafile->StartPageForVectorCanvas(
params.page_slot, page_size, content_area, 1.0f);
page_size, content_area, 1.0f);
if (!device)
return;

Expand Down
8 changes: 3 additions & 5 deletions chrome/renderer/print_web_view_helper_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@

float scale_factor = frame->getPrintPageShrink(params.page_number);
int page_number = params.page_number;
int page_slot = params.page_slot;

// Render page for printing.
gfx::Rect content_area(params.params.printable_size);
RenderPage(params.params.printable_size, content_area, scale_factor,
page_number, page_slot, frame, &metafile);
page_number, frame, &metafile);
metafile.FinishDocument();

PrintHostMsg_DidPrintPage_Params page_params;
Expand Down Expand Up @@ -81,7 +80,6 @@

base::TimeTicks begin_time = base::TimeTicks::Now();
RenderPage(printParams.page_size, content_area, scale_factor, page_number,
print_preview_context_.GetPageSlotForPage(page_number),
print_preview_context_.frame(), initial_render_metafile);
print_preview_context_.RenderedPreviewPage(
base::TimeTicks::Now() - begin_time);
Expand Down Expand Up @@ -114,13 +112,13 @@

void PrintWebViewHelper::RenderPage(
const gfx::Size& page_size, const gfx::Rect& content_area,
const float& scale_factor, int page_number, int page_slot, WebFrame* frame,
const float& scale_factor, int page_number, WebFrame* frame,
printing::Metafile* metafile) {

{
#if defined(USE_SKIA)
SkDevice* device = metafile->StartPageForVectorCanvas(
page_slot, page_size, content_area, scale_factor);
page_size, content_area, scale_factor);
if (!device)
return;

Expand Down
12 changes: 4 additions & 8 deletions chrome/renderer/print_web_view_helper_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,13 @@ void PrintWebViewHelper::PrintPageInternal(
skia::InitializeDC(metafile->context());

int page_number = params.page_number;
int page_slot = params.page_slot;

// Calculate the dpi adjustment.
float scale_factor = static_cast<float>(params.params.desired_dpi /
params.params.dpi);

// Render page for printing.
RenderPage(params.params, &scale_factor, page_number, page_slot, false, frame,
RenderPage(params.params, &scale_factor, page_number, false, frame,
&metafile);

// Close the device context to retrieve the compiled metafile.
Expand Down Expand Up @@ -133,8 +132,7 @@ void PrintWebViewHelper::RenderPreviewPage(int page_number) {
scoped_ptr<Metafile> metafile(print_preview_context_.metafile());

base::TimeTicks begin_time = base::TimeTicks::Now();
RenderPage(print_params, &scale_factor, page_number,
print_preview_context_.GetPageSlotForPage(page_number), true,
RenderPage(print_params, &scale_factor, page_number, true,
print_preview_context_.frame(), &metafile);

print_preview_context_.RenderedPreviewPage(
Expand All @@ -152,8 +150,7 @@ void PrintWebViewHelper::RenderPreviewPage(int page_number) {

void PrintWebViewHelper::RenderPage(
const PrintMsg_Print_Params& params, float* scale_factor, int page_number,
int page_slot, bool is_preview, WebFrame* frame,
scoped_ptr<Metafile>* metafile) {
bool is_preview, WebFrame* frame, scoped_ptr<Metafile>* metafile) {
PageSizeMargins page_layout_in_points;
GetPageSizeAndMarginsInPoints(frame, page_number, params,
&page_layout_in_points);
Expand Down Expand Up @@ -182,8 +179,7 @@ void PrintWebViewHelper::RenderPage(
static_cast<int>(page_layout_in_points.content_width),
static_cast<int>(page_layout_in_points.content_height));
SkDevice* device = (*metafile)->StartPageForVectorCanvas(
page_slot, page_size, content_area,
frame->getPrintPageShrink(page_number));
page_size, content_area, frame->getPrintPageShrink(page_number));
DCHECK(device);
// The printPage method may take a reference to the canvas we pass down, so it
// can't be a stack object.
Expand Down
3 changes: 1 addition & 2 deletions printing/emf_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,8 @@ bool Emf::Record::SafePlayback(const XFORM* base_matrix) const {
}

SkDevice* Emf::StartPageForVectorCanvas(
int page_number, const gfx::Size& page_size, const gfx::Rect& content_area,
const gfx::Size& page_size, const gfx::Rect& content_area,
const float& scale_factor) {
DCHECK(page_number == page_count_);
if (!StartPage(page_size, content_area, scale_factor))
return NULL;

Expand Down
4 changes: 2 additions & 2 deletions printing/emf_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class Emf : public Metafile {
virtual bool InitFromData(const void* src_buffer, uint32 src_buffer_size);

virtual SkDevice* StartPageForVectorCanvas(
int page_number, const gfx::Size& page_size,
const gfx::Rect& content_area, const float& scale_factor);
const gfx::Size& page_size, const gfx::Rect& content_area,
const float& scale_factor);
// Inserts a custom GDICOMMENT records indicating StartPage/EndPage calls
// (since StartPage and EndPage do not work in a metafile DC). Only valid
// when hdc_ is non-NULL. |page_size|, |content_area|, and |scale_factor| are
Expand Down
3 changes: 1 addition & 2 deletions printing/metafile.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@ class Metafile {

// This method calls StartPage and then returns an appropriate
// VectorPlatformDevice implementation bound to the context created by
// StartPage or NULL on error. |page_number| is zero based.
// StartPage or NULL on error.
virtual SkDevice* StartPageForVectorCanvas(
int page_number,
const gfx::Size& page_size,
const gfx::Rect& content_area,
const float& scale_factor) = 0;
Expand Down
4 changes: 2 additions & 2 deletions printing/pdf_metafile_cairo_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ bool PdfMetafileCairo::InitFromData(const void* src_buffer,
}

SkDevice* PdfMetafileCairo::StartPageForVectorCanvas(
int /*page_number*/, const gfx::Size& page_size,
const gfx::Rect& content_area, const float& scale_factor) {
const gfx::Size& page_size, const gfx::Rect& content_area,
const float& scale_factor) {
if (!StartPage(page_size, content_area, scale_factor))
return NULL;

Expand Down
4 changes: 2 additions & 2 deletions printing/pdf_metafile_cairo_linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class PdfMetafileCairo : public Metafile {
virtual bool InitFromData(const void* src_buffer, uint32 src_buffer_size);

virtual SkDevice* StartPageForVectorCanvas(
int page_number, const gfx::Size& page_size,
const gfx::Rect& content_area, const float& scale_factor);
const gfx::Size& page_size, const gfx::Rect& content_area,
const float& scale_factor);

virtual bool StartPage(const gfx::Size& page_size,
const gfx::Rect& content_area,
Expand Down
2 changes: 1 addition & 1 deletion printing/pdf_metafile_cg_mac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ bool PdfMetafileCg::InitFromData(const void* src_buffer,
}

SkDevice* PdfMetafileCg::StartPageForVectorCanvas(
int page_number, const gfx::Size& page_size, const gfx::Rect& content_area,
const gfx::Size& page_size, const gfx::Rect& content_area,
const float& scale_factor) {
NOTIMPLEMENTED();
return NULL;
Expand Down
4 changes: 2 additions & 2 deletions printing/pdf_metafile_cg_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class PdfMetafileCg : public Metafile, public base::ThreadChecker {

// Not implemented on mac.
virtual SkDevice* StartPageForVectorCanvas(
int page_number, const gfx::Size& page_size,
const gfx::Rect& content_area, const float& scale_factor);
const gfx::Size& page_size, const gfx::Rect& content_area,
const float& scale_factor);
virtual bool StartPage(const gfx::Size& page_size,
const gfx::Rect& content_area,
const float& scale_factor);
Expand Down
17 changes: 7 additions & 10 deletions printing/pdf_metafile_skia.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,10 @@ bool PdfMetafileSkia::InitFromData(const void* src_buffer,
}

SkDevice* PdfMetafileSkia::StartPageForVectorCanvas(
int page_number, const gfx::Size& page_size, const gfx::Rect& content_area,
const gfx::Size& page_size, const gfx::Rect& content_area,
const float& scale_factor) {
DCHECK_EQ(outstanding_page_number_, kNoOutstandingPage);
DCHECK_GE(page_number, 0);
outstanding_page_number_ = page_number;
DCHECK(!page_outstanding_);
page_outstanding_ = true;

// Adjust for the margins and apply the scale factor.
SkMatrix transform;
Expand Down Expand Up @@ -84,11 +83,9 @@ bool PdfMetafileSkia::StartPage(const gfx::Size& page_size,

bool PdfMetafileSkia::FinishPage() {
DCHECK(data_->current_page_.get());
DCHECK_GE(outstanding_page_number_, 0);

data_->pdf_doc_.setPage(outstanding_page_number_ + 1,
data_->current_page_.get());
outstanding_page_number_ = kNoOutstandingPage;
data_->pdf_doc_.appendPage(data_->current_page_.get());
page_outstanding_ = false;
return true;
}

Expand All @@ -97,7 +94,7 @@ bool PdfMetafileSkia::FinishDocument() {
if (data_->pdf_stream_.getOffset())
return true;

if (outstanding_page_number_ >= 0)
if (page_outstanding_)
FinishPage();

data_->current_page_ = NULL;
Expand Down Expand Up @@ -239,7 +236,7 @@ bool PdfMetafileSkia::SaveToFD(const base::FileDescriptor& fd) const {

PdfMetafileSkia::PdfMetafileSkia()
: data_(new PdfMetafileSkiaData),
outstanding_page_number_(kNoOutstandingPage) {
page_outstanding_(false) {
}

PdfMetafileSkia* PdfMetafileSkia::GetMetafileForCurrentPage() {
Expand Down
7 changes: 2 additions & 5 deletions printing/pdf_metafile_skia.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class PdfMetafileSkia : public Metafile {
virtual bool InitFromData(const void* src_buffer, uint32 src_buffer_size);

virtual SkDevice* StartPageForVectorCanvas(
int page_number,
const gfx::Size& page_size,
const gfx::Rect& content_area,
const float& scale_factor);
Expand Down Expand Up @@ -73,12 +72,10 @@ class PdfMetafileSkia : public Metafile {
PdfMetafileSkia* GetMetafileForCurrentPage();

private:
static const int kNoOutstandingPage = -1;

scoped_ptr<PdfMetafileSkiaData> data_;

// Page number of the outstanding page, or kNoOutstandingPage.
int outstanding_page_number_;
// True when finish page is outstanding for current page.
bool page_outstanding_;

DISALLOW_COPY_AND_ASSIGN(PdfMetafileSkia);
};
Expand Down

0 comments on commit 534c4fb

Please sign in to comment.