⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 html.c

📁 嵌入式下基于MiniGUI的Web Browser
💻 C
📖 第 1 页 / 共 5 页
字号:
/* * File: html.c * * Copyright (C) 1997 Raph Levien <raph@acm.org> * Copyright (C) 1999 James McCollough <jamesm@gtwn.net> * * This program is g_free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. *//* * Dillo HTML parsing routines */#include <ctype.h>#include <string.h>#include <stdlib.h>#include <stdio.h>#include <stdarg.h>#include <errno.h>#include "mgdconfig.h"#include "html.h"#include "dw_widget.h"#include "mgwidget.h"#include "dw_viewport.h"#include "dw_page.h"#include "dw_bullet.h"#include "dw_button.h"#include "dw_hruler.h"#include "dw_table.h"#include "dw_table_cell.h"#include "dw_list_item.h"#include "msg.h"#include "debug.h"#include "list.h"#include "colors.h"#include "prefs.h"#include "cache.h"#include "web.h"#include "dillo.h"#include "interface.h"#include "history.h"#include "nav.h"#include "url.h"#include "progressbar.h"#include "binaryconst.h"#define USE_TABLES#define SGML_SPCDEL 0/*define the ID for all kinds of control*/#define IDC_PASSWORD 1#define IDC_SUBMIT   1DilloPrefs prefs;extern HWND hMainWnd_Global;extern void a_MG_close_client (BrowserWindow* bw, int ClientKey);static int dillo_dbg_rendering = 0;#define DEBUG_LEVEL 10#include "debug.h"//typedef void (*TagFunct) (DilloHtml *Html, char *Tag, int Tagsize);typedef void (*TagOpenFunct) (DilloHtml *Html, char *Tag, gint Tagsize);typedef void (*TagCloseFunct) (DilloHtml *Html, gint TagIdx);#define TAB_SIZE 8/* * Forward declarations */static const char *Html_get_attr(DilloHtml *html,                                 const char *tag,                                 int tagsize,                                 const char *attrname);static const char *Html_get_attr2(DilloHtml *html,                                  const char *tag,                                  int tagsize,                                  const char *attrname,                                  DilloHtmlTagParsingFlags flags);static char *Html_get_attr_wdef(DilloHtml *html,                                const char *tag,                                gint tagsize,                                const char *attrname,                                const char *def);static void Html_add_widget(DilloHtml *html, DwWidget *widget,                            char *width_str, char *height_str,                            DwStyle *style_attrs);static int Html_write_raw(DilloHtml *html, char *buf, int bufsize, int Eof);static void Html_write(DilloHtml *html, char *Buf, int BufSize, int Eof);static void Html_close(DilloHtml *html, int ClientKey);static void Html_callback(int Op, CacheClient_t *Client);static DilloHtml *Html_new(BrowserWindow *bw, const DilloUrl *url);static void Html_tag_open_input(DilloHtml *html, char *tag, int tagsize);static void Html_add_input(DilloHtmlForm *form,                           DilloHtmlInputType type,                           DwMgWidget *widget,                           const char *name,                           const char *init_str,                           DilloHtmlSelect *select,                           gboolean init_val);void Html_submit_form(DilloHtmlLB* html_lb, DilloHtmlForm* form,                      DwWidget* submit);void Html_reset_form(HWND hwnd, int id, int nc, DWORD add_data);static gint Html_tag_index(char *tag);/* exported function */DwWidget *a_Html_text(const char *Type, void *P, CA_Callback_t *Call,                      void **Data);/* * Local Data *//* The following array of font sizes has to be _strictly_ crescent */static const int FontSizes[] = {8, 10, 12, 14, 16, 20};static const int FontSizesNum = 6;static const int FontSizesBase = 2;/* Parsing table structure */typedef struct {   gchar *name;           /* element name */   unsigned char Flags;   /* flags (explained near the table data) */   gchar EndTag;          /* Is it Required, Optional or Forbidden */   guchar TagLevel;       /* Used to heuristically parse bad HTML  */   TagOpenFunct open;     /* Open function */   TagCloseFunct close;   /* Close function */} TagInfo;static const TagInfo Tags[];/* * Return the line number of the tag being processed by the parser. */static int Html_get_line_number(DilloHtml *html){    int i, ofs, line;    const char *p = html->Start_Buf;    if (p == NULL) return -1;    ofs = html->CurrTagOfs;    line = html->OldTagLine;    for (i = html->OldTagOfs; i < ofs; ++i)        if (p[i] == '\n')            ++line;    html->OldTagOfs = html->CurrTagOfs;    html->OldTagLine = line;    return line;}/* * Collect HTML error strings inside the linkblock. */static void Html_msg (DilloHtml *html, const char *format, ... ){    va_list argp;    char buf[512];    snprintf (buf, 512, "HTML warning: line %d, ",                Html_get_line_number(html));    g_string_append (html->linkblock->page_bugs, buf);    va_start (argp, format);    vsnprintf (buf, 512, format, argp);    va_end (argp);    g_string_append (html->linkblock->page_bugs, buf);#if 0    a_Interface_bug_meter_update (html->bw,                                     ++html->linkblock->num_page_bugs);#else#endif}/* * Wrapper for a_Url_new that adds an error detection message. * (if use_base_url is TRUE, html->linkblock->base_url is used) */static DilloUrl *Html_url_new(DilloHtml *html,                              const char *url_str, const char *base_url,                              int flags, Sint32 posx, Sint32 posy,                              int use_base_url){    DilloUrl *url;    int n_ic;    url = a_Url_new (url_str,            (use_base_url) ? base_url : URL_STR_(html->linkblock->base_url),            flags, posx, posy);    if ((n_ic = URL_ILLEGAL_CHARS(url)) != 0)        MSG_HTML("URL has %d illegal character%s (00-1F, 7F or space)\n",                n_ic, (n_ic) > 1 ? "s" : "");    return url;}/* * Set callback function and callback data for "html/text" MIME type. */DwWidget *a_Html_text(const char *Type, void *P, CA_Callback_t *Call,                      void **Data){    DilloWeb *web = P;    DilloHtml *html = Html_new(web->bw, web->url);    *Data = (void *) html;    *Call = (CA_Callback_t) Html_callback;    return html->dw;}/* * We'll make the linkblock first to get it out of the way. */static DilloHtmlLB *Html_lb_new (BrowserWindow *bw, const DilloUrl *url){    DilloHtmlLB *html_lb = g_malloc0 (sizeof (DilloHtmlLB));    html_lb->bw = bw;    html_lb->base_url = a_Url_dup(url);    html_lb->num_forms_max = 1;    html_lb->num_forms = 0;    html_lb->forms = NULL;    html_lb->num_links_max = 1;    html_lb->num_links = 0;    html_lb->links = NULL;    a_Dw_image_map_list_init (&html_lb->maps);    html_lb->link_color = prefs.link_color;    html_lb->visited_color = prefs.visited_color;    html_lb->num_page_bugs = 0;    html_lb->page_bugs = g_string_new("");    return html_lb;}/* * Free the memory used by the linkblock */static void Html_lb_free(void *lb){    int i, j, k;    DilloHtmlForm *form;    DilloHtmlLB *html_lb = lb;    DEBUG_MSG (3, "Html_lb_free called\n");    a_Url_free (html_lb->base_url);    for (i = 0; i < html_lb->num_forms; i++) {        form = &html_lb->forms[i];        a_Url_free (form->action);        for (j = 0; j < form->num_inputs; j++)         {            g_free (form->inputs[j].name);            g_free (form->inputs[j].init_str);            if (form->inputs[j].type == DILLO_HTML_INPUT_SELECT ||                    form->inputs[j].type == DILLO_HTML_INPUT_SEL_LIST) {                for (k = 0; k < form->inputs[j].select->num_options; k++) {                    g_free (form->inputs[j].select->options[k].value);                }                g_free (form->inputs[j].select->options);                g_free (form->inputs[j].select);            }        }        g_free (form->inputs);    }    g_free (html_lb->forms);    for (i = 0; i < html_lb->num_links; i++)        if (html_lb->links[i])            a_Url_free (html_lb->links[i]);    g_free (html_lb->links);    a_Dw_image_map_list_free (&html_lb->maps);    g_string_free (html_lb->page_bugs, TRUE);    g_free (html_lb);}/* * Set the URL data for image maps. */static void Html_set_link_coordinates (DilloHtmlLB *lb,                                      int link, int x, int y){   char data [64];   if (x != -1) {      snprintf (data, 64, "?%d,%d", x, y);      a_Url_set_ismap_coords (lb->links[link], data);   }}/* * Handle the status function generated by the dw scroller, * and show the url in the browser status-bar. */static void Html_handle_status (DwWidget *widget, int link, int x, int y,                               DilloHtmlLB *lb){   DilloUrl *url;   url = (link == -1) ? NULL : lb->links[link];   if (url) {//      Html_set_link_coordinates(lb, link, x, y);      a_Interface_msg(lb->bw, "%s",                         URL_ALT_(url) ? URL_ALT_(url) : URL_STR_(url));      a_Dw_widget_set_cursor (widget, GetSystemCursor (IDC_HAND_POINT));      lb->bw->status_is_link = 1;   } else {      if (lb->bw->status_is_link)         a_Interface_msg(lb->bw, "");      a_Dw_widget_set_cursor (widget, GetSystemCursor (IDC_ARROW));   }}#if 0/* * Popup the link menu ("link_pressed" callback of the page) */{    DwWidget *widget_at_cursor;    gboolean show_oi = FALSE;        Html_set_link_coordinates (lb, link, x, y);        a_Menu_popup_set_url (lb->bw, lb->links[link]);        /* if we've got an image, prepare the image popup */        widget_at_cursor =            a_Dw_gtk_scrolled_window_widget_at_viewport_point (                GTK_DW_SCROLLED_WINDOW (lb->bw->docwin), event->x, event->y);        if (widget_at_cursor && DW_IS_IMAGE (widget_at_cursor)) {            DwImage *image = DW_IMAGE (widget_at_cursor);            /* test image->url (it may have not started to arrive yet!) */            if (image->url) {                /* use the second URL for this popup */                gtk_object_set_data (GTK_OBJECT (lb->bw->menu_popup.over_image),                                "url2", GINT_TO_POINTER(2));                a_Menu_popup_set_url2 (lb->bw, image->url);                show_oi = TRUE;            }        }        a_Menu_popup_ol_show_oi (lb->bw, show_oi);        gtk_menu_popup (GTK_MENU (lb->bw->menu_popup.over_link), NULL, NULL,                        NULL, NULL, event->button, event->time);        return TRUE;    }    return FALSE;}#endif/* * Activate a link ("link_clicked" callback of the page) */static gboolean Html_link_clicked (DwWidget *widget, int link, int x, int y,                                  DWORD flags, DilloHtmlLB *lb){    if (HIWORD (flags) == MSG_LBUTTONUP) {        a_Interface_set_location_text(lb->bw, lb->links[link]->url_string->str);        a_Nav_push(lb->bw, lb->links[link]);    }        else if (HIWORD (flags) == MSG_RBUTTONUP) {        a_Interface_set_location_text(lb->bw, lb->links[link]->url_string->str);    }    else {        return FALSE;    }    if (DW_IS_PAGE (widget))        a_Dw_page_change_link_color (DW_PAGE (widget), link, lb->visited_color);        return TRUE;}#if 0/* * Popup the image menu ("button_press_event" callback of image) */static gboolean Html_image_menu (DwWidget *widget,                                Sint32 x, Sint32 y, GdkEventButton *event,                                BrowserWindow *bw){    DwImage *image = DW_IMAGE (widget);    if (event->button == 3 && image->url) {        a_Menu_popup_set_url (bw, image->url);        gtk_menu_popup(GTK_MENU (bw->menu_popup.over_image), NULL, NULL,                        NULL, NULL, event->button, event->time);        return TRUE;    }    return FALSE;}/* * Popup the page menu ("button_press_event" callback of the viewport) */static int Html_page_menu (MGWidget *viewport, GdkEventButton *event,                          BrowserWindow *bw){    POINT bug_pix;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -