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

Side by Side Diff: xfa/fde/css/cfde_cssrulecollection.cpp

Issue 2616813002: Remove CFX_MapPtrToPtr from xfa/fde. (Closed)
Patch Set: no FDE_LPC* Created 3 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 | xfa/fde/css/fde_css.h » ('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 2016 PDFium Authors. All rights reserved. 1 // Copyright 2016 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 "xfa/fde/css/fde_cssstyleselector.h" 7 #include "xfa/fde/css/fde_cssstyleselector.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <map>
10 #include <memory> 11 #include <memory>
11 12
12 #include "xfa/fde/css/fde_csscache.h" 13 #include "xfa/fde/css/fde_csscache.h"
13 #include "xfa/fde/css/fde_cssdeclaration.h" 14 #include "xfa/fde/css/fde_cssdeclaration.h"
14 #include "xfa/fde/css/fde_cssstylesheet.h" 15 #include "xfa/fde/css/fde_cssstylesheet.h"
15 #include "xfa/fde/css/fde_csssyntax.h" 16 #include "xfa/fde/css/fde_csssyntax.h"
16 #include "xfa/fxfa/app/xfa_textlayout.h" 17 #include "xfa/fxfa/app/xfa_textlayout.h"
17 18
18 #define FDE_CSSUNIVERSALHASH ('*') 19 #define FDE_CSSUNIVERSALHASH ('*')
19 20
20 void CFDE_CSSRuleCollection::Clear() { 21 void CFDE_CSSRuleCollection::Clear() {
21 m_IDRules.RemoveAll(); 22 m_IDRules.clear();
22 m_TagRules.RemoveAll(); 23 m_TagRules.clear();
23 m_ClassRules.RemoveAll(); 24 m_ClassRules.clear();
24 m_pUniversalRules = nullptr; 25 m_pUniversalRules = nullptr;
25 m_pStaticStore = nullptr; 26 m_pStaticStore = nullptr;
26 m_iSelectors = 0; 27 m_iSelectors = 0;
27 } 28 }
28 29
29 CFDE_CSSRuleCollection::CFDE_CSSRuleCollection() 30 CFDE_CSSRuleCollection::CFDE_CSSRuleCollection()
30 : m_pStaticStore(nullptr), 31 : m_pStaticStore(nullptr),
31 m_pUniversalRules(nullptr), 32 m_pUniversalRules(nullptr),
32 m_pPersudoRules(nullptr), 33 m_pPseudoRules(nullptr),
33 m_iSelectors(0) {} 34 m_iSelectors(0) {}
34 35
35 CFDE_CSSRuleCollection::~CFDE_CSSRuleCollection() { 36 CFDE_CSSRuleCollection::~CFDE_CSSRuleCollection() {
36 Clear(); 37 Clear();
37 } 38 }
38 39
39 void CFDE_CSSRuleCollection::AddRulesFrom(const CFDE_CSSStyleSheetArray& sheets, 40 void CFDE_CSSRuleCollection::AddRulesFrom(const CFDE_CSSStyleSheetArray& sheets,
40 uint32_t dwMediaList, 41 uint32_t dwMediaList,
41 CFGAS_FontMgr* pFontMgr) { 42 CFGAS_FontMgr* pFontMgr) {
42 int32_t iSheets = sheets.GetSize(); 43 int32_t iSheets = sheets.GetSize();
(...skipping 12 matching lines...) Expand all
55 IFDE_CSSRule* pRule, 56 IFDE_CSSRule* pRule,
56 uint32_t dwMediaList, 57 uint32_t dwMediaList,
57 CFGAS_FontMgr* pFontMgr) { 58 CFGAS_FontMgr* pFontMgr) {
58 switch (pRule->GetType()) { 59 switch (pRule->GetType()) {
59 case FDE_CSSRULETYPE_Style: { 60 case FDE_CSSRULETYPE_Style: {
60 IFDE_CSSStyleRule* pStyleRule = static_cast<IFDE_CSSStyleRule*>(pRule); 61 IFDE_CSSStyleRule* pStyleRule = static_cast<IFDE_CSSStyleRule*>(pRule);
61 CFDE_CSSDeclaration* pDeclaration = pStyleRule->GetDeclaration(); 62 CFDE_CSSDeclaration* pDeclaration = pStyleRule->GetDeclaration();
62 int32_t iSelectors = pStyleRule->CountSelectorLists(); 63 int32_t iSelectors = pStyleRule->CountSelectorLists();
63 for (int32_t i = 0; i < iSelectors; ++i) { 64 for (int32_t i = 0; i < iSelectors; ++i) {
64 CFDE_CSSSelector* pSelector = pStyleRule->GetSelectorList(i); 65 CFDE_CSSSelector* pSelector = pStyleRule->GetSelectorList(i);
65 if (pSelector->GetType() == FDE_CSSSELECTORTYPE_Persudo) { 66 if (pSelector->GetType() == FDE_CSSSELECTORTYPE_Pseudo) {
66 FDE_CSSRuleData* pData = NewRuleData(pSelector, pDeclaration); 67 FDE_CSSRuleData* pData = NewRuleData(pSelector, pDeclaration);
67 AddRuleTo(m_pPersudoRules, pData); 68 AddRuleTo(&m_pPseudoRules, pData);
68 continue; 69 continue;
69 } 70 }
70 if (pSelector->GetNameHash() != FDE_CSSUNIVERSALHASH) { 71 if (pSelector->GetNameHash() != FDE_CSSUNIVERSALHASH) {
71 AddRuleTo(m_TagRules, pSelector->GetNameHash(), pSelector, 72 AddRuleTo(&m_TagRules, pSelector->GetNameHash(), pSelector,
72 pDeclaration); 73 pDeclaration);
73 continue; 74 continue;
74 } 75 }
75 CFDE_CSSSelector* pNext = pSelector->GetNextSelector(); 76 CFDE_CSSSelector* pNext = pSelector->GetNextSelector();
76 if (!pNext) { 77 if (!pNext) {
77 FDE_CSSRuleData* pData = NewRuleData(pSelector, pDeclaration); 78 FDE_CSSRuleData* pData = NewRuleData(pSelector, pDeclaration);
78 AddRuleTo(m_pUniversalRules, pData); 79 AddRuleTo(&m_pUniversalRules, pData);
79 continue; 80 continue;
80 } 81 }
81 switch (pNext->GetType()) { 82 switch (pNext->GetType()) {
82 case FDE_CSSSELECTORTYPE_ID: 83 case FDE_CSSSELECTORTYPE_ID:
83 AddRuleTo(m_IDRules, pNext->GetNameHash(), pSelector, pDeclaration); 84 AddRuleTo(&m_IDRules, pNext->GetNameHash(), pSelector,
85 pDeclaration);
84 break; 86 break;
85 case FDE_CSSSELECTORTYPE_Class: 87 case FDE_CSSSELECTORTYPE_Class:
86 AddRuleTo(m_ClassRules, pNext->GetNameHash(), pSelector, 88 AddRuleTo(&m_ClassRules, pNext->GetNameHash(), pSelector,
87 pDeclaration); 89 pDeclaration);
88 break; 90 break;
89 case FDE_CSSSELECTORTYPE_Descendant: 91 case FDE_CSSSELECTORTYPE_Descendant:
90 case FDE_CSSSELECTORTYPE_Element: 92 case FDE_CSSSELECTORTYPE_Element:
91 AddRuleTo(m_pUniversalRules, NewRuleData(pSelector, pDeclaration)); 93 AddRuleTo(&m_pUniversalRules, NewRuleData(pSelector, pDeclaration));
92 break; 94 break;
93 default: 95 default:
94 ASSERT(false); 96 ASSERT(false);
95 break; 97 break;
96 } 98 }
97 } 99 }
98 } break; 100 } break;
99 case FDE_CSSRULETYPE_Media: { 101 case FDE_CSSRULETYPE_Media: {
100 IFDE_CSSMediaRule* pMediaRule = static_cast<IFDE_CSSMediaRule*>(pRule); 102 IFDE_CSSMediaRule* pMediaRule = static_cast<IFDE_CSSMediaRule*>(pRule);
101 if (pMediaRule->GetMediaList() & dwMediaList) { 103 if (pMediaRule->GetMediaList() & dwMediaList) {
102 int32_t iRules = pMediaRule->CountRules(); 104 int32_t iRules = pMediaRule->CountRules();
103 for (int32_t i = 0; i < iRules; ++i) { 105 for (int32_t i = 0; i < iRules; ++i) {
104 AddRulesFrom(pStyleSheet, pMediaRule->GetRule(i), dwMediaList, 106 AddRulesFrom(pStyleSheet, pMediaRule->GetRule(i), dwMediaList,
105 pFontMgr); 107 pFontMgr);
106 } 108 }
107 } 109 }
108 } break; 110 } break;
109 default: 111 default:
110 break; 112 break;
111 } 113 }
112 } 114 }
113 115
114 void CFDE_CSSRuleCollection::AddRuleTo(CFX_MapPtrToPtr& map, 116 void CFDE_CSSRuleCollection::AddRuleTo(
115 uint32_t dwKey, 117 std::map<uint32_t, FDE_CSSRuleData*>* pMap,
116 CFDE_CSSSelector* pSel, 118 uint32_t dwKey,
117 CFDE_CSSDeclaration* pDecl) { 119 CFDE_CSSSelector* pSel,
118 void* pKey = (void*)(uintptr_t)dwKey; 120 CFDE_CSSDeclaration* pDecl) {
119 FDE_CSSRuleData* pData = NewRuleData(pSel, pDecl); 121 FDE_CSSRuleData* pData = NewRuleData(pSel, pDecl);
120 FDE_CSSRuleData* pList = nullptr; 122 FDE_CSSRuleData* pList = (*pMap)[dwKey];
121 if (!map.Lookup(pKey, (void*&)pList)) { 123 if (!pList) {
122 map.SetAt(pKey, pData); 124 (*pMap)[dwKey] = pData;
123 } else if (AddRuleTo(pList, pData)) { 125 } else if (AddRuleTo(&pList, pData)) {
124 map.SetAt(pKey, pList); 126 (*pMap)[dwKey] = pList;
125 } 127 }
126 } 128 }
127 129
128 bool CFDE_CSSRuleCollection::AddRuleTo(FDE_CSSRuleData*& pList, 130 bool CFDE_CSSRuleCollection::AddRuleTo(FDE_CSSRuleData** pList,
129 FDE_CSSRuleData* pData) { 131 FDE_CSSRuleData* pData) {
130 if (pList) { 132 if (*pList) {
131 pData->pNext = pList->pNext; 133 pData->pNext = (*pList)->pNext;
132 pList->pNext = pData; 134 (*pList)->pNext = pData;
133 return false; 135 return false;
134 } 136 }
135 137 *pList = pData;
136 pList = pData;
137 return true; 138 return true;
138 } 139 }
139 140
140 FDE_CSSRuleData* CFDE_CSSRuleCollection::NewRuleData( 141 FDE_CSSRuleData* CFDE_CSSRuleCollection::NewRuleData(
141 CFDE_CSSSelector* pSel, 142 CFDE_CSSSelector* pSel,
142 CFDE_CSSDeclaration* pDecl) { 143 CFDE_CSSDeclaration* pDecl) {
143 return FXTARGET_NewWith(m_pStaticStore) 144 return FXTARGET_NewWith(m_pStaticStore)
144 FDE_CSSRuleData(pSel, pDecl, ++m_iSelectors); 145 FDE_CSSRuleData(pSel, pDecl, ++m_iSelectors);
145 } 146 }
OLDNEW
« no previous file with comments | « no previous file | xfa/fde/css/fde_css.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698