| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/html/canvas/CanvasFontCache.h" | 5 #include "core/html/canvas/CanvasFontCache.h" |
| 6 | 6 |
| 7 #include "core/css/parser/CSSParser.h" | 7 #include "core/css/parser/CSSParser.h" |
| 8 #include "core/css/resolver/StyleResolver.h" | 8 #include "core/css/resolver/StyleResolver.h" |
| 9 #include "core/dom/Document.h" | 9 #include "core/dom/Document.h" |
| 10 #include "core/style/ComputedStyle.h" | 10 #include "core/style/ComputedStyle.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 } | 66 } |
| 67 | 67 |
| 68 // Addition to LRU list taken care of inside parseFont | 68 // Addition to LRU list taken care of inside parseFont |
| 69 MutableStylePropertySet* parsedStyle = parseFont(fontString); | 69 MutableStylePropertySet* parsedStyle = parseFont(fontString); |
| 70 if (!parsedStyle) | 70 if (!parsedStyle) |
| 71 return false; | 71 return false; |
| 72 | 72 |
| 73 RefPtr<ComputedStyle> fontStyle = | 73 RefPtr<ComputedStyle> fontStyle = |
| 74 ComputedStyle::clone(*m_defaultFontStyle.get()); | 74 ComputedStyle::clone(*m_defaultFontStyle.get()); |
| 75 m_document->ensureStyleResolver().computeFont(fontStyle.get(), *parsedStyle); | 75 m_document->ensureStyleResolver().computeFont(fontStyle.get(), *parsedStyle); |
| 76 m_fontsResolvedUsingDefaultStyle.add(fontString, fontStyle->font()); | 76 m_fontsResolvedUsingDefaultStyle.insert(fontString, fontStyle->font()); |
| 77 resolvedFont = m_fontsResolvedUsingDefaultStyle.find(fontString)->value; | 77 resolvedFont = m_fontsResolvedUsingDefaultStyle.find(fontString)->value; |
| 78 return true; | 78 return true; |
| 79 } | 79 } |
| 80 | 80 |
| 81 MutableStylePropertySet* CanvasFontCache::parseFont(const String& fontString) { | 81 MutableStylePropertySet* CanvasFontCache::parseFont(const String& fontString) { |
| 82 MutableStylePropertySet* parsedStyle; | 82 MutableStylePropertySet* parsedStyle; |
| 83 MutableStylePropertyMap::iterator i = m_fetchedFonts.find(fontString); | 83 MutableStylePropertyMap::iterator i = m_fetchedFonts.find(fontString); |
| 84 if (i != m_fetchedFonts.end()) { | 84 if (i != m_fetchedFonts.end()) { |
| 85 ASSERT(m_fontLRUList.contains(fontString)); | 85 ASSERT(m_fontLRUList.contains(fontString)); |
| 86 parsedStyle = i->value; | 86 parsedStyle = i->value; |
| 87 m_fontLRUList.remove(fontString); | 87 m_fontLRUList.remove(fontString); |
| 88 m_fontLRUList.add(fontString); | 88 m_fontLRUList.add(fontString); |
| 89 } else { | 89 } else { |
| 90 parsedStyle = MutableStylePropertySet::create(HTMLStandardMode); | 90 parsedStyle = MutableStylePropertySet::create(HTMLStandardMode); |
| 91 CSSParser::parseValue(parsedStyle, CSSPropertyFont, fontString, true); | 91 CSSParser::parseValue(parsedStyle, CSSPropertyFont, fontString, true); |
| 92 if (parsedStyle->isEmpty()) | 92 if (parsedStyle->isEmpty()) |
| 93 return nullptr; | 93 return nullptr; |
| 94 // According to | 94 // According to |
| 95 // http://lists.w3.org/Archives/Public/public-html/2009Jul/0947.html, | 95 // http://lists.w3.org/Archives/Public/public-html/2009Jul/0947.html, |
| 96 // the "inherit" and "initial" values must be ignored. | 96 // the "inherit" and "initial" values must be ignored. |
| 97 const CSSValue* fontValue = | 97 const CSSValue* fontValue = |
| 98 parsedStyle->getPropertyCSSValue(CSSPropertyFontSize); | 98 parsedStyle->getPropertyCSSValue(CSSPropertyFontSize); |
| 99 if (fontValue && | 99 if (fontValue && |
| 100 (fontValue->isInitialValue() || fontValue->isInheritedValue())) | 100 (fontValue->isInitialValue() || fontValue->isInheritedValue())) |
| 101 return nullptr; | 101 return nullptr; |
| 102 m_fetchedFonts.add(fontString, parsedStyle); | 102 m_fetchedFonts.insert(fontString, parsedStyle); |
| 103 m_fontLRUList.add(fontString); | 103 m_fontLRUList.add(fontString); |
| 104 // Hard limit is applied here, on the fly, while the soft limit is | 104 // Hard limit is applied here, on the fly, while the soft limit is |
| 105 // applied at the end of the task. | 105 // applied at the end of the task. |
| 106 if (m_fetchedFonts.size() > hardMaxFonts()) { | 106 if (m_fetchedFonts.size() > hardMaxFonts()) { |
| 107 ASSERT(m_fetchedFonts.size() == hardMaxFonts() + 1); | 107 ASSERT(m_fetchedFonts.size() == hardMaxFonts() + 1); |
| 108 ASSERT(m_fontLRUList.size() == hardMaxFonts() + 1); | 108 ASSERT(m_fontLRUList.size() == hardMaxFonts() + 1); |
| 109 m_fetchedFonts.erase(m_fontLRUList.first()); | 109 m_fetchedFonts.erase(m_fontLRUList.first()); |
| 110 m_fontsResolvedUsingDefaultStyle.erase(m_fontLRUList.first()); | 110 m_fontsResolvedUsingDefaultStyle.erase(m_fontLRUList.first()); |
| 111 m_fontLRUList.removeFirst(); | 111 m_fontLRUList.removeFirst(); |
| 112 } | 112 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 m_fontLRUList.clear(); | 147 m_fontLRUList.clear(); |
| 148 m_fontsResolvedUsingDefaultStyle.clear(); | 148 m_fontsResolvedUsingDefaultStyle.clear(); |
| 149 } | 149 } |
| 150 | 150 |
| 151 DEFINE_TRACE(CanvasFontCache) { | 151 DEFINE_TRACE(CanvasFontCache) { |
| 152 visitor->trace(m_fetchedFonts); | 152 visitor->trace(m_fetchedFonts); |
| 153 visitor->trace(m_document); | 153 visitor->trace(m_document); |
| 154 } | 154 } |
| 155 | 155 |
| 156 } // namespace blink | 156 } // namespace blink |
| OLD | NEW |