| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium 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 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "fpdfsdk/javascript/Document.h" | 7 #include "fpdfsdk/javascript/Document.h" |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" | 11 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" |
| 12 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" | 12 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" |
| 13 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
| 13 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | 14 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
| 14 #include "core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h" | 15 #include "core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h" |
| 15 #include "core/fpdfdoc/include/cpdf_interform.h" | 16 #include "core/fpdfdoc/include/cpdf_interform.h" |
| 17 #include "core/fpdfdoc/include/cpdf_nametree.h" |
| 16 #include "fpdfsdk/include/fsdk_mgr.h" | 18 #include "fpdfsdk/include/fsdk_mgr.h" |
| 17 #include "fpdfsdk/javascript/Field.h" | 19 #include "fpdfsdk/javascript/Field.h" |
| 18 #include "fpdfsdk/javascript/Icon.h" | 20 #include "fpdfsdk/javascript/Icon.h" |
| 19 #include "fpdfsdk/javascript/JS_Define.h" | 21 #include "fpdfsdk/javascript/JS_Define.h" |
| 20 #include "fpdfsdk/javascript/JS_EventHandler.h" | 22 #include "fpdfsdk/javascript/JS_EventHandler.h" |
| 21 #include "fpdfsdk/javascript/JS_Object.h" | 23 #include "fpdfsdk/javascript/JS_Object.h" |
| 22 #include "fpdfsdk/javascript/JS_Value.h" | 24 #include "fpdfsdk/javascript/JS_Value.h" |
| 23 #include "fpdfsdk/javascript/app.h" | 25 #include "fpdfsdk/javascript/app.h" |
| 24 #include "fpdfsdk/javascript/cjs_context.h" | 26 #include "fpdfsdk/javascript/cjs_context.h" |
| 25 #include "fpdfsdk/javascript/cjs_runtime.h" | 27 #include "fpdfsdk/javascript/cjs_runtime.h" |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 JS_STATIC_METHOD_ENTRY(getIcon) | 119 JS_STATIC_METHOD_ENTRY(getIcon) |
| 118 JS_STATIC_METHOD_ENTRY(getLinks) | 120 JS_STATIC_METHOD_ENTRY(getLinks) |
| 119 JS_STATIC_METHOD_ENTRY(getNthFieldName) | 121 JS_STATIC_METHOD_ENTRY(getNthFieldName) |
| 120 JS_STATIC_METHOD_ENTRY(getOCGs) | 122 JS_STATIC_METHOD_ENTRY(getOCGs) |
| 121 JS_STATIC_METHOD_ENTRY(getPageBox) | 123 JS_STATIC_METHOD_ENTRY(getPageBox) |
| 122 JS_STATIC_METHOD_ENTRY(getPageNthWord) | 124 JS_STATIC_METHOD_ENTRY(getPageNthWord) |
| 123 JS_STATIC_METHOD_ENTRY(getPageNthWordQuads) | 125 JS_STATIC_METHOD_ENTRY(getPageNthWordQuads) |
| 124 JS_STATIC_METHOD_ENTRY(getPageNumWords) | 126 JS_STATIC_METHOD_ENTRY(getPageNumWords) |
| 125 JS_STATIC_METHOD_ENTRY(getPrintParams) | 127 JS_STATIC_METHOD_ENTRY(getPrintParams) |
| 126 JS_STATIC_METHOD_ENTRY(getURL) | 128 JS_STATIC_METHOD_ENTRY(getURL) |
| 129 JS_STATIC_METHOD_ENTRY(gotoNamedDest) |
| 127 JS_STATIC_METHOD_ENTRY(importAnFDF) | 130 JS_STATIC_METHOD_ENTRY(importAnFDF) |
| 128 JS_STATIC_METHOD_ENTRY(importAnXFDF) | 131 JS_STATIC_METHOD_ENTRY(importAnXFDF) |
| 129 JS_STATIC_METHOD_ENTRY(importTextData) | 132 JS_STATIC_METHOD_ENTRY(importTextData) |
| 130 JS_STATIC_METHOD_ENTRY(insertPages) | 133 JS_STATIC_METHOD_ENTRY(insertPages) |
| 131 JS_STATIC_METHOD_ENTRY(mailForm) | 134 JS_STATIC_METHOD_ENTRY(mailForm) |
| 132 JS_STATIC_METHOD_ENTRY(print) | 135 JS_STATIC_METHOD_ENTRY(print) |
| 133 JS_STATIC_METHOD_ENTRY(removeField) | 136 JS_STATIC_METHOD_ENTRY(removeField) |
| 134 JS_STATIC_METHOD_ENTRY(replacePages) | 137 JS_STATIC_METHOD_ENTRY(replacePages) |
| 135 JS_STATIC_METHOD_ENTRY(resetForm) | 138 JS_STATIC_METHOD_ENTRY(resetForm) |
| 136 JS_STATIC_METHOD_ENTRY(removeIcon) | 139 JS_STATIC_METHOD_ENTRY(removeIcon) |
| (...skipping 1322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1459 } | 1462 } |
| 1460 | 1463 |
| 1461 FX_BOOL Document::getURL(IJS_Context* cc, | 1464 FX_BOOL Document::getURL(IJS_Context* cc, |
| 1462 const std::vector<CJS_Value>& params, | 1465 const std::vector<CJS_Value>& params, |
| 1463 CJS_Value& vRet, | 1466 CJS_Value& vRet, |
| 1464 CFX_WideString& sError) { | 1467 CFX_WideString& sError) { |
| 1465 // Unsafe, not supported. | 1468 // Unsafe, not supported. |
| 1466 return TRUE; | 1469 return TRUE; |
| 1467 } | 1470 } |
| 1468 | 1471 |
| 1472 FX_BOOL Document::gotoNamedDest(IJS_Context* cc, |
| 1473 const std::vector<CJS_Value>& params, |
| 1474 CJS_Value& vRet, |
| 1475 CFX_WideString& sError) { |
| 1476 CJS_Context* context = (CJS_Context*)cc; |
| 1477 if (params.size() != 1) { |
| 1478 sError = JSGetStringFromID(context, IDS_STRING_JSPARAMERROR); |
| 1479 return FALSE; |
| 1480 } |
| 1481 |
| 1482 CPDF_Document* pDocument = m_pDocument->GetPDFDocument(); |
| 1483 if (!pDocument) |
| 1484 return FALSE; |
| 1485 |
| 1486 CFX_WideString wideName = params[0].ToCFXWideString(); |
| 1487 CFX_ByteString utf8Name = wideName.UTF8Encode(); |
| 1488 |
| 1489 CPDF_NameTree nameTree(pDocument, "Dests"); |
| 1490 CPDF_Array* destArray = nameTree.LookupNamedDest(pDocument, utf8Name); |
| 1491 if (!destArray) |
| 1492 return FALSE; |
| 1493 |
| 1494 CPDF_Dest dest(destArray); |
| 1495 const CPDF_Array* arrayObject = ToArray(dest.GetObject()); |
| 1496 |
| 1497 std::unique_ptr<float[]> scrollPositionArray; |
| 1498 int scrollPositionArraySize = 0; |
| 1499 |
| 1500 if (arrayObject) { |
| 1501 scrollPositionArray.reset(new float[arrayObject->GetCount()]); |
| 1502 int j = 0; |
| 1503 for (size_t i = 2; i < arrayObject->GetCount(); i++) |
| 1504 scrollPositionArray[j++] = arrayObject->GetFloatAt(i); |
| 1505 scrollPositionArraySize = j; |
| 1506 } |
| 1507 |
| 1508 CJS_Runtime* runtime = context->GetJSRuntime(); |
| 1509 runtime->BeginBlock(); |
| 1510 CPDFDoc_Environment* pApp = m_pDocument->GetEnv(); |
| 1511 pApp->FFI_DoGoToAction(dest.GetPageIndex(pDocument), dest.GetZoomMode(), |
| 1512 scrollPositionArray.get(), scrollPositionArraySize); |
| 1513 runtime->EndBlock(); |
| 1514 |
| 1515 return TRUE; |
| 1516 } |
| 1517 |
| 1469 void Document::AddDelayData(CJS_DelayData* pData) { | 1518 void Document::AddDelayData(CJS_DelayData* pData) { |
| 1470 m_DelayData.push_back(std::unique_ptr<CJS_DelayData>(pData)); | 1519 m_DelayData.push_back(std::unique_ptr<CJS_DelayData>(pData)); |
| 1471 } | 1520 } |
| 1472 | 1521 |
| 1473 void Document::DoFieldDelay(const CFX_WideString& sFieldName, | 1522 void Document::DoFieldDelay(const CFX_WideString& sFieldName, |
| 1474 int nControlIndex) { | 1523 int nControlIndex) { |
| 1475 std::vector<std::unique_ptr<CJS_DelayData>> DelayDataForFieldAndControlIndex; | 1524 std::vector<std::unique_ptr<CJS_DelayData>> DelayDataForFieldAndControlIndex; |
| 1476 auto iter = m_DelayData.begin(); | 1525 auto iter = m_DelayData.begin(); |
| 1477 while (iter != m_DelayData.end()) { | 1526 while (iter != m_DelayData.end()) { |
| 1478 auto old = iter++; | 1527 auto old = iter++; |
| 1479 if ((*old)->sFieldName == sFieldName && | 1528 if ((*old)->sFieldName == sFieldName && |
| 1480 (*old)->nControlIndex == nControlIndex) { | 1529 (*old)->nControlIndex == nControlIndex) { |
| 1481 DelayDataForFieldAndControlIndex.push_back(std::move(*old)); | 1530 DelayDataForFieldAndControlIndex.push_back(std::move(*old)); |
| 1482 m_DelayData.erase(old); | 1531 m_DelayData.erase(old); |
| 1483 } | 1532 } |
| 1484 } | 1533 } |
| 1485 | 1534 |
| 1486 for (const auto& pData : DelayDataForFieldAndControlIndex) | 1535 for (const auto& pData : DelayDataForFieldAndControlIndex) |
| 1487 Field::DoDelay(m_pDocument, pData.get()); | 1536 Field::DoDelay(m_pDocument, pData.get()); |
| 1488 } | 1537 } |
| 1489 | 1538 |
| 1490 CJS_Document* Document::GetCJSDoc() const { | 1539 CJS_Document* Document::GetCJSDoc() const { |
| 1491 return static_cast<CJS_Document*>(m_pJSObject); | 1540 return static_cast<CJS_Document*>(m_pJSObject); |
| 1492 } | 1541 } |
| OLD | NEW |