Value Plugin::get(ExecState *exec, const Identifier &propertyName) const { #ifdef KJS_VERBOSE kdDebug(6070) << "Plugin::get " << propertyName.qstring() << endl; #endif if(propertyName == lengthPropertyName) return Number(m_info->mimes.count()); // plugin[#] bool ok; unsigned int i = propertyName.toULong(&ok); // kdDebug(6070) << "Plugin::get plugin[" << i << "]" << endl; if(ok && i < m_info->mimes.count()) { // kdDebug(6070) << "returning mimetype " << m_info->mimes.at(i)->type << endl; return Value(new MimeType(exec, m_info->mimes.at(i))); } // plugin["name"] Value val = mimeByName(exec, propertyName.qstring()); if(!val.isA(UndefinedType)) return val; return lookupGet< PluginFunc, Plugin, ObjectImp >(exec, propertyName, &PluginTable, this); }
Value MimeTypes::get(ExecState *exec, const Identifier &propertyName) const { #ifdef KJS_VERBOSE kdDebug(6070) << "MimeTypes::get " << propertyName.qstring() << endl; #endif if(!pluginsEnabled()) { if(propertyName == lengthPropertyName) return Number(0); } else { if(propertyName == lengthPropertyName) return Number(mimes->count()); // mimeTypes[#] bool ok; unsigned int i = propertyName.toULong(&ok); if(ok && i < mimes->count()) return Value(new MimeType(exec, mimes->at(i))); // mimeTypes[name] Value val = mimeTypeByName(exec, propertyName.qstring()); if(!val.isA(UndefinedType)) return val; } return lookupGet< MimeTypesFunc, MimeTypes, ObjectImp >(exec, propertyName, &MimeTypesTable, this); }
Value DOMCSSStyleDeclaration::tryGet(ExecState *exec, const Identifier &propertyName) const { #ifdef KJS_VERBOSE kdDebug(6070) << "DOMCSSStyleDeclaration::tryGet " << propertyName.qstring() << endl; #endif const HashEntry *entry = Lookup::findEntry(&DOMCSSStyleDeclarationTable, propertyName); if(entry) switch(entry->value) { case CssText: return String(styleDecl.cssText()); case Length: return Number(styleDecl.length()); case ParentRule: return getDOMCSSRule(exec, styleDecl.parentRule()); default: break; } // Look in the prototype (for functions) before assuming it's a name Object proto = Object::dynamicCast(prototype()); if(proto.isValid() && proto.hasProperty(exec, propertyName)) return proto.get(exec, propertyName); bool ok; long unsigned int u = propertyName.toULong(&ok); if(ok) return String(DOM::CSSStyleDeclaration(styleDecl).item(u)); // pixelTop returns "CSS Top" as number value in unit pixels // posTop returns "CSS top" as number value in unit pixels _if_ its a // positioned element. if it is not a positioned element, return 0 // from MSIE documentation ### IMPLEMENT THAT (Dirk) bool asNumber; QString p = cssPropertyName(propertyName, asNumber); #ifdef KJS_VERBOSE kdDebug(6070) << "DOMCSSStyleDeclaration: converting to css property name: " << p << (asNumber ? "px" : "") << endl; #endif if(asNumber) { DOM::CSSValue v = styleDecl.getPropertyCSSValue(p); if(!v.isNull() && v.cssValueType() == DOM::CSSValue::CSS_PRIMITIVE_VALUE) return Number(static_cast< DOM::CSSPrimitiveValue >(v).getFloatValue(DOM::CSSPrimitiveValue::CSS_PX)); } DOM::DOMString str = const_cast< DOM::CSSStyleDeclaration & >(styleDecl).getPropertyValue(p); if(!str.isNull()) return String(str); // see if we know this css property, return empty then if(DOM::getPropertyID(p.latin1(), p.length())) return String(DOM::DOMString("")); return DOMObject::tryGet(exec, propertyName); }
bool StringInstanceImp::hasProperty(ExecState *exec, const Identifier &propertyName) const { if (propertyName == lengthPropertyName) return true; bool ok; unsigned index = propertyName.toULong(&ok); if (ok && index < (unsigned)internalValue().toString(exec).size()) return true; return ObjectImp::hasProperty(exec, propertyName); }
Value DOMMediaList::tryGet(ExecState *exec, const Identifier &p) const { if(p == "mediaText") return String(mediaList.mediaText()); else if(p == lengthPropertyName) return Number(mediaList.length()); bool ok; long unsigned int u = p.toULong(&ok); if(ok) return String(mediaList.item(u)); return DOMObject::tryGet(exec, p); }
Value DOMStyleSheetList::tryGet(ExecState *exec, const Identifier &p) const { #ifdef KJS_VERBOSE kdDebug(6070) << "DOMStyleSheetList::tryGet " << p.qstring() << endl; #endif if(p == lengthPropertyName) return Number(styleSheetList.length()); else if(p == "item") return lookupOrCreateFunction< DOMStyleSheetListFunc >(exec, p, this, DOMStyleSheetList::Item, 1, DontDelete | Function); // Retrieve stylesheet by index bool ok; long unsigned int u = p.toULong(&ok); if(ok) return getDOMStyleSheet(exec, DOM::StyleSheetList(styleSheetList).item(u)); // IE also supports retrieving a stylesheet by name, using the name/id of the <style> tag // (this is consistent with all the other collections) #if 0 // Bad implementation because DOM::StyleSheet doesn't inherit DOM::Node // so we can't use DOMNamedNodesCollection..... // We could duplicate it for stylesheets though - worth it ? // Other problem of this implementation: it doesn't look for the ID attribute! DOM::NameNodeListImpl namedList( m_doc.documentElement().handle(), p.string() ); int len = namedList.length(); if ( len ) { QValueList<DOM::Node> styleSheets; for ( int i = 0 ; i < len ; ++i ) { DOM::HTMLStyleElement elem = DOM::Node(namedList.item(i)); if (!elem.isNull()) styleSheets.append(elem.sheet()); } if ( styleSheets.count() == 1 ) // single result return getDOMStyleSheet(exec, styleSheets[0]); else if ( styleSheets.count() > 1 ) { return new DOMNamedItemsCollection(exec,styleSheets); } } #endif // ### Bad implementation because returns a single element (are IDs always unique?) // and doesn't look for name attribute (see implementation above). // But unicity of stylesheet ids is good practice anyway ;) DOM::DOMString pstr = p.string(); DOM::HTMLStyleElement styleElem = m_doc.getElementById(pstr); if(!styleElem.isNull()) return getDOMStyleSheet(exec, styleElem.sheet()); return DOMObject::tryGet(exec, p); }
Value DOMCSSRuleList::tryGet(ExecState *exec, const Identifier &p) const { Value result; if(p == lengthPropertyName) return Number(cssRuleList.length()); else if(p == "item") return lookupOrCreateFunction< DOMCSSRuleListFunc >(exec, p, this, DOMCSSRuleList::Item, 1, DontDelete | Function); bool ok; long unsigned int u = p.toULong(&ok); if(ok) return getDOMCSSRule(exec, DOM::CSSRuleList(cssRuleList).item(u)); return DOMObject::tryGet(exec, p); }