| OLD | NEW |
| 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 const uint32 kAutoScrollTimeoutMs = 50; | 69 const uint32 kAutoScrollTimeoutMs = 50; |
| 70 const double kAutoScrollFactor = 0.2; | 70 const double kAutoScrollFactor = 0.2; |
| 71 | 71 |
| 72 // Javascript methods. | 72 // Javascript methods. |
| 73 const char kJSAccessibility[] = "accessibility"; | 73 const char kJSAccessibility[] = "accessibility"; |
| 74 const char kJSDocumentLoadComplete[] = "documentLoadComplete"; | 74 const char kJSDocumentLoadComplete[] = "documentLoadComplete"; |
| 75 const char kJSGetHeight[] = "getHeight"; | 75 const char kJSGetHeight[] = "getHeight"; |
| 76 const char kJSGetHorizontalScrollbarThickness[] = | 76 const char kJSGetHorizontalScrollbarThickness[] = |
| 77 "getHorizontalScrollbarThickness"; | 77 "getHorizontalScrollbarThickness"; |
| 78 const char kJSGetPageLocationNormalized[] = "getPageLocationNormalized"; | 78 const char kJSGetPageLocationNormalized[] = "getPageLocationNormalized"; |
| 79 const char kJSGetSelectedText[] = "getSelectedText"; |
| 79 const char kJSGetVerticalScrollbarThickness[] = "getVerticalScrollbarThickness"; | 80 const char kJSGetVerticalScrollbarThickness[] = "getVerticalScrollbarThickness"; |
| 80 const char kJSGetWidth[] = "getWidth"; | 81 const char kJSGetWidth[] = "getWidth"; |
| 81 const char kJSGetZoomLevel[] = "getZoomLevel"; | 82 const char kJSGetZoomLevel[] = "getZoomLevel"; |
| 82 const char kJSGoToPage[] = "goToPage"; | 83 const char kJSGoToPage[] = "goToPage"; |
| 83 const char kJSGrayscale[] = "grayscale"; | 84 const char kJSGrayscale[] = "grayscale"; |
| 84 const char kJSLoadPreviewPage[] = "loadPreviewPage"; | 85 const char kJSLoadPreviewPage[] = "loadPreviewPage"; |
| 85 const char kJSOnLoad[] = "onload"; | 86 const char kJSOnLoad[] = "onload"; |
| 86 const char kJSOnPluginSizeChanged[] = "onPluginSizeChanged"; | 87 const char kJSOnPluginSizeChanged[] = "onPluginSizeChanged"; |
| 87 const char kJSOnScroll[] = "onScroll"; | 88 const char kJSOnScroll[] = "onScroll"; |
| 88 const char kJSPageXOffset[] = "pageXOffset"; | 89 const char kJSPageXOffset[] = "pageXOffset"; |
| (...skipping 1587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1676 } | 1677 } |
| 1677 | 1678 |
| 1678 // Called by PDFScriptableObject. | 1679 // Called by PDFScriptableObject. |
| 1679 bool Instance::HasScriptableMethod(const pp::Var& method, pp::Var* exception) { | 1680 bool Instance::HasScriptableMethod(const pp::Var& method, pp::Var* exception) { |
| 1680 std::string method_str = method.AsString(); | 1681 std::string method_str = method.AsString(); |
| 1681 return (method_str == kJSAccessibility || | 1682 return (method_str == kJSAccessibility || |
| 1682 method_str == kJSDocumentLoadComplete || | 1683 method_str == kJSDocumentLoadComplete || |
| 1683 method_str == kJSGetHeight || | 1684 method_str == kJSGetHeight || |
| 1684 method_str == kJSGetHorizontalScrollbarThickness || | 1685 method_str == kJSGetHorizontalScrollbarThickness || |
| 1685 method_str == kJSGetPageLocationNormalized || | 1686 method_str == kJSGetPageLocationNormalized || |
| 1687 method_str == kJSGetSelectedText || |
| 1686 method_str == kJSGetVerticalScrollbarThickness || | 1688 method_str == kJSGetVerticalScrollbarThickness || |
| 1687 method_str == kJSGetWidth || | 1689 method_str == kJSGetWidth || |
| 1688 method_str == kJSGetZoomLevel || | 1690 method_str == kJSGetZoomLevel || |
| 1689 method_str == kJSGoToPage || | 1691 method_str == kJSGoToPage || |
| 1690 method_str == kJSGrayscale || | 1692 method_str == kJSGrayscale || |
| 1691 method_str == kJSLoadPreviewPage || | 1693 method_str == kJSLoadPreviewPage || |
| 1692 method_str == kJSOnLoad || | 1694 method_str == kJSOnLoad || |
| 1693 method_str == kJSOnPluginSizeChanged || | 1695 method_str == kJSOnPluginSizeChanged || |
| 1694 method_str == kJSOnScroll || | 1696 method_str == kJSOnScroll || |
| 1695 method_str == kJSPageXOffset || | 1697 method_str == kJSPageXOffset || |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1799 return pp::Var(plugin_size_.width()); | 1801 return pp::Var(plugin_size_.width()); |
| 1800 } | 1802 } |
| 1801 if (method_str == kJSGetHorizontalScrollbarThickness) { | 1803 if (method_str == kJSGetHorizontalScrollbarThickness) { |
| 1802 return pp::Var( | 1804 return pp::Var( |
| 1803 h_scrollbar_.get() ? GetScrollbarReservedThickness() : 0); | 1805 h_scrollbar_.get() ? GetScrollbarReservedThickness() : 0); |
| 1804 } | 1806 } |
| 1805 if (method_str == kJSGetVerticalScrollbarThickness) { | 1807 if (method_str == kJSGetVerticalScrollbarThickness) { |
| 1806 return pp::Var( | 1808 return pp::Var( |
| 1807 v_scrollbar_.get() ? GetScrollbarReservedThickness() : 0); | 1809 v_scrollbar_.get() ? GetScrollbarReservedThickness() : 0); |
| 1808 } | 1810 } |
| 1811 if (method_str == kJSGetSelectedText) { |
| 1812 return GetSelectedText(false); |
| 1813 } |
| 1809 if (method_str == kJSDocumentLoadComplete) { | 1814 if (method_str == kJSDocumentLoadComplete) { |
| 1810 return pp::Var((document_load_state_ != LOAD_STATE_LOADING)); | 1815 return pp::Var((document_load_state_ != LOAD_STATE_LOADING)); |
| 1811 } | 1816 } |
| 1812 if (method_str == kJSPageYOffset) { | 1817 if (method_str == kJSPageYOffset) { |
| 1813 return pp::Var(static_cast<int32_t>( | 1818 return pp::Var(static_cast<int32_t>( |
| 1814 v_scrollbar_.get() ? v_scrollbar_->GetValue() : 0)); | 1819 v_scrollbar_.get() ? v_scrollbar_->GetValue() : 0)); |
| 1815 } | 1820 } |
| 1816 if (method_str == kJSSetPageYOffset) { | 1821 if (method_str == kJSSetPageYOffset) { |
| 1817 if (args.size() == 1 && args[0].is_number() && v_scrollbar_.get()) | 1822 if (args.size() == 1 && args[0].is_number() && v_scrollbar_.get()) |
| 1818 ScrollToY(GetScaled(args[0].AsInt())); | 1823 ScrollToY(GetScaled(args[0].AsInt())); |
| (...skipping 937 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2756 return instance_->HasScriptableMethod(name, exception); | 2761 return instance_->HasScriptableMethod(name, exception); |
| 2757 } | 2762 } |
| 2758 | 2763 |
| 2759 pp::Var PDFScriptableObject::Call(const pp::Var& method, | 2764 pp::Var PDFScriptableObject::Call(const pp::Var& method, |
| 2760 const std::vector<pp::Var>& args, | 2765 const std::vector<pp::Var>& args, |
| 2761 pp::Var* exception) { | 2766 pp::Var* exception) { |
| 2762 return instance_->CallScriptableMethod(method, args, exception); | 2767 return instance_->CallScriptableMethod(method, args, exception); |
| 2763 } | 2768 } |
| 2764 | 2769 |
| 2765 } // namespace chrome_pdf | 2770 } // namespace chrome_pdf |
| OLD | NEW |