bool LayoutEditor::growInside(String propertyName, const CSSPrimitiveValue* value) { FloatQuad content1, padding1, border1, margin1; InspectorHighlight::buildNodeQuads(m_element.get(), &content1, &padding1, &border1, &margin1); CSSStyleDeclaration* elementStyle = m_element->style(); if (!elementStyle) return false; String initialValue = elementStyle->getPropertyValue(propertyName); String initialPriority = elementStyle->getPropertyPriority(propertyName); String newValue; if (value) newValue = String::format("%f", value->getFloatValue() + 1) + CSSPrimitiveValue::unitTypeToString(value->typeWithCalcResolved()); else newValue = "5px"; TrackExceptionState exceptionState; elementStyle->setProperty(propertyName, newValue, "important", exceptionState); m_element->ownerDocument()->updateStyleAndLayout(); FloatQuad content2, padding2, border2, margin2; InspectorHighlight::buildNodeQuads(m_element.get(), &content2, &padding2, &border2, &margin2); elementStyle->setProperty(propertyName, initialValue, initialPriority, exceptionState); m_element->ownerDocument()->updateStyleAndLayout(); float eps = 0.0001; FloatRect boundingBox1, boundingBox2; if (propertyName.startsWith("padding")) { boundingBox1 = padding1.boundingBox(); boundingBox2 = padding2.boundingBox(); } else { boundingBox1 = margin1.boundingBox(); boundingBox2 = margin2.boundingBox(); } if (propertyName.endsWith("left")) return std::abs(boundingBox1.x() - boundingBox2.x()) < eps; if (propertyName.endsWith("right")) return std::abs(boundingBox1.maxX() - boundingBox2.maxX()) < eps; if (propertyName.endsWith("top")) return std::abs(boundingBox1.y() - boundingBox2.y()) < eps; if (propertyName.endsWith("bottom")) return std::abs(boundingBox1.maxY() - boundingBox2.maxY()) < eps; return false; }
v8::Handle<v8::Value> V8CSSStyleDeclaration::namedPropertySetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { INC_STATS("DOM.CSSStyleDeclaration.NamedPropertySetter"); CSSStyleDeclaration* imp = V8CSSStyleDeclaration::toNative(info.Holder()); CSSPropertyInfo* propInfo = cssPropertyInfo(name); if (!propInfo) return notHandledByInterceptor(); String propertyValue = toWebCoreStringWithNullCheck(value); if (propInfo->hadPixelOrPosPrefix) propertyValue.append("px"); ExceptionCode ec = 0; int importantIndex = propertyValue.find("!important", 0, false); bool important = false; if (importantIndex != -1) { important = true; propertyValue = propertyValue.left(importantIndex - 1); } imp->setProperty(propInfo->propID, propertyValue, important, ec); if (ec) throwError(ec); return value; }
/*! Sets the value of the inline style with the given \a name to \a value. Setting a value, does not necessarily mean that it will become the applied value, due to the fact that the style property's value might have been set earlier with a higher priority in external or embedded style declarations. In order to ensure that the value will be applied, you may have to append "!important" to the value. */ void QWebElement::setStyleProperty(const QString &name, const QString &value) { if (!m_element || !m_element->isStyledElement()) return; int propID = cssPropertyID(name); CSSStyleDeclaration* style = static_cast<StyledElement*>(m_element)->style(); if (!propID || !style) return; ExceptionCode exception = 0; style->setProperty(name, value, exception); }
JSValue* jsCSSStyleDeclarationPrototypeFunctionSetProperty(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args) { if (!thisValue->isObject(&JSCSSStyleDeclaration::s_info)) return throwError(exec, TypeError); JSCSSStyleDeclaration* castedThisObj = static_cast<JSCSSStyleDeclaration*>(thisValue); CSSStyleDeclaration* imp = static_cast<CSSStyleDeclaration*>(castedThisObj->impl()); ExceptionCode ec = 0; const UString& propertyName = args[0]->toString(exec); const UString& value = valueToStringWithNullCheck(exec, args[1]); const UString& priority = args[2]->toString(exec); imp->setProperty(propertyName, value, priority, ec); setDOMException(exec, ec); return jsUndefined(); }
JSValue JSC_HOST_CALL jsCSSStyleDeclarationPrototypeFunctionSetProperty(ExecState* exec, JSObject*, JSValue thisValue, const ArgList& args) { UNUSED_PARAM(args); if (!thisValue.isObject(&JSCSSStyleDeclaration::s_info)) return throwError(exec, TypeError); JSCSSStyleDeclaration* castedThisObj = static_cast<JSCSSStyleDeclaration*>(asObject(thisValue)); CSSStyleDeclaration* imp = static_cast<CSSStyleDeclaration*>(castedThisObj->impl()); ExceptionCode ec = 0; const UString& propertyName = args.at(0).toString(exec); const UString& value = valueToStringWithNullCheck(exec, args.at(1)); const UString& priority = args.at(2).toString(exec); imp->setProperty(propertyName, value, priority, ec); setDOMException(exec, ec); return jsUndefined(); }
EncodedJSValue JSC_HOST_CALL jsCSSStyleDeclarationPrototypeFunctionSetProperty(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (!thisValue.inherits(&JSCSSStyleDeclaration::s_info)) return throwVMTypeError(exec); JSCSSStyleDeclaration* castedThis = static_cast<JSCSSStyleDeclaration*>(asObject(thisValue)); CSSStyleDeclaration* imp = static_cast<CSSStyleDeclaration*>(castedThis->impl()); ExceptionCode ec = 0; const String& propertyName(ustringToString(exec->argument(0).toString(exec))); if (exec->hadException()) return JSValue::encode(jsUndefined()); const String& value(valueToStringWithNullCheck(exec, exec->argument(1))); if (exec->hadException()) return JSValue::encode(jsUndefined()); const String& priority(ustringToString(exec->argument(2).toString(exec))); if (exec->hadException()) return JSValue::encode(jsUndefined()); imp->setProperty(propertyName, value, priority, ec); setDOMException(exec, ec); return JSValue::encode(jsUndefined()); }
JSValue* JSCSSStyleDeclarationPrototypeFunction::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args) { if (!thisObj->inherits(&JSCSSStyleDeclaration::info)) return throwError(exec, TypeError); CSSStyleDeclaration* imp = static_cast<CSSStyleDeclaration*>(static_cast<JSCSSStyleDeclaration*>(thisObj)->impl()); switch (id) { case JSCSSStyleDeclaration::GetPropertyValueFuncNum: { String propertyName = args[0]->toString(exec); KJS::JSValue* result = jsStringOrNull(imp->getPropertyValue(propertyName)); return result; } case JSCSSStyleDeclaration::GetPropertyCSSValueFuncNum: { String propertyName = args[0]->toString(exec); KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->getPropertyCSSValue(propertyName))); return result; } case JSCSSStyleDeclaration::RemovePropertyFuncNum: { ExceptionCode ec = 0; String propertyName = args[0]->toString(exec); KJS::JSValue* result = jsStringOrNull(imp->removeProperty(propertyName, ec)); setDOMException(exec, ec); return result; } case JSCSSStyleDeclaration::GetPropertyPriorityFuncNum: { String propertyName = args[0]->toString(exec); KJS::JSValue* result = jsStringOrNull(imp->getPropertyPriority(propertyName)); return result; } case JSCSSStyleDeclaration::SetPropertyFuncNum: { ExceptionCode ec = 0; String propertyName = args[0]->toString(exec); String value = valueToStringWithNullCheck(exec, args[1]); String priority = args[2]->toString(exec); imp->setProperty(propertyName, value, priority, ec); setDOMException(exec, ec); return jsUndefined(); } case JSCSSStyleDeclaration::ItemFuncNum: { bool indexOk; unsigned index = args[0]->toInt32(exec, indexOk); if (!indexOk) { setDOMException(exec, TYPE_MISMATCH_ERR); return jsUndefined(); } KJS::JSValue* result = jsStringOrNull(imp->item(index)); return result; } case JSCSSStyleDeclaration::GetPropertyShorthandFuncNum: { String propertyName = args[0]->toString(exec); KJS::JSValue* result = jsStringOrNull(imp->getPropertyShorthand(propertyName)); return result; } case JSCSSStyleDeclaration::IsPropertyImplicitFuncNum: { String propertyName = args[0]->toString(exec); KJS::JSValue* result = jsBoolean(imp->isPropertyImplicit(propertyName)); return result; } } return 0; }