Skip to content

Commit

Permalink
Make the PDF viewer background color a property of the instance.
Browse files Browse the repository at this point in the history
This simplifies how the background color is set and makes it work for
print preview.

BUG= 456621

Review URL: https://codereview.chromium.org/874663006

Cr-Commit-Position: refs/heads/master@{#315256}
  • Loading branch information
raymes authored and Commit bot committed Feb 9, 2015
1 parent 8533a51 commit 8a9c0f3
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 33 deletions.
6 changes: 4 additions & 2 deletions pdf/instance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,6 @@ bool Instance::Init(uint32_t argc, const char* argn[], const char* argv[]) {

CreatePageIndicator(IsPrintPreviewUrl(url));

engine_->SetBackgroundColor(kBackgroundColor);

if (!full_) {
// For PDFs embedded in a frame, we don't get the data automatically like we
// do for full-frame loads. Start loading the data manually.
Expand Down Expand Up @@ -2643,6 +2641,10 @@ bool Instance::IsPrintPreview() {
return IsPrintPreviewUrl(url_);
}

uint32 Instance::GetBackgroundColor() {
return kBackgroundColor;
}

int Instance::GetPageNumberToDisplay() {
int page = engine_->GetMostVisiblePage();
if (IsPrintPreview() && !print_preview_page_numbers_.empty()) {
Expand Down
1 change: 1 addition & 0 deletions pdf/instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ class Instance : public pp::InstancePrivate,
void DocumentLoadProgress(uint32 available, uint32 doc_size) override;
void FormTextFieldFocusChange(bool in_focus) override;
bool IsPrintPreview() override;
uint32 GetBackgroundColor() override;

// ControlOwner implementation.
void OnEvent(uint32 control_id, uint32 event_id, void* data) override;
Expand Down
16 changes: 10 additions & 6 deletions pdf/out_of_process_instance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ OutOfProcessInstance::OutOfProcessInstance(PP_Instance instance)
recently_sent_find_update_(false),
received_viewport_message_(false),
did_call_start_loading_(false),
stop_scrolling_(false) {
stop_scrolling_(false),
background_color_(kBackgroundColor) {
loader_factory_.Initialize(this);
timer_factory_.Initialize(this);
form_factory_.Initialize(this);
Expand Down Expand Up @@ -348,10 +349,9 @@ bool OutOfProcessInstance::Init(uint32_t argc,
}

if (is_material)
engine_->SetBackgroundColor(kBackgroundColorMaterial);
background_color_ = kBackgroundColorMaterial;
else
engine_->SetBackgroundColor(kBackgroundColor);

background_color_ = kBackgroundColor;

// TODO(raymes): This is a hack to ensure that if no headers are passed in
// then we get the right MIME type. When the in process plugin is removed we
Expand Down Expand Up @@ -675,7 +675,7 @@ void OutOfProcessInstance::OnPaint(
if (first_paint_) {
first_paint_ = false;
pp::Rect rect = pp::Rect(pp::Point(), image_data_.size());
FillRect(rect, engine_->GetBackgroundColor());
FillRect(rect, background_color_);
ready->push_back(PaintManager::ReadyRect(rect, image_data_, true));
}

Expand Down Expand Up @@ -768,7 +768,7 @@ void OutOfProcessInstance::CalculateBackgroundParts() {
// horizontal centering.
BackgroundPart part = {
pp::Rect(0, 0, left_width, bottom),
engine_->GetBackgroundColor()
background_color_
};
if (!part.location.IsEmpty())
background_parts_.push_back(part);
Expand Down Expand Up @@ -1347,6 +1347,10 @@ bool OutOfProcessInstance::IsPrintPreview() {
return IsPrintPreviewUrl(url_);
}

uint32 OutOfProcessInstance::GetBackgroundColor() {
return background_color_;
}

void OutOfProcessInstance::ProcessPreviewPageInfo(const std::string& url,
int dst_page_index) {
if (!IsPrintPreview())
Expand Down
8 changes: 6 additions & 2 deletions pdf/out_of_process_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ class OutOfProcessInstance : public pp::Instance,
void DocumentLoadProgress(uint32 available, uint32 doc_size) override;
void FormTextFieldFocusChange(bool in_focus) override;
bool IsPrintPreview() override;
uint32 GetBackgroundColor() override;

// PreviewModeClient::Client implementation.
void PreviewDocumentLoadComplete() override;
Expand Down Expand Up @@ -283,6 +284,9 @@ class OutOfProcessInstance : public pp::Instance,
// Used for printing without re-entrancy issues.
pp::CompletionCallbackFactory<OutOfProcessInstance> print_callback_factory_;

// The callback for receiving the password from the page.
scoped_ptr<pp::CompletionCallbackWithOutput<pp::Var> > password_callback_;

// True if we haven't painted the plugin viewport yet.
bool first_paint_;

Expand Down Expand Up @@ -339,8 +343,8 @@ class OutOfProcessInstance : public pp::Instance,
// zooming the plugin so that flickering doesn't occur while zooming.
bool stop_scrolling_;

// The callback for receiving the password from the page.
scoped_ptr<pp::CompletionCallbackWithOutput<pp::Var> > password_callback_;
// The background color of the PDF viewer.
uint32 background_color_;
};

} // namespace chrome_pdf
Expand Down
8 changes: 3 additions & 5 deletions pdf/pdf_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ class PDFEngine {

// Returns true if the plugin has been opened within print preview.
virtual bool IsPrintPreview() = 0;

// Get the background color of the PDF.
virtual uint32 GetBackgroundColor() = 0;
};

// Factory method to create an instance of the PDF Engine.
Expand Down Expand Up @@ -246,11 +249,6 @@ class PDFEngine {
// Returns number of copies to be printed.
virtual int GetCopiesToPrint() = 0;

// Retrieve the background color of the PDF viewer.
virtual uint32 GetBackgroundColor() = 0;
// Set the background color of the PDF viewer.
virtual void SetBackgroundColor(uint32 background_color) = 0;

// Returns a VarArray of Bookmarks, each a VarDictionary containing the
// following key/values:
// - "title" - a string Var.
Expand Down
18 changes: 5 additions & 13 deletions pdf/pdfium/pdfium_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,6 @@ PDFiumEngine::PDFiumEngine(PDFEngine::Client* client)
most_visible_page_(-1),
called_do_document_action_(false),
render_grayscale_(false),
background_color_(0),
progressive_paint_timeout_(0),
getting_password_(false) {
find_factory_.Initialize(this);
Expand Down Expand Up @@ -2368,14 +2367,6 @@ int PDFiumEngine::GetNumberOfPages() {
return pages_.size();
}

uint32 PDFiumEngine::GetBackgroundColor() {
return background_color_;
}

void PDFiumEngine::SetBackgroundColor(uint32 background_color) {
background_color_ = background_color;
}

pp::VarArray PDFiumEngine::GetBookmarks() {
pp::VarDictionary dict = TraverseBookmarks(doc_, NULL);
// The root bookmark contains no useful information.
Expand Down Expand Up @@ -2947,7 +2938,7 @@ void PDFiumEngine::FillPageSides(int progressive_index) {

FPDFBitmap_FillRect(bitmap, left.x() - dirty_in_screen.x(),
left.y() - dirty_in_screen.y(), left.width(),
left.height(), background_color_);
left.height(), client_->GetBackgroundColor());
}

if (page_rect.right() < document_size_.width()) {
Expand All @@ -2961,7 +2952,7 @@ void PDFiumEngine::FillPageSides(int progressive_index) {

FPDFBitmap_FillRect(bitmap, right.x() - dirty_in_screen.x(),
right.y() - dirty_in_screen.y(), right.width(),
right.height(), background_color_);
right.height(), client_->GetBackgroundColor());
}

// Paint separator.
Expand All @@ -2973,7 +2964,7 @@ void PDFiumEngine::FillPageSides(int progressive_index) {

FPDFBitmap_FillRect(bitmap, bottom.x() - dirty_in_screen.x(),
bottom.y() - dirty_in_screen.y(), bottom.width(),
bottom.height(), background_color_);
bottom.height(), client_->GetBackgroundColor());
}

void PDFiumEngine::PaintPageShadow(int progressive_index,
Expand Down Expand Up @@ -3425,7 +3416,8 @@ void PDFiumEngine::DrawPageShadow(const pp::Rect& page_rc,

// We need to check depth only to verify our copy of shadow matrix is correct.
if (!page_shadow_.get() || page_shadow_->depth() != depth)
page_shadow_.reset(new ShadowMatrix(depth, factor, background_color_));
page_shadow_.reset(new ShadowMatrix(depth, factor,
client_->GetBackgroundColor()));

DCHECK(!image_data->is_null());
DrawShadow(image_data, shadow_rect, page_rect, clip_rect, *page_shadow_);
Expand Down
5 changes: 0 additions & 5 deletions pdf/pdfium/pdfium_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ class PDFiumEngine : public PDFEngine,
virtual bool HasPermission(DocumentPermission permission) const;
virtual void SelectAll();
virtual int GetNumberOfPages();
virtual uint32 GetBackgroundColor();
virtual void SetBackgroundColor(uint32 backgroundColor);
virtual pp::VarArray GetBookmarks();
virtual int GetNamedDestinationPage(const std::string& destination);
virtual pp::VarDictionary GetNamedDestinations();
Expand Down Expand Up @@ -683,9 +681,6 @@ class PDFiumEngine : public PDFEngine,
// Whether to render in grayscale or in color.
bool render_grayscale_;

// Background color of the PDF.
uint32 background_color_;

// The link currently under the cursor.
std::string link_under_cursor_;

Expand Down
5 changes: 5 additions & 0 deletions pdf/preview_mode_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,9 @@ bool PreviewModeClient::IsPrintPreview() {
return false;
}

uint32 PreviewModeClient::GetBackgroundColor() {
NOTREACHED();
return 0;
}

} // namespace chrome_pdf
1 change: 1 addition & 0 deletions pdf/preview_mode_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class PreviewModeClient : public PDFEngine::Client {
virtual void DocumentLoadProgress(uint32 available, uint32 doc_size);
virtual void FormTextFieldFocusChange(bool in_focus);
virtual bool IsPrintPreview();
virtual uint32 GetBackgroundColor();

private:
Client* client_;
Expand Down

0 comments on commit 8a9c0f3

Please sign in to comment.