2002-01-16 04:06:26 +03:00
|
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
|
|
|
|
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
|
|
|
|
<title>Space Manager High Level Design</title>
|
|
|
|
<meta name="author" content="Marc Attinasi (attinasi@netscape.com)">
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
|
|
|
|
<h1><font color="#cc0000">Gecko Layout High Level Design Document</font></h1>
|
|
|
|
|
|
|
|
<h1>Space Manager High Level Design</h1>
|
|
|
|
<br>
|
|
|
|
|
|
|
|
<h2>Overview</h2>
|
|
|
|
The Space Manager and associated classes and strructures are used by Block
|
|
|
|
and Line layout to manage rectangular regions that are occupied and available,
|
|
|
|
for correct handling of floated elements and the elements that flow around
|
|
|
|
them. When elements are floated to the left or right in a layout, they
|
|
|
|
take up space and influence where other elements can be placed. The
|
|
|
|
Space Manager is responsible for keeping track of where space is taken up
|
|
|
|
and where it is available. This information is used by block layout to correctly
|
|
|
|
compute where other floated elements should be placed, and how much space
|
|
|
|
is available to normal in-flow elements that flow around the floated bits.<br>
|
|
|
|
<br>
|
|
|
|
The Space Manager works in concert with several other classes to do its
|
|
|
|
job. The classes that are considered part of the Space Manager are:<br>
|
|
|
|
|
|
|
|
<ul>
|
|
|
|
<li>nsSpaceManager</li>
|
|
|
|
<li>nsBandData</li>
|
|
|
|
<li>nsBlockBandData</li>
|
|
|
|
<li>BandRect / BandList (private structs)</li>
|
|
|
|
<li>FrameInfo (private struct)</li>
|
|
|
|
<li>nsBandtrapezoid</li>
|
|
|
|
|
|
|
|
</ul>
|
|
|
|
Outside of the Space Manager itself, the clients of the Space Manager also
|
|
|
|
play an inportant part in the management of he available and used space.
|
2005-11-21 01:05:24 +03:00
|
|
|
The primary classes that interact with the Space Manager are:<br>
|
2002-01-16 04:06:26 +03:00
|
|
|
|
|
|
|
<ul>
|
|
|
|
<li>nsBlockReflowState</li>
|
|
|
|
<li>nsBlockFrame</li>
|
|
|
|
<li>nsBoxToBlockAdaptor</li>
|
|
|
|
|
|
|
|
</ul>
|
|
|
|
The general interaction model is to create a Space Manager for a block
|
|
|
|
frame in the context of a Reflow, and to associate it with the BlockReflowState
|
|
|
|
so it is passed down to child frames' reflow methods. After reflow, the
|
|
|
|
Space Manager is destroyed. During reflow, the space manager stores
|
2003-10-14 01:51:02 +04:00
|
|
|
the space taken up by floats (UpdateSpaceManager in nsBlockFrame) and
|
2002-01-16 04:06:26 +03:00
|
|
|
provides information about the space available for other elements (GetAvailableSpace
|
|
|
|
in nsBlockReflowState). <br>
|
|
|
|
<br>
|
2002-04-26 23:28:27 +04:00
|
|
|
Additionally, there is a need to manage impacts to lines caused by
|
|
|
|
changes to floated elements. This is referred to as Propagation
|
2003-10-14 01:51:02 +04:00
|
|
|
of Float Damage and is handled by the Block Frame, making use of the
|
2002-04-26 23:28:27 +04:00
|
|
|
Space Manager. When a float is incrementally reflowed, the Space
|
2005-11-21 01:05:24 +03:00
|
|
|
Manager is notified if the float's region has changed. If so, the
|
2002-04-26 23:28:27 +04:00
|
|
|
vertical space that has been affected (including both the float's old
|
|
|
|
region and the float's new region) is noted in the internal
|
2003-10-14 01:51:02 +04:00
|
|
|
nsIntervalSet as potential float damage (the method is
|
2002-04-26 23:28:27 +04:00
|
|
|
IncludeInDamage). During the incremental reflow of dirty lines the
|
|
|
|
block frame may encounter lines that are NOT dirty. In this case the
|
2003-10-14 01:51:02 +04:00
|
|
|
Space Manager is also asked if there is any float damage, and
|
2002-04-26 23:28:27 +04:00
|
|
|
if there is then the block further checks to see if that damage
|
|
|
|
intersects the area of the non-dirty line, marking it dirty if there
|
2003-10-14 01:51:02 +04:00
|
|
|
is intersection. Thus, changes to floats on other lines may
|
2002-04-26 23:28:27 +04:00
|
|
|
cause impact to otherwise clean lines, and the Space Manager
|
|
|
|
facilitates the detection of this. <h2>Data Model</h2>
|
2002-01-16 04:06:26 +03:00
|
|
|
|
|
|
|
<h4>Class/Component Diagram</h4>
|
|
|
|
|
|
|
|
<blockquote>
|
2002-02-05 02:28:29 +03:00
|
|
|
<div align="Left"><img src="SpaceManagerClasses.png" alt="SpaceManager Class Diagram" idth="500" eight="459" title="Example Class Diagram">
|
2002-01-16 04:06:26 +03:00
|
|
|
<br>
|
|
|
|
</div>
|
|
|
|
</blockquote>
|
|
|
|
|
|
|
|
<ul>
|
|
|
|
<li>nsSpaceManager: The central point of management of the space taken
|
2003-10-14 01:51:02 +04:00
|
|
|
up by floats in a block</li>
|
2002-01-16 04:06:26 +03:00
|
|
|
<li>nsBandData: Provides information about the frames occupying a band
|
|
|
|
of occupied or available space</li>
|
|
|
|
<li>nsBlockBandData: A specialization of nsBandData that is used by
|
2003-10-14 01:51:02 +04:00
|
|
|
nsBlockReflowState to determine the available space, float impacts, and
|
|
|
|
where floats are cleared. Essentially a CSS-specific wrapper for
|
2002-01-16 04:06:26 +03:00
|
|
|
generic nsBandData.</li>
|
|
|
|
<li>BandRect: Keeps the bounds of a band, along with the frames associated
|
|
|
|
with the band. BandRects are a linked list (provided by PRCListStr
|
|
|
|
super-class) and also provide some geometry-management methods (SplitVertically,
|
|
|
|
SplitHorizontally) and some methods that query or manipulate the frames associated
|
|
|
|
with the band (IsOccupiedBy, AddFrame, RemoveFrame).</li>
|
|
|
|
<li>BandList: A subclass of BandRect that provides a list interface
|
|
|
|
- Head(), Tail(), IsEmpty(), etc.</li>
|
|
|
|
<li>FrameInfo: A structure that keeps information about the rectangle
|
|
|
|
associated with a specific frame, in a linked list.</li>
|
|
|
|
<li>nsBandTrapezoid: Represents the discrete regions within a band that
|
|
|
|
are either Available, Occupied by a single frame, or Occupied by several
|
|
|
|
frames. This is used to communicate information about the space in
|
|
|
|
the band to the clients of the SpaceManager. There is no internal use
|
|
|
|
of the nsBandTrapezoid by the Space Manager, rather it uses its internal
|
|
|
|
BandList to create a BandData collection, which is largely made up of nsTrapezoid
|
|
|
|
data.<br>
|
|
|
|
</li>
|
|
|
|
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
<h2>Use Case</h2>
|
|
|
|
|
2005-11-21 01:05:24 +03:00
|
|
|
<h4>Use Case 1: Space Manager is Created / Destroyed</h4>
|
2002-01-16 04:06:26 +03:00
|
|
|
Space Manager instances are created in the nsBlockFrame's Reflow method.
|
|
|
|
<br>
|
|
|
|
|
|
|
|
<ul>
|
|
|
|
<li>An instance is created </li>
|
2005-11-21 01:05:24 +03:00
|
|
|
<li>The BlockReflowState's previous Space Manager is saved off.</li>
|
|
|
|
<li>The new Space Manager instance is associated with the BlockReflowState.
|
2002-01-16 04:06:26 +03:00
|
|
|
</li>
|
|
|
|
<li>After the block frame's Reflow has completed, the old Space Manager
|
|
|
|
instance is re-associated with the BlockReflowState</li>
|
|
|
|
<li>The new Space Manager is destroyed.</li>
|
|
|
|
|
|
|
|
</ul>
|
|
|
|
If the BlockReflowState already had a Space Manager instance associated
|
|
|
|
with it, it is stored off before being replaced, and the returned to the
|
|
|
|
BlockReflowState instance after the new one has been destroyed. Thus,
|
|
|
|
Space Managers are effectively 'nested' during reflow, with each new block
|
|
|
|
introducing its own Space Manager.
|
2002-02-05 02:28:29 +03:00
|
|
|
|
2003-10-14 01:51:02 +04:00
|
|
|
<h4>Use Case 2: Float is added to the Space Manager</h4> After a Space Manager is created for a block context's reflow chain, a
|
|
|
|
floated block may be added to it. This happens in the method <i>nsBlockReflowState::RecoverFloats</i> and
|
|
|
|
<i>nsBlockReflowState::FlowAndPlaceFloat</i> (formerly this was done in nsBlockFrame::UpdateSpaceManager). <br>
|
2002-02-05 02:28:29 +03:00
|
|
|
<br>
|
2003-10-14 01:51:02 +04:00
|
|
|
The general algorightm in <i>nsBlockReflowState::RecoverFloats</i> is:<br>
|
2002-01-16 04:06:26 +03:00
|
|
|
|
|
|
|
<ul>
|
|
|
|
<li>For each line in the block, see if it has floated blocks</li>
|
2003-10-14 01:51:02 +04:00
|
|
|
<li>If floats are in the line, iterate over the floats and add each
|
2005-11-21 01:05:24 +03:00
|
|
|
one to the Space Manager via the AddRectRegion method. The actual rect
|
2003-10-14 01:51:02 +04:00
|
|
|
for the frame is cached in an nsFloatCache so it does not have to be recomputed.</li>
|
2002-01-16 04:06:26 +03:00
|
|
|
<li>If the block has any block children, then translate the Space Manager
|
|
|
|
to the child block's origin and update the space manager in the context
|
2002-02-05 02:28:29 +03:00
|
|
|
for the child block, recursively. When done with the child, restore the Space
|
2002-01-16 04:06:26 +03:00
|
|
|
Managers coordinates by translating by the negative of the child block's
|
|
|
|
origin. <br>
|
|
|
|
</li>
|
|
|
|
|
2002-02-05 02:28:29 +03:00
|
|
|
</ul><br>
|
|
|
|
|
2003-10-14 01:51:02 +04:00
|
|
|
The general algorightm in <i>nsBlockReflowState::FlowAndPlaceFloat</i> is:<br>
|
2002-02-05 02:28:29 +03:00
|
|
|
<ul>
|
2002-04-26 23:28:27 +04:00
|
|
|
<li>The region that the float currently occupies is recorded.</li>
|
2002-02-05 02:28:29 +03:00
|
|
|
<li>The band of available space is searched (with nsBlockReflowState::GetAvailableSpace);</li>
|
2003-10-14 01:51:02 +04:00
|
|
|
<li>The float frame that is get from the passed nsFloatCache argument is reflowed
|
2005-11-21 09:25:15 +03:00
|
|
|
and its rect is retrieved with GetRect;</li>
|
2003-10-14 01:51:02 +04:00
|
|
|
<li>The floats margins are added;</li>
|
|
|
|
<li>Check if the float can be placed in the acutal band: if not advance to the next band;</li>
|
|
|
|
<li>Check the float type and if it can be added to the space manager;</li>
|
|
|
|
<li>Align the float to its containing block top if rule
|
2002-02-05 02:28:29 +03:00
|
|
|
<a href="http://www.w3.org/TR/REC-CSS2/visuren.html#float-position">CSS2/9.5.1/4</a>
|
|
|
|
is not respected;</li>
|
2003-10-14 01:51:02 +04:00
|
|
|
<li>Add the float using <i>nsSpaceManager::AddRectRegion</i> </li>
|
2002-04-26 23:28:27 +04:00
|
|
|
<li>Compare the area that the float used to occupy with the area that it now occupies: if different,
|
|
|
|
record the vertically affected interval using <i>nsSpaceManager::IncludeInDamage</i></li>
|
2002-02-05 02:28:29 +03:00
|
|
|
</ul>
|
2002-01-16 04:06:26 +03:00
|
|
|
<h4>Use Case 3: Space Manager is used to find available space to reflow
|
|
|
|
into</h4>
|
|
|
|
The nsBlockFrame makes use of the Space Manager indirectly to get the available
|
|
|
|
space to reflow a child block or inline frame into. The block frame uses
|
|
|
|
a helper method on the nsBlockReflowState class to do the actual computation
|
2005-11-21 01:05:24 +03:00
|
|
|
of available space based on the data in the Space Manager. Here is how it
|
2002-01-16 04:06:26 +03:00
|
|
|
works for reflowing an inline frame within a block (this also occurs for
|
|
|
|
reflowing a block frame and, partially, for preparing for a resize reflow).<br>
|
|
|
|
|
|
|
|
<ul>
|
2003-10-14 01:51:02 +04:00
|
|
|
<li>nsBlockFrame first frees all float information for the line that
|
2002-01-16 04:06:26 +03:00
|
|
|
is being reflowed.</li>
|
|
|
|
<li>GetAvailableSpace is called on the BlockReflowState</li>
|
|
|
|
<li>the BlockReflowState calls GetAvailableSpace on its BlockBandData
|
|
|
|
instance (which was setup in the BlockReflowState's constructor based on
|
|
|
|
the SpaceManager passed in and computed content area).</li>
|
|
|
|
<li>BlockBandData then gets the band data from the space manager via
|
|
|
|
a call to the Space Manager associated with the BlockBandData instance.</li>
|
|
|
|
<li>The BlockBandData then walks the collection of trapezoids that were
|
|
|
|
returned by the SpaceManager method GetBandData (as nsBandData wrappers)
|
|
|
|
and determines the right-most edge of the available space.</li>
|
|
|
|
<li>The BlockReflowState then stores this available space rect for use
|
|
|
|
in the rest of the reflow chain.<br>
|
|
|
|
</li>
|
|
|
|
|
|
|
|
</ul>
|
|
|
|
|
2003-10-14 01:51:02 +04:00
|
|
|
<h4>Use Case 4: Propagation of Float Damage: detecting and handling float
|
2002-01-16 04:06:26 +03:00
|
|
|
damage</h4>
|
|
|
|
This process is driven by the Block Frame.<br>
|
|
|
|
|
|
|
|
<ul>
|
|
|
|
<li>A non-dirty line is encountered by the Block Frame in ReflowDirtyLines</li>
|
2003-10-14 01:51:02 +04:00
|
|
|
<li>Block Frame calls its PropagateFloatDamage method</li>
|
2005-11-21 01:05:24 +03:00
|
|
|
<li>The Space Manager is checked to see if there is any float damage</li>
|
2002-01-16 04:06:26 +03:00
|
|
|
<li>If there is, then the block frame asks the Space Manager if the
|
2003-10-14 01:51:02 +04:00
|
|
|
line in question intersects the float damage</li>
|
2002-01-16 04:06:26 +03:00
|
|
|
<li>If the line does intersect a damage interval, then the line is marked
|
|
|
|
dirty</li>
|
|
|
|
<li>If the line does not intersect a damage interval, it may still be
|
|
|
|
marked dirty if:</li>
|
|
|
|
|
|
|
|
<ul>
|
2003-10-14 01:51:02 +04:00
|
|
|
<li>it was impacted by floats before, but is not any longer</li>
|
|
|
|
<li>it was not impacted by floats befre, but is now</li>
|
2002-01-16 04:06:26 +03:00
|
|
|
<li><a name="block-line-impact"></a>
|
2003-10-14 01:51:02 +04:00
|
|
|
it is impacted by floats and is a block<br>
|
2002-01-16 04:06:26 +03:00
|
|
|
</li>
|
|
|
|
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
</ul>
|
|
|
|
<br>
|
|
|
|
|
|
|
|
<hr width="100%" size="2"><br>
|
|
|
|
|
|
|
|
<h1><font color="#ff0000">Problems / bugs found during documentation:</font></h1>
|
|
|
|
|
|
|
|
<ul>
|
|
|
|
<li>BandRect and BandList are public in nsSpaceManager.h - should be
|
|
|
|
private (compiles fine)</li>
|
|
|
|
<li>nsSpaceManager data members are declared protected, but there are
|
|
|
|
no subclasses. Should be private (compiles fine)</li>
|
|
|
|
<li>nsBlockFrame::Paint is mucking with nsBlockBandData in and #if 0
|
|
|
|
block - remove that and the include (compiles fine)</li>
|
2003-10-14 01:51:02 +04:00
|
|
|
<li>nsSpaceManger has no way of clearing the float damage interval
|
2002-01-16 04:06:26 +03:00
|
|
|
set - this might be needed if the SpaceManager persists beyond a Reflow</li>
|
|
|
|
</ul>
|
|
|
|
<br>
|
|
|
|
<br>
|
|
|
|
|
|
|
|
</body>
|
|
|
|
</html>
|