Example #1
0
QString QWebElement::styleProperty(const QString &name, StyleResolveStrategy strategy) const
{
    if (!m_element || !m_element->isStyledElement())
        return QString();

    int propID = cssPropertyID(name);

    if (!propID)
        return QString();

    CSSStyleDeclaration* style = static_cast<StyledElement*>(m_element)->style();

    if (strategy == InlineStyle)
        return style->getPropertyValue(propID);

    if (strategy == CascadedStyle) {
        if (style->getPropertyPriority(propID))
            return style->getPropertyValue(propID);

        // We are going to resolve the style property by walking through the
        // list of non-inline matched CSS rules for the element, looking for
        // the highest priority definition.

        // Get an array of matched CSS rules for the given element sorted
        // by importance and inheritance order. This include external CSS
        // declarations, as well as embedded and inline style declarations.

        DOMWindow* domWindow = m_element->document()->frame()->domWindow();
        if (RefPtr<CSSRuleList> rules = domWindow->getMatchedCSSRules(m_element, "")) {
            for (int i = rules->length(); i > 0; --i) {
                CSSStyleRule* rule = static_cast<CSSStyleRule*>(rules->item(i - 1));

                if (rule->style()->getPropertyPriority(propID))
                    return rule->style()->getPropertyValue(propID);

                if (style->getPropertyValue(propID).isEmpty())
                    style = rule->style();
            }
        }

        return style->getPropertyValue(propID);
    }

    if (strategy == ComputedStyle) {
        if (!m_element || !m_element->isStyledElement())
            return QString();

        int propID = cssPropertyID(name);

        RefPtr<CSSComputedStyleDeclaration> style = computedStyle(m_element);
        if (!propID || !style)
            return QString();

        return style->getPropertyValue(propID);
    }

    return QString();
}
Example #2
0
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;
}
Example #3
0
JSValue* jsCSSStyleDeclarationPrototypeFunctionGetPropertyValue(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());
    const UString& propertyName = args[0]->toString(exec);


    KJS::JSValue* result = jsStringOrNull(exec, imp->getPropertyValue(propertyName));
    return result;
}
Example #4
0
JSValue JSC_HOST_CALL jsCSSStyleDeclarationPrototypeFunctionGetPropertyValue(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());
    const UString& propertyName = args.at(0).toString(exec);


    JSC::JSValue result = jsStringOrNull(exec, imp->getPropertyValue(propertyName));
    return result;
}
Example #5
0
EncodedJSValue JSC_HOST_CALL jsCSSStyleDeclarationPrototypeFunctionGetPropertyValue(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());
    const String& propertyName(ustringToString(exec->argument(0).toString(exec)));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());


    JSC::JSValue result = jsStringOrNull(exec, imp->getPropertyValue(propertyName));
    return JSValue::encode(result);
}
Example #6
0
QVariantMap DumpRenderTreeSupportQt::computedStyleIncludingVisitedInfo(const QWebElement& element)
{
    QVariantMap res;

    WebCore::Element* webElement = element.m_element;
    if (!webElement)
        return res;

    RefPtr<WebCore::CSSComputedStyleDeclaration> computedStyleDeclaration = CSSComputedStyleDeclaration::create(webElement, true);
    CSSStyleDeclaration* style = static_cast<WebCore::CSSStyleDeclaration*>(computedStyleDeclaration.get());
    for (unsigned i = 0; i < style->length(); i++) {
        QString name = style->item(i);
        QString value = style->getPropertyValue(name);
        res[convertToPropertyName(name)] = QVariant(value);
    }
    return res;
}
v8::Handle<v8::Value> V8CSSStyleDeclaration::namedPropertyGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
{
    INC_STATS("DOM.CSSStyleDeclaration.NamedPropertyGetter");
    // First look for API defined attributes on the style declaration object.
    if (info.Holder()->HasRealNamedCallbackProperty(name))
        return notHandledByInterceptor();

    // Search the style declaration.
    CSSStyleDeclaration* imp = V8CSSStyleDeclaration::toNative(info.Holder());
    CSSPropertyInfo* propInfo = cssPropertyInfo(name);

    // Do not handle non-property names.
    if (!propInfo)
        return notHandledByInterceptor();


    RefPtr<CSSValue> cssValue = imp->getPropertyCSSValue(propInfo->propID);
    if (cssValue) {
        if (propInfo->hadPixelOrPosPrefix &&
            cssValue->cssValueType() == CSSValue::CSS_PRIMITIVE_VALUE) {
            return v8::Number::New(static_cast<CSSPrimitiveValue*>(
                cssValue.get())->getFloatValue(CSSPrimitiveValue::CSS_PX));
        }
        return v8StringOrNull(cssValue->cssText());
    }

    String result = imp->getPropertyValue(propInfo->propID);
    if (result.isNull())
        result = "";  // convert null to empty string.

    // The 'filter' attribute is made undetectable in KJS/WebKit
    // to avoid confusion with IE's filter extension.
    if (propInfo->wasFilter)
        return v8UndetectableString(result);

    return v8String(result);
}
Example #8
0
HTMLMarqueeElement::Metrics HTMLMarqueeElement::getMetrics() {
    Metrics metrics;
    CSSStyleDeclaration* marqueeStyle =
        document().domWindow()->getComputedStyle(this, String());
    // For marquees that are declared inline, getComputedStyle returns "auto" for
    // width and height. Setting all the metrics to zero disables animation for
    // inline marquees.
    if (marqueeStyle->getPropertyValue("width") == "auto" &&
            marqueeStyle->getPropertyValue("height") == "auto") {
        metrics.contentHeight = 0;
        metrics.contentWidth = 0;
        metrics.marqueeWidth = 0;
        metrics.marqueeHeight = 0;
        return metrics;
    }

    if (isHorizontal()) {
        m_mover->style()->setProperty("width", "-webkit-max-content", "important",
                                      ASSERT_NO_EXCEPTION);
    } else {
        m_mover->style()->setProperty("height", "-webkit-max-content", "important",
                                      ASSERT_NO_EXCEPTION);
    }
    CSSStyleDeclaration* moverStyle =
        document().domWindow()->getComputedStyle(m_mover, String());

    metrics.contentWidth = moverStyle->getPropertyValue("width").toDouble();
    metrics.contentHeight = moverStyle->getPropertyValue("height").toDouble();
    metrics.marqueeWidth = marqueeStyle->getPropertyValue("width").toDouble();
    metrics.marqueeHeight = marqueeStyle->getPropertyValue("height").toDouble();

    if (isHorizontal()) {
        m_mover->style()->setProperty("width", "", "important",
                                      ASSERT_NO_EXCEPTION);
    } else {
        m_mover->style()->setProperty("height", "", "important",
                                      ASSERT_NO_EXCEPTION);
    }

    return metrics;
}
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;
}