<commit_before>/**
 * Copyright 2009 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
package org.waveprotocol.wave.client.common.util;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.user.client.Event;

/**
 * Attempts to bring sanity to the incredibly complex and inconsistent world of
 * browser events, especially with regards to key events.
 *
 * {@link SignalEventImpl}
 *
 * @author <EMAIL> (<NAME>)
 */
public interface SignalEvent {

  /**
   * The "type" of key signal. The type is defined by us, based on a convenient
   * classification of these events.
   */
  public enum KeySignalType {
    /**
     * Typing in the form of inputting text
     *
     * NOTE: "TAB" is treated as INPUT.
     */
    INPUT,
    /** Moving around */
    NAVIGATION,
    /** Deleting text (Backspace + Delete) */
    DELETE,
    /** Other, like ESC or F3, that by themselves will do nothing to the document */
    NOEFFECT,
    /** Sentinal for debugging purposes only */
    SENTINAL
  }

  /**
   * The "movement unit" of this event. For example, on windows and linux,
   * holding down CTRL whilst navigating left and right with the arrow
   * keys moves a word at a time. Even more importantly, move units
   * are used for deleting text.
   */
  public enum MoveUnit {
    /** A character at a time */
    CHARACTER,
    /** A word at a time */
    WORD,
    /** To the start or end of the line */
    LINE,
    /** A "page" at a time */
    PAGE,
    /** To the start or end of the document */
    DOCUMENT
  }

  /**
   * These are the currently supported modifier combinations
   *
   * Supporting more requires tricky, browser-specific code. Go to the experiment harness
   * and have a look at the wonders....
   */
  public enum KeyModifier {
    /** No modifiers are pressed */
    NONE {
      @Override
      public boolean check(SignalEvent event) {
        return !event.getShiftKey() && !event.getAltKey()
            && !event.getCtrlKey() && !event.getMetaKey();
      }
    },
    /** Only shift is pressed */
    SHIFT {
      @Override
      public boolean check(SignalEvent event) {
        return event.getShiftKey() && !event.getAltKey()
            && !event.getCtrlKey() && !event.getMetaKey();
      }
    },
    /** Only ctrl is pressed */
    CTRL {
      @Override
      public boolean check(SignalEvent event) {
        return !event.getShiftKey() && !event.getAltKey()
            && event.getCtrlKey() && !event.getMetaKey();
      }
    },
    /** Only alt is pressed */
    ALT {
      @Override
      public boolean check(SignalEvent event) {
        return !event.getShiftKey() && event.getAltKey()
            && !event.getCtrlKey() && !event.getMetaKey();
      }
    },
    /** Only the meta key is pressed */
    META {
      @Override
      public boolean check(SignalEvent event) {
        return !event.getShiftKey() && !event.getAltKey()
            && !event.getCtrlKey() && event.getMetaKey();
      }
    },
    /**
     * Only the "command" key is pressed
     * @see SignalEvent#COMMAND_IS_CTRL
     */
    COMMAND {
      @Override
      public boolean check(SignalEvent event) {
        return COMMAND_IS_CTRL ? CTRL.check(event) : META.check(event);
      }
    },
    /** Both ctrl and alt, but no others, are pressed */
    CTRL_ALT {
      @Override
      public boolean check(SignalEvent event) {
        return !event.getShiftKey() && event.getAltKey()
            && event.getCtrlKey() && !event.getMetaKey();
      }
    },
    /** Both "command" and shift, but no others, are pressed */
    COMMAND_SHIFT {
      @Override
      public boolean check(SignalEvent event) {
        // The ctrl/meta key which is NOT the command key
        boolean notCommandKey = COMMAND_IS_CTRL ? event.getMetaKey() : event.getCtrlKey();
        return event.getShiftKey() && !event.getAltKey()
            && event.getCommandKey() && !notCommandKey;
      }
    }
    ;

    /**
     * Whether the "command" key is the control key (as opposed to the meta key).
     */
    // TODO(danilatos): Reconcile this with the value in SignalKeyLogic.
    private static final boolean COMMAND_IS_CTRL = !GWT.isScript() && !UserAgent.isMac();

    /**
     * Check if the given event has the enum value's modifiers pressed.
     * @param event
     * @return true if they are pressed
     */
    public abstract boolean check(SignalEvent event);
  }


  /**
   * @return Event type as a string, e.g. "keypress"
   */
  String getType();

