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

📄 renderthemechromiummac.mm

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 MM
📖 第 1 页 / 共 5 页
字号:
    if (style->width().isIntrinsicOrAuto() && size.width() > 0)        style->setWidth(Length(size.width(), Fixed));    if (style->height().isAuto() && size.height() > 0)        style->setHeight(Length(size.height(), Fixed));}void RenderThemeChromiumMac::setFontFromControlSize(CSSStyleSelector* selector, RenderStyle* style, NSControlSize controlSize) const{    FontDescription fontDescription;    fontDescription.setIsAbsoluteSize(true);    fontDescription.setGenericFamily(FontDescription::SerifFamily);    NSFont* font = [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:controlSize]];    fontDescription.firstFamily().setFamily([font familyName]);    fontDescription.setComputedSize([font pointSize] * style->effectiveZoom());    fontDescription.setSpecifiedSize([font pointSize] * style->effectiveZoom());    // Reset line height    style->setLineHeight(RenderStyle::initialLineHeight());    if (style->setFontDescription(fontDescription))        style->font().update(0);}NSControlSize RenderThemeChromiumMac::controlSizeForSystemFont(RenderStyle* style) const{    int fontSize = style->fontSize();    if (fontSize >= [NSFont systemFontSizeForControlSize:NSRegularControlSize])        return NSRegularControlSize;    if (fontSize >= [NSFont systemFontSizeForControlSize:NSSmallControlSize])        return NSSmallControlSize;    return NSMiniControlSize;}// FIXME: This used to be in the upstream version until it was converted to the new theme API in r37731.bool RenderThemeChromiumMac::paintCheckbox(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r){    // Determine the width and height needed for the control and prepare the cell for painting.    setCheckboxCellState(o, r);    paintInfo.context->save();    float zoomLevel = o->style()->effectiveZoom();    // We inflate the rect as needed to account for padding included in the cell to accommodate the checkbox    // shadow" and the check.  We don't consider this part of the bounds of the control in WebKit.    NSButtonCell* checkbox = this->checkbox();    IntSize size = checkboxSizes()[[checkbox controlSize]];    size.setWidth(size.width() * zoomLevel);    size.setHeight(size.height() * zoomLevel);    IntRect inflatedRect = inflateRect(r, size, checkboxMargins(), zoomLevel);        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());    }        [checkbox drawWithFrame:NSRect(IntRectToNSRect(inflatedRect)) inView:nil];    [checkbox setControlView:nil];    paintInfo.context->restore();    return false;}// FIXME: This used to be in the upstream version until it was converted to the new theme API in r37731.const IntSize* RenderThemeChromiumMac::checkboxSizes() const{    static const IntSize sizes[3] = { IntSize(14, 14), IntSize(12, 12), IntSize(10, 10) };    return sizes;}// FIXME: This used to be in the upstream version until it was converted to the new theme API in r37731.const int* RenderThemeChromiumMac::checkboxMargins() const{    static const int margins[3][4] =    {        { 3, 4, 4, 2 },        { 4, 3, 3, 3 },        { 4, 3, 3, 3 },    };    return margins[[checkbox() controlSize]];}// FIXME: This used to be in the upstream version until it was converted to the new theme API in r37731.void RenderThemeChromiumMac::setCheckboxCellState(const RenderObject* o, const IntRect& r){    NSButtonCell* checkbox = this->checkbox();    // Set the control size based off the rectangle we're painting into.    setControlSize(checkbox, checkboxSizes(), r.size(), o->style()->effectiveZoom());    // Update the various states we respond to.    updateCheckedState(checkbox, o);    updateEnabledState(checkbox, o);    updatePressedState(checkbox, o);    updateFocusedState(checkbox, o);}// FIXME: This used to be in the upstream version until it was converted to the new theme API in r37731.void RenderThemeChromiumMac::setCheckboxSize(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, checkboxSizes());}// FIXME: This used to be in the upstream version until it was converted to the new theme API in r37731.bool RenderThemeChromiumMac::paintRadio(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r){    // Determine the width and height needed for the control and prepare the cell for painting.    setRadioCellState(o, r);    paintInfo.context->save();    float zoomLevel = o->style()->effectiveZoom();    // We inflate the rect as needed to account for padding included in the cell to accommodate the checkbox    // shadow" and the check.  We don't consider this part of the bounds of the control in WebKit.    NSButtonCell* radio = this->radio();    IntSize size = radioSizes()[[radio controlSize]];    size.setWidth(size.width() * zoomLevel);    size.setHeight(size.height() * zoomLevel);    IntRect inflatedRect = inflateRect(r, size, radioMargins(), zoomLevel);        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());    }    [radio drawWithFrame:NSRect(IntRectToNSRect(inflatedRect)) inView:nil];    [radio setControlView:nil];    paintInfo.context->restore();    return false;}// FIXME: This used to be in the upstream version until it was converted to the new theme API in r37731.const IntSize* RenderThemeChromiumMac::radioSizes() const{    static const IntSize sizes[3] = { IntSize(14, 15), IntSize(12, 13), IntSize(10, 10) };    return sizes;}// FIXME: This used to be in the upstream version until it was converted to the new theme API in r37731.const int* RenderThemeChromiumMac::radioMargins() const{    static const int margins[3][4] =    {        { 2, 2, 4, 2 },        { 3, 2, 3, 2 },        { 1, 0, 2, 0 },    };    return margins[[radio() controlSize]];}// FIXME: This used to be in the upstream version until it was converted to the new theme API in r37731.void RenderThemeChromiumMac::setRadioCellState(const RenderObject* o, const IntRect& r){    NSButtonCell* radio = this->radio();    // Set the control size based off the rectangle we're painting into.    setControlSize(radio, radioSizes(), r.size(), o->style()->effectiveZoom());    // Update the various states we respond to.    updateCheckedState(radio, o);    updateEnabledState(radio, o);    updatePressedState(radio, o);    updateFocusedState(radio, o);}// FIXME: This used to be in the upstream version until it was converted to the new theme API in r37731.void RenderThemeChromiumMac::setRadioSize(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, radioSizes());}// FIXME: This used to be in the upstream version until it was converted to the new theme API in r37731.void RenderThemeChromiumMac::setButtonPaddingFromControlSize(RenderStyle* style, NSControlSize size) const{    // Just use 8px.  AppKit wants to use 11px for mini buttons, but that padding is just too large    // for real-world Web sites (creating a huge necessary minimum width for buttons whose space is    // by definition constrained, since we select mini only for small cramped environments.    // This also guarantees the HTML4 <button> will match our rendering by default, since we're using a consistent    // padding.    const int padding = 8 * style->effectiveZoom();    style->setPaddingLeft(Length(padding, Fixed));    style->setPaddingRight(Length(padding, Fixed));    style->setPaddingTop(Length(0, Fixed));    style->setPaddingBottom(Length(0, Fixed));}// FIXME: This used to be in the upstream version until it was converted to the new theme API in r37731.void RenderThemeChromiumMac::adjustButtonStyle(CSSStyleSelector* selector, RenderStyle* style, Element* e) const{    // There are three appearance constants for buttons.    // (1) Push-button is the constant for the default Aqua system button.  Push buttons will not scale vertically and will not allow    // custom fonts or colors.  <input>s use this constant.  This button will allow custom colors and font weights/variants but won't    // scale vertically.    // (2) square-button is the constant for the square button.  This button will allow custom fonts and colors and will scale vertically.    // (3) Button is the constant that means "pick the best button as appropriate."  <button>s use this constant.  This button will    // also scale vertically and allow custom fonts and colors.  It will attempt to use Aqua if possible and will make this determination    // solely on the rectangle of the control.    // Determine our control size based off our font.    NSControlSize controlSize = controlSizeForFont(style);    if (style->appearance() == PushButtonPart) {        // Ditch the border.        style->resetBorder();        // Height is locked to auto.        style->setHeight(Length(Auto));        // White-space is locked to pre        style->setWhiteSpace(PRE);        // Set the button's vertical size.        setButtonSize(style);        // Add in the padding that we'd like to use.        setButtonPaddingFromControlSize(style, controlSize);        // 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);    } else {        // Set a min-height so that we can't get smaller than the mini button.        style->setMinHeight(Length(static_cast<int>(15 * style->effectiveZoom()), Fixed));        // Reset the top and bottom borders.        style->resetBorderTop();        style->resetBorderBottom();    }    style->setBoxShadow(0);}// FIXME: This used to be in the upstream version until it was converted to the new theme API in r37731.const IntSize* RenderThemeChromiumMac::buttonSizes() const{    static const IntSize sizes[3] = { IntSize(0, 21), IntSize(0, 18), IntSize(0, 15) };    return sizes;}// FIXME: This used to be in the upstream version until it was converted to the new theme API in r37731.const int* RenderThemeChromiumMac::buttonMargins() const{    static const int margins[3][4] =    {        { 4, 6, 7, 6 },        { 4, 5, 6, 5 },        { 0, 1, 1, 1 },    };    return margins[[button() controlSize]];}// FIXME: This used to be in the upstream version until it was converted to the new theme API in r37731.void RenderThemeChromiumMac::setButtonSize(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, buttonSizes());}// FIXME: This used to be in the upstream version until it was converted to the new theme API in r37731.void RenderThemeChromiumMac::setButtonCellState(const RenderObject* o, const IntRect& r){    NSButtonCell* button = this->button();    // Set the control size based off the rectangle we're painting into.    if (o->style()->appearance() == SquareButtonPart ||        r.height() > buttonSizes()[NSRegularControlSize].height() * o->style()->effectiveZoom()) {        // Use the square button        if ([button bezelStyle] != NSShadowlessSquareBezelStyle)            [button setBezelStyle:NSShadowlessSquareBezelStyle];    } else if ([button bezelStyle] != NSRoundedBezelStyle)        [button setBezelStyle:NSRoundedBezelStyle];    setControlSize(button, buttonSizes(), r.size(), o->style()->effectiveZoom());    NSWindow *window = [nil window];    BOOL isDefaultButton = (isDefault(o) && [window isKeyWindow]);    [button setKeyEquivalent:(isDefaultButton ? @"\r" : @"")];    // Update the various states we respond to.    updateCheckedState(button, o);    updateEnabledState(button, o);    updatePressedState(button, o);    updateFocusedState(button, o);}// FIXME: This used to be in the upstream version until it was converted to the new theme API in r37731.bool RenderThemeChromiumMac::paintButton(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r){    NSButtonCell* button = this->button();    LocalCurrentGraphicsContext localContext(paintInfo.context);    // Determine the width and height needed for the control and prepare the cell for painting.    setButtonCellState(o, r);    paintInfo.context->save();    // We inflate the rect as needed to account for padding included in the cell to accommodate the button    // shadow.  We don't consider this part of the bounds of the control in WebKit.    float zoomLevel = o->style()->effectiveZoom();

⌨️ 快捷键说明

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