1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
6 #include "core/paint/DetailsMarkerPainter.h"
8 #include "core/paint/BlockPainter.h"
9 #include "core/rendering/PaintInfo.h"
10 #include "core/rendering/RenderDetailsMarker.h"
11 #include "platform/geometry/LayoutPoint.h"
12 #include "platform/graphics/Path.h"
16 void DetailsMarkerPainter::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
18 if (paintInfo.phase != PaintPhaseForeground || m_renderDetailsMarker.style()->visibility() != VISIBLE) {
19 BlockPainter(m_renderDetailsMarker).paint(paintInfo, paintOffset);
23 LayoutPoint boxOrigin(paintOffset + m_renderDetailsMarker.location());
24 LayoutRect overflowRect(m_renderDetailsMarker.visualOverflowRect());
25 overflowRect.moveBy(boxOrigin);
27 if (!paintInfo.rect.intersects(pixelSnappedIntRect(overflowRect)))
30 const Color color(m_renderDetailsMarker.resolveColor(CSSPropertyColor));
31 paintInfo.context->setStrokeColor(color);
32 paintInfo.context->setStrokeStyle(SolidStroke);
33 paintInfo.context->setStrokeThickness(1.0f);
34 paintInfo.context->setFillColor(color);
36 boxOrigin.move(m_renderDetailsMarker.borderLeft() + m_renderDetailsMarker.paddingLeft(), m_renderDetailsMarker.borderTop() + m_renderDetailsMarker.paddingTop());
37 paintInfo.context->fillPath(getPath(boxOrigin));
40 static Path createPath(const FloatPoint* path)
43 result.moveTo(FloatPoint(path[0].x(), path[0].y()));
44 for (int i = 1; i < 4; ++i)
45 result.addLineTo(FloatPoint(path[i].x(), path[i].y()));
49 static Path createDownArrowPath()
51 FloatPoint points[4] = { FloatPoint(0.0f, 0.07f), FloatPoint(0.5f, 0.93f), FloatPoint(1.0f, 0.07f), FloatPoint(0.0f, 0.07f) };
52 return createPath(points);
55 static Path createUpArrowPath()
57 FloatPoint points[4] = { FloatPoint(0.0f, 0.93f), FloatPoint(0.5f, 0.07f), FloatPoint(1.0f, 0.93f), FloatPoint(0.0f, 0.93f) };
58 return createPath(points);
61 static Path createLeftArrowPath()
63 FloatPoint points[4] = { FloatPoint(1.0f, 0.0f), FloatPoint(0.14f, 0.5f), FloatPoint(1.0f, 1.0f), FloatPoint(1.0f, 0.0f) };
64 return createPath(points);
67 static Path createRightArrowPath()
69 FloatPoint points[4] = { FloatPoint(0.0f, 0.0f), FloatPoint(0.86f, 0.5f), FloatPoint(0.0f, 1.0f), FloatPoint(0.0f, 0.0f) };
70 return createPath(points);
73 Path DetailsMarkerPainter::getCanonicalPath() const
75 switch (m_renderDetailsMarker.orientation()) {
76 case RenderDetailsMarker::Left: return createLeftArrowPath();
77 case RenderDetailsMarker::Right: return createRightArrowPath();
78 case RenderDetailsMarker::Up: return createUpArrowPath();
79 case RenderDetailsMarker::Down: return createDownArrowPath();
85 Path DetailsMarkerPainter::getPath(const LayoutPoint& origin) const
87 Path result = getCanonicalPath();
88 result.transform(AffineTransform().scale(m_renderDetailsMarker.contentWidth().toFloat(), m_renderDetailsMarker.contentHeight().toFloat()));
89 result.translate(FloatSize(origin.x().toFloat(), origin.y().toFloat()));