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

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

Issue 455223002: Make anchors mouse-focusable (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: from scratch: put focus logic in Element Created 6 years, 4 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 * (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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 } 132 }
133 133
134 PassRefPtrWillBeRawPtr<Element> Element::create(const QualifiedName& tagName, Do cument* document) 134 PassRefPtrWillBeRawPtr<Element> Element::create(const QualifiedName& tagName, Do cument* document)
135 { 135 {
136 return adoptRefWillBeNoop(new Element(tagName, document, CreateElement)); 136 return adoptRefWillBeNoop(new Element(tagName, document, CreateElement));
137 } 137 }
138 138
139 Element::Element(const QualifiedName& tagName, Document* document, ConstructionT ype type) 139 Element::Element(const QualifiedName& tagName, Document* document, ConstructionT ype type)
140 : ContainerNode(document, type) 140 : ContainerNode(document, type)
141 , m_tagName(tagName) 141 , m_tagName(tagName)
142 , m_wasFocusedByMouse(false)
142 { 143 {
143 ScriptWrappable::init(this); 144 ScriptWrappable::init(this);
144 } 145 }
145 146
146 Element::~Element() 147 Element::~Element()
147 { 148 {
148 ASSERT(needsAttach()); 149 ASSERT(needsAttach());
149 150
150 #if !ENABLE(OILPAN) 151 #if !ENABLE(OILPAN)
151 if (hasRareData()) 152 if (hasRareData())
(...skipping 1967 matching lines...) Expand 10 before | Expand all | Expand 10 after
2119 { 2120 {
2120 // FIXME: supportsFocus() can be called when layout is not up to date. 2121 // FIXME: supportsFocus() can be called when layout is not up to date.
2121 // Logic that deals with the renderer should be moved to rendererIsFocusable (). 2122 // Logic that deals with the renderer should be moved to rendererIsFocusable ().
2122 // But supportsFocus must return true when the element is editable, or else 2123 // But supportsFocus must return true when the element is editable, or else
2123 // it won't be focusable. Furthermore, supportsFocus cannot just return true 2124 // it won't be focusable. Furthermore, supportsFocus cannot just return true
2124 // always or else tabIndex() will change for all HTML elements. 2125 // always or else tabIndex() will change for all HTML elements.
2125 return hasElementFlag(TabIndexWasSetExplicitly) || (hasEditableStyle() && pa rentNode() && !parentNode()->hasEditableStyle()) 2126 return hasElementFlag(TabIndexWasSetExplicitly) || (hasEditableStyle() && pa rentNode() && !parentNode()->hasEditableStyle())
2126 || supportsSpatialNavigationFocus(); 2127 || supportsSpatialNavigationFocus();
2127 } 2128 }
2128 2129
2130 bool Element::shouldHaveFocusAppearance() const
2131 {
2132 ASSERT(focused());
2133 return shouldShowFocusRingOnMouseFocus() || !m_wasFocusedByMouse;
2134 }
2135
2129 bool Element::supportsSpatialNavigationFocus() const 2136 bool Element::supportsSpatialNavigationFocus() const
2130 { 2137 {
2131 // This function checks whether the element satisfies the extended criteria 2138 // This function checks whether the element satisfies the extended criteria
2132 // for the element to be focusable, introduced by spatial navigation feature , 2139 // for the element to be focusable, introduced by spatial navigation feature ,
2133 // i.e. checks if click or keyboard event handler is specified. 2140 // i.e. checks if click or keyboard event handler is specified.
2134 // This is the way to make it possible to navigate to (focus) elements 2141 // This is the way to make it possible to navigate to (focus) elements
2135 // which web designer meant for being active (made them respond to click eve nts). 2142 // which web designer meant for being active (made them respond to click eve nts).
2136 2143
2137 if (!document().settings() || !document().settings()->spatialNavigationEnabl ed()) 2144 if (!document().settings() || !document().settings()->spatialNavigationEnabl ed())
2138 return false; 2145 return false;
(...skipping 18 matching lines...) Expand all
2157 bool Element::isKeyboardFocusable() const 2164 bool Element::isKeyboardFocusable() const
2158 { 2165 {
2159 return isFocusable() && tabIndex() >= 0; 2166 return isFocusable() && tabIndex() >= 0;
2160 } 2167 }
2161 2168
2162 bool Element::isMouseFocusable() const 2169 bool Element::isMouseFocusable() const
2163 { 2170 {
2164 return isFocusable(); 2171 return isFocusable();
2165 } 2172 }
2166 2173
2167 void Element::dispatchFocusEvent(Element* oldFocusedElement, FocusType) 2174 void Element::willCallDefaultEventHandler(const Event& event)
2168 { 2175 {
2176 if (!m_wasFocusedByMouse)
2177 return;
2178 if (!event.isKeyboardEvent() || event.type() != EventTypeNames::keydown)
2179 return;
2180 m_wasFocusedByMouse = false;
2181 // Focus changes could affect the focus ring appearance if the focus ring is not shown by default on mouse focus.
2182 if (!shouldShowFocusRingOnMouseFocus() && renderer())
2183 renderer()->setShouldDoFullPaintInvalidation(true);
2184 }
2185
2186 void Element::dispatchFocusEvent(Element* oldFocusedElement, FocusType type)
2187 {
2188 if (type != FocusTypePage)
2189 m_wasFocusedByMouse = type == FocusTypeMouse;
2190
2169 RefPtrWillBeRawPtr<FocusEvent> event = FocusEvent::create(EventTypeNames::fo cus, false, false, document().domWindow(), 0, oldFocusedElement); 2191 RefPtrWillBeRawPtr<FocusEvent> event = FocusEvent::create(EventTypeNames::fo cus, false, false, document().domWindow(), 0, oldFocusedElement);
2170 EventDispatcher::dispatchEvent(this, FocusEventDispatchMediator::create(even t.release())); 2192 EventDispatcher::dispatchEvent(this, FocusEventDispatchMediator::create(even t.release()));
2171 } 2193 }
2172 2194
2173 void Element::dispatchBlurEvent(Element* newFocusedElement) 2195 void Element::dispatchBlurEvent(Element* newFocusedElement)
2174 { 2196 {
2175 RefPtrWillBeRawPtr<FocusEvent> event = FocusEvent::create(EventTypeNames::bl ur, false, false, document().domWindow(), 0, newFocusedElement); 2197 RefPtrWillBeRawPtr<FocusEvent> event = FocusEvent::create(EventTypeNames::bl ur, false, false, document().domWindow(), 0, newFocusedElement);
2176 EventDispatcher::dispatchEvent(this, BlurEventDispatchMediator::create(event .release())); 2198 EventDispatcher::dispatchEvent(this, BlurEventDispatchMediator::create(event .release()));
2177 } 2199 }
2178 2200
(...skipping 1069 matching lines...) Expand 10 before | Expand all | Expand 10 after
3248 { 3270 {
3249 #if ENABLE(OILPAN) 3271 #if ENABLE(OILPAN)
3250 if (hasRareData()) 3272 if (hasRareData())
3251 visitor->trace(elementRareData()); 3273 visitor->trace(elementRareData());
3252 visitor->trace(m_elementData); 3274 visitor->trace(m_elementData);
3253 #endif 3275 #endif
3254 ContainerNode::trace(visitor); 3276 ContainerNode::trace(visitor);
3255 } 3277 }
3256 3278
3257 } // namespace blink 3279 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698