void GraphicsContext::drawFocusRing(const Color& color) { if (paintingDisabled()) return; float radius = (focusRingWidth() - 1) / 2.0f; int offset = radius + focusRingOffset(); CGColorRef colorRef = color.isValid() ? cgColor(color) : 0; CGMutablePathRef focusRingPath = CGPathCreateMutable(); const Vector<IntRect>& rects = focusRingRects(); unsigned rectCount = rects.size(); for (unsigned i = 0; i < rectCount; i++) CGPathAddRect(focusRingPath, 0, CGRectInset(rects[i], -offset, -offset)); CGContextRef context = platformContext(); CGContextSaveGState(context); CGContextBeginPath(context); CGContextAddPath(context, focusRingPath); wkDrawFocusRing(context, colorRef, radius); CGColorRelease(colorRef); CGPathRelease(focusRingPath); CGContextRestoreGState(context); }
void GraphicsContext::drawFocusRing(const Color& color) { if (paintingDisabled()) return; const Vector<IntRect>& rects = focusRingRects(); unsigned rectCount = rects.size(); if (0 == rectCount) return; SkRegion focusRingRegion; const SkScalar focusRingOutset = WebCoreFloatToSkScalar(0.5); for (unsigned i = 0; i < rectCount; i++) { SkIRect r = rects[i]; r.inset(-focusRingOutset, -focusRingOutset); focusRingRegion.op(r, SkRegion::kUnion_Op); } SkPath path; SkPaint paint; paint.setAntiAlias(true); paint.setStyle(SkPaint::kStroke_Style); paint.setColor(color.rgb()); paint.setStrokeWidth(focusRingOutset * 2); paint.setPathEffect(new SkCornerPathEffect(focusRingOutset * 2))->unref(); focusRingRegion.getBoundaryPath(&path); platformContext()->canvas()->drawPath(path, paint); }
void GraphicsContext::drawFocusRing(const Color& color) { if (paintingDisabled()) return; int radius = (focusRingWidth() - 1) / 2; int offset = radius + focusRingOffset(); const Vector<IntRect>& rects = focusRingRects(); unsigned rectCount = rects.size(); IntRect finalFocusRect; for (unsigned i = 0; i < rectCount; i++) { IntRect focusRect = rects[i]; focusRect.inflate(offset); finalFocusRect.unite(focusRect); } cairo_t* cr = m_data->cr; cairo_save(cr); // FIXME: These rects should be rounded cairo_rectangle(cr, finalFocusRect.x(), finalFocusRect.y(), finalFocusRect.width(), finalFocusRect.height()); // Force the alpha to 50%. This matches what the Mac does with outline rings. Color ringColor(color.red(), color.green(), color.blue(), 127); setColor(cr, ringColor); cairo_stroke(cr); cairo_restore(cr); }
IntRect GraphicsContext::focusRingBoundingRect() { IntRect result = IntRect(0, 0, 0, 0); const Vector<IntRect>& rects = focusRingRects(); unsigned rectCount = rects.size(); for (unsigned i = 0; i < rectCount; i++) result.unite(rects[i]); return result; }
void GraphicsContext::drawFocusRing(const Color& color) { if (paintingDisabled()) return; const Vector<IntRect>& rects = focusRingRects(); unsigned rectCount = rects.size(); cairo_t* cr = m_data->cr; cairo_save(cr); cairo_push_group(cr); cairo_new_path(cr); #if PLATFORM(GTK) GdkRegion* reg = gdk_region_new(); for (unsigned i = 0; i < rectCount; i++) { GdkRectangle rect = rects[i]; gdk_region_union_with_rect(reg, &rect); } gdk_cairo_region(cr, reg); gdk_region_destroy(reg); setColor(cr, color); cairo_set_line_width(cr, 2.0f); setPlatformStrokeStyle(DottedStroke); #else int radius = (focusRingWidth() - 1) / 2; for (unsigned i = 0; i < rectCount; i++) addPath(Path::createRoundedRectangle(rects[i], FloatSize(radius, radius))); // Force the alpha to 50%. This matches what the Mac does with outline rings. Color ringColor(color.red(), color.green(), color.blue(), 127); setColor(cr, ringColor); cairo_set_line_width(cr, focusRingWidth()); setPlatformStrokeStyle(SolidStroke); #endif cairo_set_operator(cr, CAIRO_OPERATOR_OVER); cairo_stroke_preserve(cr); cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); cairo_set_fill_rule(cr, CAIRO_FILL_RULE_WINDING); cairo_fill(cr); cairo_pop_group_to_source(cr); cairo_set_operator(cr, CAIRO_OPERATOR_OVER); cairo_paint(cr); cairo_restore(cr); }
void GraphicsContext::drawFocusRing(const Color& color) { if (paintingDisabled()) return; return; const Vector<IntRect>& rects = focusRingRects(); unsigned rectCount = rects.size(); QVector<QRect> qrects(rectCount); for (int i = 0; i < rectCount; ++i) qrects[i] = rects[i]; m_data->p().save(); m_data->p().setClipRect(m_data->focusRingClip); m_data->p().setPen(color); m_data->p().drawRects(qrects); m_data->p().restore(); }
void GraphicsContext::drawFocusRing(const Color& color) { if (paintingDisabled()) return; const Vector<IntRect>& rects = focusRingRects(); unsigned rectCount = rects.size(); if (rects.size() == 0) return; QPainter *p = m_data->p(); const bool antiAlias = p->testRenderHint(QPainter::Antialiasing); p->setRenderHint(QPainter::Antialiasing, m_data->antiAliasingForRectsAndLines); const QPen oldPen = p->pen(); const QBrush oldBrush = p->brush(); QPen nPen = p->pen(); nPen.setColor(color); p->setBrush(Qt::NoBrush); nPen.setStyle(Qt::DotLine); p->setPen(nPen); #if 0 // FIXME How do we do a bounding outline with Qt? QPainterPath path; for (int i = 0; i < rectCount; ++i) path.addRect(QRectF(rects[i])); QPainterPathStroker stroker; QPainterPath newPath = stroker.createStroke(path); p->strokePath(newPath, nPen); #else for (int i = 0; i < rectCount; ++i) p->drawRect(QRectF(rects[i])); #endif p->setPen(oldPen); p->setBrush(oldBrush); p->setRenderHint(QPainter::Antialiasing, antiAlias); }