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

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

Issue 1619793002: Remove use of minimumValueForLength in HTMLAreaElement::getRegion (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 10 matching lines...) Expand all
21 21
22 #include "core/html/HTMLAreaElement.h" 22 #include "core/html/HTMLAreaElement.h"
23 23
24 #include "core/HTMLNames.h" 24 #include "core/HTMLNames.h"
25 #include "core/dom/ElementTraversal.h" 25 #include "core/dom/ElementTraversal.h"
26 #include "core/html/HTMLImageElement.h" 26 #include "core/html/HTMLImageElement.h"
27 #include "core/html/HTMLMapElement.h" 27 #include "core/html/HTMLMapElement.h"
28 #include "core/layout/HitTestResult.h" 28 #include "core/layout/HitTestResult.h"
29 #include "core/layout/LayoutImage.h" 29 #include "core/layout/LayoutImage.h"
30 #include "core/layout/LayoutView.h" 30 #include "core/layout/LayoutView.h"
31 #include "platform/LengthFunctions.h"
32 #include "platform/graphics/Path.h" 31 #include "platform/graphics/Path.h"
33 #include "platform/transforms/AffineTransform.h" 32 #include "platform/transforms/AffineTransform.h"
34 33
35 namespace blink { 34 namespace blink {
36 35
36 namespace {
37
38 // Adapt a Length to the allowed range of a LayoutUnit.
39 float clampCoordinate(const Length& length)
40 {
41 ASSERT(length.isFixed());
42 return LayoutUnit(length.value()).toFloat();
43 }
44
45 }
46
37 using namespace HTMLNames; 47 using namespace HTMLNames;
38 48
39 inline HTMLAreaElement::HTMLAreaElement(Document& document) 49 inline HTMLAreaElement::HTMLAreaElement(Document& document)
40 : HTMLAnchorElement(areaTag, document) 50 : HTMLAnchorElement(areaTag, document)
41 , m_lastSize(-1, -1) 51 , m_lastSize(-1, -1)
42 , m_shape(Unknown) 52 , m_shape(Unknown)
43 { 53 {
44 } 54 }
45 55
46 // An explicit empty destructor should be in HTMLAreaElement.cpp, because 56 // An explicit empty destructor should be in HTMLAreaElement.cpp, because
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 LayoutRect HTMLAreaElement::computeRect(const LayoutObject* obj) const 129 LayoutRect HTMLAreaElement::computeRect(const LayoutObject* obj) const
120 { 130 {
121 return enclosingLayoutRect(computePath(obj).boundingRect()); 131 return enclosingLayoutRect(computePath(obj).boundingRect());
122 } 132 }
123 133
124 Path HTMLAreaElement::getRegion(const LayoutSize& size) const 134 Path HTMLAreaElement::getRegion(const LayoutSize& size) const
125 { 135 {
126 if (m_coords.isEmpty() && m_shape != Default) 136 if (m_coords.isEmpty() && m_shape != Default)
127 return Path(); 137 return Path();
128 138
129 LayoutUnit width = size.width();
130 LayoutUnit height = size.height();
131
132 // If element omits the shape attribute, select shape based on number of coo rdinates. 139 // If element omits the shape attribute, select shape based on number of coo rdinates.
133 Shape shape = m_shape; 140 Shape shape = m_shape;
134 if (shape == Unknown) { 141 if (shape == Unknown) {
135 if (m_coords.size() == 3) 142 if (m_coords.size() == 3)
136 shape = Circle; 143 shape = Circle;
137 else if (m_coords.size() == 4) 144 else if (m_coords.size() == 4)
138 shape = Rect; 145 shape = Rect;
139 else if (m_coords.size() >= 6) 146 else if (m_coords.size() >= 6)
140 shape = Poly; 147 shape = Poly;
141 } 148 }
142 149
143 Path path; 150 Path path;
144 switch (shape) { 151 switch (shape) {
145 case Poly: 152 case Poly:
146 if (m_coords.size() >= 6) { 153 if (m_coords.size() >= 6) {
147 int numPoints = m_coords.size() / 2; 154 int numPoints = m_coords.size() / 2;
148 path.moveTo(FloatPoint(minimumValueForLength(m_coords[0], width).toF loat(), minimumValueForLength(m_coords[1], height).toFloat())); 155 path.moveTo(FloatPoint(clampCoordinate(m_coords[0]), clampCoordinate (m_coords[1])));
149 for (int i = 1; i < numPoints; ++i) 156 for (int i = 1; i < numPoints; ++i)
150 path.addLineTo(FloatPoint(minimumValueForLength(m_coords[i * 2], width).toFloat(), minimumValueForLength(m_coords[i * 2 + 1], height).toFloat()) ); 157 path.addLineTo(FloatPoint(clampCoordinate(m_coords[i * 2]), clam pCoordinate(m_coords[i * 2 + 1])));
151 path.closeSubpath(); 158 path.closeSubpath();
152 } 159 }
153 break; 160 break;
154 case Circle: 161 case Circle:
155 if (m_coords.size() >= 3) { 162 if (m_coords.size() >= 3) {
156 Length radius = m_coords[2]; 163 float r = clampCoordinate(m_coords[2]);
157 float r = std::min(minimumValueForLength(radius, width).toFloat(), m inimumValueForLength(radius, height).toFloat()); 164 path.addEllipse(FloatRect(clampCoordinate(m_coords[0]) - r, clampCoo rdinate(m_coords[1]) - r, 2 * r, 2 * r));
158 path.addEllipse(FloatRect(minimumValueForLength(m_coords[0], width). toFloat() - r, minimumValueForLength(m_coords[1], height).toFloat() - r, 2 * r, 2 * r));
159 } 165 }
160 break; 166 break;
161 case Rect: 167 case Rect:
162 if (m_coords.size() >= 4) { 168 if (m_coords.size() >= 4) {
163 float x0 = minimumValueForLength(m_coords[0], width).toFloat(); 169 float x0 = clampCoordinate(m_coords[0]);
164 float y0 = minimumValueForLength(m_coords[1], height).toFloat(); 170 float y0 = clampCoordinate(m_coords[1]);
165 float x1 = minimumValueForLength(m_coords[2], width).toFloat(); 171 float x1 = clampCoordinate(m_coords[2]);
166 float y1 = minimumValueForLength(m_coords[3], height).toFloat(); 172 float y1 = clampCoordinate(m_coords[3]);
167 path.addRect(FloatRect(x0, y0, x1 - x0, y1 - y0)); 173 path.addRect(FloatRect(x0, y0, x1 - x0, y1 - y0));
168 } 174 }
169 break; 175 break;
170 case Default: 176 case Default:
171 path.addRect(FloatRect(0, 0, width.toFloat(), height.toFloat())); 177 path.addRect(FloatRect(FloatPoint(0, 0), FloatSize(size)));
172 break; 178 break;
173 case Unknown: 179 case Unknown:
174 break; 180 break;
175 } 181 }
176 182
177 return path; 183 return path;
178 } 184 }
179 185
180 HTMLImageElement* HTMLAreaElement::imageElement() const 186 HTMLImageElement* HTMLAreaElement::imageElement() const
181 { 187 {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 void HTMLAreaElement::updateFocusAppearance(SelectionBehaviorOnFocus selectionBe havior) 230 void HTMLAreaElement::updateFocusAppearance(SelectionBehaviorOnFocus selectionBe havior)
225 { 231 {
226 if (!isFocusable()) 232 if (!isFocusable())
227 return; 233 return;
228 234
229 if (HTMLImageElement* imageElement = this->imageElement()) 235 if (HTMLImageElement* imageElement = this->imageElement())
230 imageElement->updateFocusAppearance(selectionBehavior); 236 imageElement->updateFocusAppearance(selectionBehavior);
231 } 237 }
232 238
233 } 239 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698