📄 cssstyleselector.cpp
字号:
//kdDebug( 6080 ) << "*** Rule #" << j << endl; CSSRuleImpl *childItem = rules->item(j); if (childItem->isStyleRule()) { // It is a StyleRule, so append it to our list CSSStyleRuleImpl* rule = static_cast<CSSStyleRuleImpl*>(childItem); for (CSSSelector* s = rule->selector(); s; s = s->next()) addRule(rule, s); } else { //kdDebug( 6080 ) << "Ignoring child rule of " // "ImportRule: rule is not a StyleRule!" << endl; } } // for rules } // if rules else { //kdDebug( 6080 ) << "CSSMediaRule not rendered: " // << "rule empty or wrong medium!" << endl; } } // ### include other rules }}// -------------------------------------------------------------------------------------// this is mostly boring stuff on how to apply a certain rule to the renderstyle...static Length convertToLength( CSSPrimitiveValueImpl *primitiveValue, RenderStyle *style, QPaintDeviceMetrics *paintDeviceMetrics, bool *ok = 0 ){ Length l; if ( !primitiveValue ) { if ( ok ) *ok = false; } else { int type = primitiveValue->primitiveType(); if(type > CSSPrimitiveValue::CSS_PERCENTAGE && type < CSSPrimitiveValue::CSS_DEG) l = Length(primitiveValue->computeLength(style, paintDeviceMetrics), Fixed); else if(type == CSSPrimitiveValue::CSS_PERCENTAGE) l = Length(int(primitiveValue->getFloatValue(CSSPrimitiveValue::CSS_PERCENTAGE)), Percent); else if(type == CSSPrimitiveValue::CSS_NUMBER) l = Length(int(primitiveValue->getFloatValue(CSSPrimitiveValue::CSS_NUMBER)*100), Percent); else if (type == CSSPrimitiveValue::CSS_HTML_RELATIVE) l = Length(int(primitiveValue->getFloatValue(CSSPrimitiveValue::CSS_HTML_RELATIVE)), Relative); else if ( ok ) *ok = false; } return l;}// color mapping codestruct colorMap { int css_value; QRgb color;};static const colorMap cmap[] = { { CSS_VAL_AQUA, 0xFF00FFFF }, { CSS_VAL_BLACK, 0xFF000000 }, { CSS_VAL_BLUE, 0xFF0000FF }, { CSS_VAL_FUCHSIA, 0xFFFF00FF }, { CSS_VAL_GRAY, 0xFF808080 }, { CSS_VAL_GREEN, 0xFF008000 }, { CSS_VAL_LIME, 0xFF00FF00 }, { CSS_VAL_MAROON, 0xFF800000 }, { CSS_VAL_NAVY, 0xFF000080 }, { CSS_VAL_OLIVE, 0xFF808000 }, { CSS_VAL_ORANGE, 0xFFFFA500 }, { CSS_VAL_PURPLE, 0xFF800080 }, { CSS_VAL_RED, 0xFFFF0000 }, { CSS_VAL_SILVER, 0xFFC0C0C0 }, { CSS_VAL_TEAL, 0xFF008080 }, { CSS_VAL_WHITE, 0xFFFFFFFF }, { CSS_VAL_YELLOW, 0xFFFFFF00 }, { CSS_VAL_INVERT, invertedColor }, { CSS_VAL_TRANSPARENT, transparentColor }, { CSS_VAL_GREY, 0xFF808080 },#if APPLE_CHANGES { CSS_VAL_ACTIVEBORDER, 0xFFE0E0E0 }, { CSS_VAL_ACTIVECAPTION, 0xFF000000 }, { CSS_VAL_APPWORKSPACE, 0xFF000000 }, { CSS_VAL_BUTTONFACE, 0xFFC0C0C0 }, { CSS_VAL_BUTTONHIGHLIGHT, 0xFFE0E0E0 }, { CSS_VAL_BUTTONSHADOW, 0xFFFFFFFF }, { CSS_VAL_BUTTONTEXT, 0xFF000000 }, { CSS_VAL_CAPTIONTEXT, 0xFF000000 }, { CSS_VAL_GRAYTEXT, 0xFF000000 }, { CSS_VAL_HIGHLIGHT, 0xFFFFFFFF }, { CSS_VAL_HIGHLIGHTTEXT, 0xFFFFFFFF }, { CSS_VAL_INACTIVEBORDER, 0xFFFFFFFF }, { CSS_VAL_INACTIVECAPTION, 0xFFFFFFFF }, { CSS_VAL_INACTIVECAPTIONTEXT, 0xFF000000 }, { CSS_VAL_INFOBACKGROUND, 0xFF000000 }, { CSS_VAL_INFOTEXT, 0xFF000000 }, { CSS_VAL_MENU, 0xFFFFFFFF }, { CSS_VAL_MENUTEXT, 0xFFFFFFFF }, { CSS_VAL_SCROLLBAR, 0xFFFFFFFF }, { CSS_VAL_TEXT, 0xFF000000 }, { CSS_VAL_THREEDDARKSHADOW, 0xFF404040 }, { CSS_VAL_THREEDFACE, 0xFFC0C0C0 }, { CSS_VAL_THREEDHIGHLIGHT, 0xFFE0E0E0 }, { CSS_VAL_THREEDLIGHTSHADOW, 0xFFC0C0C0 }, { CSS_VAL_THREEDSHADOW, 0xFFFFFFFF }, { CSS_VAL_WINDOW, 0xFFFFFFFF }, { CSS_VAL_WINDOWFRAME, 0xFFFFFFFF }, { CSS_VAL_WINDOWTEXT, 0xFF000000 },#endif { 0, 0 }};#if !APPLE_CHANGESstruct uiColors { int css_value; const char * configGroup; const char * configEntry;QPalette::ColorGroup group;QColorGroup::ColorRole role;};const char * const wmgroup = "WM";const char * const generalgroup = "General";/* Mapping system settings to CSS 2* Tried hard to get an appropriate mapping - schlpbch*/static const uiColors uimap[] = { // Active window border. { CSS_VAL_ACTIVEBORDER, wmgroup, "background", QPalette::Active, QColorGroup::Light }, // Active window caption. { CSS_VAL_ACTIVECAPTION, wmgroup, "background", QPalette::Active, QColorGroup::Text }, // Text in caption, size box, and scrollbar arrow box. { CSS_VAL_CAPTIONTEXT, wmgroup, "activeForeground", QPalette::Active, QColorGroup::Text }, // Face color for three-dimensional display elements. { CSS_VAL_BUTTONFACE, wmgroup, 0, QPalette::Inactive, QColorGroup::Button }, // Dark shadow for three-dimensional display elements (for edges facing away from the light source). { CSS_VAL_BUTTONHIGHLIGHT, wmgroup, 0, QPalette::Inactive, QColorGroup::Light }, // Shadow color for three-dimensional display elements. { CSS_VAL_BUTTONSHADOW, wmgroup, 0, QPalette::Inactive, QColorGroup::Shadow }, // Text on push buttons. { CSS_VAL_BUTTONTEXT, wmgroup, "buttonForeground", QPalette::Inactive, QColorGroup::ButtonText }, // Dark shadow for three-dimensional display elements. { CSS_VAL_THREEDDARKSHADOW, wmgroup, 0, QPalette::Inactive, QColorGroup::Dark }, // Face color for three-dimensional display elements. { CSS_VAL_THREEDFACE, wmgroup, 0, QPalette::Inactive, QColorGroup::Button }, // Highlight color for three-dimensional display elements. { CSS_VAL_THREEDHIGHLIGHT, wmgroup, 0, QPalette::Inactive, QColorGroup::Light }, // Light color for three-dimensional display elements (for edges facing the light source). { CSS_VAL_THREEDLIGHTSHADOW, wmgroup, 0, QPalette::Inactive, QColorGroup::Midlight }, // Dark shadow for three-dimensional display elements. { CSS_VAL_THREEDSHADOW, wmgroup, 0, QPalette::Inactive, QColorGroup::Shadow }, // Inactive window border. { CSS_VAL_INACTIVEBORDER, wmgroup, "background", QPalette::Disabled, QColorGroup::Background }, // Inactive window caption. { CSS_VAL_INACTIVECAPTION, wmgroup, "inactiveBackground", QPalette::Disabled, QColorGroup::Background }, // Color of text in an inactive caption. { CSS_VAL_INACTIVECAPTIONTEXT, wmgroup, "inactiveForeground", QPalette::Disabled, QColorGroup::Text }, { CSS_VAL_GRAYTEXT, wmgroup, 0, QPalette::Disabled, QColorGroup::Text }, // Menu background { CSS_VAL_MENU, generalgroup, "background", QPalette::Inactive, QColorGroup::Background }, // Text in menus { CSS_VAL_MENUTEXT, generalgroup, "foreground", QPalette::Inactive, QColorGroup::Background }, // Text of item(s) selected in a control. { CSS_VAL_HIGHLIGHT, generalgroup, "selectBackground", QPalette::Inactive, QColorGroup::Background }, // Text of item(s) selected in a control. { CSS_VAL_HIGHLIGHTTEXT, generalgroup, "selectForeground", QPalette::Inactive, QColorGroup::Background }, // Background color of multiple document interface. { CSS_VAL_APPWORKSPACE, generalgroup, "background", QPalette::Inactive, QColorGroup::Text }, // Scroll bar gray area. { CSS_VAL_SCROLLBAR, generalgroup, "background", QPalette::Inactive, QColorGroup::Background }, // Window background. { CSS_VAL_WINDOW, generalgroup, "windowBackground", QPalette::Inactive, QColorGroup::Background }, // Window frame. { CSS_VAL_WINDOWFRAME, generalgroup, "windowBackground", QPalette::Inactive, QColorGroup::Background }, // WindowText { CSS_VAL_WINDOWTEXT, generalgroup, "windowForeground", QPalette::Inactive, QColorGroup::Text }, { CSS_VAL_TEXT, generalgroup, 0, QPalette::Inactive, QColorGroup::Text }, { 0, 0, 0, QPalette::NColorGroups, QColorGroup::NColorRoles }};#endif // !APPLE_CHANGESstatic QColor colorForCSSValue( int css_value ){ // try the regular ones first const colorMap *col = cmap; while ( col->css_value && col->css_value != css_value ) ++col; if ( col->css_value ) return col->color;#if APPLE_CHANGES return QColor();#else const uiColors *uicol = uimap; while ( uicol->css_value && uicol->css_value != css_value ) ++uicol; if ( !uicol->css_value ) { if ( css_value == CSS_VAL_INFOBACKGROUND ) return QToolTip::palette().inactive().background(); else if ( css_value == CSS_VAL_INFOTEXT ) return QToolTip::palette().inactive().foreground(); else if ( css_value == CSS_VAL_BACKGROUND ) { KConfig bckgrConfig("kdesktoprc", true, false); // No multi-screen support bckgrConfig.setGroup("Desktop0"); // Desktop background. return bckgrConfig.readColorEntry("Color1", &qApp->palette().disabled().background()); } return khtml::invalidColor; } const QPalette &pal = qApp->palette(); QColor c = pal.color( uicol->group, uicol->role ); if ( uicol->configEntry ) { KConfig *globalConfig = KGlobal::config(); globalConfig->setGroup( uicol->configGroup ); c = globalConfig->readColorEntry( uicol->configEntry, &c ); } return c;#endif}void CSSStyleSelector::applyDeclarations(bool applyFirst, bool isImportant, int startIndex, int endIndex){ if (startIndex == -1) return; for (int i = startIndex; i <= endIndex; i++) { CSSStyleDeclarationImpl* decl = m_matchedDecls[i]; QPtrList<CSSProperty>* props = decl->values(); if (props) { QPtrListIterator<CSSProperty> propertyIt(*props); CSSProperty* current; for (propertyIt.toFirst(); (current = propertyIt.current()); ++propertyIt) { // give special priority to font-xxx, color properties if (isImportant == current->isImportant()) { bool first; switch(current->id()) { case CSS_PROP_BACKGROUND: case CSS_PROP_BACKGROUND_IMAGE: case CSS_PROP_COLOR: case CSS_PROP_DISPLAY: case CSS_PROP_FONT: case CSS_PROP_FONT_SIZE: case CSS_PROP_FONT_STYLE: case CSS_PROP_FONT_FAMILY: case CSS_PROP_FONT_WEIGHT:#if APPLE_CHANGES case CSS_PROP__APPLE_TEXT_SIZE_ADJUST:#endif // these have to be applied first, because other properties use the computed // values of these porperties. first = true; break; default: first = false; break; } if (first == applyFirst) applyProperty(current->id(), current->value()); } } } }}void CSSStyleSelector::applyProperty( int id, DOM::CSSValueImpl *value ){ //kdDebug( 6080 ) << "applying property " << prop->m_id << endl; CSSPrimitiveValueImpl *primitiveValue = 0; if(value->isPrimitiveValue()) primitiveValue = static_cast<CSSPrimitiveValueImpl *>(value); Length l; bool apply = false; bool isInherit = (parentNode && value->cssValueType() == CSSValue::CSS_INHERIT); bool isInitial = (value->cssValueType() == CSSValue::CSS_INITIAL) || (!parentNode && value->cssValueType() == CSSValue::CSS_INHERIT); // What follows is a list that maps the CSS properties into their corresponding front-end // RenderStyle values. Shorthands (e.g. border, background) occur in this list as well and // are only hit when mapping "inherit" or "initial" into front-end values. switch(id) {// ident only properties case CSS_PROP_BACKGROUND_ATTACHMENT: HANDLE_INHERIT_AND_INITIAL(backgroundAttachment, BackgroundAttachment) if(!primitiveValue) break; switch(primitiveValue->getIdent()) { case CSS_VAL_FIXED: { style->setBackgroundAttachment(false); // only use slow repaints if we actually have a background pixmap if( style->backgroundImage() && view ) view->useSlowRepaints(); break; } case CSS_VAL_SCROLL: style->setBackgroundAttachment(true); break; default: return; } case CSS_PROP_BACKGROUND_REPEAT: { HANDLE_INHERIT_AND_INITIAL(backgroundRepeat, BackgroundRepeat) if(!primitiveValue) return; switch(primitiveValue->getIdent()) { case CSS_VAL_REPEAT: style->setBackgroundRepeat( REPEAT ); break; case CSS_VAL_REPEAT_X: style->setBackgroundRepeat( REPEAT_X ); break; case CSS_VAL_REPEAT_Y: style->setBackgroundRepeat( REPEAT_Y ); break; case CSS_VAL_NO_REPEAT: style->setBackgroundRepeat( NO_REPEAT ); break; default: return; } } case CSS_PROP_BORDER_COLLAPSE: HANDLE_INHERIT_AND_INITIAL(borderCollapse, BorderCollapse) if(!primitiveValue) break; switch(primitiveValue->getIdent()) { case CSS_VAL_COLLAPSE: st
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -