Annotation of Amaya/amaya/XHTMLbuilder.c, revision 1.104
1.1 cvs 1: /*
2: *
1.101 vatton 3: * (c) COPYRIGHT INRIA and W3C, 1996-2004
1.1 cvs 4: * Please first read the full copyright statement in file COPYRIGHT.
5: *
6: */
7:
8: /*
1.30 cvs 9: * XHTMLbuilder.c
1.23 cvs 10: * Builds the corresponding abstract tree for a Thot document of type HTML.
1.1 cvs 11: *
1.20 cvs 12: * Authors: L. Carcone
13: * V. Quint
1.1 cvs 14: */
15:
16: #define THOT_EXPORT extern
17: #include "amaya.h"
18: #include "css.h"
1.2 cvs 19: #include "parser.h"
20: #include "HTML.h"
1.30 cvs 21: #include "fetchHTMLname.h"
1.2 cvs 22:
1.13 cvs 23: #include "css_f.h"
1.76 vatton 24: #include "EDITstyle_f.h"
1.13 cvs 25: #include "fetchXMLname_f.h"
1.30 cvs 26: #include "fetchHTMLname_f.h"
1.22 cvs 27: #include "html2thot_f.h"
1.1 cvs 28: #include "HTMLactions_f.h"
29: #include "HTMLedit_f.h"
1.22 cvs 30: #include "HTMLform_f.h"
1.1 cvs 31: #include "HTMLimage_f.h"
32: #include "HTMLtable_f.h"
33: #include "HTMLimage_f.h"
1.104 ! vatton 34: #include "init_f.h"
1.1 cvs 35: #include "UIcss_f.h"
1.13 cvs 36: #include "styleparser_f.h"
1.2 cvs 37: #include "XHTMLbuilder_f.h"
1.13 cvs 38: #include "Xml2thot_f.h"
1.1 cvs 39:
1.30 cvs 40: #define MaxMsgLength 200
41:
1.47 cvs 42: /* Elements that cannot contain text as immediate children.
43: When some text is present in the HTML file it must be
44: surrounded by a Pseudo_paragraph element */
45: static int NoTextChild[] =
46: {
47: HTML_EL_Document, HTML_EL_HTML, HTML_EL_HEAD, HTML_EL_BODY,
48: HTML_EL_Definition_List, HTML_EL_Block_Quote, HTML_EL_Directory,
49: HTML_EL_Form, HTML_EL_Menu, HTML_EL_FIELDSET,
50: HTML_EL_Numbered_List, HTML_EL_Option_Menu,
51: HTML_EL_Unnumbered_List, HTML_EL_Definition, HTML_EL_List_Item,
52: HTML_EL_MAP, HTML_EL_map, HTML_EL_Applet,
53: HTML_EL_Object, HTML_EL_IFRAME, HTML_EL_NOFRAMES,
54: HTML_EL_Division, HTML_EL_Center, HTML_EL_NOSCRIPT,
55: HTML_EL_Data_cell, HTML_EL_Heading_cell,
56: 0};
57:
1.28 cvs 58: /* Define a pointer to let parser functions access the HTML entity table */
59: extern XmlEntity *pXhtmlEntityTable;
1.6 cvs 60:
1.30 cvs 61: /* maximum size of error messages */
62: #define MaxMsgLength 200
63:
1.6 cvs 64: /*----------------------------------------------------------------------
1.104 ! vatton 65: ParseCharsetAndContentType:
1.6 cvs 66: Parses the element HTTP-EQUIV and looks for the charset value.
67: ----------------------------------------------------------------------*/
1.104 ! vatton 68: void ParseCharsetAndContentType (Element el, Document doc)
1.30 cvs 69:
1.6 cvs 70: {
1.15 cvs 71: AttributeType attrType;
72: Attribute attr;
73: SSchema docSSchema;
74: CHARSET charset;
1.39 cvs 75: char *text, *text2, *ptrText, *str;
76: char charsetname[MAX_LENGTH];
1.15 cvs 77: int length;
1.6 cvs 78: int pos, index = 0;
79:
1.15 cvs 80: charset = TtaGetDocumentCharset (doc);
1.104 ! vatton 81: if (charset != UNDEFINED_CHARSET &&
! 82: DocumentMeta[doc] && DocumentMeta[doc]->content_type)
1.15 cvs 83: return;
1.6 cvs 84:
85: docSSchema = TtaGetDocumentSSchema (doc);
86: attrType.AttrSSchema = docSSchema;
87: attrType.AttrTypeNum = HTML_ATTR_http_equiv;
88: attr = TtaGetAttribute (el, attrType);
89: if (attr != NULL)
90: {
91: /* There is a HTTP-EQUIV attribute */
92: length = TtaGetTextAttributeLength (attr);
93: if (length > 0)
94: {
1.100 gully 95: text = (char *)TtaGetMemory (length + 1);
1.6 cvs 96: TtaGiveTextAttributeValue (attr, text, &length);
1.37 cvs 97: if (!strcasecmp (text, "content-type"))
1.6 cvs 98: {
99: attrType.AttrTypeNum = HTML_ATTR_meta_content;
100: attr = TtaGetAttribute (el, attrType);
101: if (attr != NULL)
102: {
103: length = TtaGetTextAttributeLength (attr);
104: if (length > 0)
105: {
1.100 gully 106: text2 = (char *)TtaGetMemory (length + 1);
1.6 cvs 107: TtaGiveTextAttributeValue (attr, text2, &length);
108: ptrText = text2;
109: while (*ptrText)
110: {
1.53 vatton 111: *ptrText = tolower (*ptrText);
1.6 cvs 112: ptrText++;
113: }
1.104 ! vatton 114:
! 115: if (!DocumentMeta[doc])
! 116: DocumentMeta[doc] = DocumentMetaDataAlloc ();
! 117: if (DocumentMeta[doc]->content_type == NULL)
1.6 cvs 118: {
1.104 ! vatton 119:
! 120: if (!strncmp (text2, "text/html", 9))
! 121: DocumentMeta[doc]->content_type = TtaStrdup ("text/html");
! 122: else
! 123: DocumentMeta[doc]->content_type = TtaStrdup (AM_XHTML_MIME_TYPE);
! 124: }
! 125:
! 126: if (charset == UNDEFINED_CHARSET)
! 127: {
! 128: /* the charset is not already defined by the http header */
! 129: str = strstr (text2, "charset=");
! 130: if (str)
! 131: {
! 132: pos = str - text2 + 8;
! 133: while (text2[pos] != SPACE &&
! 134: text2[pos] != TAB && text2[pos] != EOS)
! 135: charsetname[index++] = text2[pos++];
! 136: charsetname[index] = EOS;
! 137: charset = TtaGetCharset (charsetname);
! 138: if (charset != UNDEFINED_CHARSET)
! 139: TtaSetDocumentCharset (doc, charset, FALSE);
! 140: }
1.6 cvs 141: }
142: TtaFreeMemory (text2);
143: }
144: }
145: }
146: TtaFreeMemory (text);
147: }
148: }
149: }
150:
1.23 cvs 151: /*----------------------------------------------------------------------
1.47 cvs 152: XhtmlCannotContainText
153: Return TRUE if element el is a block element.
154: ----------------------------------------------------------------------*/
155: ThotBool XhtmlCannotContainText (ElementType elType)
156:
157: {
158: int i;
159: ThotBool ret;
160:
161: if (strcmp (TtaGetSSchemaName (elType.ElSSchema), "HTML"))
162: /* not an HTML element */
163: ret = TRUE;
164: else
165: {
166: ret = FALSE;
167: i = 0;
168: while (NoTextChild[i] > 0 && NoTextChild[i] != elType.ElTypeNum)
169: i++;
170: if (NoTextChild[i] == elType.ElTypeNum)
171: ret = TRUE;
172: }
173: return ret;
1.23 cvs 174: }
175:
1.6 cvs 176: /*----------------------------------------------------------------------
177: XhtmlElementComplete
1.20 cvs 178: Complete Xhtml elements.
1.6 cvs 179: Check its attributes and its contents.
180: ----------------------------------------------------------------------*/
1.99 cvs 181: void XhtmlElementComplete (ParserData *context, Element el, int *error)
1.30 cvs 182: {
1.72 cvs 183: Document doc;
1.30 cvs 184: ElementType elType, newElType, childType;
1.104 ! vatton 185: Element child, desc, leaf, prev, next, last,
1.62 quint 186: elFrames, lastFrame, lastChild, parent, picture, content;
1.30 cvs 187: Attribute attr;
188: AttributeType attrType;
189: Language lang;
1.41 cvs 190: char *text;
1.39 cvs 191: char lastChar[2];
1.79 quint 192: char *name1, *data;
1.30 cvs 193: int length;
194: SSchema docSSchema;
1.62 quint 195: ThotBool isImage;
1.6 cvs 196:
197: *error = 0;
1.72 cvs 198: doc = context->doc;
1.6 cvs 199: docSSchema = TtaGetDocumentSSchema (doc);
200:
201: elType = TtaGetElementType (el);
1.96 quint 202: newElType.ElSSchema = elType.ElSSchema;
203:
1.97 quint 204: if (elType.ElTypeNum != HTML_EL_Text_Area &&
205: IsXMLElementInline (elType, doc))
1.96 quint 206: /* It's an inline element. If it is empty, insert a Basic_Elem to allow
207: the user to put the selection within this element */
1.97 quint 208: /* Don't do it for a Text_Area, as a Inserted_Text element has to be
209: created (see below) */
1.96 quint 210: {
211: child = TtaGetFirstChild (el);
212: if (child == NULL)
213: /* it's an empty inline element */
214: /* insert a Basic_Elem element in the element */
215: {
216: newElType.ElTypeNum = HTML_EL_Basic_Elem;
217: child = TtaNewTree (doc, newElType, "");
218: TtaInsertFirstChild (&child, el, doc);
219: }
220: }
221: else
222: /* It's a block-level element. Is it within a character-level element? */
223: if (elType.ElTypeNum != HTML_EL_Comment_ &&
224: elType.ElTypeNum != HTML_EL_XMLPI)
1.6 cvs 225: BlockInCharLevelElem (el);
226:
227: switch (elType.ElTypeNum)
228: {
1.62 quint 229: case HTML_EL_Object: /* it's an object */
1.79 quint 230: data = NULL;
1.62 quint 231: isImage = FALSE;
232: /* is there a type attribute on the object element? */
233: attrType.AttrSSchema = elType.ElSSchema;
234: attrType.AttrTypeNum = HTML_ATTR_Object_type;
1.6 cvs 235: attr = TtaGetAttribute (el, attrType);
1.62 quint 236: if (attr)
237: /* there is a type attribute. Get its value to see if the object
238: represents an image */
1.6 cvs 239: {
240: length = TtaGetTextAttributeLength (attr);
241: if (length > 0)
242: {
1.100 gully 243: name1 = (char *)TtaGetMemory (length + 1);
1.6 cvs 244: TtaGiveTextAttributeValue (attr, name1, &length);
1.68 kahan 245: if (!strcmp (name1, AM_MATHML_MIME_TYPE) ||
1.62 quint 246: !strcmp (name1, "application/postscript") ||
247: !strcmp (name1, "image/x-bitmap") ||
248: !strcmp (name1, "image/x-xpixmap") ||
249: !strcmp (name1, "image/gif") ||
250: !strcmp (name1, "image/jpeg") ||
251: !strcmp (name1, "image/png") ||
1.67 kahan 252: !strcmp (name1, "image/svg") ||
1.83 cvs 253: !strcmp (name1, AM_SVG_MIME_TYPE) ||
254: !strcmp (name1, AM_XHTML_MIME_TYPE) ||
255: !strcmp (name1, "text/html") ||
256: !strcmp (name1, "text/htm") ||
257: !strcmp (name1, AM_GENERIC_XML_MIME_TYPE))
1.62 quint 258: isImage = TRUE;
259: TtaFreeMemory (name1);
260: }
261: }
1.79 quint 262:
263: attrType.AttrTypeNum = HTML_ATTR_data;
264: attr = TtaGetAttribute (el, attrType);
265: if (attr)
266: /* the object has a data attribute */
267: {
268: length = TtaGetTextAttributeLength (attr);
269: if (length > 0)
270: {
1.100 gully 271: data = (char *)TtaGetMemory (length + 1);
1.79 quint 272: TtaGiveTextAttributeValue (attr, data, &length);
273: if (!isImage)
274: if (!strcmp (&data[length-3], "mml") ||
275: !strcmp (&data[length-3], "gif") ||
276: !strcmp (&data[length-3], "jpg") ||
277: !strcmp (&data[length-4], "jpeg") ||
278: !strcmp (&data[length-3], "png") ||
279: !strcmp (&data[length-3], "svg") ||
1.80 cvs 280: !strcmp (&data[length-4], "svgz") ||
1.83 cvs 281: !strcmp (&data[length-3], "htm") ||
282: !strcmp (&data[length-4], "html") ||
283: !strcmp (&data[length-3], "xml"))
1.79 quint 284: isImage = TRUE;
285: }
286: }
1.62 quint 287: picture = NULL; /* no PICTURE element yet */
288: child = TtaGetFirstChild (el);
289: if (isImage)
290: /* the object represents an image. We need a PICTURE element as
291: child of the object to hold the image */
292: {
293: if (child)
294: {
295: elType = TtaGetElementType (child);
296: if (elType.ElTypeNum == HTML_EL_PICTURE_UNIT)
297: /* there is already a PICTURE element */
298: picture = child;
299: }
1.79 quint 300: /* if the object element has no PICTURE element as its first child
1.62 quint 301: create one */
302: if (!picture)
303: {
304: elType.ElTypeNum = HTML_EL_PICTURE_UNIT;
305: picture = TtaNewTree (doc, elType, "");
306: if (child)
307: TtaInsertSibling (picture, child, TRUE, doc);
308: else
309: TtaInsertFirstChild (&picture, el, doc);
310: child = picture;
311: }
312: /* copy attribute data of the object into the SRC attribute of
313: the PICTURE element */
1.79 quint 314: if (data)
315: /* the object has a data attribute */
316: {
317: attrType.AttrTypeNum = HTML_ATTR_SRC;
318: attr = TtaGetAttribute (picture, attrType);
319: if (attr == NULL)
320: {
321: attr = TtaNewAttribute (attrType);
322: TtaAttachAttribute (picture, attr, doc);
323: }
324: TtaSetAttributeText (attr, data, picture, doc);
325: }
326: attrType.AttrTypeNum = HTML_ATTR_Height_;
1.62 quint 327: attr = TtaGetAttribute (el, attrType);
328: if (attr)
1.79 quint 329: /* the Object has a height attribute. Applies it to the
330: picture element */
331: {
332: length = TtaGetTextAttributeLength (attr);
333: if (length > 0)
334: {
1.100 gully 335: text = (char *)TtaGetMemory (length + 1);
1.79 quint 336: TtaGiveTextAttributeValue (attr, text, &length);
337: /* create the corresponding attribute IntHeightPercent or */
338: /* IntHeightPxl */
339: CreateAttrHeightPercentPxl (text, el, doc, -1);
340: TtaFreeMemory (text);
341: }
342: }
343: attrType.AttrTypeNum = HTML_ATTR_Width__;
344: attr = TtaGetAttribute (el, attrType);
345: if (attr)
346: /* the Object has a width attribute. Applies it to the
347: picture element */
1.62 quint 348: {
349: length = TtaGetTextAttributeLength (attr);
350: if (length > 0)
1.6 cvs 351: {
1.100 gully 352: text = (char *)TtaGetMemory (length + 1);
1.79 quint 353: TtaGiveTextAttributeValue (attr, text, &length);
354: /* create the corresponding attribute IntWidthPercent or */
355: /* IntWidthPxl */
356: CreateAttrWidthPercentPxl (text, el, doc, -1);
357: TtaFreeMemory (text);
1.6 cvs 358: }
359: }
360: }
361: /* is the Object_Content element already created ? */
1.62 quint 362: if (child)
363: /* the object element has at least 1 child element */
364: {
365: content = NULL;
366: desc = child;
1.6 cvs 367: elType = TtaGetElementType (desc);
1.62 quint 368: if (elType.ElTypeNum != HTML_EL_Object_Content)
369: {
370: TtaNextSibling(&desc);
371: if (desc)
372: elType = TtaGetElementType (desc);
373: }
374: /* is it the Object_Content element ? */
375: if (elType.ElTypeNum == HTML_EL_Object_Content)
376: content = desc;
377: else
1.6 cvs 378: {
1.62 quint 379: /* create an Object_Content element */
380: elType.ElTypeNum = HTML_EL_Object_Content;
381: content = TtaNewElement (doc, elType);
382: if (picture)
383: TtaInsertSibling (content, picture, FALSE, doc);
384: else
385: TtaInsertSibling (content, child, TRUE, doc);
386: /* move previous existing children into Object_Content */
1.6 cvs 387: child = TtaGetLastChild(el);
1.62 quint 388: while (child != content)
389: {
390: TtaRemoveTree (child, doc);
391: TtaInsertFirstChild (&child, content, doc);
392: child = TtaGetLastChild(el);
393: }
394: }
1.6 cvs 395: }
1.79 quint 396: if (data)
397: TtaFreeMemory (data);
1.6 cvs 398: break;
1.62 quint 399:
1.6 cvs 400: case HTML_EL_Unnumbered_List:
401: case HTML_EL_Numbered_List:
402: case HTML_EL_Menu:
403: case HTML_EL_Directory:
404: /* It's a List element. It should only have List_Item children.
405: If it has List element chidren, move these List elements
406: within their previous List_Item sibling. This is to fix
407: a bug in document generated by Mozilla. */
408: prev = NULL;
409: next = NULL;
410: child = TtaGetFirstChild (el);
411: while (child != NULL)
412: {
413: next = child;
414: TtaNextSibling (&next);
415: elType = TtaGetElementType (child);
416: if (elType.ElTypeNum == HTML_EL_Unnumbered_List ||
417: elType.ElTypeNum == HTML_EL_Numbered_List ||
418: elType.ElTypeNum == HTML_EL_Menu ||
419: elType.ElTypeNum == HTML_EL_Directory)
420: /* this list element is a child of another list element */
421: if (prev)
422: {
423: elType = TtaGetElementType (prev);
424: if (elType.ElTypeNum == HTML_EL_List_Item)
425: {
426: /* get the last child of the previous List_Item */
427: desc = TtaGetFirstChild (prev);
428: last = NULL;
429: while (desc)
430: {
431: last = desc;
432: TtaNextSibling (&desc);
433: }
434: /* move the list element after the last child of the
435: previous List_Item */
436: TtaRemoveTree (child, doc);
437: if (last)
438: TtaInsertSibling (child, last, FALSE, doc);
439: else
440: TtaInsertFirstChild (&child, prev, doc);
441: child = prev;
442: }
443: }
444: prev = child;
445: child = next;
446: }
447: break;
448:
449: case HTML_EL_FRAMESET:
450: /* The FRAMESET element is now complete. Gather all its FRAMESET
451: and FRAME children and wrap them up in a Frames element */
452: elFrames = NULL; lastFrame = NULL;
453: lastChild = NULL;
454: child = TtaGetFirstChild (el);
455: while (child != NULL)
456: {
457: next = child;
458: TtaNextSibling (&next);
459: elType = TtaGetElementType (child);
460: if (elType.ElTypeNum == HTML_EL_FRAMESET ||
461: elType.ElTypeNum == HTML_EL_FRAME ||
462: elType.ElTypeNum == HTML_EL_Comment_)
463: {
464: /* create the Frames element if it does not exist */
465: if (elFrames == NULL)
466: {
467: newElType.ElSSchema = docSSchema;
468: newElType.ElTypeNum = HTML_EL_Frames;
469: elFrames = TtaNewElement (doc, newElType);
1.63 cvs 470: if (DocumentMeta[doc]->xmlformat)
471: XmlSetElemLineNumber (elFrames);
472: else
473: SetHtmlElemLineNumber (elFrames);
1.6 cvs 474: TtaInsertSibling (elFrames, child, TRUE, doc);
475: }
476: /* move the element as the last child of the Frames element */
477: TtaRemoveTree (child, doc);
478: if (lastFrame == NULL)
479: TtaInsertFirstChild (&child, elFrames, doc);
480: else
481: TtaInsertSibling (child, lastFrame, FALSE, doc);
482: lastFrame = child;
483: }
484: child = next;
485: }
486: break;
487:
488: case HTML_EL_Input: /* it's an INPUT without any TYPE attribute */
489: /* Create a child of type Text_Input */
490: elType.ElTypeNum = HTML_EL_Text_Input;
491: child = TtaNewTree (doc, elType, "");
1.63 cvs 492: if (DocumentMeta[doc]->xmlformat)
493: XmlSetElemLineNumber (child);
494: else
495: SetHtmlElemLineNumber (child);
1.6 cvs 496: TtaInsertFirstChild (&child, el, doc);
497: /* now, process it like a Text_Input element */
498:
499: case HTML_EL_Text_Input:
500: case HTML_EL_Password_Input:
501: case HTML_EL_File_Input:
1.91 quint 502: /* set default size */
503: attrType.AttrSSchema = elType.ElSSchema;
504: attrType.AttrTypeNum = HTML_ATTR_IntAreaSize;
505: attr = TtaGetAttribute (el, attrType);
506: if (!attr)
507: CreateAttrIntAreaSize (20, el, doc);
1.6 cvs 508: /* get element Inserted_Text */
509: child = TtaGetFirstChild (el);
510: if (child != NULL)
511: {
512: attrType.AttrTypeNum = HTML_ATTR_Value_;
513: attr = TtaGetAttribute (el, attrType);
514: if (attr != NULL)
515: {
516: /* copy the value of attribute "value" into the first text
517: leaf of element */
518: length = TtaGetTextAttributeLength (attr);
519: if (length > 0)
520: {
521: /* get the text leaf */
522: leaf = TtaGetFirstChild (child);
523: if (leaf != NULL)
524: {
525: childType = TtaGetElementType (leaf);
526: if (childType.ElTypeNum == HTML_EL_TEXT_UNIT)
527: {
528: /* copy attribute value into the text leaf */
1.100 gully 529: text = (char *)TtaGetMemory (length + 1);
1.6 cvs 530: TtaGiveTextAttributeValue (attr, text, &length);
1.100 gully 531: TtaSetTextContent (leaf, (unsigned char *)text,
1.6 cvs 532: TtaGetDefaultLanguage (), doc);
533: TtaFreeMemory (text);
534: }
535: }
536: }
537: }
538: }
539: break;
540:
541: case HTML_EL_META:
1.104 ! vatton 542: ParseCharsetAndContentType (el, doc);
1.6 cvs 543: break;
544:
545: case HTML_EL_STYLE_: /* it's a STYLE element */
1.60 vatton 546: case HTML_EL_SCRIPT_: /* it's a SCRIPT element */
1.6 cvs 547: case HTML_EL_Preformatted: /* it's a PRE */
548: /* if the last line of the Preformatted is empty, remove it */
549: leaf = XmlLastLeafInElement (el);
550: if (leaf != NULL)
551: {
552: elType = TtaGetElementType (leaf);
553: if (elType.ElTypeNum == HTML_EL_TEXT_UNIT)
554: /* the last leaf is a TEXT element */
555: {
556: length = TtaGetTextLength (leaf);
557: if (length > 0)
558: {
1.100 gully 559: TtaGiveSubString (leaf, (unsigned char *)lastChar, length, 1);
1.6 cvs 560: if (lastChar[0] == EOL)
561: /* last character is new line, delete it */
562: {
563: if (length == 1)
564: /* empty TEXT element */
565: TtaDeleteTree (leaf, doc);
566: else
567: /* remove the last character */
568: TtaDeleteTextContent (leaf, length, 1, doc);
569: }
570: }
571: }
572: }
1.75 kahan 573: if (DocumentMeta[doc] && DocumentMeta[doc]->xmlformat)
1.63 cvs 574: {
575: if (IsXmlParsingCSS ())
576: {
577: text = GetStyleContents (el);
578: if (text)
579: {
1.71 vatton 580: ReadCSSRules (doc, NULL, text, NULL,
1.82 quint 581: TtaGetElementLineNumber (el), FALSE, el);
1.63 cvs 582: TtaFreeMemory (text);
583: }
584: SetXmlParsingCSS (FALSE);
585: }
586: }
587: else
1.6 cvs 588: {
1.63 cvs 589: if (IsHtmlParsingCSS ())
1.6 cvs 590: {
1.63 cvs 591: text = GetStyleContents (el);
592: if (text)
593: {
1.71 vatton 594: ReadCSSRules (doc, NULL, text, NULL,
1.82 quint 595: TtaGetElementLineNumber (el), FALSE, el);
1.63 cvs 596: TtaFreeMemory (text);
597: }
598: SetHtmlParsingCSS (FALSE);
1.6 cvs 599: }
600: }
601: /* and continue as if it were a Preformatted or a Script */
602: break;
603:
604: case HTML_EL_Text_Area: /* it's a Text_Area */
1.69 cvs 605: if (DocumentMeta[doc]->xmlformat)
606: SetParsingTextArea (FALSE);
607: else
608: SetHtmlParsingTextArea (FALSE);
1.6 cvs 609: child = TtaGetFirstChild (el);
610: if (child == NULL)
611: /* it's an empty Text_Area */
1.97 quint 612: /* insert a Inserted_Text element and a child Basic_Elem in the
613: Text_Area element */
1.6 cvs 614: {
615: newElType.ElTypeNum = HTML_EL_Inserted_Text;
616: child = TtaNewTree (doc, newElType, "");
617: TtaInsertFirstChild (&child, el, doc);
618: }
619: else
620: {
621: /* save the text into Default_Value attribute */
622: attrType.AttrSSchema = docSSchema;
623: attrType.AttrTypeNum = HTML_ATTR_Default_Value;
624: if (TtaGetAttribute (el, attrType) == NULL)
625: /* attribute Default_Value is missing */
626: {
627: desc = TtaGetFirstChild (child);
1.97 quint 628: if (desc)
629: {
630: length = TtaGetTextLength (desc);
631: if (length > 0)
632: {
633: length++;
634: attr = TtaNewAttribute (attrType);
635: TtaAttachAttribute (el, attr, doc);
1.100 gully 636: text = (char *)TtaGetMemory (length);
637: TtaGiveTextContent (desc, (unsigned char *)text, &length, &lang);
1.97 quint 638: TtaSetAttributeText (attr, text, el, doc);
639: TtaFreeMemory (text);
640: }
641: }
1.6 cvs 642: }
643: }
644: break;
1.103 quint 645:
1.6 cvs 646: case HTML_EL_Radio_Input:
647: case HTML_EL_Checkbox_Input:
648: /* put an attribute Checked if it is missing */
649: attrType.AttrSSchema = docSSchema;
650: attrType.AttrTypeNum = HTML_ATTR_Checked;
651: if (TtaGetAttribute (el, attrType) == NULL)
652: /* attribute Checked is missing */
653: {
654: attr = TtaNewAttribute (attrType);
655: TtaAttachAttribute (el, attr, doc);
656: TtaSetAttributeValue (attr, HTML_ATTR_Checked_VAL_No_, el, doc);
657: }
658: break;
659:
660: case HTML_EL_Option_Menu:
661: /* Check that at least one option has a SELECTED attribute */
662: OnlyOneOptionSelected (el, doc, TRUE);
663: break;
664:
665: case HTML_EL_PICTURE_UNIT:
666: break;
667:
668: case HTML_EL_LINK:
669: CheckCSSLink (el, doc, docSSchema);
670: break;
671:
672: case HTML_EL_Data_cell:
673: case HTML_EL_Heading_cell:
674: /* insert a pseudo paragraph into empty cells */
675: child = TtaGetFirstChild (el);
676: if (child == NULL)
677: {
678: elType.ElTypeNum = HTML_EL_Pseudo_paragraph;
679: child = TtaNewTree (doc, elType, "");
680: if (child != NULL)
681: TtaInsertFirstChild (&child, el, doc);
682: }
683:
1.80 cvs 684: /* detect whether we are parsing a whole table or just a cell */
1.63 cvs 685: if (DocumentMeta[doc]->xmlformat)
686: {
687: if (IsWithinXmlTable ())
1.102 quint 688: NewCell (el, doc, FALSE, FALSE, FALSE);
1.63 cvs 689: }
690: else
691: {
692: if (IsWithinHtmlTable ())
1.102 quint 693: NewCell (el, doc, FALSE, FALSE, FALSE);
1.63 cvs 694: }
1.6 cvs 695: break;
696:
697: case HTML_EL_Table:
698: CheckTable (el, doc);
699: SubWithinTable ();
700: break;
701:
702: case HTML_EL_TITLE:
703: /* show the TITLE in the main window */
704: UpdateTitle (el, doc);
705: break;
1.41 cvs 706:
707: case HTML_EL_rbc:
708: /* an rbc element has been read. Its parent should be a complex_ruby.
709: Change the type of the parent, as simple_ruby are created by
710: default */
711: parent = TtaGetParent (el);
712: if (parent)
713: {
714: newElType = TtaGetElementType (parent);
715: if (newElType.ElSSchema == elType.ElSSchema &&
716: newElType.ElTypeNum == HTML_EL_simple_ruby)
1.95 vatton 717: TtaChangeElementType (parent, HTML_EL_complex_ruby);
1.41 cvs 718: }
719: break;
720:
721: case HTML_EL_rtc1:
722: /* an rtc element has been parsed. If it has already a rtc1 sibling,
723: change its type to rtc2 */
724: prev = el;
725: do
726: {
727: TtaPreviousSibling(&prev);
728: if (prev)
729: {
730: newElType = TtaGetElementType (prev);
731: if (newElType.ElSSchema == elType.ElSSchema &&
732: newElType.ElTypeNum == HTML_EL_rtc1)
733: {
1.95 vatton 734: TtaChangeElementType (el, HTML_EL_rtc2);
1.41 cvs 735: prev = NULL;
736: }
737: }
738: }
739: while (prev);
740: break;
741:
1.6 cvs 742: default:
743: break;
744: }
745: }
1.1 cvs 746:
747: /*----------------------------------------------------------------------
1.30 cvs 748: PutInContent
749: Put the string ChrString in the leaf of current element.
750: ----------------------------------------------------------------------*/
1.39 cvs 751: Element PutInContent (char *ChrString, ParserData *context)
1.30 cvs 752:
753: {
754: Element el, child;
755: ElementType elType;
756: int length;
757:
758: el = NULL;
759: if (context->lastElement != NULL)
760: {
761: /* search first leaf of current element */
762: el = context->lastElement;
763: do
764: {
765: child = TtaGetFirstChild (el);
766: if (child != NULL)
767: el = child;
768: }
769: while (child != NULL);
770: elType = TtaGetElementType (el);
771: length = 0;
772: if (elType.ElTypeNum == 1)
773: length = TtaGetTextLength (el);
774: if (length == 0)
1.100 gully 775: TtaSetTextContent (el, (unsigned char *)ChrString, context->language, context->doc);
1.30 cvs 776: else
1.100 gully 777: TtaAppendTextContent (el, (unsigned char *)ChrString, context->doc);
1.30 cvs 778: }
779: return el;
780: }
781:
782: /*----------------------------------------------------------------------
1.93 vatton 783: UnknownXhtmlNameSpace
784: The element doesn't belong to a supported namespace
1.51 cvs 785: ----------------------------------------------------------------------*/
1.93 vatton 786: void UnknownXhtmlNameSpace (ParserData *context, Element *unknownEl,
787: char* content)
1.51 cvs 788: {
789: ElementType elType;
1.65 cvs 790: Element elText;
1.51 cvs 791:
792: /* Create a new Invalid_element */
793: elType.ElSSchema = GetXMLSSchema (XHTML_TYPE, context->doc);
1.94 cvs 794: elType.ElTypeNum = HTML_EL_XHTML_Unknown_namespace;
1.65 cvs 795: *unknownEl = TtaNewElement (context->doc, elType);
796: if (*unknownEl != NULL)
1.51 cvs 797: {
1.65 cvs 798: XmlSetElemLineNumber (*unknownEl);
799: InsertXmlElement (unknownEl);
1.51 cvs 800: context->lastElementClosed = TRUE;
801: elType.ElTypeNum = HTML_EL_TEXT_UNIT;
802: elText = TtaNewElement (context->doc, elType);
803: XmlSetElemLineNumber (elText);
1.65 cvs 804: TtaInsertFirstChild (&elText, *unknownEl, context->doc);
1.100 gully 805: TtaSetTextContent (elText, (unsigned char *)content, context->language, context->doc);
1.51 cvs 806: TtaSetAccessRight (elText, ReadOnly, context->doc);
807: }
808: }
809:
810: /*----------------------------------------------------------------------
1.30 cvs 811: CreateHTMLAttribute
812: create an attribute of type attrType for the element el.
813: ----------------------------------------------------------------------*/
1.93 vatton 814: void CreateHTMLAttribute (Element el,
815: AttributeType attrType,
816: char* text,
817: ThotBool isInvalid,
818: Document doc,
819: Attribute *lastAttribute,
820: Element *lastAttrElement)
1.30 cvs 821: {
822: int attrKind;
823: int length;
1.39 cvs 824: char *buffer;
1.30 cvs 825: Attribute attr, oldAttr;
826:
827: if (attrType.AttrTypeNum != 0)
828: {
829: oldAttr = TtaGetAttribute (el, attrType);
830: if (oldAttr != NULL)
831: /* this attribute already exists */
832: attr = oldAttr;
833: else
834: /* create a new attribute and attach it to the element */
835: {
836: attr = TtaNewAttribute (attrType);
837: TtaAttachAttribute (el, attr, doc);
838: }
839: *lastAttribute = attr;
840: *lastAttrElement = el;
841:
842: TtaGiveAttributeType (attr, &attrType, &attrKind);
843: if (attrKind == 0) /* enumerate */
844: TtaSetAttributeValue (attr, 1, el, doc);
845:
846: /* attribute BORDER without any value (ThotBool attribute) is */
847: /* considered as BORDER=1 */
848: if (attrType.AttrTypeNum == HTML_ATTR_Border)
849: TtaSetAttributeValue (attr, 1, el, doc);
850:
851: if (isInvalid)
852: /* Copy the name of the invalid attribute as the content */
853: /* of the Invalid_attribute attribute. */
854: {
1.37 cvs 855: length = strlen (text) + 2;
1.30 cvs 856: length += TtaGetTextAttributeLength (attr);
1.100 gully 857: buffer = (char *)TtaGetMemory (length + 1);
1.30 cvs 858: TtaGiveTextAttributeValue (attr, buffer, &length);
1.37 cvs 859: strcat (buffer, " ");
860: strcat (buffer, text);
1.30 cvs 861: TtaSetAttributeText (attr, buffer, el, doc);
862: TtaFreeMemory (buffer);
863: }
864: }
865: }
866:
867: /*----------------------------------------------------------------------
868: HTMLTypeAttrValue
869: Value val has been read for the HTML attribute TYPE.
870: Create a child for the current Thot element INPUT accordingly.
871: ----------------------------------------------------------------------*/
1.46 cvs 872: void HTMLTypeAttrValue (char *val,
1.30 cvs 873: Attribute lastAttribute,
874: Element lastAttrElement,
875: ParserData *context)
876:
877: {
878: ElementType elType;
879: Element newChild;
880: AttributeType attrType;
881: Attribute attr;
1.39 cvs 882: char msgBuffer[MaxMsgLength];
1.30 cvs 883: int value;
884: int numberOfLinesRead;
885:
886: value = MapAttrValue (DummyAttribute, val);
1.91 quint 887: if (value <= 0)
1.30 cvs 888: {
1.37 cvs 889: if (strlen (val) > MaxMsgLength - 40)
890: val[MaxMsgLength - 40] = EOS;
891: sprintf (msgBuffer, "Unknown attribute value \"type = %s\"", val);
1.42 cvs 892: HTMLParseError (context->doc, msgBuffer);
1.30 cvs 893: attrType.AttrSSchema = TtaGetDocumentSSchema (context->doc);
894: attrType.AttrTypeNum = pHTMLAttributeMapping[0].ThotAttribute;
1.37 cvs 895: sprintf (msgBuffer, "type=%s", val);
1.30 cvs 896: CreateHTMLAttribute (context->lastElement, attrType, msgBuffer, TRUE,
897: context->doc, &lastAttribute, &lastAttrElement);
898: }
899: else
900: {
901: elType = TtaGetElementType (context->lastElement);
902: if (elType.ElTypeNum != HTML_EL_Input)
903: {
1.37 cvs 904: if (strlen (val) > MaxMsgLength - 40)
905: val[MaxMsgLength - 40] = EOS;
906: sprintf (msgBuffer, "Duplicate attribute \"type = %s\"", val);
1.30 cvs 907: }
908: else
909: {
910: elType.ElSSchema = TtaGetDocumentSSchema (context->doc);
911: elType.ElTypeNum = value;
912: newChild = TtaNewTree (context->doc, elType, "");
913: numberOfLinesRead = 0;
914: TtaSetElementLineNumber (newChild, numberOfLinesRead);
915: TtaInsertFirstChild (&newChild, context->lastElement, context->doc);
916: if (value == HTML_EL_PICTURE_UNIT)
917: {
918: /* add the attribute IsInput to input pictures */
919: attrType.AttrSSchema = elType.ElSSchema;
920: attrType.AttrTypeNum = HTML_ATTR_IsInput;
921: attr = TtaNewAttribute (attrType);
922: TtaAttachAttribute (newChild, attr, context->doc);
923: }
924: }
925: }
926: }
927:
928: /*----------------------------------------------------------------------
929: XhtmlTypeAttrValue
930: Value val has been read for the HTML attribute TYPE.
931: Create a child for the current Thot element INPUT accordingly.
932: ----------------------------------------------------------------------*/
1.46 cvs 933: void XhtmlTypeAttrValue (char *val,
1.30 cvs 934: Attribute currentAttribute,
935: Element lastAttrElement,
936: ParserData *context)
937:
938: {
939: ElementType elType;
940: Element newChild;
941: AttributeType attrType;
942: Attribute attr;
1.39 cvs 943: char msgBuffer[MaxMsgLength];
1.30 cvs 944: int value;
945: ThotBool level;
946:
1.91 quint 947: /* Look in the dummy section of the attribute value table */
1.30 cvs 948: attrType.AttrTypeNum = DummyAttribute;
1.100 gully 949: MapHTMLAttributeValue (val, &attrType, &value);
1.91 quint 950: if (value <= 0)
951: /* invalid value for the type attribute of an input element */
1.30 cvs 952: {
1.37 cvs 953: sprintf (msgBuffer, "Unknown attribute value \"type=%s\"", val);
1.100 gully 954: XmlParseError (errorParsing, (unsigned char *)msgBuffer, 0);
1.36 cvs 955: MapHTMLAttribute ("unknown_attr", &attrType, NULL,
1.30 cvs 956: &level, context->doc);
1.37 cvs 957: sprintf (msgBuffer, "type=%s", val);
1.30 cvs 958: CreateHTMLAttribute (context->lastElement, attrType, msgBuffer, TRUE,
959: context->doc, ¤tAttribute, &lastAttrElement);
960: }
961: else
1.91 quint 962: /* value is the Thot type of the element to be created for this value of
963: the TYPE attribute */
1.30 cvs 964: {
965: elType = TtaGetElementType (context->lastElement);
966: if (elType.ElTypeNum != HTML_EL_Input)
967: {
1.37 cvs 968: sprintf (msgBuffer, "Duplicate attribute \"type = %s\"", val);
1.100 gully 969: XmlParseError (errorParsing, (unsigned char *)msgBuffer, 0);
1.30 cvs 970: }
971: else
972: {
973: elType.ElTypeNum = value;
974: newChild = TtaNewTree (context->doc, elType, "");
975: XmlSetElemLineNumber (newChild);
976: TtaInsertFirstChild (&newChild, context->lastElement, context->doc);
977: if (value == HTML_EL_PICTURE_UNIT)
978: {
979: /* add the attribute IsInput to input pictures */
980: attrType.AttrSSchema = elType.ElSSchema;
981: attrType.AttrTypeNum = HTML_ATTR_IsInput;
982: attr = TtaNewAttribute (attrType);
983: TtaAttachAttribute (newChild, attr, context->doc);
984: }
985: }
986: }
987: }
988:
989: /*----------------------------------------------------------------------
990: CreateAttrWidthPercentPxl
1.79 quint 991: an HTML attribute "width" has been created for a Table, an image,
992: an Object of a HR.
1.30 cvs 993: Create the corresponding attribute IntWidthPercent or IntWidthPxl.
994: oldWidth is -1 or the old image width.
995: ----------------------------------------------------------------------*/
1.58 vatton 996: void CreateAttrWidthPercentPxl (char *buffer, Element el,
997: Document doc, int oldWidth)
1.30 cvs 998: {
999: AttributeType attrTypePxl, attrTypePercent;
1000: Attribute attrOld, attrNew;
1001: int length, val;
1.39 cvs 1002: char msgBuffer[MaxMsgLength];
1.79 quint 1003: ElementType elType, childType;
1004: Element origEl, child;
1.30 cvs 1005: int w, h;
1006: ThotBool isImage;
1007:
1.79 quint 1008: origEl = el;
1.30 cvs 1009: elType = TtaGetElementType (el);
1010: isImage = (elType.ElTypeNum == HTML_EL_PICTURE_UNIT ||
1011: elType.ElTypeNum == HTML_EL_Data_cell ||
1.79 quint 1012: elType.ElTypeNum == HTML_EL_Heading_cell ||
1013: elType.ElTypeNum == HTML_EL_Object);
1014: if (elType.ElTypeNum == HTML_EL_Object)
1015: /* the width attribute is attached to an Object element */
1016: {
1017: child = TtaGetFirstChild (el);
1018: if (child)
1019: {
1020: childType = TtaGetElementType (child);
1021: if (childType.ElTypeNum == HTML_EL_PICTURE_UNIT)
1022: /* the Object element is of type image. apply the width
1023: attribute to the actual image element */
1024: el = child;
1025: }
1026: }
1.30 cvs 1027: /* remove trailing spaces */
1.37 cvs 1028: length = strlen (buffer) - 1;
1.30 cvs 1029: while (length > 0 && buffer[length] <= SPACE)
1030: length--;
1031: attrTypePxl.AttrSSchema = TtaGetDocumentSSchema (doc);
1032: attrTypePercent.AttrSSchema = TtaGetDocumentSSchema (doc);
1033: attrTypePxl.AttrTypeNum = HTML_ATTR_IntWidthPxl;
1034: attrTypePercent.AttrTypeNum = HTML_ATTR_IntWidthPercent;
1035: /* is the last character a '%' ? */
1036: if (buffer[length] == '%')
1037: {
1038: /* remove IntWidthPxl */
1039: attrOld = TtaGetAttribute (el, attrTypePxl);
1040: /* update IntWidthPercent */
1041: attrNew = TtaGetAttribute (el, attrTypePercent);
1042: if (attrNew == NULL)
1043: {
1044: attrNew = TtaNewAttribute (attrTypePercent);
1045: TtaAttachAttribute (el, attrNew, doc);
1046: }
1047: else if (isImage && oldWidth == -1)
1048: {
1049: if (attrOld == NULL)
1050: oldWidth = TtaGetAttributeValue (attrNew);
1051: else
1052: oldWidth = TtaGetAttributeValue (attrOld);
1053: }
1054: }
1055: else
1056: {
1057: /* remove IntWidthPercent */
1058: attrOld = TtaGetAttribute (el, attrTypePercent);
1059: /* update IntWidthPxl */
1060: attrNew = TtaGetAttribute (el, attrTypePxl);
1061: if (attrNew == NULL)
1062: {
1063: attrNew = TtaNewAttribute (attrTypePxl);
1064: TtaAttachAttribute (el, attrNew, doc);
1065: }
1066: else if (isImage && oldWidth == -1)
1067: {
1068: TtaGiveBoxSize (el, doc, 1, UnPixel, &w, &h);
1069: if (attrOld == NULL)
1070: oldWidth = w * TtaGetAttributeValue (attrNew) / 100;
1071: else
1072: oldWidth = w * TtaGetAttributeValue (attrOld) / 100;
1073: }
1074: }
1075:
1076: if (attrOld != NULL)
1077: TtaRemoveAttribute (el, attrOld, doc);
1.43 cvs 1078: if (sscanf (buffer, "%d", &val))
1.30 cvs 1079: TtaSetAttributeValue (attrNew, val, el, doc);
1080: else
1081: /* its not a number. Delete attribute and send an error message */
1082: {
1083: TtaRemoveAttribute (el, attrNew, doc);
1.37 cvs 1084: if (strlen (buffer) > MaxMsgLength - 30)
1.30 cvs 1085: buffer[MaxMsgLength - 30] = EOS;
1.37 cvs 1086: sprintf (msgBuffer, "Invalid attribute value \"%s\"", buffer);
1.42 cvs 1087: HTMLParseError (doc, msgBuffer);
1.30 cvs 1088: }
1089: if (isImage)
1.79 quint 1090: UpdateImageMap (origEl, doc, oldWidth, -1);
1.30 cvs 1091: }
1092:
1093: /*----------------------------------------------------------------------
1.58 vatton 1094: CreateAttrHeightPercentPxl
1.79 quint 1095: an HTML attribute "width" has been created for a Table, an image,
1096: an Object or a HR.
1.58 vatton 1097: Create the corresponding attribute IntHeightPercent or IntHeightPxl.
1098: oldHeight is -1 or the old image width.
1099: ----------------------------------------------------------------------*/
1100: void CreateAttrHeightPercentPxl (char *buffer, Element el,
1101: Document doc, int oldHeight)
1102: {
1103: AttributeType attrTypePxl, attrTypePercent;
1104: Attribute attrOld, attrNew;
1105: int length, val;
1106: char msgBuffer[MaxMsgLength];
1.79 quint 1107: ElementType elType, childType;
1108: Element origEl, child;
1.58 vatton 1109: int w, h;
1110: ThotBool isImage;
1111:
1.79 quint 1112: origEl = el;
1.58 vatton 1113: elType = TtaGetElementType (el);
1114: isImage = (elType.ElTypeNum == HTML_EL_PICTURE_UNIT ||
1115: elType.ElTypeNum == HTML_EL_Data_cell ||
1.79 quint 1116: elType.ElTypeNum == HTML_EL_Heading_cell ||
1117: elType.ElTypeNum == HTML_EL_Object);
1118: if (elType.ElTypeNum == HTML_EL_Object)
1119: /* the height attribute is attached to an Object element */
1120: {
1121: child = TtaGetFirstChild (el);
1.81 cvs 1122: if (!child)
1123: return;
1124: else
1.79 quint 1125: {
1126: childType = TtaGetElementType (child);
1127: if (childType.ElTypeNum == HTML_EL_PICTURE_UNIT)
1128: /* the Object element is of type image. apply the width
1129: attribute to the actual image element */
1130: el = child;
1.81 cvs 1131: else
1132: return;
1.79 quint 1133: }
1134: }
1.58 vatton 1135: /* remove trailing spaces */
1136: length = strlen (buffer) - 1;
1137: while (length > 0 && buffer[length] <= SPACE)
1138: length--;
1139: attrTypePxl.AttrSSchema = TtaGetDocumentSSchema (doc);
1140: attrTypePercent.AttrSSchema = TtaGetDocumentSSchema (doc);
1141: attrTypePxl.AttrTypeNum = HTML_ATTR_IntHeightPxl;
1142: attrTypePercent.AttrTypeNum = HTML_ATTR_IntHeightPercent;
1143: /* is the last character a '%' ? */
1144: if (buffer[length] == '%')
1145: {
1146: /* remove IntHeightPxl */
1147: attrOld = TtaGetAttribute (el, attrTypePxl);
1148: /* update IntHeightPercent */
1149: attrNew = TtaGetAttribute (el, attrTypePercent);
1150: if (attrNew == NULL)
1151: {
1152: attrNew = TtaNewAttribute (attrTypePercent);
1153: TtaAttachAttribute (el, attrNew, doc);
1154: }
1155: else if (isImage && oldHeight == -1)
1156: {
1157: if (attrOld == NULL)
1158: oldHeight = TtaGetAttributeValue (attrNew);
1159: else
1160: oldHeight = TtaGetAttributeValue (attrOld);
1161: }
1162: }
1163: else
1164: {
1165: /* remove IntHeightPercent */
1166: attrOld = TtaGetAttribute (el, attrTypePercent);
1167: /* update IntHeightPxl */
1168: attrNew = TtaGetAttribute (el, attrTypePxl);
1169: if (attrNew == NULL)
1170: {
1171: attrNew = TtaNewAttribute (attrTypePxl);
1172: TtaAttachAttribute (el, attrNew, doc);
1173: }
1174: else if (isImage && oldHeight == -1)
1175: {
1176: TtaGiveBoxSize (el, doc, 1, UnPixel, &w, &h);
1177: if (attrOld == NULL)
1178: oldHeight = w * TtaGetAttributeValue (attrNew) / 100;
1179: else
1180: oldHeight = w * TtaGetAttributeValue (attrOld) / 100;
1181: }
1182: }
1183:
1184: if (attrOld != NULL)
1185: TtaRemoveAttribute (el, attrOld, doc);
1186: if (sscanf (buffer, "%d", &val))
1187: TtaSetAttributeValue (attrNew, val, el, doc);
1188: else
1189: /* its not a number. Delete attribute and send an error message */
1190: {
1191: TtaRemoveAttribute (el, attrNew, doc);
1192: if (strlen (buffer) > MaxMsgLength - 30)
1193: buffer[MaxMsgLength - 30] = EOS;
1194: sprintf (msgBuffer, "Invalid attribute value \"%s\"", buffer);
1195: HTMLParseError (doc, msgBuffer);
1196: }
1197: if (isImage)
1.79 quint 1198: UpdateImageMap (origEl, doc, oldHeight, -1);
1.58 vatton 1199: }
1200:
1201: /*----------------------------------------------------------------------
1.91 quint 1202: CreateAttrIntAreaSize
1203: an HTML attribute "size" has been created or modified for a input element.
1204: Create or update the corresponding attribute IntAreaSize.
1205: ----------------------------------------------------------------------*/
1206: void CreateAttrIntAreaSize (int value, Element el, Document doc)
1207: {
1208: AttributeType attrType;
1209: Attribute attr;
1210: ElementType elType;
1211:
1212: elType = TtaGetElementType (el);
1213: attrType.AttrSSchema = elType.ElSSchema;
1214: attrType.AttrTypeNum = HTML_ATTR_IntAreaSize;
1215: attr = TtaGetAttribute (el, attrType);
1216: if (!attr)
1217: {
1218: attr = TtaNewAttribute (attrType);
1219: TtaAttachAttribute (el, attr, doc);
1220: }
1221: /* the presentation rule associated with attribute IntAreaSize expresses
1222: the element width in "em". Convert the value into em */
1223: TtaSetAttributeValue (attr, (int) (value * 0.55), el, doc);
1224: }
1225:
1226: /*----------------------------------------------------------------------
1.30 cvs 1227: CreateAttrIntSize
1228: an HTML attribute "size" has been created for a Font element.
1229: Create the corresponding internal attribute.
1230: ----------------------------------------------------------------------*/
1.46 cvs 1231: void CreateAttrIntSize (char *buffer, Element el, Document doc)
1.30 cvs 1232:
1233: {
1234: AttributeType attrType;
1235: int val, ind, factor, delta;
1236: Attribute attr;
1.37 cvs 1237: char msgBuffer[MaxMsgLength];
1.30 cvs 1238:
1239: /* is the first character a '+' or a '-' ? */
1240: ind = 0;
1241: factor = 1;
1242: delta = 0;
1243: if (buffer[0] == '+')
1244: {
1245: attrType.AttrTypeNum = HTML_ATTR_IntSizeIncr;
1246: ind++;
1.90 vatton 1247: factor = 1;
1.30 cvs 1248: }
1249: else if (buffer[0] == '-')
1250: {
1251: attrType.AttrTypeNum = HTML_ATTR_IntSizeDecr;
1252: ind++;
1.90 vatton 1253: factor = 1;
1.30 cvs 1254: }
1255: else
1256: {
1257: attrType.AttrTypeNum = HTML_ATTR_IntSizeRel;
1258: delta = 1;
1259: }
1260: attrType.AttrSSchema = TtaGetDocumentSSchema (doc);
1261: attr = TtaGetAttribute (el, attrType);
1.43 cvs 1262: if (sscanf (&buffer[ind], "%d", &val))
1.30 cvs 1263: {
1264: val = val * factor + delta;
1265: if (attr == NULL)
1266: {
1267: /* this attribute doesn't exist, create it */
1268: attr = TtaNewAttribute (attrType);
1269: TtaAttachAttribute (el, attr, doc);
1270: }
1271: TtaSetAttributeValue (attr, val, el, doc);
1272: }
1273: else
1274: /* its not a number. Delete attribute and send an error message */
1275: {
1276: if (attr)
1277: TtaRemoveAttribute (el, attr, doc);
1.37 cvs 1278: if (strlen (buffer) > MaxMsgLength - 30)
1.30 cvs 1279: buffer[MaxMsgLength - 30] = EOS;
1.37 cvs 1280: sprintf (msgBuffer, "Invalid attribute value \"%s\"", buffer);
1.42 cvs 1281: HTMLParseError (doc, msgBuffer);
1.30 cvs 1282: }
1283: }
1284: /*----------------------------------------------------------------------
1285: EndOfHTMLAttributeValue
1286: Filling of an HTML attribute value
1287: ----------------------------------------------------------------------*/
1.48 vatton 1288: void EndOfHTMLAttributeValue (char *attrValue,
1289: AttributeMapping *lastMappedAttr,
1290: Attribute currentAttribute,
1291: Element lastAttrElement,
1292: ThotBool UnknownAttr,
1293: ParserData *context,
1294: ThotBool isXML)
1.30 cvs 1295: {
1.48 vatton 1296: AttributeType attrType, attrType1;
1297: Attribute attr;
1.79 quint 1298: ElementType elType;
1.48 vatton 1299: Element child, root;
1300: Language lang;
1301: char translation;
1302: char shape;
1303: char *buffer;
1304: char *attrName;
1305: char msgBuffer[MaxMsgLength];
1306: int val;
1307: int length;
1308: int attrKind;
1309: ThotBool done = FALSE;
1.88 vatton 1310: ThotBool loadcss;
1.30 cvs 1311:
1.48 vatton 1312: /* treatments of some particular HTML attributes */
1313: if (!strcmp (lastMappedAttr->XMLattribute, "style"))
1314: {
1315: TtaSetAttributeText (currentAttribute, attrValue,
1316: lastAttrElement, context->doc);
1.88 vatton 1317: /* check if we have to load CSS */
1318: TtaGetEnvBoolean ("LOAD_CSS", &loadcss);
1319: if (loadcss)
1320: ParseHTMLSpecificStyle (context->lastElement, attrValue,
1321: context->doc, 100, FALSE);
1.48 vatton 1322: done = TRUE;
1323: }
1324: else
1325: {
1326: if (!strcmp (lastMappedAttr->XMLattribute, "link"))
1.89 vatton 1327: HTMLSetAlinkColor (context->doc, context->lastElement, attrValue);
1.48 vatton 1328: else if (!strcmp (lastMappedAttr->XMLattribute, "alink"))
1.89 vatton 1329: HTMLSetAactiveColor (context->doc, context->lastElement, attrValue);
1.48 vatton 1330: else if (!strcmp (lastMappedAttr->XMLattribute, "vlink"))
1.89 vatton 1331: HTMLSetAvisitedColor (context->doc, context->lastElement, attrValue);
1.48 vatton 1332: }
1.30 cvs 1333:
1.48 vatton 1334: if (!done)
1335: {
1336: val = 0;
1337: translation = lastMappedAttr->AttrOrContent;
1338: switch (translation)
1339: {
1340: case 'C': /* Content */
1341: child = PutInContent (attrValue, context);
1342: if (child != NULL)
1.100 gully 1343: TtaAppendTextContent (child, (unsigned char *)"\" ", context->doc);
1.48 vatton 1344: break;
1345:
1346: case 'A':
1347: if (currentAttribute != NULL)
1348: {
1349: TtaGiveAttributeType (currentAttribute, &attrType, &attrKind);
1350: switch (attrKind)
1351: {
1352: case 0: /* enumerate */
1353: if (isXML)
1.100 gully 1354: MapHTMLAttributeValue (attrValue, &attrType, &val);
1.48 vatton 1355: else
1356: val = MapAttrValue (lastMappedAttr->ThotAttribute,
1.40 cvs 1357: attrValue);
1.48 vatton 1358: if (val < 0)
1359: {
1360: TtaGiveAttributeType (currentAttribute,
1361: &attrType, &attrKind);
1362: attrName = TtaGetAttributeName (attrType);
1363: sprintf (msgBuffer,
1.51 cvs 1364: "Invalid attribute value \"%s = %s\"",
1.48 vatton 1365: attrName, attrValue);
1366: if (isXML)
1.100 gully 1367: XmlParseError (errorParsing, (unsigned char *)msgBuffer, 0);
1.48 vatton 1368: else
1.84 quint 1369: /* we are parsing an HTML file, not an XHTML file */
1.51 cvs 1370: {
1.84 quint 1371: /* generate an error message in the log */
1.51 cvs 1372: HTMLParseError (context->doc, msgBuffer);
1.84 quint 1373: /* special case for value POLYGON of attribute
1374: shape (AREA element) */
1375: if (attrType.AttrTypeNum == HTML_ATTR_shape &&
1376: strcasecmp (attrValue, "POLYGON") == 0)
1377: {
1378: val = HTML_ATTR_shape_VAL_polygon;
1379: /* interpret it as if it were "poly" */
1380: TtaSetAttributeValue (currentAttribute, val,
1381: lastAttrElement, context->doc);
1382: }
1383: else
1384: /* remove the attribute and replace it by an */
1385: /* Invalid_attribute (not for XHTML) */
1386: {
1387: TtaRemoveAttribute (lastAttrElement,
1.51 cvs 1388: currentAttribute, context->doc);
1.84 quint 1389: attrType.AttrSSchema =
1390: TtaGetDocumentSSchema (context->doc);
1391: attrType.AttrTypeNum =
1392: pHTMLAttributeMapping[0].ThotAttribute;
1393: sprintf (msgBuffer, "%s=%s", attrName,attrValue);
1394: CreateHTMLAttribute (lastAttrElement, attrType,
1395: msgBuffer, TRUE, context->doc,
1396: ¤tAttribute, &lastAttrElement);
1397: }
1.48 vatton 1398: }
1399: }
1400: else
1401: TtaSetAttributeValue (currentAttribute, val,
1402: lastAttrElement, context->doc);
1403: break;
1404: case 1: /* integer */
1405: if (attrType.AttrTypeNum == HTML_ATTR_Border &&
1406: !strcasecmp (attrValue, "border"))
1407: {
1408: /* border="border" for a table */
1409: val = 1;
1410: TtaSetAttributeValue (currentAttribute, val,
1.30 cvs 1411: lastAttrElement, context->doc);
1.48 vatton 1412: }
1413: else if (sscanf (attrValue, "%d", &val))
1414: TtaSetAttributeValue (currentAttribute, val,
1415: lastAttrElement, context->doc);
1416: else
1417: {
1418: TtaRemoveAttribute (lastAttrElement, currentAttribute,
1419: context->doc);
1420: sprintf (msgBuffer,
1421: "Unknown attribute value \"%s\"",
1422: attrValue);
1423: if (isXML)
1.100 gully 1424: XmlParseError (errorParsing, (unsigned char *)msgBuffer, 0);
1.48 vatton 1425: else
1426: HTMLParseError (context->doc, msgBuffer);
1427: }
1428: break;
1429: case 2: /* text */
1430: if (!UnknownAttr)
1431: {
1432: TtaSetAttributeText (currentAttribute, attrValue,
1433: lastAttrElement, context->doc);
1.55 cvs 1434: if (attrType.AttrTypeNum == HTML_ATTR_Language)
1.48 vatton 1435: {
1436: /* it's a LANG attribute value */
1437: lang = TtaGetLanguageIdFromName (attrValue);
1.70 vatton 1438: if (lang < 0)
1.48 vatton 1439: {
1440: sprintf (msgBuffer,
1441: "warning - unsupported language: %s",
1442: attrValue);
1443: if (isXML)
1.100 gully 1444: XmlParseError (warningMessage, (unsigned char *)msgBuffer, 0);
1.48 vatton 1445: else
1446: HTMLParseError (context->doc, msgBuffer);
1447: }
1448: else
1449: {
1450: /* change current language */
1451: context->language = lang;
1452: if (isXML)
1453: SetLanguagInXmlStack (lang);
1454: else
1455: SetLanguagInHTMLStack (lang);
1456: }
1457: root = TtaGetRootElement (context->doc);
1458: if (lastAttrElement == root)
1459: /* it's a LANG attribute on the root element */
1460: /* set the RealLang attribute */
1461: {
1462: attrType1.AttrSSchema = TtaGetDocumentSSchema (context->doc);
1463: attrType1.AttrTypeNum = HTML_ATTR_RealLang;
1464: /* this attribute could be already present,
1465: (lang and xml:lang attributes) */
1466: if (!TtaGetAttribute (lastAttrElement,
1467: attrType1))
1468: /* it's not present. Add it */
1469: {
1470: attr = TtaNewAttribute (attrType1);
1471: TtaAttachAttribute (lastAttrElement,
1472: attr, context->doc);
1473: TtaSetAttributeValue (attr,
1474: HTML_ATTR_RealLang_VAL_Yes_,
1475: lastAttrElement,
1476: context->doc);
1477: }
1478: }
1479: }
1480: else if (attrType.AttrTypeNum == HTML_ATTR_accesskey)
1481: TtaAddAccessKey (context->doc, (unsigned int)attrValue[0],
1482: lastAttrElement);
1483: }
1484: else
1485: {
1.51 cvs 1486: /* this is the content of an invalid attribute */
1487: /* append it to the current Invalid_attribute */
1488: if (!isXML)
1489: {
1490: length = strlen (attrValue) + 2;
1491: length += TtaGetTextAttributeLength (currentAttribute);
1.100 gully 1492: buffer = (char *)TtaGetMemory (length + 1);
1.51 cvs 1493: TtaGiveTextAttributeValue (currentAttribute,
1494: buffer, &length);
1495: strcat (buffer, "=");
1496: strcat (buffer, attrValue);
1497: TtaSetAttributeText (currentAttribute, buffer,
1498: lastAttrElement, context->doc);
1499: TtaFreeMemory (buffer);
1500: }
1.48 vatton 1501: }
1502: break;
1503: case 3: /* reference */
1504: break;
1505: }
1506: }
1507: break;
1508:
1509: case SPACE:
1510: if (isXML)
1511: XhtmlTypeAttrValue (attrValue, currentAttribute,
1.30 cvs 1512: lastAttrElement, context);
1.48 vatton 1513: else
1514: HTMLTypeAttrValue (attrValue, currentAttribute,
1515: lastAttrElement, context);
1516: break;
1517:
1.30 cvs 1518: default:
1519: break;
1.48 vatton 1520: }
1.30 cvs 1521:
1522: if (lastMappedAttr->ThotAttribute == HTML_ATTR_Width__)
1.79 quint 1523: /* HTML attribute "width" */
1524: {
1525: /* if it's an Object element, wait until all attributes are handled,
1526: especially the data attribute that may generate the image to
1527: which the width has to be applied */
1528: elType = TtaGetElementType (lastAttrElement);
1529: if (elType.ElTypeNum != HTML_EL_Object)
1530: /* create the corresponding attribute IntWidthPercent or */
1531: /* IntWidthPxl */
1532: CreateAttrWidthPercentPxl (attrValue, lastAttrElement,
1533: context->doc, -1);
1534: }
1.58 vatton 1535: else if (lastMappedAttr->ThotAttribute == HTML_ATTR_Height_)
1.79 quint 1536: /* HTML attribute "height" */
1537: {
1538: /* if it's an Object element, wait until all attributes are handled,
1539: especially the data attribute that may generate the image to
1540: which the height has to be applied */
1541: elType = TtaGetElementType (lastAttrElement);
1542: if (elType.ElTypeNum != HTML_EL_Object)
1543: /* create the corresponding attribute IntHeightPercent or */
1544: /* IntHeightPxl */
1545: CreateAttrHeightPercentPxl (attrValue, lastAttrElement,
1546: context->doc, -1);
1547: }
1.91 quint 1548: else if (lastMappedAttr->ThotAttribute == HTML_ATTR_Area_Size)
1549: /* HTML attribute "size" for an element "input" */
1550: CreateAttrIntAreaSize (val, lastAttrElement, context->doc);
1.48 vatton 1551: else if (!strcmp (lastMappedAttr->XMLattribute, "size"))
1552: {
1553: TtaGiveAttributeType (currentAttribute, &attrType, &attrKind);
1554: if (attrType.AttrTypeNum == HTML_ATTR_Font_size)
1555: CreateAttrIntSize (attrValue, lastAttrElement, context->doc);
1556: }
1557: else if (!strcmp (lastMappedAttr->XMLattribute, "shape"))
1558: {
1559: child = TtaGetFirstChild (lastAttrElement);
1560: if (child != NULL)
1561: {
1562: switch (val)
1563: {
1564: case HTML_ATTR_shape_VAL_rectangle:
1565: shape = 'R';
1566: break;
1567: case HTML_ATTR_shape_VAL_circle:
1568: shape = 'a';
1569: break;
1570: case HTML_ATTR_shape_VAL_polygon:
1571: shape = 'p';
1572: break;
1573: default:
1574: shape = SPACE;
1575: break;
1576: }
1577: TtaSetGraphicsShape (child, shape, context->doc);
1578: }
1579: }
1580: else if (!strcmp (lastMappedAttr->XMLattribute, "value"))
1581: {
1582: elType = TtaGetElementType (lastAttrElement);
1583: if (elType.ElTypeNum == HTML_EL_Text_Input ||
1584: elType.ElTypeNum == HTML_EL_Password_Input ||
1585: elType.ElTypeNum == HTML_EL_File_Input ||
1586: elType.ElTypeNum == HTML_EL_Input)
1587: /* create a Default_Value attribute with the same content */
1588: {
1589: attrType1.AttrSSchema = attrType.AttrSSchema;
1590: attrType1.AttrTypeNum = HTML_ATTR_Default_Value;
1591: attr = TtaNewAttribute (attrType1);
1592: TtaAttachAttribute (lastAttrElement, attr, context->doc);
1593: TtaSetAttributeText (attr, attrValue,
1594: lastAttrElement, context->doc);
1595: }
1596: }
1.30 cvs 1597: else
1.48 vatton 1598: {
1599: /* Some HTML attributes are equivalent to a CSS property: */
1600: /* background -> background */
1601: /* bgcolor -> background */
1602: /* text -> color */
1603: /* color -> color */
1604: if (!strcmp (lastMappedAttr->XMLattribute, "background"))
1605: {
1606: if (strlen (attrValue) > MaxMsgLength - 30)
1607: attrValue[MaxMsgLength - 30] = EOS;
1.76 vatton 1608: HTMLSetBackgroundImage (context->doc, context->lastElement,
1.85 vatton 1609: REPEAT, attrValue, FALSE);
1.48 vatton 1610: }
1611: else if (!strcmp (lastMappedAttr->XMLattribute, "bgcolor"))
1.76 vatton 1612: HTMLSetBackgroundColor (context->doc, context->lastElement,
1613: attrValue);
1.48 vatton 1614: else if (!strcmp (lastMappedAttr->XMLattribute, "text") ||
1615: !strcmp (lastMappedAttr->XMLattribute, "color"))
1616: HTMLSetForegroundColor (context->doc,
1617: context->lastElement, attrValue);
1618: }
1619: }
1.30 cvs 1620: }
1621:
1622: /*----------------------------------------------------------------------
1.16 cvs 1623: MapHTMLAttributeValue
1.2 cvs 1624: Search in the Attribute Value Mapping Table the entry for the attribute
1.66 vatton 1625: ThotAtt and its value attVal. Returns the corresponding Thot value.
1.1 cvs 1626: ----------------------------------------------------------------------*/
1.100 gully 1627: void MapHTMLAttributeValue (char *attVal, const AttributeType * attrType, int *value)
1.1 cvs 1628: {
1.66 vatton 1629: MapXMLAttributeValue (XHTML_TYPE, attVal, attrType, value);
1.1 cvs 1630: }
Webmaster