static blink::WebThemeEngine::State getWebThemeState(const RenderTheme* theme, const RenderObject* o) { if (!theme->isEnabled(o)) return blink::WebThemeEngine::StateDisabled; if (useMockTheme() && theme->isReadOnlyControl(o)) return blink::WebThemeEngine::StateReadonly; if (theme->isPressed(o)) return blink::WebThemeEngine::StatePressed; if (useMockTheme() && theme->isFocused(o)) return blink::WebThemeEngine::StateFocused; if (theme->isHovered(o)) return blink::WebThemeEngine::StateHover; return blink::WebThemeEngine::StateNormal; }
bool ThemePainterDefault::paintSliderThumb(const LayoutObject& o, const PaintInfo& i, const IntRect& rect) { WebThemeEngine::ExtraParams extraParams; WebCanvas* canvas = i.context.canvas(); extraParams.slider.vertical = o.styleRef().appearance() == SliderThumbVerticalPart; extraParams.slider.inDrag = LayoutTheme::isPressed(o); // FIXME: Mock theme doesn't handle zoomed sliders. float zoomLevel = useMockTheme() ? 1 : o.styleRef().effectiveZoom(); GraphicsContextStateSaver stateSaver(i.context, false); IntRect unzoomedRect = rect; if (zoomLevel != 1) { stateSaver.save(); unzoomedRect.setWidth(unzoomedRect.width() / zoomLevel); unzoomedRect.setHeight(unzoomedRect.height() / zoomLevel); i.context.translate(unzoomedRect.x(), unzoomedRect.y()); i.context.scale(zoomLevel, zoomLevel); i.context.translate(-unzoomedRect.x(), -unzoomedRect.y()); } Platform::current()->themeEngine()->paint( canvas, WebThemeEngine::PartSliderThumb, getWebThemeState(o), WebRect(unzoomedRect), &extraParams); return false; }
bool RenderThemeChromiumDefault::paintMenuListButton(RenderObject* o, const PaintInfo& i, const IntRect& rect) { if (!o->isBox() || i.context->paintingDisabled()) return false; const int right = rect.x() + rect.width(); const int middle = rect.y() + rect.height() / 2; blink::WebThemeEngine::ExtraParams extraParams; extraParams.menuList.arrowY = middle; extraParams.menuList.hasBorder = false; extraParams.menuList.hasBorderRadius = o->style()->hasBorderRadius(); extraParams.menuList.backgroundColor = Color::transparent; extraParams.menuList.fillContentArea = false; if (useMockTheme()) { const RenderBox* box = toRenderBox(o); // The size and position of the drop-down button is different between // the mock theme and the regular aura theme. int spacingTop = box->borderTop() + box->paddingTop(); int spacingBottom = box->borderBottom() + box->paddingBottom(); int spacingRight = box->borderRight() + box->paddingRight(); extraParams.menuList.arrowX = (o->style()->direction() == RTL) ? rect.x() + 4 + spacingRight: right - 13 - spacingRight; extraParams.menuList.arrowHeight = rect.height() - spacingBottom - spacingTop; } else { extraParams.menuList.arrowX = (o->style()->direction() == RTL) ? rect.x() + 7 : right - 13; } blink::WebCanvas* canvas = i.context->canvas(); blink::Platform::current()->themeEngine()->paint(canvas, blink::WebThemeEngine::PartMenuList, getWebThemeState(this, o), blink::WebRect(rect), &extraParams); return false; }
void ScrollbarThemeAura::paintTrackPiece(GraphicsContext& gc, const Scrollbar& scrollbar, const IntRect& rect, ScrollbarPart partType) { DisplayItem::Type displayItemType = trackPiecePartToDisplayItemType(partType); if (DrawingRecorder::useCachedDrawingIfPossible(gc, scrollbar, displayItemType)) return; DrawingRecorder recorder(gc, scrollbar, displayItemType, rect); WebThemeEngine::State state = scrollbar.hoveredPart() == partType ? WebThemeEngine::StateHover : WebThemeEngine::StateNormal; if (useMockTheme() && !scrollbar.enabled()) state = WebThemeEngine::StateDisabled; IntRect alignRect = trackRect(scrollbar, false); WebThemeEngine::ExtraParams extraParams; extraParams.scrollbarTrack.isBack = (partType == BackTrackPart); extraParams.scrollbarTrack.trackX = alignRect.x(); extraParams.scrollbarTrack.trackY = alignRect.y(); extraParams.scrollbarTrack.trackWidth = alignRect.width(); extraParams.scrollbarTrack.trackHeight = alignRect.height(); Platform::current()->themeEngine()->paint( gc.canvas(), scrollbar.orientation() == HorizontalScrollbar ? WebThemeEngine::PartScrollbarHorizontalTrack : WebThemeEngine::PartScrollbarVerticalTrack, state, WebRect(rect), &extraParams); }
bool RenderThemeChromiumDefault::paintSliderThumb(RenderObject* o, const PaintInfo& i, const IntRect& rect) { if (i.context->paintingDisabled()) return false; blink::WebThemeEngine::ExtraParams extraParams; blink::WebCanvas* canvas = i.context->canvas(); extraParams.slider.vertical = o->style()->appearance() == SliderThumbVerticalPart; extraParams.slider.inDrag = isPressed(o); // FIXME: Mock theme doesn't handle zoomed sliders. float zoomLevel = useMockTheme() ? 1 : o->style()->effectiveZoom(); GraphicsContextStateSaver stateSaver(*i.context, false); IntRect unzoomedRect = rect; if (zoomLevel != 1) { stateSaver.save(); unzoomedRect.setWidth(unzoomedRect.width() / zoomLevel); unzoomedRect.setHeight(unzoomedRect.height() / zoomLevel); i.context->translate(unzoomedRect.x(), unzoomedRect.y()); i.context->scale(zoomLevel, zoomLevel); i.context->translate(-unzoomedRect.x(), -unzoomedRect.y()); } blink::Platform::current()->themeEngine()->paint(canvas, blink::WebThemeEngine::PartSliderThumb, getWebThemeState(this, o), blink::WebRect(unzoomedRect), &extraParams); return false; }
int ScrollbarThemeAura::scrollbarThickness(ScrollbarControlSize controlSize) { // Horiz and Vert scrollbars are the same thickness. // In unit tests we don't have the mock theme engine (because of layering violations), so we hard code the size (see bug 327470). if (useMockTheme()) return 15; IntSize scrollbarSize = Platform::current()->themeEngine()->getSize(WebThemeEngine::PartScrollbarVerticalTrack); return scrollbarSize.width(); }
bool LayoutThemeDefault::shouldUseFallbackTheme(const ComputedStyle& style) const { if (useMockTheme()) { // The mock theme can't handle zoomed controls, so we fall back to the "fallback" theme. ControlPart part = style.appearance(); if (part == CheckboxPart || part == RadioPart) return style.effectiveZoom() != 1; } return LayoutTheme::shouldUseFallbackTheme(style); }
bool RenderThemeChromiumDefault::shouldUseFallbackTheme(RenderStyle* style) const { if (useMockTheme()) { // The mock theme can't handle zoomed controls, so we fall back to the "fallback" theme. ControlPart part = style->appearance(); if (part == CheckboxPart || part == RadioPart) return style->effectiveZoom() != 1; } return RenderTheme::shouldUseFallbackTheme(style); }
void ScrollbarThemeGtkOrAura::paintButton(GraphicsContext* gc, ScrollbarThemeClient* scrollbar, const IntRect& rect, ScrollbarPart part) { blink::WebThemeEngine::Part paintPart; blink::WebThemeEngine::State state = blink::WebThemeEngine::StateNormal; blink::WebCanvas* canvas = gc->canvas(); bool checkMin = false; bool checkMax = false; if (scrollbar->orientation() == HorizontalScrollbar) { if (part == BackButtonStartPart) { paintPart = blink::WebThemeEngine::PartScrollbarLeftArrow; checkMin = true; } else if (useMockTheme() && part != ForwardButtonEndPart) { return; } else { paintPart = blink::WebThemeEngine::PartScrollbarRightArrow; checkMax = true; } } else { if (part == BackButtonStartPart) { paintPart = blink::WebThemeEngine::PartScrollbarUpArrow; checkMin = true; } else if (useMockTheme() && part != ForwardButtonEndPart) { return; } else { paintPart = blink::WebThemeEngine::PartScrollbarDownArrow; checkMax = true; } } if (useMockTheme() && !scrollbar->enabled()) { state = blink::WebThemeEngine::StateDisabled; } else if (!useMockTheme() && ((checkMin && (scrollbar->currentPos() <= 0)) || (checkMax && scrollbar->currentPos() >= scrollbar->maximum()))) { state = blink::WebThemeEngine::StateDisabled; } else { if (part == scrollbar->pressedPart()) state = blink::WebThemeEngine::StatePressed; else if (part == scrollbar->hoveredPart()) state = blink::WebThemeEngine::StateHover; } blink::Platform::current()->themeEngine()->paint(canvas, paintPart, state, blink::WebRect(rect), 0); }
bool RenderThemeChromiumDefault::supportsFocusRing(const RenderStyle* style) const { if (useMockTheme()) { // Don't use focus rings for buttons when mocking controls. return style->appearance() == ButtonPart || style->appearance() == PushButtonPart || style->appearance() == SquareButtonPart; } return RenderThemeChromiumSkia::supportsFocusRing(style); }
bool LayoutThemeDefault::themeDrawsFocusRing(const ComputedStyle& style) const { if (useMockTheme()) { // Don't use focus rings for buttons when mocking controls. return style.appearance() == ButtonPart || style.appearance() == PushButtonPart || style.appearance() == SquareButtonPart; } // This causes Blink to draw the focus rings for us. return false; }
bool RenderThemeChromiumDefault::paintButton(RenderObject* o, const PaintInfo& i, const IntRect& rect) { if (i.context->paintingDisabled()) return false; blink::WebThemeEngine::ExtraParams extraParams; blink::WebCanvas* canvas = i.context->canvas(); extraParams.button.hasBorder = true; extraParams.button.backgroundColor = useMockTheme() ? 0xffc0c0c0 : defaultButtonBackgroundColor; if (o->hasBackground()) extraParams.button.backgroundColor = o->resolveColor(CSSPropertyBackgroundColor).rgb(); blink::Platform::current()->themeEngine()->paint(canvas, blink::WebThemeEngine::PartButton, getWebThemeState(this, o), blink::WebRect(rect), &extraParams); return false; }
Color LayoutThemeDefault::systemColor(CSSValueID cssValueId) const { static const Color defaultButtonGrayColor(0xffdddddd); static const Color defaultMenuColor(0xfff7f7f7); if (cssValueId == CSSValueButtonface) { if (useMockTheme()) return Color(0xc0, 0xc0, 0xc0); return defaultButtonGrayColor; } if (cssValueId == CSSValueMenu) return defaultMenuColor; return LayoutTheme::systemColor(cssValueId); }
void RenderThemeChromiumDefault::adjustSliderThumbSize(RenderStyle* style, Element* element) const { IntSize size = blink::Platform::current()->themeEngine()->getSize(blink::WebThemeEngine::PartSliderThumb); // FIXME: Mock theme doesn't handle zoomed sliders. float zoomLevel = useMockTheme() ? 1 : style->effectiveZoom(); if (style->appearance() == SliderThumbHorizontalPart) { style->setWidth(Length(size.width() * zoomLevel, Fixed)); style->setHeight(Length(size.height() * zoomLevel, Fixed)); } else if (style->appearance() == SliderThumbVerticalPart) { style->setWidth(Length(size.height() * zoomLevel, Fixed)); style->setHeight(Length(size.width() * zoomLevel, Fixed)); } else RenderThemeChromiumSkia::adjustSliderThumbSize(style, element); }
void LayoutThemeDefault::adjustSliderThumbSize(ComputedStyle& style) const { IntSize size = Platform::current()->themeEngine()->getSize(WebThemeEngine::PartSliderThumb); // FIXME: Mock theme doesn't handle zoomed sliders. float zoomLevel = useMockTheme() ? 1 : style.effectiveZoom(); if (style.appearance() == SliderThumbHorizontalPart) { style.setWidth(Length(size.width() * zoomLevel, Fixed)); style.setHeight(Length(size.height() * zoomLevel, Fixed)); } else if (style.appearance() == SliderThumbVerticalPart) { style.setWidth(Length(size.height() * zoomLevel, Fixed)); style.setHeight(Length(size.width() * zoomLevel, Fixed)); } else { MediaControlsPainter::adjustMediaSliderThumbSize(style); } }
bool ThemePainterDefault::paintButton(const LayoutObject& o, const PaintInfo& i, const IntRect& rect) { WebThemeEngine::ExtraParams extraParams; WebCanvas* canvas = i.context.canvas(); extraParams.button.hasBorder = true; extraParams.button.backgroundColor = useMockTheme() ? 0xffc0c0c0 : defaultButtonBackgroundColor; if (o.styleRef().hasBackground()) extraParams.button.backgroundColor = o.resolveColor(CSSPropertyBackgroundColor).rgb(); Platform::current()->themeEngine()->paint(canvas, WebThemeEngine::PartButton, getWebThemeState(o), WebRect(rect), &extraParams); return false; }
bool RenderThemeChromiumDefault::paintMenuList(RenderObject* o, const PaintInfo& i, const IntRect& rect) { if (!o->isBox() || i.context->paintingDisabled()) return false; const int right = rect.x() + rect.width(); const int middle = rect.y() + rect.height() / 2; blink::WebThemeEngine::ExtraParams extraParams; extraParams.menuList.arrowY = middle; const RenderBox* box = toRenderBox(o); // Match Chromium Win behaviour of showing all borders if any are shown. extraParams.menuList.hasBorder = box->borderRight() || box->borderLeft() || box->borderTop() || box->borderBottom(); extraParams.menuList.hasBorderRadius = o->style()->hasBorderRadius(); // Fallback to transparent if the specified color object is invalid. Color backgroundColor(Color::transparent); if (o->hasBackground()) backgroundColor = o->resolveColor(CSSPropertyBackgroundColor); extraParams.menuList.backgroundColor = backgroundColor.rgb(); // If we have a background image, don't fill the content area to expose the // parent's background. Also, we shouldn't fill the content area if the // alpha of the color is 0. The API of Windows GDI ignores the alpha. // FIXME: the normal Aura theme doesn't care about this, so we should // investigate if we really need fillContentArea. extraParams.menuList.fillContentArea = !o->style()->hasBackgroundImage() && backgroundColor.alpha(); if (useMockTheme()) { // The size and position of the drop-down button is different between // the mock theme and the regular aura theme. int spacingTop = box->borderTop() + box->paddingTop(); int spacingBottom = box->borderBottom() + box->paddingBottom(); int spacingRight = box->borderRight() + box->paddingRight(); extraParams.menuList.arrowX = (o->style()->direction() == RTL) ? rect.x() + 4 + spacingRight: right - 13 - spacingRight; extraParams.menuList.arrowHeight = rect.height() - spacingBottom - spacingTop; } else { extraParams.menuList.arrowX = (o->style()->direction() == RTL) ? rect.x() + 7 : right - 13; } blink::WebCanvas* canvas = i.context->canvas(); blink::Platform::current()->themeEngine()->paint(canvas, blink::WebThemeEngine::PartMenuList, getWebThemeState(this, o), blink::WebRect(rect), &extraParams); return false; }
void ThemePainterDefault::setupMenuListArrow( const LayoutBox& box, const IntRect& rect, WebThemeEngine::ExtraParams& extraParams) { const int left = rect.x() + box.borderLeft(); const int right = rect.x() + rect.width() - box.borderRight(); const int middle = rect.y() + rect.height() / 2; extraParams.menuList.arrowY = middle; float arrowBoxWidth = m_theme.clampedMenuListArrowPaddingSize( box.frameView()->getHostWindow(), box.styleRef()); float arrowScaleFactor = arrowBoxWidth / m_theme.scrollbarThicknessInDIP(); if (useMockTheme()) { // The size and position of the drop-down button is different between // the mock theme and the regular aura theme. // Padding inside the arrowBox. float extraPadding = 2 * arrowScaleFactor; float arrowSize = std::min(arrowBoxWidth, static_cast<float>(rect.height() - box.borderTop() - box.borderBottom())) - 2 * extraPadding; // |arrowX| is the middle position for mock theme engine. extraParams.menuList.arrowX = (box.styleRef().direction() == RTL) ? rect.x() + extraPadding + (arrowSize / 2) : right - (arrowSize / 2) - extraPadding; extraParams.menuList.arrowSize = arrowSize; } else { // TODO(tkent): This should be 7.0 to match scroll bar buttons. float arrowSize = 6.0 * arrowScaleFactor; // Put the 6px arrow at the center of paddingForArrow area. // |arrowX| is the left position for Aura theme engine. extraParams.menuList.arrowX = (box.styleRef().direction() == RTL) ? left + (arrowBoxWidth - arrowSize) / 2 : right - (arrowBoxWidth + arrowSize) / 2; extraParams.menuList.arrowSize = arrowSize; } extraParams.menuList.arrowColor = box.resolveColor(CSSPropertyColor).rgb(); }
Color RenderThemeChromiumDefault::platformActiveSelectionForegroundColor() const { if (useMockTheme()) return Color(0xff, 0xff, 0xcc); // Pale yellow. return m_activeSelectionForegroundColor; }
IntSize RenderThemeChromiumDefault::sliderTickSize() const { if (useMockTheme()) return IntSize(1, 3); return IntSize(1, 6); }
int RenderThemeChromiumDefault::sliderTickOffsetFromTrackCenter() const { if (useMockTheme()) return 11; return -16; }
int LayoutThemeDefault::sliderTickOffsetFromTrackCenter() const { if (useMockTheme()) return 11; return -16; }
IntSize LayoutThemeDefault::sliderTickSize() const { if (useMockTheme()) return IntSize(1, 3); return IntSize(1, 6); }
Color LayoutThemeDefault::platformInactiveSelectionForegroundColor() const { if (useMockTheme()) return Color::white; return m_inactiveSelectionForegroundColor; }
Color LayoutThemeDefault::platformActiveSelectionForegroundColor() const { if (useMockTheme()) return Color(0xff, 0xff, 0xcc); // Pale yellow. return m_activeSelectionForegroundColor; }
Color LayoutThemeDefault::platformInactiveSelectionBackgroundColor() const { if (useMockTheme()) return Color(0x99, 0x99, 0x99); // Medium gray. return m_inactiveSelectionBackgroundColor; }
Color LayoutThemeDefault::platformActiveSelectionBackgroundColor() const { if (useMockTheme()) return Color(0x00, 0x00, 0xff); // Royal blue. return m_activeSelectionBackgroundColor; }
Color RenderThemeChromiumDefault::platformInactiveSelectionForegroundColor() const { if (useMockTheme()) return Color::white; return m_inactiveSelectionForegroundColor; }
Color RenderThemeChromiumDefault::platformActiveSelectionBackgroundColor() const { if (useMockTheme()) return Color(0x00, 0x00, 0xff); // Royal blue. return m_activeSelectionBackgroundColor; }