  /**
   * @return The target element of the event
   */<commit_msg>Fix undo on windows and linux<commit_after>/**
 * Copyright 2009 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
package org.waveprotocol.wave.client.common.util;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.user.client.Event;

/**
 * Attempts to bring sanity to the incredibly complex and inconsistent world of
 * browser events, especially with regards to key events.
 *
 * {@link SignalEventImpl}
 *
 * @author <EMAIL> (<NAME>)
 */
public interface SignalEvent {

  /**
   * The "type" of key signal. The type is defined by us, based on a convenient
   * classification of these events.
   */
  public enum KeySignalType {
    /**
     * Typing in the form of inputting text
     *
     * NOTE: "TAB" is treated as INPUT.
     */
    INPUT,
    /** Moving around */
    NAVIGATION,
    /** Deleting text (Backspace + Delete) */
    DELETE,
    /** Other, like ESC or F3, that by themselves will do nothing to the document */
    NOEFFECT,
    /** Sentinal for debugging purposes only */
    SENTINAL
  }

  /**
   * The "movement unit" of this event. For example, on windows and linux,
   * holding down CTRL whilst navigating left and right with the arrow
   * keys moves a word at a time. Even more importantly, move units
   * are used for deleting text.
   */
  public enum MoveUnit {
    /** A character at a time */
    CHARACTER,
    /** A word at a time */
    WORD,
    /** To the start or end of the line */
    LINE,
    /** A "page" at a time */
    PAGE,
    /** To the start or end of the document */
    DOCUMENT
  }

  /**
   * These are the currently supported modifier combinations
   *
   * Supporting more requires tricky, browser-specific code. Go to the experiment harness
   * and have a look at the wonders....
   */
  public enum KeyModifier {
    /** No modifiers are pressed */
    NONE {
      @Override
      public boolean check(SignalEvent event) {
        return !event.getShiftKey() && !event.getAltKey()
            && !event.getCtrlKey() && !event.getMetaKey();
      }
    },
    /** Only shift is pressed */
    SHIFT {
      @Override
      public boolean check(SignalEvent event) {
        return event.getShiftKey() && !event.getAltKey()
            && !event.getCtrlKey() && !event.getMetaKey();
      }
    },
    /** Only ctrl is pressed */
    CTRL {
      @Override
      public boolean check(SignalEvent event) {
        return !event.getShiftKey() && !event.getAltKey()
            && event.getCtrlKey() && !event.getMetaKey();
      }
    },
    /** Only alt is pressed */
    ALT {
      @Override
      public boolean check(SignalEvent event) {
        return !event.getShiftKey() && event.getAltKey()
            && !event.getCtrlKey() && !event.getMetaKey();
      }
    },
    /** Only the meta key is pressed */
    META {
      @Override
      public boolean check(SignalEvent event) {
        return !event.getShiftKey() && !event.getAltKey()
            && !event.getCtrlKey() && event.getMetaKey();
      }
    },
    /**
     * Only the "command" key is pressed
     * @see SignalEvent#COMMAND_IS_CTRL
     */
    COMMAND {
      @Override
      public boolean check(SignalEvent event) {
        return COMMAND_IS_CTRL ? CTRL.check(event) : META.check(event);
      }
    },
    /** Both ctrl and alt, but no others, are pressed */
    CTRL_ALT {
      @Override
      public boolean check(SignalEvent event) {
        return !event.getShiftKey() && event.getAltKey()
            && event.getCtrlKey() && !event.getMetaKey();
      }
    },
    /** Both "command" and shift, but no others, are pressed */
    COMMAND_SHIFT {
      @Override
      public boolean check(SignalEvent event) {
        // The ctrl/meta key which is NOT the command key
        boolean notCommandKey = COMMAND_IS_CTRL ? event.getMetaKey() : event.getCtrlKey();
        return event.getShiftKey() && !event.getAltKey()
            && event.getCommandKey() && !notCommandKey;
      }
    }
    ;

    /**
     * Whether the "command" key is the control key (as opposed to the meta key).
     */
    // TODO(danilatos): Reconcile this with the value in SignalKeyLogic.
    private static final boolean COMMAND_IS_CTRL = !UserAgent.isMac();

    /**
     * Check if the given event has the enum value's modifiers pressed.
     * @param event
     * @return true if they are pressed
     */
    public abstract boolean check(SignalEvent event);
  }


  /**
   * @return Event type as a string, e.g. "keypress"
   */
  String getType();

  /**
   * @return The target element of the event
   */
{'fraction_non_alphanumeric': 0.111358574610245, 'fraction_numerical': 0.0017430037765081825, 'mean_word_length': 2.418735518040384, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3870822', 'n_tokens_mistral': 3034, 'n_tokens_neox': 2915, 'n_words': 1028}