PlatformWebView.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 PlatformWebView_h
  26. #define PlatformWebView_h
  27. #include <WebKit2/WKRetainPtr.h>
  28. #if defined(BUILDING_QT__)
  29. QT_BEGIN_NAMESPACE
  30. class QQuickView;
  31. class QEventLoop;
  32. QT_END_NAMESPACE
  33. class QQuickWebView;
  34. typedef QQuickWebView* PlatformWKView;
  35. typedef QQuickView* PlatformWindow;
  36. #elif defined(__APPLE__) && __APPLE__
  37. #ifdef __OBJC__
  38. @class WKView;
  39. @class WebKitTestRunnerWindow;
  40. #else
  41. class WKView;
  42. class WebKitTestRunnerWindow;
  43. #endif
  44. typedef WKView* PlatformWKView;
  45. typedef WebKitTestRunnerWindow* PlatformWindow;
  46. #elif defined(WIN32) || defined(_WIN32)
  47. typedef WKViewRef PlatformWKView;
  48. typedef HWND PlatformWindow;
  49. #elif defined(BUILDING_GTK__)
  50. typedef struct _GtkWidget GtkWidget;
  51. typedef WKViewRef PlatformWKView;
  52. typedef GtkWidget* PlatformWindow;
  53. #elif PLATFORM(MANX)
  54. typedef WKViewRef PlatformWKView;
  55. typedef void* PlatformWindow;
  56. #elif PLATFORM(EFL)
  57. typedef struct _Ecore_Evas Ecore_Evas;
  58. #if USE(EO)
  59. typedef struct _Eo Evas_Object;
  60. #else
  61. typedef struct _Evas_Object Evas_Object;
  62. #endif
  63. typedef Evas_Object* PlatformWKView;
  64. typedef Ecore_Evas* PlatformWindow;
  65. #endif
  66. namespace WTR {
  67. class PlatformWebView {
  68. public:
  69. PlatformWebView(WKContextRef, WKPageGroupRef, WKPageRef relatedPage, WKDictionaryRef options = 0);
  70. ~PlatformWebView();
  71. WKPageRef page();
  72. PlatformWKView platformView() { return m_view; }
  73. PlatformWindow platformWindow() { return m_window; }
  74. void resizeTo(unsigned width, unsigned height);
  75. void focus();
  76. #if PLATFORM(QT)
  77. bool sendEvent(QEvent*);
  78. void postEvent(QEvent*);
  79. void setModalEventLoop(QEventLoop* eventLoop) { m_modalEventLoop = eventLoop; }
  80. static bool windowShapshotEnabled();
  81. #endif
  82. WKRect windowFrame();
  83. void setWindowFrame(WKRect);
  84. void didInitializeClients();
  85. void addChromeInputField();
  86. void removeChromeInputField();
  87. void makeWebViewFirstResponder();
  88. void setWindowIsKey(bool isKey) { m_windowIsKey = isKey; }
  89. bool windowIsKey() const { return m_windowIsKey; }
  90. #if PLATFORM(MAC) || PLATFORM(EFL) || PLATFORM(QT)
  91. bool viewSupportsOptions(WKDictionaryRef) const;
  92. #else
  93. bool viewSupportsOptions(WKDictionaryRef) const { return true; }
  94. #endif
  95. WKRetainPtr<WKImageRef> windowSnapshotImage();
  96. WKDictionaryRef options() const { return m_options.get(); }
  97. #if PLATFORM(MANX)
  98. private:
  99. static WKSize viewSize(WKViewRef, const void* clientInfo);
  100. #endif
  101. private:
  102. PlatformWKView m_view;
  103. PlatformWindow m_window;
  104. bool m_windowIsKey;
  105. WKRetainPtr<WKDictionaryRef> m_options;
  106. #if PLATFORM(EFL) || PLATFORM(QT)
  107. bool m_usingFixedLayout;
  108. #endif
  109. #if PLATFORM(QT)
  110. QEventLoop* m_modalEventLoop;
  111. #endif
  112. };
  113. } // namespace WTR
  114. #endif // PlatformWebView_h