WebCore rendering V-floats

Source: Internet
Author: User
WebCore rendering V-floats

PostedDave HyattOn Wednesday, August 15th, 2007 at pm

AFloatIs a Renderer that is designed to shift all the way to the left side or all the way to the right side of a paragraph. the lines of the paragraph then flow around the floating object avoiding it. you can see an example of a float in this very paragraph. there is a purple box in the upper right hand corner. note how all of the text in this paragraph is avoiding the float.

Here is how the purple float abve was declared:

<div style="float:right; width:50px; height:50px; background-color:purple; margin-left: 5px"></div>

There are also HTML constructs that imply CSS floating behavior. For example,AlignAttribute onIMGElement can be used to float an image.

A float can span multiple paragraphs. In this example, even though the float was declared inside this paragraph, it is tall enough that it will protrude out of this paragraph and into the next one.

Because floats can define tively intersect multiple blocks, WebCore usesFloating Objects listOn Block flows to track all of the floating renderers that intrude into the bounds of that block. A single float can therefore be in the floating objects lists of multiple block flows. line Layout has to be aware of the positions of floats so that it can make sure to shrink lines as necessary to avoid these floats. by having all of the relevant floats for a given block immediately accessible in this floating objects list, it becomes easy for that block to know where the floats are that it needs to avoid.

A floating objects list contains the following data structure:

    struct FloatingObject {        enum Type {            FloatLeft,            FloatRight        };        FloatingObject(Type type)            : node(0)            , startY(0)            , endY(0)            , left(0)            , width(0)            , m_type(type)            , noPaint(false)        {        }        Type type() { return static_cast<type>(m_type); }        RenderObject* node;        int startY;        int endY;        int left;        int width;        unsigned m_type : 1; // Type (left or right aligned)        bool noPaint : 1;    };

As you can see, this structure implements tively contains a rectangle (a top, bottom, left and width ). the reason each list entry has its own position and size that is independent of the floating object's position and size is that these coordinates are in the space of the block that owns the floating objects list. this way each block can easily query for the float's position in its own coordinate space without having to do a bunch of conversions.

In addition the margins of the float are encoded in the List entry rectangles, since lines don't just avoid the border box of the float. they avoid the margin box of the float. this is important so that floats can be padded with extra space to avoid having lines run right up to their edges.

The following methods operate on the floating objects list:

void insertFloatingObject(RenderObject*);void removeFloatingObject(RenderObject*);void clearFloats();void positionNewFloats();

The first two functions are pretty self-explanatory. They are used to add and remove specific floats from a block's floating objects list.clearFloatsWill delete all of the objects in a block's floating objects list.

When an object gets inserted into the list it is unpositioned initially. Its vertical position is set-1.positionNewFloatsMethod is called by layout to place all of the floats. CSS has a bunch of rules for where floats are allowed to go. It is this method that ensures that all of those rules are obeyed.

There are more helper methods for working with floats. I will cover these when I talk about block and line layout in more detail in future articles.

Clearance

CSS provides a way for objects to specify that they shoshould be below either all left floats, all Right floats, or all floats.ClearProperty specifies this behavior and has valuesNone,Left,RightOrBoth.

This paragraph is below the blue float from the previous paragraph because it specified clear: left. Clearance is computed and applied during block and line layout. the clear property can also be applied to floats to make sure that a float ends up below all previous floats (again, either left, right or both types of floats ).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.