PlatformWebViewGtk.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * Copyright (C) 2010 Apple Inc. All rights reserved.
  3. * Copyright (C) 2010 University of Szeged. All rights reserved.
  4. * Copyright (C) 2010 Igalia S.L.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  16. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  17. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  18. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  19. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  20. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  21. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  22. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  23. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  25. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. #include "config.h"
  28. #include "PlatformWebView.h"
  29. #include <WebKit2/WKViewPrivate.h>
  30. #include <gtk/gtk.h>
  31. namespace WTR {
  32. PlatformWebView::PlatformWebView(WKContextRef context, WKPageGroupRef pageGroup, WKPageRef /* relatedPage */, WKDictionaryRef options)
  33. : m_view(WKViewCreate(context, pageGroup))
  34. , m_window(gtk_window_new(GTK_WINDOW_POPUP))
  35. , m_windowIsKey(true)
  36. , m_options(options)
  37. {
  38. gtk_container_add(GTK_CONTAINER(m_window), GTK_WIDGET(m_view));
  39. GtkAllocation size = { 0, 0, 800, 600 };
  40. gtk_widget_size_allocate(m_window, &size);
  41. gtk_window_resize(GTK_WINDOW(m_window), 800, 600);
  42. gtk_widget_show_all(m_window);
  43. while (gtk_events_pending())
  44. gtk_main_iteration();
  45. }
  46. PlatformWebView::~PlatformWebView()
  47. {
  48. gtk_widget_destroy(m_window);
  49. }
  50. void PlatformWebView::resizeTo(unsigned width, unsigned height)
  51. {
  52. GtkAllocation size = { 0, 0, static_cast<int>(width), static_cast<int>(height) };
  53. gtk_widget_size_allocate(m_window, &size);
  54. gtk_window_resize(GTK_WINDOW(m_window), width, height);
  55. while (gtk_events_pending())
  56. gtk_main_iteration();
  57. }
  58. WKPageRef PlatformWebView::page()
  59. {
  60. return WKViewGetPage(m_view);
  61. }
  62. void PlatformWebView::focus()
  63. {
  64. WKViewSetFocus(m_view, true);
  65. setWindowIsKey(true);
  66. }
  67. WKRect PlatformWebView::windowFrame()
  68. {
  69. GtkAllocation geometry;
  70. #ifdef GTK_API_VERSION_2
  71. gint depth;
  72. gdk_window_get_geometry(gtk_widget_get_window(GTK_WIDGET(m_window)),
  73. &geometry.x, &geometry.y, &geometry.width, &geometry.height, &depth);
  74. #else
  75. gdk_window_get_geometry(gtk_widget_get_window(GTK_WIDGET(m_window)),
  76. &geometry.x, &geometry.y, &geometry.width, &geometry.height);
  77. #endif
  78. WKRect frame;
  79. frame.origin.x = geometry.x;
  80. frame.origin.y = geometry.y;
  81. frame.size.width = geometry.width;
  82. frame.size.height = geometry.height;
  83. return frame;
  84. }
  85. void PlatformWebView::setWindowFrame(WKRect frame)
  86. {
  87. gtk_window_move(GTK_WINDOW(m_window), frame.origin.x, frame.origin.y);
  88. resizeTo(frame.size.width, frame.size.height);
  89. }
  90. void PlatformWebView::addChromeInputField()
  91. {
  92. }
  93. void PlatformWebView::removeChromeInputField()
  94. {
  95. }
  96. void PlatformWebView::makeWebViewFirstResponder()
  97. {
  98. }
  99. WKRetainPtr<WKImageRef> PlatformWebView::windowSnapshotImage()
  100. {
  101. // FIXME: implement to capture pixels in the UI process,
  102. // which may be necessary to capture things like 3D transforms.
  103. return 0;
  104. }
  105. void PlatformWebView::didInitializeClients()
  106. {
  107. }
  108. } // namespace WTR