📄 renderthemechromiummac.mm
字号:
IntSize size = buttonSizes()[[button controlSize]]; size.setWidth(r.width()); size.setHeight(size.height() * zoomLevel); IntRect inflatedRect = r; if ([button bezelStyle] == NSRoundedBezelStyle) { // Center the button within the available space. if (inflatedRect.height() > size.height()) { inflatedRect.setY(inflatedRect.y() + (inflatedRect.height() - size.height()) / 2); inflatedRect.setHeight(size.height()); } // Now inflate it to account for the shadow. inflatedRect = inflateRect(inflatedRect, size, buttonMargins(), 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()); } } NSView *view = nil; NSWindow *window = [view window]; NSButtonCell *previousDefaultButtonCell = [window defaultButtonCell]; if (isDefault(o) && [window isKeyWindow]) { [window setDefaultButtonCell:button]; wkAdvanceDefaultButtonPulseAnimation(button); } else if ([previousDefaultButtonCell isEqual:button]) [window setDefaultButtonCell:nil]; [button drawWithFrame:NSRect(IntRectToNSRect(inflatedRect)) inView:view]; [button setControlView:nil]; if (![previousDefaultButtonCell isEqual:button]) [window setDefaultButtonCell:previousDefaultButtonCell]; paintInfo.context->restore(); return false;}bool RenderThemeChromiumMac::paintTextField(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r){ LocalCurrentGraphicsContext localContext(paintInfo.context); wkDrawBezeledTextFieldCell(IntRectToNSRect(r), isEnabled(o) && !isReadOnlyControl(o)); return false;}void RenderThemeChromiumMac::adjustTextFieldStyle(CSSStyleSelector*, RenderStyle*, Element*) const{}bool RenderThemeChromiumMac::paintCapsLockIndicator(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r){ if (paintInfo.context->paintingDisabled()) return true; LocalCurrentGraphicsContext localContext(paintInfo.context); wkDrawCapsLockIndicator(paintInfo.context->platformContext(), r); return false;}bool RenderThemeChromiumMac::paintTextArea(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r){ LocalCurrentGraphicsContext localContext(paintInfo.context); wkDrawBezeledTextArea(IntRectToNSRect(r), isEnabled(o) && !isReadOnlyControl(o)); return false;}void RenderThemeChromiumMac::adjustTextAreaStyle(CSSStyleSelector*, RenderStyle*, Element*) const{}const int* RenderThemeChromiumMac::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* RenderThemeChromiumMac::popupButtonSizes() const{ static const IntSize sizes[3] = { IntSize(0, 21), IntSize(0, 18), IntSize(0, 15) }; return sizes;}const int* RenderThemeChromiumMac::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 RenderThemeChromiumMac::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:IntRectToNSRect(inflatedRect) inView:nil]; [popupButton setControlView:nil]; paintInfo.context->restore(); return false;}static const float baseFontSize = 11.0f;static const float baseArrowHeight = 4.0f;static const float baseArrowWidth = 5.0f;static const float baseSpaceBetweenArrows = 2.0f;static const int arrowPaddingLeft = 6;static const int arrowPaddingRight = 6;static const int paddingBeforeSeparator = 4;static const int baseBorderRadius = 5;static const int styledPopupPaddingLeft = 8;static const int styledPopupPaddingTop = 1;static const int styledPopupPaddingBottom = 2;static void TopGradientInterpolate(void* info, 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* info, 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* info, 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* info, 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 RenderThemeChromiumMac::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 RenderThemeChromiumMac::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) };
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -