Chromium Code Reviews| 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 "Field.h" | 7 #include "Field.h" |
| 8 | 8 |
| 9 #include "Document.h" | 9 #include "Document.h" |
| 10 #include "Icon.h" | 10 #include "Icon.h" |
| (...skipping 3065 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3076 return TRUE; | 3076 return TRUE; |
| 3077 } | 3077 } |
| 3078 | 3078 |
| 3079 FX_BOOL Field::deleteItemAt(IJS_Context* cc, | 3079 FX_BOOL Field::deleteItemAt(IJS_Context* cc, |
| 3080 const std::vector<CJS_Value>& params, | 3080 const std::vector<CJS_Value>& params, |
| 3081 CJS_Value& vRet, | 3081 CJS_Value& vRet, |
| 3082 CFX_WideString& sError) { | 3082 CFX_WideString& sError) { |
| 3083 return TRUE; | 3083 return TRUE; |
| 3084 } | 3084 } |
| 3085 | 3085 |
| 3086 int JS_COMPARESTRING(CFX_WideString* ps1, CFX_WideString* ps2) { | |
| 3087 return ps1->Compare(*ps2); | |
| 3088 } | |
| 3089 | |
| 3090 FX_BOOL Field::getArray(IJS_Context* cc, | 3086 FX_BOOL Field::getArray(IJS_Context* cc, |
| 3091 const std::vector<CJS_Value>& params, | 3087 const std::vector<CJS_Value>& params, |
| 3092 CJS_Value& vRet, | 3088 CJS_Value& vRet, |
| 3093 CFX_WideString& sError) { | 3089 CFX_WideString& sError) { |
| 3094 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); | 3090 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 3095 if (FieldArray.empty()) | 3091 if (FieldArray.empty()) |
| 3096 return FALSE; | 3092 return FALSE; |
| 3097 | 3093 |
| 3098 CGW_ArrayTemplate<CFX_WideString*> swSort; | 3094 std::vector<std::unique_ptr<CFX_WideString>> swSort; |
|
Lei Zhang
2016/02/01 19:12:55
#include <vector>, <memory> and <algorithm>
Tom Sepez
2016/02/01 20:14:23
Done.
| |
| 3095 for (CPDF_FormField* pFormField : FieldArray) { | |
| 3096 swSort.push_back(std::unique_ptr<CFX_WideString>( | |
| 3097 new CFX_WideString(pFormField->GetFullName()))); | |
| 3098 } | |
| 3099 | 3099 |
| 3100 for (CPDF_FormField* pFormField : FieldArray) | 3100 std::sort( |
| 3101 swSort.Add(new CFX_WideString(pFormField->GetFullName())); | 3101 swSort.begin(), swSort.end(), |
| 3102 swSort.Sort(JS_COMPARESTRING); | 3102 [](const std::unique_ptr<CFX_WideString>& p1, |
| 3103 const std::unique_ptr<CFX_WideString>& p2) { return *p1 < *p2; }); | |
| 3103 | 3104 |
| 3104 CJS_Context* pContext = (CJS_Context*)cc; | 3105 CJS_Context* pContext = (CJS_Context*)cc; |
| 3105 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 3106 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
| 3106 ASSERT(pRuntime); | 3107 CJS_Array FormFieldArray(pRuntime); |
| 3107 | 3108 |
| 3108 CJS_Array FormFieldArray(pRuntime); | 3109 int j = 0; |
| 3109 for (int j = 0, jsz = swSort.GetSize(); j < jsz; j++) { | 3110 for (const auto& pStr : swSort) { |
| 3110 std::unique_ptr<CFX_WideString> pStr(swSort.GetAt(j)); | |
| 3111 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj( | 3111 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj( |
| 3112 pRuntime->GetIsolate(), pRuntime, CJS_Field::g_nObjDefnID); | 3112 pRuntime->GetIsolate(), pRuntime, CJS_Field::g_nObjDefnID); |
| 3113 ASSERT(!pObj.IsEmpty()); | 3113 ASSERT(!pObj.IsEmpty()); |
| 3114 | 3114 |
| 3115 CJS_Field* pJSField = | 3115 CJS_Field* pJSField = |
| 3116 (CJS_Field*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj); | 3116 static_cast<CJS_Field*>(FXJS_GetPrivate(pRuntime->GetIsolate(), pObj)); |
| 3117 Field* pField = (Field*)pJSField->GetEmbedObject(); | 3117 Field* pField = static_cast<Field*>(pJSField->GetEmbedObject()); |
| 3118 pField->AttachField(m_pJSDoc, *pStr); | 3118 pField->AttachField(m_pJSDoc, *pStr); |
| 3119 | 3119 |
| 3120 CJS_Value FormFieldValue(pRuntime); | 3120 CJS_Value FormFieldValue(pRuntime); |
| 3121 FormFieldValue = pJSField; | 3121 FormFieldValue = pJSField; |
| 3122 FormFieldArray.SetElement(j, FormFieldValue); | 3122 FormFieldArray.SetElement(j++, FormFieldValue); |
| 3123 } | 3123 } |
| 3124 | 3124 |
| 3125 vRet = FormFieldArray; | 3125 vRet = FormFieldArray; |
| 3126 swSort.RemoveAll(); | |
| 3127 return TRUE; | 3126 return TRUE; |
| 3128 } | 3127 } |
| 3129 | 3128 |
| 3130 FX_BOOL Field::getItemAt(IJS_Context* cc, | 3129 FX_BOOL Field::getItemAt(IJS_Context* cc, |
| 3131 const std::vector<CJS_Value>& params, | 3130 const std::vector<CJS_Value>& params, |
| 3132 CJS_Value& vRet, | 3131 CJS_Value& vRet, |
| 3133 CFX_WideString& sError) { | 3132 CFX_WideString& sError) { |
| 3134 int iSize = params.size(); | 3133 int iSize = params.size(); |
| 3135 | 3134 |
| 3136 int nIdx = -1; | 3135 int nIdx = -1; |
| (...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3586 } | 3585 } |
| 3587 } | 3586 } |
| 3588 | 3587 |
| 3589 void Field::AddField(CPDFSDK_Document* pDocument, | 3588 void Field::AddField(CPDFSDK_Document* pDocument, |
| 3590 int nPageIndex, | 3589 int nPageIndex, |
| 3591 int nFieldType, | 3590 int nFieldType, |
| 3592 const CFX_WideString& sName, | 3591 const CFX_WideString& sName, |
| 3593 const CPDF_Rect& rcCoords) { | 3592 const CPDF_Rect& rcCoords) { |
| 3594 // Not supported. | 3593 // Not supported. |
| 3595 } | 3594 } |
| OLD | NEW |