Subversion Repositories Kolibri OS

Rev

Rev 8500 | Rev 9104 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
8439 leency 1
void TWebBrowser::SetStyle()
2
{
8444 leency 3
	if (tag.get_value_of("name")) || (tag.get_value_of("id")) {
8439 leency 4
		anchors.add(tag.value, draw_y);
5
		if (anchors.current) && (streq(tag.value, #anchors.current+1)) {
6
			list.first = draw_y;
7
			anchors.current = NULL;
8
		}
9
	}
10
	if (tag.is("a"))          { tag_a();                   return; }
11
	if (tag.is("p"))          { tag_p();                   return; }
12
	if (tag.is("img"))        { tag_img();                 return; }
13
	if (tag.is("div"))        { tag_div();                 return; }
8500 leency 14
	if (tag.is("br"))         { /*draw_x++;*/NewLine();    return; }
8439 leency 15
	if (tag.is("header"))     { NewLine();                 return; }
16
	if (tag.is("article"))    { NewLine();                 return; }
17
	if (tag.is("footer"))     { NewLine();                 return; }
18
	if (tag.is("figure"))     { NewLine();                 return; }
19
	if (tag.is("w:p"))        { NewLine();                 return; }
8462 leency 20
	if (tag.is("b"))          { style.b      = tag.opened; return; }
21
	if (tag.is("strong"))     { style.b      = tag.opened; return; }
22
	if (tag.is("big"))        { style.b      = tag.opened; return; }
23
	if (tag.is("w:b"))        { style.b      = tag.opened; return; }
24
	if (tag.is("u"))          { style.u      = tag.opened; return; }
25
	if (tag.is("ins"))        { style.u      = tag.opened; return; }
26
	if (tag.is("s"))          { style.s      = tag.opened; return; }
27
	if (tag.is("strike"))     { style.s      = tag.opened; return; }
28
	if (tag.is("del"))        { style.s      = tag.opened; return; }
29
	if (tag.is("pre"))        { style.pre    = tag.opened; return; }
30
	if (tag.is("blockquote")) { style.blq    = tag.opened; return; }
31
	if (tag.is("button"))     { style.button = tag.opened; return; }
8439 leency 32
	if (tag.is("dl"))         { if (tag.opened) NewLine(); return; }
33
	if (tag.is("w:r"))        { if (!tag.opened) style.b = false;      return; }
34
	if (tag.is("h1"))         { tag_h1234_caption();  return; }
35
	if (tag.is("h2"))         { tag_h1234_caption();  return; }
36
	if (tag.is("h3"))         { tag_h1234_caption();  return; }
37
	if (tag.is("h4"))         { tag_h1234_caption();  return; }
38
	if (tag.is("font"))       { tag_font();           return; }
39
	if (tag.is("dt"))         { tag_ol_ul_dt();       return; }
40
	if (tag.is("ul"))         { tag_ol_ul_dt();       return; }
41
	if (tag.is("ol"))         { tag_ol_ul_dt();       return; }
42
	if (tag.is("li"))         { tag_li();             return; }
43
	if (tag.is("q"))          { tag_q();              return; }
44
	if (tag.is("hr"))         { tag_hr();             return; }
45
	if (tag.is("meta"))       { tag_meta_xml();       return; }
46
	if (tag.is("?xml"))       { tag_meta_xml();       return; }
47
	if (tag.is("code"))       { tag_code();           return; }
48
	if (tag.is("iframe"))     { tag_iframe();         return; }
49
	if (tag.is("caption"))    { tag_h1234_caption();  return; }
50
	if (tag.is("title"))      { tag_title();          return; }
51
	if (tag.is("body"))       { tag_body();           return; }
52
	if (tag.is("html"))       { t_html = tag.opened;  return; }
9103 leency 53
	tag_table();
8439 leency 54
}
55
 
56
void TWebBrowser::tag_p()
57
{
58
	IF (tag.prior[0] == 'h') || (streq(#tag.prior,"td")) || (streq(#tag.prior,"p")) return;
59
	NewLine();
60
}
61
 
62
void TWebBrowser::tag_title()
63
{
64
	style.title = tag.opened;
65
	if (!tag.opened) DrawTitle(#header);
66
}
67
 
68
void TWebBrowser::tag_font()
69
{
70
	style.font = tag.opened;
71
	if (tag.opened)
72
	{
8451 leency 73
		if (tag.get_value_of("bg")) {
74
			bg_colors.add(GetColor(tag.value));
75
		} else {
76
			bg_colors.add(bg_colors.get_last());
77
		}
8444 leency 78
		if (tag.get_value_of("color")) {
8439 leency 79
			text_colors.add(GetColor(tag.value));
80
		} else {
81
			text_colors.add(text_colors.get_last());
82
		}
83
	}
8451 leency 84
	else {
85
		text_colors.pop();
8499 leency 86
		if (bg_colors.count>1) bg_colors.pop(); //never pop the last color
8451 leency 87
	}
8439 leency 88
}
89
 
90
void TWebBrowser::tag_div()
91
{
8499 leency 92
	//if (streq(#tag.prior,"div")) && (tag.opened) return;
8490 leency 93
	if (streq(#tag.prior,"td")) return;
8499 leency 94
	if (streq(#tag.prior,"div")) return;
8439 leency 95
	if (!tag.opened) && (style.font) text_colors.pop();
96
	NewLine();
97
}
98
 
99
void TWebBrowser::tag_iframe()
100
{
8444 leency 101
	if (tag.get_value_of("src")) {
8439 leency 102
		NewLine();
8492 leency 103
		strcpy(#linebuf, "IFRAME: ");
8491 leency 104
		RenderTextbuf();
8439 leency 105
		link=true;
106
		links.add_link(tag.value);
8492 leency 107
		strncpy(#linebuf, tag.value, sizeof(TWebBrowser.linebuf)-1);
8491 leency 108
		RenderTextbuf();
8439 leency 109
		link=false;
110
		NewLine();
111
	}
112
}
113
 
114
void TWebBrowser::tag_a()
115
{
116
	if (tag.opened)
117
	{
8444 leency 118
		if (tag.get_value_of("href")) && (!strstr(tag.value,"javascript:"))
8439 leency 119
		{
120
			link = true;
121
			links.add_link(tag.value);
122
		}
123
	} else {
124
		link = false;
125
	}
126
}
127
 
128
void TWebBrowser::tag_meta_xml()
129
{
8444 leency 130
	if (custom_encoding == -1) if (tag.get_value_of("charset"))
131
	|| (tag.get_value_of("content")) || (tag.get_value_of("encoding"))
8439 leency 132
	{
133
		EDX = strrchr(tag.value, '=') + tag.value; //search in content=
134
		if (ESBYTE[EDX] == '"') EDX++;
135
		strlwr(EDX);
8492 leency 136
		EAX = get_encoding_type_by_name(EDX);
137
		if (EAX!=-1) ChangeEncoding(EAX);
8439 leency 138
	}
8444 leency 139
	if (streq(tag.get_value_of("http-equiv"), "refresh")) && (tag.get_value_of("content")) {
140
		if (tag.value = strstri(tag.value, "url")) strcpy(#redirect, tag.value);
8439 leency 141
	}
142
}
143
 
8492 leency 144
signed int get_encoding_type_by_name(dword name)
145
{
146
	EDX = name;
147
	if      (streqrp(EDX,"utf-8"))        || (streqrp(EDX,"utf8"))        return CH_UTF8;
148
	else if (streqrp(EDX,"windows-1251")) || (streqrp(EDX,"windows1251")) return CH_CP1251;
149
	else if (streqrp(EDX,"dos"))          || (streqrp(EDX,"cp-866"))      return CH_CP866;
150
	else if (streqrp(EDX,"iso-8859-5"))   || (streqrp(EDX,"iso8859-5"))   return CH_ISO8859_5;
151
	else if (streqrp(EDX,"koi8-r"))       || (streqrp(EDX,"koi8-u"))      return CH_KOI8;
152
	return -1;
153
}
154
 
8439 leency 155
void TWebBrowser::tag_code()
156
{
157
	if (style.pre = tag.opened) {
8451 leency 158
		bg_colors.add(0xe4ffcb);
8439 leency 159
	} else {
8499 leency 160
		if (bg_colors.count>1) bg_colors.pop(); //never pop the last color
8439 leency 161
	}
162
}
163
 
164
void TWebBrowser::tag_ol_ul_dt()
165
{
166
	char type = ESBYTE[#tag.name];
167
	style.tag_list.upd_level(tag.opened, type);
168
	switch(type)
169
	{
170
		case 'd':
171
			if (tag.opened) NewLine();
172
			break;
173
		case 'u':
174
		case 'o':
175
			if (!tag.opened) && (!style.pre) NewLine();
176
	}
177
}
178
 
179
void TWebBrowser::tag_li()
180
{
181
	if (tag.opened) {
182
		if (!style.tag_list.level) style.tag_list.upd_level(1, 'u');
183
		if (!style.pre) NewLine();
184
		if (style.tag_list.order_type() == 'u') {
8492 leency 185
			strcpy(#linebuf, "\31 ");
8462 leency 186
			draw_x = style.tag_list.level * 5 - 2 * list.font_w + left_gap;
8439 leency 187
		}
188
		if (style.tag_list.order_type() == 'o') {
8492 leency 189
			sprintf(#linebuf, "%i. ", style.tag_list.inc_counter());
190
			draw_x = style.tag_list.level * 5 - 1 - strlen(#linebuf) * list.font_w + left_gap;
8439 leency 191
		}
192
	}
193
}
194
 
195
void TWebBrowser::tag_hr()
196
{
9103 leency 197
	dword hrcol = 0x00777777;
8491 leency 198
	if (tag.get_value_of("color")) hrcol = GetColor(tag.value);
199
	if (draw_x != left_gap) NewLine();
9103 leency 200
	if (secondrun) canvas.DrawBar(5, style.cur_line_h / 2 + draw_y - 1, draw_w-10, 1, hrcol);
8500 leency 201
	draw_x++;
8439 leency 202
	NewLine();
203
	return;
204
}
205
 
206
void TWebBrowser::tag_body()
207
{
208
	t_body = tag.opened;
8444 leency 209
	if (tag.get_value_of("link"))   link_color_default = GetColor(tag.value);
210
	if (tag.get_value_of("alink"))  link_color_active = GetColor(tag.value);
211
	if (tag.get_value_of("text"))   text_colors.set(0, GetColor(tag.value));
212
	if (tag.get_value_of("bgcolor")) {
8451 leency 213
		bg_colors.set(0, GetColor(tag.value));
214
		canvas.Fill(0, bg_colors.get(0));
8439 leency 215
	}
216
	// Autodetecting encoding if no encoding was set
217
	if (tag.opened) && (custom_encoding==-1) && (cur_encoding == CH_CP866) {
218
		if (strstr(bufpointer, "\208\190")) ChangeEncoding(CH_UTF8);
219
		else if (chrnum(bufpointer, '\246')>5) ChangeEncoding(CH_CP1251);
220
	}
221
}
222
 
223
void TWebBrowser::tag_q()
224
{
8492 leency 225
	chrncat(#linebuf, '\"', sizeof(TWebBrowser.linebuf));
8439 leency 226
}
227
 
228
void TWebBrowser::tag_h1234_caption()
229
{
230
	if (ESBYTE[#tag.name+1]=='4') {
231
		NewLine();
232
		NewLine();
233
		style.h = tag.opened;
234
		style.b = tag.opened;
235
	} else {
236
		style.h = tag.opened;
237
		if (tag.opened) {
238
			if (!style.pre) NewLine();
239
			draw_y += 10;
8457 leency 240
			list.SetFont(BASIC_CHAR_W*2, 14*2, 10011001b);
8439 leency 241
			list.item_h = BASIC_LINE_H * 2 - 2;
242
			if (tag.is("h1")) style.b = true;
243
		} else {
244
			if (tag.is("h1")) style.b = false;
245
			NewLine();
8457 leency 246
			list.SetFont(BASIC_CHAR_W, 14, 10011000b);
8451 leency 247
			style.cur_line_h = list.item_h = BASIC_LINE_H;
8439 leency 248
		}
249
	}
250
}
251
 
252
 
253
void TWebBrowser::tag_img()
254
{
255
	char img_path[4096]=0;
8462 leency 256
	dword base64img;
8439 leency 257
 
8454 leency 258
	if (!tag.get_value_of("data-large-image"))
259
		if (!tag.get_value_of("data-src"))
260
			if (!tag.get_value_of("src")) return;
8439 leency 261
 
262
	if (streqrp(tag.value, "data:")) {
263
		if (!strstr(tag.value, "base64,")) goto NOIMG;
264
		EDX = EAX+7;
265
		if (ESBYTE[EDX]==' ') EDX++;
8462 leency 266
		base64img = malloc(strlen(EDX));
267
		base64_decode stdcall (EDX, base64img, strlen(EDX));
268
		img_decode stdcall (base64img, EAX, 0);
8439 leency 269
		$push eax
8462 leency 270
		free(base64img);
8439 leency 271
		$pop eax
272
		if (EAX) goto IMGOK; else goto NOIMG;
273
	}
274
 
275
	if (!strcmp(tag.value + strrchr(tag.value, '.'), "svg")) goto NOIMG;
8454 leency 276
	if (!strcmp(tag.value + strrchr(tag.value, '.'), "webp")) goto NOIMG;
277
 
8439 leency 278
	strlcpy(#img_path, tag.value, sizeof(img_path)-1);
8490 leency 279
	replace_char(#img_path, ' ', '\0', sizeof(img_path));
8439 leency 280
	get_absolute_url(#img_path, history.current());
281
 
282
	if (check_is_the_adress_local(#img_path)) {
283
		img_from_file stdcall(#img_path);
284
		if (EAX) goto IMGOK; else goto NOIMG;
285
	}
286
 
287
	if (cache.has(#img_path)) {
288
		img_decode stdcall (cache.current_buf, cache.current_size, 0);
289
		if (EAX) goto IMGOK; else goto NOIMG;
290
	} else {
291
		img_url.add(#img_path);
292
		goto NOIMG;
293
	}
294
 
295
IMGOK:
8462 leency 296
	if (RenderImage(EAX)) return;
8439 leency 297
 
298
NOIMG:
8444 leency 299
	if (tag.get_value_of("title")) || (tag.get_value_of("alt")) {
8492 leency 300
		strncpy(#img_path, tag.value, sizeof(TWebBrowser.linebuf)-3);
301
		sprintf(#linebuf, "[%s]", #img_path);
8439 leency 302
	} else {
303
		if (streqrp(#img_path, "data:")) img_path=0;
304
		replace_char(#img_path, '?', NULL, strlen(#img_path));
8492 leency 305
		img_path[sizeof(TWebBrowser.linebuf)-3] = '\0'; //prevent overflow in sprintf
306
		sprintf(#linebuf, "[%s]", #img_path+strrchr(#img_path, '/'));
307
		linebuf[50]= NULL;
8439 leency 308
	}
309
	text_colors.add(0x9A6F29);
310
	style.image = true;
8491 leency 311
	RenderTextbuf();
8439 leency 312
	style.image = false;
313
	text_colors.pop();
8462 leency 314
}
315
 
316
 
317
 
318
 
9103 leency 319
 
320
 
321
 
322
 
323
 
8500 leency 324
int tdepth;
9103 leency 325
collection_int tr_col_count; //drop on once!
326
int tr_pos, td_pos;
327
int row_start_y;
328
int colcount;
329
dword tallest_cell_in_row;
8492 leency 330
 
331
void TWebBrowser::tag_table_reset()
332
{
8500 leency 333
	tdepth = 0;
9103 leency 334
	colcount = 0;
335
	tr_pos = 0;
336
	td_pos = 0;
8492 leency 337
}
338
 
8462 leency 339
void TWebBrowser::tag_table()
340
{
9103 leency 341
	if (tag.is("table")) {
342
		if(tag.opened) {
343
			tdepth++;
344
		} else {
345
			if (tdepth>0) tdepth--;
346
			if (tdepth==0) {
347
				draw_x = left_gap = style.tag_list.level * 5 * list.font_w + BODY_MARGIN;
348
				draw_w = list.w;
349
 
350
				draw_y = math.max(draw_y+style.cur_line_h, tallest_cell_in_row);
351
				row_start_y = draw_y = tallest_cell_in_row = draw_y;
352
				style.cur_line_h = list.item_h;
353
			}
8492 leency 354
		}
9103 leency 355
	}
356
	if (tdepth>1) {
357
		if (tag.is("tr")) && (tag.opened) NewLine();
358
		return;
359
	}
360
 
361
	if (!secondrun) {
362
		if (tag.is("tr")) {
363
			if (colcount) tr_col_count.set(tr_col_count.count-1, colcount);
364
			colcount = 0;
365
			if (tag.opened) {
366
				tr_col_count.add(1);
367
			}
8492 leency 368
		}
9103 leency 369
		if (tag.opened) && (tag.is("td")) || (tag.is("th")) {
370
			colcount++;
371
			//if (tag.get_number_of("colspan")) colcount += tag.number-1;
8492 leency 372
		}
9103 leency 373
	} else {
374
		if (tag.is("tr")) {
375
			if (tag.opened) {
376
				if (draw_x==left_gap) && (draw_y==BODY_MARGIN) {
377
					row_start_y = tallest_cell_in_row = draw_y;
378
				} else {
379
					row_start_y = tallest_cell_in_row = draw_y = draw_y + style.cur_line_h;
380
				}
381
				style.cur_line_h = list.item_h;
382
				tr_pos++;
383
				td_pos = 0;
8500 leency 384
			} else {
9103 leency 385
				draw_x = left_gap = style.tag_list.level * 5 * list.font_w + BODY_MARGIN;
386
				draw_w = list.w;
387
				draw_y = tallest_cell_in_row;
8500 leency 388
			}
8492 leency 389
		}
9103 leency 390
		if (tr_pos) && (tag.is("td")) || (tag.is("th"))  {
391
			tallest_cell_in_row = math.max(draw_y+style.cur_line_h-list.item_h, tallest_cell_in_row);
392
			style.cur_line_h = list.item_h;
393
			if (tag.opened) {
394
				draw_w = list.w - BODY_MARGIN - BODY_MARGIN - 23 / tr_col_count.get(tr_pos-1);
395
				draw_x = left_gap = draw_w * td_pos + BODY_MARGIN;
396
				//debugval(itoa(draw_x), list.w);
397
				draw_y = row_start_y;
398
				//canvas.WriteText(draw_x, draw_y, 10001001b, 0x0000FE, itoa(draw_x), NULL);
399
				td_pos++;
400
			}
8500 leency 401
		}
9103 leency 402
	}
403
}
8500 leency 404