PageOverlay.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * Copyright (C) 2010 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 INC. AND ITS CONTRIBUTORS ``AS IS''
  14. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  15. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
  17. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  18. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  19. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  20. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  21. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  22. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  23. * THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #ifndef PageOverlay_h
  26. #define PageOverlay_h
  27. #include "APIObject.h"
  28. #include "WKBase.h"
  29. #include <WebCore/RunLoop.h>
  30. #include <wtf/PassRefPtr.h>
  31. namespace WebCore {
  32. class GraphicsContext;
  33. class IntPoint;
  34. class IntRect;
  35. }
  36. namespace WebKit {
  37. class WebMouseEvent;
  38. class WebPage;
  39. class PageOverlay : public TypedAPIObject<APIObject::TypeBundlePageOverlay> {
  40. public:
  41. class Client {
  42. protected:
  43. virtual ~Client() { }
  44. public:
  45. virtual void pageOverlayDestroyed(PageOverlay*) = 0;
  46. virtual void willMoveToWebPage(PageOverlay*, WebPage*) = 0;
  47. virtual void didMoveToWebPage(PageOverlay*, WebPage*) = 0;
  48. virtual void drawRect(PageOverlay*, WebCore::GraphicsContext&, const WebCore::IntRect& dirtyRect) = 0;
  49. virtual bool mouseEvent(PageOverlay*, const WebMouseEvent&) = 0;
  50. virtual WKTypeRef copyAccessibilityAttributeValue(PageOverlay*, WKStringRef attribute, WKTypeRef parameter) { return 0; }
  51. virtual WKArrayRef copyAccessibilityAttributeNames(PageOverlay*, bool parameterizedNames) { return 0; }
  52. };
  53. static PassRefPtr<PageOverlay> create(Client*);
  54. virtual ~PageOverlay();
  55. void setPage(WebPage*);
  56. void setNeedsDisplay(const WebCore::IntRect& dirtyRect);
  57. void setNeedsDisplay();
  58. void drawRect(WebCore::GraphicsContext&, const WebCore::IntRect& dirtyRect);
  59. bool mouseEvent(const WebMouseEvent&);
  60. WKTypeRef copyAccessibilityAttributeValue(WKStringRef attribute, WKTypeRef parameter);
  61. WKArrayRef copyAccessibilityAttributeNames(bool parameterizedNames);
  62. void startFadeInAnimation();
  63. void startFadeOutAnimation();
  64. void stopFadeOutAnimation();
  65. float fractionFadedIn() const { return m_fractionFadedIn; }
  66. Client* client() const { return m_client; }
  67. protected:
  68. explicit PageOverlay(Client*);
  69. private:
  70. WebCore::IntRect bounds() const;
  71. void startFadeAnimation();
  72. void fadeAnimationTimerFired();
  73. Client* m_client;
  74. WebPage* m_webPage;
  75. WebCore::RunLoop::Timer<PageOverlay> m_fadeAnimationTimer;
  76. double m_fadeAnimationStartTime;
  77. double m_fadeAnimationDuration;
  78. enum FadeAnimationType {
  79. NoAnimation,
  80. FadeInAnimation,
  81. FadeOutAnimation,
  82. };
  83. FadeAnimationType m_fadeAnimationType;
  84. float m_fractionFadedIn;
  85. bool m_pageOverlayShouldApplyFadeWhenPainting;
  86. };
  87. } // namespace WebKit
  88. #endif // PageOverlay_h