Chromium Code Reviews| 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, 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 if (containerObject->isBox()) | |
| 124 path.addRect(FloatRect(toLayoutBox(containerObject)->borderBoxRect() )); | |
|
pdr.
2016/04/26 18:47:29
This doesn't need the zoom below because it alread
Xianzhu
2016/04/26 19:25:02
Done.
| |
| 125 m_path = nullptr; | |
| 126 return path; | |
| 102 } | 127 } |
| 103 | 128 |
| 104 return m_region->contains(FloatPoint(location)); | 129 Path path; |
| 105 } | 130 if (m_path) { |
| 131 path = *m_path; | |
| 132 } else { | |
| 133 if (m_coords.isEmpty()) | |
| 134 return path; | |
| 106 | 135 |
| 107 Path HTMLAreaElement::computePath(const LayoutObject* obj) const | 136 switch (m_shape) { |
| 108 { | 137 case Poly: |
| 109 if (!obj) | 138 if (m_coords.size() >= 6) { |
| 110 return Path(); | 139 int numPoints = m_coords.size() / 2; |
| 140 path.moveTo(FloatPoint(clampCoordinate(m_coords[0]), clampCoordi nate(m_coords[1]))); | |
| 141 for (int i = 1; i < numPoints; ++i) | |
| 142 path.addLineTo(FloatPoint(clampCoordinate(m_coords[i * 2]), clampCoordinate(m_coords[i * 2 + 1]))); | |
| 143 path.closeSubpath(); | |
| 144 path.setWindRule(RULE_EVENODD); | |
| 145 } | |
| 146 break; | |
| 147 case Circle: | |
| 148 if (m_coords.size() >= 3 && m_coords[2] > 0) { | |
| 149 float r = clampCoordinate(m_coords[2]); | |
| 150 path.addEllipse(FloatRect(clampCoordinate(m_coords[0]) - r, clam pCoordinate(m_coords[1]) - r, 2 * r, 2 * r)); | |
| 151 } | |
| 152 break; | |
| 153 case Rect: | |
| 154 if (m_coords.size() >= 4) { | |
| 155 float x0 = clampCoordinate(m_coords[0]); | |
| 156 float y0 = clampCoordinate(m_coords[1]); | |
| 157 float x1 = clampCoordinate(m_coords[2]); | |
| 158 float y1 = clampCoordinate(m_coords[3]); | |
| 159 path.addRect(FloatRect(x0, y0, x1 - x0, y1 - y0)); | |
| 160 } | |
| 161 break; | |
| 162 default: | |
| 163 ASSERT_NOT_REACHED(); | |
| 164 break; | |
| 165 } | |
| 111 | 166 |
| 112 // FIXME: This doesn't work correctly with transforms. | 167 // Cache the original path, not depending on containerObject. |
| 113 FloatPoint absPos = obj->localToAbsolute(); | 168 m_path = adoptPtr(new Path(path)); |
| 169 } | |
| 114 | 170 |
| 115 // Default should default to the size of the containing object. | 171 // Zoom the path into coordinates of the container object. |
| 116 LayoutSize size = m_lastSize; | 172 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) { | 173 if (zoomFactor != 1.0f) { |
| 123 AffineTransform zoomTransform; | 174 AffineTransform zoomTransform; |
| 124 zoomTransform.scale(zoomFactor); | 175 zoomTransform.scale(zoomFactor); |
| 125 p.transform(zoomTransform); | 176 path.transform(zoomTransform); |
| 126 } | 177 } |
| 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; | 178 return path; |
| 175 } | 179 } |
| 176 | 180 |
| 177 HTMLImageElement* HTMLAreaElement::imageElement() const | 181 HTMLImageElement* HTMLAreaElement::imageElement() const |
| 178 { | 182 { |
| 179 if (HTMLMapElement* mapElement = Traversal<HTMLMapElement>::firstAncestor(*t his)) | 183 if (HTMLMapElement* mapElement = Traversal<HTMLMapElement>::firstAncestor(*t his)) |
| 180 return mapElement->imageElement(); | 184 return mapElement->imageElement(); |
| 181 return nullptr; | 185 return nullptr; |
| 182 } | 186 } |
| 183 | 187 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 222 { | 226 { |
| 223 document().updateLayoutTreeForNode(this); | 227 document().updateLayoutTreeForNode(this); |
| 224 if (!isFocusable()) | 228 if (!isFocusable()) |
| 225 return; | 229 return; |
| 226 | 230 |
| 227 if (HTMLImageElement* imageElement = this->imageElement()) | 231 if (HTMLImageElement* imageElement = this->imageElement()) |
| 228 imageElement->updateFocusAppearance(selectionBehavior); | 232 imageElement->updateFocusAppearance(selectionBehavior); |
| 229 } | 233 } |
| 230 | 234 |
| 231 } // namespace blink | 235 } // namespace blink |
| OLD | NEW |