Chromium Code Reviews| OLD | NEW |
|---|---|
| 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) 2008 David Smith (catfish.man@gmail.com) | 5 * (C) 2008 David Smith (catfish.man@gmail.com) |
| 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. | 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. |
| 7 * | 7 * |
| 8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
| 9 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
| 10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
| 11 * version 2 of the License, or (at your option) any later version. | 11 * version 2 of the License, or (at your option) any later version. |
| 12 * | 12 * |
| 13 * This library is distributed in the hope that it will be useful, | 13 * This library is distributed in the hope that it will be useful, |
| 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 * Library General Public License for more details. | 16 * Library General Public License for more details. |
| 17 * | 17 * |
| 18 * You should have received a copy of the GNU Library General Public License | 18 * You should have received a copy of the GNU Library General Public License |
| 19 * along with this library; see the file COPYING.LIB. If not, write to | 19 * along with this library; see the file COPYING.LIB. If not, write to |
| 20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 21 * Boston, MA 02110-1301, USA. | 21 * Boston, MA 02110-1301, USA. |
| 22 * | 22 * |
| 23 */ | 23 */ |
| 24 | 24 |
| 25 #ifndef NodeComputedStyle_h | 25 #ifndef NodeComputedStyle_h |
| 26 #define NodeComputedStyle_h | 26 #define NodeComputedStyle_h |
| 27 | 27 |
| 28 #include "core/dom/LayoutTreeBuilderTraversal.h" | 28 #include "core/dom/LayoutTreeBuilderTraversal.h" |
| 29 #include "core/dom/Node.h" | 29 #include "core/dom/Node.h" |
| 30 #include "core/dom/NodeRareData.h" | |
| 30 #include "core/dom/shadow/InsertionPoint.h" | 31 #include "core/dom/shadow/InsertionPoint.h" |
| 31 #include "core/html/HTMLOptGroupElement.h" | 32 #include "core/html/HTMLOptGroupElement.h" |
| 32 #include "core/layout/LayoutObject.h" | 33 #include "core/layout/LayoutObject.h" |
| 33 #include "core/style/ComputedStyle.h" | 34 #include "core/style/ComputedStyle.h" |
| 34 | 35 |
| 35 namespace blink { | 36 namespace blink { |
| 36 | 37 |
| 37 inline const ComputedStyle* Node::computedStyle() const | 38 inline const ComputedStyle* Node::computedStyle() const |
| 38 { | 39 { |
| 39 return mutableComputedStyle(); | 40 return mutableComputedStyle(); |
| 40 } | 41 } |
| 41 | 42 |
| 42 inline ComputedStyle* Node::mutableComputedStyle() const | 43 inline ComputedStyle* Node::mutableComputedStyle() const |
| 43 { | 44 { |
| 44 if (LayoutObject* layoutObject = this->layoutObject()) | 45 if (hasLayoutObject()) |
| 45 return layoutObject->mutableStyle(); | 46 return layoutObject()->mutableStyle(); |
| 46 // <option> and <optgroup> can be styled even if they don't get layout objec ts, | 47 // <option> and <optgroup> can be styled even if they don't get layout objec ts, |
| 47 // so they store their style internally and return it through nonLayoutObjec tComputedStyle(). | 48 // so they store their style internally and return it through nonLayoutObjec tComputedStyle(). |
| 48 // We check here explicitly to avoid the virtual call in the common case. | 49 // We check here explicitly to avoid the virtual call in the common case. |
| 49 if (isHTMLOptGroupElement(*this) || isHTMLOptionElement(this)) | 50 if (isHTMLOptGroupElement(*this) || isHTMLOptionElement(this)) |
| 50 return nonLayoutObjectComputedStyle(); | 51 return nonLayoutObjectComputedStyle(); |
| 51 return 0; | 52 if (hasRareData()) |
| 53 return rareData()->computedStyle(); | |
| 54 return m_data.m_computedStyle; | |
| 55 } | |
| 56 | |
| 57 inline void Node::setComputedStyle(ComputedStyle* computedStyle) | |
|
Timothy Loh
2016/06/01 07:36:38
should take PassRefPtr<ComputedStyle>
| |
| 58 { | |
| 59 if (hasRareData()) { | |
| 60 rareData()->setComputedStyle(computedStyle); | |
| 61 } else if (hasLayoutObject()) { | |
| 62 m_data.m_layoutObject->setStyleInternal(computedStyle); | |
| 63 } else { | |
| 64 if (computedStyle) | |
| 65 computedStyle->ref(); | |
| 66 if (m_data.m_computedStyle) | |
| 67 m_data.m_computedStyle->deref(); | |
| 68 m_data.m_computedStyle = computedStyle; | |
| 69 } | |
| 52 } | 70 } |
| 53 | 71 |
| 54 inline const ComputedStyle* Node::parentComputedStyle() const | 72 inline const ComputedStyle* Node::parentComputedStyle() const |
| 55 { | 73 { |
| 56 if (isSlotOrActiveInsertionPoint()) | 74 if (isSlotOrActiveInsertionPoint()) |
| 57 return 0; | 75 return 0; |
| 58 ContainerNode* parent = LayoutTreeBuilderTraversal::parent(*this); | 76 ContainerNode* parent = LayoutTreeBuilderTraversal::parent(*this); |
| 59 return parent ? parent->computedStyle() : 0; | 77 return parent ? parent->computedStyle() : 0; |
| 60 } | 78 } |
| 61 | 79 |
| 62 inline const ComputedStyle& Node::computedStyleRef() const | 80 inline const ComputedStyle& Node::computedStyleRef() const |
| 63 { | 81 { |
| 64 const ComputedStyle* style = computedStyle(); | 82 const ComputedStyle* style = computedStyle(); |
| 65 DCHECK(style); | 83 DCHECK(style); |
| 66 return *style; | 84 return *style; |
| 67 } | 85 } |
| 68 | 86 |
| 69 } // namespace blink | 87 } // namespace blink |
| 70 #endif // NodeComputedStyle_h | 88 #endif // NodeComputedStyle_h |
| OLD | NEW |