| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "core/html/shadow/AppearanceSwitchElement.h" | |
| 6 | |
| 7 #include "core/dom/NodeComputedStyle.h" | |
| 8 | |
| 9 namespace blink { | |
| 10 | |
| 11 inline AppearanceSwitchElement::AppearanceSwitchElement(Document& doc, Mode mode
) | |
| 12 : HTMLDivElement(doc) | |
| 13 , m_mode(mode) | |
| 14 { | |
| 15 setHasCustomStyleCallbacks(); | |
| 16 } | |
| 17 | |
| 18 AppearanceSwitchElement* AppearanceSwitchElement::create(Document& doc, Mode mod
e) | |
| 19 { | |
| 20 return new AppearanceSwitchElement(doc, mode); | |
| 21 } | |
| 22 | |
| 23 PassRefPtr<ComputedStyle> AppearanceSwitchElement::customStyleForLayoutObject() | |
| 24 { | |
| 25 // We can't use setInlineStyleProperty() because it updates the DOM tree. | |
| 26 // We shouldn't do it during style calculation. | |
| 27 // TODO(tkent): Injecting a CSS variable by host is a better approach? | |
| 28 Element* host = shadowHost(); | |
| 29 RefPtr<ComputedStyle> style = originalStyleForLayoutObject(); | |
| 30 if (!host || !host->computedStyle()) | |
| 31 return style.release(); | |
| 32 if (m_mode == ShowIfHostHasAppearance) { | |
| 33 if (host->computedStyle()->hasAppearance()) | |
| 34 return style.release(); | |
| 35 } else { | |
| 36 if (!host->computedStyle()->hasAppearance()) | |
| 37 return style.release(); | |
| 38 } | |
| 39 if (style->display() == NONE) | |
| 40 return style.release(); | |
| 41 RefPtr<ComputedStyle> newStyle = ComputedStyle::clone(*style); | |
| 42 newStyle->setDisplay(NONE); | |
| 43 newStyle->setUnique(); | |
| 44 return newStyle.release(); | |
| 45 } | |
| 46 | |
| 47 } // namespace blink | |
| OLD | NEW |