Skip to content

Latest commit

 

History

History
41 lines (31 loc) · 1.63 KB

File metadata and controls

41 lines (31 loc) · 1.63 KB

任务

构建一个ElementTree

ElementTree介绍

ElementTree是提供给用户使用的,用户构造一颗ElementTree来表示富文本结构。

构成ElementTree的节点有:

  • Block:块级元素,布局类似CSS中的 display: block,布局效果参考 CSSLayout.md 文件
  • InlineBlock:内联块级元素,布局类似CSS中的 display: inline-block,布局效果参考 CSSLayout.md 文件
  • Inline:内联元素,布局类似CSS中的 display: inline,布局效果参考 CSSLayout.md 文件
  • Text:文本元素
  • Attachment:自定义附件,用户可以通过Attachment来插入图片、自定义View等

每一个节点都会有 Style 属性,用于节点样式,Style中的属性有:

  • width/height
  • minWidth/minHeight
  • maxWidth/maxHeight
  • marginTop/marginRight/marginBottom/marginLeft
  • paddingTop/paddingRight/paddingBottom/paddingLeft
  • font
  • color:前景色
  • backgroundColor:背景色
  • borderWidth:边框宽度
  • borderColor:边框颜色
  • cornerRadius:圆角大小
  • texttDecoration:枚举,表示划线类型,需要支持:下划线、删除线
  • fontStyle:枚举,表示字体样式,需要支持:普通样式、斜体

注意

  1. 每种类型的节点可以选择性响应Style中的属性,不需要所有属性都响应,尽量对齐CSS的规范。
  2. Style 中属性支持继承,以font为例,子元素如果没有指定font,可以继承父元素的font属性;哪些属性支持继承,需要对齐CSS的规范

单元测试

针对ElementTree写单元测试,要求覆盖如下场景:

  • Style的属性继承生效
  • Element 的添加、删除子元素生效