Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Mouse Gestures for Internet Explorer

, 21 Sep 2005
Adding mouse gesture recognition to Internet Explorer.
mousegestures_inst.zip
MouseGestures.exe
mousegestures_inst_1.zip
MouseGestures.exe
mousegestures_src.zip
src
gesture.weights
images
about.bmp
ClickLeftRight.bmp
ClickRightLeft.bmp
down.bmp
downarrow.bmp
downleft.bmp
downright.bmp
downup.bmp
exclamation.bmp
left.bmp
leftarrow.bmp
leftright.bmp
none.bmp
right.bmp
rightarrow.bmp
rightleft.bmp
up.bmp
uparrow.bmp
updown.bmp
upleft.bmp
upright.bmp
wheel.bmp
MouseGestures.rgs
mousegestures_src_1.zip
MouseGestures
BrowserHelperObject.rgs
gesture.weights
images
about.bmp
ClickLeftRight.bmp
ClickRightLeft.bmp
down.bmp
downleft.bmp
downright.bmp
downup.bmp
left.bmp
none.bmp
right.bmp
up.bmp
updown.bmp
upleft.bmp
upright.bmp
wheel.bmp
MouseGestures.def
MouseGestures.dsp
MouseGesturesCfg.rgs
///////////////////////////////////////////////////////////////
//
// BrowserWatcher60.cpp
//
// Created: 23/09/2003
// Copyright (c) 2003 Ralph Hare (ralph.hare@ysgyfarnog.co.uk)
// All rights reserved.
//
// The code and information is provided "as-is" without
// warranty of any kind, either expressed or implied.
//
///////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "BrowserWatcher60.h"
#include "WindowHelper.h"
#include "ComUtils.h"

namespace IE60
{
    HRESULT GetElementOffset( IHTMLElement *pElement, SIZE &offset )
    {
        if( !pElement )
        {
            return E_POINTER;
        }
        
    //
    // as we're zeroing the offset structure here, be sure
    // to perform the recursive step before adding the offset
    // of the current element
    //
        ::ZeroMemory( &offset, sizeof( SIZE ) );

        ThrowHResult    hr;

        try
        {
        //
        // do we need to recurse up the element hierarchy?
        //
            CComPtr< IHTMLElement > pParent;
            hr = pElement->get_parentElement( &pParent );
            if( pParent )
            {
                hr = GetElementOffset( pParent, offset );
            }

            long    cx, cy;
            hr = pElement->get_offsetLeft( &cx );
            hr = pElement->get_offsetTop( &cy );

            offset.cx += cx;
            offset.cy += cy;
        }
        catch( HRESULT )
        {
        }

        return hr;
    }

/**
 * Ascend the frame hierarchy (if any) until we find the first non-frame HTML 
 * element at the specified position
 **/
    HRESULT HitTest( IWebBrowser2 *pWB, const POINT &pt, IHTMLElement **ppElement )
    {
        if( pWB == NULL )
        {
            return E_INVALIDARG;
        }

        if( !ppElement )
        {
            return E_POINTER;
        }

        *ppElement = NULL;

        ThrowHResult    hr;

        try
        {
        //
        // get the document associated with this web browser object
        //
            CComPtr< IDispatch >    pDisp;
            hr = pWB->get_Document( &pDisp );

        //
        // is it an HTML document?
        //
            CComQIPtr< IHTMLDocument2 >   pDoc = pDisp;

            if( pDoc == NULL )
            {
            //
            // no - nothing more doing
            //
                return S_OK;
            }

        //
        // get the element at the specified point
        //
            CComPtr< IHTMLElement > pElement;
            hr = pDoc->elementFromPoint( pt.x, pt.y, &pElement );

            if( pElement == NULL )
            {
                return S_OK;
            }

        //
        // it could be a nested frame - if so we need to
        // drill down
        //
            CComQIPtr< IWebBrowser2 >   pFrame = pElement;

            if( pFrame )
            {
            //
            // how far is the frame nested within the document?
            //
                SIZE    offset;
                hr = GetElementOffset( pElement, offset );

                POINT   ptInFrame = { pt.x - offset.cx, pt.y - offset.cy };

                return HitTest( pFrame, ptInFrame, ppElement );
            }

        //
        // return the element we've found to the user
        //
            hr = pElement->QueryInterface( 
                                    IID_IHTMLElement,
                                    reinterpret_cast< void ** >( ppElement )
                                    );
        }
        catch( HRESULT )
        {
        }

        return hr;
    }
}

BrowserWatcher60::BrowserWatcher60( 
                                IWebBrowser2 *pWebBrowser, 
                                GestureTracker::Observer *pObserver 
                                ) :
    BrowserWatcher( pWebBrowser, pObserver )
{
}

HRESULT BrowserWatcher60::HitTest( HWND, const POINT &pt, IHTMLElement **ppElement )
{
    return IE60::HitTest( GetWebBrowser(), pt, ppElement );
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Ralph Hare
Web Developer
United Kingdom United Kingdom
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141223.1 | Last Updated 21 Sep 2005
Article Copyright 2003 by Ralph Hare
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid