基于chromium24的HTML5特性实现(input type = week date datetime datetimelocal month time)

inputtype= month (date datetime datetimelocal weektime),把这几个特性拿到一起说是因为它们的实现方法完全一样。以month为例,该特性的实现过程可以分为两步:一是记录type,二是相应事件。

所谓记录type就是webcore在解析网页时记录下该inputtypeType主要分为下面几种(类似color那样需要特殊类支持的排除在外):

enumTextInputType {

//Input caret is not in an editablenode, no input method shall be used.

TEXT_INPUT_TYPE_NONE,


//Input caret is in a normal editablenode, any input method can be used.

TEXT_INPUT_TYPE_TEXT,


//Input caret is in a password box, an input method may be used only if

//it's suitable for password input.

TEXT_INPUT_TYPE_PASSWORD,


TEXT_INPUT_TYPE_SEARCH,

TEXT_INPUT_TYPE_EMAIL,

TEXT_INPUT_TYPE_NUMBER,

TEXT_INPUT_TYPE_TELEPHONE,

TEXT_INPUT_TYPE_URL,

TEXT_INPUT_TYPE_DATE,

TEXT_INPUT_TYPE_DATE_TIME,

TEXT_INPUT_TYPE_DATE_TIME_LOCAL,

TEXT_INPUT_TYPE_MONTH,

TEXT_INPUT_TYPE_TIME,

TEXT_INPUT_TYPE_WEEK,

TEXT_INPUT_TYPE_TEXT_AREA,


//Input caret is in a contenteditablenode (not an INPUT field).

TEXT_INPUT_TYPE_CONTENT_EDITABLE,


TEXT_INPUT_TYPE_MAX= TEXT_INPUT_TYPE_CONTENT_EDITABLE,

};


所有这些type可以分为两类:dialoginputtypetextinputtypemonthweek等前面提到的类型都属于dialoginputtype,而其他的诸如input_type_text的类型都属于textinputtype。这两种类型的区别就是,当点击input时(相应单击事件)所做的反映不同。textinputtype类型的input会弹出输入法,dialoginputtype类型的input则会弹出相应的dialog进行输入。所以第二步响应事件,就是根据type里进行不同的响应。

#0 content::cos::ImeAdapter::attachAndShowIfNeeded (this=0x4b1ea5b0,nativeImeAdapter=0x4b4aa9dc, textInputType=1, text=...,showIfNeeded=true) atcos/content/public/cos/browser/cos_ime_adapter.cc:218

#1 0x61fa4e3e in content::cos::ContentViewCore::imeUpdateAdapter(this=0x4b17adf0, nativeImeAdapterCos=,textInputType=1, text=..., selectionStart=0, selectionEnd=0,compositionStart=-1,

compositionEnd=-1,showImeIfNeeded=true) atcos/content/public/cos/browser/cos_content_view_core.cc:803

#2 0x61f93656 in content::ContentViewCoreImpl::ImeUpdateAdapter(this=, native_ime_adapter=1263184348,text_input_type=1, text=,selection_start=0, selection_end=0,

composition_start=-1,composition_end=-1, show_ime_if_needed=true) atcos/content/browser/cos/content_view_core_impl.cc:1376

#3 0x61f9c132 incontent::RenderWidgetHostViewCos::TextInputStateChanged (this=, params=) atcos/content/browser/renderer_host/render_widget_host_view_cos.cc:343

#4 content::RenderWidgetHostViewCos::TextInputStateChanged (this=, params=) atcos/content/browser/renderer_host/render_widget_host_view_cos.cc:333

#5 0x61f5ec5e incontent::RenderWidgetHostImpl::OnMsgTextInputStateChanged(this=, params=)at content/browser/renderer_host/render_widget_host_impl.cc:1799


上述堆栈是重要函数attachAndShowIfNeeded的调用过程,但单击input的时触发该流程,该函数的一个参数即为type,在该函数中判断进行弹对话框还是弹软键盘。具体实现还算跟平台相关。


该类中还提供一个replaceTextstring)函数,用来取得对话框的值后设置给input,很简单,无需多说

你可能感兴趣的:(chromium)