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

Side by Side Diff: xfa/src/fde/css/fde_cssdeclaration.cpp

Issue 1803723002: Move xfa/src up to xfa/. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Rebase to master Created 4 years, 9 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 | « xfa/src/fde/css/fde_cssdeclaration.h ('k') | xfa/src/fde/css/fde_cssstyleselector.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7 #include "xfa/src/fde/css/fde_cssdeclaration.h"
8
9 #include "core/include/fxcrt/fx_ext.h"
10 #include "xfa/src/fgas/crt/fgas_system.h"
11
12 IFDE_CSSValue* CFDE_CSSDeclaration::GetProperty(FDE_CSSPROPERTY eProperty,
13 FX_BOOL& bImportant) const {
14 for (const FDE_CSSPropertyHolder* pHolder = m_pFirstProperty; pHolder;
15 pHolder = pHolder->pNext) {
16 if (pHolder->eProperty == eProperty) {
17 bImportant = pHolder->bImportant;
18 return pHolder->pValue;
19 }
20 }
21 return NULL;
22 }
23 FX_POSITION CFDE_CSSDeclaration::GetStartPosition() const {
24 return (FX_POSITION)m_pFirstProperty;
25 }
26 void CFDE_CSSDeclaration::GetNextProperty(FX_POSITION& pos,
27 FDE_CSSPROPERTY& eProperty,
28 IFDE_CSSValue*& pValue,
29 FX_BOOL& bImportant) const {
30 const FDE_CSSPropertyHolder* pHolder = (const FDE_CSSPropertyHolder*)pos;
31 FXSYS_assert(pHolder != NULL);
32 bImportant = pHolder->bImportant;
33 eProperty = (FDE_CSSPROPERTY)pHolder->eProperty;
34 pValue = pHolder->pValue;
35 pos = (FX_POSITION)pHolder->pNext;
36 }
37 FX_POSITION CFDE_CSSDeclaration::GetStartCustom() const {
38 return (FX_POSITION)m_pFirstCustom;
39 }
40 void CFDE_CSSDeclaration::GetNextCustom(FX_POSITION& pos,
41 CFX_WideString& wsName,
42 CFX_WideString& wsValue) const {
43 const FDE_CSSCustomProperty* pProperty = (const FDE_CSSCustomProperty*)pos;
44 if (pProperty == NULL) {
45 return;
46 }
47 wsName = pProperty->pwsName;
48 wsValue = pProperty->pwsValue;
49 pos = (FX_POSITION)pProperty->pNext;
50 }
51 const FX_WCHAR* CFDE_CSSDeclaration::CopyToLocal(
52 const FDE_CSSPROPERTYARGS* pArgs,
53 const FX_WCHAR* pszValue,
54 int32_t iValueLen) {
55 FXSYS_assert(iValueLen > 0);
56 CFX_MapPtrToPtr* pCache = pArgs->pStringCache;
57 void* pKey = NULL;
58 if (pCache) {
59 void* pszCached = NULL;
60 pKey =
61 (void*)(uintptr_t)FX_HashCode_String_GetW(pszValue, iValueLen, FALSE);
62 if (pCache->Lookup(pKey, pszCached)) {
63 return (const FX_WCHAR*)pszCached;
64 }
65 }
66 FX_WCHAR* psz =
67 (FX_WCHAR*)pArgs->pStaticStore->Alloc((iValueLen + 1) * sizeof(FX_WCHAR));
68 if (psz == NULL) {
69 return NULL;
70 }
71 FXSYS_wcsncpy(psz, pszValue, iValueLen);
72 psz[iValueLen] = '\0';
73 if (pCache) {
74 pCache->SetAt(pKey, psz);
75 }
76 return psz;
77 }
78 IFDE_CSSPrimitiveValue* CFDE_CSSDeclaration::NewNumberValue(
79 IFX_MEMAllocator* pStaticStore,
80 FDE_CSSPRIMITIVETYPE eUnit,
81 FX_FLOAT fValue) const {
82 static CFDE_CSSPrimitiveValue s_ZeroValue(FDE_CSSPRIMITIVETYPE_Number, 0.0f);
83 if (eUnit == FDE_CSSPRIMITIVETYPE_Number && FXSYS_fabs(fValue) < 0.001f) {
84 return &s_ZeroValue;
85 }
86 return FXTARGET_NewWith(pStaticStore) CFDE_CSSPrimitiveValue(eUnit, fValue);
87 }
88 inline IFDE_CSSPrimitiveValue* CFDE_CSSDeclaration::NewEnumValue(
89 IFX_MEMAllocator* pStaticStore,
90 FDE_CSSPROPERTYVALUE eValue) const {
91 return FXTARGET_NewWith(pStaticStore) CFDE_CSSPrimitiveValue(eValue);
92 }
93 void CFDE_CSSDeclaration::AddPropertyHolder(IFX_MEMAllocator* pStaticStore,
94 FDE_CSSPROPERTY eProperty,
95 IFDE_CSSValue* pValue,
96 FX_BOOL bImportant) {
97 FDE_CSSPropertyHolder* pHolder =
98 FXTARGET_NewWith(pStaticStore) FDE_CSSPropertyHolder;
99 pHolder->bImportant = bImportant;
100 pHolder->eProperty = eProperty;
101 pHolder->pValue = pValue;
102 pHolder->pNext = NULL;
103 if (m_pLastProperty == NULL) {
104 m_pLastProperty = m_pFirstProperty = pHolder;
105 } else {
106 m_pLastProperty->pNext = pHolder;
107 m_pLastProperty = pHolder;
108 }
109 }
110 FX_BOOL CFDE_CSSDeclaration::AddProperty(const FDE_CSSPROPERTYARGS* pArgs,
111 const FX_WCHAR* pszValue,
112 int32_t iValueLen) {
113 FXSYS_assert(iValueLen > 0);
114 FX_BOOL bImportant = FALSE;
115 if (iValueLen >= 10 && pszValue[iValueLen - 10] == '!' &&
116 FX_wcsnicmp(L"important", pszValue + iValueLen - 9, 9) == 0) {
117 if ((iValueLen -= 10) == 0) {
118 return FALSE;
119 }
120 bImportant = TRUE;
121 }
122 const FX_DWORD dwType = pArgs->pProperty->dwType;
123 switch (dwType & 0x0F) {
124 case FDE_CSSVALUETYPE_Primitive: {
125 static const FX_DWORD g_ValueGuessOrder[] = {
126 FDE_CSSVALUETYPE_MaybeNumber, FDE_CSSVALUETYPE_MaybeEnum,
127 FDE_CSSVALUETYPE_MaybeColor, FDE_CSSVALUETYPE_MaybeURI,
128 FDE_CSSVALUETYPE_MaybeFunction, FDE_CSSVALUETYPE_MaybeString,
129 };
130 static const int32_t g_ValueGuessCount =
131 sizeof(g_ValueGuessOrder) / sizeof(FX_DWORD);
132 for (int32_t i = 0; i < g_ValueGuessCount; ++i) {
133 const FX_DWORD dwMatch = dwType & g_ValueGuessOrder[i];
134 if (dwMatch == 0) {
135 continue;
136 }
137 IFDE_CSSValue* pCSSValue = NULL;
138 switch (dwMatch) {
139 case FDE_CSSVALUETYPE_MaybeFunction:
140 pCSSValue = ParseFunction(pArgs, pszValue, iValueLen);
141 break;
142 case FDE_CSSVALUETYPE_MaybeNumber:
143 pCSSValue = ParseNumber(pArgs, pszValue, iValueLen);
144 break;
145 case FDE_CSSVALUETYPE_MaybeEnum:
146 pCSSValue = ParseEnum(pArgs, pszValue, iValueLen);
147 break;
148 case FDE_CSSVALUETYPE_MaybeColor:
149 pCSSValue = ParseColor(pArgs, pszValue, iValueLen);
150 break;
151 case FDE_CSSVALUETYPE_MaybeURI:
152 pCSSValue = ParseURI(pArgs, pszValue, iValueLen);
153 break;
154 case FDE_CSSVALUETYPE_MaybeString:
155 pCSSValue = ParseString(pArgs, pszValue, iValueLen);
156 break;
157 default:
158 break;
159 }
160 if (pCSSValue != NULL) {
161 AddPropertyHolder(pArgs->pStaticStore, pArgs->pProperty->eName,
162 pCSSValue, bImportant);
163 return TRUE;
164 }
165 if (FDE_IsOnlyValue(dwType, g_ValueGuessOrder[i])) {
166 return FALSE;
167 }
168 }
169 } break;
170 case FDE_CSSVALUETYPE_Shorthand: {
171 IFX_MEMAllocator* pStaticStore = pArgs->pStaticStore;
172 IFDE_CSSValue *pColor, *pStyle, *pWidth;
173 switch (pArgs->pProperty->eName) {
174 case FDE_CSSPROPERTY_Font:
175 return ParseFontProperty(pArgs, pszValue, iValueLen, bImportant);
176 case FDE_CSSPROPERTY_Background:
177 return ParseBackgroundProperty(pArgs, pszValue, iValueLen,
178 bImportant);
179 case FDE_CSSPROPERTY_ListStyle:
180 return ParseListStyleProperty(pArgs, pszValue, iValueLen, bImportant);
181 case FDE_CSSPROPERTY_Border:
182 if (ParseBorderPropoerty(pStaticStore, pszValue, iValueLen, pColor,
183 pStyle, pWidth)) {
184 AddBorderProperty(pStaticStore, pColor, pStyle, pWidth, bImportant,
185 FDE_CSSPROPERTY_BorderLeftColor,
186 FDE_CSSPROPERTY_BorderLeftStyle,
187 FDE_CSSPROPERTY_BorderLeftWidth);
188 AddBorderProperty(pStaticStore, pColor, pStyle, pWidth, bImportant,
189 FDE_CSSPROPERTY_BorderTopColor,
190 FDE_CSSPROPERTY_BorderTopStyle,
191 FDE_CSSPROPERTY_BorderTopWidth);
192 AddBorderProperty(pStaticStore, pColor, pStyle, pWidth, bImportant,
193 FDE_CSSPROPERTY_BorderRightColor,
194 FDE_CSSPROPERTY_BorderRightStyle,
195 FDE_CSSPROPERTY_BorderRightWidth);
196 AddBorderProperty(pStaticStore, pColor, pStyle, pWidth, bImportant,
197 FDE_CSSPROPERTY_BorderBottomColor,
198 FDE_CSSPROPERTY_BorderBottomStyle,
199 FDE_CSSPROPERTY_BorderBottomWidth);
200 return TRUE;
201 }
202 break;
203 case FDE_CSSPROPERTY_BorderLeft:
204 if (ParseBorderPropoerty(pStaticStore, pszValue, iValueLen, pColor,
205 pStyle, pWidth)) {
206 AddBorderProperty(pStaticStore, pColor, pStyle, pWidth, bImportant,
207 FDE_CSSPROPERTY_BorderLeftColor,
208 FDE_CSSPROPERTY_BorderLeftStyle,
209 FDE_CSSPROPERTY_BorderLeftWidth);
210 return TRUE;
211 }
212 break;
213 case FDE_CSSPROPERTY_BorderTop:
214 if (ParseBorderPropoerty(pStaticStore, pszValue, iValueLen, pColor,
215 pStyle, pWidth)) {
216 AddBorderProperty(pStaticStore, pColor, pStyle, pWidth, bImportant,
217 FDE_CSSPROPERTY_BorderTopColor,
218 FDE_CSSPROPERTY_BorderTopStyle,
219 FDE_CSSPROPERTY_BorderTopWidth);
220 return TRUE;
221 }
222 break;
223 case FDE_CSSPROPERTY_BorderRight:
224 if (ParseBorderPropoerty(pStaticStore, pszValue, iValueLen, pColor,
225 pStyle, pWidth)) {
226 AddBorderProperty(pStaticStore, pColor, pStyle, pWidth, bImportant,
227 FDE_CSSPROPERTY_BorderRightColor,
228 FDE_CSSPROPERTY_BorderRightStyle,
229 FDE_CSSPROPERTY_BorderRightWidth);
230 return TRUE;
231 }
232 break;
233 case FDE_CSSPROPERTY_BorderBottom:
234 if (ParseBorderPropoerty(pStaticStore, pszValue, iValueLen, pColor,
235 pStyle, pWidth)) {
236 AddBorderProperty(pStaticStore, pColor, pStyle, pWidth, bImportant,
237 FDE_CSSPROPERTY_BorderBottomColor,
238 FDE_CSSPROPERTY_BorderBottomStyle,
239 FDE_CSSPROPERTY_BorderBottomWidth);
240 return TRUE;
241 }
242 break;
243 case FDE_CSSPROPERTY_Overflow:
244 return ParseOverflowProperty(pArgs, pszValue, iValueLen, bImportant);
245 case FDE_CSSPROPERTY_ColumnRule:
246 return ParseColumnRuleProperty(pArgs, pszValue, iValueLen,
247 bImportant);
248 default:
249 break;
250 }
251 } break;
252 case FDE_CSSVALUETYPE_List:
253 switch (pArgs->pProperty->eName) {
254 case FDE_CSSPROPERTY_CounterIncrement:
255 case FDE_CSSPROPERTY_CounterReset:
256 return ParseCounterProperty(pArgs, pszValue, iValueLen, bImportant);
257 case FDE_CSSPROPERTY_Content:
258 return ParseContentProperty(pArgs, pszValue, iValueLen, bImportant);
259 default:
260 return ParseValueListProperty(pArgs, pszValue, iValueLen, bImportant);
261 }
262 default:
263 FXSYS_assert(FALSE);
264 break;
265 }
266 return FALSE;
267 }
268 FX_BOOL CFDE_CSSDeclaration::AddProperty(const FDE_CSSPROPERTYARGS* pArgs,
269 const FX_WCHAR* pszName,
270 int32_t iNameLen,
271 const FX_WCHAR* pszValue,
272 int32_t iValueLen) {
273 FDE_CSSCustomProperty* pProperty =
274 FXTARGET_NewWith(pArgs->pStaticStore) FDE_CSSCustomProperty;
275 pProperty->pwsName = CopyToLocal(pArgs, pszName, iNameLen);
276 pProperty->pwsValue = CopyToLocal(pArgs, pszValue, iValueLen);
277 pProperty->pNext = NULL;
278 if (m_pLastCustom == NULL) {
279 m_pLastCustom = m_pFirstCustom = pProperty;
280 } else {
281 m_pLastCustom->pNext = pProperty;
282 m_pLastCustom = pProperty;
283 }
284 return TRUE;
285 }
286 IFDE_CSSValue* CFDE_CSSDeclaration::ParseNumber(
287 const FDE_CSSPROPERTYARGS* pArgs,
288 const FX_WCHAR* pszValue,
289 int32_t iValueLen) {
290 FX_FLOAT fValue;
291 FDE_CSSPRIMITIVETYPE eUnit;
292 if (!FDE_ParseCSSNumber(pszValue, iValueLen, fValue, eUnit)) {
293 return NULL;
294 }
295 return NewNumberValue(pArgs->pStaticStore, eUnit, fValue);
296 }
297 IFDE_CSSValue* CFDE_CSSDeclaration::ParseEnum(const FDE_CSSPROPERTYARGS* pArgs,
298 const FX_WCHAR* pszValue,
299 int32_t iValueLen) {
300 const FDE_CSSPROPERTYVALUETABLE* pValue =
301 FDE_GetCSSPropertyValueByName(pszValue, iValueLen);
302 return pValue ? NewEnumValue(pArgs->pStaticStore, pValue->eName) : NULL;
303 }
304 IFDE_CSSValue* CFDE_CSSDeclaration::ParseColor(const FDE_CSSPROPERTYARGS* pArgs,
305 const FX_WCHAR* pszValue,
306 int32_t iValueLen) {
307 FX_ARGB dwColor;
308 if (!FDE_ParseCSSColor(pszValue, iValueLen, dwColor)) {
309 return NULL;
310 }
311 return FXTARGET_NewWith(pArgs->pStaticStore) CFDE_CSSPrimitiveValue(dwColor);
312 }
313 IFDE_CSSValue* CFDE_CSSDeclaration::ParseURI(const FDE_CSSPROPERTYARGS* pArgs,
314 const FX_WCHAR* pszValue,
315 int32_t iValueLen) {
316 int32_t iOffset;
317 if (!FDE_ParseCSSURI(pszValue, iValueLen, iOffset, iValueLen)) {
318 return NULL;
319 }
320 if (iValueLen <= 0) {
321 return NULL;
322 }
323 pszValue = CopyToLocal(pArgs, pszValue + iOffset, iValueLen);
324 return pszValue
325 ? FXTARGET_NewWith(pArgs->pStaticStore)
326 CFDE_CSSPrimitiveValue(FDE_CSSPRIMITIVETYPE_URI, pszValue)
327 : NULL;
328 }
329 IFDE_CSSValue* CFDE_CSSDeclaration::ParseString(
330 const FDE_CSSPROPERTYARGS* pArgs,
331 const FX_WCHAR* pszValue,
332 int32_t iValueLen) {
333 int32_t iOffset;
334 if (!FDE_ParseCSSString(pszValue, iValueLen, iOffset, iValueLen)) {
335 return NULL;
336 }
337 if (iValueLen <= 0) {
338 return NULL;
339 }
340 pszValue = CopyToLocal(pArgs, pszValue + iOffset, iValueLen);
341 return pszValue
342 ? FXTARGET_NewWith(pArgs->pStaticStore)
343 CFDE_CSSPrimitiveValue(FDE_CSSPRIMITIVETYPE_String, pszValue)
344 : NULL;
345 }
346 IFDE_CSSValue* CFDE_CSSDeclaration::ParseFunction(
347 const FDE_CSSPROPERTYARGS* pArgs,
348 const FX_WCHAR* pszValue,
349 int32_t iValueLen) {
350 if (pszValue[iValueLen - 1] != ')') {
351 return NULL;
352 }
353 int32_t iStartBracket = 0;
354 while (pszValue[iStartBracket] != '(') {
355 if (iStartBracket < iValueLen) {
356 iStartBracket++;
357 } else {
358 return NULL;
359 }
360 }
361 if (iStartBracket == 0) {
362 return NULL;
363 }
364 const FX_WCHAR* pszFuncName = CopyToLocal(pArgs, pszValue, iStartBracket);
365 pszValue += (iStartBracket + 1);
366 iValueLen -= (iStartBracket + 2);
367 CFDE_CSSValueArray argumentArr;
368 CFDE_CSSValueListParser parser(pszValue, iValueLen, ',');
369 FDE_CSSPRIMITIVETYPE ePrimitiveType;
370 while (parser.NextValue(ePrimitiveType, pszValue, iValueLen)) {
371 switch (ePrimitiveType) {
372 case FDE_CSSPRIMITIVETYPE_String: {
373 const FDE_CSSPROPERTYVALUETABLE* pPropertyValue =
374 FDE_GetCSSPropertyValueByName(pszValue, iValueLen);
375 if (pPropertyValue != NULL) {
376 argumentArr.Add(
377 NewEnumValue(pArgs->pStaticStore, pPropertyValue->eName));
378 continue;
379 }
380 IFDE_CSSValue* pFunctionValue =
381 ParseFunction(pArgs, pszValue, iValueLen);
382 if (pFunctionValue != NULL) {
383 argumentArr.Add(pFunctionValue);
384 continue;
385 }
386 argumentArr.Add(FXTARGET_NewWith(pArgs->pStaticStore)
387 CFDE_CSSPrimitiveValue(
388 FDE_CSSPRIMITIVETYPE_String,
389 CopyToLocal(pArgs, pszValue, iValueLen)));
390 } break;
391 case FDE_CSSPRIMITIVETYPE_Number: {
392 FX_FLOAT fValue;
393 if (FDE_ParseCSSNumber(pszValue, iValueLen, fValue, ePrimitiveType)) {
394 argumentArr.Add(
395 NewNumberValue(pArgs->pStaticStore, ePrimitiveType, fValue));
396 }
397 } break;
398 default:
399 argumentArr.Add(FXTARGET_NewWith(pArgs->pStaticStore)
400 CFDE_CSSPrimitiveValue(
401 FDE_CSSPRIMITIVETYPE_String,
402 CopyToLocal(pArgs, pszValue, iValueLen)));
403 break;
404 }
405 }
406 IFDE_CSSValueList* pArgumentList = FXTARGET_NewWith(pArgs->pStaticStore)
407 CFDE_CSSValueList(pArgs->pStaticStore, argumentArr);
408 CFDE_CSSFunction* pFunction = FXTARGET_NewWith(pArgs->pStaticStore)
409 CFDE_CSSFunction(pszFuncName, pArgumentList);
410 return FXTARGET_NewWith(pArgs->pStaticStore)
411 CFDE_CSSPrimitiveValue(pFunction);
412 }
413 FX_BOOL CFDE_CSSDeclaration::ParseContentProperty(
414 const FDE_CSSPROPERTYARGS* pArgs,
415 const FX_WCHAR* pszValue,
416 int32_t iValueLen,
417 FX_BOOL bImportant) {
418 IFX_MEMAllocator* pStaticStore = (IFX_MEMAllocator*)pArgs->pStaticStore;
419 CFDE_CSSValueListParser parser(pszValue, iValueLen, ' ');
420 FDE_CSSPRIMITIVETYPE eType;
421 CFDE_CSSValueArray list;
422 while (parser.NextValue(eType, pszValue, iValueLen)) {
423 switch (eType) {
424 case FDE_CSSPRIMITIVETYPE_URI:
425 list.Add(FXTARGET_NewWith(pStaticStore) CFDE_CSSPrimitiveValue(
426 eType, CopyToLocal(pArgs, pszValue, iValueLen)));
427 break;
428 case FDE_CSSPRIMITIVETYPE_Number:
429 return FALSE;
430 case FDE_CSSPRIMITIVETYPE_String: {
431 const FDE_CSSPROPERTYVALUETABLE* pValue =
432 FDE_GetCSSPropertyValueByName(pszValue, iValueLen);
433 if (pValue != NULL) {
434 switch (pValue->eName) {
435 case FDE_CSSPROPERTYVALUE_Normal:
436 case FDE_CSSPROPERTYVALUE_None: {
437 if (list.GetSize() == 0) {
438 list.Add(NewEnumValue(pStaticStore, pValue->eName));
439 } else {
440 return FALSE;
441 }
442 } break;
443 case FDE_CSSPROPERTYVALUE_OpenQuote:
444 case FDE_CSSPROPERTYVALUE_CloseQuote:
445 case FDE_CSSPROPERTYVALUE_NoOpenQuote:
446 case FDE_CSSPROPERTYVALUE_NoCloseQuote:
447 list.Add(NewEnumValue(pStaticStore, pValue->eName));
448 break;
449 default:
450 return FALSE;
451 }
452 continue;
453 }
454 IFDE_CSSValue* pFunction = ParseFunction(pArgs, pszValue, iValueLen);
455 if (pFunction != NULL) {
456 list.Add(pFunction);
457 continue;
458 }
459 list.Add(FXTARGET_NewWith(pStaticStore) CFDE_CSSPrimitiveValue(
460 eType, CopyToLocal(pArgs, pszValue, iValueLen)));
461 } break;
462 case FDE_CSSPRIMITIVETYPE_RGB:
463 return FALSE;
464 default:
465 break;
466 }
467 }
468 if (list.GetSize() == 0) {
469 return FALSE;
470 }
471 AddPropertyHolder(pStaticStore, pArgs->pProperty->eName,
472 FXTARGET_NewWith(pStaticStore)
473 CFDE_CSSValueList(pStaticStore, list),
474 bImportant);
475 return TRUE;
476 }
477 FX_BOOL CFDE_CSSDeclaration::ParseCounterProperty(
478 const FDE_CSSPROPERTYARGS* pArgs,
479 const FX_WCHAR* pszValue,
480 int32_t iValueLen,
481 FX_BOOL bImportant) {
482 IFX_MEMAllocator* pStaticStore = pArgs->pStaticStore;
483 CFDE_CSSValueListParser parser(pszValue, iValueLen, ' ');
484 CFDE_CSSValueArray list;
485 CFDE_CSSValueArray listFull;
486 FDE_CSSPRIMITIVETYPE eType;
487 while (parser.NextValue(eType, pszValue, iValueLen)) {
488 switch (eType) {
489 case FDE_CSSPRIMITIVETYPE_Number: {
490 FX_FLOAT fValue;
491 if (FDE_ParseCSSNumber(pszValue, iValueLen, fValue, eType)) {
492 if (list.GetSize() == 1) {
493 list.Add(NewNumberValue(pStaticStore, eType, fValue));
494 listFull.Add(FXTARGET_NewWith(pStaticStore)
495 CFDE_CSSValueList(pStaticStore, list));
496 list.RemoveAll();
497 } else {
498 return FALSE;
499 }
500 }
501 } break;
502 case FDE_CSSPRIMITIVETYPE_String: {
503 if (list.GetSize() == 0) {
504 pszValue = CopyToLocal(pArgs, pszValue, iValueLen);
505 list.Add(FXTARGET_NewWith(pStaticStore) CFDE_CSSPrimitiveValue(
506 FDE_CSSPRIMITIVETYPE_String, pszValue));
507 } else {
508 listFull.Add(FXTARGET_NewWith(pStaticStore)
509 CFDE_CSSValueList(pStaticStore, list));
510 list.RemoveAll();
511 pszValue = CopyToLocal(pArgs, pszValue, iValueLen);
512 list.Add(FXTARGET_NewWith(pStaticStore) CFDE_CSSPrimitiveValue(
513 FDE_CSSPRIMITIVETYPE_String, pszValue));
514 }
515 } break;
516 default:
517 break;
518 }
519 }
520 if (list.GetSize() == 1) {
521 listFull.Add(FXTARGET_NewWith(pStaticStore)
522 CFDE_CSSValueList(pStaticStore, list));
523 }
524 if (listFull.GetSize() == 0) {
525 return FALSE;
526 }
527 AddPropertyHolder(pStaticStore, pArgs->pProperty->eName,
528 FXTARGET_NewWith(pStaticStore)
529 CFDE_CSSValueList(pStaticStore, listFull),
530 bImportant);
531 return TRUE;
532 }
533 FX_BOOL CFDE_CSSDeclaration::ParseValueListProperty(
534 const FDE_CSSPROPERTYARGS* pArgs,
535 const FX_WCHAR* pszValue,
536 int32_t iValueLen,
537 FX_BOOL bImportant) {
538 IFX_MEMAllocator* pStaticStore = pArgs->pStaticStore;
539 FX_WCHAR separator =
540 (pArgs->pProperty->eName == FDE_CSSPROPERTY_FontFamily) ? ',' : ' ';
541 CFDE_CSSValueListParser parser(pszValue, iValueLen, separator);
542 const FX_DWORD dwType = pArgs->pProperty->dwType;
543 FDE_CSSPRIMITIVETYPE eType;
544 CFDE_CSSValueArray list;
545 while (parser.NextValue(eType, pszValue, iValueLen)) {
546 switch (eType) {
547 case FDE_CSSPRIMITIVETYPE_Number:
548 if (dwType & FDE_CSSVALUETYPE_MaybeNumber) {
549 FX_FLOAT fValue;
550 if (FDE_ParseCSSNumber(pszValue, iValueLen, fValue, eType)) {
551 list.Add(NewNumberValue(pStaticStore, eType, fValue));
552 }
553 }
554 break;
555 case FDE_CSSPRIMITIVETYPE_String:
556 if (dwType & FDE_CSSVALUETYPE_MaybeColor) {
557 FX_ARGB dwColor;
558 if (FDE_ParseCSSColor(pszValue, iValueLen, dwColor)) {
559 list.Add(FXTARGET_NewWith(pStaticStore)
560 CFDE_CSSPrimitiveValue(dwColor));
561 continue;
562 }
563 }
564 if (dwType & FDE_CSSVALUETYPE_MaybeEnum) {
565 const FDE_CSSPROPERTYVALUETABLE* pValue =
566 FDE_GetCSSPropertyValueByName(pszValue, iValueLen);
567 if (pValue != NULL) {
568 list.Add(NewEnumValue(pStaticStore, pValue->eName));
569 continue;
570 }
571 }
572 if (dwType & FDE_CSSVALUETYPE_MaybeString) {
573 pszValue = CopyToLocal(pArgs, pszValue, iValueLen);
574 list.Add(FXTARGET_NewWith(pStaticStore) CFDE_CSSPrimitiveValue(
575 FDE_CSSPRIMITIVETYPE_String, pszValue));
576 }
577 break;
578 case FDE_CSSPRIMITIVETYPE_RGB:
579 if (dwType & FDE_CSSVALUETYPE_MaybeColor) {
580 FX_ARGB dwColor;
581 if (FDE_ParseCSSColor(pszValue, iValueLen, dwColor)) {
582 list.Add(FXTARGET_NewWith(pStaticStore)
583 CFDE_CSSPrimitiveValue(dwColor));
584 }
585 }
586 break;
587 default:
588 break;
589 }
590 }
591 if (list.GetSize() == 0) {
592 return FALSE;
593 }
594 switch (pArgs->pProperty->eName) {
595 case FDE_CSSPROPERTY_BorderColor:
596 return Add4ValuesProperty(
597 pStaticStore, list, bImportant, FDE_CSSPROPERTY_BorderLeftColor,
598 FDE_CSSPROPERTY_BorderTopColor, FDE_CSSPROPERTY_BorderRightColor,
599 FDE_CSSPROPERTY_BorderBottomColor);
600 case FDE_CSSPROPERTY_BorderStyle:
601 return Add4ValuesProperty(
602 pStaticStore, list, bImportant, FDE_CSSPROPERTY_BorderLeftStyle,
603 FDE_CSSPROPERTY_BorderTopStyle, FDE_CSSPROPERTY_BorderRightStyle,
604 FDE_CSSPROPERTY_BorderBottomStyle);
605 case FDE_CSSPROPERTY_BorderWidth:
606 return Add4ValuesProperty(
607 pStaticStore, list, bImportant, FDE_CSSPROPERTY_BorderLeftWidth,
608 FDE_CSSPROPERTY_BorderTopWidth, FDE_CSSPROPERTY_BorderRightWidth,
609 FDE_CSSPROPERTY_BorderBottomWidth);
610 case FDE_CSSPROPERTY_Margin:
611 return Add4ValuesProperty(
612 pStaticStore, list, bImportant, FDE_CSSPROPERTY_MarginLeft,
613 FDE_CSSPROPERTY_MarginTop, FDE_CSSPROPERTY_MarginRight,
614 FDE_CSSPROPERTY_MarginBottom);
615 case FDE_CSSPROPERTY_Padding:
616 return Add4ValuesProperty(
617 pStaticStore, list, bImportant, FDE_CSSPROPERTY_PaddingLeft,
618 FDE_CSSPROPERTY_PaddingTop, FDE_CSSPROPERTY_PaddingRight,
619 FDE_CSSPROPERTY_PaddingBottom);
620 default: {
621 CFDE_CSSValueList* pList =
622 FXTARGET_NewWith(pStaticStore) CFDE_CSSValueList(pStaticStore, list);
623 AddPropertyHolder(pStaticStore, pArgs->pProperty->eName, pList,
624 bImportant);
625 return TRUE;
626 } break;
627 }
628 return FALSE;
629 }
630 FX_BOOL CFDE_CSSDeclaration::Add4ValuesProperty(IFX_MEMAllocator* pStaticStore,
631 const CFDE_CSSValueArray& list,
632 FX_BOOL bImportant,
633 FDE_CSSPROPERTY eLeft,
634 FDE_CSSPROPERTY eTop,
635 FDE_CSSPROPERTY eRight,
636 FDE_CSSPROPERTY eBottom) {
637 switch (list.GetSize()) {
638 case 1:
639 AddPropertyHolder(pStaticStore, eLeft, list[0], bImportant);
640 AddPropertyHolder(pStaticStore, eTop, list[0], bImportant);
641 AddPropertyHolder(pStaticStore, eRight, list[0], bImportant);
642 AddPropertyHolder(pStaticStore, eBottom, list[0], bImportant);
643 return TRUE;
644 case 2:
645 AddPropertyHolder(pStaticStore, eLeft, list[1], bImportant);
646 AddPropertyHolder(pStaticStore, eTop, list[0], bImportant);
647 AddPropertyHolder(pStaticStore, eRight, list[1], bImportant);
648 AddPropertyHolder(pStaticStore, eBottom, list[0], bImportant);
649 return TRUE;
650 case 3:
651 AddPropertyHolder(pStaticStore, eLeft, list[1], bImportant);
652 AddPropertyHolder(pStaticStore, eTop, list[0], bImportant);
653 AddPropertyHolder(pStaticStore, eRight, list[1], bImportant);
654 AddPropertyHolder(pStaticStore, eBottom, list[2], bImportant);
655 return TRUE;
656 case 4:
657 AddPropertyHolder(pStaticStore, eLeft, list[3], bImportant);
658 AddPropertyHolder(pStaticStore, eTop, list[0], bImportant);
659 AddPropertyHolder(pStaticStore, eRight, list[1], bImportant);
660 AddPropertyHolder(pStaticStore, eBottom, list[2], bImportant);
661 return TRUE;
662 default:
663 break;
664 }
665 return FALSE;
666 }
667 FX_BOOL CFDE_CSSDeclaration::ParseBorderPropoerty(
668 IFX_MEMAllocator* pStaticStore,
669 const FX_WCHAR* pszValue,
670 int32_t iValueLen,
671 IFDE_CSSValue*& pColor,
672 IFDE_CSSValue*& pStyle,
673 IFDE_CSSValue*& pWidth) const {
674 pColor = pStyle = pWidth = NULL;
675 CFDE_CSSValueListParser parser(pszValue, iValueLen, ' ');
676 FDE_CSSPRIMITIVETYPE eType;
677 while (parser.NextValue(eType, pszValue, iValueLen)) {
678 switch (eType) {
679 case FDE_CSSPRIMITIVETYPE_Number:
680 if (pWidth == NULL) {
681 FX_FLOAT fValue;
682 if (FDE_ParseCSSNumber(pszValue, iValueLen, fValue, eType)) {
683 pWidth = NewNumberValue(pStaticStore, eType, fValue);
684 }
685 }
686 break;
687 case FDE_CSSPRIMITIVETYPE_RGB:
688 if (pColor == NULL) {
689 FX_ARGB dwColor;
690 if (FDE_ParseCSSColor(pszValue, iValueLen, dwColor)) {
691 pColor =
692 FXTARGET_NewWith(pStaticStore) CFDE_CSSPrimitiveValue(dwColor);
693 }
694 }
695 break;
696 case FDE_CSSPRIMITIVETYPE_String: {
697 const FDE_CSSCOLORTABLE* pColorItem =
698 FDE_GetCSSColorByName(pszValue, iValueLen);
699 if (pColorItem != NULL) {
700 if (pColor == NULL) {
701 pColor = FXTARGET_NewWith(pStaticStore)
702 CFDE_CSSPrimitiveValue(pColorItem->dwValue);
703 }
704 continue;
705 }
706 const FDE_CSSPROPERTYVALUETABLE* pValue =
707 FDE_GetCSSPropertyValueByName(pszValue, iValueLen);
708 if (pValue == NULL) {
709 continue;
710 }
711 switch (pValue->eName) {
712 case FDE_CSSPROPERTYVALUE_Transparent:
713 if (pColor == NULL) {
714 pColor = FXTARGET_NewWith(pStaticStore)
715 CFDE_CSSPrimitiveValue((FX_ARGB)0);
716 }
717 break;
718 case FDE_CSSPROPERTYVALUE_Thin:
719 case FDE_CSSPROPERTYVALUE_Thick:
720 case FDE_CSSPROPERTYVALUE_Medium:
721 if (pWidth == NULL) {
722 pWidth = NewEnumValue(pStaticStore, pValue->eName);
723 }
724 break;
725 case FDE_CSSPROPERTYVALUE_None:
726 case FDE_CSSPROPERTYVALUE_Hidden:
727 case FDE_CSSPROPERTYVALUE_Dotted:
728 case FDE_CSSPROPERTYVALUE_Dashed:
729 case FDE_CSSPROPERTYVALUE_Solid:
730 case FDE_CSSPROPERTYVALUE_Double:
731 case FDE_CSSPROPERTYVALUE_Groove:
732 case FDE_CSSPROPERTYVALUE_Ridge:
733 case FDE_CSSPROPERTYVALUE_Inset:
734 case FDE_CSSPROPERTYVALUE_Outset:
735 if (pStyle == NULL) {
736 pStyle = NewEnumValue(pStaticStore, pValue->eName);
737 }
738 break;
739 default:
740 break;
741 }
742 }; break;
743 default:
744 break;
745 }
746 }
747 if (pColor == NULL) {
748 pColor = FXTARGET_NewWith(pStaticStore) CFDE_CSSPrimitiveValue((FX_ARGB)0);
749 }
750 if (pStyle == NULL) {
751 pStyle = NewEnumValue(pStaticStore, FDE_CSSPROPERTYVALUE_None);
752 }
753 if (pWidth == NULL) {
754 pWidth = NewNumberValue(pStaticStore, FDE_CSSPRIMITIVETYPE_Number, 0.0f);
755 }
756 return TRUE;
757 }
758 void CFDE_CSSDeclaration::AddBorderProperty(IFX_MEMAllocator* pStaticStore,
759 IFDE_CSSValue* pColor,
760 IFDE_CSSValue* pStyle,
761 IFDE_CSSValue* pWidth,
762 FX_BOOL bImportant,
763 FDE_CSSPROPERTY eColor,
764 FDE_CSSPROPERTY eStyle,
765 FDE_CSSPROPERTY eWidth) {
766 AddPropertyHolder(pStaticStore, eStyle, pStyle, bImportant);
767 AddPropertyHolder(pStaticStore, eWidth, pWidth, bImportant);
768 AddPropertyHolder(pStaticStore, eColor, pColor, bImportant);
769 }
770 FX_BOOL CFDE_CSSDeclaration::ParseListStyleProperty(
771 const FDE_CSSPROPERTYARGS* pArgs,
772 const FX_WCHAR* pszValue,
773 int32_t iValueLen,
774 FX_BOOL bImportant) {
775 IFX_MEMAllocator* pStaticStore = pArgs->pStaticStore;
776 CFDE_CSSValueListParser parser(pszValue, iValueLen, ' ');
777 IFDE_CSSPrimitiveValue *pType = NULL, *pImage = NULL, *pPosition = NULL;
778 FDE_CSSPRIMITIVETYPE eType;
779 while (parser.NextValue(eType, pszValue, iValueLen)) {
780 switch (eType) {
781 case FDE_CSSPRIMITIVETYPE_URI:
782 if (pImage == NULL) {
783 pImage = FXTARGET_NewWith(pStaticStore) CFDE_CSSPrimitiveValue(
784 eType, CopyToLocal(pArgs, pszValue, iValueLen));
785 }
786 break;
787 case FDE_CSSPRIMITIVETYPE_String: {
788 const FDE_CSSPROPERTYVALUETABLE* pValue =
789 FDE_GetCSSPropertyValueByName(pszValue, iValueLen);
790 if (pValue == NULL) {
791 break;
792 }
793 switch (pValue->eName) {
794 case FDE_CSSPROPERTYVALUE_None:
795 if (pImage == NULL) {
796 pImage = NewEnumValue(pStaticStore, pValue->eName);
797 } else if (pType == NULL) {
798 pImage = NewEnumValue(pStaticStore, pValue->eName);
799 }
800 break;
801 case FDE_CSSPROPERTYVALUE_Inside:
802 case FDE_CSSPROPERTYVALUE_Outside:
803 if (pPosition == NULL) {
804 pPosition = NewEnumValue(pStaticStore, pValue->eName);
805 }
806 break;
807 case FDE_CSSPROPERTYVALUE_Disc:
808 case FDE_CSSPROPERTYVALUE_Circle:
809 case FDE_CSSPROPERTYVALUE_Square:
810 case FDE_CSSPROPERTYVALUE_Decimal:
811 case FDE_CSSPROPERTYVALUE_DecimalLeadingZero:
812 case FDE_CSSPROPERTYVALUE_LowerRoman:
813 case FDE_CSSPROPERTYVALUE_UpperRoman:
814 case FDE_CSSPROPERTYVALUE_LowerGreek:
815 case FDE_CSSPROPERTYVALUE_LowerLatin:
816 case FDE_CSSPROPERTYVALUE_UpperLatin:
817 case FDE_CSSPROPERTYVALUE_Armenian:
818 case FDE_CSSPROPERTYVALUE_Georgian:
819 case FDE_CSSPROPERTYVALUE_LowerAlpha:
820 case FDE_CSSPROPERTYVALUE_UpperAlpha:
821 if (pType == NULL) {
822 pType = NewEnumValue(pStaticStore, pValue->eName);
823 }
824 break;
825 default:
826 break;
827 }
828 }; break;
829 default:
830 break;
831 }
832 }
833 if (pPosition == NULL) {
834 pPosition = NewEnumValue(pStaticStore, FDE_CSSPROPERTYVALUE_Outside);
835 }
836 if (pImage == NULL) {
837 pImage = NewEnumValue(pStaticStore, FDE_CSSPROPERTYVALUE_None);
838 }
839 if (pType == NULL) {
840 pType = NewEnumValue(pStaticStore, FDE_CSSPROPERTYVALUE_None);
841 }
842 AddPropertyHolder(pStaticStore, FDE_CSSPROPERTY_ListStylePosition, pPosition,
843 bImportant);
844 AddPropertyHolder(pStaticStore, FDE_CSSPROPERTY_ListStyleImage, pImage,
845 bImportant);
846 AddPropertyHolder(pStaticStore, FDE_CSSPROPERTY_ListStyleType, pType,
847 bImportant);
848 return TRUE;
849 }
850 FX_BOOL CFDE_CSSDeclaration::ParseBackgroundProperty(
851 const FDE_CSSPROPERTYARGS* pArgs,
852 const FX_WCHAR* pszValue,
853 int32_t iValueLen,
854 FX_BOOL bImportant) {
855 IFX_MEMAllocator* pStaticStore = pArgs->pStaticStore;
856 CFDE_CSSValueListParser parser(pszValue, iValueLen, ' ');
857 IFDE_CSSPrimitiveValue *pColor = NULL, *pImage = NULL, *pRepeat = NULL;
858 IFDE_CSSPrimitiveValue *pPosX = NULL, *pPosY = NULL, *pAttachment = NULL;
859 FDE_CSSPRIMITIVETYPE eType;
860 while (parser.NextValue(eType, pszValue, iValueLen)) {
861 switch (eType) {
862 case FDE_CSSPRIMITIVETYPE_URI:
863 if (pImage == NULL) {
864 pImage = FXTARGET_NewWith(pStaticStore) CFDE_CSSPrimitiveValue(
865 eType, CopyToLocal(pArgs, pszValue, iValueLen));
866 }
867 break;
868 case FDE_CSSPRIMITIVETYPE_Number: {
869 FX_FLOAT fValue;
870 if (!FDE_ParseCSSNumber(pszValue, iValueLen, fValue, eType)) {
871 break;
872 }
873 if (pPosX == NULL) {
874 pPosX = NewNumberValue(pStaticStore, eType, fValue);
875 } else if (pPosY == NULL) {
876 pPosY = NewNumberValue(pStaticStore, eType, fValue);
877 }
878 } break;
879 case FDE_CSSPRIMITIVETYPE_String: {
880 const FDE_CSSPROPERTYVALUETABLE* pValue =
881 FDE_GetCSSPropertyValueByName(pszValue, iValueLen);
882 if (pValue != NULL) {
883 switch (pValue->eName) {
884 case FDE_CSSPROPERTYVALUE_None:
885 if (pImage == NULL) {
886 pImage = NewEnumValue(pStaticStore, pValue->eName);
887 }
888 break;
889 case FDE_CSSPROPERTYVALUE_Transparent:
890 if (pColor == NULL) {
891 pColor = FXTARGET_NewWith(pStaticStore)
892 CFDE_CSSPrimitiveValue((FX_ARGB)0);
893 }
894 break;
895 case FDE_CSSPROPERTYVALUE_Fixed:
896 case FDE_CSSPROPERTYVALUE_Scroll:
897 if (pAttachment == NULL) {
898 pAttachment = NewEnumValue(pStaticStore, pValue->eName);
899 }
900 break;
901 case FDE_CSSPROPERTYVALUE_Repeat:
902 case FDE_CSSPROPERTYVALUE_RepeatX:
903 case FDE_CSSPROPERTYVALUE_RepeatY:
904 case FDE_CSSPROPERTYVALUE_NoRepeat:
905 if (pRepeat == NULL) {
906 pRepeat = NewEnumValue(pStaticStore, pValue->eName);
907 }
908 break;
909 case FDE_CSSPROPERTYVALUE_Left:
910 case FDE_CSSPROPERTYVALUE_Right:
911 if (pPosX == NULL) {
912 pPosX = NewEnumValue(pStaticStore, pValue->eName);
913 }
914 break;
915 case FDE_CSSPROPERTYVALUE_Top:
916 case FDE_CSSPROPERTYVALUE_Bottom:
917 if (pPosY == NULL) {
918 pPosX = NewEnumValue(pStaticStore, pValue->eName);
919 }
920 break;
921 case FDE_CSSPROPERTYVALUE_Center:
922 if (pPosX == NULL) {
923 pPosX = NewEnumValue(pStaticStore, pValue->eName);
924 } else if (pPosY == NULL) {
925 pPosX = NewEnumValue(pStaticStore, pValue->eName);
926 }
927 break;
928 default:
929 break;
930 }
931 break;
932 }
933 const FDE_CSSCOLORTABLE* pColorItem =
934 FDE_GetCSSColorByName(pszValue, iValueLen);
935 if (pColorItem != NULL) {
936 if (pColor == NULL) {
937 pColor = FXTARGET_NewWith(pStaticStore)
938 CFDE_CSSPrimitiveValue(pColorItem->dwValue);
939 }
940 }
941 } break;
942 case FDE_CSSPRIMITIVETYPE_RGB:
943 if (pColor == NULL) {
944 FX_ARGB dwColor;
945 if (FDE_ParseCSSColor(pszValue, iValueLen, dwColor)) {
946 pColor =
947 FXTARGET_NewWith(pStaticStore) CFDE_CSSPrimitiveValue(dwColor);
948 }
949 }
950 break;
951 default:
952 break;
953 }
954 }
955 if (pColor == NULL) {
956 pColor = FXTARGET_NewWith(pStaticStore) CFDE_CSSPrimitiveValue((FX_ARGB)0);
957 }
958 if (pImage == NULL) {
959 pImage = NewEnumValue(pStaticStore, FDE_CSSPROPERTYVALUE_None);
960 }
961 if (pRepeat == NULL) {
962 pRepeat = NewEnumValue(pStaticStore, FDE_CSSPROPERTYVALUE_Repeat);
963 }
964 if (pAttachment == NULL) {
965 pAttachment = NewEnumValue(pStaticStore, FDE_CSSPROPERTYVALUE_Scroll);
966 }
967 if (pPosX == NULL) {
968 pPosX = NewNumberValue(pStaticStore, FDE_CSSPRIMITIVETYPE_Number, 0.0f);
969 pPosY = NewNumberValue(pStaticStore, FDE_CSSPRIMITIVETYPE_Number, 0.0f);
970 } else if (pPosY == NULL) {
971 pPosY = NewNumberValue(pStaticStore, FDE_CSSPRIMITIVETYPE_Number, 0.0f);
972 }
973 CFDE_CSSValueArray position;
974 position.Add(pPosX);
975 position.Add(pPosY);
976 CFDE_CSSValueList* pPosList =
977 FXTARGET_NewWith(pStaticStore) CFDE_CSSValueList(pStaticStore, position);
978 AddPropertyHolder(pStaticStore, FDE_CSSPROPERTY_BackgroundColor, pColor,
979 bImportant);
980 AddPropertyHolder(pStaticStore, FDE_CSSPROPERTY_BackgroundImage, pImage,
981 bImportant);
982 AddPropertyHolder(pStaticStore, FDE_CSSPROPERTY_BackgroundRepeat, pRepeat,
983 bImportant);
984 AddPropertyHolder(pStaticStore, FDE_CSSPROPERTY_BackgroundPosition, pPosList,
985 bImportant);
986 AddPropertyHolder(pStaticStore, FDE_CSSPROPERTY_BackgroundAttachment,
987 pAttachment, bImportant);
988 return TRUE;
989 }
990 FX_BOOL CFDE_CSSDeclaration::ParseFontProperty(const FDE_CSSPROPERTYARGS* pArgs,
991 const FX_WCHAR* pszValue,
992 int32_t iValueLen,
993 FX_BOOL bImportant) {
994 IFX_MEMAllocator* pStaticStore = pArgs->pStaticStore;
995 CFDE_CSSValueListParser parser(pszValue, iValueLen, '/');
996 IFDE_CSSPrimitiveValue *pStyle = NULL, *pVariant = NULL, *pWeight = NULL;
997 IFDE_CSSPrimitiveValue *pFontSize = NULL, *pLineHeight = NULL;
998 CFDE_CSSValueArray familyList;
999 FDE_CSSPRIMITIVETYPE eType;
1000 while (parser.NextValue(eType, pszValue, iValueLen)) {
1001 switch (eType) {
1002 case FDE_CSSPRIMITIVETYPE_String: {
1003 const FDE_CSSPROPERTYVALUETABLE* pValue =
1004 FDE_GetCSSPropertyValueByName(pszValue, iValueLen);
1005 if (pValue != NULL) {
1006 switch (pValue->eName) {
1007 case FDE_CSSPROPERTYVALUE_XxSmall:
1008 case FDE_CSSPROPERTYVALUE_XSmall:
1009 case FDE_CSSPROPERTYVALUE_Small:
1010 case FDE_CSSPROPERTYVALUE_Medium:
1011 case FDE_CSSPROPERTYVALUE_Large:
1012 case FDE_CSSPROPERTYVALUE_XLarge:
1013 case FDE_CSSPROPERTYVALUE_XxLarge:
1014 case FDE_CSSPROPERTYVALUE_Smaller:
1015 case FDE_CSSPROPERTYVALUE_Larger:
1016 if (pFontSize == NULL) {
1017 pFontSize = NewEnumValue(pStaticStore, pValue->eName);
1018 }
1019 continue;
1020 case FDE_CSSPROPERTYVALUE_Bold:
1021 case FDE_CSSPROPERTYVALUE_Bolder:
1022 case FDE_CSSPROPERTYVALUE_Lighter:
1023 if (pWeight == NULL) {
1024 pWeight = NewEnumValue(pStaticStore, pValue->eName);
1025 }
1026 continue;
1027 case FDE_CSSPROPERTYVALUE_Italic:
1028 case FDE_CSSPROPERTYVALUE_Oblique:
1029 if (pStyle == NULL) {
1030 pStyle = NewEnumValue(pStaticStore, pValue->eName);
1031 }
1032 continue;
1033 case FDE_CSSPROPERTYVALUE_SmallCaps:
1034 if (pVariant == NULL) {
1035 pVariant = NewEnumValue(pStaticStore, pValue->eName);
1036 }
1037 continue;
1038 case FDE_CSSPROPERTYVALUE_Normal:
1039 if (pStyle == NULL) {
1040 pStyle = NewEnumValue(pStaticStore, pValue->eName);
1041 } else if (pVariant == NULL) {
1042 pVariant = NewEnumValue(pStaticStore, pValue->eName);
1043 } else if (pWeight == NULL) {
1044 pWeight = NewEnumValue(pStaticStore, pValue->eName);
1045 } else if (pFontSize == NULL) {
1046 pFontSize = NewEnumValue(pStaticStore, pValue->eName);
1047 } else if (pLineHeight == NULL) {
1048 pLineHeight = NewEnumValue(pStaticStore, pValue->eName);
1049 }
1050 continue;
1051 default:
1052 break;
1053 }
1054 }
1055 if (pFontSize != NULL) {
1056 familyList.Add(FXTARGET_NewWith(pStaticStore) CFDE_CSSPrimitiveValue(
1057 eType, CopyToLocal(pArgs, pszValue, iValueLen)));
1058 }
1059 parser.m_Separator = ',';
1060 } break;
1061 case FDE_CSSPRIMITIVETYPE_Number: {
1062 FX_FLOAT fValue;
1063 if (!FDE_ParseCSSNumber(pszValue, iValueLen, fValue, eType)) {
1064 break;
1065 }
1066 if (eType == FDE_CSSPRIMITIVETYPE_Number) {
1067 switch ((int32_t)fValue) {
1068 case 100:
1069 case 200:
1070 case 300:
1071 case 400:
1072 case 500:
1073 case 600:
1074 case 700:
1075 case 800:
1076 case 900:
1077 if (pWeight == NULL) {
1078 pWeight = NewNumberValue(pStaticStore,
1079 FDE_CSSPRIMITIVETYPE_Number, fValue);
1080 }
1081 continue;
1082 }
1083 }
1084 if (pFontSize == NULL) {
1085 pFontSize = NewNumberValue(pStaticStore, eType, fValue);
1086 } else if (pLineHeight == NULL) {
1087 pLineHeight = NewNumberValue(pStaticStore, eType, fValue);
1088 }
1089 } break;
1090 default:
1091 break;
1092 }
1093 }
1094 if (pStyle == NULL) {
1095 pStyle = NewEnumValue(pStaticStore, FDE_CSSPROPERTYVALUE_Normal);
1096 }
1097 if (pVariant == NULL) {
1098 pVariant = NewEnumValue(pStaticStore, FDE_CSSPROPERTYVALUE_Normal);
1099 }
1100 if (pWeight == NULL) {
1101 pWeight = NewEnumValue(pStaticStore, FDE_CSSPROPERTYVALUE_Normal);
1102 }
1103 if (pFontSize == NULL) {
1104 pFontSize = NewEnumValue(pStaticStore, FDE_CSSPROPERTYVALUE_Medium);
1105 }
1106 if (pLineHeight == NULL) {
1107 pLineHeight = NewEnumValue(pStaticStore, FDE_CSSPROPERTYVALUE_Normal);
1108 }
1109 AddPropertyHolder(pStaticStore, FDE_CSSPROPERTY_FontStyle, pStyle,
1110 bImportant);
1111 AddPropertyHolder(pStaticStore, FDE_CSSPROPERTY_FontVariant, pVariant,
1112 bImportant);
1113 AddPropertyHolder(pStaticStore, FDE_CSSPROPERTY_FontWeight, pWeight,
1114 bImportant);
1115 AddPropertyHolder(pStaticStore, FDE_CSSPROPERTY_FontSize, pFontSize,
1116 bImportant);
1117 AddPropertyHolder(pStaticStore, FDE_CSSPROPERTY_LineHeight, pLineHeight,
1118 bImportant);
1119 if (familyList.GetSize() > 0) {
1120 CFDE_CSSValueList* pList = FXTARGET_NewWith(pStaticStore)
1121 CFDE_CSSValueList(pStaticStore, familyList);
1122 AddPropertyHolder(pStaticStore, FDE_CSSPROPERTY_FontFamily, pList,
1123 bImportant);
1124 }
1125 return TRUE;
1126 }
1127 FX_BOOL CFDE_CSSDeclaration::ParseColumnRuleProperty(
1128 const FDE_CSSPROPERTYARGS* pArgs,
1129 const FX_WCHAR* pszValue,
1130 int32_t iValueLen,
1131 FX_BOOL bImportant) {
1132 IFX_MEMAllocator* pStaticStore = pArgs->pStaticStore;
1133 CFDE_CSSValueListParser parser(pszValue, iValueLen, ' ');
1134 IFDE_CSSPrimitiveValue* pColumnRuleWidth = NULL;
1135 IFDE_CSSPrimitiveValue* pColumnRuleStyle = NULL;
1136 IFDE_CSSPrimitiveValue* pColumnRuleColor = NULL;
1137 FDE_CSSPRIMITIVETYPE eType;
1138 while (parser.NextValue(eType, pszValue, iValueLen)) {
1139 switch (eType) {
1140 case FDE_CSSPRIMITIVETYPE_String: {
1141 const FDE_CSSPROPERTYVALUETABLE* pValue =
1142 FDE_GetCSSPropertyValueByName(pszValue, iValueLen);
1143 if (pValue != NULL) {
1144 switch (pValue->eName) {
1145 case FDE_CSSPROPERTYVALUE_None:
1146 case FDE_CSSPROPERTYVALUE_Hidden:
1147 case FDE_CSSPROPERTYVALUE_Dotted:
1148 case FDE_CSSPROPERTYVALUE_Dashed:
1149 case FDE_CSSPROPERTYVALUE_Solid:
1150 case FDE_CSSPROPERTYVALUE_Double:
1151 case FDE_CSSPROPERTYVALUE_Groove:
1152 case FDE_CSSPROPERTYVALUE_Ridge:
1153 case FDE_CSSPROPERTYVALUE_Inset:
1154 case FDE_CSSPROPERTYVALUE_Outset:
1155 if (pColumnRuleStyle == NULL) {
1156 pColumnRuleStyle = NewEnumValue(pStaticStore, pValue->eName);
1157 }
1158 break;
1159 case FDE_CSSPROPERTYVALUE_Transparent:
1160 if (pColumnRuleColor == NULL) {
1161 pColumnRuleColor = NewEnumValue(pStaticStore, pValue->eName);
1162 }
1163 break;
1164 case FDE_CSSPROPERTYVALUE_Thin:
1165 case FDE_CSSPROPERTYVALUE_Medium:
1166 case FDE_CSSPROPERTYVALUE_Thick:
1167 if (pColumnRuleWidth == NULL) {
1168 pColumnRuleWidth = NewEnumValue(pStaticStore, pValue->eName);
1169 }
1170 break;
1171 default:
1172 break;
1173 }
1174 continue;
1175 }
1176 FX_ARGB dwColor;
1177 if (FDE_ParseCSSColor(pszValue, iValueLen, dwColor) &&
1178 pColumnRuleColor == NULL) {
1179 pColumnRuleColor = FXTARGET_NewWith(pStaticStore)
1180 CFDE_CSSPrimitiveValue((FX_ARGB)dwColor);
1181 continue;
1182 }
1183 } break;
1184 case FDE_CSSPRIMITIVETYPE_Number: {
1185 FX_FLOAT fValue;
1186 if (FDE_ParseCSSNumber(pszValue, iValueLen, fValue, eType) &&
1187 pColumnRuleWidth == NULL) {
1188 pColumnRuleWidth = NewNumberValue(pStaticStore, eType, fValue);
1189 }
1190 } break;
1191 case FDE_CSSPRIMITIVETYPE_RGB: {
1192 FX_ARGB dwColor;
1193 if (pColumnRuleColor == NULL &&
1194 FDE_ParseCSSColor(pszValue, iValueLen, dwColor)) {
1195 pColumnRuleColor = FXTARGET_NewWith(pStaticStore)
1196 CFDE_CSSPrimitiveValue((FX_ARGB)dwColor);
1197 }
1198 } break;
1199 default:
1200 break;
1201 }
1202 }
1203 if (pColumnRuleColor == NULL && pColumnRuleStyle == NULL &&
1204 pColumnRuleWidth == NULL) {
1205 return FALSE;
1206 }
1207 if (pColumnRuleStyle == NULL) {
1208 pColumnRuleStyle = NewEnumValue(pStaticStore, FDE_CSSPROPERTYVALUE_None);
1209 }
1210 if (pColumnRuleWidth == NULL) {
1211 pColumnRuleWidth = NewEnumValue(pStaticStore, FDE_CSSPROPERTYVALUE_Medium);
1212 }
1213 if (pColumnRuleColor == NULL) {
1214 pColumnRuleColor =
1215 FXTARGET_NewWith(pStaticStore) CFDE_CSSPrimitiveValue((FX_ARGB)0);
1216 }
1217 AddPropertyHolder(pStaticStore, FDE_CSSPROPERTY_ColumnRuleStyle,
1218 pColumnRuleStyle, bImportant);
1219 AddPropertyHolder(pStaticStore, FDE_CSSPROPERTY_ColumnRuleWidth,
1220 pColumnRuleWidth, bImportant);
1221 AddPropertyHolder(pStaticStore, FDE_CSSPROPERTY_ColumnRuleColor,
1222 pColumnRuleColor, bImportant);
1223 return TRUE;
1224 }
1225 FX_BOOL CFDE_CSSDeclaration::ParseTextEmphasisProperty(
1226 FDE_CSSPROPERTYARGS* pArgs,
1227 const FX_WCHAR* pszValue,
1228 int32_t iValueLen,
1229 FX_BOOL bImportant) {
1230 IFX_MEMAllocator* pStaticStore = pArgs->pStaticStore;
1231 CFDE_CSSValueListParser parser(pszValue, iValueLen, ' ');
1232 CFDE_CSSValueArray arrEmphasisStyle;
1233 FDE_CSSPRIMITIVETYPE eType;
1234 IFDE_CSSPrimitiveValue* pEmphasisColor = NULL;
1235 while (parser.NextValue(eType, pszValue, iValueLen)) {
1236 switch (eType) {
1237 case FDE_CSSPRIMITIVETYPE_String: {
1238 const FDE_CSSPROPERTYVALUETABLE* pValue =
1239 FDE_GetCSSPropertyValueByName(pszValue, iValueLen);
1240 if (pValue != NULL) {
1241 arrEmphasisStyle.Add(NewEnumValue(pStaticStore, pValue->eName));
1242 continue;
1243 }
1244 FX_ARGB dwColor;
1245 if (FDE_ParseCSSColor(pszValue, iValueLen, dwColor)) {
1246 pEmphasisColor =
1247 FXTARGET_NewWith(pStaticStore) CFDE_CSSPrimitiveValue(dwColor);
1248 continue;
1249 }
1250 pszValue = CopyToLocal(pArgs, pszValue, iValueLen);
1251 arrEmphasisStyle.Add(
1252 FXTARGET_NewWith(pStaticStore)
1253 CFDE_CSSPrimitiveValue(FDE_CSSPRIMITIVETYPE_String, pszValue));
1254 } break;
1255 case FDE_CSSPRIMITIVETYPE_RGB: {
1256 FX_ARGB dwColor;
1257 if (FDE_ParseCSSColor(pszValue, iValueLen, dwColor)) {
1258 pEmphasisColor =
1259 FXTARGET_NewWith(pStaticStore) CFDE_CSSPrimitiveValue(dwColor);
1260 }
1261 } break;
1262 default:
1263 break;
1264 }
1265 }
1266 if (arrEmphasisStyle.GetSize() != 0) {
1267 AddPropertyHolder(pStaticStore, FDE_CSSPROPERTY_TextEmphasisStyle,
1268 FXTARGET_NewWith(pStaticStore)
1269 CFDE_CSSValueList(pStaticStore, arrEmphasisStyle),
1270 bImportant);
1271 }
1272 if (pEmphasisColor != NULL) {
1273 AddPropertyHolder(pStaticStore, FDE_CSSPROPERTY_TextEmphasisColor,
1274 pEmphasisColor, bImportant);
1275 }
1276 return TRUE;
1277 }
1278 FX_BOOL CFDE_CSSDeclaration::ParseColumnsProperty(
1279 const FDE_CSSPROPERTYARGS* pArgs,
1280 const FX_WCHAR* pszValue,
1281 int32_t iValueLen,
1282 FX_BOOL bImportant) {
1283 IFX_MEMAllocator* pStaticStore = pArgs->pStaticStore;
1284 CFDE_CSSValueListParser parser(pszValue, iValueLen, ' ');
1285 IFDE_CSSPrimitiveValue* pColumnWidth = NULL;
1286 IFDE_CSSPrimitiveValue* pColumnCount = NULL;
1287 FDE_CSSPRIMITIVETYPE eType;
1288 while (parser.NextValue(eType, pszValue, iValueLen)) {
1289 switch (eType) {
1290 case FDE_CSSPRIMITIVETYPE_String: {
1291 const FDE_CSSPROPERTYVALUETABLE* pValue =
1292 FDE_GetCSSPropertyValueByName(pszValue, iValueLen);
1293 if (pValue == NULL && pValue->eName == FDE_CSSPROPERTYVALUE_Auto) {
1294 pColumnWidth = NewEnumValue(pStaticStore, pValue->eName);
1295 }
1296 } break;
1297 case FDE_CSSPRIMITIVETYPE_Number: {
1298 FX_FLOAT fValue;
1299 if (FDE_ParseCSSNumber(pszValue, iValueLen, fValue, eType)) {
1300 switch (eType) {
1301 case FDE_CSSPRIMITIVETYPE_Number:
1302 if (pColumnCount == NULL) {
1303 pColumnCount = NewNumberValue(pStaticStore, eType, fValue);
1304 }
1305 break;
1306 default:
1307 if (pColumnWidth == NULL) {
1308 pColumnWidth = NewNumberValue(pStaticStore, eType, fValue);
1309 }
1310 break;
1311 }
1312 }
1313 } break;
1314 default:
1315 break;
1316 }
1317 }
1318 if (pColumnWidth == NULL && pColumnCount == NULL) {
1319 return FALSE;
1320 } else if (pColumnWidth == NULL) {
1321 pColumnWidth = NewEnumValue(pStaticStore, FDE_CSSPROPERTYVALUE_Auto);
1322 } else if (pColumnCount == NULL) {
1323 pColumnCount = NewEnumValue(pStaticStore, FDE_CSSPROPERTYVALUE_Auto);
1324 }
1325 AddPropertyHolder(pStaticStore, FDE_CSSPROPERTY_ColumnWidth, pColumnWidth,
1326 bImportant);
1327 AddPropertyHolder(pStaticStore, FDE_CSSPROPERTY_ColumnCount, pColumnCount,
1328 bImportant);
1329 return TRUE;
1330 }
1331 FX_BOOL CFDE_CSSDeclaration::ParseOverflowProperty(
1332 const FDE_CSSPROPERTYARGS* pArgs,
1333 const FX_WCHAR* pszValue,
1334 int32_t iValueLen,
1335 FX_BOOL bImportant) {
1336 IFX_MEMAllocator* pStaticStore = pArgs->pStaticStore;
1337 CFDE_CSSValueListParser parser(pszValue, iValueLen, ' ');
1338 IFDE_CSSPrimitiveValue* pOverflowX = NULL;
1339 IFDE_CSSPrimitiveValue* pOverflowY = NULL;
1340 FDE_CSSPRIMITIVETYPE eType;
1341 while (parser.NextValue(eType, pszValue, iValueLen)) {
1342 if (eType == FDE_CSSPRIMITIVETYPE_String) {
1343 const FDE_CSSPROPERTYVALUETABLE* pValue =
1344 FDE_GetCSSPropertyValueByName(pszValue, iValueLen);
1345 if (pValue != NULL) {
1346 switch (pValue->eName) {
1347 case FDE_CSSOVERFLOW_Visible:
1348 case FDE_CSSOVERFLOW_Hidden:
1349 case FDE_CSSOVERFLOW_Scroll:
1350 case FDE_CSSOVERFLOW_Auto:
1351 case FDE_CSSOVERFLOW_NoDisplay:
1352 case FDE_CSSOVERFLOW_NoContent:
1353 if (pOverflowX != NULL && pOverflowY != NULL) {
1354 return FALSE;
1355 } else if (pOverflowX == NULL) {
1356 pOverflowX = NewEnumValue(pStaticStore, pValue->eName);
1357 } else if (pOverflowY == NULL) {
1358 pOverflowY = NewEnumValue(pStaticStore, pValue->eName);
1359 }
1360 break;
1361 default:
1362 break;
1363 }
1364 }
1365 }
1366 }
1367 if (pOverflowX == NULL && pOverflowY == NULL) {
1368 return FALSE;
1369 } else if (pOverflowY == NULL) {
1370 pOverflowY = NewEnumValue(pStaticStore, pOverflowX->GetEnum());
1371 }
1372 AddPropertyHolder(pStaticStore, FDE_CSSPROPERTY_OverflowX, pOverflowX,
1373 bImportant);
1374 AddPropertyHolder(pStaticStore, FDE_CSSPROPERTY_OverflowY, pOverflowY,
1375 bImportant);
1376 return TRUE;
1377 }
OLDNEW
« no previous file with comments | « xfa/src/fde/css/fde_cssdeclaration.h ('k') | xfa/src/fde/css/fde_cssstyleselector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698