WebBrowserComponent suggestions

Jules - here are some suggested fixes for some niggles I have with the WebBrowserComponent.

Niggle 1

On Windows the ActiveX browser won't take the focus if you give the focus to it's containing component. This means that you can't mousewheel to scroll unless you click inside the browser first. This can be sorted by adding a focusGained method to the pimpl and executing the following:

    //  Activates UI of ActiveX browser control
    IOleObject* oleObject = (IOleObject*)browser->queryInterface (&__uuidof (IOleObject));
    IOleWindow* oleWindow = (IOleWindow*)browser->queryInterface (&__uuidof (IOleWindow));
    IOleClientSite* pActiveSite = nullptr; // Assign nullptr to avoid warning
    if (oleObject != nullptr && oleWindow != nullptr && oleObject->GetClientSite (&pActiveSite) == S_OK)
        HWND hwnd;
        oleWindow->GetWindow (&hwnd);
        oleObject->DoVerb (OLEIVERB_UIACTIVATE, NULL, pActiveSite, 0, hwnd, NULL);
    if (pActiveSite != nullptr) pActiveSite->Release ();
    if (oleObject != nullptr) oleObject->Release ();
    if (oleWindow != nullptr) oleWindow->Release ();

This doesn't seem to be an issue on OS X, and iOS/Android require touching to scroll so it shouldn't be a problem there either.


Niggle 2

The other inconsistency is that on Windows you can execute javascript code with the goToUrl() method but you can't do this on Mac. The attached .mm file uses WebView:stringByEvaluatingJavaScriptFromString to sort this out. I've tested this on OS X but not on iOS.

Joining Niggle 1. I would love not having to make it attached to the desktop to go around this.

Did you actually test that code? It doesn't look like the "browser->queryInterface" call will compile unless you actually mean that you put the focusGained call in the WebBrowserComponent class rather than the pimpl?

How about this as a cleaned up version?

        if (IOleObject* oleObject = (IOleObject*) queryInterface (&IID_IOleObject))
            if (IOleWindow* oleWindow = (IOleWindow*) queryInterface (&IID_IOleWindow))
                IOleClientSite* oleClientSite = nullptr;

                if (SUCCEEDED (oleObject->GetClientSite (&oleClientSite)))
                    HWND hwnd;
                    oleWindow->GetWindow (&hwnd);
                    oleObject->DoVerb (OLEIVERB_UIACTIVATE, nullptr, oleClientSite, 0, hwnd, nullptr);



Sorry Jules - I did test it successfully but I shouldn't post in a hurry late at night! I did add it to the WebBrowserComponent class and not the pimpl (must have been thinking about the pimpl stuff for niggle 2).

I assume you've added that cleaned up code to the pimpl after all as you're calling queryInterface directly. Adding it there and calling it from WebBrowserComponent::focusGained works nicely for me.

ok, thanks, I'll add it shortly.