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

📄 renderthememac.mm

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 MM
📖 第 1 页 / 共 5 页
字号:
}bool RenderThemeMac::paintTextArea(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r){    LocalCurrentGraphicsContext localContext(paintInfo.context);    wkDrawBezeledTextArea(r, isEnabled(o) && !isReadOnlyControl(o));    return false;}void RenderThemeMac::adjustTextAreaStyle(CSSStyleSelector*, RenderStyle*, Element*) const{}const int* RenderThemeMac::popupButtonMargins() const{    static const int margins[3][4] =    {        { 0, 3, 1, 3 },        { 0, 3, 2, 3 },        { 0, 1, 0, 1 }    };    return margins[[popupButton() controlSize]];}const IntSize* RenderThemeMac::popupButtonSizes() const{    static const IntSize sizes[3] = { IntSize(0, 21), IntSize(0, 18), IntSize(0, 15) };    return sizes;}const int* RenderThemeMac::popupButtonPadding(NSControlSize size) const{    static const int padding[3][4] =    {        { 2, 26, 3, 8 },        { 2, 23, 3, 8 },        { 2, 22, 3, 10 }    };    return padding[size];}bool RenderThemeMac::paintMenuList(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r){    setPopupButtonCellState(o, r);    NSPopUpButtonCell* popupButton = this->popupButton();    float zoomLevel = o->style()->effectiveZoom();    IntSize size = popupButtonSizes()[[popupButton controlSize]];    size.setHeight(size.height() * zoomLevel);    size.setWidth(r.width());    // Now inflate it to account for the shadow.    IntRect inflatedRect = r;    if (r.width() >= minimumMenuListSize(o->style()))        inflatedRect = inflateRect(inflatedRect, size, popupButtonMargins(), zoomLevel);    paintInfo.context->save();    #ifndef BUILDING_ON_TIGER    // On Leopard, the cell will draw outside of the given rect, so we have to clip to the rect    paintInfo.context->clip(inflatedRect);#endif    if (zoomLevel != 1.0f) {        inflatedRect.setWidth(inflatedRect.width() / zoomLevel);        inflatedRect.setHeight(inflatedRect.height() / zoomLevel);        paintInfo.context->translate(inflatedRect.x(), inflatedRect.y());        paintInfo.context->scale(FloatSize(zoomLevel, zoomLevel));        paintInfo.context->translate(-inflatedRect.x(), -inflatedRect.y());    }    [popupButton drawWithFrame:inflatedRect inView:o->view()->frameView()->documentView()];    [popupButton setControlView:nil];    paintInfo.context->restore();    return false;}const float baseFontSize = 11.0f;const float baseArrowHeight = 4.0f;const float baseArrowWidth = 5.0f;const float baseSpaceBetweenArrows = 2.0f;const int arrowPaddingLeft = 6;const int arrowPaddingRight = 6;const int paddingBeforeSeparator = 4;const int baseBorderRadius = 5;const int styledPopupPaddingLeft = 8;const int styledPopupPaddingTop = 1;const int styledPopupPaddingBottom = 2;static void TopGradientInterpolate(void*, const CGFloat* inData, CGFloat* outData){    static float dark[4] = { 1.0f, 1.0f, 1.0f, 0.4f };    static float light[4] = { 1.0f, 1.0f, 1.0f, 0.15f };    float a = inData[0];    int i = 0;    for (i = 0; i < 4; i++)        outData[i] = (1.0f - a) * dark[i] + a * light[i];}static void BottomGradientInterpolate(void*, const CGFloat* inData, CGFloat* outData){    static float dark[4] = { 1.0f, 1.0f, 1.0f, 0.0f };    static float light[4] = { 1.0f, 1.0f, 1.0f, 0.3f };    float a = inData[0];    int i = 0;    for (i = 0; i < 4; i++)        outData[i] = (1.0f - a) * dark[i] + a * light[i];}static void MainGradientInterpolate(void*, const CGFloat* inData, CGFloat* outData){    static float dark[4] = { 0.0f, 0.0f, 0.0f, 0.15f };    static float light[4] = { 0.0f, 0.0f, 0.0f, 0.0f };    float a = inData[0];    int i = 0;    for (i = 0; i < 4; i++)        outData[i] = (1.0f - a) * dark[i] + a * light[i];}static void TrackGradientInterpolate(void*, const CGFloat* inData, CGFloat* outData){    static float dark[4] = { 0.0f, 0.0f, 0.0f, 0.678f };    static float light[4] = { 0.0f, 0.0f, 0.0f, 0.13f };    float a = inData[0];    int i = 0;    for (i = 0; i < 4; i++)        outData[i] = (1.0f - a) * dark[i] + a * light[i];}void RenderThemeMac::paintMenuListButtonGradients(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r){    CGContextRef context = paintInfo.context->platformContext();    paintInfo.context->save();    int radius = o->style()->borderTopLeftRadius().width();    RetainPtr<CGColorSpaceRef> cspace(AdoptCF, CGColorSpaceCreateDeviceRGB());    FloatRect topGradient(r.x(), r.y(), r.width(), r.height() / 2.0f);    struct CGFunctionCallbacks topCallbacks = { 0, TopGradientInterpolate, NULL };    RetainPtr<CGFunctionRef> topFunction(AdoptCF, CGFunctionCreate(NULL, 1, NULL, 4, NULL, &topCallbacks));    RetainPtr<CGShadingRef> topShading(AdoptCF, CGShadingCreateAxial(cspace.get(), CGPointMake(topGradient.x(), topGradient.y()), CGPointMake(topGradient.x(), topGradient.bottom()), topFunction.get(), false, false));    FloatRect bottomGradient(r.x() + radius, r.y() + r.height() / 2.0f, r.width() - 2.0f * radius, r.height() / 2.0f);    struct CGFunctionCallbacks bottomCallbacks = { 0, BottomGradientInterpolate, NULL };    RetainPtr<CGFunctionRef> bottomFunction(AdoptCF, CGFunctionCreate(NULL, 1, NULL, 4, NULL, &bottomCallbacks));    RetainPtr<CGShadingRef> bottomShading(AdoptCF, CGShadingCreateAxial(cspace.get(), CGPointMake(bottomGradient.x(),  bottomGradient.y()), CGPointMake(bottomGradient.x(), bottomGradient.bottom()), bottomFunction.get(), false, false));    struct CGFunctionCallbacks mainCallbacks = { 0, MainGradientInterpolate, NULL };    RetainPtr<CGFunctionRef> mainFunction(AdoptCF, CGFunctionCreate(NULL, 1, NULL, 4, NULL, &mainCallbacks));    RetainPtr<CGShadingRef> mainShading(AdoptCF, CGShadingCreateAxial(cspace.get(), CGPointMake(r.x(),  r.y()), CGPointMake(r.x(), r.bottom()), mainFunction.get(), false, false));    RetainPtr<CGShadingRef> leftShading(AdoptCF, CGShadingCreateAxial(cspace.get(), CGPointMake(r.x(),  r.y()), CGPointMake(r.x() + radius, r.y()), mainFunction.get(), false, false));    RetainPtr<CGShadingRef> rightShading(AdoptCF, CGShadingCreateAxial(cspace.get(), CGPointMake(r.right(),  r.y()), CGPointMake(r.right() - radius, r.y()), mainFunction.get(), false, false));    paintInfo.context->save();    CGContextClipToRect(context, r);    paintInfo.context->addRoundedRectClip(r,        o->style()->borderTopLeftRadius(), o->style()->borderTopRightRadius(),        o->style()->borderBottomLeftRadius(), o->style()->borderBottomRightRadius());    CGContextDrawShading(context, mainShading.get());    paintInfo.context->restore();    paintInfo.context->save();    CGContextClipToRect(context, topGradient);    paintInfo.context->addRoundedRectClip(enclosingIntRect(topGradient),        o->style()->borderTopLeftRadius(), o->style()->borderTopRightRadius(),        IntSize(), IntSize());    CGContextDrawShading(context, topShading.get());    paintInfo.context->restore();    paintInfo.context->save();    CGContextClipToRect(context, bottomGradient);    paintInfo.context->addRoundedRectClip(enclosingIntRect(bottomGradient),        IntSize(), IntSize(),        o->style()->borderBottomLeftRadius(), o->style()->borderBottomRightRadius());    CGContextDrawShading(context, bottomShading.get());    paintInfo.context->restore();    paintInfo.context->save();    CGContextClipToRect(context, r);    paintInfo.context->addRoundedRectClip(r,        o->style()->borderTopLeftRadius(), o->style()->borderTopRightRadius(),        o->style()->borderBottomLeftRadius(), o->style()->borderBottomRightRadius());    CGContextDrawShading(context, leftShading.get());    CGContextDrawShading(context, rightShading.get());    paintInfo.context->restore();    paintInfo.context->restore();}bool RenderThemeMac::paintMenuListButton(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r){    paintInfo.context->save();    IntRect bounds = IntRect(r.x() + o->style()->borderLeftWidth(),                             r.y() + o->style()->borderTopWidth(),                             r.width() - o->style()->borderLeftWidth() - o->style()->borderRightWidth(),                             r.height() - o->style()->borderTopWidth() - o->style()->borderBottomWidth());    // Draw the gradients to give the styled popup menu a button appearance    paintMenuListButtonGradients(o, paintInfo, bounds);    // Since we actually know the size of the control here, we restrict the font scale to make sure the arrows will fit vertically in the bounds    float fontScale = min(o->style()->fontSize() / baseFontSize, bounds.height() / (baseArrowHeight * 2 + baseSpaceBetweenArrows));    float centerY = bounds.y() + bounds.height() / 2.0f;    float arrowHeight = baseArrowHeight * fontScale;    float arrowWidth = baseArrowWidth * fontScale;    float leftEdge = bounds.right() - arrowPaddingRight * o->style()->effectiveZoom() - arrowWidth;    float spaceBetweenArrows = baseSpaceBetweenArrows * fontScale;    if (bounds.width() < arrowWidth + arrowPaddingLeft * o->style()->effectiveZoom())        return false;        paintInfo.context->setFillColor(o->style()->color());    paintInfo.context->setStrokeStyle(NoStroke);    FloatPoint arrow1[3];    arrow1[0] = FloatPoint(leftEdge, centerY - spaceBetweenArrows / 2.0f);    arrow1[1] = FloatPoint(leftEdge + arrowWidth, centerY - spaceBetweenArrows / 2.0f);    arrow1[2] = FloatPoint(leftEdge + arrowWidth / 2.0f, centerY - spaceBetweenArrows / 2.0f - arrowHeight);    // Draw the top arrow    paintInfo.context->drawConvexPolygon(3, arrow1, true);    FloatPoint arrow2[3];    arrow2[0] = FloatPoint(leftEdge, centerY + spaceBetweenArrows / 2.0f);    arrow2[1] = FloatPoint(leftEdge + arrowWidth, centerY + spaceBetweenArrows / 2.0f);    arrow2[2] = FloatPoint(leftEdge + arrowWidth / 2.0f, centerY + spaceBetweenArrows / 2.0f + arrowHeight);    // Draw the bottom arrow    paintInfo.context->drawConvexPolygon(3, arrow2, true);    Color leftSeparatorColor(0, 0, 0, 40);    Color rightSeparatorColor(255, 255, 255, 40);    // FIXME: Should the separator thickness and space be scaled up by fontScale?    int separatorSpace = 2; // Deliberately ignores zoom since it looks nicer if it stays thin.    int leftEdgeOfSeparator = static_cast<int>(leftEdge - arrowPaddingLeft * o->style()->effectiveZoom()); // FIXME: Round?    // Draw the separator to the left of the arrows    paintInfo.context->setStrokeThickness(1.0f); // Deliberately ignores zoom since it looks nicer if it stays thin.    paintInfo.context->setStrokeStyle(SolidStroke);    paintInfo.context->setStrokeColor(leftSeparatorColor);    paintInfo.context->drawLine(IntPoint(leftEdgeOfSeparator, bounds.y()),                                IntPoint(leftEdgeOfSeparator, bounds.bottom()));    paintInfo.context->setStrokeColor(rightSeparatorColor);    paintInfo.context->drawLine(IntPoint(leftEdgeOfSeparator + separatorSpace, bounds.y()),                                IntPoint(leftEdgeOfSeparator + separatorSpace, bounds.bottom()));    paintInfo.context->restore();    return false;}static const IntSize* menuListButtonSizes(){    static const IntSize sizes[3] = { IntSize(0, 21), IntSize(0, 18), IntSize(0, 15) };    return sizes;}void RenderThemeMac::adjustMenuListStyle(CSSStyleSelector* selector, RenderStyle* style, Element* e) const{    NSControlSize controlSize = controlSizeForFont(style);    style->resetBorder();    style->resetPadding();        // Height is locked to auto.    style->setHeight(Length(Auto));    // White-space is locked to pre    style->setWhiteSpace(PRE);    // Set the foreground color to black or gray when we have the aqua look.    // Cast to RGB32 is to work around a compiler bug.    bool isEnabled = true;    if (FormControlElement* formControlElement = toFormControlElement(e))        isEnabled = formControlElement->isEnabled();    style->setColor(isEnabled ? static_cast<RGBA32>(Color::black) : Color::darkGray);    // Set the button's vertical size.    setSizeFromFont(style, menuListButtonSizes());    // Our font is locked to the appropriate system font size for the control.  To clarify, we first use the CSS-specified font to figure out    // a reasonable control size, but once that control size is determined, we throw that font away and use the appropriate    // system font for the control size instead.    setFontFromControlSize(selector, style, controlSize);    style->setBoxShadow(0);}int RenderThemeMac::popupInternalPaddingLeft(RenderStyle* style) const{    if (style->appearance() == MenulistPart)        return popupButtonPadding(controlSizeForFont(style))[leftPadding] * style->effectiveZoom();    if (style->appearance() == MenulistButtonPart)        return styledPopupPaddingLeft * style->effectiveZoom();    return 0;}int RenderThemeMac::popupInternalPaddingRight(RenderStyle* style) const{    if (style->appearance() == MenulistPart)        return popupButtonPadding(controlSizeForFont(style))[rightPadding] * style->effectiveZoom();    if (style->appearance() == MenulistButtonPart) {        float fontScale = style->fontSize() / baseFontSize;        float arrowWidth = baseArrowWidth * fontScale;        return static_cast<int>(ceilf(arrowWidth + (arrowPaddingLeft + arrowPaddingRight + paddingBeforeSeparator) * style->effectiveZoom()));    }    return 0;}int RenderThemeMac::popupInternalPaddingTop(RenderStyle* style) const{    if (style->appearance() == MenulistPart)        return popupButtonPadding(controlSizeForFont(style))[topPadding] * style->effectiveZoom();    if (style->appearance() == MenulistButtonPart)        return styledPopupPaddingTop * style->effectiveZoom();    return 0;}int RenderThemeMac::popupInternalPaddingBottom(RenderStyle* style) const{    if (style->appearance() == MenulistPart)        return popupButtonPadding(controlSizeForFont(style))[bottomPadding] * style->effectiveZoom();    if (style->appearance() == MenulistButtonPart)        return styledPopupPaddingBottom * style->effectiveZoom();    return 0;}void RenderThemeMac::adjustMenuListButtonStyle(CSSStyleSelector*, RenderStyle* style, Element*) const{

⌨️ 快捷键说明

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