blink渲染知识6 - floats

本文介绍了网页布局中浮动元素(float)的概念及其使用方法。通过实际示例展示了如何利用CSS声明浮动对象,并探讨了浮动对象如何影响周围文本和其他元素的排列方式。此外,还深入讨论了WebCore如何处理浮动对象,确保文本能够正确绕过这些浮动元素。

Posted by DaveHyatt onWednesday, August 15th, 2007 at 4:33 pm



A float is a renderer that is designed to shift all theway 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 objectavoiding it. You can see an example of a float in this veryparagraph. There is a purple box in the upper right hand corner. Notehow all of the text in this paragraph is avoiding the float.

Here is how the purple float above 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, the align attribute on the img element canbe used to float an image.

<img align=left src="...">



A float can span multiple paragraphs. In this example, eventhough the float was declared inside this paragraph, it is tallenough that it will protrude out of this paragraph and into the nextone.

Because floats can effectively intersect multiple blocks, WebCoreuses a floating objects list on block flows to track all ofthe floating renderers that intrude into the bounds of that block. Asingle float can therefore be in the floating objects lists ofmultiple block flows. Line layout has to be aware of the positions offloats so that it can make sure to shrink lines as necessary to avoidthese floats. By having all of the relevant floats for a given blockimmediately accessible in this floating objects list, it becomes easyfor 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 effectively contains a rectangle (atop, bottom, left and width). The reason each list entry has its ownposition and size that is independent of the floating object’sposition and size is that these coordinates are in the space of theblock that owns the floating objects list. This way each block caneasily query for the float’s position in its own coordinate spacewithout having to do a bunch of conversions.

In addition the margins of the float are included in the listentry rectangles, since lines don’t just avoid the border box ofthe float. They avoid the margin box of the float. This is importantso that floats can be padded with extra space to avoid having linesrun 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 usedto add and remove specific floats from a block’s floating objectslist. clearFloats will delete all of the objects in ablock’s floating objects list.

When an object gets inserted into the list it is unpositionedinitially. Its vertical position is set to -1. ThepositionNewFloats method is called by layout to placeall of the floats. CSS has abunch of rules for where floats are allowed to go. It is thismethod that ensures that all of those rules are obeyed.

There are many more helper methods for working with floats. I willcover these when I talk about block and line layout in more detail infuture articles.

Clearance

CSS



provides a way for objects to specify that they should bebelow either all left floats, all right floats, or all floats. The clear property specifies this behavior and has values of none, left, right or both.

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

You can follow any responses to this entry through the RSS2.0 feed. Both comments and pings are currently closed.



先看效果: https://renmaiwang.cn/s/jkhfz Hue系列产品将具备高度的个性化定制能力,并且借助内置红、蓝、绿三原色LED的灯泡,能够混合生成1600万种不同色彩的灯光。 整个操作流程完全由安装于iPhone上的应用程序进行管理。 这一创新举措为智能照明控制领域带来了新的启示,国内相关领域的从业者也积极投身于相关研究。 鉴于Hue产品采用WiFi无线连接方式,而国内WiFi网络尚未全面覆盖,本研究选择应用更为普及的蓝牙技术,通过手机蓝牙与单片机进行数据交互,进而产生可调节占空比的PWM信号,以此来控制LED驱动电路,实现LED的调光功能以及DIY调色方案。 本文重点阐述了一种基于手机蓝牙通信的LED灯设计方案,该方案受到飞利浦Hue智能灯泡的启发,但考虑到国内WiFi网络的覆盖限制,故而选用更为通用的蓝牙技术。 以下为相关技术细节的详尽介绍:1. **智能照明控制系统**:智能照明控制系统允许用户借助手机应用程序实现远程控制照明设备,提供个性化的调光及色彩调整功能。 飞利浦Hue作为行业领先者,通过红、蓝、绿三原色LED的混合,能够呈现1600万种颜色,实现了全面的定制化体验。 2. **蓝牙通信技术**:蓝牙技术是一种低成本、短距离的无线传输方案,工作于2.4GHz ISM频段,具备即插即用和强抗干扰能力。 蓝牙协议栈由硬件层和软件层构成,提供通用访问Profile、服务发现应用Profile以及串口Profiles等丰富功能,确保不同设备间的良好互操作性。 3. **脉冲宽度调制调光**:脉冲宽度调制(PWM)是一种高效能的调光方式,通过调节脉冲宽度来控制LED的亮度。 当PWM频率超过200Hz时,人眼无法察觉明显的闪烁现象。 占空比指的...
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值