📄 html_formimpl.cpp
字号:
// getAttribute(ATTR_NAME) : getAttribute(ATTR_ID); DOMString n = getAttribute(ATTR_NAME); if (n.isNull()) return new DOMStringImpl(""); return n;}void HTMLGenericFormElementImpl::setName(const DOMString& name){ if (m_name) m_name->deref(); m_name = name.implementation(); if (m_name) m_name->ref();}void HTMLGenericFormElementImpl::onSelect(){ // ### make this work with new form events architecture dispatchHTMLEvent(EventImpl::SELECT_EVENT,true,false);}void HTMLGenericFormElementImpl::onChange(){ // ### make this work with new form events architecture dispatchHTMLEvent(EventImpl::CHANGE_EVENT,true,false);}bool HTMLGenericFormElementImpl::disabled() const{ return m_disabled;}void HTMLGenericFormElementImpl::setDisabled( bool _disabled ){ if ( m_disabled != _disabled ) { m_disabled = _disabled; setChanged(); }}void HTMLGenericFormElementImpl::recalcStyle( StyleChange ch ){ //bool changed = changed(); HTMLElementImpl::recalcStyle( ch ); if (m_render /*&& changed*/) m_render->updateFromElement();}bool HTMLGenericFormElementImpl::isFocusable() const{ if (!m_render || (m_render->style() && m_render->style()->visibility() != VISIBLE)) return false; return true;}bool HTMLGenericFormElementImpl::isKeyboardFocusable() const{ if (isFocusable()) { if (m_render->isWidget()) { return static_cast<RenderWidget*>(m_render)->widget() && (static_cast<RenderWidget*>(m_render)->widget()->focusPolicy() & QWidget::TabFocus); } if (getDocument()->part()) return getDocument()->part()->tabsToAllControls(); } return false;}bool HTMLGenericFormElementImpl::isMouseFocusable() const{ if (isFocusable()) { if (m_render->isWidget()) { return static_cast<RenderWidget*>(m_render)->widget() && (static_cast<RenderWidget*>(m_render)->widget()->focusPolicy() & QWidget::ClickFocus); }#if APPLE_CHANGES // For <input type=image> and <button>, we will assume no mouse focusability. This is // consistent with OS X behavior for buttons. return false;#else return true;#endif } return false;}void HTMLGenericFormElementImpl::defaultEventHandler(EventImpl *evt){ if (evt->target()==this) { // Report focus in/out changes to the browser extension (editable widgets only) KHTMLPart *part = getDocument()->part(); if (evt->id()==EventImpl::DOMFOCUSIN_EVENT && isEditable() && part && m_render && m_render->isWidget()) { KHTMLPartBrowserExtension *ext = static_cast<KHTMLPartBrowserExtension *>(part->browserExtension()); QWidget *widget = static_cast<RenderWidget*>(m_render)->widget(); if (ext) ext->editableWidgetFocused(widget); }#if APPLE_CHANGES // We don't want this default key event handling, we'll count on // Cocoa event dispatch if the event doesn't get blocked.#else if (evt->id()==EventImpl::KEYDOWN_EVENT || evt->id()==EventImpl::KEYUP_EVENT) { KeyboardEventImpl * k = static_cast<KeyboardEventImpl *>(evt); if (k->keyVal() == QChar('\n').unicode() && m_render && m_render->isWidget() && k->qKeyEvent) QApplication::sendEvent(static_cast<RenderWidget *>(m_render)->widget(), k->qKeyEvent); }#endif if (evt->id()==EventImpl::DOMFOCUSOUT_EVENT && isEditable() && part && m_render && m_render->isWidget()) { KHTMLPartBrowserExtension *ext = static_cast<KHTMLPartBrowserExtension *>(part->browserExtension()); QWidget *widget = static_cast<RenderWidget*>(m_render)->widget(); if (ext) ext->editableWidgetBlurred(widget); // ### Don't count popup as a valid reason for losing the focus (example: opening the options of a select // combobox shouldn't emit onblur) } } HTMLElementImpl::defaultEventHandler(evt);}bool HTMLGenericFormElementImpl::isEditable(){ return false;}// Special chars used to encode form state strings.// We pick chars that are unlikely to be used in an HTML attr, so we rarely have to really encode.const char stateSeparator = '&';const char stateEscape = '<';static const char stateSeparatorMarker[] = "<A";static const char stateEscapeMarker[] = "<<";// Encode an element name so we can put it in a state string without colliding// with our separator char.static QString encodedElementName(QString str){ int sepLoc = str.find(stateSeparator); int escLoc = str.find(stateSeparator); if (sepLoc >= 0 || escLoc >= 0) { QString newStr = str; // replace "<" with "<<" while (escLoc >= 0) { newStr.replace(escLoc, 1, stateEscapeMarker); escLoc = str.find(stateSeparator, escLoc+1); } // replace "&" with "<A" while (sepLoc >= 0) { newStr.replace(sepLoc, 1, stateSeparatorMarker); sepLoc = str.find(stateSeparator, sepLoc+1); } return newStr; } else { return str; }}QString HTMLGenericFormElementImpl::state( ){ // Build a string that contains ElementName&ElementType& return encodedElementName(name().string()) + stateSeparator + type().string() + stateSeparator;}QString HTMLGenericFormElementImpl::findMatchingState(QStringList &states){ QString encName = encodedElementName(name().string()); QString typeStr = type().string(); for (QStringList::Iterator it = states.begin(); it != states.end(); ++it) { QString state = *it; int sep1 = state.find(stateSeparator); int sep2 = state.find(stateSeparator, sep1+1); assert(sep1 >= 0); assert(sep2 >= 0); QString nameAndType = state.left(sep2); if (encName.length() + typeStr.length() + 1 == (uint)sep2 && nameAndType.startsWith(encName) && nameAndType.endsWith(typeStr)) { states.remove(it); return state.mid(sep2+1); } } return QString::null;}// -------------------------------------------------------------------------HTMLButtonElementImpl::HTMLButtonElementImpl(DocumentPtr *doc, HTMLFormElementImpl *f) : HTMLGenericFormElementImpl(doc, f){ m_type = SUBMIT; m_dirty = true; m_activeSubmit = false;}HTMLButtonElementImpl::~HTMLButtonElementImpl(){}NodeImpl::Id HTMLButtonElementImpl::id() const{ return ID_BUTTON;}DOMString HTMLButtonElementImpl::type() const{ return getAttribute(ATTR_TYPE);}void HTMLButtonElementImpl::parseHTMLAttribute(HTMLAttributeImpl *attr){ switch(attr->id()) { case ATTR_TYPE: if ( strcasecmp( attr->value(), "submit" ) == 0 ) m_type = SUBMIT; else if ( strcasecmp( attr->value(), "reset" ) == 0 ) m_type = RESET; else if ( strcasecmp( attr->value(), "button" ) == 0 ) m_type = BUTTON; break; case ATTR_VALUE: m_value = attr->value(); m_currValue = m_value.string(); break; case ATTR_ACCESSKEY: break; case ATTR_ONFOCUS: setHTMLEventListener(EventImpl::FOCUS_EVENT, getDocument()->createHTMLEventListener(attr->value().string())); break; case ATTR_ONBLUR: setHTMLEventListener(EventImpl::BLUR_EVENT, getDocument()->createHTMLEventListener(attr->value().string())); break; default: HTMLGenericFormElementImpl::parseHTMLAttribute(attr); }}void HTMLButtonElementImpl::defaultEventHandler(EventImpl *evt){ if (m_type != BUTTON && (evt->id() == EventImpl::DOMACTIVATE_EVENT)) { if(m_form && m_type == SUBMIT) { m_activeSubmit = true; m_form->prepareSubmit(); m_activeSubmit = false; // in case we were canceled } if(m_form && m_type == RESET) m_form->reset(); } HTMLGenericFormElementImpl::defaultEventHandler(evt);}bool HTMLButtonElementImpl::isSuccessfulSubmitButton() const{ // HTML spec says that buttons must have names // to be considered successful. However, other browsers // do not impose this constraint. Therefore, we behave // differently and can use different buttons than the // author intended. // Remove the name constraint for now. // Was: m_type == SUBMIT && !m_disabled && !name().isEmpty() return m_type == SUBMIT && !m_disabled;}bool HTMLButtonElementImpl::isActivatedSubmit() const{ return m_activeSubmit;}void HTMLButtonElementImpl::setActivatedSubmit(bool flag){ m_activeSubmit = flag;}bool HTMLButtonElementImpl::encoding(const QTextCodec* codec, khtml::encodingList& encoding, bool /*multipart*/){ if (m_type != SUBMIT || name().isEmpty() || !m_activeSubmit) return false; encoding += fixUpfromUnicode(codec, name().string()); QString enc_str = m_currValue.isNull() ? QString("") : m_currValue; encoding += fixUpfromUnicode(codec, enc_str); return true;}void HTMLButtonElementImpl::click(){#if APPLE_CHANGES QWidget *widget; if (renderer() && (widget = static_cast<RenderWidget *>(renderer())->widget())) { // using this method gives us nice Cocoa user interface feedback static_cast<QButton *>(widget)->click(); } else#endif HTMLGenericFormElementImpl::click();}void HTMLButtonElementImpl::accessKeyAction(){ click();}// -------------------------------------------------------------------------HTMLFieldSetElementImpl::HTMLFieldSetElementImpl(DocumentPtr *doc, HTMLFormElementImpl *f) : HTMLGenericFormElementImpl(doc, f){}HTMLFieldSetElementImpl::~HTMLFieldSetElementImpl(){}bool HTMLFieldSetElementImpl::isFocusable() const{ return false;}NodeImpl::Id HTMLFieldSetElementImpl::id() const{ return ID_FIELDSET;}DOMString HTMLFieldSetElementImpl::type() const{ return "fieldset";}RenderObject* HTMLFieldSetElementImpl::createRenderer(RenderArena* arena, RenderStyle* style){ return new (arena) RenderFieldset(this);}// -------------------------------------------------------------------------HTMLInputElementImpl::HTMLInputElementImpl(DocumentPtr *doc, HTMLFormElementImpl *f) : HTMLGenericFormElementImpl(doc, f), m_imageLoader(0){ m_type = TEXT; m_maxLen = -1; m_size = 20; m_checked = false; m_defaultChecked = false; m_useDefaultChecked = true; m_haveType = false; m_activeSubmit = false; m_autocomplete = true; m_inited = false; xPos = 0; yPos = 0;#if APPLE_CHANGES m_maxResults = 0;#endif if ( m_form ) m_autocomplete = f->autoComplete();}HTMLInputElementImpl::~HTMLInputElementImpl(){ if (getDocument()) getDocument()->deregisterMaintainsState(this); delete m_imageLoader;}NodeImpl::Id HTMLInputElementImpl::id() const{ return ID_INPUT;}void HTMLInputElementImpl::setType(const DOMString& t){ typeEnum newType; if ( strcasecmp( t, "password" ) == 0 ) newType = PASSWORD; else if ( strcasecmp( t, "checkbox" ) == 0 ) newType = CHECKBOX; else if ( strcasecmp( t, "radio" ) == 0 ) newType = RADIO; else if ( strcasecmp( t, "submit" ) == 0 ) newType = SUBMIT; else if ( strcasecmp( t, "reset" ) == 0 ) newType = RESET; else if ( strcasecmp( t, "file" ) == 0 ) newType = FILE; else if ( strcasecmp( t, "hidden" ) == 0 ) newType = HIDDEN; else if ( strcasecmp( t, "image" ) == 0 ) newType = IMAGE; else if ( strcasecmp( t, "button" ) == 0 ) newType = BUTTON; else if ( strcasecmp( t, "khtml_isindex" ) == 0 ) newType = ISINDEX;#if APPLE_CHANGES else if ( strcasecmp( t, "search" ) == 0 ) newType = SEARCH; else if ( strcasecmp( t, "range" ) == 0 ) newType = RANGE;#endif else newType = TEXT; // ### IMPORTANT: Don't allow the type to be changed to FILE after the first // type change, otherwise a JavaScript programmer would be able to set a text // field's value to something like /etc/passwd and then change it to a file field. if (m_type != newType) { if (newType == FILE && m_haveType) { // Set the attribute back to the old value. // Useful in case we were called from inside parseHTMLAttribute. setAttribute(ATTR_TYPE, type()); } else { m_type = newType; } } m_haveType = true;#if KWIQ if (m_type == RADIO) if (m_form) m_form->updateRadioGroups(); #endif}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -