On Jan 5, 1:30 pm, Drew <drewt...@gmail.com> wrote:
> On Dec 31 2008, 3:24 pm, Drew <drewt...@gmail.com> wrote:
>
>
>
>
>
> > I'm attempting to get the mousewheel working for my embedding browser.
> > Here's where I'm stuck.
>
> > If I set the focus on an element in a page (drop-down, textbox, or
> > press tab to an element) I receive WM_MOUSEWHEEL events in my message
> > handler. I pass these on
>
> > However, if I click on the background of a webpage I send a mouse down
> > event to Mozilla (that's all). This obviously causes any element in
> > the page to lose it's focus and I no longer receive WM_MOUSEWHEEL
> > events to my message handler.
>
> > I've tried calling nsIWebBrowserFocus::Activate on the mouse up event,
> > but this doesn't fix it. Does anyone have any other suggestions?
>
> > Thanks
>
> I've narrowed down the problem a little so I thought I would repost
> with some more information and see if anyone has a clue.
>
> I forgot to mention that I'm working in the 1.8 branch of the Mozilla
> code.
>
> I noticed I shouldn't have to handle the WM_MOUSEWHEEL messages, so I
> removed my code that does that. Mozilla handles these messages
> automatically.
>
> I noticed the problem with my scrolling occurs in the DoScrollText()
> method of the nsEventStateManager object. There is a call to
> GetFocusedContent on line 1830 that fails when nothing has the focus.
>
>   nsCOMPtr<nsIContent> targetContent = aTargetFrame->GetContent();
>   if (!targetContent)
>     GetFocusedContent(getter_AddRefs(targetContent));
>   if (!targetContent) return NS_OK;
>
> When I click on the background, no object has the focus. Does anyone
> know how I can simulate something to have the focus so that I can
> still scroll a page when clicking on just the background?
>
> I've looked at nsWebBrowser::SetFocusAtFirstElement() but that just
> returns NS_OK.- Hide quoted text -
>
> - Show quoted text -

For those looking for a way to do it, here's how I solved it. Not the
greatest solution, but it solves the problem for me.

In my event handler, I handle the "click" event. I then check to see
if any element has focus. If nothing does, I call
nsIEventStateManager::ShiftFocus().

Here's a snippet.

    nsCOMPtr< nsIWebBrowserFocus > focus ( do_QueryInterface
( m_webBrowser ) );
    if ( focus )
    {
      nsCOMPtr<nsIDOMElement> element;
      focus->GetFocusedElement( getter_AddRefs( element ) );

      if ( !element )
      {
        nsCOMPtr< nsIDocShell > docShell = do_GetInterface
( m_webBrowser );
        if ( !docShell )
          return PR_FALSE;

        nsCOMPtr< nsPresContext > presContext;
        docShell->GetPresContext( getter_AddRefs( presContext ) );
        if ( !presContext )
          return PR_FALSE;

        nsIEventStateManager* esm = presContext->EventStateManager();
        if ( !esm )
          return PR_FALSE;

        esm->ShiftFocus( PR_TRUE, nsnull );
      }
    }
_______________________________________________
dev-embedding mailing list
dev-embedding@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-embedding

Reply via email to