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

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

Issue 2252963007: PDF rotation should maintain current page. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add TODO Created 4 years, 4 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
« no previous file with comments | « 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 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 void PDFiumEngine::AddSegment(FX_DOWNLOADHINTS* param, 850 void PDFiumEngine::AddSegment(FX_DOWNLOADHINTS* param,
851 size_t offset, size_t size) { 851 size_t offset, size_t size) {
852 PDFiumEngine::DownloadHints* download_hints = 852 PDFiumEngine::DownloadHints* download_hints =
853 static_cast<PDFiumEngine::DownloadHints*>(param); 853 static_cast<PDFiumEngine::DownloadHints*>(param);
854 return download_hints->loader->RequestData(offset, size); 854 return download_hints->loader->RequestData(offset, size);
855 } 855 }
856 856
857 bool PDFiumEngine::New(const char* url, 857 bool PDFiumEngine::New(const char* url,
858 const char* headers) { 858 const char* headers) {
859 url_ = url; 859 url_ = url;
860 if (!headers) 860 if (headers)
861 headers_ = headers;
862 else
861 headers_.clear(); 863 headers_.clear();
862 else
863 headers_ = headers;
864 return true; 864 return true;
865 } 865 }
866 866
867 void PDFiumEngine::PageOffsetUpdated(const pp::Point& page_offset) { 867 void PDFiumEngine::PageOffsetUpdated(const pp::Point& page_offset) {
868 page_offset_ = page_offset; 868 page_offset_ = page_offset;
869 } 869 }
870 870
871 void PDFiumEngine::PluginSizeUpdated(const pp::Size& size) { 871 void PDFiumEngine::PluginSizeUpdated(const pp::Size& size) {
872 CancelPaints(); 872 CancelPaints();
873 873
(...skipping 2272 matching lines...) Expand 10 before | Expand all | Expand 10 after
3146 DCHECK(valid_); 3146 DCHECK(valid_);
3147 return ++index_; 3147 return ++index_;
3148 } 3148 }
3149 3149
3150 void PDFiumEngine::DeviceToPage(int page_index, 3150 void PDFiumEngine::DeviceToPage(int page_index,
3151 float device_x, 3151 float device_x,
3152 float device_y, 3152 float device_y,
3153 double* page_x, 3153 double* page_x,
3154 double* page_y) { 3154 double* page_y) {
3155 *page_x = *page_y = 0; 3155 *page_x = *page_y = 0;
3156 int temp_x = static_cast<int>((device_x + position_.x())/ current_zoom_ - 3156 int temp_x = static_cast<int>((device_x + position_.x()) / current_zoom_ -
3157 pages_[page_index]->rect().x()); 3157 pages_[page_index]->rect().x());
3158 int temp_y = static_cast<int>((device_y + position_.y())/ current_zoom_ - 3158 int temp_y = static_cast<int>((device_y + position_.y()) / current_zoom_ -
3159 pages_[page_index]->rect().y()); 3159 pages_[page_index]->rect().y());
3160 FPDF_DeviceToPage( 3160 FPDF_DeviceToPage(
3161 pages_[page_index]->GetPage(), 0, 0, 3161 pages_[page_index]->GetPage(), 0, 0,
3162 pages_[page_index]->rect().width(), pages_[page_index]->rect().height(), 3162 pages_[page_index]->rect().width(), pages_[page_index]->rect().height(),
3163 current_rotation_, temp_x, temp_y, page_x, page_y); 3163 current_rotation_, temp_x, temp_y, page_x, page_y);
3164 } 3164 }
3165 3165
3166 int PDFiumEngine::GetVisiblePageIndex(FPDF_PAGE page) { 3166 int PDFiumEngine::GetVisiblePageIndex(FPDF_PAGE page) {
3167 for (int page_index : visible_pages_) { 3167 for (int page_index : visible_pages_) {
3168 if (pages_[page_index]->GetPage() == page) 3168 if (pages_[page_index]->GetPage() == page)
3169 return page_index; 3169 return page_index;
3170 } 3170 }
3171 return -1; 3171 return -1;
3172 } 3172 }
3173 3173
3174 void PDFiumEngine::SetCurrentPage(int index) { 3174 void PDFiumEngine::SetCurrentPage(int index) {
3175 if (index == most_visible_page_ || !form_) 3175 if (index == most_visible_page_ || !form_)
3176 return; 3176 return;
3177
3177 if (most_visible_page_ != -1 && called_do_document_action_) { 3178 if (most_visible_page_ != -1 && called_do_document_action_) {
3178 FPDF_PAGE old_page = pages_[most_visible_page_]->GetPage(); 3179 FPDF_PAGE old_page = pages_[most_visible_page_]->GetPage();
3179 FORM_DoPageAAction(old_page, form_, FPDFPAGE_AACTION_CLOSE); 3180 FORM_DoPageAAction(old_page, form_, FPDFPAGE_AACTION_CLOSE);
3180 } 3181 }
3181 most_visible_page_ = index; 3182 most_visible_page_ = index;
3182 #if defined(OS_LINUX) 3183 #if defined(OS_LINUX)
3183 g_last_instance_id = client_->GetPluginInstance()->pp_instance(); 3184 g_last_instance_id = client_->GetPluginInstance()->pp_instance();
3184 #endif 3185 #endif
3185 if (most_visible_page_ != -1 && called_do_document_action_) { 3186 if (most_visible_page_ != -1 && called_do_document_action_) {
3186 FPDF_PAGE new_page = pages_[most_visible_page_]->GetPage(); 3187 FPDF_PAGE new_page = pages_[most_visible_page_]->GetPage();
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
3348 3349
3349 void PDFiumEngine::RotateInternal() { 3350 void PDFiumEngine::RotateInternal() {
3350 // Store the current find index so that we can resume finding at that 3351 // Store the current find index so that we can resume finding at that
3351 // particular index after we have recomputed the find results. 3352 // particular index after we have recomputed the find results.
3352 std::string current_find_text = current_find_text_; 3353 std::string current_find_text = current_find_text_;
3353 if (current_find_index_.valid()) 3354 if (current_find_index_.valid())
3354 resume_find_index_.SetIndex(current_find_index_.GetIndex()); 3355 resume_find_index_.SetIndex(current_find_index_.GetIndex());
3355 else 3356 else
3356 resume_find_index_.Invalidate(); 3357 resume_find_index_.Invalidate();
3357 3358
3359 // Save the current page.
3360 int most_visible_page = most_visible_page_;
3361
3358 InvalidateAllPages(); 3362 InvalidateAllPages();
3359 3363
3364 // Restore find results.
3360 if (!current_find_text.empty()) { 3365 if (!current_find_text.empty()) {
3361 // Clear the UI. 3366 // Clear the UI.
3362 client_->NotifyNumberOfFindResultsChanged(0, false); 3367 client_->NotifyNumberOfFindResultsChanged(0, false);
3363 StartFind(current_find_text, false); 3368 StartFind(current_find_text, false);
3364 } 3369 }
3370
3371 // Restore current page. After a rotation, the page heights have changed but
3372 // the scroll position has not. Re-adjust.
3373 // TODO(thestig): It would be better to also restore the position on the page.
3374 client_->ScrollToPage(most_visible_page);
3365 } 3375 }
3366 3376
3367 void PDFiumEngine::SetSelecting(bool selecting) { 3377 void PDFiumEngine::SetSelecting(bool selecting) {
3368 bool was_selecting = selecting_; 3378 bool was_selecting = selecting_;
3369 selecting_ = selecting; 3379 selecting_ = selecting;
3370 if (selecting_ != was_selecting) 3380 if (selecting_ != was_selecting)
3371 client_->IsSelectingChanged(selecting); 3381 client_->IsSelectingChanged(selecting);
3372 } 3382 }
3373 3383
3374 void PDFiumEngine::Form_Invalidate(FPDF_FORMFILLINFO* param, 3384 void PDFiumEngine::Form_Invalidate(FPDF_FORMFILLINFO* param,
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
3910 FPDF_DOCUMENT doc = 3920 FPDF_DOCUMENT doc =
3911 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); 3921 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr);
3912 if (!doc) 3922 if (!doc)
3913 return false; 3923 return false;
3914 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; 3924 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0;
3915 FPDF_CloseDocument(doc); 3925 FPDF_CloseDocument(doc);
3916 return success; 3926 return success;
3917 } 3927 }
3918 3928
3919 } // namespace chrome_pdf 3929 } // namespace chrome_pdf
OLDNEW
« no previous file with comments | « pdf/pdfium/pdfium_engine.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698