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

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: 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 2280 matching lines...) Expand 10 before | Expand all | Expand 10 after
3154 DCHECK(valid_); 3154 DCHECK(valid_);
3155 return ++index_; 3155 return ++index_;
3156 } 3156 }
3157 3157
3158 void PDFiumEngine::DeviceToPage(int page_index, 3158 void PDFiumEngine::DeviceToPage(int page_index,
3159 float device_x, 3159 float device_x,
3160 float device_y, 3160 float device_y,
3161 double* page_x, 3161 double* page_x,
3162 double* page_y) { 3162 double* page_y) {
3163 *page_x = *page_y = 0; 3163 *page_x = *page_y = 0;
3164 int temp_x = static_cast<int>((device_x + position_.x())/ current_zoom_ - 3164 int temp_x = static_cast<int>((device_x + position_.x()) / current_zoom_ -
3165 pages_[page_index]->rect().x()); 3165 pages_[page_index]->rect().x());
3166 int temp_y = static_cast<int>((device_y + position_.y())/ current_zoom_ - 3166 int temp_y = static_cast<int>((device_y + position_.y()) / current_zoom_ -
3167 pages_[page_index]->rect().y()); 3167 pages_[page_index]->rect().y());
3168 FPDF_DeviceToPage( 3168 FPDF_DeviceToPage(
3169 pages_[page_index]->GetPage(), 0, 0, 3169 pages_[page_index]->GetPage(), 0, 0,
3170 pages_[page_index]->rect().width(), pages_[page_index]->rect().height(), 3170 pages_[page_index]->rect().width(), pages_[page_index]->rect().height(),
3171 current_rotation_, temp_x, temp_y, page_x, page_y); 3171 current_rotation_, temp_x, temp_y, page_x, page_y);
3172 } 3172 }
3173 3173
3174 int PDFiumEngine::GetVisiblePageIndex(FPDF_PAGE page) { 3174 int PDFiumEngine::GetVisiblePageIndex(FPDF_PAGE page) {
3175 for (int page_index : visible_pages_) { 3175 for (int page_index : visible_pages_) {
3176 if (pages_[page_index]->GetPage() == page) 3176 if (pages_[page_index]->GetPage() == page)
3177 return page_index; 3177 return page_index;
3178 } 3178 }
3179 return -1; 3179 return -1;
3180 } 3180 }
3181 3181
3182 void PDFiumEngine::SetCurrentPage(int index) { 3182 void PDFiumEngine::SetCurrentPage(int index) {
3183 if (index == most_visible_page_ || !form_) 3183 if (index == most_visible_page_ || !form_)
3184 return; 3184 return;
3185
3185 if (most_visible_page_ != -1 && called_do_document_action_) { 3186 if (most_visible_page_ != -1 && called_do_document_action_) {
3186 FPDF_PAGE old_page = pages_[most_visible_page_]->GetPage(); 3187 FPDF_PAGE old_page = pages_[most_visible_page_]->GetPage();
3187 FORM_DoPageAAction(old_page, form_, FPDFPAGE_AACTION_CLOSE); 3188 FORM_DoPageAAction(old_page, form_, FPDFPAGE_AACTION_CLOSE);
3188 } 3189 }
3189 most_visible_page_ = index; 3190 most_visible_page_ = index;
3190 #if defined(OS_LINUX) 3191 #if defined(OS_LINUX)
3191 g_last_instance_id = client_->GetPluginInstance()->pp_instance(); 3192 g_last_instance_id = client_->GetPluginInstance()->pp_instance();
3192 #endif 3193 #endif
3193 if (most_visible_page_ != -1 && called_do_document_action_) { 3194 if (most_visible_page_ != -1 && called_do_document_action_) {
3194 FPDF_PAGE new_page = pages_[most_visible_page_]->GetPage(); 3195 FPDF_PAGE new_page = pages_[most_visible_page_]->GetPage();
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
3356 3357
3357 void PDFiumEngine::RotateInternal() { 3358 void PDFiumEngine::RotateInternal() {
3358 // Store the current find index so that we can resume finding at that 3359 // Store the current find index so that we can resume finding at that
3359 // particular index after we have recomputed the find results. 3360 // particular index after we have recomputed the find results.
3360 std::string current_find_text = current_find_text_; 3361 std::string current_find_text = current_find_text_;
3361 if (current_find_index_.valid()) 3362 if (current_find_index_.valid())
3362 resume_find_index_.SetIndex(current_find_index_.GetIndex()); 3363 resume_find_index_.SetIndex(current_find_index_.GetIndex());
3363 else 3364 else
3364 resume_find_index_.Invalidate(); 3365 resume_find_index_.Invalidate();
3365 3366
3367 // Save the current page.
3368 int most_visible_page = most_visible_page_;
3369
3366 InvalidateAllPages(); 3370 InvalidateAllPages();
3367 3371
3372 // Restore find results.
3368 if (!current_find_text.empty()) { 3373 if (!current_find_text.empty()) {
3369 // Clear the UI. 3374 // Clear the UI.
3370 client_->NotifyNumberOfFindResultsChanged(0, false); 3375 client_->NotifyNumberOfFindResultsChanged(0, false);
3371 StartFind(current_find_text, false); 3376 StartFind(current_find_text, false);
3372 } 3377 }
3378
3379 // Restore current page. After a rotation, the page heights have changed but
3380 // the scroll position has not. Readjust.
raymes 2016/08/22 01:09:30 Possibly add a note that we should restore the pos
Lei Zhang 2016/08/22 19:08:44 Done.
3381 client_->ScrollToPage(most_visible_page);
3373 } 3382 }
3374 3383
3375 void PDFiumEngine::SetSelecting(bool selecting) { 3384 void PDFiumEngine::SetSelecting(bool selecting) {
3376 bool was_selecting = selecting_; 3385 bool was_selecting = selecting_;
3377 selecting_ = selecting; 3386 selecting_ = selecting;
3378 if (selecting_ != was_selecting) 3387 if (selecting_ != was_selecting)
3379 client_->IsSelectingChanged(selecting); 3388 client_->IsSelectingChanged(selecting);
3380 } 3389 }
3381 3390
3382 void PDFiumEngine::Form_Invalidate(FPDF_FORMFILLINFO* param, 3391 void PDFiumEngine::Form_Invalidate(FPDF_FORMFILLINFO* param,
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
3918 FPDF_DOCUMENT doc = 3927 FPDF_DOCUMENT doc =
3919 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr); 3928 FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, nullptr);
3920 if (!doc) 3929 if (!doc)
3921 return false; 3930 return false;
3922 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; 3931 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0;
3923 FPDF_CloseDocument(doc); 3932 FPDF_CloseDocument(doc);
3924 return success; 3933 return success;
3925 } 3934 }
3926 3935
3927 } // namespace chrome_pdf 3936 } // 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