summaryrefslogtreecommitdiffstats
path: root/chromium/chrome/browser/resources/settings/device_page/keyboard.js
blob: a636592e369362729a57a881aaa6e834e7225280 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

/**
 * @fileoverview
 * 'settings-keyboard' is the settings subpage with keyboard settings.
 */
cr.exportPath('settings');

/**
 * Modifier key IDs corresponding to the ModifierKey enumerators in
 * /ui/base/ime/chromeos/ime_keyboard.h.
 * @enum {number}
 */
settings.ModifierKey = {
  SEARCH_KEY: 0,
  CONTROL_KEY: 1,
  ALT_KEY: 2,
  VOID_KEY: 3,  // Represents a disabled key.
  CAPS_LOCK_KEY: 4,
  ESCAPE_KEY: 5,
  BACKSPACE_KEY: 6,
  ASSISTANT_KEY: 7,
};

Polymer({
  is: 'settings-keyboard',

  properties: {
    /** Preferences state. */
    prefs: {
      type: Object,
      notify: true,
    },

    /** @private Whether to show Caps Lock options. */
    showCapsLock_: Boolean,

    /** @private Whether this device has an internal keyboard. */
    hasInternalKeyboard_: Boolean,

    /** @private Whether this device has an Assistant key on keyboard. */
    hasAssistantKey_: Boolean,

    /**
     * Whether to show a remapping option for external keyboard's Meta key
     * (Search/Windows keys). This is true only when there's an external
     * keyboard connected that is a non-Apple keyboard.
     * @private
     */
    showExternalMetaKey_: Boolean,

    /**
     * Whether to show a remapping option for the Command key. This is true when
     * one of the connected keyboards is an Apple keyboard.
     * @private
     */
    showAppleCommandKey_: Boolean,

    /** @private {!DropdownMenuOptionList} Menu items for key mapping. */
    keyMapTargets_: Object,

    /**
     * Auto-repeat delays (in ms) for the corresponding slider values, from
     * long to short. The values were chosen to provide a large range while
     * giving several options near the defaults.
     * @private {!Array<number>}
     */
    autoRepeatDelays_: {
      type: Array,
      value: [2000, 1500, 1000, 500, 300, 200, 150],
      readOnly: true,
    },

    /**
     * Auto-repeat intervals (in ms) for the corresponding slider values, from
     * long to short. The slider itself is labeled "rate", the inverse of
     * interval, and goes from slow (long interval) to fast (short interval).
     * @private {!Array<number>}
     */
    autoRepeatIntervals_: {
      type: Array,
      value: [2000, 1000, 500, 300, 200, 100, 50, 30, 20],
      readOnly: true,
    },
  },

  /** @override */
  ready: function() {
    cr.addWebUIListener('show-keys-changed', this.onShowKeysChange_.bind(this));
    settings.DevicePageBrowserProxyImpl.getInstance().initializeKeyboard();
    this.setUpKeyMapTargets_();
  },

  /**
   * Initializes the dropdown menu options for remapping keys.
   * @private
   */
  setUpKeyMapTargets_: function() {
    // Ordering is according to UX, but values match settings.ModifierKey.
    this.keyMapTargets_ = [
      {
        value: settings.ModifierKey.SEARCH_KEY,
        name: loadTimeData.getString('keyboardKeySearch'),
      },
      {
        value: settings.ModifierKey.CONTROL_KEY,
        name: loadTimeData.getString('keyboardKeyCtrl')
      },
      {
        value: settings.ModifierKey.ALT_KEY,
        name: loadTimeData.getString('keyboardKeyAlt')
      },
      {
        value: settings.ModifierKey.CAPS_LOCK_KEY,
        name: loadTimeData.getString('keyboardKeyCapsLock')
      },
      {
        value: settings.ModifierKey.ESCAPE_KEY,
        name: loadTimeData.getString('keyboardKeyEscape')
      },
      {
        value: settings.ModifierKey.BACKSPACE_KEY,
        name: loadTimeData.getString('keyboardKeyBackspace')
      },
      {
        value: settings.ModifierKey.ASSISTANT_KEY,
        name: loadTimeData.getString('keyboardKeyAssistant')
      },
      {
        value: settings.ModifierKey.VOID_KEY,
        name: loadTimeData.getString('keyboardKeyDisabled')
      }
    ];
  },

  /**
   * Handler for updating which keys to show.
   * @param {Object} keyboardParams
   * @private
   */
  onShowKeysChange_: function(keyboardParams) {
    this.hasInternalKeyboard_ = keyboardParams['hasInternalKeyboard'];
    this.hasAssistantKey_ = keyboardParams['hasAssistantKey'];
    this.showCapsLock_ = keyboardParams['showCapsLock'];
    this.showExternalMetaKey_ = keyboardParams['showExternalMetaKey'];
    this.showAppleCommandKey_ = keyboardParams['showAppleCommandKey'];
  },

  onShowKeyboardShortcutViewerTap_: function() {
    settings.DevicePageBrowserProxyImpl.getInstance()
        .showKeyboardShortcutViewer();
  },

  onShowLanguageInputTap_: function() {
    settings.navigateTo(
        settings.routes.LANGUAGES_DETAILS,
        /* dynamicParams */ null, /* removeSearch */ true);
  },

  getExternalMetaKeyLabel_: function(hasInternalKeyboard) {
    return loadTimeData.getString(
        hasInternalKeyboard ? 'keyboardKeyExternalMeta' : 'keyboardKeyMeta');
  },

  getExternalCommandKeyLabel_: function(hasInternalKeyboard) {
    return loadTimeData.getString(
        hasInternalKeyboard ? 'keyboardKeyExternalCommand' :
                              'keyboardKeyCommand');
  },
});