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 "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 FXSYS_assert(pTag); |
|
Tom Sepez
2016/04/21 20:21:56
not needed, given line 38
dsinclair
2016/04/21 20:46:34
Done.
| |
| 31 CFX_WideStringC wsValue, wsName = pTag->GetTagName(); | 33 |
| 32 dwTagHash = FX_HashCode_String_GetW(wsName.c_str(), wsName.GetLength(), TRUE); | 34 static const uint32_t s_dwIDHash = FX_HashCode_String_GetW(L"id", 2, TRUE); |
| 33 FX_POSITION pos = pTag->GetFirstAttribute(); | 35 static const uint32_t s_dwClassHash = |
| 34 while (pos != NULL) { | 36 FX_HashCode_String_GetW(L"class", 5, TRUE); |
| 35 pTag->GetNextAttribute(pos, wsName, wsValue); | 37 |
| 38 CFX_WideString wsTag = pTag->GetTagName(); | |
| 39 dwTagHash = FX_HashCode_String_GetW(wsTag.c_str(), wsTag.GetLength(), TRUE); | |
| 40 | |
| 41 for (auto it : *pTag) { | |
| 42 CFX_WideString wsValue = it.first; | |
| 43 CFX_WideString wsName = it.second; | |
| 44 | |
| 36 uint32_t dwNameHash = | 45 uint32_t dwNameHash = |
| 37 FX_HashCode_String_GetW(wsName.c_str(), wsName.GetLength(), TRUE); | 46 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); | 47 |
| 39 static const uint32_t s_dwClassHash = | |
| 40 FX_HashCode_String_GetW(L"class", 5, TRUE); | |
| 41 if (dwNameHash == s_dwClassHash) { | 48 if (dwNameHash == s_dwClassHash) { |
| 42 uint32_t dwHash = | 49 uint32_t dwHash = |
| 43 FX_HashCode_String_GetW(wsValue.c_str(), wsValue.GetLength()); | 50 FX_HashCode_String_GetW(wsValue.c_str(), wsValue.GetLength()); |
| 44 dwClassHashs.Add(dwHash); | 51 dwClassHashs.Add(dwHash); |
| 45 } else if (dwNameHash == s_dwIDHash) { | 52 } else if (dwNameHash == s_dwIDHash) { |
| 46 dwIDHash = FX_HashCode_String_GetW(wsValue.c_str(), wsValue.GetLength()); | 53 dwIDHash = FX_HashCode_String_GetW(wsValue.c_str(), wsValue.GetLength()); |
| 47 } | 54 } |
| 48 } | 55 } |
| 49 } | 56 } |
| 57 | |
| 50 FDE_CSSTagCache::FDE_CSSTagCache(const FDE_CSSTagCache& it) | 58 FDE_CSSTagCache::FDE_CSSTagCache(const FDE_CSSTagCache& it) |
| 51 : pTag(it.pTag), | 59 : pTag(it.pTag), |
| 52 pParent(it.pParent), | 60 pParent(it.pParent), |
| 53 dwIDHash(it.dwIDHash), | 61 dwIDHash(it.dwIDHash), |
| 54 dwTagHash(it.dwTagHash), | 62 dwTagHash(it.dwTagHash), |
| 55 iClassIndex(0), | 63 iClassIndex(0), |
| 56 dwClassHashs(1) { | 64 dwClassHashs(1) { |
| 57 if (it.dwClassHashs.GetSize() > 0) { | 65 if (it.dwClassHashs.GetSize() > 0) |
| 58 dwClassHashs.Copy(it.dwClassHashs); | 66 dwClassHashs.Copy(it.dwClassHashs); |
| 59 } | |
| 60 } | 67 } |
| 61 void CFDE_CSSAccelerator::OnEnterTag(IFDE_CSSTagProvider* pTag) { | 68 |
| 69 void CFDE_CSSAccelerator::OnEnterTag(CXFA_CSSTagProvider* pTag) { | |
| 62 FDE_CSSTagCache* pTop = GetTopElement(); | 70 FDE_CSSTagCache* pTop = GetTopElement(); |
| 63 FDE_CSSTagCache item(pTop, pTag); | 71 FDE_CSSTagCache item(pTop, pTag); |
| 64 m_Stack.Push(item); | 72 m_Stack.Push(item); |
| 65 } | 73 } |
| 66 void CFDE_CSSAccelerator::OnLeaveTag(IFDE_CSSTagProvider* pTag) { | 74 |
| 75 void CFDE_CSSAccelerator::OnLeaveTag(CXFA_CSSTagProvider* pTag) { | |
| 67 FXSYS_assert(m_Stack.GetTopElement()); | 76 FXSYS_assert(m_Stack.GetTopElement()); |
| 68 FXSYS_assert(m_Stack.GetTopElement()->GetTag() == pTag); | 77 FXSYS_assert(m_Stack.GetTopElement()->GetTag() == pTag); |
| 69 m_Stack.Pop(); | 78 m_Stack.Pop(); |
| 70 } | 79 } |
| OLD | NEW |