• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "config.h"
6 #include "core/paint/DetailsMarkerPainter.h"
7 
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"
13 
14 namespace blink {
15 
paint(PaintInfo & paintInfo,const LayoutPoint & paintOffset)16 void DetailsMarkerPainter::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
17 {
18     if (paintInfo.phase != PaintPhaseForeground || m_renderDetailsMarker.style()->visibility() != VISIBLE) {
19         BlockPainter(m_renderDetailsMarker).paint(paintInfo, paintOffset);
20         return;
21     }
22 
23     LayoutPoint boxOrigin(paintOffset + m_renderDetailsMarker.location());
24     LayoutRect overflowRect(m_renderDetailsMarker.visualOverflowRect());
25     overflowRect.moveBy(boxOrigin);
26 
27     if (!paintInfo.rect.intersects(pixelSnappedIntRect(overflowRect)))
28         return;
29 
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);
35 
36     boxOrigin.move(m_renderDetailsMarker.borderLeft() + m_renderDetailsMarker.paddingLeft(), m_renderDetailsMarker.borderTop() + m_renderDetailsMarker.paddingTop());
37     paintInfo.context->fillPath(getPath(boxOrigin));
38 }
39 
createPath(const FloatPoint * path)40 static Path createPath(const FloatPoint* path)
41 {
42     Path result;
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()));
46     return result;
47 }
48 
createDownArrowPath()49 static Path createDownArrowPath()
50 {
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);
53 }
54 
createUpArrowPath()55 static Path createUpArrowPath()
56 {
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);
59 }
60 
createLeftArrowPath()61 static Path createLeftArrowPath()
62 {
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);
65 }
66 
createRightArrowPath()67 static Path createRightArrowPath()
68 {
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);
71 }
72 
getCanonicalPath() const73 Path DetailsMarkerPainter::getCanonicalPath() const
74 {
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();
80     }
81 
82     return Path();
83 }
84 
getPath(const LayoutPoint & origin) const85 Path DetailsMarkerPainter::getPath(const LayoutPoint& origin) const
86 {
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()));
90     return result;
91 }
92 
93 } // namespace paint
94