<?xml version="1.0"?>

<!--
Can't yet put script tags in XBL (hyatt has the bug)
  <script type="text/javascript" src="chrome://embed/content/nsTransferable.js"/>
  <script type="text/javascript" src="chrome://embed/content/nsClipboard.js"/>
  <script type="text/javascript" src="chrome://embed/content/nsDragAndDrop.js"/>
-->

<bindings id="htmlBindings"
   xmlns="http://www.mozilla.org/xbl"
   xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

  <binding id="browserBase">
    <handlers>

      <handler event="draggesture">
<!--
         nsDragAndDrop.startDrag(event, contentAreaDNDObserver);
-->
      </handler>
      <handler event="dragover">
<!--
         nsDragAndDrop.dragOver(event, contentAreaDNDObserver);
-->
      </handler>
      <handler event="dragdrop">
<!--
         nsDragAndDrop.drop(event, contentAreaDNDObserver);
-->
      </handler>

      <handler event="keypress" key=" ">
      <![CDATA[
        var v = document.commandDispatcher.focusedElement;

        if (v) {
          switch (v.localName) {
            case 'TEXTAREA':
              return true;
    	      case 'INPUT':
              switch (v.getAttribute('type').toLowerCase()) {
		            case 'button':
		            case 'image':
		            case 'submit':
		            case 'reset':
		            case 'checkbox':
		            case 'radio':
		            case 'file':
            	    return true;
              }
	            break;
            case 'BUTTON':
              switch (v.getAttribute('type').toLowerCase()) {
                case 'submit':
		            case 'button':
		            case 'reset':
                  return true;
              }
	            break;
          }
        }
        var controller =
          document.commandDispatcher.getControllerForCommand('cmd_scrollPageDown');
          controller.doCommand('cmd_scrollPageDown');

        return true;
      ]]>
      </handler>
      <handler event="keypress" keycode="VK_PAGE_UP" command="cmd_scrollPageUp" />
      <handler event="keypress" keycode="VK_PAGE_DOWN" command="cmd_scrollPageDown" />

      <handler event="keypress" keycode="VK_UP" command="cmd_scrollLineUp" />
      <handler event="keypress" keycode="VK_DOWN" command="cmd_scrollLineDown" />
      <handler event="keypress" keycode="VK_LEFT" command="cmd_scrollLeft" />
      <handler event="keypress" keycode="VK_RIGHT" command="cmd_scrollRight" />

      <handler event="keypress" keycode="VK_HOME" command="cmd_scrollTop"/>
      <handler event="keypress" keycode="VK_END" command="cmd_scrollBottom"/>

      <handler event="keypress" key="x" command="cmd_cut" modifiers="accel"/>
      <handler event="keypress" key="c" command="cmd_copy" modifiers="accel"/>
      <handler event="keypress" key="v" command="cmd_paste" modifiers="accel"/>
      <handler event="keypress" key="z" command="cmd_undo" modifiers="accel"/>
      <handler event="keypress" key="y" command="cmd_redo" modifiers="accel"/>
    </handlers>
  </binding>

  <binding id="editorBase">
    <handlers>
      <handler event="keypress" keycode="VK_HOME" command="cmd_beginLine"/>
      <handler event="keypress" keycode="VK_END" command="cmd_endLine"/>
      <handler event="keypress" keycode="VK_LEFT" command="cmd_charPrevious"/>
      <handler event="keypress" keycode="VK_RIGHT" command="cmd_charNext"/>
      <handler event="keypress" keycode="VK_HOME" command="cmd_selectBeginLine" modifiers="shift"/>
      <handler event="keypress" keycode="VK_END" command="cmd_selectEndLine" modifiers="shift"/>
      <handler event="keypress" keycode="VK_LEFT" command="cmd_selectCharPrevious" modifiers="shift"/>
      <handler event="keypress" keycode="VK_RIGHT" command="cmd_selectCharNext" modifiers="shift"/>
      <handler event="keypress" keycode="VK_PAGE_UP" command="cmd_scrollPageUp"/>
      <handler event="keypress" keycode="VK_PAGE_DOWN" command="cmd_scrollPageDown"/>
      <handler event="keypress" keycode="VK_UP" command="cmd_linePrevious"/>
      <handler event="keypress" keycode="VK_DOWN" command="cmd_lineNext"/>
      <handler event="keypress" keycode="VK_UP" command="cmd_selectLinePrevious" modifiers="shift"/>
      <handler event="keypress" keycode="VK_DOWN" command="cmd_selectLineNext" modifiers="shift"/>
      <handler event="keypress" key="z" command="cmd_undo" modifiers="accel"/>
      <handler event="keypress" key="y" command="cmd_redo" modifiers="accel"/>
      <handler event="keypress" key="x" command="cmd_cut" modifiers="accel"/>
      <handler event="keypress" key="c" command="cmd_copy" modifiers="accel"/>
      <handler event="keypress" key="v" command="cmd_paste" modifiers="accel"/>
      <handler event="keypress" key="z" command="cmd_undo" modifiers="accel"/>
      <handler event="keypress" key="r" command="cmd_redo" modifiers="accel"/>

    </handlers>

  </binding>




  <binding id="inputFieldsBase">
    <handlers>

    <handler event="keypress" id="key_home" keycode="VK_HOME"
        command="cmd_beginLine"/>
    <handler event="keypress" id="key_end" keycode="VK_END"
        command="cmd_endLine"/>
    <handler event="keypress" id="key_left" keycode="VK_LEFT"
        command="cmd_charPrevious"/>
    <handler event="keypress" id="key_right" keycode="VK_RIGHT"
        command="cmd_charNext"/>
    <handler event="keypress" id="key_pageup" keycode="VK_PAGE_UP"
        command="cmd_scrollPageUp"/>
    <handler event="keypress" id="key_pagedown" keycode="VK_PAGE_DOWN"
        command="cmd_scrollPageDown"/>

    <handler event="keypress" id="key_homeshift" keycode="VK_HOME" modifiers="shift"
        command="cmd_selectBeginLine"/>
    <handler event="keypress" id="key_endshift" keycode="VK_END" modifiers="shift"
        command="cmd_selectEndLine"/>
    <handler event="keypress" id="key_leftshift" keycode="VK_LEFT" modifiers="shift"
        command="cmd_selectCharPrevious"/>
    <handler event="keypress" id="key_rightshift" keycode="VK_RIGHT" modifiers="shift"
        command="cmd_selectCharNext"/>
    <handler event="keypress" id="key_undo" key="z" modifiers="accel"
        command="cmd_undo"/>

    <!-- Cut/copy/paste/undo -->
    <handler event="keypress" id="key_copy" key="c" modifiers="accel"
        command="cmd_copy"/>
    <handler event="keypress" id="key_cut" key="x" modifiers="accel"
        command="cmd_cut"/>
    <handler event="keypress" id="key_paste" key="v" modifiers="accel"
        command="cmd_paste"/>
    <handler event="keypress" id="key_undo" key="z" modifiers="accel"
        command="cmd_undo"/>

    </handlers>
  </binding>

  <binding id="textAreasBase">
    <handlers>

    <handler event="keypress" id="key_left" keycode="VK_LEFT"
        command="cmd_charPrevious"/>
    <handler event="keypress" id="key_right" keycode="VK_RIGHT"
        command="cmd_charNext"/>
    <handler event="keypress" id="key_leftshift" keycode="VK_LEFT" modifiers="shift"
        command="cmd_selectCharPrevious"/>
    <handler event="keypress" id="key_rightshift" keycode="VK_RIGHT" modifiers="shift"
        command="cmd_selectCharNext"/>
    <handler event="keypress" id="key_up" keycode="VK_UP"
        command="cmd_linePrevious"/>
    <handler event="keypress" id="key_down" keycode="VK_DOWN"
        command="cmd_lineNext"/>
    <handler event="keypress" id="key_up_shift" keycode="VK_UP" modifiers="shift"
        command="cmd_selectLinePrevious"/>
    <handler event="keypress" id="key_down_shift" keycode="VK_DOWN" modifiers="shift"
        command="cmd_selectLineNext"/>
    <handler event="keypress" id="key_pageup" keycode="VK_PAGE_UP"
        command="cmd_scrollPageUp"/>
    <handler event="keypress" id="key_pagedown" keycode="VK_PAGE_DOWN"
        command="cmd_scrollPageDown"/>
    <handler event="keypress" id="key_undo" key="z" modifiers="accel"
        command="cmd_undo"/>

    <!-- Cut/copy/paste/undo -->
    <handler event="keypress" id="key_copy" key="c" modifiers="accel"
        command="cmd_copy"/>
    <handler event="keypress" id="key_cut" key="x" modifiers="accel"
        command="cmd_cut"/>
    <handler event="keypress" id="key_paste" key="v" modifiers="accel"
        command="cmd_paste"/>
    <handler event="keypress" id="key_undo" key="z" modifiers="accel"
        command="cmd_undo"/>

    </handlers>
  </binding>


</bindings>
