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

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: Move m_wasFocusedByMouse to elementData().m_shouldHideFocusRingOnMouseFocus Created 6 years, 3 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 2108 matching lines...) Expand 10 before | Expand all | Expand 10 after
2119 { 2119 {
2120 // FIXME: supportsFocus() can be called when layout is not up to date. 2120 // FIXME: supportsFocus() can be called when layout is not up to date.
2121 // Logic that deals with the renderer should be moved to rendererIsFocusable (). 2121 // Logic that deals with the renderer should be moved to rendererIsFocusable ().
2122 // But supportsFocus must return true when the element is editable, or else 2122 // But supportsFocus must return true when the element is editable, or else
2123 // it won't be focusable. Furthermore, supportsFocus cannot just return true 2123 // it won't be focusable. Furthermore, supportsFocus cannot just return true
2124 // always or else tabIndex() will change for all HTML elements. 2124 // always or else tabIndex() will change for all HTML elements.
2125 return hasElementFlag(TabIndexWasSetExplicitly) || (hasEditableStyle() && pa rentNode() && !parentNode()->hasEditableStyle()) 2125 return hasElementFlag(TabIndexWasSetExplicitly) || (hasEditableStyle() && pa rentNode() && !parentNode()->hasEditableStyle())
2126 || supportsSpatialNavigationFocus(); 2126 || supportsSpatialNavigationFocus();
2127 } 2127 }
2128 2128
2129 bool Element::shouldHaveFocusAppearance() const
2130 {
2131 ASSERT(focused());
2132 return shouldShowFocusRingOnMouseFocus() || !shouldHideFocusRingOnMouseFocus ();
2133 }
2134
2129 bool Element::supportsSpatialNavigationFocus() const 2135 bool Element::supportsSpatialNavigationFocus() const
2130 { 2136 {
2131 // This function checks whether the element satisfies the extended criteria 2137 // This function checks whether the element satisfies the extended criteria
2132 // for the element to be focusable, introduced by spatial navigation feature , 2138 // for the element to be focusable, introduced by spatial navigation feature ,
2133 // i.e. checks if click or keyboard event handler is specified. 2139 // 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 2140 // 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). 2141 // which web designer meant for being active (made them respond to click eve nts).
2136 2142
2137 if (!document().settings() || !document().settings()->spatialNavigationEnabl ed()) 2143 if (!document().settings() || !document().settings()->spatialNavigationEnabl ed())
2138 return false; 2144 return false;
(...skipping 18 matching lines...) Expand all
2157 bool Element::isKeyboardFocusable() const 2163 bool Element::isKeyboardFocusable() const
2158 { 2164 {
2159 return isFocusable() && tabIndex() >= 0; 2165 return isFocusable() && tabIndex() >= 0;
2160 } 2166 }
2161 2167
2162 bool Element::isMouseFocusable() const 2168 bool Element::isMouseFocusable() const
2163 { 2169 {
2164 return isFocusable(); 2170 return isFocusable();
2165 } 2171 }
2166 2172
2167 void Element::dispatchFocusEvent(Element* oldFocusedElement, FocusType) 2173 void Element::willCallDefaultEventHandler(const Event& event)
2168 { 2174 {
2175 if (!event.isKeyboardEvent() || event.type() != EventTypeNames::keydown)
2176 return;
2177 if (!shouldHideFocusRingOnMouseFocus())
2178 return;
2179
2180 ensureUniqueElementData().m_shouldHideFocusRingOnMouseFocus = false;
2181 // Focus changes could affect the focus ring appearance if the focus ring is not shown by default on mouse focus.
2182 if (renderer())
2183 renderer()->setShouldDoFullPaintInvalidation(true);
2184 }
2185
2186 void Element::dispatchFocusEvent(Element* oldFocusedElement, FocusType type)
2187 {
2188 if (type != FocusTypePage && !shouldShowFocusRingOnMouseFocus())
2189 ensureUniqueElementData().m_shouldHideFocusRingOnMouseFocus = type == Fo cusTypeMouse;
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