📄 html_formimpl.cpp
字号:
static_cast<RenderLineEdit*>(m_render)->select(); else if (m_type == FILE) static_cast<RenderFileButton*>(m_render)->select();}void HTMLInputElementImpl::click( ){ // ####ifdef FORMS_DEBUG kdDebug( 6030 ) << " HTMLInputElementImpl::click( )" << endl;#endif}void HTMLInputElementImpl::parseAttribute(AttrImpl *attr){ // ### IMPORTANT: check that the type can't be changed after the first time // otherwise a javascript programmer may be able to set a text field's value // to something like /etc/passwd and then change it to a file field // ### also check that input defaults to something - text perhaps? switch(attr->attrId) { case ATTR_AUTOCOMPLETE: m_autocomplete = strcasecmp( attr->value(), "off" ); break; case ATTR_TYPE: { typeEnum newType; if ( strcasecmp( attr->value(), "password" ) == 0 ) newType = PASSWORD; else if ( strcasecmp( attr->value(), "checkbox" ) == 0 ) newType = CHECKBOX; else if ( strcasecmp( attr->value(), "radio" ) == 0 ) newType = RADIO; else if ( strcasecmp( attr->value(), "submit" ) == 0 ) newType = SUBMIT; else if ( strcasecmp( attr->value(), "reset" ) == 0 ) newType = RESET; else if ( strcasecmp( attr->value(), "file" ) == 0 ) newType = FILE; else if ( strcasecmp( attr->value(), "hidden" ) == 0 ) newType = HIDDEN; else if ( strcasecmp( attr->value(), "image" ) == 0 ) newType = IMAGE; else if ( strcasecmp( attr->value(), "button" ) == 0 ) newType = BUTTON; else if ( strcasecmp( attr->value(), "khtml_isindex" ) == 0 ) newType = ISINDEX; else newType = TEXT; if (!m_haveType) { m_type = newType; m_haveType = true; } else if (m_type != newType) { setAttribute(ATTR_TYPE,type()); } } break; case ATTR_VALUE: m_value = attr->value(); break; case ATTR_CHECKED: setChecked(attr->val() != 0); break; case ATTR_MAXLENGTH: m_maxLen = attr->val() ? attr->val()->toInt() : -1; break; case ATTR_SIZE: m_size = attr->val() ? attr->val()->toInt() : 20; break; case ATTR_SRC: m_src = khtml::parseURL(attr->value()); break; case ATTR_ALT: case ATTR_USEMAP: case ATTR_ACCESSKEY: // ### ignore for the moment break; case ATTR_ALIGN: addHTMLAlignment( attr->value() ); break; case ATTR_WIDTH: // ignore this attribute, do _not_ add // a CSS_PROP_WIDTH here! // webdesigner are stupid - and IE/NS behave the same ( Dirk ) break; case ATTR_HEIGHT: addCSSLength(CSS_PROP_HEIGHT, attr->value() ); break; case ATTR_ONFOCUS: setHTMLEventListener(EventImpl::FOCUS_EVENT, ownerDocument()->createHTMLEventListener(attr->value().string())); break; case ATTR_ONBLUR: setHTMLEventListener(EventImpl::BLUR_EVENT, ownerDocument()->createHTMLEventListener(attr->value().string())); break; case ATTR_ONSELECT: setHTMLEventListener(EventImpl::SELECT_EVENT, ownerDocument()->createHTMLEventListener(attr->value().string())); break; case ATTR_ONCHANGE: setHTMLEventListener(EventImpl::CHANGE_EVENT, ownerDocument()->createHTMLEventListener(attr->value().string())); break; default: HTMLGenericFormElementImpl::parseAttribute(attr); }}void HTMLInputElementImpl::attach(){ // make sure we don't inherit a color to the form elements // by adding a non-CSS color property. this his higher // priority than inherited color, but lesser priority than // any color specified by CSS for the elements. switch( m_type ) { case TEXT: case PASSWORD: case ISINDEX: case FILE: addCSSProperty(CSS_PROP_COLOR, "text"); break; case SUBMIT: case RESET: case BUTTON: case CHECKBOX: case RADIO: addCSSProperty(CSS_PROP_COLOR, "buttontext" ); case HIDDEN: case IMAGE: break; }; setStyle(ownerDocument()->styleSelector()->styleForElement(this)); view = ownerDocument()->view(); if(m_firstAttach) { m_defaultChecked = m_checked; m_defaultValue = m_value; m_firstAttach = false; } khtml::RenderObject *r = _parent ? _parent->renderer() : 0; if(r && m_style->display() != NONE) { switch(m_type) { case TEXT: case PASSWORD: case ISINDEX: m_render = new RenderLineEdit(view, this); break; case CHECKBOX: m_render = new RenderCheckBox(view, this); break; case RADIO: m_render = new RenderRadioButton(view, this); break; case SUBMIT: m_render = new RenderSubmitButton(view, this); break; case IMAGE: { m_render = new RenderImageButton(this); setHasEvents(); break; } case RESET: m_render = new RenderResetButton(view, this); break; case FILE: m_render = new RenderFileButton(view, this); break; case HIDDEN: m_render = 0; break; case BUTTON: m_render = new RenderPushButton(view, this); break; } if (m_render) { m_render->setStyle(m_style); QString state = ownerDocument()->registerElement(this); if ( !state.isEmpty()) {#ifdef FORMS_DEBUG kdDebug( 6030 ) << "Restoring InputElem name=" << _name.string() << " state=" << state << endl;#endif restoreState( state ); } r->addChild(m_render, nextRenderer()); } } HTMLElementImpl::attach(); if (m_render && m_type == IMAGE) { static_cast<RenderImageButton*> (m_render)->setImageUrl(m_src, static_cast<HTMLDocumentImpl *>(ownerDocument())->baseURL(), static_cast<HTMLDocumentImpl *>(ownerDocument())->docLoader()); }}bool HTMLInputElementImpl::encoding(const QTextCodec* codec, khtml::encodingList& encoding, bool multipart){ // image generates its own name's if (_name.isEmpty() && m_type != IMAGE) return false; // IMAGE needs special handling later if(m_type != IMAGE) encoding += fixUpfromUnicode(codec, _name.string().stripWhiteSpace()); switch (m_type) { case HIDDEN: case TEXT: case PASSWORD: // always successful encoding += fixUpfromUnicode(codec, m_value.string()); return true; case CHECKBOX: if( checked() ) { encoding += ( m_value.isNull() ? QCString("on") : fixUpfromUnicode(codec, m_value.string())); return true; } break; case RADIO: if( checked() ) { encoding += fixUpfromUnicode(codec, m_value.string()); return true; } break; case BUTTON: case RESET: // those buttons are never successful return false; case IMAGE: if(m_clicked && clickX() != -1) { m_clicked = false; QString astr(_name.isEmpty() ? QString::fromLatin1("x") : _name.string().stripWhiteSpace() + ".x"); encoding += fixUpfromUnicode(codec, astr); astr.setNum(clickX()); encoding += fixUpfromUnicode(codec, astr); astr = _name.isEmpty() ? QString::fromLatin1("y") : _name.string().stripWhiteSpace() + ".y"; encoding += fixUpfromUnicode(codec, astr); astr.setNum(clickY()); encoding += fixUpfromUnicode(codec, astr); return true; } break; case SUBMIT: if (m_activeSubmit) { QString enc_str = m_value.isNull() ? static_cast<RenderSubmitButton*>(m_render)->defaultLabel() : value().string(); if(!enc_str.isEmpty()) { encoding += fixUpfromUnicode(codec, enc_str); return true; } } break; case FILE: { // can't submit file on GET // don't submit if display: none or display: hidden if(!multipart || !renderer() || !renderer()->isVisible()) return false; QString local; QCString dummy(""); // if no filename at all is entered, return successful, however empty // null would be more logical but netscape posts an empty file. argh. if(m_filename.isEmpty()) { encoding += dummy; return true; } KURL fileurl(m_filename.string()); KIO::UDSEntry filestat; if (!KIO::NetAccess::stat(fileurl, filestat)) { KMessageBox::sorry(0L, i18n("Error fetching file for submission:\n%1").arg(KIO::NetAccess::lastErrorString())); return false; } KFileItem fileitem(filestat, fileurl, true, false); if(fileitem.isDir()) { encoding += dummy; return false; } if ( KIO::NetAccess::download(KURL(m_filename.string()), local) ) { QFile file(local); if (file.open(IO_ReadOnly)) { QCString filearray(file.size()+1); int readbytes = file.readBlock( filearray.data(), file.size()); if ( readbytes >= 0 ) filearray[readbytes] = '\0'; file.close(); encoding += filearray; KIO::NetAccess::removeTempFile( local ); return true; } else { KMessageBox::error(0L, i18n("Cannot open downloaded file.\nSubmit a bug report.")); KIO::NetAccess::removeTempFile( local ); return false; } } else { KMessageBox::sorry(0L, i18n("Error fetching file for submission:\n%1").arg(KIO::NetAccess::lastErrorString())); return false; } break; } case ISINDEX: encoding += fixUpfromUnicode(codec, m_value.string()); return true; } return false;}void HTMLInputElementImpl::reset(){ setValue(m_defaultValue); setChecked(m_defaultChecked);}void HTMLInputElementImpl::setChecked(bool _checked){ m_checked = _checked; if (m_type == RADIO && m_form && m_checked) m_form->radioClicked(this); setChanged(true);}DOMString HTMLInputElementImpl::value() const{ // Readonly support for type=file if ( m_type == FILE ) return m_filename; if(m_value.isNull()) return DOMString(""); // some JS sites obviously need this return m_value;}void HTMLInputElementImpl::setValue(DOMString val){ switch (m_type) { case TEXT: case PASSWORD: m_value = (val.isNull() ? DOMString("") : val); setChanged(true); break; case FILE: // sorry, can't change this! m_value = m_filename; setChanged(true); break; default: setAttribute(ATTR_VALUE,val); }}void HTMLInputElementImpl::defaultEventHandler(EventImpl *evt){ if (evt->isMouseEvent() && evt->id() == EventImpl::CLICK_EVENT && m_type == IMAGE && m_render) { // record the mouse position for when we get the DOMActivate event MouseEventImpl *me = static_cast<MouseEventImpl*>(evt); int offsetX, offsetY; m_render->absolutePosition(offsetX,offsetY); xPos = me->clientX()-offsetX; yPos = me->clientY()-offsetY; // since we are not called from a RenderFormElement, the DOMActivate event will not get // sent so we have to do it here if (me->detail() % 2 == 0) // double click dispatchUIEvent(EventImpl::DOMACTIVATE_EVENT,2); else dispatchUIEvent(EventImpl::DOMACTIVATE_EVENT,1); me->setDefaultHandled(); } if ((evt->id() == EventImpl::DOMACTIVATE_EVENT) && (m_type == IMAGE || m_type == SUBMIT || m_type == RESET)){ if (!m_form || !m_render) return; m_clicked = true; if(m_type == RESET) m_form->reset(); else { m_activeSubmit = true; if (!m_form->prepareSubmit()) { xPos = 0; yPos = 0; } m_activeSubmit = false; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -