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

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, 7 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)));
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 LayoutObject* containerObj ect) const
108 { 102 {
109 if (!obj) 103 if (!containerObject)
110 return Path(); 104 return LayoutRect();
111 105
112 // FIXME: This doesn't work correctly with transforms. 106 // FIXME: This doesn't work correctly with transforms.
113 FloatPoint absPos = obj->localToAbsolute(); 107 FloatPoint absPos = containerObject->localToAbsolute();
114 108
115 // Default should default to the size of the containing object. 109 Path p = getPath(containerObject);
pdr. 2016/04/26 01:29:35 Nit: p -> path
116 LayoutSize size = m_lastSize; 110 float zoomFactor = containerObject->style()->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) { 111 if (zoomFactor != 1.0f) {
pdr. 2016/04/26 01:29:35 Do we really want to zoom this value? I traced the
123 AffineTransform zoomTransform; 112 AffineTransform zoomTransform;
124 zoomTransform.scale(zoomFactor); 113 zoomTransform.scale(zoomFactor);
125 p.transform(zoomTransform); 114 p.transform(zoomTransform);
126 } 115 }
127 116
128 p.translate(toFloatSize(absPos)); 117 p.translate(toFloatSize(absPos));
129 return p; 118 return enclosingLayoutRect(p.boundingRect());
130 } 119 }
131 120
132 LayoutRect HTMLAreaElement::computeRect(const LayoutObject* obj) const 121 Path HTMLAreaElement::getPath(const LayoutObject* containerObject) const
133 { 122 {
134 return enclosingLayoutRect(computePath(obj).boundingRect()); 123 // Always recompute for default shape because it depends on container object 's size
135 } 124 // and is cheap.
125 if (m_shape == Default) {
126 Path path;
pdr. 2016/04/26 01:29:35 Invalidate m_path for this codepath?
Xianzhu 2016/04/26 17:42:27 Done.
127 if (containerObject && containerObject->isBox())
128 path.addRect(FloatRect(toLayoutBox(containerObject)->borderBoxRect() ));
129 return path;
130 }
136 131
137 Path HTMLAreaElement::getRegion(const LayoutSize& size) const 132 if (m_path)
138 { 133 return *m_path;
134
135 m_path = adoptPtr(new Path);
136
139 if (m_coords.isEmpty() && m_shape != Default) 137 if (m_coords.isEmpty() && m_shape != Default)
pdr. 2016/04/26 01:29:35 m_shape can't be Default here so this can just be:
Xianzhu 2016/04/26 17:42:27 Done.
140 return Path(); 138 return *m_path;
141 139
142 Path path;
143 switch (m_shape) { 140 switch (m_shape) {
144 case Poly: 141 case Poly:
145 if (m_coords.size() >= 6) { 142 if (m_coords.size() >= 6) {
146 int numPoints = m_coords.size() / 2; 143 int numPoints = m_coords.size() / 2;
147 path.moveTo(FloatPoint(clampCoordinate(m_coords[0]), clampCoordinate (m_coords[1]))); 144 m_path->moveTo(FloatPoint(clampCoordinate(m_coords[0]), clampCoordin ate(m_coords[1])));
148 for (int i = 1; i < numPoints; ++i) 145 for (int i = 1; i < numPoints; ++i)
149 path.addLineTo(FloatPoint(clampCoordinate(m_coords[i * 2]), clam pCoordinate(m_coords[i * 2 + 1]))); 146 m_path->addLineTo(FloatPoint(clampCoordinate(m_coords[i * 2]), c lampCoordinate(m_coords[i * 2 + 1])));
150 path.closeSubpath(); 147 m_path->closeSubpath();
151 path.setWindRule(RULE_EVENODD); 148 m_path->setWindRule(RULE_EVENODD);
152 } 149 }
153 break; 150 break;
154 case Circle: 151 case Circle:
155 if (m_coords.size() >= 3 && m_coords[2] > 0) { 152 if (m_coords.size() >= 3 && m_coords[2] > 0) {
156 float r = clampCoordinate(m_coords[2]); 153 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)); 154 m_path->addEllipse(FloatRect(clampCoordinate(m_coords[0]) - r, clamp Coordinate(m_coords[1]) - r, 2 * r, 2 * r));
158 } 155 }
159 break; 156 break;
160 case Rect: 157 case Rect:
161 if (m_coords.size() >= 4) { 158 if (m_coords.size() >= 4) {
162 float x0 = clampCoordinate(m_coords[0]); 159 float x0 = clampCoordinate(m_coords[0]);
163 float y0 = clampCoordinate(m_coords[1]); 160 float y0 = clampCoordinate(m_coords[1]);
164 float x1 = clampCoordinate(m_coords[2]); 161 float x1 = clampCoordinate(m_coords[2]);
165 float y1 = clampCoordinate(m_coords[3]); 162 float y1 = clampCoordinate(m_coords[3]);
166 path.addRect(FloatRect(x0, y0, x1 - x0, y1 - y0)); 163 m_path->addRect(FloatRect(x0, y0, x1 - x0, y1 - y0));
167 } 164 }
168 break; 165 break;
169 case Default: 166 default:
170 path.addRect(FloatRect(FloatPoint(0, 0), FloatSize(size))); 167 ASSERT_NOT_REACHED();
171 break; 168 break;
172 } 169 }
173 170
174 return path; 171 return *m_path;
175 } 172 }
176 173
177 HTMLImageElement* HTMLAreaElement::imageElement() const 174 HTMLImageElement* HTMLAreaElement::imageElement() const
178 { 175 {
179 if (HTMLMapElement* mapElement = Traversal<HTMLMapElement>::firstAncestor(*t his)) 176 if (HTMLMapElement* mapElement = Traversal<HTMLMapElement>::firstAncestor(*t his))
180 return mapElement->imageElement(); 177 return mapElement->imageElement();
181 return nullptr; 178 return nullptr;
182 } 179 }
183 180
184 bool HTMLAreaElement::isKeyboardFocusable() const 181 bool HTMLAreaElement::isKeyboardFocusable() const
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 { 219 {
223 document().updateLayoutTreeForNode(this); 220 document().updateLayoutTreeForNode(this);
224 if (!isFocusable()) 221 if (!isFocusable())
225 return; 222 return;
226 223
227 if (HTMLImageElement* imageElement = this->imageElement()) 224 if (HTMLImageElement* imageElement = this->imageElement())
228 imageElement->updateFocusAppearance(selectionBehavior); 225 imageElement->updateFocusAppearance(selectionBehavior);
229 } 226 }
230 227
231 } // namespace blink 228 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698