| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2008 Nuanti Ltd. | 3 * Copyright (C) 2008 Nuanti Ltd. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 : m_rootNode(treeScope.rootNode()) | 105 : m_rootNode(treeScope.rootNode()) |
| 106 , m_rootSlot(nullptr) | 106 , m_rootSlot(nullptr) |
| 107 , m_current(const_cast<Element*>(current)) | 107 , m_current(const_cast<Element*>(current)) |
| 108 { | 108 { |
| 109 } | 109 } |
| 110 | 110 |
| 111 ScopedFocusNavigation::ScopedFocusNavigation(HTMLSlotElement& slot, const Elemen
t* current) | 111 ScopedFocusNavigation::ScopedFocusNavigation(HTMLSlotElement& slot, const Elemen
t* current) |
| 112 : m_rootNode(nullptr) | 112 : m_rootNode(nullptr) |
| 113 , m_rootSlot(&slot) | 113 , m_rootSlot(&slot) |
| 114 , m_current(const_cast<Element*>(current)) | 114 , m_current(const_cast<Element*>(current)) |
| 115 , m_slotFallbackTraversal(slot.getAssignedNodes().isEmpty()) | 115 , m_slotFallbackTraversal(slot.assignedNodes().isEmpty()) |
| 116 { | 116 { |
| 117 } | 117 } |
| 118 | 118 |
| 119 Element* ScopedFocusNavigation::currentElement() const | 119 Element* ScopedFocusNavigation::currentElement() const |
| 120 { | 120 { |
| 121 return m_current; | 121 return m_current; |
| 122 } | 122 } |
| 123 | 123 |
| 124 void ScopedFocusNavigation::setCurrentElement(Element* element) | 124 void ScopedFocusNavigation::setCurrentElement(Element* element) |
| 125 { | 125 { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 m_current = ElementTraversal::previous(*m_current); | 161 m_current = ElementTraversal::previous(*m_current); |
| 162 while (m_current && (SlotScopedTraversal::isSlotScoped(*m_current) || Sc
opedFocusNavigation::isSlotFallbackScoped(*m_current))) | 162 while (m_current && (SlotScopedTraversal::isSlotScoped(*m_current) || Sc
opedFocusNavigation::isSlotFallbackScoped(*m_current))) |
| 163 m_current = ElementTraversal::previous(*m_current); | 163 m_current = ElementTraversal::previous(*m_current); |
| 164 } | 164 } |
| 165 } | 165 } |
| 166 | 166 |
| 167 void ScopedFocusNavigation::moveToFirst() | 167 void ScopedFocusNavigation::moveToFirst() |
| 168 { | 168 { |
| 169 if (m_rootSlot) { | 169 if (m_rootSlot) { |
| 170 if (!m_slotFallbackTraversal) { | 170 if (!m_slotFallbackTraversal) { |
| 171 HeapVector<Member<Node>> assignedNodes = m_rootSlot->getAssignedNode
s(); | 171 HeapVector<Member<Node>> assignedNodes = m_rootSlot->assignedNodes()
; |
| 172 for (auto assignedNode : assignedNodes) { | 172 for (auto assignedNode : assignedNodes) { |
| 173 if (assignedNode->isElementNode()) { | 173 if (assignedNode->isElementNode()) { |
| 174 m_current = toElement(assignedNode); | 174 m_current = toElement(assignedNode); |
| 175 break; | 175 break; |
| 176 } | 176 } |
| 177 } | 177 } |
| 178 } else { | 178 } else { |
| 179 Element* first = ElementTraversal::firstChild(*m_rootSlot); | 179 Element* first = ElementTraversal::firstChild(*m_rootSlot); |
| 180 while (first && !ScopedFocusNavigation::isSlotFallbackScopedForThisS
lot(*m_rootSlot, *first)) | 180 while (first && !ScopedFocusNavigation::isSlotFallbackScopedForThisS
lot(*m_rootSlot, *first)) |
| 181 first = ElementTraversal::next(*first, m_rootSlot); | 181 first = ElementTraversal::next(*first, m_rootSlot); |
| 182 m_current = first; | 182 m_current = first; |
| 183 } | 183 } |
| 184 } else { | 184 } else { |
| 185 Element* first = m_rootNode->isElementNode() ? &toElement(*m_rootNode) :
ElementTraversal::next(*m_rootNode); | 185 Element* first = m_rootNode->isElementNode() ? &toElement(*m_rootNode) :
ElementTraversal::next(*m_rootNode); |
| 186 while (first && (SlotScopedTraversal::isSlotScoped(*first) || ScopedFocu
sNavigation::isSlotFallbackScoped(*first))) | 186 while (first && (SlotScopedTraversal::isSlotScoped(*first) || ScopedFocu
sNavigation::isSlotFallbackScoped(*first))) |
| 187 first = ElementTraversal::next(*first, m_rootNode); | 187 first = ElementTraversal::next(*first, m_rootNode); |
| 188 m_current = first; | 188 m_current = first; |
| 189 } | 189 } |
| 190 | 190 |
| 191 } | 191 } |
| 192 | 192 |
| 193 void ScopedFocusNavigation::moveToLast() | 193 void ScopedFocusNavigation::moveToLast() |
| 194 { | 194 { |
| 195 if (m_rootSlot) { | 195 if (m_rootSlot) { |
| 196 if (!m_slotFallbackTraversal) { | 196 if (!m_slotFallbackTraversal) { |
| 197 HeapVector<Member<Node>> assignedNodes = m_rootSlot->getAssignedNode
s(); | 197 HeapVector<Member<Node>> assignedNodes = m_rootSlot->assignedNodes()
; |
| 198 for (auto assignedNode = assignedNodes.rbegin(); assignedNode != ass
ignedNodes.rend(); ++assignedNode) { | 198 for (auto assignedNode = assignedNodes.rbegin(); assignedNode != ass
ignedNodes.rend(); ++assignedNode) { |
| 199 if ((*assignedNode)->isElementNode()) { | 199 if ((*assignedNode)->isElementNode()) { |
| 200 m_current = ElementTraversal::lastWithinOrSelf(*toElement(*a
ssignedNode)); | 200 m_current = ElementTraversal::lastWithinOrSelf(*toElement(*a
ssignedNode)); |
| 201 break; | 201 break; |
| 202 } | 202 } |
| 203 } | 203 } |
| 204 } else { | 204 } else { |
| 205 Element* last = ElementTraversal::lastWithin(*m_rootSlot); | 205 Element* last = ElementTraversal::lastWithin(*m_rootSlot); |
| 206 while (last && !ScopedFocusNavigation::isSlotFallbackScopedForThisSl
ot(*m_rootSlot, *last)) | 206 while (last && !ScopedFocusNavigation::isSlotFallbackScopedForThisSl
ot(*m_rootSlot, *last)) |
| 207 last = ElementTraversal::previous(*last, m_rootSlot); | 207 last = ElementTraversal::previous(*last, m_rootSlot); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 ScopedFocusNavigation ScopedFocusNavigation::ownedByHTMLSlotElement(const HTMLSl
otElement& element) | 277 ScopedFocusNavigation ScopedFocusNavigation::ownedByHTMLSlotElement(const HTMLSl
otElement& element) |
| 278 { | 278 { |
| 279 return ScopedFocusNavigation(const_cast<HTMLSlotElement&>(element), nullptr)
; | 279 return ScopedFocusNavigation(const_cast<HTMLSlotElement&>(element), nullptr)
; |
| 280 } | 280 } |
| 281 | 281 |
| 282 HTMLSlotElement* ScopedFocusNavigation::findFallbackScopeOwnerSlot(const Element
& element) | 282 HTMLSlotElement* ScopedFocusNavigation::findFallbackScopeOwnerSlot(const Element
& element) |
| 283 { | 283 { |
| 284 Element* parent = const_cast<Element*>(element.parentElement()); | 284 Element* parent = const_cast<Element*>(element.parentElement()); |
| 285 while (parent) { | 285 while (parent) { |
| 286 if (isHTMLSlotElement(parent)) | 286 if (isHTMLSlotElement(parent)) |
| 287 return toHTMLSlotElement(parent)->getAssignedNodes().isEmpty() ? toH
TMLSlotElement(parent) : nullptr; | 287 return toHTMLSlotElement(parent)->assignedNodes().isEmpty() ? toHTML
SlotElement(parent) : nullptr; |
| 288 parent = parent->parentElement(); | 288 parent = parent->parentElement(); |
| 289 } | 289 } |
| 290 return nullptr; | 290 return nullptr; |
| 291 } | 291 } |
| 292 | 292 |
| 293 bool ScopedFocusNavigation::isSlotFallbackScoped(const Element& element) | 293 bool ScopedFocusNavigation::isSlotFallbackScoped(const Element& element) |
| 294 { | 294 { |
| 295 return ScopedFocusNavigation::findFallbackScopeOwnerSlot(element); | 295 return ScopedFocusNavigation::findFallbackScopeOwnerSlot(element); |
| 296 } | 296 } |
| 297 | 297 |
| 298 bool ScopedFocusNavigation::isSlotFallbackScopedForThisSlot(const HTMLSlotElemen
t& slot, const Element& current) | 298 bool ScopedFocusNavigation::isSlotFallbackScopedForThisSlot(const HTMLSlotElemen
t& slot, const Element& current) |
| 299 { | 299 { |
| 300 Element* parent = current.parentElement(); | 300 Element* parent = current.parentElement(); |
| 301 while (parent) { | 301 while (parent) { |
| 302 if (isHTMLSlotElement(parent) && toHTMLSlotElement(parent)->getAssignedN
odes().isEmpty()) | 302 if (isHTMLSlotElement(parent) && toHTMLSlotElement(parent)->assignedNode
s().isEmpty()) |
| 303 return !SlotScopedTraversal::isSlotScoped(current) && toHTMLSlotElem
ent(parent) == slot; | 303 return !SlotScopedTraversal::isSlotScoped(current) && toHTMLSlotElem
ent(parent) == slot; |
| 304 parent = parent->parentElement(); | 304 parent = parent->parentElement(); |
| 305 } | 305 } |
| 306 return false; | 306 return false; |
| 307 } | 307 } |
| 308 | 308 |
| 309 inline void dispatchBlurEvent(const Document& document, Element& focusedElement) | 309 inline void dispatchBlurEvent(const Document& document, Element& focusedElement) |
| 310 { | 310 { |
| 311 focusedElement.dispatchBlurEvent(nullptr, WebFocusTypePage); | 311 focusedElement.dispatchBlurEvent(nullptr, WebFocusTypePage); |
| 312 if (focusedElement == document.focusedElement()) { | 312 if (focusedElement == document.focusedElement()) { |
| (...skipping 993 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1306 return consumed; | 1306 return consumed; |
| 1307 } | 1307 } |
| 1308 | 1308 |
| 1309 DEFINE_TRACE(FocusController) | 1309 DEFINE_TRACE(FocusController) |
| 1310 { | 1310 { |
| 1311 visitor->trace(m_page); | 1311 visitor->trace(m_page); |
| 1312 visitor->trace(m_focusedFrame); | 1312 visitor->trace(m_focusedFrame); |
| 1313 } | 1313 } |
| 1314 | 1314 |
| 1315 } // namespace blink | 1315 } // namespace blink |
| OLD | NEW |