WML在chromium中实现的补充

21 篇文章 0 订阅
14 篇文章 0 订阅
本文详细介绍了在Chromium中WML文本字段的处理,包括如何判断选择是否在WML文本字段中,以及在事件处理中如何考虑WML文本字段的选择。涉及到的关键函数包括`isSelectionInWMLTextField`、`enclosingFormControl`和`selectionForCommand`等,揭示了Chromium在WML文档中处理编辑操作的内部逻辑。
摘要由CSDN通过智能技术生成

忘记了,还有几个小的修改
Source/core/editing/Editor.cpp
bool isSelectionInTextField(const VisibleSelection& selection)
{
HTMLTextFormControlElement* textControl = enclosingTextFormControl(selection.start());
return textControl && textControl->hasTagName(inputTag) && toHTMLInputElement(textControl)->isTextField();
}

#if ENABLE(WML)
bool isSelectionInWMLTextField(const VisibleSelection& selection)
{
WMLFormControlElement* textControl = enclosingFormControl(selection.start());
return textControl && textControl->hasTagName(WMLNames::inputTag) && toWMLInputElement(textControl)->isTextField();

}
#endif

} // namespace

// When an event handler has moved the selection outside of a text control
// we should use the target control’s selection for this editing operation.
VisibleSelection Editor::selectionForCommand(Event* event)
{
VisibleSelection selection = m_frame->selection()->selection();
if (!event)
return selection;
// If the target is a text control, and the current selection is outside of its shadow tree,
// then use the saved selection for that text control.
#if ENABLE(WML)
if (m_frame->document()->isWMLDocument()) {
WMLFormControlElement* textFormControlOfSelectionStart = enclosingFormControl(selection.start());
WMLFormControlElement* textFromControlOfTarget = isWMLFormControlElement(event->target()->toNode()) ? toWMLFormControlElement(event->target()->toNode()) : 0;
if (textFromControlOfTarget && (selection.start().isNull() || textFromControlOfTarget != textFormControlOfSelectionStart)) {
if (RefPtr range = textFromControlOfTarget->selection())
return VisibleSelection(range.get(), DOWNSTREAM, selection.isDirectional());
}
} else {
#endif
HTMLTextFormControlElement* textFormControlOfSelectionStart = enclosingTextFormControl(selection.start());
HTMLTextFormControlElement* textFromControlOfTarget = isHTMLTextFormControlElement(event->target()->toNode()) ? toHTMLTextFormControlElement(event->target()->toNode()) : 0;
if (textFromControlOfTarget && (selection.start().isNull() || textFromControlOfTarget != textFormControlOfSelectionStart)) {
if (RefPtr range = textFromControlOfTarget->selection())
return VisibleSelection(range.get(), DOWNSTREAM, selection.isDirectional());
}
void Editor::setBaseWritingDirection(WritingDirection direction)
{
Node* focusedElement = frame()->document()->focusedElement();
#if ENABLE(WML)
if (focusedElement->isWMLElement()) {
if (focusedElement && isWMLFormControlElement(focusedElement)) {
if (direction == NaturalWritingDirection)
return;
toWMLElement(focusedElement)->setAttribute(dirAttr, direction == LeftToRightWritingDirection ? “ltr” : “rtl”);
focusedElement->dispatchInputEvent();
frame()->document()->updateStyleIfNeeded();
return;
}
} else {
#endif
void Editor::textFieldDidBeginEditing(Element* e)
{
if (isContinuousSpellCheckingEnabled()) {
#if ENABLE(WML)
if (e->isWMLElement()) {
Element* element = toWMLFormControlElement(e)->innerTextElement();
VisibleSelection selection = VisibleSelection::selectionFromContentsOfNode(element);
markMisspellingsAndBadGrammar(selection);
} else {
#endif
Element* element = toHTMLTextFormControlElement(e)->innerTextElement();
VisibleSelection selection = VisibleSelection::selectionFromContentsOfNode(element);
markMisspellingsAndBadGrammar(selection);
#if ENABLE(WML)
}
#endif
}
}

void Editor::textFieldDidEndEditing(Element* e)
{
// Remove markers when deactivating a selection in an .
// Prevent new ones from appearing too.
m_spellChecker->cancelCheck();
HTMLElement* innerText;
#if ENABLE(WML)
if (e->isWMLElement()) {
WMLFormControlElement* textFormControlElement = toWMLFormControlElement(e);
innerText = textFormControlElement->innerTextElement();
} else {
#endif
void Editor::respondToChangedSelection(const VisibleSelection& oldSelection, FrameSelection::SetSelectionOptions options)
if (shouldCheckSpellingAndGrammar
&& closeTyping
&& oldSelection.isContentEditable()
&& oldSelection.start().deprecatedNode()
&& oldSelection.start().anchorNode()->inDocument()
&& (!(m_frame->document()->isWMLDocument() && isSelectionInWMLTextField(oldSelection))
||!(!m_frame->document()->isWMLDocument() && isSelectionInTextField(oldSelection)))) {
void Editor::spellCheckAfterBlur()
{
if (!m_frame->selection()->selection().isContentEditable())
return;

if (m_frame->document()->isWMLDocument() && isSelectionInWMLTextField(m_frame->selection()->selection()))
    return;
if (!m_frame->document()->isWMLDocument() && isSelectionInTextField(m_frame->selection()->selection())) {     
    // textFieldDidEndEditing() and textFieldDidBeginEditing() handle this.        

inline HTMLInputElement* toHTMLInputElement(Node* node)
{
ASSERT_WITH_SECURITY_IMPLICATION(!node || node->hasTagName(HTMLNames::inputTag));
if(node && node->isWMLElement())
return NULL;
return static_cast<HTMLInputElement*>(node);
}

Source/core/html/HTMLInputElement.h

inline const HTMLInputElement* toHTMLInputElement(const Node* node)
{
ASSERT_WITH_SECURITY_IMPLICATION(!node || node->hasTagName(HTMLNames::inputTag));
if(node && node->isWMLElement())
return NULL;
return static_cast<const HTMLInputElement*>(node);
}

Source/core/html/HTMLTextFormControlElement.h
inline HTMLTextFormControlElement* toHTMLTextFormControlElement(Node* node)
{
if (node && node->isWMLElement())
return NULL;

Source/core/html/TextFieldInputType.cpp
wmlelement()->setValueFromRenderer(sanitizeValue(convertFromVisibleValue(wmlelement()->innerTextValue())));

Source/core/wml/WMLFormControlElement.cpp
Element::defaultEventHandler(event);

Source/web/EditorClientImpl.cpp
void EditorClientImpl::textFieldDidEndEditing(Element* element)
{
#if ENABLE(WML)
if (element->hasTagName(WMLNames::inputTag))
return;
#endif
if (m_webView->autofillClient() && element->hasTagName(HTMLNames::inputTag))
m_webView->autofillClient()->textFieldDidEndEditing(WebInputElement(toHTMLInputElement(element)));

// Notification that focus was lost.  Be careful with this, it's also sent
// when the page is being closed.

// Hide any showing popup.
m_webView->hideAutofillPopup();

}

void EditorClientImpl::textDidChangeInTextField(Element* element)
{
#if ENABLE(WML)
if (element->hasTagName(WMLNames::inputTag))
return;
#endif
HTMLInputElement* inputElement = toHTMLInputElement(element);
if (m_webView->autofillClient())
m_webView->autofillClient()->textFieldDidChange(WebInputElement(inputElement));
}

bool EditorClientImpl::doTextFieldCommandFromEvent(Element* element,
KeyboardEvent* event)
{
#if ENABLE(WML)
if (element->hasTagName(WMLNames::inputTag))
return false;
#endif

Source/web/WebNode.cpp
bool WebNode::isWMLElement() const
{
return m_private->isWMLElement();
}

Source/web/WebViewImpl.cpp

if (element->hasTagName(WMLNames::inputTag)) {
    WMLInputElement* input = toWMLInputElement(element);
    if (input->isPasswordField())
        return WebTextInputTypePassword;
    if (input->isTextField())
        return WebTextInputTypeText;

    return WebTextInputTypeNone;
}
if (isHTMLTextAreaElement(element)) {
    if (toHTMLTextAreaElement(element)->isDisabledOrReadOnly())
        return WebTextInputTypeNone;
    return WebTextInputTypeTextArea;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值