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 V_VT(pVar) = VT_UNKNOWN;
122 V_UNKNOWN(pVar) = WebElementPropertyBag::createInstance(m_frame->eventHandler()->hitTestResultAtPoint(point, false));
125 } else if (isEqual(pszPropName, WebActionButtonKey)) {
126 if (const MouseEvent* mouseEvent = findMouseEvent(m_action.event())) {
128 V_I4(pVar) = mouseEvent->button();
131 } else if (isEqual(pszPropName, WebActionOriginalURLKey)) {
132 V_VT(pVar) = VT_BSTR;
133 V_BSTR(pVar) = BString(m_action.url().string()).release();
135 } else if (isEqual(pszPropName, WebActionModifierFlagsKey)) {
136 if (const UIEventWithKeyState* keyEvent = findEventWithKeyState(const_cast<Event*>(m_action.event()))) {
139 if (keyEvent->ctrlKey())
140 modifiers |= MK_CONTROL;
141 if (keyEvent->shiftKey())
142 modifiers |= MK_SHIFT;
143 if (keyEvent->altKey())
147 V_I4(pVar) = modifiers;
154 HRESULT STDMETHODCALLTYPE WebActionPropertyBag::Write(LPCOLESTR pszPropName, VARIANT* pVar)
156 if (!pszPropName || !pVar)