How to disable shortcuts in Geckofx engine C#

Discuss building things with or for the Mozilla Platform.
Post Reply
Tomektls
Posts: 2
Joined: February 5th, 2015, 6:35 am

How to disable shortcuts in Geckofx engine C#

Post by Tomektls »

Hi,

In IE Browser there is:
https://msdn.microsoft.com/en-us/librar ... 10%29.aspx

and the line:
this.WebBrowserShortcutsEnabled = false;
Disalbling all shortcuts in IE. l

How to do it in Gecko?

I need this to handle refresh button (f5) with my own methods, not with default gecko refresh.

I am writing about this:
https://bitbucket.org/geckofx/geckofx-31.0
User avatar
patrickjdempsey
Posts: 23686
Joined: October 23rd, 2008, 11:43 am
Location: Asheville NC
Contact:

Re: How to disable shortcuts in Geckofx engine C#

Post by patrickjdempsey »

No-one is going to read through the source code for your project to try to figure out what it does. What exactly are you trying to do?

Either way, that IE method is probably complete overkill for just changing one shortcut which can be done pretty simply with an overlay.
Tip of the day: If it has "toolbar" in the name, it's crap.
What my avatar is about: https://addons.mozilla.org/en-US/seamonkey/addon/sea-fox/
Tomektls
Posts: 2
Joined: February 5th, 2015, 6:35 am

Re: How to disable shortcuts in Geckofx engine C#

Post by Tomektls »

patrickjdempsey wrote:No-one is going to read through the source code for your project to try to figure out what it does. What exactly are you trying to do?

It isn't my source code, it is GeckoFX engine for .net :)
I am trying to do: capture this key and handle refresh with my own methods/override methods/. For example: I want to a lock refresh button and key until ULR has "http" header.

patrickjdempsey wrote:Either way, that IE method is probably complete overkill for just changing one shortcut which can be done pretty simply with an overlay.

There is no problem at all, I don't need other shortcuts, and it's works.
User avatar
patrickjdempsey
Posts: 23686
Joined: October 23rd, 2008, 11:43 am
Location: Asheville NC
Contact:

Re: How to disable shortcuts in Geckofx engine C#

Post by patrickjdempsey »

Ahh. It would be a trivial thing to do in a Firefox extension, but no clue about how .net programming works. TMK the shortcuts are not defined in C# at all, but in an XUL overlay that uses a series of localization files to build up the shortcuts.

One of the (localized) keyboard shortcuts is found in browser.dtd:

Code: Select all

<!ENTITY reloadCmd.commandkey         "r">


More keyboard shortcuts (F5 and modified Ctrl+Shift+R) are defined in browser.xul:

Code: Select all

<key keycode="VK_F5" command="Browser:Reload"/>

<key keycode="VK_F5" command="Browser:ReloadSkipCache" modifiers="accel"/>

<key key="&reloadCmd.commandkey;" command="Browser:Reload" modifiers="accel" id="key_reload"/>
<key key="&reloadCmd.commandkey;" command="Browser:ReloadSkipCache" modifiers="accel,shift"/>


And the commands are defined in browser.xul (ReloadOrDuplicate makes a duplicate tab if the Ctrl or middle mouse button is pressed):

Code: Select all

<command id="Browser:Reload"  oncommand="if (event.shiftKey) BrowserReloadSkipCache(); else BrowserReload()" disabled="true"/>
<command id="Browser:ReloadOrDuplicate" oncommand="BrowserReloadOrDuplicate(event)" disabled="true">
      <observes element="Browser:Reload" attribute="disabled"/>
</command>
<command id="Browser:ReloadSkipCache" oncommand="BrowserReloadSkipCache()" disabled="true">
      <observes element="Browser:Reload" attribute="disabled"/>
</command>


And all of that runs through browser.js:

Code: Select all

function BrowserReloadOrDuplicate(aEvent) {
  var backgroundTabModifier = aEvent.button == 1 ||
//@line 1735 "e:\builds\moz2_slave\rel-m-rel-w32_bld-000000000000\build\browser\base\content\browser.js"
    aEvent.ctrlKey;
//@line 1737 "e:\builds\moz2_slave\rel-m-rel-w32_bld-000000000000\build\browser\base\content\browser.js"
  if (aEvent.shiftKey && !backgroundTabModifier) {
    BrowserReloadSkipCache();
    return;
  }

  let where = whereToOpenLink(aEvent, false, true);
  if (where == "current")
    BrowserReload();
  else
    duplicateTabIn(gBrowser.selectedTab, where);
}

function BrowserReload() {
  const reloadFlags = nsIWebNavigation.LOAD_FLAGS_NONE;
  BrowserReloadWithFlags(reloadFlags);
}

function BrowserReloadSkipCache() {
  // Bypass proxy and cache.
  const reloadFlags = nsIWebNavigation.LOAD_FLAGS_BYPASS_PROXY | nsIWebNavigation.LOAD_FLAGS_BYPASS_CACHE;
  BrowserReloadWithFlags(reloadFlags);
}

function BrowserReloadWithFlags(reloadFlags) {
  let url = gBrowser.currentURI.spec;
  if (gBrowser._updateBrowserRemoteness(gBrowser.selectedBrowser,
                                        gBrowser._shouldBrowserBeRemote(url))) {
    // If the remoteness has changed, the new browser doesn't have any
    // information of what was loaded before, so we need to load the previous
    // URL again.
    gBrowser.loadURIWithFlags(url, reloadFlags);
    return;
  }

  /* First, we'll try to use the session history object to reload so
   * that framesets are handled properly. If we're in a special
   * window (such as view-source) that has no session history, fall
   * back on using the web navigation's reload method.
   */

  var webNav = gBrowser.webNavigation;
  try {
    var sh = webNav.sessionHistory;
    if (sh)
      webNav = sh.QueryInterface(nsIWebNavigation);
  } catch (e) {
  }

  try {
    webNav.reload(reloadFlags);
  } catch (e) {
  }
}


Note that none of this includes the code for the menus, just the direct shortcuts and the button.
Tip of the day: If it has "toolbar" in the name, it's crap.
What my avatar is about: https://addons.mozilla.org/en-US/seamonkey/addon/sea-fox/
johnsijems
Posts: 1
Joined: October 22nd, 2015, 12:32 am

Re: How to disable shortcuts in Geckofx engine C#

Post by johnsijems »

hi...

3
down vote
favorite


update: I've modified the code below to reveal some additional information regarding the key that was pressed.

update #2: I've discovered the root cause of the issue: we have an HTML control (Gecko rendering engine) on our form. When that Gecko rendering engine navigates to some Flash control, suddenly ~2% of our key presses don't get through, even after we've removed the Gecko HTML control. Wahoo, I get to blame this on Flash! Now the question is, how do I fix this?

update #3: Nope, it's not Flash. It's the Gecko rendering engine. Navigating even to Google causes some keys to not come through to our app right. Hrmmm.

We have a strange case in our WinForms app where the user presses a key combination (in this case, Alt + S), and WinForms tells us some other key combo (value 262162) is pressed:

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if(keyData == (Keys.S | Keys.Alt))
{
Console.WriteLine("You pressed Alt+S");
}
else if(keyData == (Keys.Menu | Keys.Alt))
{
Console.WriteLine("What the hell?"); // This sometimes gets hit when I press Alt+S
}
}
Post Reply