bool RenderThemeChromiumSkia::paintSearchFieldCancelButton(RenderObject* cancelButtonObject, const PaintInfo& paintInfo, const IntRect& r) { // Get the renderer of <input> element. Node* input = cancelButtonObject->node()->shadowHost(); RenderObject* baseRenderer = input ? input->renderer() : cancelButtonObject; if (!baseRenderer->isBox()) return false; RenderBox* inputRenderBox = toRenderBox(baseRenderer); LayoutRect inputContentBox = inputRenderBox->contentBoxRect(); // Make sure the scaled button stays square and will fit in its parent's box. LayoutUnit cancelButtonSize = std::min(inputContentBox.width(), std::min<LayoutUnit>(inputContentBox.height(), r.height())); // Calculate cancel button's coordinates relative to the input element. // Center the button vertically. Round up though, so if it has to be one pixel off-center, it will // be one pixel closer to the bottom of the field. This tends to look better with the text. LayoutRect cancelButtonRect(cancelButtonObject->offsetFromAncestorContainer(inputRenderBox).width(), inputContentBox.y() + (inputContentBox.height() - cancelButtonSize + 1) / 2, cancelButtonSize, cancelButtonSize); IntRect paintingRect = convertToPaintingRect(inputRenderBox, cancelButtonObject, cancelButtonRect, r); static Image* cancelImage = Image::loadPlatformResource("searchCancel").leakRef(); static Image* cancelPressedImage = Image::loadPlatformResource("searchCancelPressed").leakRef(); paintInfo.context->drawImage(isPressed(cancelButtonObject) ? cancelPressedImage : cancelImage, cancelButtonObject->style()->colorSpace(), paintingRect); return false; }
bool ThemePainterDefault::paintSearchFieldCancelButton( const LayoutObject& cancelButtonObject, const PaintInfo& paintInfo, const IntRect& r) { // Get the layoutObject of <input> element. if (!cancelButtonObject.node()) return false; Node* input = cancelButtonObject.node()->ownerShadowHost(); const LayoutObject& baseLayoutObject = input ? *input->layoutObject() : cancelButtonObject; if (!baseLayoutObject.isBox()) return false; const LayoutBox& inputLayoutBox = toLayoutBox(baseLayoutObject); LayoutRect inputContentBox = inputLayoutBox.contentBoxRect(); // Make sure the scaled button stays square and will fit in its parent's box. LayoutUnit cancelButtonSize = std::min(inputContentBox.width(), std::min(inputContentBox.height(), LayoutUnit(r.height()))); // Calculate cancel button's coordinates relative to the input element. // Center the button vertically. Round up though, so if it has to be one // pixel off-center, it will be one pixel closer to the bottom of the field. // This tends to look better with the text. LayoutRect cancelButtonRect( cancelButtonObject.offsetFromAncestorContainer(&inputLayoutBox).width(), inputContentBox.y() + (inputContentBox.height() - cancelButtonSize + 1) / 2, cancelButtonSize, cancelButtonSize); IntRect paintingRect = convertToPaintingRect( inputLayoutBox, cancelButtonObject, cancelButtonRect, r); DEFINE_STATIC_REF(Image, cancelImage, (Image::loadPlatformResource("searchCancel"))); DEFINE_STATIC_REF(Image, cancelPressedImage, (Image::loadPlatformResource("searchCancelPressed"))); paintInfo.context.drawImage(LayoutTheme::isPressed(cancelButtonObject) ? cancelPressedImage : cancelImage, paintingRect); return false; }