|
Lines 21-31
a/Source/WebCore/rendering/RenderDetailsMarker.cpp_sec1
|
| 21 |
#include "config.h" |
21 |
#include "config.h" |
| 22 |
#include "RenderDetailsMarker.h" |
22 |
#include "RenderDetailsMarker.h" |
| 23 |
|
23 |
|
|
|
24 |
#include "GraphicsContext.h" |
| 25 |
#include "HTMLNames.h" |
| 26 |
#include "PaintInfo.h" |
| 27 |
#include "RenderDetails.h" |
| 28 |
#include "RenderSummary.h" |
| 29 |
|
| 24 |
namespace WebCore { |
30 |
namespace WebCore { |
| 25 |
|
31 |
|
| 26 |
RenderDetailsMarker::RenderDetailsMarker(Node* element) |
32 |
using namespace HTMLNames; |
| 27 |
: RenderBlock(element) |
33 |
|
|
|
34 |
RenderDetailsMarker::RenderDetailsMarker(RenderSummary* item) |
| 35 |
: RenderBox(item->document()) |
| 36 |
, m_summary(item) |
| 28 |
{ |
37 |
{ |
|
|
38 |
setInline(true); |
| 39 |
setReplaced(true); |
| 40 |
} |
| 41 |
|
| 42 |
int RenderDetailsMarker::lineHeight(bool firstLine, LineDirectionMode direction, LinePositionMode) const |
| 43 |
{ |
| 44 |
return m_summary->lineHeight(firstLine, direction, PositionOfInteriorLineBoxes); |
| 45 |
} |
| 46 |
|
| 47 |
int RenderDetailsMarker::baselinePosition(FontBaseline baselineType, bool firstLine, LineDirectionMode direction, LinePositionMode) const |
| 48 |
{ |
| 49 |
return m_summary->baselinePosition(baselineType, firstLine, direction, PositionOfInteriorLineBoxes); |
| 50 |
} |
| 51 |
|
| 52 |
void RenderDetailsMarker::computePreferredLogicalWidths() |
| 53 |
{ |
| 54 |
ASSERT(preferredLogicalWidthsDirty()); |
| 55 |
|
| 56 |
m_minPreferredLogicalWidth = 2 * style()->fontMetrics().ascent() / 3; |
| 57 |
m_maxPreferredLogicalWidth = m_minPreferredLogicalWidth; |
| 58 |
|
| 59 |
setPreferredLogicalWidthsDirty(false); |
| 60 |
} |
| 61 |
|
| 62 |
void RenderDetailsMarker::layout() |
| 63 |
{ |
| 64 |
ASSERT(needsLayout()); |
| 65 |
|
| 66 |
setLogicalWidth(minPreferredLogicalWidth()); |
| 67 |
setLogicalHeight(style()->fontMetrics().height()); |
| 68 |
|
| 69 |
setMarginStart(0); |
| 70 |
setMarginEnd(style()->fontMetrics().ascent() - minPreferredLogicalWidth() + 1); |
| 71 |
|
| 72 |
setNeedsLayout(false); |
| 73 |
} |
| 74 |
|
| 75 |
IntRect RenderDetailsMarker::getRelativeMarkerRect() const |
| 76 |
{ |
| 77 |
IntRect relativeRect; |
| 78 |
|
| 79 |
int bulletWidth = minPreferredLogicalWidth(); |
| 80 |
relativeRect = IntRect((logicalWidth() - bulletWidth) / 2, (logicalHeight() - bulletWidth) / 2, bulletWidth, bulletWidth); |
| 81 |
|
| 82 |
if (!style()->isHorizontalWritingMode()) { |
| 83 |
relativeRect = relativeRect.transposedRect(); |
| 84 |
relativeRect.setX(width() - relativeRect.x() - relativeRect.width()); |
| 85 |
} |
| 86 |
|
| 87 |
return relativeRect; |
| 88 |
} |
| 89 |
|
| 90 |
bool RenderDetailsMarker::isOpen() const |
| 91 |
{ |
| 92 |
if (!parent() || !parent()->isSummary() || !parent()->containingBlock() || !parent()->containingBlock()->isDetails()) |
| 93 |
return false; |
| 94 |
|
| 95 |
return static_cast<RenderDetails*>(parent()->containingBlock())->isOpen(); |
| 96 |
} |
| 97 |
|
| 98 |
namespace ArrowPath { |
| 99 |
|
| 100 |
enum Direction { right, left, up, down }; |
| 101 |
|
| 102 |
static Path createPath(const FloatPoint* path) |
| 103 |
{ |
| 104 |
Path result; |
| 105 |
result.moveTo(FloatPoint(path[0].x(), path[0].y())); |
| 106 |
for (int i = 1; i < 4; ++i) |
| 107 |
result.addLineTo(FloatPoint(path[i].x(), path[i].y())); |
| 108 |
return result; |
| 109 |
} |
| 110 |
|
| 111 |
static Path createPath(Direction direction) |
| 112 |
{ |
| 113 |
switch (direction) { |
| 114 |
case right: { |
| 115 |
FloatPoint points[4] = { FloatPoint(0.0, 0.0), FloatPoint(0.86, 0.5), FloatPoint(0.0, 1.0), FloatPoint(0.0, 0.0) }; |
| 116 |
return createPath(points); |
| 117 |
} |
| 118 |
case left: { |
| 119 |
FloatPoint points[4] = { FloatPoint(1.0, 0.0), FloatPoint(0.14, 0.5), FloatPoint(1.0, 1.0), FloatPoint(1.0, 0.0) }; |
| 120 |
return createPath(points); |
| 121 |
} |
| 122 |
case up: { |
| 123 |
FloatPoint points[4] = { FloatPoint(0.0, 0.93), FloatPoint(0.5, 0.07), FloatPoint(1.0, 0.93), FloatPoint(0.0, 0.93) }; |
| 124 |
return createPath(points); |
| 125 |
} |
| 126 |
case down: { |
| 127 |
FloatPoint points[4] = { FloatPoint(0.0, 0.07), FloatPoint(0.5, 0.93), FloatPoint(1.0, 0.07), FloatPoint(0.0, 0.07) }; |
| 128 |
return createPath(points); |
| 129 |
} |
| 130 |
} |
| 131 |
|
| 132 |
return Path(); |
| 133 |
} |
| 134 |
}; |
| 135 |
|
| 136 |
static Path getCanonicalPath(bool isOpen, WritingMode writingMode, TextDirection textDirection) |
| 137 |
{ |
| 138 |
static Path down = ArrowPath::createPath(ArrowPath::down); |
| 139 |
static Path up = ArrowPath::createPath(ArrowPath::up); |
| 140 |
static Path left = ArrowPath::createPath(ArrowPath::left); |
| 141 |
static Path right = ArrowPath::createPath(ArrowPath::right); |
| 142 |
|
| 143 |
switch (writingMode) { |
| 144 |
case TopToBottomWritingMode: |
| 145 |
switch (textDirection) { |
| 146 |
case LTR: return isOpen ? down : right; |
| 147 |
case RTL: return isOpen ? down : left; |
| 148 |
} |
| 149 |
case RightToLeftWritingMode: |
| 150 |
switch (textDirection) { |
| 151 |
case LTR: return isOpen ? left : down; |
| 152 |
case RTL: return isOpen ? left : up; |
| 153 |
} |
| 154 |
case LeftToRightWritingMode: |
| 155 |
switch (textDirection) { |
| 156 |
case LTR: return isOpen ? right : down; |
| 157 |
case RTL: return isOpen ? right : up; |
| 158 |
} |
| 159 |
case BottomToTopWritingMode: |
| 160 |
switch (textDirection) { |
| 161 |
case LTR: return isOpen ? up : right; |
| 162 |
case RTL: return isOpen ? up : left; |
| 163 |
} |
| 164 |
} |
| 165 |
|
| 166 |
return Path(); |
| 167 |
} |
| 168 |
|
| 169 |
Path RenderDetailsMarker::getPath(const IntPoint& origin) const |
| 170 |
{ |
| 171 |
IntRect rect = getRelativeMarkerRect(); |
| 172 |
Path result = getCanonicalPath(isOpen(), style()->writingMode(), style()->direction()); |
| 173 |
result.transform(AffineTransform().scale(rect.width())); |
| 174 |
result.translate(FloatSize(origin.x() + rect.x(), origin.y() + rect.y())); |
| 175 |
return result; |
| 176 |
} |
| 177 |
|
| 178 |
void RenderDetailsMarker::paint(PaintInfo& paintInfo, int tx, int ty) |
| 179 |
{ |
| 180 |
if (paintInfo.phase != PaintPhaseForeground || style()->visibility() != VISIBLE) |
| 181 |
return; |
| 182 |
|
| 183 |
IntPoint boxOrigin(tx + x(), ty + y()); |
| 184 |
IntRect overflowRect(visualOverflowRect()); |
| 185 |
overflowRect.move(boxOrigin.x(), boxOrigin.y()); |
| 186 |
overflowRect.inflate(maximalOutlineSize(paintInfo.phase)); |
| 187 |
|
| 188 |
if (!paintInfo.rect.intersects(overflowRect)) |
| 189 |
return; |
| 190 |
|
| 191 |
const Color color(style()->visitedDependentColor(CSSPropertyColor)); |
| 192 |
paintInfo.context->setStrokeColor(color, style()->colorSpace()); |
| 193 |
paintInfo.context->setStrokeStyle(SolidStroke); |
| 194 |
paintInfo.context->setStrokeThickness(1.0f); |
| 195 |
paintInfo.context->setFillColor(color, style()->colorSpace()); |
| 196 |
|
| 197 |
paintInfo.context->fillPath(getPath(boxOrigin)); |
| 29 |
} |
198 |
} |
| 30 |
|
199 |
|
| 31 |
} |
200 |
} |