Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(584)

Side by Side Diff: pdf/pdfium/pdfium_engine.cc

Issue 871403005: Switch the background color in PDF Viewer when using Material Design (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rearrange function declarations Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« pdf/pdf_engine.h ('K') | « pdf/pdfium/pdfium_engine.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "pdf/pdfium/pdfium_engine.h" 5 #include "pdf/pdfium/pdfium_engine.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 8
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 last_page_to_search_(-1), 592 last_page_to_search_(-1),
593 last_character_index_to_search_(-1), 593 last_character_index_to_search_(-1),
594 permissions_(0), 594 permissions_(0),
595 fpdf_availability_(NULL), 595 fpdf_availability_(NULL),
596 next_timer_id_(0), 596 next_timer_id_(0),
597 last_page_mouse_down_(-1), 597 last_page_mouse_down_(-1),
598 first_visible_page_(-1), 598 first_visible_page_(-1),
599 most_visible_page_(-1), 599 most_visible_page_(-1),
600 called_do_document_action_(false), 600 called_do_document_action_(false),
601 render_grayscale_(false), 601 render_grayscale_(false),
602 background_color_(kBackgroundColor),
602 progressive_paint_timeout_(0), 603 progressive_paint_timeout_(0),
603 getting_password_(false) { 604 getting_password_(false) {
604 find_factory_.Initialize(this); 605 find_factory_.Initialize(this);
605 password_factory_.Initialize(this); 606 password_factory_.Initialize(this);
606 607
607 file_access_.m_FileLen = 0; 608 file_access_.m_FileLen = 0;
608 file_access_.m_GetBlock = &GetBlock; 609 file_access_.m_GetBlock = &GetBlock;
609 file_access_.m_Param = &doc_loader_; 610 file_access_.m_Param = &doc_loader_;
610 611
611 file_availability_.version = 1; 612 file_availability_.version = 1;
(...skipping 1747 matching lines...) Expand 10 before | Expand all | Expand 10 after
2359 if (pages_[i]->available()) { 2360 if (pages_[i]->available()) {
2360 selection_.push_back(PDFiumRange(pages_[i], 0, 2361 selection_.push_back(PDFiumRange(pages_[i], 0,
2361 pages_[i]->GetCharCount())); 2362 pages_[i]->GetCharCount()));
2362 } 2363 }
2363 } 2364 }
2364 2365
2365 int PDFiumEngine::GetNumberOfPages() { 2366 int PDFiumEngine::GetNumberOfPages() {
2366 return pages_.size(); 2367 return pages_.size();
2367 } 2368 }
2368 2369
2370 uint32 PDFiumEngine::GetBackgroundColor() {
2371 return background_color_;
2372 }
2373
2374 void PDFiumEngine::SetBackgroundColor(uint32 background_color) {
2375 background_color_ = background_color;
2376 }
2377
2369 pp::VarArray PDFiumEngine::GetBookmarks() { 2378 pp::VarArray PDFiumEngine::GetBookmarks() {
2370 pp::VarDictionary dict = TraverseBookmarks(doc_, NULL); 2379 pp::VarDictionary dict = TraverseBookmarks(doc_, NULL);
2371 // The root bookmark contains no useful information. 2380 // The root bookmark contains no useful information.
2372 return pp::VarArray(dict.Get(pp::Var("children"))); 2381 return pp::VarArray(dict.Get(pp::Var("children")));
2373 } 2382 }
2374 2383
2375 int PDFiumEngine::GetNamedDestinationPage(const std::string& destination) { 2384 int PDFiumEngine::GetNamedDestinationPage(const std::string& destination) {
2376 // Look for the destination. 2385 // Look for the destination.
2377 FPDF_DEST dest = FPDF_GetNamedDestByName(doc_, destination.c_str()); 2386 FPDF_DEST dest = FPDF_GetNamedDestByName(doc_, destination.c_str());
2378 if (!dest) { 2387 if (!dest) {
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after
2929 if (page_rect.x() > 0) { 2938 if (page_rect.x() > 0) {
2930 pp::Rect left(0, 2939 pp::Rect left(0,
2931 page_rect.y() - kPageShadowTop, 2940 page_rect.y() - kPageShadowTop,
2932 page_rect.x() - kPageShadowLeft, 2941 page_rect.x() - kPageShadowLeft,
2933 page_rect.height() + kPageShadowTop + 2942 page_rect.height() + kPageShadowTop +
2934 kPageShadowBottom + kPageSeparatorThickness); 2943 kPageShadowBottom + kPageSeparatorThickness);
2935 left = GetScreenRect(left).Intersect(dirty_in_screen); 2944 left = GetScreenRect(left).Intersect(dirty_in_screen);
2936 2945
2937 FPDFBitmap_FillRect(bitmap, left.x() - dirty_in_screen.x(), 2946 FPDFBitmap_FillRect(bitmap, left.x() - dirty_in_screen.x(),
2938 left.y() - dirty_in_screen.y(), left.width(), 2947 left.y() - dirty_in_screen.y(), left.width(),
2939 left.height(), kBackgroundColor); 2948 left.height(), background_color_);
2940 } 2949 }
2941 2950
2942 if (page_rect.right() < document_size_.width()) { 2951 if (page_rect.right() < document_size_.width()) {
2943 pp::Rect right(page_rect.right() + kPageShadowRight, 2952 pp::Rect right(page_rect.right() + kPageShadowRight,
2944 page_rect.y() - kPageShadowTop, 2953 page_rect.y() - kPageShadowTop,
2945 document_size_.width() - page_rect.right() - 2954 document_size_.width() - page_rect.right() -
2946 kPageShadowRight, 2955 kPageShadowRight,
2947 page_rect.height() + kPageShadowTop + 2956 page_rect.height() + kPageShadowTop +
2948 kPageShadowBottom + kPageSeparatorThickness); 2957 kPageShadowBottom + kPageSeparatorThickness);
2949 right = GetScreenRect(right).Intersect(dirty_in_screen); 2958 right = GetScreenRect(right).Intersect(dirty_in_screen);
2950 2959
2951 FPDFBitmap_FillRect(bitmap, right.x() - dirty_in_screen.x(), 2960 FPDFBitmap_FillRect(bitmap, right.x() - dirty_in_screen.x(),
2952 right.y() - dirty_in_screen.y(), right.width(), 2961 right.y() - dirty_in_screen.y(), right.width(),
2953 right.height(), kBackgroundColor); 2962 right.height(), background_color_);
2954 } 2963 }
2955 2964
2956 // Paint separator. 2965 // Paint separator.
2957 pp::Rect bottom(page_rect.x() - kPageShadowLeft, 2966 pp::Rect bottom(page_rect.x() - kPageShadowLeft,
2958 page_rect.bottom() + kPageShadowBottom, 2967 page_rect.bottom() + kPageShadowBottom,
2959 page_rect.width() + kPageShadowLeft + kPageShadowRight, 2968 page_rect.width() + kPageShadowLeft + kPageShadowRight,
2960 kPageSeparatorThickness); 2969 kPageSeparatorThickness);
2961 bottom = GetScreenRect(bottom).Intersect(dirty_in_screen); 2970 bottom = GetScreenRect(bottom).Intersect(dirty_in_screen);
2962 2971
2963 FPDFBitmap_FillRect(bitmap, bottom.x() - dirty_in_screen.x(), 2972 FPDFBitmap_FillRect(bitmap, bottom.x() - dirty_in_screen.x(),
2964 bottom.y() - dirty_in_screen.y(), bottom.width(), 2973 bottom.y() - dirty_in_screen.y(), bottom.width(),
2965 bottom.height(), kBackgroundColor); 2974 bottom.height(), background_color_);
2966 } 2975 }
2967 2976
2968 void PDFiumEngine::PaintPageShadow(int progressive_index, 2977 void PDFiumEngine::PaintPageShadow(int progressive_index,
2969 pp::ImageData* image_data) { 2978 pp::ImageData* image_data) {
2970 DCHECK_GE(progressive_index, 0); 2979 DCHECK_GE(progressive_index, 0);
2971 DCHECK_LT(static_cast<size_t>(progressive_index), progressive_paints_.size()); 2980 DCHECK_LT(static_cast<size_t>(progressive_index), progressive_paints_.size());
2972 DCHECK(image_data); 2981 DCHECK(image_data);
2973 2982
2974 int page_index = progressive_paints_[progressive_index].page_index; 2983 int page_index = progressive_paints_[progressive_index].page_index;
2975 pp::Rect dirty_in_screen = progressive_paints_[progressive_index].rect; 2984 pp::Rect dirty_in_screen = progressive_paints_[progressive_index].rect;
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
3407 const double factor = 0.5; 3416 const double factor = 0.5;
3408 uint32 depth = std::max( 3417 uint32 depth = std::max(
3409 std::max(page_rect.x() - shadow_rect.x(), 3418 std::max(page_rect.x() - shadow_rect.x(),
3410 page_rect.y() - shadow_rect.y()), 3419 page_rect.y() - shadow_rect.y()),
3411 std::max(shadow_rect.right() - page_rect.right(), 3420 std::max(shadow_rect.right() - page_rect.right(),
3412 shadow_rect.bottom() - page_rect.bottom())); 3421 shadow_rect.bottom() - page_rect.bottom()));
3413 depth = static_cast<uint32>(depth * 1.5) + 1; 3422 depth = static_cast<uint32>(depth * 1.5) + 1;
3414 3423
3415 // We need to check depth only to verify our copy of shadow matrix is correct. 3424 // We need to check depth only to verify our copy of shadow matrix is correct.
3416 if (!page_shadow_.get() || page_shadow_->depth() != depth) 3425 if (!page_shadow_.get() || page_shadow_->depth() != depth)
3417 page_shadow_.reset(new ShadowMatrix(depth, factor, kBackgroundColor)); 3426 page_shadow_.reset(new ShadowMatrix(depth, factor, background_color_));
3418 3427
3419 DCHECK(!image_data->is_null()); 3428 DCHECK(!image_data->is_null());
3420 DrawShadow(image_data, shadow_rect, page_rect, clip_rect, *page_shadow_); 3429 DrawShadow(image_data, shadow_rect, page_rect, clip_rect, *page_shadow_);
3421 } 3430 }
3422 3431
3423 void PDFiumEngine::GetRegion(const pp::Point& location, 3432 void PDFiumEngine::GetRegion(const pp::Point& location,
3424 pp::ImageData* image_data, 3433 pp::ImageData* image_data,
3425 void** region, 3434 void** region,
3426 int* stride) const { 3435 int* stride) const {
3427 if (image_data->is_null()) { 3436 if (image_data->is_null()) {
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after
4017 double* height) { 4026 double* height) {
4018 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); 4027 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL);
4019 if (!doc) 4028 if (!doc)
4020 return false; 4029 return false;
4021 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; 4030 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0;
4022 FPDF_CloseDocument(doc); 4031 FPDF_CloseDocument(doc);
4023 return success; 4032 return success;
4024 } 4033 }
4025 4034
4026 } // namespace chrome_pdf 4035 } // namespace chrome_pdf
OLDNEW
« pdf/pdf_engine.h ('K') | « pdf/pdfium/pdfium_engine.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698