コード例 #1
0
ファイル: CSSToStyleMap.cpp プロジェクト: dog-god/iptv
void CSSToStyleMap::mapFillYPosition(CSSPropertyID, FillLayer* layer, CSSValue* value)
{
    if (value->isInitialValue()) {
        layer->setYPosition(FillLayer::initialFillYPosition(layer->type()));
        return;
    }

    if (!value->isPrimitiveValue())
        return;

    float zoomFactor = style()->effectiveZoom();

    CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value);
    Length length;
    if (primitiveValue->isLength())
        length = primitiveValue->computeLength<Length>(style(), rootElementStyle(), zoomFactor);
    else if (primitiveValue->isPercentage())
        length = Length(primitiveValue->getDoubleValue(), Percent);
    else if (primitiveValue->isCalculatedPercentageWithLength())
        length = Length(primitiveValue->cssCalcValue()->toCalcValue(style(), rootElementStyle(), zoomFactor));
    else if (primitiveValue->isViewportPercentageLength())
        length = primitiveValue->viewportPercentageLength();
    else
        return;
    layer->setYPosition(length);
}
コード例 #2
0
void CSSToStyleMap::mapFillYPosition(CSSPropertyID propertyID, FillLayer* layer, CSSValue* value)
{
    if (value->isInitialValue()) {
        layer->setYPosition(FillLayer::initialFillYPosition(layer->type()));
        return;
    }

    if (!value->isPrimitiveValue())
        return;

    float zoomFactor = style()->effectiveZoom();

    CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value);
    Pair* pair = primitiveValue->getPairValue();
    if (pair) {
        ASSERT_UNUSED(propertyID, propertyID == CSSPropertyBackgroundPositionY || propertyID == CSSPropertyWebkitMaskPositionY);
        primitiveValue = pair->second();
    }

    Length length;
    if (primitiveValue->isLength())
        length = primitiveValue->computeLength<Length>(style(), rootElementStyle(), zoomFactor);
    else if (primitiveValue->isPercentage())
        length = Length(primitiveValue->getDoubleValue(), Percent);
    else if (primitiveValue->isCalculatedPercentageWithLength())
        length = Length(primitiveValue->cssCalcValue()->toCalcValue(style(), rootElementStyle(), zoomFactor));
    else if (primitiveValue->isViewportPercentageLength())
        length = primitiveValue->viewportPercentageLength();
    else
        return;

    layer->setYPosition(length);
    if (pair)
        layer->setBackgroundYOrigin(*(pair->first()));
}
コード例 #3
0
CSSToLengthConversionData StyleResolverState::fontSizeConversionData() const
{
    float em = parentStyle()->specifiedFontSize();
    float rem = rootElementStyle() ? rootElementStyle()->specifiedFontSize() : 1;
    CSSToLengthConversionData::FontSizes fontSizes(em, rem, &parentStyle()->font());
    CSSToLengthConversionData::ViewportSize viewportSize(document().layoutViewItem());

    return CSSToLengthConversionData(style(), fontSizes, viewportSize, 1);
}
コード例 #4
0
float SVGLengthContext::convertValueToUserUnits(float value, SVGLengthMode mode, CSSPrimitiveValue::UnitType fromUnit) const
{
    float userUnits = value;
    switch (fromUnit) {
    case CSSPrimitiveValue::UnitType::Pixels:
    case CSSPrimitiveValue::UnitType::Number:
    case CSSPrimitiveValue::UnitType::UserUnits:
        userUnits = value;
        break;
    case CSSPrimitiveValue::UnitType::Percentage: {
        FloatSize viewportSize;
        if (!determineViewport(viewportSize))
            return 0;
        userUnits = value * dimensionForLengthMode(mode, viewportSize) / 100;
        break;
    }
    case CSSPrimitiveValue::UnitType::Ems:
        userUnits = convertValueFromEMSToUserUnits(computedStyleForLengthResolving(m_context), value);
        break;
    case CSSPrimitiveValue::UnitType::Exs:
        userUnits = convertValueFromEXSToUserUnits(value);
        break;
    case CSSPrimitiveValue::UnitType::Centimeters:
        userUnits = value * cssPixelsPerCentimeter;
        break;
    case CSSPrimitiveValue::UnitType::Millimeters:
        userUnits = value * cssPixelsPerMillimeter;
        break;
    case CSSPrimitiveValue::UnitType::Inches:
        userUnits = value * cssPixelsPerInch;
        break;
    case CSSPrimitiveValue::UnitType::Points:
        userUnits = value * cssPixelsPerPoint;
        break;
    case CSSPrimitiveValue::UnitType::Picas:
        userUnits = value * cssPixelsPerPica;
        break;
    case CSSPrimitiveValue::UnitType::Rems:
        userUnits = convertValueFromEMSToUserUnits(rootElementStyle(m_context), value);
        break;
    case CSSPrimitiveValue::UnitType::Chs:
        userUnits = convertValueFromCHSToUserUnits(value);
        break;
    case CSSPrimitiveValue::UnitType::ViewportWidth:
    case CSSPrimitiveValue::UnitType::ViewportHeight:
    case CSSPrimitiveValue::UnitType::ViewportMin:
    case CSSPrimitiveValue::UnitType::ViewportMax:
        userUnits = value * dimensionForViewportUnit(m_context, fromUnit);
        break;
    default:
        ASSERT_NOT_REACHED();
        break;
    }

    // Since we mix css <length> values with svg's length values we need to
    // clamp values to the narrowest range, otherwise it can result in
    // rendering issues.
    return CSSPrimitiveValue::clampToCSSLengthRange(userUnits);
}
コード例 #5
0
LengthBox CSSToStyleMap::mapNinePieceImageQuad(CSSValue* value)
{
    if (!value || !value->isPrimitiveValue())
        return LengthBox();

    // Get our zoom value.
    float zoom = useSVGZoomRules() ? 1.0f : style()->effectiveZoom();

    // Retrieve the primitive value.
    CSSPrimitiveValue* borderWidths = static_cast<CSSPrimitiveValue*>(value);

    // Set up a length box to represent our image slices.
    LengthBox box; // Defaults to 'auto' so we don't have to handle that explicitly below.
    Quad* slices = borderWidths->getQuadValue();
    if (slices->top()->isNumber())
        box.m_top = Length(slices->top()->getIntValue(), Relative);
    else if (slices->top()->isPercentage())
        box.m_top = Length(slices->top()->getDoubleValue(CSSPrimitiveValue::CSS_PERCENTAGE), Percent);
    else if (slices->top()->getValueID() != CSSValueAuto)
        box.m_top = slices->top()->computeLength<Length>(style(), rootElementStyle(), zoom);

    if (slices->right()->isNumber())
        box.m_right = Length(slices->right()->getIntValue(), Relative);
    else if (slices->right()->isPercentage())
        box.m_right = Length(slices->right()->getDoubleValue(CSSPrimitiveValue::CSS_PERCENTAGE), Percent);
    else if (slices->right()->getValueID() != CSSValueAuto)
        box.m_right = slices->right()->computeLength<Length>(style(), rootElementStyle(), zoom);

    if (slices->bottom()->isNumber())
        box.m_bottom = Length(slices->bottom()->getIntValue(), Relative);
    else if (slices->bottom()->isPercentage())
        box.m_bottom = Length(slices->bottom()->getDoubleValue(CSSPrimitiveValue::CSS_PERCENTAGE), Percent);
    else if (slices->bottom()->getValueID() != CSSValueAuto)
        box.m_bottom = slices->bottom()->computeLength<Length>(style(), rootElementStyle(), zoom);

    if (slices->left()->isNumber())
        box.m_left = Length(slices->left()->getIntValue(), Relative);
    else if (slices->left()->isPercentage())
        box.m_left = Length(slices->left()->getDoubleValue(CSSPrimitiveValue::CSS_PERCENTAGE), Percent);
    else if (slices->left()->getValueID() != CSSValueAuto)
        box.m_left = slices->left()->computeLength<Length>(style(), rootElementStyle(), zoom);

    return box;
}
コード例 #6
0
void CSSToStyleMap::mapFillSize(CSSPropertyID, FillLayer* layer, CSSValue* value)
{
    if (!value->isPrimitiveValue()) {
        layer->setSizeType(SizeNone);
        return;
    }

    CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value);
    if (primitiveValue->getValueID() == CSSValueContain)
        layer->setSizeType(Contain);
    else if (primitiveValue->getValueID() == CSSValueCover)
        layer->setSizeType(Cover);
    else
        layer->setSizeType(SizeLength);

    LengthSize b = FillLayer::initialFillSizeLength(layer->type());

    if (value->isInitialValue() || primitiveValue->getValueID() == CSSValueContain || primitiveValue->getValueID() == CSSValueCover) {
        layer->setSizeLength(b);
        return;
    }

    float zoomFactor = style()->effectiveZoom();

    Length firstLength;
    Length secondLength;

    if (Pair* pair = primitiveValue->getPairValue()) {
        CSSPrimitiveValue* first = static_cast<CSSPrimitiveValue*>(pair->first());
        CSSPrimitiveValue* second = static_cast<CSSPrimitiveValue*>(pair->second());
        firstLength = first->convertToLength<AnyConversion>(style(), rootElementStyle(), zoomFactor);
        secondLength = second->convertToLength<AnyConversion>(style(), rootElementStyle(), zoomFactor);
    } else {
        firstLength = primitiveValue->convertToLength<AnyConversion>(style(), rootElementStyle(), zoomFactor);
        secondLength = Length();
    }

    if (firstLength.isUndefined() || secondLength.isUndefined())
        return;

    b.setWidth(firstLength);
    b.setHeight(secondLength);
    layer->setSizeLength(b);
}
コード例 #7
0
float SVGLengthContext::convertValueToUserUnits(float value, SVGLengthMode mode, SVGLengthType fromUnit) const
{
    float userUnits = value;
    switch (fromUnit) {
    case LengthTypeUnknown:
        return 0;
    case LengthTypePX:
    case LengthTypeNumber:
        userUnits = value;
        break;
    case LengthTypePercentage: {
        FloatSize viewportSize;
        if (!determineViewport(viewportSize))
            return 0;
        userUnits = value * dimensionForLengthMode(mode, viewportSize) / 100;
        break;
    }
    case LengthTypeEMS:
        userUnits = convertValueFromEMSToUserUnits(computedStyleForLengthResolving(m_context), value);
        break;
    case LengthTypeEXS:
        userUnits = convertValueFromEXSToUserUnits(value);
        break;
    case LengthTypeCM:
        userUnits = value * cssPixelsPerCentimeter;
        break;
    case LengthTypeMM:
        userUnits = value * cssPixelsPerMillimeter;
        break;
    case LengthTypeIN:
        userUnits = value * cssPixelsPerInch;
        break;
    case LengthTypePT:
        userUnits = value * cssPixelsPerPoint;
        break;
    case LengthTypePC:
        userUnits = value * cssPixelsPerPica;
        break;
    case LengthTypeREMS:
        userUnits = convertValueFromEMSToUserUnits(rootElementStyle(m_context), value);
        break;
    case LengthTypeCHS:
        userUnits = convertValueFromCHSToUserUnits(value);
        break;
    default:
        ASSERT_NOT_REACHED();
        break;
    }

    // Since we mix css <length> values with svg's length values we need to
    // clamp values to the narrowest range, otherwise it can result in
    // rendering issues.
    return CSSPrimitiveValue::clampToCSSLengthRange(userUnits);
}
コード例 #8
0
float SVGLengthContext::convertValueFromUserUnits(
    float value,
    SVGLengthMode mode,
    CSSPrimitiveValue::UnitType toUnit) const {
  switch (toUnit) {
    case CSSPrimitiveValue::UnitType::Pixels:
    case CSSPrimitiveValue::UnitType::Number:
    case CSSPrimitiveValue::UnitType::Integer:
    case CSSPrimitiveValue::UnitType::UserUnits:
      return value;
    case CSSPrimitiveValue::UnitType::Percentage: {
      FloatSize viewportSize;
      if (!determineViewport(viewportSize))
        return 0;
      float dimension = dimensionForLengthMode(mode, viewportSize);
      if (!dimension)
        return 0;
      // LengthTypePercentage is represented with 100% = 100.0.
      // Good for accuracy but could eventually be changed.
      return value * 100 / dimension;
    }
    case CSSPrimitiveValue::UnitType::Ems:
      return convertValueFromUserUnitsToEMS(
          computedStyleForLengthResolving(m_context), value);
    case CSSPrimitiveValue::UnitType::Exs:
      return convertValueFromUserUnitsToEXS(value);
    case CSSPrimitiveValue::UnitType::Rems:
      return convertValueFromUserUnitsToEMS(rootElementStyle(m_context), value);
    case CSSPrimitiveValue::UnitType::Chs:
      return convertValueFromUserUnitsToCHS(value);
    case CSSPrimitiveValue::UnitType::Centimeters:
      return value / cssPixelsPerCentimeter;
    case CSSPrimitiveValue::UnitType::Millimeters:
      return value / cssPixelsPerMillimeter;
    case CSSPrimitiveValue::UnitType::Inches:
      return value / cssPixelsPerInch;
    case CSSPrimitiveValue::UnitType::Points:
      return value / cssPixelsPerPoint;
    case CSSPrimitiveValue::UnitType::Picas:
      return value / cssPixelsPerPica;
    case CSSPrimitiveValue::UnitType::ViewportWidth:
    case CSSPrimitiveValue::UnitType::ViewportHeight:
    case CSSPrimitiveValue::UnitType::ViewportMin:
    case CSSPrimitiveValue::UnitType::ViewportMax:
      return value / dimensionForViewportUnit(m_context, toUnit);
    default:
      break;
  }

  ASSERT_NOT_REACHED();
  return 0;
}
コード例 #9
0
float SVGLengthContext::resolveValue(const CSSPrimitiveValue& primitiveValue,
                                     SVGLengthMode mode) const {
  const ComputedStyle* style = computedStyleForLengthResolving(m_context);
  if (!style)
    return 0;

  const ComputedStyle* rootStyle = rootElementStyle(m_context);
  if (!rootStyle)
    return 0;

  CSSToLengthConversionData conversionData = CSSToLengthConversionData(
      style, rootStyle, m_context->document().layoutViewItem(), 1.0f);
  Length length = primitiveValue.convertToLength(conversionData);
  return valueForLength(length, 1.0f, mode);
}
コード例 #10
0
ファイル: StyleResolverState.cpp プロジェクト: krockot/mojo
StyleResolverState::StyleResolverState(Document& document, Element* element, RenderStyle* parentStyle)
    : m_elementContext(element ? ElementResolveContext(*element) : ElementResolveContext(document))
    , m_document(document)
    , m_style(nullptr)
    , m_cssToLengthConversionData(0, rootElementStyle(), document.renderView())
    , m_parentStyle(parentStyle)
    , m_lineHeightValue(nullptr)
    , m_styleMap(*this, m_elementStyleResources)
{
    if (!parentStyle && m_elementContext.parentNode())
        m_parentStyle = m_elementContext.parentNode()->renderStyle();

    ASSERT(document.isActive());
    m_elementStyleResources.setDeviceScaleFactor(document.frameHost()->deviceScaleFactor());
}
コード例 #11
0
float SVGLengthContext::convertValueFromUserUnits(float value, SVGLengthMode mode, SVGLengthType toUnit) const
{
    switch (toUnit) {
    case LengthTypeUnknown:
        return 0;
    case LengthTypeNumber:
        return value;
    case LengthTypePercentage: {
        FloatSize viewportSize;
        if (!determineViewport(viewportSize))
            return 0;
        float dimension = dimensionForLengthMode(mode, viewportSize);
        if (!dimension)
            return 0;
        // LengthTypePercentage is represented with 100% = 100.0.
        // Good for accuracy but could eventually be changed.
        return value * 100 / dimension;
    }
    case LengthTypeEMS:
        return convertValueFromUserUnitsToEMS(computedStyleForLengthResolving(m_context), value);
    case LengthTypeEXS:
        return convertValueFromUserUnitsToEXS(value);
    case LengthTypeREMS:
        return convertValueFromUserUnitsToEMS(rootElementStyle(m_context), value);
    case LengthTypeCHS:
        return convertValueFromUserUnitsToCHS(value);
    case LengthTypePX:
        return value;
    case LengthTypeCM:
        return value / cssPixelsPerCentimeter;
    case LengthTypeMM:
        return value / cssPixelsPerMillimeter;
    case LengthTypeIN:
        return value / cssPixelsPerInch;
    case LengthTypePT:
        return value / cssPixelsPerPoint;
    case LengthTypePC:
        return value / cssPixelsPerPica;
    }

    ASSERT_NOT_REACHED();
    return 0;
}
StyleResolverState::StyleResolverState(Document& document, Element* element, RenderStyle* parentStyle)
    : m_elementContext(element ? ElementResolveContext(*element) : ElementResolveContext(document))
    , m_document(document)
    , m_style(nullptr)
    , m_cssToLengthConversionData(0, rootElementStyle(), document.renderView())
    , m_parentStyle(parentStyle)
    , m_applyPropertyToRegularStyle(true)
    , m_applyPropertyToVisitedLinkStyle(false)
    , m_lineHeightValue(nullptr)
    , m_styleMap(*this, m_elementStyleResources)
{
    if (!parentStyle && m_elementContext.parentNode())
        m_parentStyle = m_elementContext.parentNode()->renderStyle();

    // FIXME: Animation unitests will start animations on non-active documents!
    // http://crbug.com/330095
    // ASSERT(document.isActive());
    if (!document.isActive())
        return;
    m_elementStyleResources.setDeviceScaleFactor(document.frameHost()->deviceScaleFactor());
}