📄 renderthemesafari.cpp
字号:
NSControlSize size; if (minSize.width() >= sizes[NSRegularControlSize].width() && minSize.height() >= sizes[NSRegularControlSize].height()) size = NSRegularControlSize; else if (minSize.width() >= sizes[NSSmallControlSize].width() && minSize.height() >= sizes[NSSmallControlSize].height()) 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 RenderThemeSafari::sizeForFont(RenderStyle* style, const IntSize* sizes) const{ return sizes[controlSizeForFont(style)];}IntSize RenderThemeSafari::sizeForSystemFont(RenderStyle* style, const IntSize* sizes) const{ return sizes[controlSizeForSystemFont(style)];}void RenderThemeSafari::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 RenderThemeSafari::setFontFromControlSize(CSSStyleSelector* selector, RenderStyle* style, NSControlSize controlSize) const{ FontDescription fontDescription; fontDescription.setIsAbsoluteSize(true); fontDescription.setGenericFamily(FontDescription::SerifFamily); float fontSize = systemFontSizeForControlSize(controlSize); fontDescription.firstFamily().setFamily("Lucida Grande"); fontDescription.setComputedSize(fontSize); fontDescription.setSpecifiedSize(fontSize); // Reset line height style->setLineHeight(RenderStyle::initialLineHeight()); if (style->setFontDescription(fontDescription)) style->font().update(selector->fontSelector());}NSControlSize RenderThemeSafari::controlSizeForSystemFont(RenderStyle* style) const{ int fontSize = style->fontSize(); if (fontSize >= 13) return NSRegularControlSize; if (fontSize >= 11) return NSSmallControlSize; return NSMiniControlSize;}bool RenderThemeSafari::paintCheckbox(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r){ ASSERT(SafariThemeLibrary()); NSControlSize controlSize = controlSizeForFont(o->style()); IntRect inflatedRect = inflateRect(r, checkboxSizes()[controlSize], checkboxMargins(controlSize)); paintThemePart(SafariTheme::CheckboxPart, paintInfo.context->platformContext(), inflatedRect, controlSize, determineState(o)); return false;}const IntSize* RenderThemeSafari::checkboxSizes() const{ static const IntSize sizes[3] = { IntSize(14, 14), IntSize(12, 12), IntSize(10, 10) }; return sizes;}const int* RenderThemeSafari::checkboxMargins(NSControlSize controlSize) const{ static const int margins[3][4] = { { 2, 2, 2, 2 }, { 2, 2, 2, 1 }, { 1, 0, 0, 0 }, }; return margins[controlSize];}void RenderThemeSafari::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());}bool RenderThemeSafari::paintRadio(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r){ ASSERT(SafariThemeLibrary()); NSControlSize controlSize = controlSizeForFont(o->style()); IntRect inflatedRect = inflateRect(r, radioSizes()[controlSize], radioMargins(controlSize)); paintThemePart(RadioButtonPart, paintInfo.context->platformContext(), inflatedRect, controlSize, determineState(o)); return false;}const IntSize* RenderThemeSafari::radioSizes() const{ static const IntSize sizes[3] = { IntSize(14, 15), IntSize(12, 13), IntSize(10, 10) }; return sizes;}const int* RenderThemeSafari::radioMargins(NSControlSize controlSize) const{ static const int margins[3][4] = { { 1, 2, 2, 2 }, { 0, 1, 2, 1 }, { 0, 0, 1, 0 }, }; return margins[controlSize];}void RenderThemeSafari::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());}void RenderThemeSafari::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->setPaddingLeft(Length(padding, Fixed)); style->setPaddingRight(Length(padding, Fixed)); style->setPaddingTop(Length(0, Fixed)); style->setPaddingBottom(Length(0, Fixed));}void RenderThemeSafari::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(15, Fixed)); // Reset the top and bottom borders. style->resetBorderTop(); style->resetBorderBottom(); }}const IntSize* RenderThemeSafari::buttonSizes() const{ static const IntSize sizes[3] = { IntSize(0, 21), IntSize(0, 18), IntSize(0, 15) }; return sizes;}const int* RenderThemeSafari::buttonMargins(NSControlSize controlSize) const{ static const int margins[3][4] = { { 4, 6, 7, 6 }, { 4, 5, 6, 5 }, { 0, 1, 1, 1 }, }; return margins[controlSize];}void RenderThemeSafari::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());}bool RenderThemeSafari::paintButton(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r){ ASSERT(SafariThemeLibrary()); // 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. NSControlSize controlSize = controlSizeFromRect(r, buttonSizes()); IntRect inflatedRect = r; ThemePart part; if (r.height() <= buttonSizes()[NSRegularControlSize].height()) { // Push button part = SafariTheme::PushButtonPart; IntSize size = buttonSizes()[controlSize]; size.setWidth(r.width()); // 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(controlSize)); } else part = SafariTheme::SquareButtonPart; paintThemePart(part, paintInfo.context->platformContext(), inflatedRect, controlSize, determineState(o)); return false;}bool RenderThemeSafari::paintTextField(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r){ ASSERT(SafariThemeLibrary()); paintThemePart(SafariTheme::TextFieldPart, paintInfo.context->platformContext(), r, (NSControlSize)0, determineState(o) & ~FocusedState); return false;}void RenderThemeSafari::adjustTextFieldStyle(CSSStyleSelector*, RenderStyle*, Element*) const{}bool RenderThemeSafari::paintCapsLockIndicator(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r){ #if defined(SAFARI_THEME_VERSION) && SAFARI_THEME_VERSION >= 1 ASSERT(SafariThemeLibrary()); if (paintInfo.context->paintingDisabled()) return true; paintThemePart(CapsLockPart, paintInfo.context->platformContext(), r, (NSControlSize)0, (ThemeControlState)0); return false;#else return true;#endif}bool RenderThemeSafari::paintTextArea(RenderObject* o, const RenderObject::PaintInfo& paintInfo, const IntRect& r){ ASSERT(SafariThemeLibrary()); paintThemePart(SafariTheme::TextAreaPart, paintInfo.context->platformContext(), r, (NSControlSize)0, determineState(o) & ~FocusedState); return false;}void RenderThemeSafari::adjustTextAreaStyle(CSSStyleSelector*, RenderStyle*, Element*) const{}const int* RenderThemeSafari::popupButtonMargins(NSControlSize size) const{ static const int margins[3][4] = { { 2, 3, 3, 3 }, { 1, 3, 3, 3 }, { 0, 1, 0, 1 } }; return margins[size];}const IntSize* RenderThemeSafari::popupButtonSizes() const{ static const IntSize sizes[3] = { IntSize(0, 21), IntSize(0, 18), IntSize(0, 15) };
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -