| 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 "xfa/fde/css/fde_csscache.h" | 7 #include "xfa/fde/css/fde_csscache.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| 11 #include "core/fxcrt/include/fx_ext.h" | 11 #include "core/fxcrt/include/fx_ext.h" |
| 12 #include "xfa/fxfa/app/xfa_textlayout.h" |
| 12 | 13 |
| 13 FDE_CSSCacheItem::FDE_CSSCacheItem(IFDE_CSSStyleSheet* p) | 14 FDE_CSSCacheItem::FDE_CSSCacheItem(IFDE_CSSStyleSheet* p) |
| 14 : pStylesheet(p), dwActivity(0) { | 15 : pStylesheet(p), dwActivity(0) { |
| 15 FXSYS_assert(pStylesheet); | 16 FXSYS_assert(pStylesheet); |
| 16 pStylesheet->AddRef(); | 17 pStylesheet->AddRef(); |
| 17 } | 18 } |
| 19 |
| 18 FDE_CSSCacheItem::~FDE_CSSCacheItem() { | 20 FDE_CSSCacheItem::~FDE_CSSCacheItem() { |
| 19 pStylesheet->Release(); | 21 pStylesheet->Release(); |
| 20 } | 22 } |
| 21 | 23 |
| 22 FDE_CSSTagCache::FDE_CSSTagCache(FDE_CSSTagCache* parent, | 24 FDE_CSSTagCache::FDE_CSSTagCache(FDE_CSSTagCache* parent, |
| 23 IFDE_CSSTagProvider* tag) | 25 CXFA_CSSTagProvider* tag) |
| 24 : pTag(tag), | 26 : pTag(tag), |
| 25 pParent(parent), | 27 pParent(parent), |
| 26 dwIDHash(0), | 28 dwIDHash(0), |
| 27 dwTagHash(0), | 29 dwTagHash(0), |
| 28 iClassIndex(0), | 30 iClassIndex(0), |
| 29 dwClassHashs(1) { | 31 dwClassHashs(1) { |
| 30 FXSYS_assert(pTag != NULL); | 32 static const uint32_t s_dwIDHash = FX_HashCode_String_GetW(L"id", 2, TRUE); |
| 31 CFX_WideStringC wsValue, wsName = pTag->GetTagName(); | 33 static const uint32_t s_dwClassHash = |
| 32 dwTagHash = FX_HashCode_String_GetW(wsName.c_str(), wsName.GetLength(), TRUE); | 34 FX_HashCode_String_GetW(L"class", 5, TRUE); |
| 33 FX_POSITION pos = pTag->GetFirstAttribute(); | 35 |
| 34 while (pos != NULL) { | 36 CFX_WideString wsTag = pTag->GetTagName(); |
| 35 pTag->GetNextAttribute(pos, wsName, wsValue); | 37 dwTagHash = FX_HashCode_String_GetW(wsTag.c_str(), wsTag.GetLength(), TRUE); |
| 38 |
| 39 for (auto it : *pTag) { |
| 40 CFX_WideString wsValue = it.first; |
| 41 CFX_WideString wsName = it.second; |
| 42 |
| 36 uint32_t dwNameHash = | 43 uint32_t dwNameHash = |
| 37 FX_HashCode_String_GetW(wsName.c_str(), wsName.GetLength(), TRUE); | 44 FX_HashCode_String_GetW(wsName.c_str(), wsName.GetLength(), TRUE); |
| 38 static const uint32_t s_dwIDHash = FX_HashCode_String_GetW(L"id", 2, TRUE); | 45 |
| 39 static const uint32_t s_dwClassHash = | |
| 40 FX_HashCode_String_GetW(L"class", 5, TRUE); | |
| 41 if (dwNameHash == s_dwClassHash) { | 46 if (dwNameHash == s_dwClassHash) { |
| 42 uint32_t dwHash = | 47 uint32_t dwHash = |
| 43 FX_HashCode_String_GetW(wsValue.c_str(), wsValue.GetLength()); | 48 FX_HashCode_String_GetW(wsValue.c_str(), wsValue.GetLength()); |
| 44 dwClassHashs.Add(dwHash); | 49 dwClassHashs.Add(dwHash); |
| 45 } else if (dwNameHash == s_dwIDHash) { | 50 } else if (dwNameHash == s_dwIDHash) { |
| 46 dwIDHash = FX_HashCode_String_GetW(wsValue.c_str(), wsValue.GetLength()); | 51 dwIDHash = FX_HashCode_String_GetW(wsValue.c_str(), wsValue.GetLength()); |
| 47 } | 52 } |
| 48 } | 53 } |
| 49 } | 54 } |
| 55 |
| 50 FDE_CSSTagCache::FDE_CSSTagCache(const FDE_CSSTagCache& it) | 56 FDE_CSSTagCache::FDE_CSSTagCache(const FDE_CSSTagCache& it) |
| 51 : pTag(it.pTag), | 57 : pTag(it.pTag), |
| 52 pParent(it.pParent), | 58 pParent(it.pParent), |
| 53 dwIDHash(it.dwIDHash), | 59 dwIDHash(it.dwIDHash), |
| 54 dwTagHash(it.dwTagHash), | 60 dwTagHash(it.dwTagHash), |
| 55 iClassIndex(0), | 61 iClassIndex(0), |
| 56 dwClassHashs(1) { | 62 dwClassHashs(1) { |
| 57 if (it.dwClassHashs.GetSize() > 0) { | 63 if (it.dwClassHashs.GetSize() > 0) |
| 58 dwClassHashs.Copy(it.dwClassHashs); | 64 dwClassHashs.Copy(it.dwClassHashs); |
| 59 } | |
| 60 } | 65 } |
| 61 void CFDE_CSSAccelerator::OnEnterTag(IFDE_CSSTagProvider* pTag) { | 66 |
| 67 void CFDE_CSSAccelerator::OnEnterTag(CXFA_CSSTagProvider* pTag) { |
| 62 FDE_CSSTagCache* pTop = GetTopElement(); | 68 FDE_CSSTagCache* pTop = GetTopElement(); |
| 63 FDE_CSSTagCache item(pTop, pTag); | 69 FDE_CSSTagCache item(pTop, pTag); |
| 64 m_Stack.Push(item); | 70 m_Stack.Push(item); |
| 65 } | 71 } |
| 66 void CFDE_CSSAccelerator::OnLeaveTag(IFDE_CSSTagProvider* pTag) { | 72 |
| 73 void CFDE_CSSAccelerator::OnLeaveTag(CXFA_CSSTagProvider* pTag) { |
| 67 FXSYS_assert(m_Stack.GetTopElement()); | 74 FXSYS_assert(m_Stack.GetTopElement()); |
| 68 FXSYS_assert(m_Stack.GetTopElement()->GetTag() == pTag); | 75 FXSYS_assert(m_Stack.GetTopElement()->GetTag() == pTag); |
| 69 m_Stack.Pop(); | 76 m_Stack.Pop(); |
| 70 } | 77 } |
| OLD | NEW |