2 * Copyright (C) 2007 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
27 #include "WebKitDLL.h"
30 #include "IWebPolicyDelegate.h"
31 #include "WebActionPropertyBag.h"
32 #include "WebElementPropertyBag.h"
35 #pragma warning(push, 0)
36 #include <WebCore/BString.h>
37 #include <WebCore/EventHandler.h>
38 #include <WebCore/MouseEvent.h>
39 #include <WebCore/HitTestResult.h>
42 using namespace WebCore;
44 // WebActionPropertyBag ------------------------------------------------
45 WebActionPropertyBag::WebActionPropertyBag(const NavigationAction& action, Frame* frame)
52 WebActionPropertyBag::~WebActionPropertyBag()
56 WebActionPropertyBag* WebActionPropertyBag::createInstance(const NavigationAction& action, Frame* frame)
58 WebActionPropertyBag* instance = new WebActionPropertyBag(action, frame);
64 // IUnknown -------------------------------------------------------------------
66 HRESULT STDMETHODCALLTYPE WebActionPropertyBag::QueryInterface(REFIID riid, void** ppvObject)
69 if (IsEqualGUID(riid, IID_IUnknown))
70 *ppvObject = static_cast<IPropertyBag*>(this);
71 else if (IsEqualGUID(riid, IID_IPropertyBag))
72 *ppvObject = static_cast<IPropertyBag*>(this);
80 ULONG STDMETHODCALLTYPE WebActionPropertyBag::AddRef(void)
85 ULONG STDMETHODCALLTYPE WebActionPropertyBag::Release(void)
87 ULONG newRef = --m_refCount;
94 static bool isEqual(LPCWSTR s1, LPCWSTR s2)
96 return !wcscmp(s1, s2);
99 static const MouseEvent* findMouseEvent(const Event* event)
101 for (const Event* e = event; e; e = e->underlyingEvent())
102 if (e->isMouseEvent())
103 return static_cast<const MouseEvent*>(e);
107 HRESULT STDMETHODCALLTYPE WebActionPropertyBag::Read(LPCOLESTR pszPropName, VARIANT *pVar, IErrorLog * /*pErrorLog*/)
114 if (isEqual(pszPropName, WebActionNavigationTypeKey)) {
116 V_I4(pVar) = m_action.type();
118 } else if (isEqual(pszPropName, WebActionElementKey)) {
119 if (const MouseEvent* mouseEvent = findMouseEvent(m_action.event())) {
120 IntPoint point(mouseEvent->clientX(), mouseEvent->clientY());
121 COMPtr<WebElementPropertyBag> elementPropertyBag;
122 elementPropertyBag.adoptRef(WebElementPropertyBag::createInstance(m_frame->eventHandler()->hitTestResultAtPoint(point, false)));
124 V_VT(pVar) = VT_UNKNOWN;
125 elementPropertyBag->QueryInterface(IID_IUnknown, (void**)V_UNKNOWNREF(pVar));
128 } else if (isEqual(pszPropName, WebActionButtonKey)) {
129 if (const MouseEvent* mouseEvent = findMouseEvent(m_action.event())) {
131 V_I4(pVar) = mouseEvent->button();
134 } else if (isEqual(pszPropName, WebActionOriginalURLKey)) {
135 V_VT(pVar) = VT_BSTR;
136 V_BSTR(pVar) = BString(m_action.url().string()).release();
138 } else if (isEqual(pszPropName, WebActionModifierFlagsKey)) {
139 if (const UIEventWithKeyState* keyEvent = findEventWithKeyState(const_cast<Event*>(m_action.event()))) {
142 if (keyEvent->ctrlKey())
143 modifiers |= MK_CONTROL;
144 if (keyEvent->shiftKey())
145 modifiers |= MK_SHIFT;
146 if (keyEvent->altKey())
150 V_I4(pVar) = modifiers;
157 HRESULT STDMETHODCALLTYPE WebActionPropertyBag::Write(LPCOLESTR pszPropName, VARIANT* pVar)
159 if (!pszPropName || !pVar)