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

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

Issue 166163005: [SVG2] Add tabindex handling in svg. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebase Created 6 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
« no previous file with comments | « Source/core/dom/Element.h ('k') | Source/core/html/HTMLAnchorElement.h » ('j') | 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 * (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. All rights reserved. 7 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. All rights reserved.
8 * (C) 2007 Eric Seidel (eric@webkit.org) 8 * (C) 2007 Eric Seidel (eric@webkit.org)
9 * 9 *
10 * This library is free software; you can redistribute it and/or 10 * This library is free software; you can redistribute it and/or
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 #include "core/dom/shadow/InsertionPoint.h" 69 #include "core/dom/shadow/InsertionPoint.h"
70 #include "core/dom/shadow/ShadowRoot.h" 70 #include "core/dom/shadow/ShadowRoot.h"
71 #include "core/editing/FrameSelection.h" 71 #include "core/editing/FrameSelection.h"
72 #include "core/editing/TextIterator.h" 72 #include "core/editing/TextIterator.h"
73 #include "core/editing/htmlediting.h" 73 #include "core/editing/htmlediting.h"
74 #include "core/editing/markup.h" 74 #include "core/editing/markup.h"
75 #include "core/events/EventDispatcher.h" 75 #include "core/events/EventDispatcher.h"
76 #include "core/events/FocusEvent.h" 76 #include "core/events/FocusEvent.h"
77 #include "core/frame/FrameView.h" 77 #include "core/frame/FrameView.h"
78 #include "core/frame/LocalFrame.h" 78 #include "core/frame/LocalFrame.h"
79 #include "core/frame/Settings.h"
79 #include "core/frame/UseCounter.h" 80 #include "core/frame/UseCounter.h"
80 #include "core/frame/csp/ContentSecurityPolicy.h" 81 #include "core/frame/csp/ContentSecurityPolicy.h"
81 #include "core/html/ClassList.h" 82 #include "core/html/ClassList.h"
82 #include "core/html/HTMLCollection.h" 83 #include "core/html/HTMLCollection.h"
83 #include "core/html/HTMLDocument.h" 84 #include "core/html/HTMLDocument.h"
84 #include "core/html/HTMLElement.h" 85 #include "core/html/HTMLElement.h"
85 #include "core/html/HTMLFormControlsCollection.h" 86 #include "core/html/HTMLFormControlsCollection.h"
86 #include "core/html/HTMLFrameElementBase.h" 87 #include "core/html/HTMLFrameElementBase.h"
87 #include "core/html/HTMLFrameOwnerElement.h" 88 #include "core/html/HTMLFrameOwnerElement.h"
88 #include "core/html/HTMLLabelElement.h" 89 #include "core/html/HTMLLabelElement.h"
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 { 226 {
226 if (hasRareData()) 227 if (hasRareData())
227 elementRareData()->clearTabIndexExplicitly(); 228 elementRareData()->clearTabIndexExplicitly();
228 } 229 }
229 230
230 void Element::setTabIndexExplicitly(short tabIndex) 231 void Element::setTabIndexExplicitly(short tabIndex)
231 { 232 {
232 ensureElementRareData().setTabIndexExplicitly(tabIndex); 233 ensureElementRareData().setTabIndexExplicitly(tabIndex);
233 } 234 }
234 235
236 void Element::setTabIndex(int value)
237 {
238 setIntegralAttribute(tabindexAttr, value);
239 }
240
235 short Element::tabIndex() const 241 short Element::tabIndex() const
236 { 242 {
237 return hasRareData() ? elementRareData()->tabIndex() : 0; 243 return hasRareData() ? elementRareData()->tabIndex() : 0;
238 } 244 }
239 245
240 bool Element::rendererIsFocusable() const 246 bool Element::rendererIsFocusable() const
241 { 247 {
242 // Elements in canvas fallback content are not rendered, but they are allowe d to be 248 // Elements in canvas fallback content are not rendered, but they are allowe d to be
243 // focusable as long as their canvas is displayed and visible. 249 // focusable as long as their canvas is displayed and visible.
244 if (isInCanvasSubtree()) { 250 if (isInCanvasSubtree()) {
(...skipping 1674 matching lines...) Expand 10 before | Expand all | Expand 10 after
1919 if (index == kNotFound) { 1925 if (index == kNotFound) {
1920 exceptionState.throwDOMException(NotFoundError, "The attribute was not f ound on this element."); 1926 exceptionState.throwDOMException(NotFoundError, "The attribute was not f ound on this element.");
1921 return nullptr; 1927 return nullptr;
1922 } 1928 }
1923 1929
1924 RefPtr<Attr> guard(attr); 1930 RefPtr<Attr> guard(attr);
1925 detachAttrNodeAtIndex(attr, index); 1931 detachAttrNodeAtIndex(attr, index);
1926 return guard.release(); 1932 return guard.release();
1927 } 1933 }
1928 1934
1935 void Element::parseAttribute(const QualifiedName& name, const AtomicString& valu e)
1936 {
1937 if (name == tabindexAttr) {
1938 int tabindex = 0;
1939 if (value.isEmpty()) {
1940 clearTabIndexExplicitlyIfNeeded();
1941 if (treeScope().adjustedFocusedElement() == this) {
1942 // We might want to call blur(), but it's dangerous to dispatch
1943 // events here.
1944 document().setNeedsFocusedElementCheck();
1945 }
1946 } else if (parseHTMLInteger(value, tabindex)) {
1947 // Clamp tabindex to the range of 'short' to match Firefox's behavio r.
1948 setTabIndexExplicitly(max(static_cast<int>(std::numeric_limits<short >::min()), std::min(tabindex, static_cast<int>(std::numeric_limits<short>::max() ))));
1949 }
1950 }
1951 }
1952
1929 bool Element::parseAttributeName(QualifiedName& out, const AtomicString& namespa ceURI, const AtomicString& qualifiedName, ExceptionState& exceptionState) 1953 bool Element::parseAttributeName(QualifiedName& out, const AtomicString& namespa ceURI, const AtomicString& qualifiedName, ExceptionState& exceptionState)
1930 { 1954 {
1931 AtomicString prefix, localName; 1955 AtomicString prefix, localName;
1932 if (!Document::parseQualifiedName(qualifiedName, prefix, localName, exceptio nState)) 1956 if (!Document::parseQualifiedName(qualifiedName, prefix, localName, exceptio nState))
1933 return false; 1957 return false;
1934 ASSERT(!exceptionState.hadException()); 1958 ASSERT(!exceptionState.hadException());
1935 1959
1936 QualifiedName qName(prefix, localName, namespaceURI); 1960 QualifiedName qName(prefix, localName, namespaceURI);
1937 1961
1938 if (!Document::hasValidNamespaceForAttributes(qName)) { 1962 if (!Document::hasValidNamespaceForAttributes(qName)) {
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
2113 cancelFocusAppearanceUpdate(); 2137 cancelFocusAppearanceUpdate();
2114 if (treeScope().adjustedFocusedElement() == this) { 2138 if (treeScope().adjustedFocusedElement() == this) {
2115 Document& doc = document(); 2139 Document& doc = document();
2116 if (doc.page()) 2140 if (doc.page())
2117 doc.page()->focusController().setFocusedElement(0, doc.frame()); 2141 doc.page()->focusController().setFocusedElement(0, doc.frame());
2118 else 2142 else
2119 doc.setFocusedElement(nullptr); 2143 doc.setFocusedElement(nullptr);
2120 } 2144 }
2121 } 2145 }
2122 2146
2147 bool Element::supportsFocus() const
2148 {
2149 // FIXME: supportsFocus() can be called when layout is not up to date.
2150 // Logic that deals with the renderer should be moved to rendererIsFocusable ().
2151 // But supportsFocus must return true when the element is editable, or else
2152 // it won't be focusable. Furthermore, supportsFocus cannot just return true
2153 // always or else tabIndex() will change for all HTML elements.
2154 return hasElementFlag(TabIndexWasSetExplicitly) || (rendererIsEditable() && parentNode() && !parentNode()->rendererIsEditable())
2155 || supportsSpatialNavigationFocus();
2156 }
2157
2158 bool Element::supportsSpatialNavigationFocus() const
2159 {
2160 // This function checks whether the element satisfies the extended criteria
2161 // for the element to be focusable, introduced by spatial navigation feature ,
2162 // i.e. checks if click or keyboard event handler is specified.
2163 // This is the way to make it possible to navigate to (focus) elements
2164 // which web designer meant for being active (made them respond to click eve nts).
2165
2166 if (!document().settings() || !document().settings()->spatialNavigationEnabl ed())
2167 return false;
2168 return hasEventListeners(EventTypeNames::click)
2169 || hasEventListeners(EventTypeNames::keydown)
2170 || hasEventListeners(EventTypeNames::keypress)
2171 || hasEventListeners(EventTypeNames::keyup);
2172 }
2173
2123 bool Element::isFocusable() const 2174 bool Element::isFocusable() const
2124 { 2175 {
2125 return inDocument() && supportsFocus() && !isInert() && rendererIsFocusable( ); 2176 return inDocument() && supportsFocus() && !isInert() && rendererIsFocusable( );
2126 } 2177 }
2127 2178
2128 bool Element::isKeyboardFocusable() const 2179 bool Element::isKeyboardFocusable() const
2129 { 2180 {
2130 return isFocusable() && tabIndex() >= 0; 2181 return isFocusable() && tabIndex() >= 0;
2131 } 2182 }
2132 2183
(...skipping 1131 matching lines...) Expand 10 before | Expand all | Expand 10 after
3264 || isHTMLObjectElement(*this) 3315 || isHTMLObjectElement(*this)
3265 || isHTMLAppletElement(*this) 3316 || isHTMLAppletElement(*this)
3266 || isHTMLCanvasElement(*this)) 3317 || isHTMLCanvasElement(*this))
3267 return false; 3318 return false;
3268 if (FullscreenElementStack::isActiveFullScreenElement(this)) 3319 if (FullscreenElementStack::isActiveFullScreenElement(this))
3269 return false; 3320 return false;
3270 return true; 3321 return true;
3271 } 3322 }
3272 3323
3273 } // namespace WebCore 3324 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/dom/Element.h ('k') | Source/core/html/HTMLAnchorElement.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698