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

📄 renderthememac.mm

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 MM
📖 第 1 页 / 共 5 页
字号:
            // Use theme independent default            break;        case CSSValueButtonface:            // We use this value instead of NSColor's controlColor to avoid website incompatibilities.            // We may want to change this to use the NSColor in future.            color = 0xFFC0C0C0;            break;        case CSSValueButtonhighlight:            color = convertNSColorToColor([NSColor controlHighlightColor]);            break;        case CSSValueButtonshadow:            color = convertNSColorToColor([NSColor controlShadowColor]);            break;        case CSSValueButtontext:            color = convertNSColorToColor([NSColor controlTextColor]);            break;        case CSSValueCaptiontext:            color = convertNSColorToColor([NSColor textColor]);            break;        case CSSValueGraytext:            color = convertNSColorToColor([NSColor disabledControlTextColor]);            break;        case CSSValueHighlight:            color = convertNSColorToColor([NSColor selectedTextBackgroundColor]);            break;        case CSSValueHighlighttext:            color = convertNSColorToColor([NSColor selectedTextColor]);            break;        case CSSValueInactiveborder:            color = convertNSColorToColor([NSColor controlBackgroundColor]);            break;        case CSSValueInactivecaption:            color = convertNSColorToColor([NSColor controlBackgroundColor]);            break;        case CSSValueInactivecaptiontext:            color = convertNSColorToColor([NSColor textColor]);            break;        case CSSValueInfobackground:            // There is no corresponding NSColor for this so we use a hard coded value.            color = 0xFFFBFCC5;            break;        case CSSValueInfotext:            color = convertNSColorToColor([NSColor textColor]);            break;        case CSSValueMenu:            color = menuBackgroundColor();            break;        case CSSValueMenutext:            color = convertNSColorToColor([NSColor selectedMenuItemTextColor]);            break;        case CSSValueScrollbar:            color = convertNSColorToColor([NSColor scrollBarColor]);            break;        case CSSValueText:            color = convertNSColorToColor([NSColor textColor]);            break;        case CSSValueThreeddarkshadow:            color = convertNSColorToColor([NSColor controlDarkShadowColor]);            break;        case CSSValueThreedshadow:            color = convertNSColorToColor([NSColor shadowColor]);            break;        case CSSValueThreedface:            // We use this value instead of NSColor's controlColor to avoid website incompatibilities.            // We may want to change this to use the NSColor in future.            color = 0xFFC0C0C0;            break;        case CSSValueThreedhighlight:            color = convertNSColorToColor([NSColor highlightColor]);            break;        case CSSValueThreedlightshadow:            color = convertNSColorToColor([NSColor controlLightHighlightColor]);            break;        case CSSValueWindow:            color = convertNSColorToColor([NSColor windowBackgroundColor]);            break;        case CSSValueWindowframe:            color = convertNSColorToColor([NSColor windowFrameColor]);            break;        case CSSValueWindowtext:            color = convertNSColorToColor([NSColor windowFrameTextColor]);            break;    }    if (!color.isValid())        color = RenderTheme::systemColor(cssValueId);    if (color.isValid())        m_systemColorCache.set(cssValueId, color.rgb());    return color;}bool RenderThemeMac::isControlStyled(const RenderStyle* style, const BorderData& border,                                     const FillLayer& background, const Color& backgroundColor) const{    if (style->appearance() == TextFieldPart || style->appearance() == TextAreaPart || style->appearance() == ListboxPart)        return style->border() != border;            // FIXME: This is horrible, but there is not much else that can be done.  Menu lists cannot draw properly when    // scaled.  They can't really draw properly when transformed either.  We can't detect the transform case at style    // adjustment time so that will just have to stay broken.  We can however detect that we're zooming.  If zooming    // is in effect we treat it like the control is styled.    if (style->appearance() == MenulistPart && style->effectiveZoom() != 1.0f)        return true;    return RenderTheme::isControlStyled(style, border, background, backgroundColor);}void RenderThemeMac::adjustRepaintRect(const RenderObject* o, IntRect& r){    ControlPart part = o->style()->appearance();    #if USE(NEW_THEME)    switch (part) {        case CheckboxPart:        case RadioPart:        case PushButtonPart:        case SquareButtonPart:        case DefaultButtonPart:        case ButtonPart:            return RenderTheme::adjustRepaintRect(o, r);        default:            break;    }#endif    float zoomLevel = o->style()->effectiveZoom();    if (part == MenulistPart) {        setPopupButtonCellState(o, r);        IntSize size = popupButtonSizes()[[popupButton() controlSize]];        size.setHeight(size.height() * zoomLevel);        size.setWidth(r.width());        r = inflateRect(r, size, popupButtonMargins(), zoomLevel);    }}IntRect RenderThemeMac::inflateRect(const IntRect& r, const IntSize& size, const int* margins, float zoomLevel) const{    // Only do the inflation if the available width/height are too small.  Otherwise try to    // fit the glow/check space into the available box's width/height.    int widthDelta = r.width() - (size.width() + margins[leftMargin] * zoomLevel + margins[rightMargin] * zoomLevel);    int heightDelta = r.height() - (size.height() + margins[topMargin] * zoomLevel + margins[bottomMargin] * zoomLevel);    IntRect result(r);    if (widthDelta < 0) {        result.setX(result.x() - margins[leftMargin] * zoomLevel);        result.setWidth(result.width() - widthDelta);    }    if (heightDelta < 0) {        result.setY(result.y() - margins[topMargin] * zoomLevel);        result.setHeight(result.height() - heightDelta);    }    return result;}FloatRect RenderThemeMac::convertToPaintingRect(const RenderObject* inputRenderer, const RenderObject* partRenderer, const FloatRect& inputRect, const IntRect& r) const{    FloatRect partRect(inputRect);        // Compute an offset between the part renderer and the input renderer    FloatSize offsetFromInputRenderer;    const RenderObject* renderer = partRenderer;    while (renderer && renderer != inputRenderer) {        RenderObject* containingRenderer = renderer->container();        offsetFromInputRenderer -= renderer->offsetFromContainer(containingRenderer);        renderer = containingRenderer;    }    // If the input renderer was not a container, something went wrong    ASSERT(renderer == inputRenderer);    // Move the rect into partRenderer's coords    partRect.move(offsetFromInputRenderer);    // Account for the local drawing offset (tx, ty)    partRect.move(r.x(), r.y());    return partRect;}void RenderThemeMac::updateCheckedState(NSCell* cell, const RenderObject* o){    bool oldIndeterminate = [cell state] == NSMixedState;    bool indeterminate = isIndeterminate(o);    bool checked = isChecked(o);    if (oldIndeterminate != indeterminate) {        [cell setState:indeterminate ? NSMixedState : (checked ? NSOnState : NSOffState)];        return;    }    bool oldChecked = [cell state] == NSOnState;    if (checked != oldChecked)        [cell setState:checked ? NSOnState : NSOffState];}void RenderThemeMac::updateEnabledState(NSCell* cell, const RenderObject* o){    bool oldEnabled = [cell isEnabled];    bool enabled = isEnabled(o);    if (enabled != oldEnabled)        [cell setEnabled:enabled];}void RenderThemeMac::updateFocusedState(NSCell* cell, const RenderObject* o){    bool oldFocused = [cell showsFirstResponder];    bool focused = isFocused(o) && o->style()->outlineStyleIsAuto();    if (focused != oldFocused)        [cell setShowsFirstResponder:focused];}void RenderThemeMac::updatePressedState(NSCell* cell, const RenderObject* o){    bool oldPressed = [cell isHighlighted];    bool pressed = (o->node() && o->node()->active());    if (pressed != oldPressed)        [cell setHighlighted:pressed];}bool RenderThemeMac::controlSupportsTints(const RenderObject* o) const{    // An alternate way to implement this would be to get the appropriate cell object    // and call the private _needRedrawOnWindowChangedKeyState method. An advantage of    // that would be that we would match AppKit behavior more closely, but a disadvantage    // would be that we would rely on an AppKit SPI method.    if (!isEnabled(o))        return false;    // Checkboxes only have tint when checked.    if (o->style()->appearance() == CheckboxPart)        return isChecked(o);    // For now assume other controls have tint if enabled.    return true;}NSControlSize RenderThemeMac::controlSizeForFont(RenderStyle* style) const{    int fontSize = style->fontSize();    if (fontSize >= 16)        return NSRegularControlSize;    if (fontSize >= 11)        return NSSmallControlSize;    return NSMiniControlSize;}void RenderThemeMac::setControlSize(NSCell* cell, const IntSize* sizes, const IntSize& minSize, float zoomLevel){    NSControlSize size;    if (minSize.width() >= static_cast<int>(sizes[NSRegularControlSize].width() * zoomLevel) &&        minSize.height() >= static_cast<int>(sizes[NSRegularControlSize].height() * zoomLevel))        size = NSRegularControlSize;    else if (minSize.width() >= static_cast<int>(sizes[NSSmallControlSize].width() * zoomLevel) &&             minSize.height() >= static_cast<int>(sizes[NSSmallControlSize].height() * zoomLevel))        size = NSSmallControlSize;    else        size = NSMiniControlSize;    if (size != [cell controlSize]) // Only update if we have to, since AppKit does work even if the size is the same.        [cell setControlSize:size];}IntSize RenderThemeMac::sizeForFont(RenderStyle* style, const IntSize* sizes) const{    if (style->effectiveZoom() != 1.0f) {        IntSize result = sizes[controlSizeForFont(style)];        return IntSize(result.width() * style->effectiveZoom(), result.height() * style->effectiveZoom());    }    return sizes[controlSizeForFont(style)];}IntSize RenderThemeMac::sizeForSystemFont(RenderStyle* style, const IntSize* sizes) const{    if (style->effectiveZoom() != 1.0f) {        IntSize result = sizes[controlSizeForSystemFont(style)];        return IntSize(result.width() * style->effectiveZoom(), result.height() * style->effectiveZoom());    }    return sizes[controlSizeForSystemFont(style)];}void RenderThemeMac::setSizeFromFont(RenderStyle* style, const IntSize* sizes) const{    // FIXME: Check is flawed, since it doesn't take min-width/max-width into account.    IntSize size = sizeForFont(style, sizes);    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 RenderThemeMac::setFontFromControlSize(CSSStyleSelector*, 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 RenderThemeMac::controlSizeForSystemFont(RenderStyle* style) const{    int fontSize = style->fontSize();    if (fontSize >= [NSFont systemFontSizeForControlSize:NSRegularControlSize])        return NSRegularControlSize;    if (fontSize >= [NSFont systemFontSizeForControlSize:NSSmallControlSize])        return NSSmallControlSize;    return NSMiniControlSize;}bool RenderThemeMac::paintTextField(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r){    LocalCurrentGraphicsContext localContext(paintInfo.context);    wkDrawBezeledTextFieldCell(r, isEnabled(o) && !isReadOnlyControl(o));    return false;}void RenderThemeMac::adjustTextFieldStyle(CSSStyleSelector*, RenderStyle*, Element*) const{}bool RenderThemeMac::paintCapsLockIndicator(RenderObject*, const RenderObject::PaintInfo& paintInfo, const IntRect& r){    if (paintInfo.context->paintingDisabled())        return true;    LocalCurrentGraphicsContext localContext(paintInfo.context);    wkDrawCapsLockIndicator(paintInfo.context->platformContext(), r);        return false;

⌨️ 快捷键说明

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