void RenderFileUploadControl::paintObject(PaintInfo& paintInfo, int tx, int ty) { if (style()->visibility() != VISIBLE) return; ASSERT(m_fileChooser); // Push a clip. GraphicsContextStateSaver stateSaver(*paintInfo.context, false); if (paintInfo.phase == PaintPhaseForeground || paintInfo.phase == PaintPhaseChildBlockBackgrounds) { IntRect clipRect(tx + borderLeft(), ty + borderTop(), width() - borderLeft() - borderRight(), height() - borderBottom() - borderTop() + buttonShadowHeight); if (clipRect.isEmpty()) return; stateSaver.save(); paintInfo.context->clip(clipRect); } if (paintInfo.phase == PaintPhaseForeground) { const String& displayedFilename = fileTextValue(); unsigned length = displayedFilename.length(); const UChar* string = displayedFilename.characters(); TextRun textRun(string, length, false, 0, 0, TextRun::AllowTrailingExpansion, style()->direction(), style()->unicodeBidi() == Override); // Determine where the filename should be placed int contentLeft = tx + borderLeft() + paddingLeft(); int buttonAndIconWidth = m_button->renderBox()->width() + afterButtonSpacing + (m_fileChooser->icon() ? iconWidth + iconFilenameSpacing : 0); int textX; if (style()->isLeftToRightDirection()) textX = contentLeft + buttonAndIconWidth; else textX = contentLeft + contentWidth() - buttonAndIconWidth - style()->font().width(textRun); // We want to match the button's baseline RenderButton* buttonRenderer = toRenderButton(m_button->renderer()); int textY = buttonRenderer->absoluteBoundingBoxRect().y() + buttonRenderer->marginTop() + buttonRenderer->borderTop() + buttonRenderer->paddingTop() + buttonRenderer->baselinePosition(AlphabeticBaseline, true, HorizontalLine, PositionOnContainingLine); paintInfo.context->setFillColor(style()->visitedDependentColor(CSSPropertyColor), style()->colorSpace()); // Draw the filename paintInfo.context->drawBidiText(style()->font(), textRun, IntPoint(textX, textY)); if (m_fileChooser->icon()) { // Determine where the icon should be placed int iconY = ty + borderTop() + paddingTop() + (contentHeight() - iconHeight) / 2; int iconX; if (style()->isLeftToRightDirection()) iconX = contentLeft + m_button->renderBox()->width() + afterButtonSpacing; else iconX = contentLeft + contentWidth() - m_button->renderBox()->width() - afterButtonSpacing - iconWidth; // Draw the file icon m_fileChooser->icon()->paint(paintInfo.context, IntRect(iconX, iconY, iconWidth, iconHeight)); } } // Paint the children. RenderBlock::paintObject(paintInfo, tx, ty); }
void RenderFileUploadControl::paintObject(PaintInfo& paintInfo, const LayoutPoint& paintOffset) { if (style()->visibility() != VISIBLE) return; // Push a clip. GraphicsContextStateSaver stateSaver(*paintInfo.context, false); if (paintInfo.phase == PaintPhaseForeground || paintInfo.phase == PaintPhaseChildBlockBackgrounds) { LayoutRect clipRect(paintOffset.x() + borderLeft(), paintOffset.y() + borderTop(), width() - borderLeft() - borderRight(), height() - borderBottom() - borderTop() + buttonShadowHeight); if (clipRect.isEmpty()) return; stateSaver.save(); paintInfo.context->clip(clipRect); } if (paintInfo.phase == PaintPhaseForeground) { const String& displayedFilename = fileTextValue(); const Font& font = style()->font(); TextRun textRun = constructTextRun(this, font, displayedFilename, style(), TextRun::AllowTrailingExpansion, RespectDirection | RespectDirectionOverride); textRun.disableRoundingHacks(); // Determine where the filename should be placed LayoutUnit contentLeft = paintOffset.x() + borderLeft() + paddingLeft(); HTMLInputElement* button = uploadButton(); if (!button) return; HTMLInputElement* input = static_cast<HTMLInputElement*>(node()); LayoutUnit buttonWidth = nodeWidth(button); LayoutUnit buttonAndIconWidth = buttonWidth + afterButtonSpacing + (input->icon() ? iconWidth + iconFilenameSpacing : 0); LayoutUnit textX; if (style()->isLeftToRightDirection()) textX = contentLeft + buttonAndIconWidth; else textX = contentLeft + contentWidth() - buttonAndIconWidth - font.width(textRun); // We want to match the button's baseline RenderButton* buttonRenderer = toRenderButton(button->renderer()); // FIXME: Make this work with transforms. LayoutUnit textY = buttonRenderer->absoluteBoundingBoxRectIgnoringTransforms().y() + buttonRenderer->baselinePosition(AlphabeticBaseline, true, HorizontalLine, PositionOnContainingLine); paintInfo.context->setFillColor(style()->visitedDependentColor(CSSPropertyColor), style()->colorSpace()); // Draw the filename paintInfo.context->drawBidiText(font, textRun, LayoutPoint(textX, textY)); if (input->icon()) { // Determine where the icon should be placed LayoutUnit iconY = paintOffset.y() + borderTop() + paddingTop() + (contentHeight() - iconHeight) / 2; LayoutUnit iconX; if (style()->isLeftToRightDirection()) iconX = contentLeft + buttonWidth + afterButtonSpacing; else iconX = contentLeft + contentWidth() - buttonWidth - afterButtonSpacing - iconWidth; // Draw the file icon input->icon()->paint(paintInfo.context, LayoutRect(iconX, iconY, iconWidth, iconHeight)); } } // Paint the children. RenderBlock::paintObject(paintInfo, paintOffset); }
void RenderFileUploadControl::paintObject(PaintInfo& paintInfo, int tx, int ty) { if (style()->visibility() != VISIBLE) return; // Push a clip. if (paintInfo.phase == PaintPhaseForeground || paintInfo.phase == PaintPhaseChildBlockBackgrounds) { IntRect clipRect(tx + borderLeft(), ty + borderTop(), width() - borderLeft() - borderRight(), height() - borderBottom() - borderTop() + buttonShadowHeight); if (clipRect.isEmpty()) return; paintInfo.context->save(); paintInfo.context->clip(clipRect); } if (paintInfo.phase == PaintPhaseForeground) { const String& displayedFilename = m_fileChooser->basenameForWidth(style()->font(), maxFilenameWidth()); unsigned length = displayedFilename.length(); const UChar* string = displayedFilename.characters(); TextStyle textStyle(0, 0, 0, style()->direction() == RTL, style()->unicodeBidi() == Override); TextRun textRun(string, length); // Determine where the filename should be placed int contentLeft = tx + borderLeft() + paddingLeft(); int buttonAndIconWidth = m_button->renderer()->width() + afterButtonSpacing + (m_fileChooser->icon() ? iconWidth + iconFilenameSpacing : 0); int textX; if (style()->direction() == LTR) textX = contentLeft + buttonAndIconWidth; else textX = contentLeft + contentWidth() - buttonAndIconWidth - style()->font().width(textRun); // We want to match the button's baseline RenderButton* buttonRenderer = static_cast<RenderButton*>(m_button->renderer()); int textY = buttonRenderer->absoluteBoundingBoxRect().y() + buttonRenderer->marginTop() + buttonRenderer->borderTop() + buttonRenderer->paddingTop() + buttonRenderer->baselinePosition(true, false); paintInfo.context->setFont(style()->font()); paintInfo.context->setFillColor(style()->color()); // Draw the filename paintInfo.context->drawBidiText(textRun, IntPoint(textX, textY), textStyle); if (m_fileChooser->icon()) { // Determine where the icon should be placed int iconY = ty + borderTop() + paddingTop() + (contentHeight() - iconHeight) / 2; int iconX; if (style()->direction() == LTR) iconX = contentLeft + m_button->renderer()->width() + afterButtonSpacing; else iconX = contentLeft + contentWidth() - m_button->renderer()->width() - afterButtonSpacing - iconWidth; // Draw the file icon m_fileChooser->icon()->paint(paintInfo.context, IntRect(iconX, iconY, iconWidth, iconHeight)); } } // Paint the children. RenderBlock::paintObject(paintInfo, tx, ty); // Pop the clip. if (paintInfo.phase == PaintPhaseForeground || paintInfo.phase == PaintPhaseChildBlockBackgrounds) paintInfo.context->restore(); }