📄 html_formimpl.cpp
字号:
}static QString calculateAutoFillKey(const HTMLFormElementImpl& e){ KURL k(e.getDocument()->URL()); k.setRef(QString::null); k.setQuery(QString::null); // ensure that we have the user / password inside the url // otherwise we might have a potential security problem // by saving passwords under wrong lookup key. const QString name = e.getAttribute(ATTR_NAME).string().stripWhiteSpace(); const QRegExp re("[;,!]"); const QStringList url = QStringList::split(re, k.url()); return url[0] + '#' + name;}void HTMLFormElementImpl::doAutoFill(){#ifndef KHTML_NO_WALLET const QString key = calculateAutoFillKey(*this); if (KWallet::Wallet::keyDoesNotExist(KWallet::Wallet::NetworkWallet(), KWallet::Wallet::FormDataFolder(), key)) return; // assert(view()) getDocument()->view()->part()->openWallet(this);#endif // KHTML_NO_WALLET}void HTMLFormElementImpl::walletOpened(KWallet::Wallet *w) {#ifndef KHTML_NO_WALLET assert(w); const QString key = calculateAutoFillKey(*this); if (!w->hasFolder(KWallet::Wallet::FormDataFolder())) { return; // failed } w->setFolder(KWallet::Wallet::FormDataFolder()); QMap<QString, QString> map; if (w->readMap(key, map)) return; // failed, abort for (QPtrListIterator<HTMLGenericFormElementImpl> it(formElements); it.current(); ++it) { if (it.current()->id() == ID_INPUT) { HTMLInputElementImpl* const current = static_cast<HTMLInputElementImpl*>(it.current()); if ((current->inputType() == HTMLInputElementImpl::PASSWORD || current->inputType() == HTMLInputElementImpl::TEXT) && !current->readOnly() && map.contains(current->name().string())) { getDocument()->setFocusNode(current); current->setValue(map[current->name().string()]); } } }#endif // KHTML_NO_WALLET}void HTMLFormElementImpl::submitFromKeyboard(){ // Activate the first nondisabled submit button // if there is none, do a submit anyway if not more // than one <input type=text> or <input type=password> unsigned int inputtext = 0; for (QPtrListIterator<HTMLGenericFormElementImpl> it(formElements); it.current(); ++it) { if (it.current()->id() == ID_BUTTON) { HTMLButtonElementImpl* const current = static_cast<HTMLButtonElementImpl *>(it.current()); if (current->buttonType() == HTMLButtonElementImpl::SUBMIT && !current->disabled()) { current->click(); return; } } else if (it.current()->id() == ID_INPUT) { HTMLInputElementImpl* const current = static_cast<HTMLInputElementImpl *>(it.current()); switch(current->inputType()) { case HTMLInputElementImpl::SUBMIT: case HTMLInputElementImpl::IMAGE: if(!current->disabled()) { current->click(); return; } break; case HTMLInputElementImpl::TEXT: case HTMLInputElementImpl::PASSWORD: ++inputtext; default: break; } } } if (inputtext <= 1) prepareSubmit();}void HTMLFormElementImpl::gatherWalletData(){#ifndef KHTML_NO_WALLET KHTMLView* const view = getDocument()->view(); // check if we have any password input's m_walletMap.clear(); m_havePassword = false; m_haveTextarea = false; const KURL formUrl(getDocument()->URL()); if (!view->nonPasswordStorableSite(formUrl.host())) { for (QPtrListIterator<HTMLGenericFormElementImpl> it(formElements); it.current(); ++it) { if (it.current()->id() == ID_INPUT) { HTMLInputElementImpl* const c = static_cast<HTMLInputElementImpl*> (it.current()); if ((c->inputType() == HTMLInputElementImpl::TEXT || c->inputType() == HTMLInputElementImpl::PASSWORD) && !c->readOnly()) { m_walletMap.insert(c->name().string(), c->value().string()); if (c->inputType() == HTMLInputElementImpl::PASSWORD && !c->value().isEmpty()) m_havePassword = true; } } else if (it.current()->id() == ID_TEXTAREA) m_haveTextarea = true; } }#endif // KHTML_NO_WALLET}bool HTMLFormElementImpl::prepareSubmit(){ KHTMLView* const view = getDocument()->view(); if(m_insubmit || !view || !view->part() || view->part()->onlyLocalReferences()) return m_insubmit; gatherWalletData(); m_insubmit = true; m_doingsubmit = false; if ( dispatchHTMLEvent(EventImpl::SUBMIT_EVENT,true,true) && !m_doingsubmit ) m_doingsubmit = true; m_insubmit = false; if ( m_doingsubmit ) submit(); return m_doingsubmit;}void HTMLFormElementImpl::submit( ){ if ( m_insubmit ) { m_doingsubmit = true; return; } m_insubmit = true;#ifdef FORMS_DEBUG kdDebug( 6030 ) << "submitting!" << endl;#endif bool ok; KHTMLView* const view = getDocument()->view(); const QByteArray form_data = formData(ok); const KURL formUrl(getDocument()->URL()); if (ok && view) { if (m_walletMap.isEmpty()) { gatherWalletData(); }#ifndef KHTML_NO_WALLET if (m_havePassword && !m_haveTextarea && KWallet::Wallet::isEnabled()) { const QString key = calculateAutoFillKey(*this); const bool doesnotexist = KWallet::Wallet::keyDoesNotExist(KWallet::Wallet::NetworkWallet(), KWallet::Wallet::FormDataFolder(), key); KWallet::Wallet* const w = view->part()->wallet(); bool login_changed = false; if (!doesnotexist && w) { // check if the login information changed from what // we had so far. if (w->hasFolder(KWallet::Wallet::FormDataFolder())) { w->setFolder(KWallet::Wallet::FormDataFolder()); QMap<QString, QString> map; if (!w->readMap(key, map)) { QMapConstIterator<QString, QString> it = map.begin(); const QMapConstIterator<QString, QString> itEnd = map.end(); for ( ; it != itEnd; ++it ) if ( map[it.key()] != m_walletMap[it.key()] ) { login_changed = true; break; } } else { login_changed = true; } } } if ( doesnotexist || !w || login_changed ) { // TODO use KMessageBox::questionYesNoCancel() again, if you can pass a KGuiItem for Cancel KDialogBase* const dialog = new KDialogBase(i18n("Save Login Information"), KDialogBase::Yes | KDialogBase::No | KDialogBase::Cancel, KDialogBase::Yes, KDialogBase::Cancel, 0, "questionYesNoCancel", true, true, i18n("Store"), KGuiItem(i18n("Ne&ver for This Site")), i18n("Do Not Store")); bool checkboxResult = false; const int savePassword = KMessageBox::createKMessageBox(dialog, QMessageBox::Information, formUrl.host().isEmpty() ? // e.g. local file i18n("Konqueror has the ability to store the password " "in an encrypted wallet. When the wallet is unlocked, it " "can then automatically restore the login information " "next time you submit this form. Do you want to store " "the information now?") : i18n("Konqueror has the ability to store the password " "in an encrypted wallet. When the wallet is unlocked, it " "can then automatically restore the login information " "next time you visit %1. Do you want to store " "the information now?").arg(formUrl.host()), QStringList(), QString::null, &checkboxResult, KMessageBox::Notify); if ( savePassword == KDialogBase::Yes ) { // ensure that we have the user / password inside the url // otherwise we might have a potential security problem // by saving passwords under wrong lookup key. getDocument()->view()->part()->saveToWallet(key, m_walletMap); } else if ( savePassword == KDialogBase::No ) { view->addNonPasswordStorableSite(formUrl.host()); } } }#endif // KHTML_NO_WALLET const DOMString url(khtml::parseURL(getAttribute(ATTR_ACTION))); if(m_post) { view->part()->submitForm( "post", url.string(), form_data, m_target.string(), enctype().string(), m_boundary ); } else { view->part()->submitForm( "get", url.string(), form_data, m_target.string() ); } } m_walletMap.clear(); // done with it m_havePassword = m_haveTextarea= false; m_doingsubmit = m_insubmit = false;}void HTMLFormElementImpl::reset( ){ KHTMLView* const view = getDocument()->view(); if(m_inreset || !view || !view->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::parseAttribute(AttributeImpl *attr){ switch(attr->id()) { case ATTR_ACTION: break; case ATTR_TARGET: m_target = attr->value(); break; case ATTR_METHOD: m_post = ( strcasecmp( attr->value(), "post" ) == 0 ); 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(), "onsubmit", this)); break; case ATTR_ONRESET: setHTMLEventListener(EventImpl::RESET_EVENT, getDocument()->createHTMLEventListener(attr->value().string(), "onreset", this)); break; case ATTR_NAME: if (inDocument() && m_name != attr->value()) { getDocument()->underDocNamedCache().remove(m_name.string(), this); getDocument()->underDocNamedCache().add (attr->value().string(), this); } m_name = attr->value(); //Fallthrough intentional default: HTMLElementImpl::parseAttribute(attr); }}void HTMLFormElementImpl::removedFromDocument(){ getDocument()->underDocNamedCache().remove(m_name.string(), this); HTMLElementImpl::removedFromDocument();}void HTMLFormElementImpl::insertedIntoDocument(){ getDocument()->underDocNamedCache().add(m_name.string(), this); HTMLElementImpl::insertedIntoDocument();}void HTMLFormElementImpl::removeId(const QString& id){ getDocument()->underDocNamedCache().remove(id, this); HTMLElementImpl::removeId(id);}void HTMLFormElementImpl::addId (const QString& id){ getDocument()->underDocNamedCache().add(id, this); HTMLElementImpl::addId(id);}void HTMLFormElementImpl::radioClicked( HTMLGenericFormElementImpl *caller ){ for (QPtrListIterator<HTMLGenericFormElementImpl> it(formElements); it.current(); ++it) { HTMLGenericFormElementImpl* const 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); }}void HTMLFormElementImpl::registerFormElement(HTMLGenericFormElementImpl *e){ formElements.append(e);}void HTMLFormElementImpl::removeFormElement(HTMLGenericFormElementImpl *e){ formElements.remove(e);}void HTMLFormElementImpl::registerImgElement(HTMLImageElementImpl *e){ imgElements.append(e);}void HTMLFormElementImpl::removeImgElement(HTMLImageElementImpl *e){ imgElements.remove(e);}// -------------------------------------------------------------------------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);}void HTMLGenericFormElementImpl::insertedIntoDocument(){ HTMLElementImpl::insertedIntoDocument(); if (!m_form) { HTMLFormElementImpl* const newform = getForm(); if (newform) { m_form = newform; m_form->registerFormElement(this); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -