Home | History | Annotate | Download | only in base
      1 <!DOCTYPE html>
      2 <!--
      3 Copyright (c) 2014 The Chromium Authors. All rights reserved.
      4 Use of this source code is governed by a BSD-style license that can be
      5 found in the LICENSE file.
      6 -->
      7 <link rel="import" href="/base/guid.html">
      8 <script>
      9 'use strict';
     10 
     11 tr.exportTo('tr.ui.b', function() {
     12   function HotKey(dict) {
     13     if (dict.eventType === undefined)
     14       throw new Error('eventType must be given');
     15     if (dict.keyCode === undefined && dict.keyCodes === undefined)
     16       throw new Error('keyCode or keyCodes must be given');
     17     if (dict.keyCode !== undefined && dict.keyCodes !== undefined)
     18       throw new Error('Only keyCode or keyCodes can be given');
     19     if (dict.callback === undefined)
     20       throw new Error('callback must be given');
     21 
     22     this.eventType_ = dict.eventType;
     23     this.keyCodes_ = [];
     24 
     25     if (dict.keyCode)
     26       this.pushKeyCode_(dict.keyCode);
     27     else if (dict.keyCodes) {
     28       dict.keyCodes.forEach(this.pushKeyCode_, this);
     29     }
     30 
     31     this.useCapture_ = !!dict.useCapture;
     32     this.callback_ = dict.callback;
     33     this.thisArg_ = dict.thisArg !== undefined ? dict.thisArg : undefined;
     34 
     35     this.helpText_ = dict.helpText !== undefined ? dict.helpText : undefined;
     36   }
     37 
     38   HotKey.prototype = {
     39     get eventType() {
     40       return this.eventType_;
     41     },
     42 
     43     get keyCodes() {
     44       return this.keyCodes_;
     45     },
     46 
     47     get helpText() {
     48       return this.helpText_;
     49     },
     50 
     51     call: function(e) {
     52       this.callback_.call(this.thisArg_, e);
     53     },
     54 
     55     pushKeyCode_: function(keyCode) {
     56       this.keyCodes_.push(keyCode);
     57     }
     58   };
     59 
     60   return {
     61     HotKey: HotKey
     62   };
     63 });
     64 </script>
     65