| OLD | NEW |
| 1 /* | 1 /* |
| 2 * (C) 1999-2003 Lars Knoll (knoll@kde.org) | 2 * (C) 1999-2003 Lars Knoll (knoll@kde.org) |
| 3 * Copyright (C) 2004, 2006, 2007, 2012 Apple Inc. All rights reserved. | 3 * Copyright (C) 2004, 2006, 2007, 2012 Apple Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
| 6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
| 7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
| 8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
| 9 * | 9 * |
| 10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
| 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 * Library General Public License for more details. | 13 * Library General Public License for more details. |
| 14 * | 14 * |
| 15 * You should have received a copy of the GNU Library General Public License | 15 * You should have received a copy of the GNU Library General Public License |
| 16 * along with this library; see the file COPYING.LIB. If not, write to | 16 * along with this library; see the file COPYING.LIB. If not, write to |
| 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 18 * Boston, MA 02110-1301, USA. | 18 * Boston, MA 02110-1301, USA. |
| 19 */ | 19 */ |
| 20 | 20 |
| 21 #include "sky/engine/config.h" | 21 #include "sky/engine/config.h" |
| 22 #include "sky/engine/core/css/CSSStyleSheet.h" | 22 #include "sky/engine/core/css/CSSStyleSheet.h" |
| 23 | 23 |
| 24 #include "sky/engine/bindings/core/v8/ExceptionState.h" | |
| 25 #include "sky/engine/bindings/core/v8/V8Binding.h" | |
| 26 #include "sky/engine/bindings/core/v8/V8PerIsolateData.h" | |
| 27 #include "sky/engine/core/css/MediaList.h" | 24 #include "sky/engine/core/css/MediaList.h" |
| 28 #include "sky/engine/core/css/StyleRule.h" | |
| 29 #include "sky/engine/core/css/StyleSheetContents.h" | 25 #include "sky/engine/core/css/StyleSheetContents.h" |
| 30 #include "sky/engine/core/css/parser/BisonCSSParser.h" | |
| 31 #include "sky/engine/core/dom/Document.h" | 26 #include "sky/engine/core/dom/Document.h" |
| 32 #include "sky/engine/core/dom/ExceptionCode.h" | |
| 33 #include "sky/engine/core/dom/Node.h" | 27 #include "sky/engine/core/dom/Node.h" |
| 34 #include "sky/engine/core/frame/UseCounter.h" | |
| 35 #include "sky/engine/core/html/HTMLStyleElement.h" | 28 #include "sky/engine/core/html/HTMLStyleElement.h" |
| 36 #include "sky/engine/wtf/text/StringBuilder.h" | |
| 37 | 29 |
| 38 namespace blink { | 30 namespace blink { |
| 39 | 31 |
| 40 #if ENABLE(ASSERT) | 32 #if ENABLE(ASSERT) |
| 41 static bool isAcceptableCSSStyleSheetParent(Node* parentNode) | 33 static bool isAcceptableCSSStyleSheetParent(Node* parentNode) |
| 42 { | 34 { |
| 43 // Only these nodes can be parents of StyleSheets, and they need to call | 35 // Only these nodes can be parents of StyleSheets, and they need to call |
| 44 // clearOwnerNode() when moved out of document. | 36 // clearOwnerNode() when moved out of document. |
| 45 // Destruction of the style sheet counts as being "moved out of the | 37 // Destruction of the style sheet counts as being "moved out of the |
| 46 // document", but only in the non-oilpan version of blink. I.e. don't call | 38 // document", but only in the non-oilpan version of blink. I.e. don't call |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 { | 73 { |
| 82 ASSERT(isAcceptableCSSStyleSheetParent(ownerNode)); | 74 ASSERT(isAcceptableCSSStyleSheetParent(ownerNode)); |
| 83 m_contents->registerClient(this); | 75 m_contents->registerClient(this); |
| 84 } | 76 } |
| 85 | 77 |
| 86 CSSStyleSheet::~CSSStyleSheet() | 78 CSSStyleSheet::~CSSStyleSheet() |
| 87 { | 79 { |
| 88 m_contents->unregisterClient(this); | 80 m_contents->unregisterClient(this); |
| 89 } | 81 } |
| 90 | 82 |
| 91 void CSSStyleSheet::willMutateRules() | |
| 92 { | |
| 93 // If we are the only client it is safe to mutate. | |
| 94 if (m_contents->clientSize() <= 1 && !m_contents->isInMemoryCache()) { | |
| 95 m_contents->clearRuleSet(); | |
| 96 if (Document* document = ownerDocument()) | |
| 97 m_contents->removeSheetFromCache(document); | |
| 98 m_contents->setMutable(); | |
| 99 return; | |
| 100 } | |
| 101 // Only cacheable stylesheets should have multiple clients. | |
| 102 ASSERT(m_contents->isCacheable()); | |
| 103 | |
| 104 // Copy-on-write. | |
| 105 m_contents->unregisterClient(this); | |
| 106 m_contents = m_contents->copy(); | |
| 107 m_contents->registerClient(this); | |
| 108 | |
| 109 m_contents->setMutable(); | |
| 110 } | |
| 111 | |
| 112 void CSSStyleSheet::didMutateRules() | |
| 113 { | |
| 114 ASSERT(m_contents->isMutable()); | |
| 115 ASSERT(m_contents->clientSize() <= 1); | |
| 116 | |
| 117 didMutate(PartialRuleUpdate); | |
| 118 } | |
| 119 | |
| 120 void CSSStyleSheet::didMutate(StyleSheetUpdateType updateType) | |
| 121 { | |
| 122 Document* owner = ownerDocument(); | |
| 123 if (!owner) | |
| 124 return; | |
| 125 | |
| 126 owner->modifiedStyleSheet(this); | |
| 127 } | |
| 128 | |
| 129 | |
| 130 void CSSStyleSheet::setMediaQueries(PassRefPtr<MediaQuerySet> mediaQueries) | 83 void CSSStyleSheet::setMediaQueries(PassRefPtr<MediaQuerySet> mediaQueries) |
| 131 { | 84 { |
| 132 m_mediaQueries = mediaQueries; | 85 m_mediaQueries = mediaQueries; |
| 133 | 86 |
| 134 // Add warning message to inspector whenever dpi/dpcm values are used for "s
creen" media. | 87 // Add warning message to inspector whenever dpi/dpcm values are used for "s
creen" media. |
| 135 reportMediaQueryWarningIfNeeded(ownerDocument(), m_mediaQueries.get()); | 88 reportMediaQueryWarningIfNeeded(ownerDocument(), m_mediaQueries.get()); |
| 136 } | 89 } |
| 137 | 90 |
| 138 unsigned CSSStyleSheet::length() const | 91 unsigned CSSStyleSheet::length() const |
| 139 { | 92 { |
| 140 return m_contents->ruleCount(); | 93 return m_contents->ruleCount(); |
| 141 } | 94 } |
| 142 | 95 |
| 143 void CSSStyleSheet::clearOwnerNode() | 96 void CSSStyleSheet::clearOwnerNode() |
| 144 { | 97 { |
| 145 didMutate(EntireStyleSheetUpdate); | 98 if (Document* owner = ownerDocument()) |
| 99 owner->modifiedStyleSheet(this); |
| 146 if (m_ownerNode) | 100 if (m_ownerNode) |
| 147 m_contents->unregisterClient(this); | 101 m_contents->unregisterClient(this); |
| 148 m_ownerNode = nullptr; | 102 m_ownerNode = nullptr; |
| 149 } | 103 } |
| 150 | 104 |
| 151 KURL CSSStyleSheet::baseURL() const | 105 KURL CSSStyleSheet::baseURL() const |
| 152 { | 106 { |
| 153 return m_contents->baseURL(); | 107 return m_contents->baseURL(); |
| 154 } | 108 } |
| 155 | 109 |
| 156 Document* CSSStyleSheet::ownerDocument() const | 110 Document* CSSStyleSheet::ownerDocument() const |
| 157 { | 111 { |
| 158 return ownerNode() ? &ownerNode()->document() : 0; | 112 return ownerNode() ? &ownerNode()->document() : 0; |
| 159 } | 113 } |
| 160 | 114 |
| 161 } // namespace blink | 115 } // namespace blink |
| OLD | NEW |