CSSFontSelector.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright (C) 2007, 2008, 2011 Apple Inc. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. * 1. Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * 2. Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
  14. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  15. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
  17. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  20. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  21. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  23. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #ifndef CSSFontSelector_h
  26. #define CSSFontSelector_h
  27. #include "CachedResourceHandle.h"
  28. #include "FontSelector.h"
  29. #include "Timer.h"
  30. #include <wtf/Forward.h>
  31. #include <wtf/HashMap.h>
  32. #include <wtf/HashSet.h>
  33. #include <wtf/RefPtr.h>
  34. #include <wtf/text/StringHash.h>
  35. namespace WebCore {
  36. class CSSFontFace;
  37. class CSSFontFaceRule;
  38. class CSSSegmentedFontFace;
  39. class CachedFont;
  40. class Document;
  41. class FontDescription;
  42. class StyleRuleFontFace;
  43. class CSSFontSelector FINAL : public FontSelector {
  44. public:
  45. static PassRefPtr<CSSFontSelector> create(Document* document)
  46. {
  47. return adoptRef(new CSSFontSelector(document));
  48. }
  49. virtual ~CSSFontSelector();
  50. virtual unsigned version() const OVERRIDE { return m_version; }
  51. virtual unsigned uniqueId() const OVERRIDE { return m_uniqueId; }
  52. virtual PassRefPtr<FontData> getFontData(const FontDescription&, const AtomicString&) OVERRIDE;
  53. CSSSegmentedFontFace* getFontFace(const FontDescription&, const AtomicString& family);
  54. virtual bool resolvesFamilyFor(const FontDescription&) const OVERRIDE;
  55. void clearDocument();
  56. void addFontFaceRule(const StyleRuleFontFace*);
  57. void fontLoaded();
  58. virtual void fontCacheInvalidated() OVERRIDE;
  59. bool isEmpty() const;
  60. virtual void registerForInvalidationCallbacks(FontSelectorClient*) OVERRIDE;
  61. virtual void unregisterForInvalidationCallbacks(FontSelectorClient*) OVERRIDE;
  62. Document* document() const { return m_document; }
  63. void beginLoadingFontSoon(CachedFont*);
  64. private:
  65. CSSFontSelector(Document*);
  66. void dispatchInvalidationCallbacks();
  67. void beginLoadTimerFired(Timer<CSSFontSelector>*);
  68. Document* m_document;
  69. HashMap<String, OwnPtr<Vector<RefPtr<CSSFontFace> > >, CaseFoldingHash> m_fontFaces;
  70. HashMap<String, OwnPtr<Vector<RefPtr<CSSFontFace> > >, CaseFoldingHash> m_locallyInstalledFontFaces;
  71. HashMap<String, OwnPtr<HashMap<unsigned, RefPtr<CSSSegmentedFontFace> > >, CaseFoldingHash> m_fonts;
  72. HashSet<FontSelectorClient*> m_clients;
  73. Vector<CachedResourceHandle<CachedFont> > m_fontsToBeginLoading;
  74. Timer<CSSFontSelector> m_beginLoadingTimer;
  75. unsigned m_uniqueId;
  76. unsigned m_version;
  77. };
  78. } // namespace WebCore
  79. #endif // CSSFontSelector_h