本文整理汇总了C++中PaintInfo::context方法的典型用法代码示例。如果您正苦于以下问题:C++ PaintInfo::context方法的具体用法?C++ PaintInfo::context怎么用?C++ PaintInfo::context使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PaintInfo
的用法示例。
在下文中一共展示了PaintInfo::context方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: paintContents
void RenderWidget::paintContents(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
{
IntPoint contentPaintOffset = roundedIntPoint(paintOffset + location() + contentBoxRect().location());
// Tell the widget to paint now. This is the only time the widget is allowed
// to paint itself. That way it will composite properly with z-indexed layers.
LayoutRect paintRect = paintInfo.rect;
IntPoint widgetLocation = m_widget->frameRect().location();
IntSize widgetPaintOffset = contentPaintOffset - widgetLocation;
// When painting widgets into compositing layers, tx and ty are relative to the enclosing compositing layer,
// not the root. In this case, shift the CTM and adjust the paintRect to be root-relative to fix plug-in drawing.
if (!widgetPaintOffset.isZero()) {
paintInfo.context().translate(widgetPaintOffset);
paintRect.move(-widgetPaintOffset);
}
// FIXME: Remove repaintrect encolsing/integral snapping when RenderWidget becomes device pixel snapped.
m_widget->paint(paintInfo.context(), snappedIntRect(paintRect));
if (!widgetPaintOffset.isZero())
paintInfo.context().translate(-widgetPaintOffset);
if (is<FrameView>(*m_widget)) {
FrameView& frameView = downcast<FrameView>(*m_widget);
bool runOverlapTests = !frameView.useSlowRepaintsIfNotOverlapped();
if (paintInfo.overlapTestRequests && runOverlapTests) {
ASSERT(!paintInfo.overlapTestRequests->contains(this));
paintInfo.overlapTestRequests->set(this, m_widget->frameRect());
}
}
}
示例2: paintSelectionBackground
void SVGInlineTextBox::paintSelectionBackground(PaintInfo& paintInfo)
{
ASSERT(paintInfo.shouldPaintWithinRoot(renderer()));
ASSERT(paintInfo.phase == PaintPhaseForeground || paintInfo.phase == PaintPhaseSelection);
ASSERT(truncation() == cNoTruncation);
if (renderer().style().visibility() != VISIBLE)
return;
auto& parentRenderer = parent()->renderer();
ASSERT(!parentRenderer.document().printing());
// Determine whether or not we're selected.
bool paintSelectedTextOnly = paintInfo.phase == PaintPhaseSelection;
bool hasSelection = selectionState() != RenderObject::SelectionNone;
if (!hasSelection || paintSelectedTextOnly)
return;
Color backgroundColor = renderer().selectionBackgroundColor();
if (!backgroundColor.isValid() || !backgroundColor.alpha())
return;
if (!textShouldBePainted(renderer()))
return;
RenderStyle& style = parentRenderer.style();
int startPosition;
int endPosition;
std::tie(startPosition, endPosition) = selectionStartEnd();
int fragmentStartPosition = 0;
int fragmentEndPosition = 0;
AffineTransform fragmentTransform;
unsigned textFragmentsSize = m_textFragments.size();
for (unsigned i = 0; i < textFragmentsSize; ++i) {
SVGTextFragment& fragment = m_textFragments.at(i);
ASSERT(!m_paintingResource);
fragmentStartPosition = startPosition;
fragmentEndPosition = endPosition;
if (!mapStartEndPositionsIntoFragmentCoordinates(fragment, fragmentStartPosition, fragmentEndPosition))
continue;
GraphicsContextStateSaver stateSaver(paintInfo.context());
fragment.buildFragmentTransform(fragmentTransform);
if (!fragmentTransform.isIdentity())
paintInfo.context().concatCTM(fragmentTransform);
paintInfo.context().setFillColor(backgroundColor);
paintInfo.context().fillRect(selectionRectForTextFragment(fragment, fragmentStartPosition, fragmentEndPosition, &style), backgroundColor);
m_paintingResourceMode = ApplyToDefaultMode;
}
ASSERT(!m_paintingResource);
}
示例3: paintFlow
void paintFlow(const RenderBlockFlow& flow, const Layout& layout, PaintInfo& paintInfo, const LayoutPoint& paintOffset)
{
if (paintInfo.phase != PaintPhaseForeground)
return;
RenderStyle& style = flow.style();
if (style.visibility() != VISIBLE)
return;
bool debugBordersEnabled = flow.frame().settings().simpleLineLayoutDebugBordersEnabled();
TextPainter textPainter(paintInfo.context());
textPainter.setFont(style.fontCascade());
textPainter.setTextPaintStyle(computeTextPaintStyle(flow.frame(), style, paintInfo));
Optional<TextDecorationPainter> textDecorationPainter;
if (style.textDecorationsInEffect() != TextDecorationNone) {
const RenderText* textRenderer = childrenOfType<RenderText>(flow).first();
if (textRenderer) {
textDecorationPainter = TextDecorationPainter(paintInfo.context(), style.textDecorationsInEffect(), *textRenderer, false);
textDecorationPainter->setFont(style.fontCascade());
textDecorationPainter->setBaseline(style.fontMetrics().ascent());
}
}
LayoutRect paintRect = paintInfo.rect;
paintRect.moveBy(-paintOffset);
auto resolver = runResolver(flow, layout);
float strokeOverflow = std::ceil(flow.style().textStrokeWidth());
float deviceScaleFactor = flow.document().deviceScaleFactor();
for (auto run : resolver.rangeForRect(paintRect)) {
if (run.start() == run.end())
continue;
FloatRect rect = run.rect();
FloatRect visualOverflowRect = rect;
visualOverflowRect.inflate(strokeOverflow);
if (paintRect.y() > visualOverflowRect.maxY() || paintRect.maxY() < visualOverflowRect.y())
continue;
TextRun textRun(run.text());
textRun.setTabSize(!style.collapseWhiteSpace(), style.tabSize());
// x position indicates the line offset from the rootbox. It's always 0 in case of simple line layout.
textRun.setXPos(0);
FloatPoint textOrigin = FloatPoint(rect.x() + paintOffset.x(), roundToDevicePixel(run.baselinePosition() + paintOffset.y(), deviceScaleFactor));
textPainter.paintText(textRun, textRun.length(), rect, textOrigin);
if (textDecorationPainter) {
textDecorationPainter->setWidth(rect.width());
textDecorationPainter->paintTextDecoration(textRun, textOrigin, rect.location() + paintOffset);
}
if (debugBordersEnabled)
paintDebugBorders(paintInfo.context(), LayoutRect(run.rect()), paintOffset);
}
}
示例4: getUnzoomedRectAndAdjustCurrentContext
// Utility to scale when the UI part are not scaled by wkDrawMediaUIPart
static FloatRect getUnzoomedRectAndAdjustCurrentContext(const RenderObject& o, const PaintInfo& paintInfo, const IntRect &originalRect)
{
float zoomLevel = o.style().effectiveZoom();
FloatRect unzoomedRect(originalRect);
if (zoomLevel != 1.0f) {
unzoomedRect.setWidth(unzoomedRect.width() / zoomLevel);
unzoomedRect.setHeight(unzoomedRect.height() / zoomLevel);
paintInfo.context().translate(unzoomedRect.x(), unzoomedRect.y());
paintInfo.context().scale(FloatSize(zoomLevel, zoomLevel));
paintInfo.context().translate(-unzoomedRect.x(), -unzoomedRect.y());
}
return unzoomedRect;
}
示例5: paint
void RenderWidget::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
{
if (!shouldPaint(paintInfo, paintOffset))
return;
LayoutPoint adjustedPaintOffset = paintOffset + location();
if (hasBoxDecorations() && (paintInfo.phase == PaintPhaseForeground || paintInfo.phase == PaintPhaseSelection))
paintBoxDecorations(paintInfo, adjustedPaintOffset);
if (paintInfo.phase == PaintPhaseMask) {
paintMask(paintInfo, adjustedPaintOffset);
return;
}
if ((paintInfo.phase == PaintPhaseOutline || paintInfo.phase == PaintPhaseSelfOutline) && hasOutline())
paintOutline(paintInfo, LayoutRect(adjustedPaintOffset, size()));
if (paintInfo.phase != PaintPhaseForeground)
return;
if (style().hasBorderRadius()) {
LayoutRect borderRect = LayoutRect(adjustedPaintOffset, size());
if (borderRect.isEmpty())
return;
// Push a clip if we have a border radius, since we want to round the foreground content that gets painted.
paintInfo.context().save();
FloatRoundedRect roundedInnerRect = FloatRoundedRect(style().getRoundedInnerBorderFor(borderRect,
paddingTop() + borderTop(), paddingBottom() + borderBottom(), paddingLeft() + borderLeft(), paddingRight() + borderRight(), true, true));
clipRoundedInnerRect(paintInfo.context(), borderRect, roundedInnerRect);
}
if (m_widget)
paintContents(paintInfo, paintOffset);
if (style().hasBorderRadius())
paintInfo.context().restore();
// Paint a partially transparent wash over selected widgets.
if (isSelected() && !document().printing()) {
// FIXME: selectionRect() is in absolute, not painting coordinates.
paintInfo.context().fillRect(snappedIntRect(selectionRect()), selectionBackgroundColor(), style().colorSpace());
}
if (hasLayer() && layer()->canResize())
layer()->paintResizer(paintInfo.context(), roundedIntPoint(adjustedPaintOffset), paintInfo.rect);
}
示例6: drawLine
// GraphicsContext::drawLine does not seem appropriate to draw menclose lines.
// To avoid unexpected behaviors and inconsistency with other notations, we just use strokePath.
static void drawLine(PaintInfo& info, const LayoutUnit& xStart, const LayoutUnit& yStart, const LayoutUnit& xEnd, const LayoutUnit& yEnd)
{
Path line;
line.moveTo(LayoutPoint(xStart, yStart));
line.addLineTo(LayoutPoint(xEnd, yEnd));
info.context().strokePath(line);
}
示例7: paint
void RenderSVGShape::paint(PaintInfo& paintInfo, const LayoutPoint&)
{
if (paintInfo.context().paintingDisabled() || paintInfo.phase != PaintPhaseForeground
|| style().visibility() == HIDDEN || isEmpty())
return;
FloatRect boundingBox = repaintRectInLocalCoordinates();
if (!SVGRenderSupport::paintInfoIntersectsRepaintRect(boundingBox, m_localTransform, paintInfo))
return;
PaintInfo childPaintInfo(paintInfo);
GraphicsContextStateSaver stateSaver(childPaintInfo.context());
childPaintInfo.applyTransform(m_localTransform);
if (childPaintInfo.phase == PaintPhaseForeground) {
SVGRenderingContext renderingContext(*this, childPaintInfo);
if (renderingContext.isRenderingPrepared()) {
const SVGRenderStyle& svgStyle = style().svgStyle();
if (svgStyle.shapeRendering() == SR_CRISPEDGES)
childPaintInfo.context().setShouldAntialias(false);
fillStrokeMarkers(childPaintInfo);
}
}
if (style().outlineWidth())
paintOutline(childPaintInfo, IntRect(boundingBox));
}
示例8: paintSnapshot
void RenderSnapshottedPlugIn::paintSnapshot(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
{
Image* image = m_snapshotResource->image().get();
if (!image || image->isNull())
return;
LayoutUnit cWidth = contentWidth();
LayoutUnit cHeight = contentHeight();
if (!cWidth || !cHeight)
return;
GraphicsContext& context = paintInfo.context();
LayoutSize contentSize(cWidth, cHeight);
LayoutPoint contentLocation = location() + paintOffset;
contentLocation.move(borderLeft() + paddingLeft(), borderTop() + paddingTop());
LayoutRect rect(contentLocation, contentSize);
IntRect alignedRect = snappedIntRect(rect);
if (alignedRect.width() <= 0 || alignedRect.height() <= 0)
return;
InterpolationQuality interpolation = chooseInterpolationQuality(context, *image, image, alignedRect.size());
ImageOrientationDescription orientationDescription(shouldRespectImageOrientation(), style().imageOrientation());
context.drawImage(*image, alignedRect, ImagePaintingOptions(orientationDescription, interpolation));
}
示例9: paintSnapshot
void RenderSnapshottedPlugIn::paintSnapshot(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
{
Image* image = m_snapshotResource->image().get();
if (!image || image->isNull())
return;
LayoutUnit cWidth = contentWidth();
LayoutUnit cHeight = contentHeight();
if (!cWidth || !cHeight)
return;
GraphicsContext& context = paintInfo.context();
LayoutSize contentSize(cWidth, cHeight);
LayoutPoint contentLocation = location() + paintOffset;
contentLocation.move(borderLeft() + paddingLeft(), borderTop() + paddingTop());
LayoutRect rect(contentLocation, contentSize);
IntRect alignedRect = snappedIntRect(rect);
if (alignedRect.width() <= 0 || alignedRect.height() <= 0)
return;
bool useLowQualityScaling = shouldPaintAtLowQuality(context, *image, image, alignedRect.size());
ImageOrientationDescription orientationDescription(shouldRespectImageOrientation());
#if ENABLE(CSS_IMAGE_ORIENTATION)
orientationDescription.setImageOrientationEnum(style().imageOrientation());
#endif
context.drawImage(*image, alignedRect, ImagePaintingOptions(orientationDescription, useLowQualityScaling));
}
示例10: paintDecorations
bool RenderTheme::paintDecorations(const RenderBox& box, const PaintInfo& paintInfo, const LayoutRect& rect)
{
if (paintInfo.context().paintingDisabled())
return false;
IntRect integralSnappedRect = snappedIntRect(rect);
FloatRect devicePixelSnappedRect = snapRectToDevicePixels(rect, box.document().deviceScaleFactor());
// Call the appropriate paint method based off the appearance value.
switch (box.style().appearance()) {
case MenulistButtonPart:
return paintMenuListButtonDecorations(box, paintInfo, devicePixelSnappedRect);
case TextFieldPart:
return paintTextFieldDecorations(box, paintInfo, devicePixelSnappedRect);
case TextAreaPart:
return paintTextAreaDecorations(box, paintInfo, devicePixelSnappedRect);
case CheckboxPart:
return paintCheckboxDecorations(box, paintInfo, integralSnappedRect);
case RadioPart:
return paintRadioDecorations(box, paintInfo, integralSnappedRect);
case PushButtonPart:
return paintPushButtonDecorations(box, paintInfo, integralSnappedRect);
case SquareButtonPart:
return paintSquareButtonDecorations(box, paintInfo, integralSnappedRect);
case ButtonPart:
return paintButtonDecorations(box, paintInfo, integralSnappedRect);
case MenulistPart:
return paintMenuListDecorations(box, paintInfo, integralSnappedRect);
case SliderThumbHorizontalPart:
case SliderThumbVerticalPart:
return paintSliderThumbDecorations(box, paintInfo, integralSnappedRect);
case SearchFieldPart:
return paintSearchFieldDecorations(box, paintInfo, integralSnappedRect);
#if ENABLE(METER_ELEMENT)
case MeterPart:
case RelevancyLevelIndicatorPart:
case ContinuousCapacityLevelIndicatorPart:
case DiscreteCapacityLevelIndicatorPart:
case RatingLevelIndicatorPart:
#endif
case ProgressBarPart:
case SliderHorizontalPart:
case SliderVerticalPart:
case ListboxPart:
case DefaultButtonPart:
case SearchFieldCancelButtonPart:
case SearchFieldDecorationPart:
case SearchFieldResultsDecorationPart:
case SearchFieldResultsButtonPart:
#if ENABLE(SERVICE_CONTROLS)
case ImageControlsButtonPart:
#endif
default:
break;
}
return false;
}
示例11: paintReplaced
void RenderEmbeddedObject::paintReplaced(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
{
if (!showsUnavailablePluginIndicator())
return;
if (paintInfo.phase == PaintPhaseSelection)
return;
GraphicsContext& context = paintInfo.context();
if (context.paintingDisabled())
return;
FloatRect contentRect;
FloatRect indicatorRect;
FloatRect replacementTextRect;
FloatRect arrowRect;
FontCascade font;
TextRun run(emptyString());
float textWidth;
if (!getReplacementTextGeometry(paintOffset, contentRect, indicatorRect, replacementTextRect, arrowRect, font, run, textWidth))
return;
Path background;
background.addRoundedRect(indicatorRect, FloatSize(replacementTextRoundedRectRadius, replacementTextRoundedRectRadius));
GraphicsContextStateSaver stateSaver(context);
context.clip(contentRect);
context.setFillColor(m_unavailablePluginIndicatorIsPressed ? replacementTextRoundedRectPressedColor() : replacementTextRoundedRectColor());
context.fillPath(background);
Path strokePath;
FloatRect strokeRect(indicatorRect);
strokeRect.inflate(1);
strokePath.addRoundedRect(strokeRect, FloatSize(replacementTextRoundedRectRadius + 1, replacementTextRoundedRectRadius + 1));
context.setStrokeColor(unavailablePluginBorderColor());
context.setStrokeThickness(2);
context.strokePath(strokePath);
const FontMetrics& fontMetrics = font.fontMetrics();
float labelX = roundf(replacementTextRect.location().x() + replacementTextRoundedRectLeftTextMargin);
float labelY = roundf(replacementTextRect.location().y() + (replacementTextRect.size().height() - fontMetrics.height()) / 2 + fontMetrics.ascent() + replacementTextRoundedRectTopTextMargin);
context.setFillColor(replacementTextColor());
context.drawBidiText(font, run, FloatPoint(labelX, labelY));
if (shouldUnavailablePluginMessageBeButton(document(), m_pluginUnavailabilityReason)) {
arrowRect.inflate(-replacementArrowCirclePadding);
context.beginTransparencyLayer(1.0);
context.setFillColor(replacementTextColor());
context.fillEllipse(arrowRect);
context.setCompositeOperation(CompositeClear);
drawReplacementArrow(context, arrowRect);
context.endTransparencyLayer();
}
}
示例12: fillStrokeMarkers
void RenderSVGShape::fillStrokeMarkers(PaintInfo& childPaintInfo)
{
auto paintOrder = style().svgStyle().paintTypesForPaintOrder();
for (unsigned i = 0; i < paintOrder.size(); ++i) {
switch (paintOrder.at(i)) {
case PaintTypeFill:
fillShape(style(), childPaintInfo.context());
break;
case PaintTypeStroke:
strokeShape(childPaintInfo.context());
break;
case PaintTypeMarkers:
if (!m_markerPositions.isEmpty())
drawMarkers(childPaintInfo);
break;
}
}
}
示例13: paintBoxDecorations
void RenderFieldset::paintBoxDecorations(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
{
if (!paintInfo.shouldPaintWithinRoot(*this))
return;
LayoutRect paintRect(paintOffset, size());
RenderBox* legend = findLegend();
if (!legend)
return RenderBlockFlow::paintBoxDecorations(paintInfo, paintOffset);
// FIXME: We need to work with "rl" and "bt" block flow directions. In those
// cases the legend is embedded in the right and bottom borders respectively.
// https://bugs.webkit.org/show_bug.cgi?id=47236
if (style().isHorizontalWritingMode()) {
LayoutUnit yOff = (legend->y() > 0) ? LayoutUnit() : (legend->height() - borderTop()) / 2;
paintRect.setHeight(paintRect.height() - yOff);
paintRect.setY(paintRect.y() + yOff);
} else {
LayoutUnit xOff = (legend->x() > 0) ? LayoutUnit() : (legend->width() - borderLeft()) / 2;
paintRect.setWidth(paintRect.width() - xOff);
paintRect.setX(paintRect.x() + xOff);
}
if (!boxShadowShouldBeAppliedToBackground(paintRect.location(), determineBackgroundBleedAvoidance(paintInfo.context())))
paintBoxShadow(paintInfo, paintRect, style(), Normal);
paintFillLayers(paintInfo, style().visitedDependentColor(CSSPropertyBackgroundColor), style().backgroundLayers(), paintRect);
paintBoxShadow(paintInfo, paintRect, style(), Inset);
if (!style().hasBorder())
return;
// Create a clipping region around the legend and paint the border as normal
GraphicsContext& graphicsContext = paintInfo.context();
GraphicsContextStateSaver stateSaver(graphicsContext);
// FIXME: We need to work with "rl" and "bt" block flow directions. In those
// cases the legend is embedded in the right and bottom borders respectively.
// https://bugs.webkit.org/show_bug.cgi?id=47236
LayoutRect clipRect;
if (style().isHorizontalWritingMode()) {
clipRect.setX(paintRect.x() + legend->x());
clipRect.setY(paintRect.y());
clipRect.setWidth(legend->width());
clipRect.setHeight(std::max<LayoutUnit>(style().borderTopWidth(), legend->height() - ((legend->height() - borderTop()) / 2)));
} else {
clipRect.setX(paintRect.x());
clipRect.setY(paintRect.y() + legend->y());
clipRect.setWidth(std::max<LayoutUnit>(style().borderLeftWidth(), legend->width()));
clipRect.setHeight(legend->height());
}
graphicsContext.clipOut(snapRectToDevicePixels(clipRect, document().deviceScaleFactor()));
paintBorder(paintInfo, paintRect, style());
}
示例14: paint
void RenderMathMLToken::paint(PaintInfo& info, const LayoutPoint& paintOffset)
{
RenderMathMLBlock::paint(info, paintOffset);
// FIXME: Instead of using DrawGlyph, we may consider using the more general TextPainter so that we can apply mathvariant to strings with an arbitrary number of characters and preserve advanced CSS effects (text-shadow, etc).
if (info.context().paintingDisabled() || info.phase != PaintPhaseForeground || style().visibility() != VISIBLE || !m_mathVariantCodePoint)
return;
auto mathVariantGlyph = style().fontCascade().glyphDataForCharacter(m_mathVariantCodePoint.value(), m_mathVariantIsMirrored);
if (!mathVariantGlyph.font)
return;
GraphicsContextStateSaver stateSaver(info.context());
info.context().setFillColor(style().visitedDependentColor(CSSPropertyColor));
GlyphBuffer buffer;
buffer.add(mathVariantGlyph.glyph, mathVariantGlyph.font, mathVariantGlyph.font->widthForGlyph(mathVariantGlyph.glyph));
LayoutUnit glyphAscent = static_cast<int>(lroundf(-mathVariantGlyph.font->boundsForGlyph(mathVariantGlyph.glyph).y()));
info.context().drawGlyphs(style().fontCascade(), *mathVariantGlyph.font, buffer, 0, 1, paintOffset + location() + LayoutPoint(0, glyphAscent));
}
示例15: paint
void RenderMathMLRoot::paint(PaintInfo& info, const LayoutPoint& paintOffset)
{
RenderMathMLRow::paint(info, paintOffset);
if (!firstChild() || info.context().paintingDisabled() || style().visibility() != VISIBLE || !isValid())
return;
// We draw the radical operator.
LayoutPoint radicalOperatorTopLeft = paintOffset + location();
LayoutUnit horizontalOffset = 0;
if (m_kind == RootWithIndex)
horizontalOffset = m_kernBeforeDegree + getIndex().logicalWidth() + m_kernAfterDegree;
radicalOperatorTopLeft.move(mirrorIfNeeded(horizontalOffset, m_radicalOperator.width()), m_radicalOperatorTop);
m_radicalOperator.paint(style(), info, radicalOperatorTopLeft);
// We draw the radical line.
if (!m_ruleThickness)
return;
GraphicsContextStateSaver stateSaver(info.context());
info.context().setStrokeThickness(m_ruleThickness);
info.context().setStrokeStyle(SolidStroke);
info.context().setStrokeColor(style().visitedDependentColor(CSSPropertyColor));
LayoutPoint ruleOffsetFrom = paintOffset + location() + LayoutPoint(0, m_radicalOperatorTop + m_ruleThickness / 2);
LayoutPoint ruleOffsetTo = ruleOffsetFrom;
horizontalOffset += m_radicalOperator.width();
ruleOffsetFrom.move(mirrorIfNeeded(horizontalOffset), 0);
horizontalOffset += m_baseWidth;
ruleOffsetTo.move(mirrorIfNeeded(horizontalOffset), 0);
info.context().drawLine(ruleOffsetFrom, ruleOffsetTo);
}