1

How to block middle mouse click on the links in TChromium?
I want to handle this middle mouse click by my own to open it in new tab, so i need to block this middle mouse click in TChromium, and then hook middle mouse, and then open selected link in new tab.
I have this default function:

function TCustomRenderProcessHandler.OnBeforeNavigation(const browser: ICefBrowser;
  const frame: ICefFrame; const request: ICefRequest;
  navigationType: TCefNavigationType; isRedirect: Boolean): Boolean;
begin
  Result:=False;
end;

But exactly it gives nothing.
TNX

Priler
  • 149
  • 1
  • 10
  • Yes, it does nothing because you should return True to cancel the navigation, but I posted you before a [`link to that event reference`](http://magpcss.org/ceforum/apidocs3/projects/(default)/CefRenderProcessHandler.html#OnBeforeNavigation) where it's clearly stated. Even though you've shown no effort to learn something, here you have a short [`proof of concept`](http://pastebin.com/pNF1RmFb). But I'm not a hook expert and don't know if there's a better time to hook the mouse. – TLama Aug 07 '13 at 10:18
  • Proof not works, `MiddleMouse` is always equals `False` in `OnBeforeNavigation`, but in `Form1` it works fine. – Priler Aug 07 '13 at 13:36

1 Answers1

1

I did it by some another way.
@TLama, thanks for fast working Hook Function.
So, how i did it:

    //@HOOK PROC
    function MouseProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
    var
      HookStruct: TMouseHookStruct;
    begin
      HookStruct := PMouseHookStruct(lParam)^;

      if (nCode >= 0) then
      begin
        case wParam of
          WM_MBUTTONDOWN:
            Begin
              MiddleDown := True;
              LeftMouse := False;
            End;

          WM_LBUTTONDOWN:
            Begin
              MiddleDown := False;
              LeftMouse := True;
            End;

          WM_RBUTTONDOWN:
            Begin
              MiddleDown := False;
              LeftMouse := False;
            End;
        end;
      end;

      Result := CallNextHookEx(0, nCode, wParam, lParam);
    end;

    procedure TForm1.Timer1Timer(Sender: TObject);
    begin
      If(MiddleDown) then
        Begin
          MiddleDown:=False;
          If(SelectedItem<>'') Then
            Form1.AddNewTab(SelectedItem,SelectedItem,'');
        End
      Else If(LeftMouse) then
        Begin
          LeftMouse:=False;
          If(SelectedItem<>'') Then
            FBrowsers[Current_FBrowser_Index].Load(SelectedItem);
        End;
    end;

function TCustomRenderProcessHandler.OnBeforeNavigation(const browser: ICefBrowser;
  const frame: ICefFrame; const request: ICefRequest;
  navigationType: TCefNavigationType; isRedirect: Boolean): Boolean;
begin

  if navigationType = NAVIGATION_LINK_CLICKED then
  begin
    Result := True;
  end
  else
    Result := False;
end;

So, thats how it works in my DCEF3 :)
Thanks to all for help!!!

Priler
  • 149
  • 1
  • 10
  • You should be able to read the value of `MiddleDown` global variable in `OnBeforeNavigation` event without any problem. Now you have no relation between an ordinary mouse click and a link click at all. – TLama Aug 07 '13 at 14:11
  • I have relation between click and linkclick by this `If(SelectedItem<>'') Then`. I had no choise, `MiddleDown` is always equals `False` in `OnBeforeNavigation` – Priler Aug 07 '13 at 14:13
  • Not in the code you've posted here. The project on pastebin I've tested in Delphi 7 and XE3. In both cases it works as expected. – TLama Aug 07 '13 at 14:23
  • I don't want to discuss this anymore. I've tested that code with the most recent CEF3 in Delphi 7 and XE3 and it worked in both versions... And I can't even see the reason why would you couldn't read that value in `OnBeforeNavigation` event method. – TLama Aug 07 '13 at 14:56
  • Well, i dont know why it happens, but it not works in my DCEF3 in XE3 – Priler Aug 07 '13 at 15:37
  • @TLama, sorry, its my mistake... Code you've posted works greate! Its my fall, sorry again. I placed codes not right, so in case of that it was not working, but now i tested your code fully and it exactly works fine!!! Thanks, and sorry again :) – Priler Aug 07 '13 at 21:22
  • @TLama, look at this please - http://stackoverflow.com/questions/18114850/strange-issue-with-dcef3 – Priler Aug 07 '13 at 22:36