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

📄 html_formimpl.cpp

📁 khtml在gtk上的移植版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
                                                             fileUploads);        if (result == KMessageBox::Cancel) {            ok = false;            return QByteArray();        }    }#endif    if (m_multipart)        enc_string = ("--" + m_boundary.string() + "--\r\n").ascii();    int old_size = form_data.size();    form_data.resize( form_data.size() + enc_string.length() );    memcpy(form_data.data() + old_size, enc_string.data(), enc_string.length() );    ok = true;    return form_data;}void HTMLFormElementImpl::setEnctype( const DOMString& type ){    if(type.string().find("multipart", 0, false) != -1 || type.string().find("form-data", 0, false) != -1)    {        m_enctype = "multipart/form-data";        m_multipart = true;        m_post = true;    } else if (type.string().find("text", 0, false) != -1 || type.string().find("plain", 0, false) != -1)    {        m_enctype = "text/plain";        m_multipart = false;    }    else    {        m_enctype = "application/x-www-form-urlencoded";        m_multipart = false;    }}void HTMLFormElementImpl::setBoundary( const DOMString& bound ){    m_boundary = bound;}bool HTMLFormElementImpl::prepareSubmit(){    KHTMLPart *part = getDocument()->part();    if(m_insubmit || !part || part->onlyLocalReferences())        return m_insubmit;    m_insubmit = true;    m_doingsubmit = false;    if ( dispatchHTMLEvent(EventImpl::SUBMIT_EVENT,false,true) && !m_doingsubmit )        m_doingsubmit = true;    m_insubmit = false;    if ( m_doingsubmit )        submit(true);    return m_doingsubmit;}void HTMLFormElementImpl::submit( bool activateSubmitButton ){    KHTMLView *view = getDocument()->view();    KHTMLPart *part = getDocument()->part();    if (!view || !part) {        return;    }    if ( m_insubmit ) {        m_doingsubmit = true;        return;    }    m_insubmit = true;#ifdef FORMS_DEBUG    kdDebug( 6030 ) << "submitting!" << endl;#endif    HTMLGenericFormElementImpl* firstSuccessfulSubmitButton = 0;    bool needButtonActivation = activateSubmitButton;	// do we need to activate a submit button?    #if APPLE_CHANGES    KWQ(part)->clearRecordedFormValues();#endif    for (QPtrListIterator<HTMLGenericFormElementImpl> it(formElements); it.current(); ++it) {        HTMLGenericFormElementImpl* current = it.current();#if APPLE_CHANGES        // Our app needs to get form values for password fields for doing password autocomplete,        // so we are more lenient in pushing values, and let the app decide what to save when.        if (current->id() == ID_INPUT) {            HTMLInputElementImpl *input = static_cast<HTMLInputElementImpl*>(current);            if (input->inputType() == HTMLInputElementImpl::TEXT                || input->inputType() ==  HTMLInputElementImpl::PASSWORD                || input->inputType() == HTMLInputElementImpl::SEARCH)            {                KWQ(part)->recordFormValue(input->name().string(), input->value().string(), this);                if (input->renderer() && input->inputType() == HTMLInputElementImpl::SEARCH)                    static_cast<RenderLineEdit*>(input->renderer())->addSearchResult();            }        }#else        if (current->id() == ID_INPUT &&            static_cast<HTMLInputElementImpl*>(current)->inputType() == HTMLInputElementImpl::TEXT &&            static_cast<HTMLInputElementImpl*>(current)->autoComplete() )        {            HTMLInputElementImpl *input = static_cast<HTMLInputElementImpl *>(current);            view->addFormCompletionItem(input->name().string(), input->value().string());        }#endif        if (needButtonActivation) {            if (current->isActivatedSubmit()) {                needButtonActivation = false;            } else if (firstSuccessfulSubmitButton == 0 && current->isSuccessfulSubmitButton()) {                firstSuccessfulSubmitButton = current;            }        }    }    if (needButtonActivation && firstSuccessfulSubmitButton) {        firstSuccessfulSubmitButton->setActivatedSubmit(true);    }    bool ok;    QByteArray form_data = formData(ok);    if (ok) {        if(m_post) {            part->submitForm( "post", m_url.string(), form_data,                                      m_target.string(),                                      enctype().string(),                                      boundary().string() );        }        else {            part->submitForm( "get", m_url.string(), form_data,                                      m_target.string() );        }    }    if (needButtonActivation && firstSuccessfulSubmitButton) {        firstSuccessfulSubmitButton->setActivatedSubmit(false);    }        m_doingsubmit = m_insubmit = false;}void HTMLFormElementImpl::reset(  ){    KHTMLPart *part = getDocument()->part();    if(m_inreset || !part) return;    m_inreset = true;#ifdef FORMS_DEBUG    kdDebug( 6030 ) << "reset pressed!" << endl;#endif    // ### DOM2 labels this event as not cancelable, however    // common browsers( sick! ) allow it be cancelled.    if ( !dispatchHTMLEvent(EventImpl::RESET_EVENT,true, true) ) {        m_inreset = false;        return;    }    for (QPtrListIterator<HTMLGenericFormElementImpl> it(formElements); it.current(); ++it)        it.current()->reset();    m_inreset = false;}void HTMLFormElementImpl::parseHTMLAttribute(HTMLAttributeImpl *attr){    switch(attr->id())    {    case ATTR_ACTION:#if APPLE_CHANGES        {        bool oldURLWasSecure = formWouldHaveSecureSubmission(m_url);#endif        m_url = khtml::parseURL(attr->value());#if APPLE_CHANGES        bool newURLIsSecure = formWouldHaveSecureSubmission(m_url);        if (m_attached && (oldURLWasSecure != newURLIsSecure))            if (newURLIsSecure)                getDocument()->secureFormAdded();            else                getDocument()->secureFormRemoved();        }#endif        break;    case ATTR_TARGET:        m_target = attr->value();        break;    case ATTR_METHOD:        if ( strcasecmp( attr->value(), "post" ) == 0 )            m_post = true;        else if ( strcasecmp( attr->value(), "get" ) == 0 )            m_post = false;        break;    case ATTR_ENCTYPE:        setEnctype( attr->value() );        break;    case ATTR_ACCEPT_CHARSET:        // space separated list of charsets the server        // accepts - see rfc2045        m_acceptcharset = attr->value();        break;    case ATTR_ACCEPT:        // ignore this one for the moment...        break;    case ATTR_AUTOCOMPLETE:        m_autocomplete = strcasecmp( attr->value(), "off" );        break;    case ATTR_ONSUBMIT:        setHTMLEventListener(EventImpl::SUBMIT_EVENT,	    getDocument()->createHTMLEventListener(attr->value().string()));        break;    case ATTR_ONRESET:        setHTMLEventListener(EventImpl::RESET_EVENT,	    getDocument()->createHTMLEventListener(attr->value().string()));        break;    case ATTR_NAME:	{	    QString newNameAttr = attr->value().string();	    if (attached() && getDocument()->isHTMLDocument()) {		HTMLDocumentImpl *document = static_cast<HTMLDocumentImpl *>(getDocument());		document->removeNamedImageOrForm(oldNameAttr);		document->addNamedImageOrForm(newNameAttr);	    }	    oldNameAttr = newNameAttr;	}	break;    case ATTR_ID:	{	    QString newIdAttr = attr->value().string();	    if (attached() && getDocument()->isHTMLDocument()) {		HTMLDocumentImpl *document = static_cast<HTMLDocumentImpl *>(getDocument());		document->removeNamedImageOrForm(oldIdAttr);		document->addNamedImageOrForm(newIdAttr);	    }	    oldIdAttr = newIdAttr;	}	// fall through    default:        HTMLElementImpl::parseHTMLAttribute(attr);    }}void HTMLFormElementImpl::radioClicked( HTMLGenericFormElementImpl *caller ){// #if 0 KWIQ -- could this be enabled now?    for (QPtrListIterator<HTMLGenericFormElementImpl> it(formElements); it.current(); ++it) {        HTMLGenericFormElementImpl *current = it.current();        if (current->id() == ID_INPUT &&            static_cast<HTMLInputElementImpl*>(current)->inputType() == HTMLInputElementImpl::RADIO &&            current != caller && current->form() == caller->form() && current->name() == caller->name()) {            static_cast<HTMLInputElementImpl*>(current)->setChecked(false);        }    }// #endif}void HTMLFormElementImpl::registerFormElement(HTMLGenericFormElementImpl *e){    formElements.append(e);#ifdef KWIQ_disabled //FIXME: why disabled    if (e->id() == ID_INPUT &&	static_cast<HTMLInputElementImpl*>(e)->inputType() == HTMLInputElementImpl::RADIO)	updateRadioGroups();#endif}void HTMLFormElementImpl::removeFormElement(HTMLGenericFormElementImpl *e){    formElements.remove(e);#ifdef KWIQ_disabled    if (e->id() == ID_INPUT &&	static_cast<HTMLInputElementImpl*>(e)->inputType() == HTMLInputElementImpl::RADIO)	updateRadioGroups();#endif}bool HTMLFormElementImpl::isURLAttribute(AttributeImpl *attr) const{    return attr->id() == ATTR_ACTION;}#if KWIQvoid HTMLFormElementImpl::updateRadioGroups(){    for (QPtrListIterator<HTMLGenericFormElementImpl> i(formElements); i.current(); ++i) {        HTMLGenericFormElementImpl *current = i.current();        if (!(current->id() == ID_INPUT &&	      static_cast<HTMLInputElementImpl*>(current)->inputType() == HTMLInputElementImpl::RADIO) &&	    (current->form() == this))	    continue;	if (!current->renderer() || !current->renderer()->isWidget()) 	    continue;	QRadioButton* crb = static_cast<RenderRadioButton*>(current->renderer())->widget();	for (QPtrListIterator<HTMLGenericFormElementImpl> j = i; j.current(); ++j) {	    HTMLGenericFormElementImpl *cmpd = j.current();	    if (cmpd->id() == ID_INPUT &&		static_cast<HTMLInputElementImpl*>(cmpd)->inputType() == HTMLInputElementImpl::RADIO &&		current != cmpd && current->form() == cmpd->form() && current->name() == cmpd->name()) {		if (!cmpd->renderer())		    continue;		QRadioButton* rb = static_cast<RenderRadioButton*>(cmpd->renderer())->widget();		rb->group()->remove(rb);		crb->group()->insert(rb);			    }        }    }    }#endif// -------------------------------------------------------------------------HTMLGenericFormElementImpl::HTMLGenericFormElementImpl(DocumentPtr *doc, HTMLFormElementImpl *f)    : HTMLElementImpl(doc){    m_disabled = m_readOnly = false;    m_name = 0;    if (f)	m_form = f;    else	m_form = getForm();    if (m_form)        m_form->registerFormElement(this);}HTMLGenericFormElementImpl::~HTMLGenericFormElementImpl(){    if (m_form)        m_form->removeFormElement(this);}void HTMLGenericFormElementImpl::parseHTMLAttribute(HTMLAttributeImpl *attr){    switch(attr->id())    {    case ATTR_NAME:        break;    case ATTR_DISABLED:        setDisabled( !attr->isNull() );        break;    case ATTR_READONLY:    {        bool m_oldreadOnly = m_readOnly;        m_readOnly = !attr->isNull();        if (m_oldreadOnly != m_readOnly) setChanged();        break;    }    default:        HTMLElementImpl::parseHTMLAttribute(attr);    }}void HTMLGenericFormElementImpl::attach(){    assert(!attached());    // FIXME: This handles the case of a new form element being created by    // JavaScript and inserted inside a form. What it does not handle is    // a form element being moved from inside a form to outside, or from one    // inside one form to another. The reason this other case is hard to fix    // is that during parsing, we may have been passed a form that we are not    // inside, DOM-tree-wise. If so, it's hard for us to know when we should    // be removed from that form's element list.    if (!m_form) {	m_form = getForm();	if (m_form)	    m_form->registerFormElement(this);    }    HTMLElementImpl::attach();    // The call to updateFromElement() needs to go after the call through    // to the base class's attach() because that can sometimes do a close    // on the renderer.    if (m_render) {        m_render->updateFromElement();            // Delayed attachment in order to prevent FOUC can result in an object being        // programmatically focused before it has a render object.  If we have been focused        // (i.e., if we are the focusNode) then go ahead and focus our corresponding native widget.        // (Attach/detach can also happen as a result of display type changes, e.g., making a widget        // block instead of inline, and focus should be restored in that case as well.)        if (getDocument()->focusNode() == this && m_render->isWidget() &&             static_cast<RenderWidget*>(renderer())->widget())            static_cast<RenderWidget*>(renderer())->widget()->setFocus();    }}void HTMLGenericFormElementImpl::removedFromDocument(){    if (m_form)        m_form->removeFormElement(this);    m_form = 0;       HTMLElementImpl::removedFromDocument();}HTMLFormElementImpl *HTMLGenericFormElementImpl::getForm() const{    NodeImpl *p = parentNode();    while(p)    {        if( p->id() == ID_FORM )            return static_cast<HTMLFormElementImpl *>(p);        p = p->parentNode();    }#ifdef FORMS_DEBUG    kdDebug( 6030 ) << "couldn't find form!" << endl;#endif    return 0;}DOMString HTMLGenericFormElementImpl::name() const{    if (m_name) return m_name;// ###//     DOMString n = getDocument()->htmlMode() != DocumentImpl::XHtml ?

⌨️ 快捷键说明

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