cssstyleselector.cpp
来自「monqueror一个很具有参考价值的源玛」· C++ 代码 · 共 1,977 行 · 第 1/5 页
CPP
1,977 行
{ case CSS_VAL_TOP: align = TOP; break; case CSS_VAL_BOTTOM: align = BOTTOM; break; case CSS_VAL_MIDDLE: align = MIDDLE; break; case CSS_VAL_BASELINE: align = BASELINE; break; case CSS_VAL_TEXT_BOTTOM: align = TEXT_BOTTOM; break; case CSS_VAL_TEXT_TOP: align = TEXT_TOP; break; case CSS_VAL_SUB: align = SUB; break; case CSS_VAL_SUPER: align = SUPER; break; default: return; } style->setVerticalAlign(align); return; } break; case CSS_PROP_FONT_SIZE: { MGFont f = style->font(); int oldSize; int size = 0; QValueList<int> standardSizes = e->ownerDocument()->view()->part()->fontSizes(); if(e->parentNode()) { MGFontInfo fi(e->parentNode()->style()->font()); oldSize = fi.pointSize(); } else oldSize = standardSizes[3]; if(value->valueType() == CSSValue::CSS_INHERIT) { size = oldSize; } else if(primitiveValue->getIdent()) { switch(primitiveValue->getIdent()) { case CSS_VAL_XX_SMALL: size = standardSizes[0]; break; case CSS_VAL_X_SMALL: size = standardSizes[1]; break; case CSS_VAL_SMALL: size = standardSizes[2]; break; case CSS_VAL_MEDIUM: size = standardSizes[3]; break; case CSS_VAL_LARGE: size = standardSizes[4]; break; case CSS_VAL_X_LARGE: size = standardSizes[5]; break; case CSS_VAL_XX_LARGE: size = standardSizes[6]; break; case CSS_VAL_LARGER: // ### use the next bigger standardSize!!! size = oldSize * 12 / 10; break; case CSS_VAL_SMALLER: size = oldSize * 10 / 12; break; default: return; } } else { int type = primitiveValue->primitiveType(); RenderStyle *parentStyle = style; // use the current style as fallback in case we have no parent if(e->parentNode()) parentStyle = e->parentNode()->style(); if(type > CSSPrimitiveValue::CSS_PERCENTAGE && type < CSSPrimitiveValue::CSS_DEG) size = computeLength(primitiveValue, parentStyle, part); else if(type == CSSPrimitiveValue::CSS_PERCENTAGE) size = (int)(primitiveValue->getFloatValue(CSSPrimitiveValue::CSS_PERCENTAGE) * parentStyle->font().pointSize() / 100.); else return; } if(size <= 0) return; // we never want to get smaller than 7 points to keep fonts readable int min = e->ownerDocument()->view()->part()->settings()->minFontSize(); if(size < min ) size = min; // ok, now some magic to get a nice unscaled font // ### all other font properties should be set before this one!!!! // ####### make it use the charset needed!!!! const MGHTMLSettings *s = e->ownerDocument()->view()->part()->settings(); MGFont::CharSet cs = s->charset(); f.setCharSet (cs); f.setPointSize (size); style->setFont (f); return; }// angle case CSS_PROP_ELEVATION:// number case CSS_PROP_FONT_SIZE_ADJUST: case CSS_PROP_ORPHANS: case CSS_PROP_PITCH_RANGE: case CSS_PROP_RICHNESS: case CSS_PROP_SPEECH_RATE: case CSS_PROP_STRESS: case CSS_PROP_WIDOWS: break; case CSS_PROP_Z_INDEX: { if(value->valueType() == CSSValue::CSS_INHERIT) { if(!e->parentNode()) return; style->setZIndex(e->parentNode()->style()->zIndex()); return; } if(!primitiveValue || primitiveValue->primitiveType() != CSSPrimitiveValue::CSS_NUMBER) return; style->setZIndex((int)primitiveValue->getFloatValue(CSSPrimitiveValue::CSS_NUMBER)); return; }// length, percent, number case CSS_PROP_LINE_HEIGHT: { if(value->valueType() == CSSValue::CSS_INHERIT) { if(!e->parentNode()) return; style->setLineHeight(e->parentNode()->style()->lineHeight()); return; } Length lineHeight; if(!primitiveValue) return; int type = primitiveValue->primitiveType(); if(primitiveValue->getIdent() == CSS_VAL_NORMAL) lineHeight = Length(100, Percent); else if(type > CSSPrimitiveValue::CSS_PERCENTAGE && type < CSSPrimitiveValue::CSS_DEG) lineHeight = Length(computeLength(primitiveValue, style, part), Fixed); else if(type == CSSPrimitiveValue::CSS_PERCENTAGE) lineHeight = Length((int)primitiveValue->getFloatValue(CSSPrimitiveValue::CSS_PERCENTAGE), Percent); else if(type == CSSPrimitiveValue::CSS_NUMBER) lineHeight = Length((int)primitiveValue->getFloatValue(CSSPrimitiveValue::CSS_NUMBER)*100, Percent); else return; style->setLineHeight(lineHeight); return; }// number, percent case CSS_PROP_VOLUME:// frequency case CSS_PROP_PITCH: break;// string case CSS_PROP_TEXT_ALIGN: { if(value->valueType() == CSSValue::CSS_INHERIT) { if(!e->parentNode()) return; style->setTextAlign(e->parentNode()->style()->textAlign()); return; } if(!primitiveValue) return; if(primitiveValue->getIdent()) { khtml::ETextAlign align; switch(primitiveValue->getIdent()) { case CSS_VAL_LEFT: align = LEFT; break; case CSS_VAL_RIGHT: align = RIGHT; break; case CSS_VAL_CENTER: align = CENTER; break; case CSS_VAL_JUSTIFY: align = JUSTIFY; break; case CSS_VAL_KONQ_CENTER: align = KONQ_CENTER; break; default: return; } style->setTextAlign(align); return; } }// rect case CSS_PROP_CLIP: // rect, ident break;// lists case CSS_PROP_CONTENT: // list of string, uri, counter, attr, i case CSS_PROP_COUNTER_INCREMENT: // list of CSS2CounterIncrement case CSS_PROP_COUNTER_RESET: // list of CSS2CounterReset break; case CSS_PROP_FONT_FAMILY: // list of strings and ids { if(!value->isValueList()) return; CSSValueListImpl *list = static_cast<CSSValueListImpl *>(value); int len = list->length(); const MGHTMLSettings *s = e->ownerDocument()->view()->part()->settings(); MGFont f = style->font(); QString family; // in MiniGUI family is same as face. for(int i = 0; i < len; i++) { CSSValueImpl *item = list->item(i); if(!item->isPrimitiveValue()) continue; CSSPrimitiveValueImpl *val = static_cast<CSSPrimitiveValueImpl *>(item); if(!val->primitiveType() == CSSPrimitiveValue::CSS_STRING) return; DOMStringImpl *str = val->getStringValue(); QString face = QConstString(str->s, str->l).string().lower(); //kdDebug(0) << "searching for face '" << face << "'" << endl; if(face == "serif") face = s->serifFontName(); else if(face == "sans-serif") face = s->sansSerifFontName(); else if( face == "cursive") face = s->cursiveFontName(); else if( face == "fantasy") face = s->fantasyFontName(); else if( face == "monospace") face = s->fixedFontName(); f.setFamily( face ); style->setFont(f); break; } //kdDebug() << "khtml::setFont: time=" << qt.elapsed() << endl; break; } case CSS_PROP_QUOTES: // list of strings or i case CSS_PROP_SIZE: // ### look up break; case CSS_PROP_TEXT_DECORATION: // list of ident // ### no list at the moment { if(value->valueType() == CSSValue::CSS_INHERIT) { if(!e->parentNode()) return; style->setTextDecoration(e->parentNode()->style()->textDecoration()); style->setTextDecorationColor(e->parentNode()->style()->textDecorationColor()); return; } int t = TDNONE; if(!value->isValueList()) return; CSSValueListImpl *list = static_cast<CSSValueListImpl *>(value); int len = list->length(); for(int i = 0; i < len; i++) { CSSValueImpl *item = list->item(i); if(!item->isPrimitiveValue()) continue; primitiveValue = static_cast<CSSPrimitiveValueImpl *>(item); switch(primitiveValue->getIdent()) { case CSS_VAL_NONE: t = TDNONE; break; case CSS_VAL_UNDERLINE: t |= UNDERLINE; break; case CSS_VAL_OVERLINE: t |= OVERLINE; break; case CSS_VAL_LINE_THROUGH: t |= LINE_THROUGH; break; case CSS_VAL_BLINK: t |= BLINK; break; default: return; } style->setTextDecoration(t); style->setTextDecorationColor(style->color()); } break; } case CSS_PROP_VOICE_FAMILY: // list of strings and i break;// shorthand properties case CSS_PROP_BACKGROUND: if(value->valueType() != CSSValue::CSS_INHERIT || !e->parentNode()) return; style->setBackgroundColor(e->parentNode()->style()->backgroundColor()); style->setBackgroundImage(e->parentNode()->style()->backgroundImage()); style->setBackgroundRepeat(e->parentNode()->style()->backgroundRepeat()); style->setBackgroundAttachment(e->parentNode()->style()->backgroundAttachment());// style->setBackgroundPosition(e->parentNode()->style()->backgroundPosition()); break; case CSS_PROP_BORDER_COLOR: if(primitiveValue && primitiveValue->getIdent() == CSS_VAL_TRANSPARENT) { style->setBorderTopColor(MGColor()); style->setBorderBottomColor(MGColor()); style->setBorderLeftColor(MGColor()); style->setBorderRightColor(MGColor()); return; } case CSS_PROP_BORDER: case CSS_PROP_BORDER_STYLE: case CSS_PROP_BORDER_WIDTH: if(value->valueType() != CSSValue::CSS_INHERIT || !e->parentNode()) return; if(prop->m_id == CSS_PROP_BORDER || prop->m_id == CSS_PROP_BORDER_COLOR) { style->setBorderTopColor(e->parentNode()->style()->borderTopColor()); style->setBorderBottomColor(e->parentNode()->style()->borderBottomColor()); style->setBorderLeftColor(e->parentNode()->style()->borderLeftColor()); style->setBorderRightColor(e->parentNode()->style()->borderRightColor()); } if(prop->m_id == CSS_PROP_BORDER || prop->m_id == CSS_PROP_BORDER_STYLE) { style->setBorderTopStyle(e->parentNode()->style()->borderTopStyle()); style->setBorderBottomStyle(e->parentNode()->style()->borderBottomStyle()); style->setBorderLeftStyle(e->parentNode()->style()->borderLeftStyle()); style->setBorderRightStyle(e->parentNode()->style()->borderRightStyle()); } if(prop->m_id == CSS_PROP_BORDER || prop->m_id == CSS_PROP_BORDER_WIDTH) { style->setBorderTopWidth(e->parentNode()->style()->borderTopWidth()); style->setBorderBottomWidth(e->parentNode()->style()->borderBottomWidth()); style->setBorderLeftWidth(e->parentNode()->style()->borderLeftWidth()); style->setBorderRightWidth(e->parentNode()->style()->borderRightWidth()); } return; case CSS_PROP_BORDER_TOP: if(value->valueType() != CSSValue::CSS_INHERIT || !e->parentNode()) return; style->setBorderTopColor(e->parentNode()->style()->borderTopColor()); style->setBorderTopStyle(e->parentNode()->style()->borderTopStyle()); style->setBorderTopWidth(e->parentNode()->style()->borderTopWidth()); return; case CSS_PROP_BORDER_RIGHT: if(value->valueType() != CSSValue::CSS_INHERIT || !e->parentNode()) return; style->setBorderRightColor(e->parentNode()->style()->borderRightColor()); style->setBorderRightStyle(e->parentNode()->style()->borderRightStyle()); style->setBorderRightWidth(e->parentNode()->style()->borderRightWidth()); return; case CSS_PROP_BORDER_BOTTOM: if(value->valueType() != CSSValue::CSS_INHERIT || !e->parentNode()) return; style->setBorderBottomColor(e->parentNode()->style()->borderBottomColor()); style->setBorderBottomStyle(e->parentNode()->style()->borderBottomStyle()); style->setBorderBottomWidth(e->parentNode()->style()->borderBottomWidth()); return; case CSS_PROP_BORDER_LEFT: if(value->valueType() != CSSValue::CSS_INHERIT || !e->parentNode()) return; style->setBorderLeftColor(e->parentNode()->style()->borderLeftColor()); style->setBorderLeftStyle(e->parentNode()->style()->borderLeftStyle()); style->setBorderLeftWidth(e->parentNode()->style()->borderLeftWidth()); return; case CSS_PROP_MARGIN: if(value->valueType() != CSSValue::CSS_INHERIT || !e->parentNode()) return; style->setMarginTop(e->parentNode()->style()->marginTop()); style->setMarginBottom(e->parentNode()->style()->marginBottom()); style->setMarginLeft(e->parentNode()->style()->marginLeft()); style->setMarginRight(e->parentNode()->style()->marginRight()); return; case CSS_PROP_PADDING: if(value->valueType() != CSSValue::CSS_INHERIT || !e->parentNode()) return; style->setPaddingTop(e->parentNode()->style()->paddingTop()); style->setPaddingBottom(e->parentNode()->style()->paddingBottom()); style->setPaddingLeft(e->parentNode()->style()->paddingLeft()); style->setPaddingRight(e->parentNode()->style()->paddingRight()); return; case CSS_PROP_CUE: case CSS_PROP_FONT: case CSS_PROP_LIST_STYLE: case CSS_PROP_OUTLINE: case CSS_PROP_PAUSE: break; default: return; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?