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

Side by Side Diff: third_party/WebKit/Source/core/html/HTMLOptionElement.cpp

Issue 2450093005: Support display: contents for elements, first-line and first-letter pseudos. (Closed)
Patch Set: Support display: contents for elements, first-line and first-letter pseudos. Created 4 years, 1 month 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 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) 5 * (C) 2006 Alexey Proskuryakov (ap@nypop.com)
6 * Copyright (C) 2004, 2005, 2006, 2010 Apple Inc. All rights reserved. 6 * Copyright (C) 2004, 2005, 2006, 2010 Apple Inc. All rights reserved.
7 * Copyright (C) 2010 Google Inc. All rights reserved. 7 * Copyright (C) 2010 Google Inc. All rights reserved.
8 * Copyright (C) 2011 Motorola Mobility, Inc. All rights reserved. 8 * Copyright (C) 2011 Motorola Mobility, Inc. All rights reserved.
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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 element->setValue(value); 83 element->setValue(value);
84 if (defaultSelected) 84 if (defaultSelected)
85 element->setAttribute(selectedAttr, emptyAtom); 85 element->setAttribute(selectedAttr, emptyAtom);
86 element->setSelected(selected); 86 element->setSelected(selected);
87 87
88 return element; 88 return element;
89 } 89 }
90 90
91 void HTMLOptionElement::attachLayoutTree(const AttachContext& context) { 91 void HTMLOptionElement::attachLayoutTree(const AttachContext& context) {
92 AttachContext optionContext(context); 92 AttachContext optionContext(context);
93 if (context.resolvedStyle) { 93 RefPtr<ComputedStyle> resolvedStyle;
94 DCHECK(!m_style || m_style == context.resolvedStyle); 94 if (!context.resolvedStyle && parentComputedStyle()) {
95 m_style = context.resolvedStyle; 95 if (HTMLSelectElement* select = ownerSelectElement())
96 } else if (parentComputedStyle()) { 96 select->updateListOnLayoutObject();
97 updateNonComputedStyle(); 97 resolvedStyle = originalStyleForLayoutObject();
98 optionContext.resolvedStyle = m_style.get(); 98 optionContext.resolvedStyle = resolvedStyle.get();
99 } 99 }
100 HTMLElement::attachLayoutTree(optionContext); 100 HTMLElement::attachLayoutTree(optionContext);
101 } 101 }
102 102
103 void HTMLOptionElement::detachLayoutTree(const AttachContext& context) { 103 void HTMLOptionElement::detachLayoutTree(const AttachContext& context) {
104 m_style.clear();
105 HTMLElement::detachLayoutTree(context); 104 HTMLElement::detachLayoutTree(context);
106 } 105 }
107 106
108 bool HTMLOptionElement::supportsFocus() const { 107 bool HTMLOptionElement::supportsFocus() const {
109 HTMLSelectElement* select = ownerSelectElement(); 108 HTMLSelectElement* select = ownerSelectElement();
110 if (select && select->usesMenuList()) 109 if (select && select->usesMenuList())
111 return false; 110 return false;
112 return HTMLElement::supportsFocus(); 111 return HTMLElement::supportsFocus();
113 } 112 }
114 113
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 return label; 322 return label;
324 return collectOptionInnerText() 323 return collectOptionInnerText()
325 .stripWhiteSpace(isHTMLSpace<UChar>) 324 .stripWhiteSpace(isHTMLSpace<UChar>)
326 .simplifyWhiteSpace(isHTMLSpace<UChar>); 325 .simplifyWhiteSpace(isHTMLSpace<UChar>);
327 } 326 }
328 327
329 void HTMLOptionElement::setLabel(const AtomicString& label) { 328 void HTMLOptionElement::setLabel(const AtomicString& label) {
330 setAttribute(labelAttr, label); 329 setAttribute(labelAttr, label);
331 } 330 }
332 331
333 void HTMLOptionElement::updateNonComputedStyle() {
334 m_style = originalStyleForLayoutObject();
335 if (HTMLSelectElement* select = ownerSelectElement())
336 select->updateListOnLayoutObject();
337 }
338
339 ComputedStyle* HTMLOptionElement::nonLayoutObjectComputedStyle() const {
340 return m_style.get();
341 }
342
343 PassRefPtr<ComputedStyle> HTMLOptionElement::customStyleForLayoutObject() {
344 updateNonComputedStyle();
345 return m_style;
346 }
347
348 String HTMLOptionElement::textIndentedToRespectGroupLabel() const { 332 String HTMLOptionElement::textIndentedToRespectGroupLabel() const {
349 ContainerNode* parent = parentNode(); 333 ContainerNode* parent = parentNode();
350 if (parent && isHTMLOptGroupElement(*parent)) 334 if (parent && isHTMLOptGroupElement(*parent))
351 return " " + displayLabel(); 335 return " " + displayLabel();
352 return displayLabel(); 336 return displayLabel();
353 } 337 }
354 338
355 bool HTMLOptionElement::ownElementDisabled() const { 339 bool HTMLOptionElement::ownElementDisabled() const {
356 return fastHasAttribute(disabledAttr); 340 return fastHasAttribute(disabledAttr);
357 } 341 }
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 } 408 }
425 409
426 bool HTMLOptionElement::spatialNavigationFocused() const { 410 bool HTMLOptionElement::spatialNavigationFocused() const {
427 HTMLSelectElement* select = ownerSelectElement(); 411 HTMLSelectElement* select = ownerSelectElement();
428 if (!select || !select->isFocused()) 412 if (!select || !select->isFocused())
429 return false; 413 return false;
430 return select->spatialNavigationFocusedOption() == this; 414 return select->spatialNavigationFocusedOption() == this;
431 } 415 }
432 416
433 bool HTMLOptionElement::isDisplayNone() const { 417 bool HTMLOptionElement::isDisplayNone() const {
434 // If m_style is not set, then the node is still unattached. 418 // If the style is not set, then the node is still unattached.
435 // We have to wait till it gets attached to read the display property. 419 // We have to wait till it gets attached to read the display property.
436 if (!m_style) 420 const ComputedStyle* style = nonLayoutObjectComputedStyle();
421 if (!style)
437 return false; 422 return false;
438 423
439 if (m_style->display() != EDisplay::None) { 424 if (style->display() != EDisplay::None) {
440 // We need to check the parent's display property. Parent's 425 // We need to check the parent's display property. Parent's
441 // display:none doesn't override children's display properties in 426 // display:none doesn't override children's display properties in
442 // ComputedStyle. 427 // ComputedStyle.
443 Element* parent = parentElement(); 428 Element* parent = parentElement();
444 DCHECK(parent); 429 DCHECK(parent);
445 if (isHTMLOptGroupElement(*parent)) { 430 if (isHTMLOptGroupElement(*parent)) {
446 const ComputedStyle* parentStyle = parent->computedStyle() 431 const ComputedStyle* parentStyle = parent->computedStyle()
447 ? parent->computedStyle() 432 ? parent->computedStyle()
448 : parent->ensureComputedStyle(); 433 : parent->ensureComputedStyle();
449 return !parentStyle || parentStyle->display() == EDisplay::None; 434 return !parentStyle || parentStyle->display() == EDisplay::None;
450 } 435 }
451 } 436 }
452 return m_style->display() == EDisplay::None; 437 return style->display() == EDisplay::None;
453 } 438 }
454 439
455 String HTMLOptionElement::innerText() { 440 String HTMLOptionElement::innerText() {
456 // A workaround for crbug.com/424578. We add ShadowRoot to an OPTION, but 441 // A workaround for crbug.com/424578. We add ShadowRoot to an OPTION, but
457 // innerText behavior for Shadow DOM is unclear. We just return the same 442 // innerText behavior for Shadow DOM is unclear. We just return the same
458 // string before adding ShadowRoot. 443 // string before adding ShadowRoot.
459 return textContent(); 444 return textContent();
460 } 445 }
461 446
462 } // namespace blink 447 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698