void MetabarFunctions::toggle(DOM::DOMString item) { DOM::HTMLDocument doc = m_html->htmlDocument(); DOM::HTMLElement node = static_cast<DOM::HTMLElement>(doc.getElementById(item)); if(!node.isNull()) { DOM::NodeList children = node.childNodes(); DOM::CSSStyleDeclaration style = node.style(); DOM::DOMString expanded = node.getAttribute("expanded"); bool isExpanded = expanded == "true"; int height = 0; if(!isExpanded) { height = getHeight(node); } DOM::DOMString att = isExpanded ? "false" : "true"; node.setAttribute("expanded", att); KConfig config("metabarrc"); config.setGroup("General"); if(config.readBoolEntry("AnimateResize", false)) { resizeMap[item.string()] = height; if(!timer->isActive()) { timer->start(RESIZE_SPEED); } } else { style.setProperty("height", QString("%1px").arg(height), CSS_PRIORITY); } } }
Value DOMCSSStyleDeclarationProtoFunc::tryCall(ExecState *exec, Object &thisObj, const List &args) { KJS_CHECK_THIS(KJS::DOMCSSStyleDeclaration, thisObj); DOM::CSSStyleDeclaration styleDecl = static_cast< DOMCSSStyleDeclaration * >(thisObj.imp())->toStyleDecl(); String str = args[0].toString(exec); DOM::DOMString s = str.value().string(); switch(id) { case DOMCSSStyleDeclaration::GetPropertyValue: return String(styleDecl.getPropertyValue(s)); case DOMCSSStyleDeclaration::GetPropertyCSSValue: return getDOMCSSValue(exec, styleDecl.getPropertyCSSValue(s)); case DOMCSSStyleDeclaration::RemoveProperty: return String(styleDecl.removeProperty(s)); case DOMCSSStyleDeclaration::GetPropertyPriority: return String(styleDecl.getPropertyPriority(s)); case DOMCSSStyleDeclaration::SetProperty: styleDecl.setProperty(args[0].toString(exec).string(), args[1].toString(exec).string(), args[2].toString(exec).string()); return Undefined(); case DOMCSSStyleDeclaration::Item: return String(styleDecl.item(args[0].toInteger(exec))); default: return Undefined(); } }
void MetabarFunctions::hide(DOM::DOMString item) { DOM::HTMLDocument doc = m_html->htmlDocument(); DOM::HTMLElement node = static_cast<DOM::HTMLElement>(doc.getElementById(item)); if(!node.isNull()) { DOM::HTMLElement parent = static_cast<DOM::HTMLElement>(node.parentNode()); DOM::CSSStyleDeclaration style = parent.style(); style.setProperty("display", "none", CSS_PRIORITY); } }
void MetabarFunctions::animate() { QMap<QString, int>::Iterator it; for(it = resizeMap.begin(); it != resizeMap.end(); ++it ) { QString id = it.key(); int height = it.data(); int currentHeight = 0; DOM::HTMLDocument doc = m_html->htmlDocument(); DOM::HTMLElement node = static_cast<DOM::HTMLElement>(doc.getElementById(id)); DOM::CSSStyleDeclaration style = node.style(); QString currentHeightString = style.getPropertyValue("height").string(); if(currentHeightString.endsWith("px")) { currentHeight = currentHeightString.left(currentHeightString.length() - 2).toInt(); } if(currentHeight == height) { resizeMap.remove(id); if(resizeMap.isEmpty()) { timer->stop(); } } else { int diff = kAbs(currentHeight - height); int changeValue = RESIZE_STEP; if(diff < RESIZE_STEP) { changeValue = diff; } int change = currentHeight < height ? changeValue : -changeValue; style.setProperty("height", QString("%1px").arg(currentHeight + change), CSS_PRIORITY); doc.updateRendering(); } } }