⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 html_formimpl.cpp

📁 monqueror一个很具有参考价值的源玛
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    bool successful = false;    uint i;    for (i = 0; i < m_listItems.size(); i++) {        if (m_listItems[i]->id() == ID_OPTION) {            HTMLOptionElementImpl *option = static_cast<HTMLOptionElementImpl*>(m_listItems[i]);            if (option->selected()) {                if (option->value().isNull())                    encoded_values += option->text().string().stripWhiteSpace().local8Bit();                else                    encoded_values += option->value().string().local8Bit();                successful = true;            }        }    }    // ### this case should not happen. make sure that we select the first option    // in any case. otherwise we have no consistency with the DOM interface. FIXME!    // we return the first one if it was a combobox select    if (!successful && !m_multiple && m_size <= 1 && m_listItems.size() &&        (m_listItems[0]->id() == ID_OPTION) ) {        HTMLOptionElementImpl *option = static_cast<HTMLOptionElementImpl*>(m_listItems[0]);        if (option->value().isNull())            encoded_values += option->text().string().stripWhiteSpace().local8Bit();        else            encoded_values += option->value().string().local8Bit();        successful = true;    }    return successful;}int HTMLSelectElementImpl::optionToListIndex(int optionIndex) const{    if (optionIndex < 0 || optionIndex >= int(m_listItems.size()))        return -1;    int listIndex = 0;    int optionIndex2 = 0;    for (;         optionIndex2 < int(m_listItems.size()) && optionIndex2 <= optionIndex;         listIndex++) { // not a typo!        if (m_listItems[listIndex]->id() == ID_OPTION)            optionIndex2++;    }    listIndex--;    return listIndex;}int HTMLSelectElementImpl::listToOptionIndex(int listIndex) const{    if (listIndex < 0 || listIndex >= int(m_listItems.size()) ||        m_listItems[listIndex]->id() != ID_OPTION)        return -1;    int optionIndex = 0; // actual index of option not counting OPTGROUP entries that may be in list    int i;    for (i = 0; i < listIndex; i++)        if (m_listItems[i]->id() == ID_OPTION)            optionIndex++;    return optionIndex;}void HTMLSelectElementImpl::recalcListItems(){    NodeImpl* current = firstChild();    bool inOptGroup = false;    m_listItems.resize(0);    bool foundSelected = false;    while(current) {        if (!inOptGroup && current->id() == ID_OPTGROUP && current->firstChild()) {            // ### what if optgroup contains just comments? don't want one of no options in it...            m_listItems.resize(m_listItems.size()+1);            m_listItems[m_listItems.size()-1] = static_cast<HTMLGenericFormElementImpl*>(current);            current = current->firstChild();            inOptGroup = true;        }        if (current->id() == ID_OPTION) {            m_listItems.resize(m_listItems.size()+1);            m_listItems[m_listItems.size()-1] = static_cast<HTMLGenericFormElementImpl*>(current);            if (foundSelected && !m_multiple && static_cast<HTMLOptionElementImpl*>(current)->selected())                static_cast<HTMLOptionElementImpl*>(current)->setSelected(false);            foundSelected = static_cast<HTMLOptionElementImpl*>(current)->selected();        }        NodeImpl *parent = current->parentNode();        current = current->nextSibling();        if (!current) {            if (inOptGroup) {                current = parent->nextSibling();                inOptGroup = false;            }        }    }    setChanged(true);}void HTMLSelectElementImpl::reset(){    uint i;    for (i = 0; i < m_listItems.size(); i++) {        if (m_listItems[i]->id() == ID_OPTION) {            HTMLOptionElementImpl *option = static_cast<HTMLOptionElementImpl*>(m_listItems[i]);            bool selected = (!option->getAttribute(ATTR_SELECTED).isNull());            option->setSelected(selected);            if (!m_multiple && selected)                return;        }    }}void HTMLSelectElementImpl::notifyOptionSelected(HTMLOptionElementImpl *selectedOption, bool selected){    if (selected && !m_multiple) {        // deselect all other options        uint i;        for (i = 0; i < m_listItems.size(); i++) {            if (m_listItems[i]->id() == ID_OPTION && m_listItems[i] != selectedOption)                static_cast<HTMLOptionElementImpl*>(m_listItems[i])->setSelected(false);        }    }    if (m_render)        static_cast<RenderSelect*>(m_render)->updateSelection();    setChanged(true);}// -------------------------------------------------------------------------HTMLOptGroupElementImpl::HTMLOptGroupElementImpl(DocumentImpl *doc, HTMLFormElementImpl *f)    : HTMLGenericFormElementImpl(doc, f){}HTMLOptGroupElementImpl::HTMLOptGroupElementImpl(DocumentImpl *doc)    : HTMLGenericFormElementImpl(doc){}HTMLOptGroupElementImpl::~HTMLOptGroupElementImpl(){}ushort HTMLOptGroupElementImpl::id() const{    return ID_OPTGROUP;}NodeImpl *HTMLOptGroupElementImpl::insertBefore ( NodeImpl *newChild, NodeImpl *refChild ){    NodeImpl *result = HTMLGenericFormElementImpl::insertBefore(newChild,refChild);    recalcSelectOptions();    return result;}NodeImpl *HTMLOptGroupElementImpl::replaceChild ( NodeImpl *newChild, NodeImpl *oldChild ){    NodeImpl *result = HTMLGenericFormElementImpl::replaceChild(newChild,oldChild);    recalcSelectOptions();    return result;}NodeImpl *HTMLOptGroupElementImpl::removeChild ( NodeImpl *oldChild ){    NodeImpl *result = HTMLGenericFormElementImpl::removeChild(oldChild);    recalcSelectOptions();    return result;}NodeImpl *HTMLOptGroupElementImpl::appendChild ( NodeImpl *newChild ){    NodeImpl *result = HTMLGenericFormElementImpl::appendChild(newChild);    recalcSelectOptions();    return result;}void HTMLOptGroupElementImpl::parseAttribute(AttrImpl *attr){    HTMLGenericFormElementImpl::parseAttribute(attr);    recalcSelectOptions();}void HTMLOptGroupElementImpl::recalcSelectOptions(){    NodeImpl *select = parentNode();    while (select && select->id() != ID_SELECT)        select = select->parentNode();    if (select)        static_cast<HTMLSelectElementImpl*>(select)->recalcListItems();}// -------------------------------------------------------------------------HTMLOptionElementImpl::HTMLOptionElementImpl(DocumentImpl *doc, HTMLFormElementImpl *f)    : HTMLGenericFormElementImpl(doc, f){    m_selected = false;}HTMLOptionElementImpl::HTMLOptionElementImpl(DocumentImpl *doc)    : HTMLGenericFormElementImpl(doc){    m_selected = false;}const DOMString HTMLOptionElementImpl::nodeName() const{    return "OPTION";}ushort HTMLOptionElementImpl::id() const{    return ID_OPTION;}DOMString HTMLOptionElementImpl::text(){    DOMString label = getAttribute(ATTR_LABEL);    if (label.isEmpty() && firstChild() && firstChild()->nodeType() == Node::TEXT_NODE) {        // ### allow for comments and multiple textnodes in our children        return firstChild()->nodeValue();    }    else        return label;}long HTMLOptionElementImpl::index() const{    // ###    return 0;}void HTMLOptionElementImpl::setIndex( long  ){    // ###}void HTMLOptionElementImpl::parseAttribute(AttrImpl *attr){    switch(attr->attrId)    {    case ATTR_SELECTED:        m_selected = (attr->val() != 0);        break;    case ATTR_VALUE:        m_value = attr->value();        break;    default:        HTMLGenericFormElementImpl::parseAttribute(attr);    }}void HTMLOptionElementImpl::setSelected(bool _selected){    m_selected = _selected;    HTMLSelectElementImpl *select = getSelect();    if (select)        select->notifyOptionSelected(this,_selected);}HTMLSelectElementImpl *HTMLOptionElementImpl::getSelect(){    NodeImpl *select = parentNode();    while (select && select->id() != ID_SELECT)        select = select->parentNode();    return static_cast<HTMLSelectElementImpl*>(select);}// -------------------------------------------------------------------------HTMLTextAreaElementImpl::HTMLTextAreaElementImpl(DocumentImpl *doc)    : HTMLGenericFormElementImpl(doc){    // DTD requires rows & cols be specified, but we will provide reasonable defaults    m_rows = 3;    m_cols = 60;    m_wrap = ta_Virtual;    m_value = 0;}HTMLTextAreaElementImpl::HTMLTextAreaElementImpl(DocumentImpl *doc, HTMLFormElementImpl *f)    : HTMLGenericFormElementImpl(doc, f){    // DTD requires rows & cols be specified, but we will provide reasonable defaults    m_rows = 3;    m_cols = 60;    m_wrap = ta_Virtual;    m_value = 0;}ushort HTMLTextAreaElementImpl::id() const{    return ID_TEXTAREA;}DOMString HTMLTextAreaElementImpl::type() const{    return "textarea";}QString HTMLTextAreaElementImpl::state( ){    // Make sure the string is not empty!    return value().string()+'.';}void HTMLTextAreaElementImpl::restoreState(const QString &state){    m_value = DOMString(state.left(state.length()-1));    setChanged(true);}void HTMLTextAreaElementImpl::select(  ){    if (m_render)        static_cast<RenderTextArea*>(m_render)->select();    onSelect();}void HTMLTextAreaElementImpl::parseAttribute(AttrImpl *attr){    switch(attr->attrId)    {    case ATTR_ROWS:        m_rows = attr->val() ? attr->val()->toInt() : 3;        break;    case ATTR_COLS:        m_cols = attr->val() ? attr->val()->toInt() : 60;        break;    case ATTR_WRAP:        // virtual / physical is Netscape extension of HTML 3.0, now deprecated        // soft/ hard / off is recommendation for HTML 4 extension by IE and NS 4        if ( strcasecmp( attr->value(), "virtual" ) == 0  || strcasecmp( attr->value(), "soft") == 0)            m_wrap = ta_Virtual;        else if ( strcasecmp ( attr->value(), "physical" ) == 0 || strcasecmp( attr->value(), "hard") == 0)            m_wrap = ta_Physical;        else if(strcasecmp( attr->value(), "on" ) == 0)            m_wrap = ta_Physical;        else if(strcasecmp( attr->value(), "off") == 0)            m_wrap = ta_NoWrap;        break;    case ATTR_ACCESSKEY:        // ignore for the moment        break;    case ATTR_ONFOCUS:    case ATTR_ONBLUR:    case ATTR_ONSELECT:    case ATTR_ONCHANGE:        // no need to parse        break;    default:        HTMLGenericFormElementImpl::parseAttribute(attr);    }}void HTMLTextAreaElementImpl::attach(MGHTMLView *_view){    m_style = document->styleSelector()->styleForElement(this, _view->part());    view = _view;    khtml::RenderObject *r = _parent->renderer();    if(r)    {        RenderTextArea *f = new RenderTextArea(view, this);        if (f)        {            m_render = f;            m_render->setPart (_view->part());            m_render->setStyle(m_style);            r->addChild(m_render, _next ? _next->renderer() : 0);            QString state = document->registerElement(this);            if (!state.isEmpty())                restoreState( state );        }    }    NodeBaseImpl::attach(_view);}bool HTMLTextAreaElementImpl::encoding(khtml::encodingList& encoding){    if (_name.isEmpty() || !m_render) return false;    // ### make this work independent of render    encoding += value().string().local8Bit();    return true;}void HTMLTextAreaElementImpl::reset(){    setValue(defaultValue());}DOMString HTMLTextAreaElementImpl::value(){    if (m_value.isNull())        m_value = defaultValue();    return m_value;}void HTMLTextAreaElementImpl::setValue(DOMString _value){    m_value = _value;    setChanged(true);}DOMString HTMLTextAreaElementImpl::defaultValue(){    DOMString val = "";    // there may be comments - just grab the text nodes    NodeImpl *n;    for (n = firstChild(); n; n = n->nextSibling())        if (n->isTextNode())            val += static_cast<TextImpl*>(n)->data();    return val;}void HTMLTextAreaElementImpl::setDefaultValue(DOMString _defaultValue){    // there may be comments - remove all the text nodes and replace them with one    QList<NodeImpl> toRemove;    NodeImpl *n;    for (n = firstChild(); n; n = n->nextSibling())        if (n->isTextNode())            toRemove.append(n);    QListIterator<NodeImpl> it(toRemove);    for (; it.current(); ++it) {        removeChild(it.current());    }    insertBefore(document->createTextNode(_defaultValue),firstChild());    setValue(_defaultValue);}// -------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -