OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
4 * Copyright (C) 2004, 2005, 2006, 2009, 2011 Apple Inc. All rights reserved. | 4 * Copyright (C) 2004, 2005, 2006, 2009, 2011 Apple Inc. All rights reserved. |
5 * | 5 * |
6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
10 * | 10 * |
(...skipping 30 matching lines...) Expand all Loading... |
41 { | 41 { |
42 return LayoutUnit(value).toFloat(); | 42 return LayoutUnit(value).toFloat(); |
43 } | 43 } |
44 | 44 |
45 } | 45 } |
46 | 46 |
47 using namespace HTMLNames; | 47 using namespace HTMLNames; |
48 | 48 |
49 inline HTMLAreaElement::HTMLAreaElement(Document& document) | 49 inline HTMLAreaElement::HTMLAreaElement(Document& document) |
50 : HTMLAnchorElement(areaTag, document) | 50 : HTMLAnchorElement(areaTag, document) |
51 , m_lastSize(-1, -1) | |
52 , m_shape(Rect) | 51 , m_shape(Rect) |
53 { | 52 { |
54 } | 53 } |
55 | 54 |
56 // An explicit empty destructor should be in HTMLAreaElement.cpp, because | 55 // An explicit empty destructor should be in HTMLAreaElement.cpp, because |
57 // if an implicit destructor is used or an empty destructor is defined in | 56 // if an implicit destructor is used or an empty destructor is defined in |
58 // HTMLAreaElement.h, when including HTMLAreaElement.h, msvc tries to expand | 57 // HTMLAreaElement.h, when including HTMLAreaElement.h, msvc tries to expand |
59 // the destructor and causes a compile error because of lack of blink::Path | 58 // the destructor and causes a compile error because of lack of blink::Path |
60 // definition. | 59 // definition. |
61 HTMLAreaElement::~HTMLAreaElement() | 60 HTMLAreaElement::~HTMLAreaElement() |
62 { | 61 { |
63 } | 62 } |
64 | 63 |
65 DEFINE_NODE_FACTORY(HTMLAreaElement) | 64 DEFINE_NODE_FACTORY(HTMLAreaElement) |
66 | 65 |
67 void HTMLAreaElement::parseAttribute(const QualifiedName& name, const AtomicStri
ng& oldValue, const AtomicString& value) | 66 void HTMLAreaElement::parseAttribute(const QualifiedName& name, const AtomicStri
ng& oldValue, const AtomicString& value) |
68 { | 67 { |
69 if (name == shapeAttr) { | 68 if (name == shapeAttr) { |
70 if (equalIgnoringASCIICase(value, "default")) { | 69 if (equalIgnoringASCIICase(value, "default")) { |
71 m_shape = Default; | 70 m_shape = Default; |
72 } else if (equalIgnoringASCIICase(value, "circle") || equalIgnoringASCII
Case(value, "circ")) { | 71 } else if (equalIgnoringASCIICase(value, "circle") || equalIgnoringASCII
Case(value, "circ")) { |
73 m_shape = Circle; | 72 m_shape = Circle; |
74 } else if (equalIgnoringASCIICase(value, "polygon") || equalIgnoringASCI
ICase(value, "poly")) { | 73 } else if (equalIgnoringASCIICase(value, "polygon") || equalIgnoringASCI
ICase(value, "poly")) { |
75 m_shape = Poly; | 74 m_shape = Poly; |
76 } else { | 75 } else { |
77 // The missing (and implicitly invalid) value default for the | 76 // The missing (and implicitly invalid) value default for the |
78 // 'shape' attribute is 'rect'. | 77 // 'shape' attribute is 'rect'. |
79 m_shape = Rect; | 78 m_shape = Rect; |
80 } | 79 } |
81 invalidateCachedRegion(); | 80 invalidateCachedPath(); |
82 } else if (name == coordsAttr) { | 81 } else if (name == coordsAttr) { |
83 m_coords = parseHTMLListOfFloatingPointNumbers(value.getString()); | 82 m_coords = parseHTMLListOfFloatingPointNumbers(value.getString()); |
84 invalidateCachedRegion(); | 83 invalidateCachedPath(); |
85 } else if (name == altAttr || name == accesskeyAttr) { | 84 } else if (name == altAttr || name == accesskeyAttr) { |
86 // Do nothing. | 85 // Do nothing. |
87 } else { | 86 } else { |
88 HTMLAnchorElement::parseAttribute(name, oldValue, value); | 87 HTMLAnchorElement::parseAttribute(name, oldValue, value); |
89 } | 88 } |
90 } | 89 } |
91 | 90 |
92 void HTMLAreaElement::invalidateCachedRegion() | 91 void HTMLAreaElement::invalidateCachedPath() |
93 { | 92 { |
94 m_lastSize = LayoutSize(-1, -1); | 93 m_path = nullptr; |
95 } | 94 } |
96 | 95 |
97 bool HTMLAreaElement::pointInArea(LayoutPoint location, const LayoutSize& contai
nerSize) | 96 bool HTMLAreaElement::pointInArea(const LayoutPoint& location) |
98 { | 97 { |
99 if (m_lastSize != containerSize) { | 98 return getPath().contains(FloatPoint(location)); |
100 m_region = adoptPtr(new Path(getRegion(containerSize))); | |
101 m_lastSize = containerSize; | |
102 } | |
103 | |
104 return m_region->contains(FloatPoint(location)); | |
105 } | 99 } |
106 | 100 |
107 Path HTMLAreaElement::computePath(const LayoutObject* obj) const | 101 LayoutRect HTMLAreaElement::computeAbsoluteRect() const |
108 { | 102 { |
109 if (!obj) | 103 LayoutObject* object = imageElementLayoutObject(); |
110 return Path(); | 104 if (!object) |
| 105 return LayoutRect(); |
111 | 106 |
112 // FIXME: This doesn't work correctly with transforms. | 107 // FIXME: This doesn't work correctly with transforms. |
113 FloatPoint absPos = obj->localToAbsolute(); | 108 FloatPoint absPos = object->localToAbsolute(); |
114 | 109 |
115 // Default should default to the size of the containing object. | 110 Path p = getPath(); |
116 LayoutSize size = m_lastSize; | 111 float zoomFactor = object->styleRef().effectiveZoom(); |
117 if (m_shape == Default) | |
118 size = obj->absoluteClippedOverflowRect().size(); | |
119 | |
120 Path p = getRegion(size); | |
121 float zoomFactor = obj->style()->effectiveZoom(); | |
122 if (zoomFactor != 1.0f) { | 112 if (zoomFactor != 1.0f) { |
123 AffineTransform zoomTransform; | 113 AffineTransform zoomTransform; |
124 zoomTransform.scale(zoomFactor); | 114 zoomTransform.scale(zoomFactor); |
125 p.transform(zoomTransform); | 115 p.transform(zoomTransform); |
126 } | 116 } |
127 | 117 |
128 p.translate(toFloatSize(absPos)); | 118 p.translate(toFloatSize(absPos)); |
129 return p; | 119 return enclosingLayoutRect(p.boundingRect()); |
130 } | 120 } |
131 | 121 |
132 LayoutRect HTMLAreaElement::computeRect(const LayoutObject* obj) const | 122 const Path& HTMLAreaElement::getPath() const |
133 { | 123 { |
134 return enclosingLayoutRect(computePath(obj).boundingRect()); | 124 if (m_path) |
135 } | 125 return *m_path; |
136 | 126 |
137 Path HTMLAreaElement::getRegion(const LayoutSize& size) const | 127 m_path = adoptPtr(new Path); |
138 { | 128 |
139 if (m_coords.isEmpty() && m_shape != Default) | 129 if (m_coords.isEmpty() && m_shape != Default) |
140 return Path(); | 130 return *m_path; |
141 | 131 |
142 Path path; | |
143 switch (m_shape) { | 132 switch (m_shape) { |
144 case Poly: | 133 case Poly: |
145 if (m_coords.size() >= 6) { | 134 if (m_coords.size() >= 6) { |
146 int numPoints = m_coords.size() / 2; | 135 int numPoints = m_coords.size() / 2; |
147 path.moveTo(FloatPoint(clampCoordinate(m_coords[0]), clampCoordinate
(m_coords[1]))); | 136 m_path->moveTo(FloatPoint(clampCoordinate(m_coords[0]), clampCoordin
ate(m_coords[1]))); |
148 for (int i = 1; i < numPoints; ++i) | 137 for (int i = 1; i < numPoints; ++i) |
149 path.addLineTo(FloatPoint(clampCoordinate(m_coords[i * 2]), clam
pCoordinate(m_coords[i * 2 + 1]))); | 138 m_path->addLineTo(FloatPoint(clampCoordinate(m_coords[i * 2]), c
lampCoordinate(m_coords[i * 2 + 1]))); |
150 path.closeSubpath(); | 139 m_path->closeSubpath(); |
151 path.setWindRule(RULE_EVENODD); | 140 m_path->setWindRule(RULE_EVENODD); |
152 } | 141 } |
153 break; | 142 break; |
154 case Circle: | 143 case Circle: |
155 if (m_coords.size() >= 3 && m_coords[2] > 0) { | 144 if (m_coords.size() >= 3 && m_coords[2] > 0) { |
156 float r = clampCoordinate(m_coords[2]); | 145 float r = clampCoordinate(m_coords[2]); |
157 path.addEllipse(FloatRect(clampCoordinate(m_coords[0]) - r, clampCoo
rdinate(m_coords[1]) - r, 2 * r, 2 * r)); | 146 m_path->addEllipse(FloatRect(clampCoordinate(m_coords[0]) - r, clamp
Coordinate(m_coords[1]) - r, 2 * r, 2 * r)); |
158 } | 147 } |
159 break; | 148 break; |
160 case Rect: | 149 case Rect: |
161 if (m_coords.size() >= 4) { | 150 if (m_coords.size() >= 4) { |
162 float x0 = clampCoordinate(m_coords[0]); | 151 float x0 = clampCoordinate(m_coords[0]); |
163 float y0 = clampCoordinate(m_coords[1]); | 152 float y0 = clampCoordinate(m_coords[1]); |
164 float x1 = clampCoordinate(m_coords[2]); | 153 float x1 = clampCoordinate(m_coords[2]); |
165 float y1 = clampCoordinate(m_coords[3]); | 154 float y1 = clampCoordinate(m_coords[3]); |
166 path.addRect(FloatRect(x0, y0, x1 - x0, y1 - y0)); | 155 m_path->addRect(FloatRect(x0, y0, x1 - x0, y1 - y0)); |
167 } | 156 } |
168 break; | 157 break; |
169 case Default: | 158 case Default: |
170 path.addRect(FloatRect(FloatPoint(0, 0), FloatSize(size))); | 159 if (LayoutObject* object = imageElementLayoutObject()) { |
| 160 if (object->isBox()) |
| 161 m_path->addRect(FloatRect(toLayoutBox(object)->contentBoxRect())
); |
| 162 } |
171 break; | 163 break; |
172 } | 164 } |
173 | 165 |
174 return path; | 166 return *m_path; |
175 } | 167 } |
176 | 168 |
177 HTMLImageElement* HTMLAreaElement::imageElement() const | 169 HTMLImageElement* HTMLAreaElement::imageElement() const |
178 { | 170 { |
179 if (HTMLMapElement* mapElement = Traversal<HTMLMapElement>::firstAncestor(*t
his)) | 171 if (HTMLMapElement* mapElement = Traversal<HTMLMapElement>::firstAncestor(*t
his)) |
180 return mapElement->imageElement(); | 172 return mapElement->imageElement(); |
181 return nullptr; | 173 return nullptr; |
182 } | 174 } |
183 | 175 |
| 176 LayoutObject* HTMLAreaElement::imageElementLayoutObject() const |
| 177 { |
| 178 if (HTMLImageElement* imageElement = this->imageElement()) |
| 179 return imageElement->layoutObject(); |
| 180 return nullptr; |
| 181 } |
| 182 |
184 bool HTMLAreaElement::isKeyboardFocusable() const | 183 bool HTMLAreaElement::isKeyboardFocusable() const |
185 { | 184 { |
186 return isFocusable(); | 185 return isFocusable(); |
187 } | 186 } |
188 | 187 |
189 bool HTMLAreaElement::isMouseFocusable() const | 188 bool HTMLAreaElement::isMouseFocusable() const |
190 { | 189 { |
191 return isFocusable(); | 190 return isFocusable(); |
192 } | 191 } |
193 | 192 |
(...skipping 28 matching lines...) Expand all Loading... |
222 { | 221 { |
223 document().updateLayoutTreeForNode(this); | 222 document().updateLayoutTreeForNode(this); |
224 if (!isFocusable()) | 223 if (!isFocusable()) |
225 return; | 224 return; |
226 | 225 |
227 if (HTMLImageElement* imageElement = this->imageElement()) | 226 if (HTMLImageElement* imageElement = this->imageElement()) |
228 imageElement->updateFocusAppearance(selectionBehavior); | 227 imageElement->updateFocusAppearance(selectionBehavior); |
229 } | 228 } |
230 | 229 |
231 } // namespace blink | 230 } // namespace blink |
OLD | NEW |