W3C home > Mailing lists > Public > www-style@w3.org > January 2008

Re: scroll bar size in width calculations

From: Andrew Fedoniouk <news@terrainformatica.com>
Date: Tue, 08 Jan 2008 00:27:25 -0800
Message-ID: <478333ED.2050008@terrainformatica.com>
To: robert@ocallahan.org
CC: Brad Kemper <brkemper@comcast.net>, Rossen Atanassov <ratan@windows.microsoft.com>, fantasai <fantasai.lists@inkedblade.net>, Alex Mogilevsky <alexmog@exchange.microsoft.com>, CSS Style <www-style@w3.org>, Sam Fortiner <samfort@microsoft.com>, Harel Williams <harelw@microsoft.com>, Scott Dickens <sdickens@exchange.microsoft.com>, Boris Zbarsky <bzbarsky@mit.edu>
Robert O'Callahan wrote:
> On Jan 8, 2008 8:39 PM, Andrew Fedoniouk <news@terrainformatica.com 
> <mailto:news@terrainformatica.com>> wrote:
> 
>     Height of HTML document by its nature is a function from its width.
>       height = F( width )
>     When this height exceeds height of the view then v-scrollbar appears
>     that is effectively changes 'width' in the equation above so you have
>     second dependency:
>       width = B( height )
> 
>     System of these two equitations is a classical "positive feedback"
>     condition. Solution of such a system may "hunt" or oscillate at some
>     input values ( e.g. when intrinsic dimensions of the content is close to
>     the size of the view). More on this: Nyquist criterion [1] and around.
> 
>  
> It's not that bad because there are only 4 possible solutions to the 
> scrollbar problem: show/hide vertical scrollbar x show/hide horizontal 
> scrollbar. In the worst case you can check each of these solutions to 
> see which ones are feasible, where "feasible" means that each scrollbar 
> is showing if and only if it is needed. If multiple solutions are 
> feasible, then you pick one using whatever heuristic you like. Our 
> heuristics are basically, in order of priority,
> 1) prefer to show no scrollbars
> 2) prefer to preserve the current vertical scrollbar visibility (this is 
> for performance, showing/hiding the vertical scrollbar changes the 
> available width of the contents, so it's expensive)
> 3) prefer to hide the horizontal scrollbar (showing/hiding the 
> horizontal scrollbar is cheap)
> 
> If no solutions are feasible then we show whatever scrollbars we're 
> allowed to, so at least the user can scroll to see all the content.
> 
> http://mxr.mozilla.org/seamonkey/source/layout/generic/nsGfxScrollFrame.cpp#606
> if you're interested :-).
> 

I am not sure but that appears as a bit complicated.
Here (in attachment) is what I have here. Not ideal too but works.
Hope it will help to find something better.

Regards.

-- 
Andrew Fedoniouk.

http://terrainformatica.com

   
  void block::update_scrollbars( view& v )
  {
      const style& cs = current_style(v);
      int overflow_x = cs.overflow_x;
      int overflow_y = cs.overflow_y;

      bool hsb_needed = (overflow_x == overflow_auto || overflow_x == overflow_scroll);
      bool vsb_needed = (overflow_y == overflow_auto || overflow_y == overflow_scroll);
      
      // 'sb' here is a scrollbar control structure - sb.hsb and sb.vsb are pointers to
      // struct scrollbar instances. 

      if( sb.hsb == 0 && !hsb_needed && sb.vsb == 0 && !vsb_needed )
        return;

      scroll_data scd;
      get_scroll_data(v,scd);
      
      for(int i = 0; i < 2; ++i)
      {
        int  minwidth    = scd.dim_doc.x;  
        bool relayout_y  =  !hsb_needed?
                            sb.remove_h():
                            sb.set_h(scd.pos.x, 0, minwidth, scd.dim_view.x, overflow_x == overflow_scroll);
        if( relayout_y) 
        {
          set_height(v, dim.y);
          get_scroll_data(v,scd);
        }
        int  minheight   = scd.dim_doc.y; 
        bool relayout_x  = !vsb_needed?
                            sb.remove_v():
                            sb.set_v(scd.pos.y, 0, minheight, scd.dim_view.y, overflow_y == overflow_scroll);
        if( relayout_x )
        {
          do_measure(v);
          set_height(v, dim.y);
          get_scroll_data(v,scd);
        }
        else if ( minwidth  == scd.dim_doc.x)
          break;
      }
      point sp;
      sp.y = limit(scd.pos.y,0,scd.dim_doc.y-scd.dim_view.y);
      sp.x = limit(scd.pos.x,0,scd.dim_doc.x-scd.dim_view.x);
      if( scd.pos != sp )
        scroll_pos(sp);

      sb.refresh(v, this);
  }
  
Received on Tuesday, 8 January 2008 08:27:31 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 27 April 2009 13:54:57 GMT