⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 css_computedstyle.cpp

📁 khtml在gtk上的移植版本
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/** * css_computedstyle.cpp * * Copyright (C)  2004  Zack Rusin <zack@kde.org> * Copyright (C)  2004  Apple Computer, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * 02111-1307  USA */#include "css_computedstyle.h"#include "cssproperties.h"#include "dom_atomicstring.h"#include "font.h"#include "khtmllayout.h"#include "loader.h"#include "rendering/render_style.h"#include "rendering/render_object.h"#if APPLE_CHANGES#include "KWQAssertions.h"#include "KWQFontFamily.h"#include "KWQLogging.h"#endifusing khtml::EBorderStyle;using khtml::ETextAlign;using khtml::Font;using khtml::FontDef;using khtml::Length;namespace DOM {static CSSValueImpl *valueForLength(const Length &length, int max){    if (length.isPercent()) {        return new CSSPrimitiveValueImpl(length.length(), CSSPrimitiveValue::CSS_PERCENTAGE);    }    else {        return new CSSPrimitiveValueImpl(length.minWidth(max), CSSPrimitiveValue::CSS_PX);    }}static DOMString stringForBorderStyle(EBorderStyle style){    switch (style) {        case khtml::BNONE:            return "none";        case khtml::BHIDDEN:            return "hidden";        case khtml::INSET:            return "inset";        case khtml::GROOVE:            return "groove";        case khtml::RIDGE:            return "ridge";        case khtml::OUTSET:            return "outset";        case khtml::DOTTED:            return "dotted";        case khtml::DASHED:            return "dashed";        case khtml::SOLID:            return "solid";        case khtml::DOUBLE:            return "double";    }    ASSERT_NOT_REACHED();    return "";}static DOMString stringForTextAlign(ETextAlign align){    switch (align) {        case khtml::TAAUTO:            return "auto";        case khtml::LEFT:            return "left";        case khtml::RIGHT:            return "right";        case khtml::CENTER:            return "center";        case khtml::JUSTIFY:            return "justify";        case khtml::KHTML_LEFT:            return "-khtml-left";        case khtml::KHTML_RIGHT:            return "-khtml-right";        case khtml::KHTML_CENTER:            return "-khtml-center";    }    ASSERT_NOT_REACHED();    return "";}CSSComputedStyleDeclarationImpl::CSSComputedStyleDeclarationImpl(NodeImpl *n)    : CSSStyleDeclarationImpl(0){    setNode(n);    m_renderer = node()->renderer();}CSSComputedStyleDeclarationImpl::~CSSComputedStyleDeclarationImpl(){}DOMString CSSComputedStyleDeclarationImpl::cssText() const{    ERROR("unimplemented");    return DOMString();}void CSSComputedStyleDeclarationImpl::setCssText(const DOMString &){    ERROR("CSSComputedStyleDeclarationImpl is a read-only object");}CSSValueImpl *CSSComputedStyleDeclarationImpl::getPropertyCSSValue(int propertyID) const{    // Make sure our layout is up to date before we allow a query on these attributes.    DocumentImpl* docimpl = node()->getDocument();    if (docimpl)        docimpl->updateLayout();    switch(propertyID)    {    case CSS_PROP_BACKGROUND_COLOR:        return new CSSPrimitiveValueImpl(m_renderer->style()->backgroundColor().rgb());    case CSS_PROP_BACKGROUND_IMAGE:        if (m_renderer->style()->backgroundImage())            return new CSSPrimitiveValueImpl(m_renderer->style()->backgroundImage()->url(),                                              CSSPrimitiveValue::CSS_URI);        return 0;    case CSS_PROP_BACKGROUND_REPEAT:        switch (m_renderer->style()->backgroundRepeat()) {            case khtml::REPEAT:                return new CSSPrimitiveValueImpl("repeat", CSSPrimitiveValue::CSS_STRING);            case khtml::REPEAT_X:                return new CSSPrimitiveValueImpl("repeat-x", CSSPrimitiveValue::CSS_STRING);            case khtml::REPEAT_Y:                return new CSSPrimitiveValueImpl("repeat-y", CSSPrimitiveValue::CSS_STRING);            case khtml::NO_REPEAT:                return new CSSPrimitiveValueImpl("no-repeat", CSSPrimitiveValue::CSS_STRING);            default:                ASSERT_NOT_REACHED();        }    case CSS_PROP_BACKGROUND_ATTACHMENT:        if (m_renderer->style()->backgroundAttachment())            return new CSSPrimitiveValueImpl("scroll", CSSPrimitiveValue::CSS_STRING);        else            return new CSSPrimitiveValueImpl("fixed", CSSPrimitiveValue::CSS_STRING);    case CSS_PROP_BACKGROUND_POSITION:    {        DOMString string;        Length length(m_renderer->style()->backgroundXPosition());        if (length.isPercent())            string = QString::number(length.length()) + "%";        else            string = QString::number(length.minWidth(m_renderer->contentWidth()));        string += " ";        length = m_renderer->style()->backgroundYPosition();        if (length.isPercent())            string += QString::number(length.length()) + "%";        else            string += QString::number(length.minWidth(m_renderer->contentWidth()));        return new CSSPrimitiveValueImpl(string, CSSPrimitiveValue::CSS_STRING);    }    case CSS_PROP_BACKGROUND_POSITION_X:        return valueForLength(m_renderer->style()->backgroundXPosition(), m_renderer->contentWidth());    case CSS_PROP_BACKGROUND_POSITION_Y:        return valueForLength(m_renderer->style()->backgroundYPosition(), m_renderer->contentHeight());#ifndef KHTML_NO_XBL    case CSS_PROP__KHTML_BINDING:        // FIXME: unimplemented		break;#endif    case CSS_PROP_BORDER_COLLAPSE:        if (m_renderer->style()->borderCollapse())            return new CSSPrimitiveValueImpl("collapse", CSSPrimitiveValue::CSS_STRING);        else            return new CSSPrimitiveValueImpl("separate", CSSPrimitiveValue::CSS_STRING);    case CSS_PROP_BORDER_SPACING:    {        QString string(QString::number(m_renderer->style()->horizontalBorderSpacing()) +             "px " +             QString::number(m_renderer->style()->verticalBorderSpacing()) +            "px");        return new CSSPrimitiveValueImpl(string, CSSPrimitiveValue::CSS_STRING);    }    case CSS_PROP__KHTML_BORDER_HORIZONTAL_SPACING:        return new CSSPrimitiveValueImpl(m_renderer->style()->horizontalBorderSpacing(), CSSPrimitiveValue::CSS_PX);    case CSS_PROP__KHTML_BORDER_VERTICAL_SPACING:        return new CSSPrimitiveValueImpl(m_renderer->style()->verticalBorderSpacing(), CSSPrimitiveValue::CSS_PX);    case CSS_PROP_BORDER_TOP_COLOR:        return new CSSPrimitiveValueImpl(m_renderer->style()->borderLeftColor().rgb());    case CSS_PROP_BORDER_RIGHT_COLOR:        return new CSSPrimitiveValueImpl(m_renderer->style()->borderRightColor().rgb());    case CSS_PROP_BORDER_BOTTOM_COLOR:        return new CSSPrimitiveValueImpl(m_renderer->style()->borderBottomColor().rgb());    case CSS_PROP_BORDER_LEFT_COLOR:        return new CSSPrimitiveValueImpl(m_renderer->style()->borderLeftColor().rgb());    case CSS_PROP_BORDER_TOP_STYLE:        return new CSSPrimitiveValueImpl(stringForBorderStyle(m_renderer->style()->borderTopStyle()), CSSPrimitiveValue::CSS_STRING);    case CSS_PROP_BORDER_RIGHT_STYLE:        return new CSSPrimitiveValueImpl(stringForBorderStyle(m_renderer->style()->borderRightStyle()), CSSPrimitiveValue::CSS_STRING);    case CSS_PROP_BORDER_BOTTOM_STYLE:        return new CSSPrimitiveValueImpl(stringForBorderStyle(m_renderer->style()->borderBottomStyle()), CSSPrimitiveValue::CSS_STRING);    case CSS_PROP_BORDER_LEFT_STYLE:        return new CSSPrimitiveValueImpl(stringForBorderStyle(m_renderer->style()->borderLeftStyle()), CSSPrimitiveValue::CSS_STRING);    case CSS_PROP_BORDER_TOP_WIDTH:        return new CSSPrimitiveValueImpl(m_renderer->style()->borderTopWidth(), CSSPrimitiveValue::CSS_PX);    case CSS_PROP_BORDER_RIGHT_WIDTH:        return new CSSPrimitiveValueImpl(m_renderer->style()->borderRightWidth(), CSSPrimitiveValue::CSS_PX);    case CSS_PROP_BORDER_BOTTOM_WIDTH:        return new CSSPrimitiveValueImpl(m_renderer->style()->borderBottomWidth(), CSSPrimitiveValue::CSS_PX);    case CSS_PROP_BORDER_LEFT_WIDTH:        return new CSSPrimitiveValueImpl(m_renderer->style()->borderLeftWidth(), CSSPrimitiveValue::CSS_PX);    case CSS_PROP_BOTTOM:        // FIXME: unimplemented		break;    case CSS_PROP__KHTML_BOX_ALIGN:        // FIXME: unimplemented		break;    case CSS_PROP__KHTML_BOX_DIRECTION:        // FIXME: unimplemented		break;    case CSS_PROP__KHTML_BOX_FLEX:        // FIXME: unimplemented		break;    case CSS_PROP__KHTML_BOX_FLEX_GROUP:        // FIXME: unimplemented		break;    case CSS_PROP__KHTML_BOX_LINES:        // FIXME: unimplemented		break;    case CSS_PROP__KHTML_BOX_ORDINAL_GROUP:        // FIXME: unimplemented		break;    case CSS_PROP__KHTML_BOX_ORIENT:        // FIXME: unimplemented		break;    case CSS_PROP__KHTML_BOX_PACK:        // FIXME: unimplemented		break;    case CSS_PROP_CAPTION_SIDE:        // FIXME: unimplemented		break;    case CSS_PROP_CLEAR:        // FIXME: unimplemented		break;    case CSS_PROP_CLIP:        // FIXME: unimplemented		break;    case CSS_PROP_COLOR:        return new CSSPrimitiveValueImpl(m_renderer->style()->color().rgb());    case CSS_PROP_CONTENT:        // FIXME: unimplemented		break;    case CSS_PROP_COUNTER_INCREMENT:        // FIXME: unimplemented		break;    case CSS_PROP_COUNTER_RESET:        // FIXME: unimplemented		break;    case CSS_PROP_CURSOR:        // FIXME: unimplemented		break;    case CSS_PROP_DIRECTION:        // FIXME: unimplemented		break;    case CSS_PROP_DISPLAY:        switch (m_renderer->style()->display()) {            case khtml::INLINE:                return new CSSPrimitiveValueImpl("inline", CSSPrimitiveValue::CSS_STRING);            case khtml::BLOCK:                return new CSSPrimitiveValueImpl("block", CSSPrimitiveValue::CSS_STRING);            case khtml::LIST_ITEM:                return new CSSPrimitiveValueImpl("list-item", CSSPrimitiveValue::CSS_STRING);            case khtml::RUN_IN:                return new CSSPrimitiveValueImpl("run-in", CSSPrimitiveValue::CSS_STRING);            case khtml::COMPACT:                return new CSSPrimitiveValueImpl("compact", CSSPrimitiveValue::CSS_STRING);            case khtml::INLINE_BLOCK:                return new CSSPrimitiveValueImpl("inline-block", CSSPrimitiveValue::CSS_STRING);            case khtml::TABLE:                return new CSSPrimitiveValueImpl("table", CSSPrimitiveValue::CSS_STRING);            case khtml::INLINE_TABLE:                return new CSSPrimitiveValueImpl("inline-table", CSSPrimitiveValue::CSS_STRING);            case khtml::TABLE_ROW_GROUP:                return new CSSPrimitiveValueImpl("table-row-group", CSSPrimitiveValue::CSS_STRING);            case khtml::TABLE_HEADER_GROUP:                return new CSSPrimitiveValueImpl("table-header-group", CSSPrimitiveValue::CSS_STRING);            case khtml::TABLE_FOOTER_GROUP:                return new CSSPrimitiveValueImpl("table-footer-group", CSSPrimitiveValue::CSS_STRING);            case khtml::TABLE_ROW:                return new CSSPrimitiveValueImpl("table-row", CSSPrimitiveValue::CSS_STRING);            case khtml::TABLE_COLUMN_GROUP:                return new CSSPrimitiveValueImpl("table-column-group", CSSPrimitiveValue::CSS_STRING);            case khtml::TABLE_COLUMN:                return new CSSPrimitiveValueImpl("table-column", CSSPrimitiveValue::CSS_STRING);            case khtml::TABLE_CELL:                return new CSSPrimitiveValueImpl("table-cell", CSSPrimitiveValue::CSS_STRING);            case khtml::TABLE_CAPTION:                return new CSSPrimitiveValueImpl("table-caption", CSSPrimitiveValue::CSS_STRING);            case khtml::BOX:                return new CSSPrimitiveValueImpl("-khtml-box", CSSPrimitiveValue::CSS_STRING);            case khtml::INLINE_BOX:                return new CSSPrimitiveValueImpl("-khtml-inline-box", CSSPrimitiveValue::CSS_STRING);            case khtml::NONE:                return new CSSPrimitiveValueImpl("none", CSSPrimitiveValue::CSS_STRING);            default:                ASSERT_NOT_REACHED();        }    case CSS_PROP_EMPTY_CELLS:        // FIXME: unimplemented		break;    case CSS_PROP_FLOAT:    {        switch (m_renderer->style()->floating()) {            case khtml::FNONE:                return new CSSPrimitiveValueImpl("none", CSSPrimitiveValue::CSS_STRING);            case khtml::FLEFT:                return new CSSPrimitiveValueImpl("left", CSSPrimitiveValue::CSS_STRING);            case khtml::FRIGHT:                return new CSSPrimitiveValueImpl("right", CSSPrimitiveValue::CSS_STRING);        }    }    case CSS_PROP_FONT_FAMILY:    {        FontDef def = m_renderer->style()->htmlFont().getFontDef();        return new CSSPrimitiveValueImpl(DOMString(def.firstFamily().family()), CSSPrimitiveValue::CSS_STRING);    }    case CSS_PROP_FONT_SIZE:    {        FontDef def = m_renderer->style()->htmlFont().getFontDef();        return new CSSPrimitiveValueImpl(def.specifiedSize, CSSPrimitiveValue::CSS_PX);    }    case CSS_PROP_FONT_SIZE_ADJUST:        // FIXME: unimplemented		break;    case CSS_PROP_FONT_STRETCH:        // FIXME: unimplemented		break;    case CSS_PROP_FONT_STYLE:    {        // FIXME: handle oblique        FontDef def = m_renderer->style()->htmlFont().getFontDef();        if (def.italic)            return new CSSPrimitiveValueImpl("italic", CSSPrimitiveValue::CSS_STRING);        else            return new CSSPrimitiveValueImpl("normal", CSSPrimitiveValue::CSS_STRING);    }    case CSS_PROP_FONT_VARIANT:    {        FontDef def = m_renderer->style()->htmlFont().getFontDef();        if (def.smallCaps)            return new CSSPrimitiveValueImpl("small-caps", CSSPrimitiveValue::CSS_STRING);        else            return new CSSPrimitiveValueImpl("normal", CSSPrimitiveValue::CSS_STRING);    }    case CSS_PROP_FONT_WEIGHT:    {        // FIXME: this does not reflect the full range of weights        // that can be expressed with CSS

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -