PlatformWebView.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Copyright (C) 2012 Samsung Electronics
  3. * Copyright (C) 2012 Intel Corporation. All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
  15. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  16. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  17. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
  18. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  19. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  20. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  21. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  22. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  23. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  24. * THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #include "config.h"
  27. #include "ewk_view_private.h"
  28. #include "PlatformWebView.h"
  29. #include "EWebKit2.h"
  30. #include <WebKit2/WKAPICast.h>
  31. #include <WebKit2/WKRetainPtr.h>
  32. #include <WebKit2/WKViewEfl.h>
  33. #include <Ecore_Evas.h>
  34. extern bool useX11Window;
  35. using namespace WebKit;
  36. namespace TestWebKitAPI {
  37. static Ecore_Evas* initEcoreEvas()
  38. {
  39. if (!ecore_evas_init())
  40. return 0;
  41. const char* engine = 0;
  42. #if defined(WTF_USE_ACCELERATED_COMPOSITING) && defined(HAVE_ECORE_X)
  43. engine = "opengl_x11";
  44. #endif
  45. Ecore_Evas* ecoreEvas = ecore_evas_new(engine, 0, 0, 800, 600, 0);
  46. ASSERT(ecoreEvas);
  47. ecore_evas_show(ecoreEvas);
  48. return ecoreEvas;
  49. }
  50. static void onWebProcessCrashed(void*, Evas_Object*, void* eventInfo)
  51. {
  52. bool* handled = static_cast<bool*>(eventInfo);
  53. *handled = true;
  54. }
  55. PlatformWebView::PlatformWebView(WKContextRef contextRef, WKPageGroupRef pageGroupRef)
  56. {
  57. m_window = initEcoreEvas();
  58. m_view = EWKViewCreate(contextRef, pageGroupRef, ecore_evas_get(m_window), /* smart */ 0);
  59. WKRetainPtr<WKStringRef> wkTheme = adoptWK(WKStringCreateWithUTF8CString(TEST_THEME_DIR "/default.edj"));
  60. WKViewSetThemePath(EWKViewGetWKView(m_view), wkTheme.get());
  61. evas_object_smart_callback_add(m_view, "webprocess,crashed", onWebProcessCrashed, 0);
  62. resizeTo(600, 800);
  63. }
  64. PlatformWebView::~PlatformWebView()
  65. {
  66. evas_object_del(m_view);
  67. ecore_evas_free(m_window);
  68. ecore_evas_shutdown();
  69. }
  70. void PlatformWebView::resizeTo(unsigned width, unsigned height)
  71. {
  72. evas_object_resize(m_view, width, height);
  73. }
  74. WKPageRef PlatformWebView::page() const
  75. {
  76. return WKViewGetPage(EWKViewGetWKView(m_view));
  77. }
  78. void PlatformWebView::simulateSpacebarKeyPress()
  79. {
  80. Evas* evas = evas_object_evas_get(m_view);
  81. evas_object_focus_set(m_view, true);
  82. evas_event_feed_key_down(evas, "space", "space", " ", 0, 0, 0);
  83. evas_event_feed_key_up(evas, "space", "space", " ", 0, 1, 0);
  84. }
  85. void PlatformWebView::simulateMouseMove(unsigned x, unsigned y)
  86. {
  87. Evas* evas = evas_object_evas_get(m_view);
  88. evas_object_show(m_view);
  89. evas_event_feed_mouse_move(evas, x, y, 0, 0);
  90. }
  91. void PlatformWebView::simulateRightClick(unsigned x, unsigned y)
  92. {
  93. Evas* evas = evas_object_evas_get(m_view);
  94. evas_object_show(m_view);
  95. evas_event_feed_mouse_move(evas, x, y, 0, 0);
  96. evas_event_feed_mouse_down(evas, 3, EVAS_BUTTON_NONE, 0, 0);
  97. evas_event_feed_mouse_up(evas, 3, EVAS_BUTTON_NONE, 0, 0);
  98. }
  99. } // namespace TestWebKitAPI