📄 css_valueimpl.cpp
字号:
{ switch(m_type) { case CSSPrimitiveValue::CSS_STRING: case CSSPrimitiveValue::CSS_URI: case CSSPrimitiveValue::CSS_ATTR: if(m_value.string) m_value.string->deref(); break; case CSSPrimitiveValue::CSS_COUNTER: m_value.counter->deref(); break; case CSSPrimitiveValue::CSS_RECT: m_value.rect->deref(); default: break; } m_type = 0;}int CSSPrimitiveValueImpl::computeLength( khtml::RenderStyle *style, QPaintDeviceMetrics *devMetrics ){ double result = computeLengthFloat( style, devMetrics );#if APPLE_CHANGES // This conversion is imprecise, often resulting in values of, e.g., 44.99998. We // need to go ahead and round if we're really close to the next integer value. int intResult = (int)(result + (result < 0 ? -0.01 : +0.01));#else int intResult = (int)result;#endif return intResult; }int CSSPrimitiveValueImpl::computeLength( khtml::RenderStyle *style, QPaintDeviceMetrics *devMetrics, double multiplier ){ double result = multiplier * computeLengthFloat( style, devMetrics );#if APPLE_CHANGES // This conversion is imprecise, often resulting in values of, e.g., 44.99998. We // need to go ahead and round if we're really close to the next integer value. int intResult = (int)(result + (result < 0 ? -0.01 : +0.01));#else int intResult = (int)result;#endif return intResult; }double CSSPrimitiveValueImpl::computeLengthFloat( khtml::RenderStyle *style, QPaintDeviceMetrics *devMetrics, bool applyZoomFactor ){ unsigned short type = primitiveType(); double dpiY = 72.; // fallback if ( devMetrics ) dpiY = devMetrics->logicalDpiY(); if ( !khtml::printpainter && dpiY < 96 ) dpiY = 96.; double factor = 1.; switch(type) { case CSSPrimitiveValue::CSS_EMS: factor = applyZoomFactor ? style->htmlFont().getFontDef().computedSize : style->htmlFont().getFontDef().specifiedSize; break; case CSSPrimitiveValue::CSS_EXS: // FIXME: We have a bug right now where the zoom will be applied multiple times to EX units. // We really need to compute EX using fontMetrics for the original specifiedSize and not use // our actual constructed rendering font. { QFontMetrics fm = style->fontMetrics();#if APPLE_CHANGES factor = fm.xHeight();#else QRect b = fm.boundingRect('x'); factor = b.height();#endif break; } case CSSPrimitiveValue::CSS_PX: break; case CSSPrimitiveValue::CSS_CM: factor = dpiY/2.54; //72dpi/(2.54 cm/in) break; case CSSPrimitiveValue::CSS_MM: factor = dpiY/25.4; break; case CSSPrimitiveValue::CSS_IN: factor = dpiY; break; case CSSPrimitiveValue::CSS_PT: factor = dpiY/72.; break; case CSSPrimitiveValue::CSS_PC: // 1 pc == 12 pt factor = dpiY*12./72.; break; default: return -1; } return getFloatValue(type)*factor;}void CSSPrimitiveValueImpl::setFloatValue( unsigned short unitType, double floatValue, int &exceptioncode ){ exceptioncode = 0; cleanup(); // ### check if property supports this type if(m_type > CSSPrimitiveValue::CSS_DIMENSION) { exceptioncode = CSSException::SYNTAX_ERR + CSSException::_EXCEPTION_OFFSET; return; } //if(m_type > CSSPrimitiveValue::CSS_DIMENSION) throw DOMException(DOMException::INVALID_ACCESS_ERR); m_value.num = floatValue; m_type = unitType;}void CSSPrimitiveValueImpl::setStringValue( unsigned short stringType, const DOMString &stringValue, int &exceptioncode ){ exceptioncode = 0; cleanup(); //if(m_type < CSSPrimitiveValue::CSS_STRING) throw DOMException(DOMException::INVALID_ACCESS_ERR); //if(m_type > CSSPrimitiveValue::CSS_ATTR) throw DOMException(DOMException::INVALID_ACCESS_ERR); if(m_type < CSSPrimitiveValue::CSS_STRING || m_type >> CSSPrimitiveValue::CSS_ATTR) { exceptioncode = CSSException::SYNTAX_ERR + CSSException::_EXCEPTION_OFFSET; return; } if(stringType != CSSPrimitiveValue::CSS_IDENT) { m_value.string = stringValue.implementation(); m_value.string->ref(); m_type = stringType; } // ### parse ident}unsigned short CSSPrimitiveValueImpl::cssValueType() const{ return CSSValue::CSS_PRIMITIVE_VALUE;}bool CSSPrimitiveValueImpl::parseString( const DOMString &/*string*/, bool ){ // ### return false;}int CSSPrimitiveValueImpl::getIdent(){ if(m_type != CSSPrimitiveValue::CSS_IDENT) return 0; return m_value.ident;}DOM::DOMString CSSPrimitiveValueImpl::cssText() const{ // ### return the original value instead of a generated one (e.g. color // name if it was specified) - check what spec says about this DOMString text; switch ( m_type ) { case CSSPrimitiveValue::CSS_UNKNOWN: // ### break; case CSSPrimitiveValue::CSS_NUMBER: text = DOMString(QString::number( (int)m_value.num )); break; case CSSPrimitiveValue::CSS_PERCENTAGE: text = DOMString(QString::number( m_value.num ) + "%"); break; case CSSPrimitiveValue::CSS_EMS: text = DOMString(QString::number( m_value.num ) + "em"); break; case CSSPrimitiveValue::CSS_EXS: text = DOMString(QString::number( m_value.num ) + "ex"); break; case CSSPrimitiveValue::CSS_PX: text = DOMString(QString::number( m_value.num ) + "px"); break; case CSSPrimitiveValue::CSS_CM: text = DOMString(QString::number( m_value.num ) + "cm"); break; case CSSPrimitiveValue::CSS_MM: text = DOMString(QString::number( m_value.num ) + "mm"); break; case CSSPrimitiveValue::CSS_IN: text = DOMString(QString::number( m_value.num ) + "in"); break; case CSSPrimitiveValue::CSS_PT: text = DOMString(QString::number( m_value.num ) + "pt"); break; case CSSPrimitiveValue::CSS_PC: text = DOMString(QString::number( m_value.num ) + "pc"); break; case CSSPrimitiveValue::CSS_DEG: text = DOMString(QString::number( m_value.num ) + "deg"); break; case CSSPrimitiveValue::CSS_RAD: text = DOMString(QString::number( m_value.num ) + "rad"); break; case CSSPrimitiveValue::CSS_GRAD: text = DOMString(QString::number( m_value.num ) + "grad"); break; case CSSPrimitiveValue::CSS_MS: text = DOMString(QString::number( m_value.num ) + "ms"); break; case CSSPrimitiveValue::CSS_S: text = DOMString(QString::number( m_value.num ) + "s"); break; case CSSPrimitiveValue::CSS_HZ: text = DOMString(QString::number( m_value.num ) + "hz"); break; case CSSPrimitiveValue::CSS_KHZ: text = DOMString(QString::number( m_value.num ) + "khz"); break; case CSSPrimitiveValue::CSS_DIMENSION: // ### break; case CSSPrimitiveValue::CSS_STRING: text = DOMString(m_value.string); break; case CSSPrimitiveValue::CSS_URI: text = "url("; text += DOMString( m_value.string ); text += ")"; break; case CSSPrimitiveValue::CSS_IDENT: text = getValueName(m_value.ident); break; case CSSPrimitiveValue::CSS_ATTR: // ### break; case CSSPrimitiveValue::CSS_COUNTER: // ### break; case CSSPrimitiveValue::CSS_RECT: { RectImpl* rectVal = getRectValue(); text = "rect("; text += rectVal->top()->cssText() + " "; text += rectVal->right()->cssText() + " "; text += rectVal->bottom()->cssText() + " "; text += rectVal->left()->cssText() + ")"; break; } case CSSPrimitiveValue::CSS_RGBCOLOR: { QColor color(m_value.rgbcolor); if (qAlpha(m_value.rgbcolor)) text = "rgba("; else text = "rgb("; text += QString::number(color.red()) + ", "; text += QString::number(color.green()) + ", "; text += QString::number(color.blue()); if (qAlpha(m_value.rgbcolor)) text += ", " + QString::number((float)qAlpha(m_value.rgbcolor) / 0xFF); text += ")"; break; } default: break; } return text;}// -----------------------------------------------------------------RectImpl::RectImpl(){ m_top = 0; m_right = 0; m_bottom = 0; m_left = 0;}RectImpl::~RectImpl(){ if (m_top) m_top->deref(); if (m_right) m_right->deref(); if (m_bottom) m_bottom->deref(); if (m_left) m_left->deref();}void RectImpl::setTop( CSSPrimitiveValueImpl *top ){ if( top ) top->ref(); if ( m_top ) m_top->deref(); m_top = top;}void RectImpl::setRight( CSSPrimitiveValueImpl *right ){ if( right ) right->ref(); if ( m_right ) m_right->deref(); m_right = right;}void RectImpl::setBottom( CSSPrimitiveValueImpl *bottom ){ if( bottom ) bottom->ref(); if ( m_bottom ) m_bottom->deref(); m_bottom = bottom;}void RectImpl::setLeft( CSSPrimitiveValueImpl *left ){ if( left ) left->ref(); if ( m_left ) m_left->deref(); m_left = left;}// -----------------------------------------------------------------CSSImageValueImpl::CSSImageValueImpl(const DOMString &url, StyleBaseImpl *style) : CSSPrimitiveValueImpl(url, CSSPrimitiveValue::CSS_URI), m_image(0), m_accessedImage(false){}CSSImageValueImpl::CSSImageValueImpl() : CSSPrimitiveValueImpl(CSS_VAL_NONE), m_image(0), m_accessedImage(true){}CSSImageValueImpl::~CSSImageValueImpl(){ if(m_image) m_image->deref(this);}khtml::CachedImage* CSSImageValueImpl::image(khtml::DocLoader* loader){ if (!m_accessedImage) { m_accessedImage = true; if (loader) m_image = loader->requestImage(getStringValue()); else m_image = khtml::Cache::requestImage(0, getStringValue()); if(m_image) m_image->ref(this); } return m_image;}// ------------------------------------------------------------------------FontFamilyValueImpl::FontFamilyValueImpl( const QString &string): CSSPrimitiveValueImpl( DOMString(), CSSPrimitiveValue::CSS_STRING){ static const QRegExp parenReg(" \\(.*\\)$"); static const QRegExp braceReg(" \\[.*\\]$");#if APPLE_CHANGES parsedFontName = string; // a language tag is often added in braces at the end. Remove it. parsedFontName.replace(parenReg, ""); // remove [Xft] qualifiers parsedFontName.replace(braceReg, "");#else const QString &available = KHTMLSettings::availableFamilies(); QString face = string.lower(); // a languge tag is often added in braces at the end. Remove it. face = face.replace(parenReg, ""); // remove [Xft] qualifiers face = face.replace(braceReg, ""); //kdDebug(0) << "searching for face '" << face << "'" << endl; int pos = available.find( face, 0, false ); if( pos == -1 ) { QString str = face; int p = face.find(' '); // Arial Blk --> Arial // MS Sans Serif --> Sans Serif if ( p != -1 ) { if(p > 0 && (int)str.length() - p > p + 1) str = str.mid( p+1 ); else str.truncate( p ); pos = available.find( str, 0, false); } } if ( pos != -1 ) { int pos1 = available.findRev( ',', pos ) + 1; pos = available.find( ',', pos ); if ( pos == -1 ) pos = available.length(); parsedFontName = available.mid( pos1, pos - pos1 ); }#endif // !APPLE_CHANGES}DOM::DOMString FontFamilyValueImpl::cssText() const{ return parsedFontName;}FontValueImpl::FontValueImpl() : style(0), variant(0), weight(0), size(0), lineHeight(0), family(0){}FontValueImpl::~FontValueImpl(){ delete style; delete variant; delete weight; delete size; delete lineHeight; delete family;}DOMString FontValueImpl::cssText() const{ // font variant weight size / line-height family DOMString result(""); if (style) { result += style->cssText(); } if (variant) { if (result.length() > 0) { result += " "; } result += variant->cssText(); } if (weight) { if (result.length() > 0) { result += " "; } result += weight->cssText(); } if (size) { if (result.length() > 0) { result += " "; } result += size->cssText(); } if (lineHeight) { if (!size) { result += " "; } result += "/"; result += lineHeight->cssText(); } if (family) { if (result.length() > 0) { result += " "; } result += family->cssText(); } return result;} // Used for text-shadow and box-shadowShadowValueImpl::ShadowValueImpl(CSSPrimitiveValueImpl* _x, CSSPrimitiveValueImpl* _y, CSSPrimitiveValueImpl* _blur, CSSPrimitiveValueImpl* _color):x(_x), y(_y), blur(_blur), color(_color) {}ShadowValueImpl::~ShadowValueImpl(){ delete x; delete y; delete blur; delete color;}DOMString ShadowValueImpl::cssText() const{ DOMString text(""); if (color) { text += color->cssText(); } if (x) { if (text.length() > 0) { text += " "; } text += x->cssText(); } if (y) { if (text.length() > 0) { text += " "; } text += y->cssText(); } if (blur) { if (text.length() > 0) { text += " "; } text += blur->cssText(); } return text;}// Used for box-flex-transition-groupFlexGroupTransitionValueImpl::FlexGroupTransitionValueImpl():autoValue(true), group1(0), group2(0), length(0){}FlexGroupTransitionValueImpl::FlexGroupTransitionValueImpl(unsigned int _group1, unsigned int _group2, CSSPrimitiveValueImpl* _length):autoValue(false), group1(_group1), group2(_group2), length(_length){}FlexGroupTransitionValueImpl::~FlexGroupTransitionValueImpl(){ delete length;}DOMString FlexGroupTransitionValueImpl::cssText() const{ DOMString text(QString::number(group1)); if (group2) { text += "/"; text += QString::number(group2); } if (length) { text += " "; text += length->cssText(); } return text;}DOMString CSSProperty::cssText() const{ return getPropertyName(m_id) + DOMString(": ") + m_value->cssText() + (m_bImportant ? DOMString(" !important") : DOMString()) + DOMString("; ");}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -