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

Side by Side Diff: third_party/WebKit/Source/core/dom/Element.cpp

Issue 2362223002: Stop clamping tabIndex to short range (Closed)
Patch Set: Fix tabindex-clamp.html Created 4 years, 1 month 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 * (C) 2001 Peter Kelly (pmk@post.com) 4 * (C) 2001 Peter Kelly (pmk@post.com)
5 * (C) 2001 Dirk Mueller (mueller@kde.org) 5 * (C) 2001 Dirk Mueller (mueller@kde.org)
6 * (C) 2007 David Smith (catfish.man@gmail.com) 6 * (C) 2007 David Smith (catfish.man@gmail.com)
7 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. 7 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc.
8 * All rights reserved. 8 * All rights reserved.
9 * (C) 2007 Eric Seidel (eric@webkit.org) 9 * (C) 2007 Eric Seidel (eric@webkit.org)
10 * 10 *
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 if (!hasRareData()) 209 if (!hasRareData())
210 return; 210 return;
211 elementRareData()->clearElementFlag(mask); 211 elementRareData()->clearElementFlag(mask);
212 } 212 }
213 213
214 void Element::clearTabIndexExplicitlyIfNeeded() { 214 void Element::clearTabIndexExplicitlyIfNeeded() {
215 if (hasRareData()) 215 if (hasRareData())
216 elementRareData()->clearTabIndexExplicitly(); 216 elementRareData()->clearTabIndexExplicitly();
217 } 217 }
218 218
219 void Element::setTabIndexExplicitly(short tabIndex) { 219 void Element::setTabIndexExplicitly() {
220 ensureElementRareData().setTabIndexExplicitly(tabIndex); 220 ensureElementRareData().setTabIndexExplicitly();
221 } 221 }
222 222
223 void Element::setTabIndex(int value) { 223 void Element::setTabIndex(int value) {
224 setIntegralAttribute(tabindexAttr, value); 224 setIntegralAttribute(tabindexAttr, value);
225 } 225 }
226 226
227 short Element::tabIndex() const { 227 int Element::tabIndex() const {
228 return hasRareData() ? elementRareData()->tabIndex() : 0; 228 return hasElementFlag(TabIndexWasSetExplicitly)
229 ? getIntegralAttribute(tabindexAttr)
230 : 0;
229 } 231 }
230 232
231 bool Element::layoutObjectIsFocusable() const { 233 bool Element::layoutObjectIsFocusable() const {
232 // Elements in canvas fallback content are not rendered, but they are allowed 234 // Elements in canvas fallback content are not rendered, but they are allowed
233 // to be focusable as long as their canvas is displayed and visible. 235 // to be focusable as long as their canvas is displayed and visible.
234 if (isInCanvasSubtree()) { 236 if (isInCanvasSubtree()) {
235 const HTMLCanvasElement* canvas = 237 const HTMLCanvasElement* canvas =
236 Traversal<HTMLCanvasElement>::firstAncestorOrSelf(*this); 238 Traversal<HTMLCanvasElement>::firstAncestorOrSelf(*this);
237 DCHECK(canvas); 239 DCHECK(canvas);
238 return canvas->layoutObject() && 240 return canvas->layoutObject() &&
(...skipping 2191 matching lines...) Expand 10 before | Expand all | Expand 10 after
2430 2432
2431 detachAttrNodeAtIndex(attr, index); 2433 detachAttrNodeAtIndex(attr, index);
2432 return attr; 2434 return attr;
2433 } 2435 }
2434 2436
2435 void Element::parseAttribute(const QualifiedName& name, 2437 void Element::parseAttribute(const QualifiedName& name,
2436 const AtomicString&, 2438 const AtomicString&,
2437 const AtomicString& value) { 2439 const AtomicString& value) {
2438 if (name == tabindexAttr) { 2440 if (name == tabindexAttr) {
2439 int tabindex = 0; 2441 int tabindex = 0;
2440 if (value.isEmpty()) { 2442 if (value.isEmpty() || !parseHTMLInteger(value, tabindex)) {
2441 clearTabIndexExplicitlyIfNeeded(); 2443 clearTabIndexExplicitlyIfNeeded();
2442 if (adjustedFocusedElementInTreeScope() == this) { 2444 if (adjustedFocusedElementInTreeScope() == this) {
2443 // We might want to call blur(), but it's dangerous to dispatch 2445 // We might want to call blur(), but it's dangerous to dispatch
2444 // events here. 2446 // events here.
2445 document().setNeedsFocusedElementCheck(); 2447 document().setNeedsFocusedElementCheck();
2446 } 2448 }
2447 } else if (parseHTMLInteger(value, tabindex)) { 2449 } else {
2448 // Clamp tabindex to the range of 'short' to match Firefox's behavior. 2450 // We only set when value is in integer range.
2449 setTabIndexExplicitly( 2451 setTabIndexExplicitly();
2450 max(static_cast<int>(std::numeric_limits<short>::min()),
2451 std::min(tabindex,
2452 static_cast<int>(std::numeric_limits<short>::max()))));
2453 } 2452 }
2454 } else if (name == XMLNames::langAttr) { 2453 } else if (name == XMLNames::langAttr) {
2455 pseudoStateChanged(CSSSelector::PseudoLang); 2454 pseudoStateChanged(CSSSelector::PseudoLang);
2456 } 2455 }
2457 } 2456 }
2458 2457
2459 bool Element::parseAttributeName(QualifiedName& out, 2458 bool Element::parseAttributeName(QualifiedName& out,
2460 const AtomicString& namespaceURI, 2459 const AtomicString& namespaceURI,
2461 const AtomicString& qualifiedName, 2460 const AtomicString& qualifiedName,
2462 ExceptionState& exceptionState) { 2461 ExceptionState& exceptionState) {
(...skipping 1626 matching lines...) Expand 10 before | Expand all | Expand 10 after
4089 } 4088 }
4090 4089
4091 DEFINE_TRACE_WRAPPERS(Element) { 4090 DEFINE_TRACE_WRAPPERS(Element) {
4092 if (hasRareData()) { 4091 if (hasRareData()) {
4093 visitor->traceWrappers(elementRareData()); 4092 visitor->traceWrappers(elementRareData());
4094 } 4093 }
4095 ContainerNode::traceWrappers(visitor); 4094 ContainerNode::traceWrappers(visitor);
4096 } 4095 }
4097 4096
4098 } // namespace blink 4097 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/Element.h ('k') | third_party/WebKit/Source/core/dom/ElementRareData.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698