WebActionPropertyBag.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. * Copyright (C) 2007, 2008 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 COMPUTER, INC. ``AS IS'' AND ANY
  14. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  15. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
  17. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  20. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  21. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  23. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #include "config.h"
  26. #include "WebKitDLL.h"
  27. #include "WebActionPropertyBag.h"
  28. #include "DOMCoreClasses.h"
  29. #include "WebElementPropertyBag.h"
  30. #include "WebKit.h"
  31. #include <WebCore/BString.h>
  32. #include <WebCore/COMPtr.h>
  33. #include <WebCore/EventHandler.h>
  34. #include <WebCore/HitTestResult.h>
  35. #include <WebCore/MouseEvent.h>
  36. using namespace WebCore;
  37. // WebActionPropertyBag ------------------------------------------------
  38. WebActionPropertyBag::WebActionPropertyBag(const NavigationAction& action, PassRefPtr<HTMLFormElement> form, PassRefPtr<Frame> frame)
  39. : m_refCount(0)
  40. , m_action(action)
  41. , m_form(form)
  42. , m_frame(frame)
  43. {
  44. gClassCount++;
  45. gClassNameCount.add("WebActionPropertyBag");
  46. }
  47. WebActionPropertyBag::~WebActionPropertyBag()
  48. {
  49. gClassCount--;
  50. gClassNameCount.remove("WebActionPropertyBag");
  51. }
  52. WebActionPropertyBag* WebActionPropertyBag::createInstance(const NavigationAction& action, PassRefPtr<HTMLFormElement> form, PassRefPtr<Frame> frame)
  53. {
  54. WebActionPropertyBag* instance = new WebActionPropertyBag(action, form, frame);
  55. instance->AddRef();
  56. return instance;
  57. }
  58. // IUnknown -------------------------------------------------------------------
  59. HRESULT STDMETHODCALLTYPE WebActionPropertyBag::QueryInterface(REFIID riid, void** ppvObject)
  60. {
  61. *ppvObject = 0;
  62. if (IsEqualGUID(riid, IID_IUnknown))
  63. *ppvObject = static_cast<IPropertyBag*>(this);
  64. else if (IsEqualGUID(riid, IID_IPropertyBag))
  65. *ppvObject = static_cast<IPropertyBag*>(this);
  66. else
  67. return E_NOINTERFACE;
  68. AddRef();
  69. return S_OK;
  70. }
  71. ULONG STDMETHODCALLTYPE WebActionPropertyBag::AddRef()
  72. {
  73. return ++m_refCount;
  74. }
  75. ULONG STDMETHODCALLTYPE WebActionPropertyBag::Release()
  76. {
  77. ULONG newRef = --m_refCount;
  78. if (!newRef)
  79. delete this;
  80. return newRef;
  81. }
  82. static bool isEqual(LPCWSTR s1, LPCWSTR s2)
  83. {
  84. return !wcscmp(s1, s2);
  85. }
  86. static const MouseEvent* findMouseEvent(const Event* event)
  87. {
  88. for (const Event* e = event; e; e = e->underlyingEvent())
  89. if (e->isMouseEvent())
  90. return static_cast<const MouseEvent*>(e);
  91. return 0;
  92. }
  93. HRESULT STDMETHODCALLTYPE WebActionPropertyBag::Read(LPCOLESTR pszPropName, VARIANT *pVar, IErrorLog * /*pErrorLog*/)
  94. {
  95. if (!pszPropName)
  96. return E_POINTER;
  97. VariantClear(pVar);
  98. if (isEqual(pszPropName, WebActionNavigationTypeKey)) {
  99. V_VT(pVar) = VT_I4;
  100. V_I4(pVar) = m_action.type();
  101. return S_OK;
  102. }
  103. if (isEqual(pszPropName, WebActionElementKey)) {
  104. if (const MouseEvent* mouseEvent = findMouseEvent(m_action.event())) {
  105. V_VT(pVar) = VT_UNKNOWN;
  106. V_UNKNOWN(pVar) = WebElementPropertyBag::createInstance(m_frame->eventHandler()->hitTestResultAtPoint(mouseEvent->absoluteLocation()));
  107. return S_OK;
  108. }
  109. }
  110. if (isEqual(pszPropName, WebActionButtonKey)) {
  111. if (const MouseEvent* mouseEvent = findMouseEvent(m_action.event())) {
  112. V_VT(pVar) = VT_I4;
  113. V_I4(pVar) = mouseEvent->button();
  114. return S_OK;
  115. }
  116. }
  117. if (isEqual(pszPropName, WebActionOriginalURLKey)) {
  118. V_VT(pVar) = VT_BSTR;
  119. V_BSTR(pVar) = BString(m_action.url().string()).release();
  120. return S_OK;
  121. }
  122. if (isEqual(pszPropName, WebActionModifierFlagsKey)) {
  123. if (const UIEventWithKeyState* keyEvent = findEventWithKeyState(const_cast<Event*>(m_action.event()))) {
  124. unsigned modifiers = 0;
  125. if (keyEvent->ctrlKey())
  126. modifiers |= MK_CONTROL;
  127. if (keyEvent->shiftKey())
  128. modifiers |= MK_SHIFT;
  129. if (keyEvent->altKey())
  130. modifiers |= MK_ALT;
  131. V_VT(pVar) = VT_UI4;
  132. V_UI4(pVar) = modifiers;
  133. return S_OK;
  134. }
  135. }
  136. if (isEqual(pszPropName, WebActionFormKey)) {
  137. IDOMNode* form = DOMNode::createInstance(m_form.get());
  138. V_VT(pVar) = VT_UNKNOWN;
  139. V_UNKNOWN(pVar) = form;
  140. return S_OK;
  141. }
  142. return E_INVALIDARG;
  143. }
  144. HRESULT STDMETHODCALLTYPE WebActionPropertyBag::Write(LPCOLESTR pszPropName, VARIANT* pVar)
  145. {
  146. if (!pszPropName || !pVar)
  147. return E_POINTER;
  148. return E_FAIL;
  149. }