TEST_F(CFDE_CSSStyleSheetTest, ParseChildSelectors) { const FX_WCHAR* buf = L"a b c { border: 10px; }"; EXPECT_TRUE(sheet_->LoadBuffer(buf, FXSYS_wcslen(buf))); EXPECT_EQ(1, sheet_->CountRules()); CFDE_CSSStyleRule* style = sheet_->GetRule(0); EXPECT_EQ(1UL, style->CountSelectorLists()); auto sel = style->GetSelectorList(0); EXPECT_TRUE(sel != nullptr); EXPECT_EQ(FX_HashCode_GetW(L"c", true), sel->GetNameHash()); sel = sel->GetNextSelector(); EXPECT_TRUE(sel != nullptr); EXPECT_EQ(FX_HashCode_GetW(L"b", true), sel->GetNameHash()); sel = sel->GetNextSelector(); EXPECT_TRUE(sel != nullptr); EXPECT_EQ(FX_HashCode_GetW(L"a", true), sel->GetNameHash()); sel = sel->GetNextSelector(); EXPECT_TRUE(sel == nullptr); decl_ = style->GetDeclaration(); EXPECT_EQ(4UL, decl_->PropertyCountForTesting()); VerifyFloat(FDE_CSSProperty::BorderLeftWidth, 10.0, FDE_CSSNumberType::Pixels); VerifyFloat(FDE_CSSProperty::BorderRightWidth, 10.0, FDE_CSSNumberType::Pixels); VerifyFloat(FDE_CSSProperty::BorderTopWidth, 10.0, FDE_CSSNumberType::Pixels); VerifyFloat(FDE_CSSProperty::BorderBottomWidth, 10.0, FDE_CSSNumberType::Pixels); }
TEST_F(CFDE_CSSStyleSheetTest, ParseMultipleSelectors) { const FX_WCHAR* buf = L"a { border: 10px; }\nb { text-decoration: underline; }"; EXPECT_TRUE(sheet_->LoadBuffer(buf, FXSYS_wcslen(buf))); EXPECT_EQ(2, sheet_->CountRules()); CFDE_CSSStyleRule* style = sheet_->GetRule(0); EXPECT_EQ(1UL, style->CountSelectorLists()); bool found_selector = false; uint32_t hash = FX_HashCode_GetW(L"a", true); for (size_t i = 0; i < style->CountSelectorLists(); i++) { if (style->GetSelectorList(i)->GetNameHash() == hash) { found_selector = true; break; } } EXPECT_TRUE(found_selector); decl_ = style->GetDeclaration(); EXPECT_EQ(4UL, decl_->PropertyCountForTesting()); VerifyFloat(FDE_CSSProperty::BorderLeftWidth, 10.0, FDE_CSSNumberType::Pixels); VerifyFloat(FDE_CSSProperty::BorderRightWidth, 10.0, FDE_CSSNumberType::Pixels); VerifyFloat(FDE_CSSProperty::BorderTopWidth, 10.0, FDE_CSSNumberType::Pixels); VerifyFloat(FDE_CSSProperty::BorderBottomWidth, 10.0, FDE_CSSNumberType::Pixels); style = sheet_->GetRule(1); EXPECT_EQ(1UL, style->CountSelectorLists()); found_selector = false; hash = FX_HashCode_GetW(L"b", true); for (size_t i = 0; i < style->CountSelectorLists(); i++) { if (style->GetSelectorList(i)->GetNameHash() == hash) { found_selector = true; break; } } EXPECT_TRUE(found_selector); decl_ = style->GetDeclaration(); EXPECT_EQ(1UL, decl_->PropertyCountForTesting()); VerifyList(FDE_CSSProperty::TextDecoration, {FDE_CSSPropertyValue::Underline}); }
CFDE_CSSSelector::CFDE_CSSSelector(FDE_CSSSELECTORTYPE eType, const FX_WCHAR* psz, int32_t iLen, bool bIgnoreCase) : m_eType(eType), m_dwHash(FX_HashCode_GetW(CFX_WideStringC(psz, iLen), bIgnoreCase)), m_pNext(nullptr) {}
CXFA_Node* CXFA_NodeList::NamedItem(const CFX_WideStringC& wsName) { uint32_t dwHashCode = FX_HashCode_GetW(wsName, false); int32_t iCount = GetLength(); for (int32_t i = 0; i < iCount; i++) { CXFA_Node* ret = Item(i); if (dwHashCode == ret->GetNameHash()) return ret; } return nullptr; }
void CXFA_ScriptContext::GlobalPropertyGetter(CFXJSE_Value* pObject, const CFX_ByteStringC& szPropName, CFXJSE_Value* pValue) { CXFA_Object* pOriginalObject = ToObject(pObject, nullptr); CXFA_Document* pDoc = pOriginalObject->GetDocument(); CXFA_ScriptContext* lpScriptContext = pDoc->GetScriptContext(); CXFA_Object* lpCurNode = lpScriptContext->GetVariablesThis(pOriginalObject); CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); if (lpScriptContext->GetType() == XFA_SCRIPTLANGTYPE_Formcalc) { if (szPropName == kFormCalcRuntime) { lpScriptContext->m_FM2JSContext->GlobalPropertyGetter(pValue); return; } XFA_HashCode uHashCode = static_cast<XFA_HashCode>( FX_HashCode_GetW(wsPropName.AsStringC(), false)); if (uHashCode != XFA_HASHCODE_Layout) { CXFA_Object* pObj = lpScriptContext->GetDocument()->GetXFAObject(uHashCode); if (pObj) { pValue->Assign(lpScriptContext->GetJSValueFromMap(pObj)); return; } } } uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Attributes; CXFA_Node* pRefNode = ToNode(lpScriptContext->GetThisObject()); if (pOriginalObject->IsVariablesThis()) { pRefNode = ToNode(lpCurNode); } if (lpScriptContext->QueryNodeByFlag(pRefNode, wsPropName.AsStringC(), pValue, dwFlag, FALSE)) { return; } dwFlag = XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings; if (lpScriptContext->QueryNodeByFlag(pRefNode, wsPropName.AsStringC(), pValue, dwFlag, FALSE)) { return; } CXFA_Object* pScriptObject = lpScriptContext->GetVariablesThis(pOriginalObject, TRUE); if (pScriptObject && lpScriptContext->QueryVariableValue(pScriptObject->AsNode(), szPropName, pValue, TRUE)) { return; } CXFA_FFNotify* pNotify = pDoc->GetNotify(); if (!pNotify) { return; } pNotify->GetDocProvider()->GetGlobalProperty(pNotify->GetHDOC(), szPropName, pValue); }
CXFA_Node* CXFA_NodeHelper::ResolveNodes_GetOneChild(CXFA_Node* parent, const FX_WCHAR* pwsName, FX_BOOL bIsClassName) { if (!parent) { return nullptr; } CXFA_NodeArray siblings; uint32_t uNameHash = FX_HashCode_GetW(CFX_WideStringC(pwsName), false); NodeAcc_TraverseAnySiblings(parent, uNameHash, &siblings, bIsClassName); if (siblings.GetSize() == 0) { return nullptr; } return siblings[0]; }
const CFX_CSSData::Property* CFX_CSSData::GetPropertyByName( WideStringView name) { if (name.IsEmpty()) return nullptr; uint32_t hash = FX_HashCode_GetW(name, true); auto* result = std::lower_bound(std::begin(propertyTable), std::end(propertyTable), hash, [](const CFX_CSSData::Property& iter, const uint32_t& hash) { return iter.dwHash < hash; }); if (result != std::end(propertyTable) && result->dwHash == hash) return result; return nullptr; }
bool CXFA_FMCallExpression::IsBuildInFunc(CFX_WideTextBuf* funcName) { uint32_t uHash = FX_HashCode_GetW(funcName->AsStringC(), true); const XFA_FMBuildInFunc* pEnd = g_BuildInFuncs + FX_ArraySize(g_BuildInFuncs); const XFA_FMBuildInFunc* pFunc = std::lower_bound(g_BuildInFuncs, pEnd, uHash, [](const XFA_FMBuildInFunc& func, uint32_t hash) { return func.m_uHash < hash; }); if (pFunc < pEnd && uHash == pFunc->m_uHash) { funcName->Clear(); *funcName << pFunc->m_buildinfunc; return true; } return false; }
void LoadAndVerifyDecl(const FX_WCHAR* buf, const std::vector<CFX_WideString>& selectors, size_t decl_count) { ASSERT(sheet_); EXPECT_TRUE(sheet_->LoadBuffer(buf, FXSYS_wcslen(buf))); EXPECT_EQ(sheet_->CountRules(), 1); CFDE_CSSStyleRule* style = sheet_->GetRule(0); EXPECT_EQ(selectors.size(), style->CountSelectorLists()); for (size_t i = 0; i < selectors.size(); i++) { uint32_t hash = FX_HashCode_GetW(selectors[i].AsStringC(), true); EXPECT_EQ(hash, style->GetSelectorList(i)->GetNameHash()); } decl_ = style->GetDeclaration(); EXPECT_EQ(decl_->PropertyCountForTesting(), decl_count); }
uint32_t CXFA_FMCallExpression::IsMethodWithObjParam( const CFX_WideStringC& methodName) { uint32_t uHash = FX_HashCode_GetW(methodName, false); XFA_FMSOMMethod somMethodWithObjPara; uint32_t parameters = 0x00; int32_t iStart = 0, iEnd = (sizeof(gs_FMSomMethods) / sizeof(gs_FMSomMethods[0])) - 1; int32_t iMid = (iStart + iEnd) / 2; do { iMid = (iStart + iEnd) / 2; somMethodWithObjPara = gs_FMSomMethods[iMid]; if (uHash == somMethodWithObjPara.m_uHash) { parameters = somMethodWithObjPara.m_dParameters; break; } else if (uHash < somMethodWithObjPara.m_uHash) { iEnd = iMid - 1; } else { iStart = iMid + 1; } } while (iStart <= iEnd); return parameters; }
void CXFA_FFDocView::RunBindItems() { for (int32_t i = 0; i < m_BindItems.GetSize(); i++) { if (m_BindItems[i]->HasRemovedChildren()) continue; CXFA_Node* pWidgetNode = m_BindItems[i]->GetNodeItem(XFA_NODEITEM_Parent); CXFA_WidgetAcc* pAcc = static_cast<CXFA_WidgetAcc*>(pWidgetNode->GetWidgetData()); if (!pAcc) continue; CXFA_BindItems binditems(m_BindItems[i]); CXFA_ScriptContext* pScriptContext = pWidgetNode->GetDocument()->GetScriptContext(); CFX_WideStringC wsRef; binditems.GetRef(wsRef); uint32_t dwStyle = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_ALL; XFA_RESOLVENODE_RS rs; pScriptContext->ResolveObjects(pWidgetNode, wsRef, rs, dwStyle); int32_t iCount = rs.nodes.GetSize(); pAcc->DeleteItem(-1); if (rs.dwFlags != XFA_RESOVENODE_RSTYPE_Nodes || iCount < 1) continue; CFX_WideStringC wsValueRef, wsLabelRef; binditems.GetValueRef(wsValueRef); binditems.GetLabelRef(wsLabelRef); const bool bUseValue = wsLabelRef.IsEmpty() || wsLabelRef == wsValueRef; const bool bLabelUseContent = wsLabelRef.IsEmpty() || wsLabelRef == FX_WSTRC(L"$"); const bool bValueUseContent = wsValueRef.IsEmpty() || wsValueRef == FX_WSTRC(L"$"); CFX_WideString wsValue; CFX_WideString wsLabel; uint32_t uValueHash = FX_HashCode_GetW(wsValueRef, false); for (int32_t j = 0; j < iCount; j++) { CXFA_Object* refObj = rs.nodes[j]; if (!refObj->IsNode()) { continue; } CXFA_Node* refNode = refObj->AsNode(); if (bValueUseContent) { wsValue = refNode->GetContent(); } else { CXFA_Node* nodeValue = refNode->GetFirstChildByName(uValueHash); wsValue = nodeValue ? nodeValue->GetContent() : refNode->GetContent(); } if (!bUseValue) { if (bLabelUseContent) { wsLabel = refNode->GetContent(); } else { CXFA_Node* nodeLabel = refNode->GetFirstChildByName(wsLabelRef); if (nodeLabel) wsLabel = nodeLabel->GetContent(); } } else { wsLabel = wsValue; } pAcc->InsertItem(wsLabel, wsValue); } } m_BindItems.RemoveAll(); }