| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2008 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 #include "core/css/CSSFontFaceSource.h" | 30 #include "core/css/CSSFontFaceSource.h" |
| 31 #include "core/css/CSSFontSelector.h" | 31 #include "core/css/CSSFontSelector.h" |
| 32 #include "core/dom/Document.h" | 32 #include "core/dom/Document.h" |
| 33 #include "RuntimeEnabledFeatures.h" | 33 #include "RuntimeEnabledFeatures.h" |
| 34 #include "core/platform/graphics/FontDescription.h" | 34 #include "core/platform/graphics/FontDescription.h" |
| 35 #include "core/platform/graphics/SegmentedFontData.h" | 35 #include "core/platform/graphics/SegmentedFontData.h" |
| 36 #include "core/platform/graphics/SimpleFontData.h" | 36 #include "core/platform/graphics/SimpleFontData.h" |
| 37 | 37 |
| 38 namespace WebCore { | 38 namespace WebCore { |
| 39 | 39 |
| 40 DEFINE_GC_TYPE_MARKER(CSSSegmentedFontFace); |
| 41 DEFINE_GC_TYPE_MARKER(CSSSegmentedFontFace::LoadFontCallback); |
| 42 |
| 40 CSSSegmentedFontFace::CSSSegmentedFontFace(CSSFontSelector* fontSelector) | 43 CSSSegmentedFontFace::CSSSegmentedFontFace(CSSFontSelector* fontSelector) |
| 41 : m_fontSelector(fontSelector) | 44 : m_fontSelector(fontSelector) |
| 42 { | 45 { |
| 43 } | 46 } |
| 44 | 47 |
| 45 CSSSegmentedFontFace::~CSSSegmentedFontFace() | 48 CSSSegmentedFontFace::~CSSSegmentedFontFace() |
| 46 { | 49 { |
| 47 pruneTable(); | 50 pruneTable(); |
| 48 unsigned size = m_fontFaces.size(); | |
| 49 for (unsigned i = 0; i < size; i++) | |
| 50 m_fontFaces[i]->removedFromSegmentedFontFace(this); | |
| 51 } | 51 } |
| 52 | 52 |
| 53 void CSSSegmentedFontFace::pruneTable() | 53 void CSSSegmentedFontFace::pruneTable() |
| 54 { | 54 { |
| 55 // Make sure the glyph page tree prunes out all uses of this custom font. | 55 // Make sure the glyph page tree prunes out all uses of this custom font. |
| 56 if (m_fontDataTable.isEmpty()) | 56 if (m_fontDataTable.isEmpty()) |
| 57 return; | 57 return; |
| 58 | 58 |
| 59 m_fontDataTable.clear(); | 59 m_fontDataTable.clear(); |
| 60 } | 60 } |
| 61 | 61 |
| 62 bool CSSSegmentedFontFace::isValid() const | 62 bool CSSSegmentedFontFace::isValid() const |
| 63 { | 63 { |
| 64 // Valid if at least one font face is valid. | 64 // Valid if at least one font face is valid. |
| 65 unsigned size = m_fontFaces.size(); | 65 unsigned size = m_fontFaces.size(); |
| 66 for (unsigned i = 0; i < size; i++) { | 66 for (unsigned i = 0; i < size; i++) { |
| 67 if (m_fontFaces[i]->isValid()) | 67 if (m_fontFaces[i]->isValid()) |
| 68 return true; | 68 return true; |
| 69 } | 69 } |
| 70 return false; | 70 return false; |
| 71 } | 71 } |
| 72 | 72 |
| 73 void CSSSegmentedFontFace::fontLoaded(CSSFontFace*) | 73 void CSSSegmentedFontFace::fontLoaded(Handle<CSSFontFace>) |
| 74 { | 74 { |
| 75 pruneTable(); | 75 pruneTable(); |
| 76 | 76 |
| 77 if (RuntimeEnabledFeatures::fontLoadEventsEnabled() && !isLoading()) { | 77 if (RuntimeEnabledFeatures::fontLoadEventsEnabled() && !isLoading()) { |
| 78 Vector<RefPtr<LoadFontCallback> > callbacks; | 78 CollectionRoot<Vector<Member<LoadFontCallback> > > callbacks; |
| 79 m_callbacks.swap(callbacks); | 79 m_callbacks.swap(*callbacks); |
| 80 for (size_t index = 0; index < callbacks.size(); ++index) { | 80 for (size_t index = 0; index < callbacks->size(); ++index) { |
| 81 if (checkFont()) | 81 if (checkFont()) |
| 82 callbacks[index]->notifyLoaded(this); | 82 callbacks->at(index)->notifyLoaded(Handle<CSSSegmentedFontFace>(
this)); |
| 83 else | 83 else |
| 84 callbacks[index]->notifyError(this); | 84 callbacks->at(index)->notifyError(Handle<CSSSegmentedFontFace>(t
his)); |
| 85 } | 85 } |
| 86 } | 86 } |
| 87 } | 87 } |
| 88 | 88 |
| 89 void CSSSegmentedFontFace::appendFontFace(PassRefPtr<CSSFontFace> fontFace) | 89 void CSSSegmentedFontFace::appendFontFace(Handle<CSSFontFace> fontFace) |
| 90 { | 90 { |
| 91 pruneTable(); | 91 pruneTable(); |
| 92 fontFace->addedToSegmentedFontFace(this); | 92 fontFace->addedToSegmentedFontFace(Handle<CSSSegmentedFontFace>(this)); |
| 93 m_fontFaces.append(fontFace); | 93 m_fontFaces.append(fontFace); |
| 94 } | 94 } |
| 95 | 95 |
| 96 static void appendFontDataWithInvalidUnicodeRangeIfLoading(SegmentedFontData* ne
wFontData, PassRefPtr<SimpleFontData> prpFaceFontData, const Vector<CSSFontFace:
:UnicodeRange>& ranges) | 96 static void appendFontDataWithInvalidUnicodeRangeIfLoading(SegmentedFontData* ne
wFontData, PassRefPtr<SimpleFontData> prpFaceFontData, const Vector<CSSFontFace:
:UnicodeRange>& ranges) |
| 97 { | 97 { |
| 98 RefPtr<SimpleFontData> faceFontData = prpFaceFontData; | 98 RefPtr<SimpleFontData> faceFontData = prpFaceFontData; |
| 99 if (faceFontData->isLoading()) { | 99 if (faceFontData->isLoading()) { |
| 100 newFontData->appendRange(FontDataRange(0, 0, faceFontData)); | 100 newFontData->appendRange(FontDataRange(0, 0, faceFontData)); |
| 101 return; | 101 return; |
| 102 } | 102 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 bool CSSSegmentedFontFace::checkFont() const | 160 bool CSSSegmentedFontFace::checkFont() const |
| 161 { | 161 { |
| 162 unsigned size = m_fontFaces.size(); | 162 unsigned size = m_fontFaces.size(); |
| 163 for (unsigned i = 0; i < size; i++) { | 163 for (unsigned i = 0; i < size; i++) { |
| 164 if (m_fontFaces[i]->loadState() != CSSFontFace::Loaded) | 164 if (m_fontFaces[i]->loadState() != CSSFontFace::Loaded) |
| 165 return false; | 165 return false; |
| 166 } | 166 } |
| 167 return true; | 167 return true; |
| 168 } | 168 } |
| 169 | 169 |
| 170 void CSSSegmentedFontFace::loadFont(const FontDescription& fontDescription, Pass
RefPtr<LoadFontCallback> callback) | 170 void CSSSegmentedFontFace::loadFont(const FontDescription& fontDescription, Hand
le<LoadFontCallback> callback) |
| 171 { | 171 { |
| 172 getFontData(fontDescription); // Kick off the load. | 172 getFontData(fontDescription); // Kick off the load. |
| 173 | 173 |
| 174 if (callback) { | 174 if (callback) { |
| 175 if (isLoading()) | 175 if (isLoading()) |
| 176 m_callbacks.append(callback); | 176 m_callbacks.append(callback); |
| 177 else if (checkFont()) | 177 else if (checkFont()) |
| 178 callback->notifyLoaded(this); | 178 callback->notifyLoaded(Handle<CSSSegmentedFontFace>(this)); |
| 179 else | 179 else |
| 180 callback->notifyError(this); | 180 callback->notifyError(Handle<CSSSegmentedFontFace>(this)); |
| 181 } | 181 } |
| 182 } | 182 } |
| 183 | 183 |
| 184 void CSSSegmentedFontFace::accept(Visitor* visitor) const |
| 185 { |
| 186 visitor->visit(m_fontFaces); |
| 187 visitor->visit(m_callbacks); |
| 184 } | 188 } |
| 189 |
| 190 } |
| OLD | NEW |