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

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

Issue 2586143004: Blur immediately if an attribute change made an element unfocasable. (Closed)
Patch Set: Update comments and a function name Created 4 years 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 1292 matching lines...) Expand 10 before | Expand all | Expand 10 after
1303 // If there is currently no StyleResolver, we can't be sure that this 1303 // If there is currently no StyleResolver, we can't be sure that this
1304 // attribute change won't affect style. 1304 // attribute change won't affect style.
1305 if (!document().styleResolver()) 1305 if (!document().styleResolver())
1306 setNeedsStyleRecalc(SubtreeStyleChange, 1306 setNeedsStyleRecalc(SubtreeStyleChange,
1307 StyleChangeReasonForTracing::fromAttribute(name)); 1307 StyleChangeReasonForTracing::fromAttribute(name));
1308 1308
1309 if (isConnected()) { 1309 if (isConnected()) {
1310 if (AXObjectCache* cache = document().existingAXObjectCache()) 1310 if (AXObjectCache* cache = document().existingAXObjectCache())
1311 cache->handleAttributeChanged(name, this); 1311 cache->handleAttributeChanged(name, this);
1312 } 1312 }
1313
1314 if (reason == AttributeModificationReason::kDirectly &&
1315 name == tabindexAttr && adjustedFocusedElementInTreeScope() == this) {
1316 // The attribute change may cause supportsFocus() to return false
1317 // for the element which had focus.
1318 //
1319 // TODO(tkent): We should avoid updating style. We'd like to check only
1320 // DOM-level focusability here.
1321 document().updateStyleAndLayoutTreeForNode(this);
1322 if (!supportsFocus())
1323 blur();
1324 }
1313 } 1325 }
1314 1326
1315 bool Element::hasLegalLinkAttribute(const QualifiedName&) const { 1327 bool Element::hasLegalLinkAttribute(const QualifiedName&) const {
1316 return false; 1328 return false;
1317 } 1329 }
1318 1330
1319 const QualifiedName& Element::subResourceAttributeName() const { 1331 const QualifiedName& Element::subResourceAttributeName() const {
1320 return QualifiedName::null(); 1332 return QualifiedName::null();
1321 } 1333 }
1322 1334
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
1481 ->cachedShareableElementDataWithAttributes(attributeVector); 1493 ->cachedShareableElementDataWithAttributes(attributeVector);
1482 else 1494 else
1483 m_elementData = 1495 m_elementData =
1484 ShareableElementData::createWithAttributes(attributeVector); 1496 ShareableElementData::createWithAttributes(attributeVector);
1485 } 1497 }
1486 1498
1487 parserDidSetAttributes(); 1499 parserDidSetAttributes();
1488 1500
1489 // Use attributeVector instead of m_elementData because attributeChanged might 1501 // Use attributeVector instead of m_elementData because attributeChanged might
1490 // modify m_elementData. 1502 // modify m_elementData.
1491 for (const auto& attribute : attributeVector) 1503 for (const auto& attribute : attributeVector) {
1492 attributeChangedFromParserOrByCloning(attribute.name(), attribute.value(), 1504 attributeChangedFromParserOrByCloning(
1493 ModifiedDirectly); 1505 attribute.name(), attribute.value(),
1506 AttributeModificationReason::kByParser);
1507 }
1494 } 1508 }
1495 1509
1496 bool Element::hasEquivalentAttributes(const Element* other) const { 1510 bool Element::hasEquivalentAttributes(const Element* other) const {
1497 synchronizeAllAttributes(); 1511 synchronizeAllAttributes();
1498 other->synchronizeAllAttributes(); 1512 other->synchronizeAllAttributes();
1499 if (elementData() == other->elementData()) 1513 if (elementData() == other->elementData())
1500 return true; 1514 return true;
1501 if (elementData()) 1515 if (elementData())
1502 return elementData()->isEquivalent(other->elementData()); 1516 return elementData()->isEquivalent(other->elementData());
1503 if (other->elementData()) 1517 if (other->elementData())
(...skipping 933 matching lines...) Expand 10 before | Expand all | Expand 10 after
2437 return attr; 2451 return attr;
2438 } 2452 }
2439 2453
2440 void Element::parseAttribute(const QualifiedName& name, 2454 void Element::parseAttribute(const QualifiedName& name,
2441 const AtomicString&, 2455 const AtomicString&,
2442 const AtomicString& value) { 2456 const AtomicString& value) {
2443 if (name == tabindexAttr) { 2457 if (name == tabindexAttr) {
2444 int tabindex = 0; 2458 int tabindex = 0;
2445 if (value.isEmpty() || !parseHTMLInteger(value, tabindex)) { 2459 if (value.isEmpty() || !parseHTMLInteger(value, tabindex)) {
2446 clearTabIndexExplicitlyIfNeeded(); 2460 clearTabIndexExplicitlyIfNeeded();
2447 if (adjustedFocusedElementInTreeScope() == this) {
2448 // We might want to call blur(), but it's dangerous to dispatch
2449 // events here.
2450 document().setNeedsFocusedElementCheck();
2451 }
2452 } else { 2461 } else {
2453 // We only set when value is in integer range. 2462 // We only set when value is in integer range.
2454 setTabIndexExplicitly(); 2463 setTabIndexExplicitly();
2455 } 2464 }
2456 } else if (name == XMLNames::langAttr) { 2465 } else if (name == XMLNames::langAttr) {
2457 pseudoStateChanged(CSSSelector::PseudoLang); 2466 pseudoStateChanged(CSSSelector::PseudoLang);
2458 } 2467 }
2459 } 2468 }
2460 2469
2461 bool Element::parseAttributeName(QualifiedName& out, 2470 bool Element::parseAttributeName(QualifiedName& out,
(...skipping 1058 matching lines...) Expand 10 before | Expand all | Expand 10 after
3520 MutationRecord::createAttributes(this, name, oldValue)); 3529 MutationRecord::createAttributes(this, name, oldValue));
3521 3530
3522 InspectorInstrumentation::willModifyDOMAttr(this, oldValue, newValue); 3531 InspectorInstrumentation::willModifyDOMAttr(this, oldValue, newValue);
3523 } 3532 }
3524 3533
3525 DISABLE_CFI_PERF 3534 DISABLE_CFI_PERF
3526 void Element::didAddAttribute(const QualifiedName& name, 3535 void Element::didAddAttribute(const QualifiedName& name,
3527 const AtomicString& value) { 3536 const AtomicString& value) {
3528 if (name == HTMLNames::idAttr) 3537 if (name == HTMLNames::idAttr)
3529 updateId(nullAtom, value); 3538 updateId(nullAtom, value);
3530 attributeChanged(name, nullAtom, value); 3539 attributeChanged(name, nullAtom, value,
3540 AttributeModificationReason::kDirectly);
3531 InspectorInstrumentation::didModifyDOMAttr(this, name, value); 3541 InspectorInstrumentation::didModifyDOMAttr(this, name, value);
3532 dispatchSubtreeModifiedEvent(); 3542 dispatchSubtreeModifiedEvent();
3533 } 3543 }
3534 3544
3535 void Element::didModifyAttribute(const QualifiedName& name, 3545 void Element::didModifyAttribute(const QualifiedName& name,
3536 const AtomicString& oldValue, 3546 const AtomicString& oldValue,
3537 const AtomicString& newValue) { 3547 const AtomicString& newValue) {
3538 if (name == HTMLNames::idAttr) 3548 if (name == HTMLNames::idAttr)
3539 updateId(oldValue, newValue); 3549 updateId(oldValue, newValue);
3540 attributeChanged(name, oldValue, newValue); 3550 attributeChanged(name, oldValue, newValue,
3551 AttributeModificationReason::kDirectly);
3541 InspectorInstrumentation::didModifyDOMAttr(this, name, newValue); 3552 InspectorInstrumentation::didModifyDOMAttr(this, name, newValue);
3542 // Do not dispatch a DOMSubtreeModified event here; see bug 81141. 3553 // Do not dispatch a DOMSubtreeModified event here; see bug 81141.
3543 } 3554 }
3544 3555
3545 void Element::didRemoveAttribute(const QualifiedName& name, 3556 void Element::didRemoveAttribute(const QualifiedName& name,
3546 const AtomicString& oldValue) { 3557 const AtomicString& oldValue) {
3547 if (name == HTMLNames::idAttr) 3558 if (name == HTMLNames::idAttr)
3548 updateId(oldValue, nullAtom); 3559 updateId(oldValue, nullAtom);
3549 attributeChanged(name, oldValue, nullAtom); 3560 attributeChanged(name, oldValue, nullAtom,
3561 AttributeModificationReason::kDirectly);
3550 InspectorInstrumentation::didRemoveDOMAttr(this, name); 3562 InspectorInstrumentation::didRemoveDOMAttr(this, name);
3551 dispatchSubtreeModifiedEvent(); 3563 dispatchSubtreeModifiedEvent();
3552 } 3564 }
3553 3565
3554 static bool needsURLResolutionForInlineStyle(const Element& element, 3566 static bool needsURLResolutionForInlineStyle(const Element& element,
3555 const Document& oldDocument, 3567 const Document& oldDocument,
3556 const Document& newDocument) { 3568 const Document& newDocument) {
3557 if (oldDocument == newDocument) 3569 if (oldDocument == newDocument)
3558 return false; 3570 return false;
3559 if (oldDocument.baseURL() == newDocument.baseURL()) 3571 if (oldDocument.baseURL() == newDocument.baseURL())
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
3736 toUniqueElementData(other.m_elementData)->makeShareableCopy(); 3748 toUniqueElementData(other.m_elementData)->makeShareableCopy();
3737 3749
3738 if (!other.m_elementData->isUnique() && 3750 if (!other.m_elementData->isUnique() &&
3739 !ownerDocumentsHaveDifferentCaseSensitivity && 3751 !ownerDocumentsHaveDifferentCaseSensitivity &&
3740 !needsURLResolutionForInlineStyle(other, other.document(), document())) 3752 !needsURLResolutionForInlineStyle(other, other.document(), document()))
3741 m_elementData = other.m_elementData; 3753 m_elementData = other.m_elementData;
3742 else 3754 else
3743 m_elementData = other.m_elementData->makeUniqueCopy(); 3755 m_elementData = other.m_elementData->makeUniqueCopy();
3744 3756
3745 AttributeCollection attributes = m_elementData->attributes(); 3757 AttributeCollection attributes = m_elementData->attributes();
3746 for (const Attribute& attr : attributes) 3758 for (const Attribute& attr : attributes) {
3747 attributeChangedFromParserOrByCloning(attr.name(), attr.value(), 3759 attributeChangedFromParserOrByCloning(
3748 ModifiedByCloning); 3760 attr.name(), attr.value(), AttributeModificationReason::kByCloning);
3761 }
3749 } 3762 }
3750 3763
3751 void Element::cloneDataFromElement(const Element& other) { 3764 void Element::cloneDataFromElement(const Element& other) {
3752 cloneAttributesFromElement(other); 3765 cloneAttributesFromElement(other);
3753 copyNonAttributePropertiesFromElement(other); 3766 copyNonAttributePropertiesFromElement(other);
3754 } 3767 }
3755 3768
3756 void Element::createUniqueElementData() { 3769 void Element::createUniqueElementData() {
3757 if (!m_elementData) { 3770 if (!m_elementData) {
3758 m_elementData = UniqueElementData::create(); 3771 m_elementData = UniqueElementData::create();
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
3833 void Element::styleAttributeChanged( 3846 void Element::styleAttributeChanged(
3834 const AtomicString& newStyleString, 3847 const AtomicString& newStyleString,
3835 AttributeModificationReason modificationReason) { 3848 AttributeModificationReason modificationReason) {
3836 DCHECK(isStyledElement()); 3849 DCHECK(isStyledElement());
3837 WTF::OrdinalNumber startLineNumber = WTF::OrdinalNumber::beforeFirst(); 3850 WTF::OrdinalNumber startLineNumber = WTF::OrdinalNumber::beforeFirst();
3838 if (document().scriptableDocumentParser() && !document().isInDocumentWrite()) 3851 if (document().scriptableDocumentParser() && !document().isInDocumentWrite())
3839 startLineNumber = document().scriptableDocumentParser()->lineNumber(); 3852 startLineNumber = document().scriptableDocumentParser()->lineNumber();
3840 3853
3841 if (newStyleString.isNull()) { 3854 if (newStyleString.isNull()) {
3842 ensureUniqueElementData().m_inlineStyle.clear(); 3855 ensureUniqueElementData().m_inlineStyle.clear();
3843 } else if (modificationReason == ModifiedByCloning || 3856 } else if (modificationReason == AttributeModificationReason::kByCloning ||
3844 ContentSecurityPolicy::shouldBypassMainWorld(&document()) || 3857 ContentSecurityPolicy::shouldBypassMainWorld(&document()) ||
3845 (containingShadowRoot() && 3858 (containingShadowRoot() &&
3846 containingShadowRoot()->type() == ShadowRootType::UserAgent) || 3859 containingShadowRoot()->type() == ShadowRootType::UserAgent) ||
3847 document().contentSecurityPolicy()->allowInlineStyle( 3860 document().contentSecurityPolicy()->allowInlineStyle(
3848 this, document().url(), String(), startLineNumber, 3861 this, document().url(), String(), startLineNumber,
3849 newStyleString)) { 3862 newStyleString)) {
3850 setInlineStyleFromString(newStyleString); 3863 setInlineStyleFromString(newStyleString);
3851 } 3864 }
3852 3865
3853 elementData()->m_styleAttributeIsDirty = false; 3866 elementData()->m_styleAttributeIsDirty = false;
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
4091 } 4104 }
4092 4105
4093 DEFINE_TRACE_WRAPPERS(Element) { 4106 DEFINE_TRACE_WRAPPERS(Element) {
4094 if (hasRareData()) { 4107 if (hasRareData()) {
4095 visitor->traceWrappers(elementRareData()); 4108 visitor->traceWrappers(elementRareData());
4096 } 4109 }
4097 ContainerNode::traceWrappers(visitor); 4110 ContainerNode::traceWrappers(visitor);
4098 } 4111 }
4099 4112
4100 } // namespace blink 4113 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/Element.h ('k') | third_party/WebKit/Source/core/html/HTMLAnchorElement.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698