FontLoader.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * Copyright (C) 2013 Google 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 are met:
  6. *
  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 INC. AND ITS CONTRIBUTORS ``AS IS'' AND
  14. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  15. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  16. * ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE
  17. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  18. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  19. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  20. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  21. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  22. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  23. * DAMAGE.
  24. */
  25. #if ENABLE(FONT_LOAD_EVENTS)
  26. #ifndef FontLoader_h
  27. #define FontLoader_h
  28. #include "ActiveDOMObject.h"
  29. #include "EventListener.h"
  30. #include "EventNames.h"
  31. #include "EventTarget.h"
  32. #include "VoidCallback.h"
  33. #include <wtf/PassRefPtr.h>
  34. #include <wtf/RefCounted.h>
  35. #include <wtf/Vector.h>
  36. namespace WebCore {
  37. class CachedFont;
  38. class CSSFontFaceRule;
  39. class CSSFontFaceSource;
  40. class Dictionary;
  41. class Document;
  42. class Event;
  43. class Font;
  44. class ScriptExecutionContext;
  45. class FontLoader : public RefCounted<FontLoader>, public ActiveDOMObject, public EventTarget {
  46. public:
  47. static PassRefPtr<FontLoader> create(Document* document)
  48. {
  49. return adoptRef<FontLoader>(new FontLoader(document));
  50. }
  51. virtual ~FontLoader();
  52. DEFINE_ATTRIBUTE_EVENT_LISTENER(loading);
  53. DEFINE_ATTRIBUTE_EVENT_LISTENER(loadingdone);
  54. DEFINE_ATTRIBUTE_EVENT_LISTENER(loadstart);
  55. DEFINE_ATTRIBUTE_EVENT_LISTENER(load);
  56. DEFINE_ATTRIBUTE_EVENT_LISTENER(error);
  57. bool checkFont(const String&, const String&);
  58. void loadFont(const Dictionary&);
  59. void notifyWhenFontsReady(PassRefPtr<VoidCallback>);
  60. bool loading() const { return m_loadingCount > 0; }
  61. virtual ScriptExecutionContext* scriptExecutionContext() const;
  62. virtual const AtomicString& interfaceName() const;
  63. using RefCounted<FontLoader>::ref;
  64. using RefCounted<FontLoader>::deref;
  65. Document* document() const { return m_document; }
  66. void didLayout();
  67. void beginFontLoading(CSSFontFaceRule*);
  68. void fontLoaded(CSSFontFaceRule*);
  69. void loadError(CSSFontFaceRule*, CSSFontFaceSource*);
  70. void loadingDone();
  71. private:
  72. FontLoader(Document*);
  73. virtual void refEventTarget() { ref(); }
  74. virtual void derefEventTarget() { deref(); }
  75. virtual EventTargetData* eventTargetData();
  76. virtual EventTargetData* ensureEventTargetData();
  77. void scheduleEvent(PassRefPtr<Event>);
  78. void firePendingEvents();
  79. bool resolveFontStyle(const String&, Font&);
  80. Document* m_document;
  81. EventTargetData m_eventTargetData;
  82. unsigned m_loadingCount;
  83. Vector<RefPtr<Event> > m_pendingEvents;
  84. Vector<RefPtr<VoidCallback> > m_callbacks;
  85. RefPtr<Event> m_loadingDoneEvent;
  86. };
  87. } // namespace WebCore
  88. #endif // FontLoader_h
  89. #endif // ENABLE(FONT_LOAD_EVENTS)