基础界面库的类结构
基础界面库位于src\ui\views目录下,定义了 跨平台 的组件,是Chromium界面的基础,顶层chrome/browser/ui/下的类都继承或使用这些基础类。
关于Widget静态图
下面是Widget及内部结构的类图,类关系做了简化,只显示较关键的联系。
Widget内组件布局
- 总体来说,Widget是最底层的UI组件(此处不区分Widget和NativeWidget,后面讨论其关系),与本地(Native)平台交互,处理平台相关的消息、事件等,转换到Chromium UI体系内。
- 为了统一处理视图组件的消息事件,Widget内定义了一个根视图RootView
- NonClientView是RootView的唯一孩子,也是其它所有视图的逻辑根 (为什么RootView和NonClientView不合并为一个视图?)
- NonClientFrameView 是NonClientView孩子之一,负责非客户区的绘制和消息处理,根据不同的系统会有不同的实现,比如Windows下有OpaqueFrameView和GlassFrameView,非客户区一般包括窗口控制按钮(最大化,最小化,关闭)和标题栏(Title bar)
- ClientView 是另一个孩子,负责客户区的绘制和消息处理,客户区包括工具栏、标签栏、地址栏、页面等。
// The NonClientView is the logical root of all Views contained within a
// Window, except for the RootView which is its parent and of which it is the
// sole child. The NonClientView has two children, the NonClientFrameView which
// is responsible for painting and responding to events from the non-client
// portions of the window, and the ClientView, which is responsible for the
// same for the client area of the window:
//
// +- views::Widget ------------------------------------+
// | +- views::RootView ------------------------------+ |
// | | +- views::NonClientView ---------------------+ | |
// | | | +- views::NonClientFrameView subclas ---+ | | |
// | | | | | | | |
// | | | | << all painting and event receiving >> | | | |
// | | | | << of the non-client areas of a >> | | | |
// | | | | << views::Widget. >> | | | |
// | | | | | | | |
// | | | +----------------------------------------+ | | |
// | | | +- views::ClientView or subclass --------+ | | |
// | | | | | | | |
// | | | | << all painting and event receiving >> | | | |
// | | | | << of the client areas of a >> | | | |
// | | | | << views::Widget. >> | | | |
// | | | | | | | |
// | | | +----------------------------------------+ | | |
// | | +--------------------------------------------+ | |
// | +------------------------------------------------+ |
// +----------------------------------------------------+
//
// The NonClientFrameView and ClientView are siblings because due to theme
// changes the NonClientFrameView may be replaced with different
// implementations (e.g. during the switch from DWM/Aero-Glass to Vista Basic/
// Classic rendering).
类关系(Class Relationship)的建立
1 | void Widget::Init(const InitParams& params) { |
总结
Chromium UI的目标是一套跨平台的方案,其中NativeWidget实现了平台相关的细节,Widget才是跨平台的组件,与NativeWidget做了映射。Widget是Windows组件,而Chromium UI的其它组件都是基于View建立的,所以需要一个RootView做中转,将窗口事件转换到View体系中,又作为其它View的根。