PlatformWebViewWin.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. #include "config.h"
  26. #include "PlatformWebView.h"
  27. namespace WTR {
  28. static LPCWSTR hostWindowClassName = L"WTRWebViewHostWindow";
  29. static void registerWindowClass()
  30. {
  31. static bool initialized;
  32. if (initialized)
  33. return;
  34. initialized = true;
  35. WNDCLASSEXW wndClass = {0};
  36. wndClass.cbSize = sizeof(wndClass);
  37. wndClass.style = CS_HREDRAW | CS_VREDRAW;
  38. wndClass.lpfnWndProc = DefWindowProcW;
  39. wndClass.hCursor = LoadCursor(0, IDC_ARROW);
  40. wndClass.hInstance = GetModuleHandle(0);
  41. wndClass.lpszClassName = hostWindowClassName;
  42. RegisterClassExW(&wndClass);
  43. }
  44. PlatformWebView::PlatformWebView(WKContextRef contextRef, WKPageGroupRef pageGroupRef, WKPageRef /* relatedPage */, WKDictionaryRef /*options*/)
  45. : m_windowIsKey(true)
  46. {
  47. registerWindowClass();
  48. RECT viewRect = {0, 0, 800, 600};
  49. m_window = CreateWindowExW(0, hostWindowClassName, L"WebKitTestRunner", WS_OVERLAPPEDWINDOW, 0 /*XOFFSET*/, 0 /*YOFFSET*/, viewRect.right, viewRect.bottom, 0, 0, GetModuleHandle(0), 0);
  50. m_view = WKViewCreate(viewRect, contextRef, pageGroupRef, m_window);
  51. WKViewSetIsInWindow(m_view, true);
  52. }
  53. PlatformWebView::~PlatformWebView()
  54. {
  55. if (::IsWindow(m_window))
  56. ::DestroyWindow(m_window);
  57. WKRelease(m_view);
  58. }
  59. void PlatformWebView::resizeTo(unsigned width, unsigned height)
  60. {
  61. ::SetWindowPos(WKViewGetWindow(m_view), 0, 0, 0, width, height, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOCOPYBITS);
  62. }
  63. WKPageRef PlatformWebView::page()
  64. {
  65. return WKViewGetPage(m_view);
  66. }
  67. void PlatformWebView::focus()
  68. {
  69. ::SetFocus(::WKViewGetWindow(m_view));
  70. }
  71. WKRect PlatformWebView::windowFrame()
  72. {
  73. // Implement.
  74. WKRect wkFrame;
  75. wkFrame.origin.x = 0;
  76. wkFrame.origin.y = 0;
  77. wkFrame.size.width = 0;
  78. wkFrame.size.height = 0;
  79. return wkFrame;
  80. }
  81. void PlatformWebView::setWindowFrame(WKRect)
  82. {
  83. // Implement.
  84. }
  85. void PlatformWebView::addChromeInputField()
  86. {
  87. }
  88. void PlatformWebView::removeChromeInputField()
  89. {
  90. }
  91. void PlatformWebView::makeWebViewFirstResponder()
  92. {
  93. }
  94. WKRetainPtr<WKImageRef> PlatformWebView::windowSnapshotImage()
  95. {
  96. // FIXME: implement to capture pixels in the UI process,
  97. // which may be necessary to capture things like 3D transforms.
  98. return 0;
  99. }
  100. void PlatformWebView::didInitializeClients()
  101. {
  102. }
  103. } // namespace WTR