changeset 698:602ab87f6cd2

Patch for CSS stylesheet loading part#2
author Jorge Arellano Cid <jcid@dillo.org>
date Sun, 21 Dec 2008 16:40:36 -0300
parents 0179a1a1fd0c
children c661fbf968ad
files ChangeLog src/bw.c src/bw.h src/html.cc src/html_common.hh src/nav.c
diffstat 6 files changed, 24 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sat Dec 20 23:46:06 2008 +0100
+++ b/ChangeLog	Sun Dec 21 16:40:36 2008 -0300
@@ -43,6 +43,7 @@
  ? Trying a new iconv() test in configure.in.
  - Allowed the rc parser to skip whitespace around the equal sign.
  - Fixed the parser not to call Html_tag_close_* functions twice.
+ - Implemented CSS Stylesheet loading.
    Patches: Jorge Arellano Cid
 
 dw
--- a/src/bw.c	Sat Dec 20 23:46:06 2008 +0100
+++ b/src/bw.c	Sun Dec 21 16:40:36 2008 -0300
@@ -63,6 +63,7 @@
    bw->ImageClients = dList_new(8);
    bw->NumImages = 0;
    bw->NumImagesGot = 0;
+   bw->NumPendingStyleSheets = 0;
    bw->PageUrls = dList_new(8);
    bw->Docs = dList_new(8);
 
@@ -253,6 +254,9 @@
    /* Zero image-progress data */
    bw->NumImages = 0;
    bw->NumImagesGot = 0;
+
+   /* Zero stylesheet counter */
+   bw->NumPendingStyleSheets = 0;
 }
 
 /*--------------------------------------------------------------------------*/
--- a/src/bw.h	Sat Dec 20 23:46:06 2008 +0100
+++ b/src/bw.h	Sun Dec 21 16:40:36 2008 -0300
@@ -38,6 +38,8 @@
    int NumImages;
    /* Number of images already loaded */
    int NumImagesGot;
+   /* Number of not yet arrived style sheets */
+   int NumPendingStyleSheets;
    /* List of all Urls requested by this page (and its types) */
    Dlist *PageUrls;
 
@@ -57,8 +59,7 @@
     * redirection loops (accounts for WEB_RootUrl only) */
    int redirect_level;
 
-   /* TODO: maybe this fits better in the linkblock.
-    * Although having it here avoids having a signal for handling it. */
+   /* HTML-bugs detected at parse time */
    int num_page_bugs;
    Dstr *page_bugs;
 };
--- a/src/html.cc	Sat Dec 20 23:46:06 2008 +0100
+++ b/src/html.cc	Sun Dec 21 16:40:36 2008 -0300
@@ -430,7 +430,6 @@
    stop_parser = false;
    stop_parser_after_head = false;
    repush_after_head = false;
-   repush_after_stylesheet = false;
 
    CurrTagOfs = 0;
    OldTagOfs = 0;
@@ -2907,12 +2906,17 @@
    }
 }
 
+/*
+ * Called by the network engine when a stylesheet has new data.
+ */
 static void Html_css_load_callback(int Op, CacheClient_t *Client)
 {
-   MSG("Css_callback: Op=%d\n", Op);
+   _MSG("Css_callback: Op=%d\n", Op);
    if (Op) { /* EOF */
-      // May check num_style_sheets here...
-      a_Nav_repush(((DilloWeb *)Client->Web)->bw);
+      BrowserWindow *bw = ((DilloWeb *)Client->Web)->bw;
+      /* Repush when we've got them all */
+      if (--bw->NumPendingStyleSheets == 0)
+         a_Nav_repush(bw);
    }
 }
 
@@ -2935,9 +2939,11 @@
       Web->bw = html->bw;
       //Web->flags |= WEB_Stylesheet;
       if ((ClientKey = a_Capi_open_url(Web, Html_css_load_callback, NULL))) {
-         html->repush_after_stylesheet = true;
+         ++html->bw->NumPendingStyleSheets;
          a_Bw_add_client(html->bw, ClientKey, 0);
          a_Bw_add_url(html->bw, url);
+         MSG("Html_load_stylesheet: NumPendingStyleSheets=%d\n",
+             html->bw->NumPendingStyleSheets);
       }
    }
 }
@@ -2964,9 +2970,6 @@
       BUG_MSG("the LINK element must be inside the HEAD section\n");
       return;
    }
-   /* Load only one stylesheet by now... */
-   if (html->repush_after_stylesheet)
-      return;
 
    /* TODO: How will we know when to use "handheld"? Ask the html->bw->ui for
       screen dimensions, or a dillorc preference. */
@@ -2985,8 +2988,7 @@
       return;
 
    MSG("  Html_tag_open_link(): URL=%s\n", URL_STR(url));
-   MSG("    repush after HEAD=%d SHEET=%d\n",
-       html->repush_after_head, html->repush_after_stylesheet);
+   MSG("    repush after HEAD=%d\n", html->repush_after_head);
 
    Html_load_stylesheet(html, url);
    a_Url_free(url);
--- a/src/html_common.hh	Sat Dec 20 23:46:06 2008 +0100
+++ b/src/html_common.hh	Sun Dec 21 16:40:36 2008 -0300
@@ -174,7 +174,6 @@
 
    bool stop_parser_after_head;
    bool repush_after_head;
-   bool repush_after_stylesheet;
 
    size_t CurrTagOfs;
    size_t OldTagOfs, OldTagLine;
--- a/src/nav.c	Sat Dec 20 23:46:06 2008 +0100
+++ b/src/nav.c	Sun Dec 21 16:40:36 2008 -0300
@@ -194,12 +194,13 @@
 static void Nav_open_url(BrowserWindow *bw, const DilloUrl *url, int offset)
 {
    DilloUrl *old_url;
-   bool_t MustLoad, ForceReload;
+   bool_t MustLoad, ForceReload, Repush;
    int x, y, idx, ClientKey;
    DilloWeb *Web;
 
    MSG("Nav_open_url: new url='%s'\n", URL_STR_(url));
 
+   Repush = (URL_FLAGS(url) & URL_ReloadFromCache);
    ForceReload = (URL_FLAGS(url) & (URL_E2EQuery + URL_ReloadFromCache)) != 0;
 
    /* Get the url of the current page */
@@ -207,8 +208,8 @@
    old_url = a_History_get_url(NAV_UIDX(bw, idx));
    _MSG("Nav_open_url:  old_url='%s' idx=%d\n", URL_STR(old_url), idx);
    /* Record current scrolling position */
-   if (URL_FLAGS(url) & URL_ReloadFromCache) {
-      /* Repush operation, don't change scroll position */
+   if (Repush) {
+      /* Don't change scroll position */
    } else if (old_url) {
       a_UIcmd_get_scroll_xy(bw, &x, &y);
       Nav_save_scroll_pos(bw, idx, x, y);