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

📄 renderthememac.mm

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 MM
📖 第 1 页 / 共 5 页
字号:
    float fontScale = style->fontSize() / baseFontSize;    style->resetPadding();    style->setBorderRadius(IntSize(int(baseBorderRadius + fontScale - 1), int(baseBorderRadius + fontScale - 1))); // FIXME: Round up?    const int minHeight = 15;    style->setMinHeight(Length(minHeight, Fixed));        style->setLineHeight(RenderStyle::initialLineHeight());}void RenderThemeMac::setPopupButtonCellState(const RenderObject* o, const IntRect& r){    NSPopUpButtonCell* popupButton = this->popupButton();    // Set the control size based off the rectangle we're painting into.    setControlSize(popupButton, popupButtonSizes(), r.size(), o->style()->effectiveZoom());    // Update the various states we respond to.    updateCheckedState(popupButton, o);    updateEnabledState(popupButton, o);    updatePressedState(popupButton, o);    updateFocusedState(popupButton, o);}const IntSize* RenderThemeMac::menuListSizes() const{    static const IntSize sizes[3] = { IntSize(9, 0), IntSize(5, 0), IntSize(0, 0) };    return sizes;}int RenderThemeMac::minimumMenuListSize(RenderStyle* style) const{    return sizeForSystemFont(style, menuListSizes()).width();}const int trackWidth = 5;const int trackRadius = 2;void RenderThemeMac::adjustSliderTrackStyle(CSSStyleSelector*, RenderStyle* style, Element*) const{    style->setBoxShadow(0);}bool RenderThemeMac::paintSliderTrack(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r){    IntRect bounds = r;    float zoomLevel = o->style()->effectiveZoom();    float zoomedTrackWidth = trackWidth * zoomLevel;    if (o->style()->appearance() ==  SliderHorizontalPart || o->style()->appearance() ==  MediaSliderPart) {        bounds.setHeight(zoomedTrackWidth);        bounds.setY(r.y() + r.height() / 2 - zoomedTrackWidth / 2);    } else if (o->style()->appearance() == SliderVerticalPart) {        bounds.setWidth(zoomedTrackWidth);        bounds.setX(r.x() + r.width() / 2 - zoomedTrackWidth / 2);    }    LocalCurrentGraphicsContext localContext(paintInfo.context);    CGContextRef context = paintInfo.context->platformContext();    RetainPtr<CGColorSpaceRef> cspace(AdoptCF, CGColorSpaceCreateDeviceRGB());    paintInfo.context->save();    CGContextClipToRect(context, bounds);    struct CGFunctionCallbacks mainCallbacks = { 0, TrackGradientInterpolate, NULL };    RetainPtr<CGFunctionRef> mainFunction(AdoptCF, CGFunctionCreate(NULL, 1, NULL, 4, NULL, &mainCallbacks));    RetainPtr<CGShadingRef> mainShading;    if (o->style()->appearance() == SliderVerticalPart)        mainShading.adoptCF(CGShadingCreateAxial(cspace.get(), CGPointMake(bounds.x(),  bounds.bottom()), CGPointMake(bounds.right(), bounds.bottom()), mainFunction.get(), false, false));    else        mainShading.adoptCF(CGShadingCreateAxial(cspace.get(), CGPointMake(bounds.x(),  bounds.y()), CGPointMake(bounds.x(), bounds.bottom()), mainFunction.get(), false, false));    IntSize radius(trackRadius, trackRadius);    paintInfo.context->addRoundedRectClip(bounds,        radius, radius,        radius, radius);    CGContextDrawShading(context, mainShading.get());    paintInfo.context->restore();        return false;}void RenderThemeMac::adjustSliderThumbStyle(CSSStyleSelector*, RenderStyle* style, Element*) const{    style->setBoxShadow(0);}const float verticalSliderHeightPadding = 0.1f;bool RenderThemeMac::paintSliderThumb(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r){    ASSERT(o->parent()->isSlider());    NSSliderCell* sliderThumbCell = o->style()->appearance() == SliderThumbVerticalPart        ? sliderThumbVertical()        : sliderThumbHorizontal();    LocalCurrentGraphicsContext localContext(paintInfo.context);    // Update the various states we respond to.    updateEnabledState(sliderThumbCell, o->parent());    updateFocusedState(sliderThumbCell, o->parent());    // Update the pressed state using the NSCell tracking methods, since that's how NSSliderCell keeps track of it.    bool oldPressed;    if (o->style()->appearance() == SliderThumbVerticalPart)        oldPressed = m_isSliderThumbVerticalPressed;    else        oldPressed = m_isSliderThumbHorizontalPressed;    bool pressed = static_cast<RenderSlider*>(o->parent())->inDragMode();    if (o->style()->appearance() == SliderThumbVerticalPart)        m_isSliderThumbVerticalPressed = pressed;    else        m_isSliderThumbHorizontalPressed = pressed;    if (pressed != oldPressed) {        if (pressed)            [sliderThumbCell startTrackingAt:NSPoint() inView:nil];        else            [sliderThumbCell stopTracking:NSPoint() at:NSPoint() inView:nil mouseIsUp:YES];    }    FloatRect bounds = r;    // Make the height of the vertical slider slightly larger so NSSliderCell will draw a vertical slider.    if (o->style()->appearance() == SliderThumbVerticalPart)        bounds.setHeight(bounds.height() + verticalSliderHeightPadding * o->style()->effectiveZoom());    paintInfo.context->save();    float zoomLevel = o->style()->effectiveZoom();        FloatRect unzoomedRect = bounds;    if (zoomLevel != 1.0f) {        unzoomedRect.setWidth(unzoomedRect.width() / zoomLevel);        unzoomedRect.setHeight(unzoomedRect.height() / zoomLevel);        paintInfo.context->translate(unzoomedRect.x(), unzoomedRect.y());        paintInfo.context->scale(FloatSize(zoomLevel, zoomLevel));        paintInfo.context->translate(-unzoomedRect.x(), -unzoomedRect.y());    }    [sliderThumbCell drawWithFrame:unzoomedRect inView:o->view()->frameView()->documentView()];    [sliderThumbCell setControlView:nil];    paintInfo.context->restore();    return false;}bool RenderThemeMac::paintSearchField(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r){    NSSearchFieldCell* search = this->search();    LocalCurrentGraphicsContext localContext(paintInfo.context);    setSearchCellState(o, r);    paintInfo.context->save();    float zoomLevel = o->style()->effectiveZoom();    IntRect unzoomedRect = r;        if (zoomLevel != 1.0f) {        unzoomedRect.setWidth(unzoomedRect.width() / zoomLevel);        unzoomedRect.setHeight(unzoomedRect.height() / zoomLevel);        paintInfo.context->translate(unzoomedRect.x(), unzoomedRect.y());        paintInfo.context->scale(FloatSize(zoomLevel, zoomLevel));        paintInfo.context->translate(-unzoomedRect.x(), -unzoomedRect.y());    }    // Set the search button to nil before drawing.  Then reset it so we can draw it later.    [search setSearchButtonCell:nil];    [search drawWithFrame:NSRect(unzoomedRect) inView:o->view()->frameView()->documentView()];#ifdef BUILDING_ON_TIGER    if ([search showsFirstResponder])        wkDrawTextFieldCellFocusRing(search, NSRect(unzoomedRect));#endif    [search setControlView:nil];    [search resetSearchButtonCell];    paintInfo.context->restore();    return false;}void RenderThemeMac::setSearchCellState(RenderObject* o, const IntRect&){    NSSearchFieldCell* search = this->search();    [search setControlSize:controlSizeForFont(o->style())];    // Update the various states we respond to.    updateEnabledState(search, o);    updateFocusedState(search, o);}const IntSize* RenderThemeMac::searchFieldSizes() const{    static const IntSize sizes[3] = { IntSize(0, 22), IntSize(0, 19), IntSize(0, 17) };    return sizes;}void RenderThemeMac::setSearchFieldSize(RenderStyle* style) const{    // If the width and height are both specified, then we have nothing to do.    if (!style->width().isIntrinsicOrAuto() && !style->height().isAuto())        return;        // Use the font size to determine the intrinsic width of the control.    setSizeFromFont(style, searchFieldSizes());}void RenderThemeMac::adjustSearchFieldStyle(CSSStyleSelector* selector, RenderStyle* style, Element*) const{    // Override border.    style->resetBorder();    const short borderWidth = 2 * style->effectiveZoom();    style->setBorderLeftWidth(borderWidth);    style->setBorderLeftStyle(INSET);    style->setBorderRightWidth(borderWidth);    style->setBorderRightStyle(INSET);    style->setBorderBottomWidth(borderWidth);    style->setBorderBottomStyle(INSET);    style->setBorderTopWidth(borderWidth);    style->setBorderTopStyle(INSET);            // Override height.    style->setHeight(Length(Auto));    setSearchFieldSize(style);        // Override padding size to match AppKit text positioning.    const int padding = 1 * style->effectiveZoom();    style->setPaddingLeft(Length(padding, Fixed));    style->setPaddingRight(Length(padding, Fixed));    style->setPaddingTop(Length(padding, Fixed));    style->setPaddingBottom(Length(padding, Fixed));        NSControlSize controlSize = controlSizeForFont(style);    setFontFromControlSize(selector, style, controlSize);    style->setBoxShadow(0);}bool RenderThemeMac::paintSearchFieldCancelButton(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r){    Node* input = o->node()->shadowAncestorNode();    if (!input->renderer()->isBox())        return false;    setSearchCellState(input->renderer(), r);    NSSearchFieldCell* search = this->search();    updatePressedState([search cancelButtonCell], o);    paintInfo.context->save();    float zoomLevel = o->style()->effectiveZoom();    FloatRect localBounds = [search cancelButtonRectForBounds:NSRect(input->renderBox()->borderBoxRect())];    localBounds = convertToPaintingRect(input->renderer(), o, localBounds, r);    FloatRect unzoomedRect(localBounds);    if (zoomLevel != 1.0f) {        unzoomedRect.setWidth(unzoomedRect.width() / zoomLevel);        unzoomedRect.setHeight(unzoomedRect.height() / zoomLevel);        paintInfo.context->translate(unzoomedRect.x(), unzoomedRect.y());        paintInfo.context->scale(FloatSize(zoomLevel, zoomLevel));        paintInfo.context->translate(-unzoomedRect.x(), -unzoomedRect.y());    }    [[search cancelButtonCell] drawWithFrame:unzoomedRect inView:o->view()->frameView()->documentView()];    [[search cancelButtonCell] setControlView:nil];    paintInfo.context->restore();    return false;}const IntSize* RenderThemeMac::cancelButtonSizes() const{    static const IntSize sizes[3] = { IntSize(16, 13), IntSize(13, 11), IntSize(13, 9) };    return sizes;}void RenderThemeMac::adjustSearchFieldCancelButtonStyle(CSSStyleSelector*, RenderStyle* style, Element*) const{    IntSize size = sizeForSystemFont(style, cancelButtonSizes());    style->setWidth(Length(size.width(), Fixed));    style->setHeight(Length(size.height(), Fixed));    style->setBoxShadow(0);}const IntSize* RenderThemeMac::resultsButtonSizes() const{    static const IntSize sizes[3] = { IntSize(19, 13), IntSize(17, 11), IntSize(17, 9) };    return sizes;}const int emptyResultsOffset = 9;void RenderThemeMac::adjustSearchFieldDecorationStyle(CSSStyleSelector*, RenderStyle* style, Element*) const{    IntSize size = sizeForSystemFont(style, resultsButtonSizes());    style->setWidth(Length(size.width() - emptyResultsOffset, Fixed));    style->setHeight(Length(size.height(), Fixed));    style->setBoxShadow(0);}bool RenderThemeMac::paintSearchFieldDecoration(RenderObject*, const RenderObject::PaintInfo&, const IntRect&){    return false;}void RenderThemeMac::adjustSearchFieldResultsDecorationStyle(CSSStyleSelector*, RenderStyle* style, Element*) const{    IntSize size = sizeForSystemFont(style, resultsButtonSizes());    style->setWidth(Length(size.width(), Fixed));    style->setHeight(Length(size.height(), Fixed));    style->setBoxShadow(0);}bool RenderThemeMac::paintSearchFieldResultsDecoration(RenderObject* o, const RenderObject::PaintInfo&, const IntRect& r){    Node* input = o->node()->shadowAncestorNode();    if (!input->renderer()->isBox())        return false;    setSearchCellState(input->renderer(), r);    NSSearchFieldCell* search = this->search();    if ([search searchMenuTemplate] != nil)        [search setSearchMenuTemplate:nil];    FloatRect localBounds = [search searchButtonRectForBounds:NSRect(input->renderBox()->borderBoxRect())];

⌨️ 快捷键说明

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