Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(839)

Side by Side Diff: Source/core/rendering/RenderDetailsMarker.cpp

Issue 596563003: Move painting code from RenderDetailsMarker into DetailsMarkerPainter. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Merge Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/rendering/RenderDetailsMarker.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010, 2011 Nokia Corporation and/or its subsidiary(-ies) 2 * Copyright (C) 2010, 2011 Nokia Corporation and/or its subsidiary(-ies)
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details. 12 * Library General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU Library General Public License 14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to 15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA. 17 * Boston, MA 02110-1301, USA.
18 * 18 *
19 */ 19 */
20 20
21 #include "config.h" 21 #include "config.h"
22 #include "core/rendering/RenderDetailsMarker.h" 22 #include "core/rendering/RenderDetailsMarker.h"
23 23
24 #include "core/HTMLNames.h" 24 #include "core/HTMLNames.h"
25 #include "core/dom/Element.h" 25 #include "core/dom/Element.h"
26 #include "core/html/HTMLElement.h" 26 #include "core/html/HTMLElement.h"
27 #include "core/paint/DetailsMarkerPainter.h"
27 #include "core/rendering/PaintInfo.h" 28 #include "core/rendering/PaintInfo.h"
28 #include "platform/graphics/GraphicsContext.h"
29 29
30 namespace blink { 30 namespace blink {
31 31
32 using namespace HTMLNames; 32 using namespace HTMLNames;
33 33
34 RenderDetailsMarker::RenderDetailsMarker(Element* element) 34 RenderDetailsMarker::RenderDetailsMarker(Element* element)
35 : RenderBlockFlow(element) 35 : RenderBlockFlow(element)
36 { 36 {
37 } 37 }
38 38
39 static Path createPath(const FloatPoint* path)
40 {
41 Path result;
42 result.moveTo(FloatPoint(path[0].x(), path[0].y()));
43 for (int i = 1; i < 4; ++i)
44 result.addLineTo(FloatPoint(path[i].x(), path[i].y()));
45 return result;
46 }
47
48 static Path createDownArrowPath()
49 {
50 FloatPoint points[4] = { FloatPoint(0.0f, 0.07f), FloatPoint(0.5f, 0.93f), F loatPoint(1.0f, 0.07f), FloatPoint(0.0f, 0.07f) };
51 return createPath(points);
52 }
53
54 static Path createUpArrowPath()
55 {
56 FloatPoint points[4] = { FloatPoint(0.0f, 0.93f), FloatPoint(0.5f, 0.07f), F loatPoint(1.0f, 0.93f), FloatPoint(0.0f, 0.93f) };
57 return createPath(points);
58 }
59
60 static Path createLeftArrowPath()
61 {
62 FloatPoint points[4] = { FloatPoint(1.0f, 0.0f), FloatPoint(0.14f, 0.5f), Fl oatPoint(1.0f, 1.0f), FloatPoint(1.0f, 0.0f) };
63 return createPath(points);
64 }
65
66 static Path createRightArrowPath()
67 {
68 FloatPoint points[4] = { FloatPoint(0.0f, 0.0f), FloatPoint(0.86f, 0.5f), Fl oatPoint(0.0f, 1.0f), FloatPoint(0.0f, 0.0f) };
69 return createPath(points);
70 }
71
72 RenderDetailsMarker::Orientation RenderDetailsMarker::orientation() const 39 RenderDetailsMarker::Orientation RenderDetailsMarker::orientation() const
73 { 40 {
74 switch (style()->writingMode()) { 41 switch (style()->writingMode()) {
75 case TopToBottomWritingMode: 42 case TopToBottomWritingMode:
76 if (style()->isLeftToRightDirection()) 43 if (style()->isLeftToRightDirection())
77 return isOpen() ? Down : Right; 44 return isOpen() ? Down : Right;
78 return isOpen() ? Down : Left; 45 return isOpen() ? Down : Left;
79 case RightToLeftWritingMode: 46 case RightToLeftWritingMode:
80 if (style()->isLeftToRightDirection()) 47 if (style()->isLeftToRightDirection())
81 return isOpen() ? Left : Down; 48 return isOpen() ? Left : Down;
82 return isOpen() ? Left : Up; 49 return isOpen() ? Left : Up;
83 case LeftToRightWritingMode: 50 case LeftToRightWritingMode:
84 if (style()->isLeftToRightDirection()) 51 if (style()->isLeftToRightDirection())
85 return isOpen() ? Right : Down; 52 return isOpen() ? Right : Down;
86 return isOpen() ? Right : Up; 53 return isOpen() ? Right : Up;
87 case BottomToTopWritingMode: 54 case BottomToTopWritingMode:
88 if (style()->isLeftToRightDirection()) 55 if (style()->isLeftToRightDirection())
89 return isOpen() ? Up : Right; 56 return isOpen() ? Up : Right;
90 return isOpen() ? Up : Left; 57 return isOpen() ? Up : Left;
91 } 58 }
92 return Right; 59 return Right;
93 } 60 }
94 61
95 Path RenderDetailsMarker::getCanonicalPath() const
96 {
97 switch (orientation()) {
98 case Left: return createLeftArrowPath();
99 case Right: return createRightArrowPath();
100 case Up: return createUpArrowPath();
101 case Down: return createDownArrowPath();
102 }
103
104 return Path();
105 }
106
107 Path RenderDetailsMarker::getPath(const LayoutPoint& origin) const
108 {
109 Path result = getCanonicalPath();
110 result.transform(AffineTransform().scale(contentWidth().toFloat(), contentHe ight().toFloat()));
111 result.translate(FloatSize(origin.x().toFloat(), origin.y().toFloat()));
112 return result;
113 }
114
115 void RenderDetailsMarker::paint(PaintInfo& paintInfo, const LayoutPoint& paintOf fset) 62 void RenderDetailsMarker::paint(PaintInfo& paintInfo, const LayoutPoint& paintOf fset)
116 { 63 {
117 if (paintInfo.phase != PaintPhaseForeground || style()->visibility() != VISI BLE) { 64 DetailsMarkerPainter(*this).paint(paintInfo, paintOffset);
118 RenderBlock::paint(paintInfo, paintOffset);
119 return;
120 }
121
122 LayoutPoint boxOrigin(paintOffset + location());
123 LayoutRect overflowRect(visualOverflowRect());
124 overflowRect.moveBy(boxOrigin);
125
126 if (!paintInfo.rect.intersects(pixelSnappedIntRect(overflowRect)))
127 return;
128
129 const Color color(resolveColor(CSSPropertyColor));
130 paintInfo.context->setStrokeColor(color);
131 paintInfo.context->setStrokeStyle(SolidStroke);
132 paintInfo.context->setStrokeThickness(1.0f);
133 paintInfo.context->setFillColor(color);
134
135 boxOrigin.move(borderLeft() + paddingLeft(), borderTop() + paddingTop());
136 paintInfo.context->fillPath(getPath(boxOrigin));
137 } 65 }
138 66
139 bool RenderDetailsMarker::isOpen() const 67 bool RenderDetailsMarker::isOpen() const
140 { 68 {
141 for (RenderObject* renderer = parent(); renderer; renderer = renderer->paren t()) { 69 for (RenderObject* renderer = parent(); renderer; renderer = renderer->paren t()) {
142 if (!renderer->node()) 70 if (!renderer->node())
143 continue; 71 continue;
144 if (isHTMLDetailsElement(*renderer->node())) 72 if (isHTMLDetailsElement(*renderer->node()))
145 return !toElement(renderer->node())->getAttribute(openAttr).isNull() ; 73 return !toElement(renderer->node())->getAttribute(openAttr).isNull() ;
146 if (isHTMLInputElement(*renderer->node())) 74 if (isHTMLInputElement(*renderer->node()))
147 return true; 75 return true;
148 } 76 }
149 77
150 return false; 78 return false;
151 } 79 }
152 80
153 } 81 }
OLDNEW
« no previous file with comments | « Source/core/rendering/RenderDetailsMarker.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698