You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Rodent of Unusual Size <co...@decus.org> on 1997/06/17 01:58:42 UTC

[PATCH] to let mod_dir include HEIGHT/WIDTH attributes on icon IMGs

    This patch adds two new options to mod_dir's IndexOptions:
    "IconHeight[=n]" and "IconWidth[=n]".  If both options are present,
    the IMG tags for the FancyIndexing tags will include HEIGHT and
    WIDTH attributes, allowing faster browser real-estate layout while
    the images are loading.  If either of the options is specified
    without an explicit value, the corresponding dimension of the
    default Apache icons (20x22) is used.  E.g.,
    "IndexOptions IconHeight IconWidth" leads to "HEIGHT=22 WIDTH=20",
    and "IndexOptions IconHeight=44 IconWidth" leads to double-height,
    normal-width ("HEIGHT=44 WIDTH=20").

    Two files in the patch: src/mod_dir.c and the documentation,
    htdocs/manual/mod/mod_dir.html.

    #ken    :-)}

Index: mod_dir.c
===================================================================
RCS file: /export/home/cvs/apache/src/mod_dir.c,v
retrieving revision 1.26
diff -c -r1.26 mod_dir.c
*** mod_dir.c	1997/05/13 04:01:50	1.26
--- mod_dir.c	1997/06/15 19:16:47
***************
*** 82,87 ****
--- 82,93 ----
  #define SUPPRESS_SIZE 16
  #define SUPPRESS_DESC 32
  
+ /*
+  * These are the dimensions of the default icons supplied with Apache.
+  */
+ #define DEFAULT_ICON_WIDTH 20
+ #define DEFAULT_ICON_HEIGHT 22
+ 
  struct item {
      char *type;
      char *apply_to;
***************
*** 93,98 ****
--- 99,106 ----
  
      char *default_icon;
      char *index_names;
+     int icon_width;
+     int icon_height;
    
      array_header *icon_list, *alt_list, *desc_list, *ign_list;
      array_header *hdr_list, *rdme_list, *opts_list;
***************
*** 188,193 ****
--- 196,202 ----
  const char *add_opts(cmd_parms *cmd, void *d, const char *optstr) {
      char *w;
      int opts = 0;
+     dir_config_rec *d_cfg = (dir_config_rec *) d;
  
      while(optstr[0]) {
          w = getword_conf(cmd->pool, &optstr);
***************
*** 205,210 ****
--- 214,243 ----
              opts |= SUPPRESS_DESC;
          else if(!strcasecmp(w,"None"))
              opts = 0;
+ 	else if (! strncasecmp (w, "IconWidth", 9)) {
+ 	    if (strchr (w, '=') != NULL) {
+ 		const char *x = pstrdup (cmd->pool, w);
+ 		char *val;
+ 		val = getword (cmd->pool, &x, '=');
+ 		val = getword (cmd->pool, &x, '=');
+ 		d_cfg->icon_width = atoi(val);
+ 	    }
+ 	    else {
+ 		d_cfg->icon_width = DEFAULT_ICON_WIDTH;
+ 	    }
+ 	}
+ 	else if (! strncasecmp (w, "IconHeight", 10)) {
+ 	    if (strchr (w, '=') != NULL) {
+ 		const char *x = pstrdup (cmd->pool, w);
+ 		char *val;
+ 		val = getword (cmd->pool, &x, '=');
+ 		val = getword (cmd->pool, &x, '=');
+ 		d_cfg->icon_height = atoi(val);
+ 	    }
+ 	    else {
+ 		d_cfg->icon_height = DEFAULT_ICON_HEIGHT;
+ 	    }
+ 	}
  	else
  	    return "Invalid directory indexing option";
      }
***************
*** 250,255 ****
--- 283,290 ----
          (dir_config_rec *) pcalloc (p, sizeof(dir_config_rec));
  
      new->index_names = NULL;
+     new->icon_width = 0;
+     new->icon_height = 0;
      new->icon_list = make_array (p, 4, sizeof (struct item));
      new->alt_list = make_array (p, 4, sizeof (struct item));
      new->desc_list = make_array (p, 4, sizeof (struct item));
***************
*** 269,274 ****
--- 304,311 ----
  
      new->default_icon = add->default_icon?add->default_icon:base->default_icon;
      new->index_names = add->index_names? add->index_names: base->index_names;
+     new->icon_height = add->icon_height ? add->icon_height : base->icon_height;
+     new->icon_width = add->icon_width ? add->icon_width : base->icon_width;
  
      new->alt_list = append_arrays (p, add->alt_list, base->alt_list);
      new->ign_list = append_arrays (p, add->ign_list, base->ign_list);
***************
*** 573,581 ****
  
      if(dir_opts & FANCY_INDEXING) {
          rputs("<PRE>", r);
!         if((tp = find_default_icon(d,"^^BLANKICON^^")))
              rvputs(r, "<IMG SRC=\"", escape_html(scratch, tp),
! 		   "\" ALT=\"     \"> ", NULL);
          rputs("Name                   ", r);
          if(!(dir_opts & SUPPRESS_LAST_MOD))
              rputs("Last modified     ", r);
--- 610,629 ----
  
      if(dir_opts & FANCY_INDEXING) {
          rputs("<PRE>", r);
!         if((tp = find_default_icon(d,"^^BLANKICON^^"))) {
              rvputs(r, "<IMG SRC=\"", escape_html(scratch, tp),
! 		   "\" ALT=\"     \"", NULL);
! 	    if (d->icon_width && d->icon_height) {
! 		rprintf
! 		    (
! 			r,
! 			" HEIGHT=\"%d\" WIDTH=\"%d\"",
! 			d->icon_height,
! 			d->icon_width
! 		    );
! 	    }
! 	    rputs ("> ", r);
! 	}
          rputs("Name                   ", r);
          if(!(dir_opts & SUPPRESS_LAST_MOD))
              rputs("Last modified     ", r);
***************
*** 633,640 ****
  		       escape_html(scratch, ar[x]->icon ?
  				   ar[x]->icon : d->default_icon),
  		       "\" ALT=\"[", (ar[x]->alt ? ar[x]->alt : "   "),
! 		       "]\">", NULL);
!             }
              if(dir_opts & ICONS_ARE_LINKS) 
                  rputs("</A>", r);
  
--- 681,698 ----
  		       escape_html(scratch, ar[x]->icon ?
  				   ar[x]->icon : d->default_icon),
  		       "\" ALT=\"[", (ar[x]->alt ? ar[x]->alt : "   "),
! 		       "]\"", NULL);
! 		if (d->icon_width && d->icon_height) {
! 		    rprintf
! 			(
! 			    r,
! 			    " HEIGHT=\"%d\" WIDTH=\"%d\"",
! 			    d->icon_height,
! 			    d->icon_width
! 			);
! 		}
! 		rputs (">", r);
! 	    }
              if(dir_opts & ICONS_ARE_LINKS) 
                  rputs("</A>", r);
  
