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

Side by Side Diff: third_party/WebKit/Source/core/html/HTMLAreaElement.cpp

Issue 1912863002: Fix image map focus ring painting (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
OLDNEW
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
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, const LayoutObjec t* containerObject) const
98 { 97 {
99 if (m_lastSize != containerSize) { 98 return getPath(containerObject).contains(FloatPoint(location));
100 m_region = adoptPtr(new Path(getRegion(containerSize))); 99 }
101 m_lastSize = containerSize; 100
101 LayoutRect HTMLAreaElement::computeAbsoluteRect(const LayoutObject* containerObj ect) const
102 {
103 if (!containerObject)
104 return LayoutRect();
105
106 // FIXME: This doesn't work correctly with transforms.
107 FloatPoint absPos = containerObject->localToAbsolute();
108
109 Path path = getPath(containerObject);
110 path.translate(toFloatSize(absPos));
111 return enclosingLayoutRect(path.boundingRect());
112 }
113
114 Path HTMLAreaElement::getPath(const LayoutObject* containerObject) const
115 {
116 if (!containerObject)
117 return Path();
118
119 // Always recompute for default shape because it depends on container object 's size
120 // and is cheap.
121 if (m_shape == Default) {
122 Path path;
123 // No need to zoom because it is already applied in containerObject->bor derBoxRect().
124 if (containerObject->isBox())
125 path.addRect(FloatRect(toLayoutBox(containerObject)->borderBoxRect() ));
126 m_path = nullptr;
127 return path;
102 } 128 }
103 129
104 return m_region->contains(FloatPoint(location)); 130 Path path;
105 } 131 if (m_path) {
132 path = *m_path;
133 } else {
134 if (m_coords.isEmpty())
135 return path;
106 136
107 Path HTMLAreaElement::computePath(const LayoutObject* obj) const 137 switch (m_shape) {
108 { 138 case Poly:
109 if (!obj) 139 if (m_coords.size() >= 6) {
110 return Path(); 140 int numPoints = m_coords.size() / 2;
141 path.moveTo(FloatPoint(clampCoordinate(m_coords[0]), clampCoordi nate(m_coords[1])));
142 for (int i = 1; i < numPoints; ++i)
143 path.addLineTo(FloatPoint(clampCoordinate(m_coords[i * 2]), clampCoordinate(m_coords[i * 2 + 1])));
144 path.closeSubpath();
145 path.setWindRule(RULE_EVENODD);
146 }
147 break;
148 case Circle:
149 if (m_coords.size() >= 3 && m_coords[2] > 0) {
150 float r = clampCoordinate(m_coords[2]);
151 path.addEllipse(FloatRect(clampCoordinate(m_coords[0]) - r, clam pCoordinate(m_coords[1]) - r, 2 * r, 2 * r));
152 }
153 break;
154 case Rect:
155 if (m_coords.size() >= 4) {
156 float x0 = clampCoordinate(m_coords[0]);
157 float y0 = clampCoordinate(m_coords[1]);
158 float x1 = clampCoordinate(m_coords[2]);
159 float y1 = clampCoordinate(m_coords[3]);
160 path.addRect(FloatRect(x0, y0, x1 - x0, y1 - y0));
161 }
162 break;
163 default:
164 ASSERT_NOT_REACHED();
165 break;
166 }
111 167
112 // FIXME: This doesn't work correctly with transforms. 168 // Cache the original path, not depending on containerObject.
113 FloatPoint absPos = obj->localToAbsolute(); 169 m_path = adoptPtr(new Path(path));
170 }
114 171
115 // Default should default to the size of the containing object. 172 // Zoom the path into coordinates of the container object.
116 LayoutSize size = m_lastSize; 173 float zoomFactor = containerObject->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) { 174 if (zoomFactor != 1.0f) {
123 AffineTransform zoomTransform; 175 AffineTransform zoomTransform;
124 zoomTransform.scale(zoomFactor); 176 zoomTransform.scale(zoomFactor);
125 p.transform(zoomTransform); 177 path.transform(zoomTransform);
126 } 178 }
127
128 p.translate(toFloatSize(absPos));
129 return p;
130 }
131
132 LayoutRect HTMLAreaElement::computeRect(const LayoutObject* obj) const
133 {
134 return enclosingLayoutRect(computePath(obj).boundingRect());
135 }
136
137 Path HTMLAreaElement::getRegion(const LayoutSize& size) const
138 {
139 if (m_coords.isEmpty() && m_shape != Default)
140 return Path();
141
142 Path path;
143 switch (m_shape) {
144 case Poly:
145 if (m_coords.size() >= 6) {
146 int numPoints = m_coords.size() / 2;
147 path.moveTo(FloatPoint(clampCoordinate(m_coords[0]), clampCoordinate (m_coords[1])));
148 for (int i = 1; i < numPoints; ++i)
149 path.addLineTo(FloatPoint(clampCoordinate(m_coords[i * 2]), clam pCoordinate(m_coords[i * 2 + 1])));
150 path.closeSubpath();
151 path.setWindRule(RULE_EVENODD);
152 }
153 break;
154 case Circle:
155 if (m_coords.size() >= 3 && m_coords[2] > 0) {
156 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));
158 }
159 break;
160 case Rect:
161 if (m_coords.size() >= 4) {
162 float x0 = clampCoordinate(m_coords[0]);
163 float y0 = clampCoordinate(m_coords[1]);
164 float x1 = clampCoordinate(m_coords[2]);
165 float y1 = clampCoordinate(m_coords[3]);
166 path.addRect(FloatRect(x0, y0, x1 - x0, y1 - y0));
167 }
168 break;
169 case Default:
170 path.addRect(FloatRect(FloatPoint(0, 0), FloatSize(size)));
171 break;
172 }
173
174 return path; 179 return path;
175 } 180 }
176 181
177 HTMLImageElement* HTMLAreaElement::imageElement() const 182 HTMLImageElement* HTMLAreaElement::imageElement() const
178 { 183 {
179 if (HTMLMapElement* mapElement = Traversal<HTMLMapElement>::firstAncestor(*t his)) 184 if (HTMLMapElement* mapElement = Traversal<HTMLMapElement>::firstAncestor(*t his))
180 return mapElement->imageElement(); 185 return mapElement->imageElement();
181 return nullptr; 186 return nullptr;
182 } 187 }
183 188
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 { 227 {
223 document().updateLayoutTreeForNode(this); 228 document().updateLayoutTreeForNode(this);
224 if (!isFocusable()) 229 if (!isFocusable())
225 return; 230 return;
226 231
227 if (HTMLImageElement* imageElement = this->imageElement()) 232 if (HTMLImageElement* imageElement = this->imageElement())
228 imageElement->updateFocusAppearance(selectionBehavior); 233 imageElement->updateFocusAppearance(selectionBehavior);
229 } 234 }
230 235
231 } // namespace blink 236 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLAreaElement.h ('k') | third_party/WebKit/Source/core/html/HTMLMapElement.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698