解析html dom 原理,HTML DOM focus() 方法之原理

1支持焦点

W3C规定,只有web page明确设置了tabIndex的Element才定义为支持焦点,他是这么定义一个Node是否支持焦点的:

bool Node::supportsFocus() const

{

return hasRareData() && rareData()->tabIndexSetExplicitly();

}

2 可被设置焦点

首先,Node必须支持焦点,其次,此Node的render对象RenderBox必须存在,而且此RenderBox的style属性设置为可见

bool Node::isFocusable() const

{

if (!inDocument() || !supportsFocus())

return false;

if (renderer())

ASSERT(!renderer()->needsLayout());

else

// If the node is in a display:none tree it might say it needs style recalc but

// the whole document is actually up to date.

ASSERT(!document()->childNeedsStyleRecalc());

// FIXME: Even if we are not visible, we might have a child that is visible.

// Hyatt wants to fix that some day with a "has visible content" flag or the like.

if (!renderer() || renderer()->style()->visibility() != VISIBLE)

return false;

return true;

}

3 按键可获取焦点

一个Element能否获取焦点,取决于:

1)自己“可被设置焦点”

2)tabIndex是正整数

bool Node::isKeyboardFocusable(KeyboardEvent*) const

{

return isFocusable() && tabIndex() >= 0;

}

4 鼠标可获取焦点

只需要判断“可被获取焦点”就行了:

bool Node::isMouseFocusable() const

{

return isFocusable();

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值