react / react-0.13.3 / examples / basic-commonjs / node_modules / reactify / node_modules / react-tools / src / browser / syntheticEvents / SyntheticKeyboardEvent.js
81155 views/**1* Copyright 2013-2014, Facebook, Inc.2* All rights reserved.3*4* This source code is licensed under the BSD-style license found in the5* LICENSE file in the root directory of this source tree. An additional grant6* of patent rights can be found in the PATENTS file in the same directory.7*8* @providesModule SyntheticKeyboardEvent9* @typechecks static-only10*/1112"use strict";1314var SyntheticUIEvent = require('SyntheticUIEvent');1516var getEventCharCode = require('getEventCharCode');17var getEventKey = require('getEventKey');18var getEventModifierState = require('getEventModifierState');1920/**21* @interface KeyboardEvent22* @see http://www.w3.org/TR/DOM-Level-3-Events/23*/24var KeyboardEventInterface = {25key: getEventKey,26location: null,27ctrlKey: null,28shiftKey: null,29altKey: null,30metaKey: null,31repeat: null,32locale: null,33getModifierState: getEventModifierState,34// Legacy Interface35charCode: function(event) {36// `charCode` is the result of a KeyPress event and represents the value of37// the actual printable character.3839// KeyPress is deprecated, but its replacement is not yet final and not40// implemented in any major browser. Only KeyPress has charCode.41if (event.type === 'keypress') {42return getEventCharCode(event);43}44return 0;45},46keyCode: function(event) {47// `keyCode` is the result of a KeyDown/Up event and represents the value of48// physical keyboard key.4950// The actual meaning of the value depends on the users' keyboard layout51// which cannot be detected. Assuming that it is a US keyboard layout52// provides a surprisingly accurate mapping for US and European users.53// Due to this, it is left to the user to implement at this time.54if (event.type === 'keydown' || event.type === 'keyup') {55return event.keyCode;56}57return 0;58},59which: function(event) {60// `which` is an alias for either `keyCode` or `charCode` depending on the61// type of the event.62if (event.type === 'keypress') {63return getEventCharCode(event);64}65if (event.type === 'keydown' || event.type === 'keyup') {66return event.keyCode;67}68return 0;69}70};7172/**73* @param {object} dispatchConfig Configuration used to dispatch this event.74* @param {string} dispatchMarker Marker identifying the event target.75* @param {object} nativeEvent Native browser event.76* @extends {SyntheticUIEvent}77*/78function SyntheticKeyboardEvent(dispatchConfig, dispatchMarker, nativeEvent) {79SyntheticUIEvent.call(this, dispatchConfig, dispatchMarker, nativeEvent);80}8182SyntheticUIEvent.augmentClass(SyntheticKeyboardEvent, KeyboardEventInterface);8384module.exports = SyntheticKeyboardEvent;858687