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

📄 renderthemewin.cpp

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 CPP
📖 第 1 页 / 共 3 页
字号:
        style->setHeight(Length(13, Fixed));}bool RenderThemeWin::paintTextField(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r){    drawControl(i.context,  o, textFieldTheme(), getThemeData(o), r);    return false;}bool RenderThemeWin::paintMenuList(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r){    // The outer box of a menu list is just a text field.  Paint it first.    drawControl(i.context,  o, textFieldTheme(), ThemeData(TFP_TEXTFIELD, determineState(o)), r);        return paintMenuListButton(o, i, r);}void RenderThemeWin::adjustMenuListStyle(CSSStyleSelector* selector, RenderStyle* style, Element* e) const{    style->resetBorder();    adjustMenuListButtonStyle(selector, style, e);}void RenderThemeWin::adjustMenuListButtonStyle(CSSStyleSelector* selector, RenderStyle* style, Element* e) const{    // These are the paddings needed to place the text correctly in the <select> box    const int dropDownBoxPaddingTop    = 2;    const int dropDownBoxPaddingRight  = style->direction() == LTR ? 4 + dropDownButtonWidth : 4;    const int dropDownBoxPaddingBottom = 2;    const int dropDownBoxPaddingLeft   = style->direction() == LTR ? 4 : 4 + dropDownButtonWidth;    // The <select> box must be at least 12px high for the button to render nicely on Windows    const int dropDownBoxMinHeight = 12;        // Position the text correctly within the select box and make the box wide enough to fit the dropdown button    style->setPaddingTop(Length(dropDownBoxPaddingTop, Fixed));    style->setPaddingRight(Length(dropDownBoxPaddingRight, Fixed));    style->setPaddingBottom(Length(dropDownBoxPaddingBottom, Fixed));    style->setPaddingLeft(Length(dropDownBoxPaddingLeft, Fixed));    // Height is locked to auto    style->setHeight(Length(Auto));    // Calculate our min-height    int minHeight = style->font().height();    minHeight = max(minHeight, dropDownBoxMinHeight);    style->setMinHeight(Length(minHeight, Fixed));        // White-space is locked to pre    style->setWhiteSpace(PRE);}bool RenderThemeWin::paintMenuListButton(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r){    // FIXME: Don't make hardcoded assumptions about the thickness of the textfield border.    int borderThickness = haveTheme ? 1 : 2;    // Paint the dropdown button on the inner edge of the text field,    // leaving space for the text field's 1px border    IntRect buttonRect(r);    buttonRect.inflate(-borderThickness);    if (o->style()->direction() == LTR)        buttonRect.setX(buttonRect.right() - dropDownButtonWidth);    buttonRect.setWidth(dropDownButtonWidth);    drawControl(i.context, o, menuListTheme(), getThemeData(o), buttonRect);    return false;}const int trackWidth = 4;bool RenderThemeWin::paintSliderTrack(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r){    IntRect bounds = r;        if (o->style()->appearance() ==  SliderHorizontalPart) {        bounds.setHeight(trackWidth);        bounds.setY(r.y() + r.height() / 2 - trackWidth / 2);    } else if (o->style()->appearance() == SliderVerticalPart) {        bounds.setWidth(trackWidth);        bounds.setX(r.x() + r.width() / 2 - trackWidth / 2);    }        drawControl(i.context,  o, sliderTheme(), getThemeData(o), bounds);    return false;}bool RenderThemeWin::paintSliderThumb(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r){       drawControl(i.context,  o, sliderTheme(), getThemeData(o), r);    return false;}const int sliderThumbWidth = 7;const int sliderThumbHeight = 15;void RenderThemeWin::adjustSliderThumbSize(RenderObject* o) const{    if (o->style()->appearance() == SliderThumbVerticalPart) {        o->style()->setWidth(Length(sliderThumbHeight, Fixed));        o->style()->setHeight(Length(sliderThumbWidth, Fixed));    } else if (o->style()->appearance() == SliderThumbHorizontalPart) {        o->style()->setWidth(Length(sliderThumbWidth, Fixed));        o->style()->setHeight(Length(sliderThumbHeight, Fixed));    }}int RenderThemeWin::buttonInternalPaddingLeft() const{    return 3;}int RenderThemeWin::buttonInternalPaddingRight() const{    return 3;}int RenderThemeWin::buttonInternalPaddingTop() const{    return 1;}int RenderThemeWin::buttonInternalPaddingBottom() const{    return 1;}bool RenderThemeWin::paintSearchField(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r){    return paintTextField(o, i, r);}void RenderThemeWin::adjustSearchFieldStyle(CSSStyleSelector* selector, RenderStyle* style, Element* e) const{       // Override padding size to match AppKit text positioning.    const int padding = 1;    style->setPaddingLeft(Length(padding, Fixed));    style->setPaddingRight(Length(padding, Fixed));    style->setPaddingTop(Length(padding, Fixed));    style->setPaddingBottom(Length(padding, Fixed));}bool RenderThemeWin::paintSearchFieldCancelButton(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r){    IntRect bounds = r;    ASSERT(o->parent());    if (!o->parent() || !o->parent()->isBox())        return false;        RenderBox* parentRenderBox = toRenderBox(o->parent());    IntRect parentBox = parentRenderBox->absoluteContentBox();        // Make sure the scaled button stays square and will fit in its parent's box    bounds.setHeight(min(parentBox.width(), min(parentBox.height(), bounds.height())));    bounds.setWidth(bounds.height());    // Center the button vertically.  Round up though, so if it has to be one pixel off-center, it will    // be one pixel closer to the bottom of the field.  This tends to look better with the text.    bounds.setY(parentBox.y() + (parentBox.height() - bounds.height() + 1) / 2);    static Image* cancelImage = Image::loadPlatformResource("searchCancel").releaseRef();    static Image* cancelPressedImage = Image::loadPlatformResource("searchCancelPressed").releaseRef();    paintInfo.context->drawImage(isPressed(o) ? cancelPressedImage : cancelImage, bounds);    return false;}void RenderThemeWin::adjustSearchFieldCancelButtonStyle(CSSStyleSelector* selector, RenderStyle* style, Element* e) const{    // Scale the button size based on the font size    float fontScale = style->fontSize() / defaultControlFontPixelSize;    int cancelButtonSize = lroundf(min(max(minCancelButtonSize, defaultCancelButtonSize * fontScale), maxCancelButtonSize));    style->setWidth(Length(cancelButtonSize, Fixed));    style->setHeight(Length(cancelButtonSize, Fixed));}void RenderThemeWin::adjustSearchFieldDecorationStyle(CSSStyleSelector* selector, RenderStyle* style, Element* e) const{    IntSize emptySize(1, 11);    style->setWidth(Length(emptySize.width(), Fixed));    style->setHeight(Length(emptySize.height(), Fixed));}void RenderThemeWin::adjustSearchFieldResultsDecorationStyle(CSSStyleSelector* selector, RenderStyle* style, Element* e) const{    // Scale the decoration size based on the font size    float fontScale = style->fontSize() / defaultControlFontPixelSize;    int magnifierSize = lroundf(min(max(minSearchFieldResultsDecorationSize, defaultSearchFieldResultsDecorationSize * fontScale),                                      maxSearchFieldResultsDecorationSize));    style->setWidth(Length(magnifierSize, Fixed));    style->setHeight(Length(magnifierSize, Fixed));}bool RenderThemeWin::paintSearchFieldResultsDecoration(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r){    IntRect bounds = r;    ASSERT(o->parent());    if (!o->parent() || !o->parent()->isBox())        return false;        RenderBox* parentRenderBox = toRenderBox(o->parent());    IntRect parentBox = parentRenderBox->absoluteContentBox();        // Make sure the scaled decoration stays square and will fit in its parent's box    bounds.setHeight(min(parentBox.width(), min(parentBox.height(), bounds.height())));    bounds.setWidth(bounds.height());    // Center the decoration vertically.  Round up though, so if it has to be one pixel off-center, it will    // be one pixel closer to the bottom of the field.  This tends to look better with the text.    bounds.setY(parentBox.y() + (parentBox.height() - bounds.height() + 1) / 2);        static Image* magnifierImage = Image::loadPlatformResource("searchMagnifier").releaseRef();    paintInfo.context->drawImage(magnifierImage, bounds);    return false;}void RenderThemeWin::adjustSearchFieldResultsButtonStyle(CSSStyleSelector* selector, RenderStyle* style, Element* e) const{    // Scale the button size based on the font size    float fontScale = style->fontSize() / defaultControlFontPixelSize;    int magnifierHeight = lroundf(min(max(minSearchFieldResultsDecorationSize, defaultSearchFieldResultsDecorationSize * fontScale),                                    maxSearchFieldResultsDecorationSize));    int magnifierWidth = lroundf(magnifierHeight * defaultSearchFieldResultsButtonWidth / defaultSearchFieldResultsDecorationSize);    style->setWidth(Length(magnifierWidth, Fixed));    style->setHeight(Length(magnifierHeight, Fixed));}bool RenderThemeWin::paintSearchFieldResultsButton(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r){    IntRect bounds = r;    ASSERT(o->parent());    if (!o->parent())        return false;    if (!o->parent() || !o->parent()->isBox())        return false;        RenderBox* parentRenderBox = toRenderBox(o->parent());    IntRect parentBox = parentRenderBox->absoluteContentBox();        // Make sure the scaled decoration will fit in its parent's box    bounds.setHeight(min(parentBox.height(), bounds.height()));    bounds.setWidth(min(parentBox.width(), static_cast<int>(bounds.height() * defaultSearchFieldResultsButtonWidth / defaultSearchFieldResultsDecorationSize)));    // Center the button vertically.  Round up though, so if it has to be one pixel off-center, it will    // be one pixel closer to the bottom of the field.  This tends to look better with the text.    bounds.setY(parentBox.y() + (parentBox.height() - bounds.height() + 1) / 2);    static Image* magnifierImage = Image::loadPlatformResource("searchMagnifierResults").releaseRef();    paintInfo.context->drawImage(magnifierImage, bounds);    return false;}// Map a CSSValue* system color to an index understood by GetSysColorstatic int cssValueIdToSysColorIndex(int cssValueId){    switch (cssValueId) {        case CSSValueActiveborder: return COLOR_ACTIVEBORDER;        case CSSValueActivecaption: return COLOR_ACTIVECAPTION;        case CSSValueAppworkspace: return COLOR_APPWORKSPACE;        case CSSValueBackground: return COLOR_BACKGROUND;        case CSSValueButtonface: return COLOR_BTNFACE;        case CSSValueButtonhighlight: return COLOR_BTNHIGHLIGHT;        case CSSValueButtonshadow: return COLOR_BTNSHADOW;        case CSSValueButtontext: return COLOR_BTNTEXT;        case CSSValueCaptiontext: return COLOR_CAPTIONTEXT;        case CSSValueGraytext: return COLOR_GRAYTEXT;        case CSSValueHighlight: return COLOR_HIGHLIGHT;        case CSSValueHighlighttext: return COLOR_HIGHLIGHTTEXT;        case CSSValueInactiveborder: return COLOR_INACTIVEBORDER;        case CSSValueInactivecaption: return COLOR_INACTIVECAPTION;        case CSSValueInactivecaptiontext: return COLOR_INACTIVECAPTIONTEXT;        case CSSValueInfobackground: return COLOR_INFOBK;        case CSSValueInfotext: return COLOR_INFOTEXT;        case CSSValueMenu: return COLOR_MENU;        case CSSValueMenutext: return COLOR_MENUTEXT;        case CSSValueScrollbar: return COLOR_SCROLLBAR;        case CSSValueThreeddarkshadow: return COLOR_3DDKSHADOW;        case CSSValueThreedface: return COLOR_3DFACE;        case CSSValueThreedhighlight: return COLOR_3DHIGHLIGHT;        case CSSValueThreedlightshadow: return COLOR_3DLIGHT;        case CSSValueThreedshadow: return COLOR_3DSHADOW;        case CSSValueWindow: return COLOR_WINDOW;        case CSSValueWindowframe: return COLOR_WINDOWFRAME;        case CSSValueWindowtext: return COLOR_WINDOWTEXT;        default: return -1; // Unsupported CSSValue    }}Color RenderThemeWin::systemColor(int cssValueId) const{    int sysColorIndex = cssValueIdToSysColorIndex(cssValueId);    if (sysColorIndex == -1)        return RenderTheme::systemColor(cssValueId);    COLORREF color = GetSysColor(sysColorIndex);    return Color(GetRValue(color), GetGValue(color), GetBValue(color));}}

⌨️ 快捷键说明

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