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

📄 thememac.mm

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 MM
📖 第 1 页 / 共 2 页
字号:
    NSButtonCell* radioCell = radio(states, zoomedRect, zoomFactor);    context->save();    NSControlSize controlSize = [radioCell controlSize];    IntSize zoomedSize = radioSizes()[controlSize];    zoomedSize.setWidth(zoomedSize.width() * zoomFactor);    zoomedSize.setHeight(zoomedSize.height() * zoomFactor);    IntRect inflatedRect = inflateRect(zoomedRect, zoomedSize, radioMargins(controlSize), zoomFactor);        if (zoomFactor != 1.0f) {        inflatedRect.setWidth(inflatedRect.width() / zoomFactor);        inflatedRect.setHeight(inflatedRect.height() / zoomFactor);        context->translate(inflatedRect.x(), inflatedRect.y());        context->scale(FloatSize(zoomFactor, zoomFactor));        context->translate(-inflatedRect.x(), -inflatedRect.y());    }        [radioCell drawWithFrame:NSRect(inflatedRect) inView:scrollView->documentView()];    [radioCell setControlView:nil];    context->restore();}// Buttons// Buttons really only constrain height. They respect width.static const IntSize* buttonSizes(){    static const IntSize sizes[3] = { IntSize(0, 21), IntSize(0, 18), IntSize(0, 15) };    return sizes;}static const int* buttonMargins(NSControlSize controlSize){    static const int margins[3][4] =    {        { 4, 6, 7, 6 },        { 4, 5, 6, 5 },        { 0, 1, 1, 1 },    };    return margins[controlSize];}static NSButtonCell* button(ControlPart part, ControlStates states, const IntRect& zoomedRect, float zoomFactor){    static NSButtonCell *buttonCell;    static bool defaultButton;    if (!buttonCell) {        buttonCell = [[NSButtonCell alloc] init];        [buttonCell setTitle:nil];        [buttonCell setButtonType:NSMomentaryPushInButton];    }    // Set the control size based off the rectangle we're painting into.    if (part == SquareButtonPart || zoomedRect.height() > buttonSizes()[NSRegularControlSize].height() * zoomFactor) {        // Use the square button        if ([buttonCell bezelStyle] != NSShadowlessSquareBezelStyle)            [buttonCell setBezelStyle:NSShadowlessSquareBezelStyle];    } else if ([buttonCell bezelStyle] != NSRoundedBezelStyle)        [buttonCell setBezelStyle:NSRoundedBezelStyle];    setControlSize(buttonCell, buttonSizes(), zoomedRect.size(), zoomFactor);    if (defaultButton != (states & DefaultState)) {        defaultButton = !defaultButton;        [buttonCell setKeyEquivalent:(defaultButton ? @"\r" : @"")];    }    // Update the various states we respond to.    updateStates(buttonCell, states);        return buttonCell;}static void paintButton(ControlPart part, ControlStates states, GraphicsContext* context, const IntRect& zoomedRect, float zoomFactor, ScrollView* scrollView){    // Determine the width and height needed for the control and prepare the cell for painting.    NSButtonCell *buttonCell = button(part, states, zoomedRect, zoomFactor);    LocalCurrentGraphicsContext localContext(context);    NSControlSize controlSize = [buttonCell controlSize];    IntSize zoomedSize = buttonSizes()[controlSize];    zoomedSize.setWidth(zoomedRect.width()); // Buttons don't ever constrain width, so the zoomed width can just be honored.    zoomedSize.setHeight(zoomedSize.height() * zoomFactor);    IntRect inflatedRect = zoomedRect;    if ([buttonCell bezelStyle] == NSRoundedBezelStyle) {        // Center the button within the available space.        if (inflatedRect.height() > zoomedSize.height()) {            inflatedRect.setY(inflatedRect.y() + (inflatedRect.height() - zoomedSize.height()) / 2);            inflatedRect.setHeight(zoomedSize.height());        }        // Now inflate it to account for the shadow.        inflatedRect = inflateRect(inflatedRect, zoomedSize, buttonMargins(controlSize), zoomFactor);        if (zoomFactor != 1.0f) {            inflatedRect.setWidth(inflatedRect.width() / zoomFactor);            inflatedRect.setHeight(inflatedRect.height() / zoomFactor);            context->translate(inflatedRect.x(), inflatedRect.y());            context->scale(FloatSize(zoomFactor, zoomFactor));            context->translate(-inflatedRect.x(), -inflatedRect.y());        }    }     NSView *view = scrollView->documentView();    NSWindow *window = [view window];    NSButtonCell *previousDefaultButtonCell = [window defaultButtonCell];    if ((states & DefaultState) && [window isKeyWindow]) {        [window setDefaultButtonCell:buttonCell];        wkAdvanceDefaultButtonPulseAnimation(buttonCell);    } else if ([previousDefaultButtonCell isEqual:buttonCell])        [window setDefaultButtonCell:nil];    [buttonCell drawWithFrame:NSRect(inflatedRect) inView:view];    [buttonCell setControlView:nil];    if (![previousDefaultButtonCell isEqual:buttonCell])        [window setDefaultButtonCell:previousDefaultButtonCell];}// Theme overridesint ThemeMac::baselinePositionAdjustment(ControlPart part) const{    if (part == CheckboxPart || part == RadioPart)        return -2;    return Theme::baselinePositionAdjustment(part);}FontDescription ThemeMac::controlFont(ControlPart part, const Font& font, float zoomFactor) const{    switch (part) {        case PushButtonPart: {            FontDescription fontDescription;            fontDescription.setIsAbsoluteSize(true);            fontDescription.setGenericFamily(FontDescription::SerifFamily);            NSFont* nsFont = [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:controlSizeForFont(font)]];            fontDescription.firstFamily().setFamily([nsFont familyName]);            fontDescription.setComputedSize([nsFont pointSize] * zoomFactor);            fontDescription.setSpecifiedSize([nsFont pointSize] * zoomFactor);            return fontDescription;        }        default:            return Theme::controlFont(part, font, zoomFactor);    }}LengthSize ThemeMac::controlSize(ControlPart part, const Font& font, const LengthSize& zoomedSize, float zoomFactor) const{    switch (part) {        case CheckboxPart:            return checkboxSize(font, zoomedSize, zoomFactor);        case RadioPart:            return radioSize(font, zoomedSize, zoomFactor);        case PushButtonPart:            // Height is reset to auto so that specified heights can be ignored.            return sizeFromFont(font, LengthSize(zoomedSize.width(), Length()), zoomFactor, buttonSizes());        default:            return zoomedSize;    }}LengthSize ThemeMac::minimumControlSize(ControlPart part, const Font& font, float zoomFactor) const{    switch (part) {        case SquareButtonPart:        case DefaultButtonPart:        case ButtonPart:            return LengthSize(Length(0, Fixed), Length(static_cast<int>(15 * zoomFactor), Fixed));        default:            return Theme::minimumControlSize(part, font, zoomFactor);    }}LengthBox ThemeMac::controlBorder(ControlPart part, const Font& font, const LengthBox& zoomedBox, float zoomFactor) const{    switch (part) {        case SquareButtonPart:        case DefaultButtonPart:        case ButtonPart:            return LengthBox(0, zoomedBox.right().value(), 0, zoomedBox.left().value());        default:            return Theme::controlBorder(part, font, zoomedBox, zoomFactor);    }}LengthBox ThemeMac::controlPadding(ControlPart part, const Font& font, const LengthBox& zoomedBox, float zoomFactor) const{    switch (part) {        case PushButtonPart: {            // 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 HTML <button> will match our rendering by default, since we're using a consistent            // padding.            const int padding = 8 * zoomFactor;            return LengthBox(0, padding, 0, padding);        }        default:            return Theme::controlPadding(part, font, zoomedBox, zoomFactor);    }}void ThemeMac::inflateControlPaintRect(ControlPart part, ControlStates states, IntRect& zoomedRect, float zoomFactor) const{    switch (part) {        case CheckboxPart: {            // 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.            NSCell *cell = checkbox(states, zoomedRect, zoomFactor);            NSControlSize controlSize = [cell controlSize];            IntSize zoomedSize = checkboxSizes()[controlSize];            zoomedSize.setHeight(zoomedSize.height() * zoomFactor);            zoomedSize.setWidth(zoomedSize.width() * zoomFactor);            zoomedRect = inflateRect(zoomedRect, zoomedSize, checkboxMargins(controlSize), zoomFactor);            break;        }        case RadioPart: {            // We inflate the rect as needed to account for padding included in the cell to accommodate the radio button            // shadow".  We don't consider this part of the bounds of the control in WebKit.            NSCell *cell = radio(states, zoomedRect, zoomFactor);            NSControlSize controlSize = [cell controlSize];            IntSize zoomedSize = radioSizes()[controlSize];            zoomedSize.setHeight(zoomedSize.height() * zoomFactor);            zoomedSize.setWidth(zoomedSize.width() * zoomFactor);            zoomedRect = inflateRect(zoomedRect, zoomedSize, radioMargins(controlSize), zoomFactor);            break;        }        case PushButtonPart:        case DefaultButtonPart:        case ButtonPart: {            NSButtonCell *cell = button(part, states, zoomedRect, zoomFactor);            NSControlSize controlSize = [cell controlSize];            // We inflate the rect as needed to account for the Aqua button's shadow.            if ([cell bezelStyle] == NSRoundedBezelStyle) {                IntSize zoomedSize = buttonSizes()[controlSize];                zoomedSize.setHeight(zoomedSize.height() * zoomFactor);                zoomedSize.setWidth(zoomedRect.width()); // Buttons don't ever constrain width, so the zoomed width can just be honored.                zoomedRect = inflateRect(zoomedRect, zoomedSize, buttonMargins(controlSize), zoomFactor);            }            break;        }        default:            break;    }}void ThemeMac::paint(ControlPart part, ControlStates states, GraphicsContext* context, const IntRect& zoomedRect, float zoomFactor, ScrollView* scrollView) const{    switch (part) {        case CheckboxPart:            paintCheckbox(states, context, zoomedRect, zoomFactor, scrollView);            break;        case RadioPart:            paintRadio(states, context, zoomedRect, zoomFactor, scrollView);            break;        case PushButtonPart:        case DefaultButtonPart:        case ButtonPart:        case SquareButtonPart:            paintButton(part, states, context, zoomedRect, zoomFactor, scrollView);            break;        default:            break;    }}}

⌨️ 快捷键说明

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