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

Side by Side Diff: fpdfsdk/src/javascript/Document.cpp

Issue 1566433003: Replace IconTree class with std::list. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Fix tests. Created 4 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 | « fpdfsdk/src/javascript/Document.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 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 "Document.h" 7 #include "Document.h"
8 8
9 #include "Field.h" 9 #include "Field.h"
10 #include "Icon.h" 10 #include "Icon.h"
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 pDoc->AttachDoc(pRuntime->GetReaderDocument()); 142 pDoc->AttachDoc(pRuntime->GetReaderDocument());
143 pDoc->SetIsolate(pRuntime->GetIsolate()); 143 pDoc->SetIsolate(pRuntime->GetIsolate());
144 } 144 }
145 145
146 /* --------------------------------- Document --------------------------------- 146 /* --------------------------------- Document ---------------------------------
147 */ 147 */
148 148
149 Document::Document(CJS_Object* pJSObject) 149 Document::Document(CJS_Object* pJSObject)
150 : CJS_EmbedObj(pJSObject), 150 : CJS_EmbedObj(pJSObject),
151 m_isolate(NULL), 151 m_isolate(NULL),
152 m_pIconTree(NULL),
153 m_pDocument(NULL), 152 m_pDocument(NULL),
154 m_cwBaseURL(L""), 153 m_cwBaseURL(L""),
155 m_bDelay(FALSE) {} 154 m_bDelay(FALSE) {}
156 155
157 Document::~Document() { 156 Document::~Document() {
158 if (m_pIconTree) {
159 m_pIconTree->DeleteIconTree();
160 delete m_pIconTree;
161 m_pIconTree = NULL;
162 }
163 for (int i = 0; i < m_DelayData.GetSize(); i++) { 157 for (int i = 0; i < m_DelayData.GetSize(); i++) {
164 if (CJS_DelayData* pData = m_DelayData.GetAt(i)) { 158 delete m_DelayData.GetAt(i);
165 delete pData;
166 pData = NULL;
167 m_DelayData.SetAt(i, NULL);
168 }
169 } 159 }
170 160
171 m_DelayData.RemoveAll(); 161 m_DelayData.RemoveAll();
172 m_DelayAnnotData.RemoveAll(); 162 m_DelayAnnotData.RemoveAll();
173 } 163 }
174 164
175 // the total number of fileds in document. 165 // the total number of fileds in document.
176 FX_BOOL Document::numFields(IJS_Context* cc, 166 FX_BOOL Document::numFields(IJS_Context* cc,
177 CJS_PropValue& vp, 167 CJS_PropValue& vp,
178 CFX_WideString& sError) { 168 CFX_WideString& sError) {
(...skipping 1069 matching lines...) Expand 10 before | Expand all | Expand 10 after
1248 CJS_Value& vRet, 1238 CJS_Value& vRet,
1249 CFX_WideString& sError) { 1239 CFX_WideString& sError) {
1250 return TRUE; 1240 return TRUE;
1251 } 1241 }
1252 1242
1253 bool Document::IsEnclosedInRect(CFX_FloatRect rect, CFX_FloatRect LinkRect) { 1243 bool Document::IsEnclosedInRect(CFX_FloatRect rect, CFX_FloatRect LinkRect) {
1254 return (rect.left <= LinkRect.left && rect.top <= LinkRect.top && 1244 return (rect.left <= LinkRect.left && rect.top <= LinkRect.top &&
1255 rect.right >= LinkRect.right && rect.bottom >= LinkRect.bottom); 1245 rect.right >= LinkRect.right && rect.bottom >= LinkRect.bottom);
1256 } 1246 }
1257 1247
1258 void IconTree::InsertIconElement(IconElement* pNewIcon) {
1259 if (!pNewIcon)
1260 return;
1261
1262 if (m_pHead || m_pEnd) {
1263 m_pEnd->NextIcon = pNewIcon;
1264 m_pEnd = pNewIcon;
1265 } else {
1266 m_pHead = pNewIcon;
1267 m_pEnd = pNewIcon;
1268 }
1269 m_iLength++;
1270 }
1271
1272 void IconTree::DeleteIconTree() {
1273 if (!m_pHead || !m_pEnd)
1274 return;
1275
1276 IconElement* pTemp = NULL;
1277 while (m_pEnd != m_pHead) {
1278 pTemp = m_pHead;
1279 m_pHead = m_pHead->NextIcon;
1280 delete pTemp;
1281 }
1282
1283 delete m_pEnd;
1284 m_pHead = NULL;
1285 m_pEnd = NULL;
1286 }
1287
1288 int IconTree::GetLength() {
1289 return m_iLength;
1290 }
1291
1292 IconElement* IconTree::operator[](int iIndex) {
1293 if (iIndex >= 0 && iIndex <= m_iLength) {
1294 IconElement* pTemp = m_pHead;
1295 for (int i = 0; i < iIndex; i++) {
1296 pTemp = pTemp->NextIcon;
1297 }
1298 return pTemp;
1299 }
1300 return NULL;
1301 }
1302
1303 FX_BOOL Document::addIcon(IJS_Context* cc, 1248 FX_BOOL Document::addIcon(IJS_Context* cc,
1304 const std::vector<CJS_Value>& params, 1249 const std::vector<CJS_Value>& params,
1305 CJS_Value& vRet, 1250 CJS_Value& vRet,
1306 CFX_WideString& sError) { 1251 CFX_WideString& sError) {
1307 CJS_Context* pContext = (CJS_Context*)cc; 1252 CJS_Context* pContext = (CJS_Context*)cc;
1308 if (params.size() != 2) { 1253 if (params.size() != 2) {
1309 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); 1254 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1310 return FALSE; 1255 return FALSE;
1311 } 1256 }
1312 CFX_WideString swIconName = params[0].ToCFXWideString(); 1257 CFX_WideString swIconName = params[0].ToCFXWideString();
1313 1258
1314 if (params[1].GetType() != CJS_Value::VT_object) { 1259 if (params[1].GetType() != CJS_Value::VT_object) {
1315 sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR); 1260 sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR);
1316 return FALSE; 1261 return FALSE;
1317 } 1262 }
1318 1263
1319 v8::Local<v8::Object> pJSIcon = params[1].ToV8Object(); 1264 v8::Local<v8::Object> pJSIcon = params[1].ToV8Object();
1320 if (FXJS_GetObjDefnID(pJSIcon) != CJS_Icon::g_nObjDefnID) { 1265 if (FXJS_GetObjDefnID(pJSIcon) != CJS_Icon::g_nObjDefnID) {
1321 sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR); 1266 sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR);
1322 return FALSE; 1267 return FALSE;
1323 } 1268 }
1324 1269
1325 CJS_EmbedObj* pEmbedObj = params[1].ToCJSObject()->GetEmbedObject(); 1270 CJS_EmbedObj* pEmbedObj = params[1].ToCJSObject()->GetEmbedObject();
1326 if (!pEmbedObj) { 1271 if (!pEmbedObj) {
1327 sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR); 1272 sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR);
1328 return FALSE; 1273 return FALSE;
1329 } 1274 }
1330 1275
1331 Icon* pIcon = (Icon*)pEmbedObj; 1276 m_IconList.push_back(std::unique_ptr<IconElement>(
1332 if (!m_pIconTree) 1277 new IconElement(swIconName, (Icon*)pEmbedObj)));
1333 m_pIconTree = new IconTree();
1334
1335 IconElement* pNewIcon = new IconElement();
1336 pNewIcon->IconName = swIconName;
1337 pNewIcon->NextIcon = NULL;
1338 pNewIcon->IconStream = pIcon;
1339 m_pIconTree->InsertIconElement(pNewIcon);
1340 return TRUE; 1278 return TRUE;
1341 } 1279 }
1342 1280
1343 FX_BOOL Document::icons(IJS_Context* cc, 1281 FX_BOOL Document::icons(IJS_Context* cc,
1344 CJS_PropValue& vp, 1282 CJS_PropValue& vp,
1345 CFX_WideString& sError) { 1283 CFX_WideString& sError) {
1346 if (vp.IsSetting()) { 1284 if (vp.IsSetting()) {
1347 CJS_Context* pContext = static_cast<CJS_Context*>(cc); 1285 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
1348 sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); 1286 sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY);
1349 return FALSE; 1287 return FALSE;
1350 } 1288 }
1351 1289
1352 if (!m_pIconTree) { 1290 if (m_IconList.empty()) {
1353 vp.SetNull(); 1291 vp.SetNull();
1354 return TRUE; 1292 return TRUE;
1355 } 1293 }
1356 1294
1357 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); 1295 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
1358 CJS_Array Icons(pRuntime); 1296 CJS_Array Icons(pRuntime);
1359 IconElement* pIconElement = NULL;
1360 int iIconTreeLength = m_pIconTree->GetLength();
1361 for (int i = 0; i < iIconTreeLength; i++) {
1362 pIconElement = (*m_pIconTree)[i];
1363 1297
1298 int i = 0;
1299 for (const auto& pIconElement : m_IconList) {
1364 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj( 1300 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj(
1365 pRuntime->GetIsolate(), pRuntime, CJS_Icon::g_nObjDefnID); 1301 pRuntime->GetIsolate(), pRuntime, CJS_Icon::g_nObjDefnID);
1366 if (pObj.IsEmpty()) 1302 if (pObj.IsEmpty())
1367 return FALSE; 1303 return FALSE;
1368 1304
1369 CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(m_isolate, pObj); 1305 CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(m_isolate, pObj);
1370 if (!pJS_Icon) 1306 if (!pJS_Icon)
1371 return FALSE; 1307 return FALSE;
1372 1308
1373 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject(); 1309 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject();
1374 if (!pIcon) 1310 if (!pIcon)
1375 return FALSE; 1311 return FALSE;
1376 1312
1377 pIcon->SetStream(pIconElement->IconStream->GetStream()); 1313 pIcon->SetStream(pIconElement->IconStream->GetStream());
1378 pIcon->SetIconName(pIconElement->IconName); 1314 pIcon->SetIconName(pIconElement->IconName);
1379 Icons.SetElement(i, CJS_Value(pRuntime, pJS_Icon)); 1315 Icons.SetElement(i++, CJS_Value(pRuntime, pJS_Icon));
1380 } 1316 }
1381 1317
1382 vp << Icons; 1318 vp << Icons;
1383 return TRUE; 1319 return TRUE;
1384 } 1320 }
1385 1321
1386 FX_BOOL Document::getIcon(IJS_Context* cc, 1322 FX_BOOL Document::getIcon(IJS_Context* cc,
1387 const std::vector<CJS_Value>& params, 1323 const std::vector<CJS_Value>& params,
1388 CJS_Value& vRet, 1324 CJS_Value& vRet,
1389 CFX_WideString& sError) { 1325 CFX_WideString& sError) {
1390 CJS_Context* pContext = (CJS_Context*)cc; 1326 CJS_Context* pContext = (CJS_Context*)cc;
1391 if (params.size() != 1) { 1327 if (params.size() != 1) {
1392 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); 1328 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1393 return FALSE; 1329 return FALSE;
1394 } 1330 }
1395 1331
1396 if (!m_pIconTree) 1332 if (m_IconList.empty())
1397 return FALSE; 1333 return FALSE;
1334
1398 CFX_WideString swIconName = params[0].ToCFXWideString(); 1335 CFX_WideString swIconName = params[0].ToCFXWideString();
1399 int iIconCounts = m_pIconTree->GetLength();
1400
1401 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); 1336 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
1402 1337
1403 for (int i = 0; i < iIconCounts; i++) { 1338 for (const auto& pIconElement : m_IconList) {
1404 if ((*m_pIconTree)[i]->IconName == swIconName) { 1339 if (pIconElement->IconName == swIconName) {
1405 Icon* pRetIcon = (*m_pIconTree)[i]->IconStream; 1340 Icon* pRetIcon = pIconElement->IconStream;
1406 1341
1407 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj( 1342 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj(
1408 pRuntime->GetIsolate(), pRuntime, CJS_Icon::g_nObjDefnID); 1343 pRuntime->GetIsolate(), pRuntime, CJS_Icon::g_nObjDefnID);
1409 if (pObj.IsEmpty()) 1344 if (pObj.IsEmpty())
1410 return FALSE; 1345 return FALSE;
1411 1346
1412 CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(m_isolate, pObj); 1347 CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(m_isolate, pObj);
1413 if (!pJS_Icon) 1348 if (!pJS_Icon)
1414 return FALSE; 1349 return FALSE;
1415 1350
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
1773 CFX_DWordArray DelArray; 1708 CFX_DWordArray DelArray;
1774 1709
1775 for (int j = DelArray.GetSize() - 1; j >= 0; j--) { 1710 for (int j = DelArray.GetSize() - 1; j >= 0; j--) {
1776 m_DelayData.RemoveAt(DelArray[j]); 1711 m_DelayData.RemoveAt(DelArray[j]);
1777 } 1712 }
1778 } 1713 }
1779 1714
1780 CJS_Document* Document::GetCJSDoc() const { 1715 CJS_Document* Document::GetCJSDoc() const {
1781 return static_cast<CJS_Document*>(m_pJSObject); 1716 return static_cast<CJS_Document*>(m_pJSObject);
1782 } 1717 }
OLDNEW
« no previous file with comments | « fpdfsdk/src/javascript/Document.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698