Index: mod_dir.html
===================================================================
RCS file: /export/home/cvs/apache/htdocs/manual/mod/mod_dir.html,v
retrieving revision 1.6
diff -c -r1.6 mod_dir.html
*** mod_dir.html	1997/06/04 16:14:19	1.6
--- mod_dir.html	1997/06/15 19:17:49
***************
*** 324,329 ****
--- 324,349 ----
  <dd>
  <!--%plaintext &lt;?INDEX {\tt SuppressDescription} index option&gt; -->
  This will suppress the file description in fancy indexing listings.
+ <dt>IconHeight[=pixels]
+ <dd>
+ <!--%plaintext &lt;?INDEX {\tt IconHeight} index option&gt; -->
+ Presence of this option, when used with IconWidth, will cause the server
+ to include <SAMP>HEIGHT</SAMP> and <SAMP>WIDTH</SAMP> attributes in the
+ <SAMP>IMG</SAMP> tag for the file icon.  This allows browser to
+ precalculate the page layout without having to wait until all the
+ images have been loaded.  If no value is given for the option, it
+ defaults to the standard height of the icons supplied with the Apache
+ software.
+ <dt>IconWidth[=pixels]
+ <dd>
+ <!--%plaintext &lt;?INDEX {\tt IconWidth} index option&gt; -->
+ Presence of this option, when used with IconHeight, will cause the server
+ to include <SAMP>HEIGHT</SAMP> and <SAMP>WIDTH</SAMP> attributes in the
+ <SAMP>IMG</SAMP> tag for the file icon.  This allows browser to
+ precalculate the page layout without having to wait until all the
+ images have been loaded.  If no value is given for the option, it
+ defaults to the standard width of the icons supplied with the Apache
+ software.
  </dl>
  This default is that no options are enabled. If multiple IndexOptions
  could apply to a directory, then the most specific one is taken complete;