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

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: Fix nits 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/pdfium/pdfium_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 2348 matching lines...) Expand 10 before | Expand all | Expand 10 after
2359 if (pages_[i]->available()) { 2359 if (pages_[i]->available()) {
2360 selection_.push_back(PDFiumRange(pages_[i], 0, 2360 selection_.push_back(PDFiumRange(pages_[i], 0,
2361 pages_[i]->GetCharCount())); 2361 pages_[i]->GetCharCount()));
2362 } 2362 }
2363 } 2363 }
2364 2364
2365 int PDFiumEngine::GetNumberOfPages() { 2365 int PDFiumEngine::GetNumberOfPages() {
2366 return pages_.size(); 2366 return pages_.size();
2367 } 2367 }
2368 2368
2369 uint32 PDFiumEngine::GetBackgroundColor() {
2370 return background_color_;
2371 }
2372
2373 void PDFiumEngine::SetBackgroundColor(uint32 background_color) {
2374 background_color_ = background_color;
2375 }
2376
2369 pp::VarArray PDFiumEngine::GetBookmarks() { 2377 pp::VarArray PDFiumEngine::GetBookmarks() {
2370 pp::VarDictionary dict = TraverseBookmarks(doc_, NULL); 2378 pp::VarDictionary dict = TraverseBookmarks(doc_, NULL);
2371 // The root bookmark contains no useful information. 2379 // The root bookmark contains no useful information.
2372 return pp::VarArray(dict.Get(pp::Var("children"))); 2380 return pp::VarArray(dict.Get(pp::Var("children")));
2373 } 2381 }
2374 2382
2375 int PDFiumEngine::GetNamedDestinationPage(const std::string& destination) { 2383 int PDFiumEngine::GetNamedDestinationPage(const std::string& destination) {
2376 // Look for the destination. 2384 // Look for the destination.
2377 FPDF_DEST dest = FPDF_GetNamedDestByName(doc_, destination.c_str()); 2385 FPDF_DEST dest = FPDF_GetNamedDestByName(doc_, destination.c_str());
2378 if (!dest) { 2386 if (!dest) {
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after
2930 if (page_rect.x() > 0) { 2938 if (page_rect.x() > 0) {
2931 pp::Rect left(0, 2939 pp::Rect left(0,
2932 page_rect.y() - kPageShadowTop, 2940 page_rect.y() - kPageShadowTop,
2933 page_rect.x() - kPageShadowLeft, 2941 page_rect.x() - kPageShadowLeft,
2934 page_rect.height() + kPageShadowTop + 2942 page_rect.height() + kPageShadowTop +
2935 kPageShadowBottom + kPageSeparatorThickness); 2943 kPageShadowBottom + kPageSeparatorThickness);
2936 left = GetScreenRect(left).Intersect(dirty_in_screen); 2944 left = GetScreenRect(left).Intersect(dirty_in_screen);
2937 2945
2938 FPDFBitmap_FillRect(bitmap, left.x() - dirty_in_screen.x(), 2946 FPDFBitmap_FillRect(bitmap, left.x() - dirty_in_screen.x(),
2939 left.y() - dirty_in_screen.y(), left.width(), 2947 left.y() - dirty_in_screen.y(), left.width(),
2940 left.height(), kBackgroundColor); 2948 left.height(), background_color_);
2941 } 2949 }
2942 2950
2943 if (page_rect.right() < document_size_.width()) { 2951 if (page_rect.right() < document_size_.width()) {
2944 pp::Rect right(page_rect.right() + kPageShadowRight, 2952 pp::Rect right(page_rect.right() + kPageShadowRight,
2945 page_rect.y() - kPageShadowTop, 2953 page_rect.y() - kPageShadowTop,
2946 document_size_.width() - page_rect.right() - 2954 document_size_.width() - page_rect.right() -
2947 kPageShadowRight, 2955 kPageShadowRight,
2948 page_rect.height() + kPageShadowTop + 2956 page_rect.height() + kPageShadowTop +
2949 kPageShadowBottom + kPageSeparatorThickness); 2957 kPageShadowBottom + kPageSeparatorThickness);
2950 right = GetScreenRect(right).Intersect(dirty_in_screen); 2958 right = GetScreenRect(right).Intersect(dirty_in_screen);
2951 2959
2952 FPDFBitmap_FillRect(bitmap, right.x() - dirty_in_screen.x(), 2960 FPDFBitmap_FillRect(bitmap, right.x() - dirty_in_screen.x(),
2953 right.y() - dirty_in_screen.y(), right.width(), 2961 right.y() - dirty_in_screen.y(), right.width(),
2954 right.height(), kBackgroundColor); 2962 right.height(), background_color_);
2955 } 2963 }
2956 2964
2957 // Paint separator. 2965 // Paint separator.
2958 pp::Rect bottom(page_rect.x() - kPageShadowLeft, 2966 pp::Rect bottom(page_rect.x() - kPageShadowLeft,
2959 page_rect.bottom() + kPageShadowBottom, 2967 page_rect.bottom() + kPageShadowBottom,
2960 page_rect.width() + kPageShadowLeft + kPageShadowRight, 2968 page_rect.width() + kPageShadowLeft + kPageShadowRight,
2961 kPageSeparatorThickness); 2969 kPageSeparatorThickness);
2962 bottom = GetScreenRect(bottom).Intersect(dirty_in_screen); 2970 bottom = GetScreenRect(bottom).Intersect(dirty_in_screen);
2963 2971
2964 FPDFBitmap_FillRect(bitmap, bottom.x() - dirty_in_screen.x(), 2972 FPDFBitmap_FillRect(bitmap, bottom.x() - dirty_in_screen.x(),
2965 bottom.y() - dirty_in_screen.y(), bottom.width(), 2973 bottom.y() - dirty_in_screen.y(), bottom.width(),
2966 bottom.height(), kBackgroundColor); 2974 bottom.height(), background_color_);
2967 } 2975 }
2968 2976
2969 void PDFiumEngine::PaintPageShadow(int progressive_index, 2977 void PDFiumEngine::PaintPageShadow(int progressive_index,
2970 pp::ImageData* image_data) { 2978 pp::ImageData* image_data) {
2971 DCHECK_GE(progressive_index, 0); 2979 DCHECK_GE(progressive_index, 0);
2972 DCHECK_LT(static_cast<size_t>(progressive_index), progressive_paints_.size()); 2980 DCHECK_LT(static_cast<size_t>(progressive_index), progressive_paints_.size());
2973 DCHECK(image_data); 2981 DCHECK(image_data);
2974 2982
2975 int page_index = progressive_paints_[progressive_index].page_index; 2983 int page_index = progressive_paints_[progressive_index].page_index;
2976 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
3408 const double factor = 0.5; 3416 const double factor = 0.5;
3409 uint32 depth = std::max( 3417 uint32 depth = std::max(
3410 std::max(page_rect.x() - shadow_rect.x(), 3418 std::max(page_rect.x() - shadow_rect.x(),
3411 page_rect.y() - shadow_rect.y()), 3419 page_rect.y() - shadow_rect.y()),
3412 std::max(shadow_rect.right() - page_rect.right(), 3420 std::max(shadow_rect.right() - page_rect.right(),
3413 shadow_rect.bottom() - page_rect.bottom())); 3421 shadow_rect.bottom() - page_rect.bottom()));
3414 depth = static_cast<uint32>(depth * 1.5) + 1; 3422 depth = static_cast<uint32>(depth * 1.5) + 1;
3415 3423
3416 // 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.
3417 if (!page_shadow_.get() || page_shadow_->depth() != depth) 3425 if (!page_shadow_.get() || page_shadow_->depth() != depth)
3418 page_shadow_.reset(new ShadowMatrix(depth, factor, kBackgroundColor)); 3426 page_shadow_.reset(new ShadowMatrix(depth, factor, background_color_));
3419 3427
3420 DCHECK(!image_data->is_null()); 3428 DCHECK(!image_data->is_null());
3421 DrawShadow(image_data, shadow_rect, page_rect, clip_rect, *page_shadow_); 3429 DrawShadow(image_data, shadow_rect, page_rect, clip_rect, *page_shadow_);
3422 } 3430 }
3423 3431
3424 void PDFiumEngine::GetRegion(const pp::Point& location, 3432 void PDFiumEngine::GetRegion(const pp::Point& location,
3425 pp::ImageData* image_data, 3433 pp::ImageData* image_data,
3426 void** region, 3434 void** region,
3427 int* stride) const { 3435 int* stride) const {
3428 if (image_data->is_null()) { 3436 if (image_data->is_null()) {
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after
4018 double* height) { 4026 double* height) {
4019 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); 4027 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL);
4020 if (!doc) 4028 if (!doc)
4021 return false; 4029 return false;
4022 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; 4030 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0;
4023 FPDF_CloseDocument(doc); 4031 FPDF_CloseDocument(doc);
4024 return success; 4032 return success;
4025 } 4033 }
4026 4034
4027 } // namespace chrome_pdf 4035 } // namespace chrome_pdf
OLDNEW
« pdf/pdfium/pdfium_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