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

Side by Side Diff: pdf/instance.cc

Issue 845203002: Don't return Windows newlines through the PDF GetSelectedText JS API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@addMissingFeatures
Patch Set: Created 5 years, 11 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 | « no previous file | pdf/out_of_process_instance.cc » ('j') | 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/instance.h" 5 #include "pdf/instance.h"
6 6
7 #include <algorithm> // for min() 7 #include <algorithm> // for min()
8 #define _USE_MATH_DEFINES // for M_PI 8 #define _USE_MATH_DEFINES // for M_PI
9 #include <cmath> // for log() and pow() 9 #include <cmath> // for log() and pow()
10 #include <math.h> 10 #include <math.h>
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 } 676 }
677 677
678 pp::Var Instance::GetLinkAtPosition(const pp::Point& point) { 678 pp::Var Instance::GetLinkAtPosition(const pp::Point& point) {
679 pp::Point offset_point(point); 679 pp::Point offset_point(point);
680 ScalePoint(device_scale_, &offset_point); 680 ScalePoint(device_scale_, &offset_point);
681 offset_point.set_x(offset_point.x() - available_area_.x()); 681 offset_point.set_x(offset_point.x() - available_area_.x());
682 return engine_->GetLinkAtPosition(offset_point); 682 return engine_->GetLinkAtPosition(offset_point);
683 } 683 }
684 684
685 pp::Var Instance::GetSelectedText(bool html) { 685 pp::Var Instance::GetSelectedText(bool html) {
686 if (html || !engine_->HasPermission(PDFEngine::PERMISSION_COPY)) 686 if (html)
687 return pp::Var(); 687 return pp::Var();
688 return engine_->GetSelectedText(); 688 return engine_->GetSelectedText();
689 } 689 }
690 690
691 void Instance::InvalidateWidget(pp::Widget_Dev widget, 691 void Instance::InvalidateWidget(pp::Widget_Dev widget,
692 const pp::Rect& dirty_rect) { 692 const pp::Rect& dirty_rect) {
693 if (v_scrollbar_.get() && *v_scrollbar_ == widget) { 693 if (v_scrollbar_.get() && *v_scrollbar_ == widget) {
694 if (!image_data_.is_null()) 694 if (!image_data_.is_null())
695 v_scrollbar_->Paint(dirty_rect.pp_rect(), &image_data_); 695 v_scrollbar_->Paint(dirty_rect.pp_rect(), &image_data_);
696 } else if (h_scrollbar_.get() && *h_scrollbar_ == widget) { 696 } else if (h_scrollbar_.get() && *h_scrollbar_ == widget) {
(...skipping 1153 matching lines...) Expand 10 before | Expand all | Expand 10 after
1850 } 1850 }
1851 if (method_str == kJSGetHorizontalScrollbarThickness) { 1851 if (method_str == kJSGetHorizontalScrollbarThickness) {
1852 return pp::Var( 1852 return pp::Var(
1853 h_scrollbar_.get() ? GetScrollbarReservedThickness() : 0); 1853 h_scrollbar_.get() ? GetScrollbarReservedThickness() : 0);
1854 } 1854 }
1855 if (method_str == kJSGetVerticalScrollbarThickness) { 1855 if (method_str == kJSGetVerticalScrollbarThickness) {
1856 return pp::Var( 1856 return pp::Var(
1857 v_scrollbar_.get() ? GetScrollbarReservedThickness() : 0); 1857 v_scrollbar_.get() ? GetScrollbarReservedThickness() : 0);
1858 } 1858 }
1859 if (method_str == kJSGetSelectedText) { 1859 if (method_str == kJSGetSelectedText) {
1860 return GetSelectedText(false); 1860 std::string selected_text = engine_->GetSelectedText();
1861 // Always return unix newlines to JS.
1862 base::ReplaceChars(selected_text, "\r", std::string(), &selected_text);
1863 return selected_text;
1861 } 1864 }
1862 if (method_str == kJSDocumentLoadComplete) { 1865 if (method_str == kJSDocumentLoadComplete) {
1863 return pp::Var((document_load_state_ != LOAD_STATE_LOADING)); 1866 return pp::Var((document_load_state_ != LOAD_STATE_LOADING));
1864 } 1867 }
1865 if (method_str == kJSPageYOffset) { 1868 if (method_str == kJSPageYOffset) {
1866 return pp::Var(static_cast<int32_t>( 1869 return pp::Var(static_cast<int32_t>(
1867 v_scrollbar_.get() ? v_scrollbar_->GetValue() : 0)); 1870 v_scrollbar_.get() ? v_scrollbar_->GetValue() : 0));
1868 } 1871 }
1869 if (method_str == kJSSetPageYOffset) { 1872 if (method_str == kJSSetPageYOffset) {
1870 if (args.size() == 1 && args[0].is_number() && v_scrollbar_.get()) 1873 if (args.size() == 1 && args[0].is_number() && v_scrollbar_.get())
(...skipping 938 matching lines...) Expand 10 before | Expand all | Expand 10 after
2809 return instance_->HasScriptableMethod(name, exception); 2812 return instance_->HasScriptableMethod(name, exception);
2810 } 2813 }
2811 2814
2812 pp::Var PDFScriptableObject::Call(const pp::Var& method, 2815 pp::Var PDFScriptableObject::Call(const pp::Var& method,
2813 const std::vector<pp::Var>& args, 2816 const std::vector<pp::Var>& args,
2814 pp::Var* exception) { 2817 pp::Var* exception) {
2815 return instance_->CallScriptableMethod(method, args, exception); 2818 return instance_->CallScriptableMethod(method, args, exception);
2816 } 2819 }
2817 2820
2818 } // namespace chrome_pdf 2821 } // namespace chrome_pdf
OLDNEW
« no previous file with comments | « no previous file | pdf/out_of_process_instance.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698