1// Copyright 2018 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Braille display access private API.
6namespace brailleDisplayPrivate {
7  // Braille display keyboard command.
8  enum KeyCommand {
9    line_up,
10    line_down,
11    pan_left,
12    pan_right,
13    top,
14    bottom,
15    routing,
16    secondary_routing,
17    dots,
18    chord,
19    standard_key
20  };
21
22  // A keyboard event.  This is not a standard keyboard event because
23  // braille display keyboards look significantly different from standard
24  // keyboards.
25  dictionary KeyEvent {
26    KeyCommand command;
27    // 0-based display position for commands that involve a routing key.
28    long? displayPosition;
29    // Braille dot keys that were pressed, stored in the low-order bits.
30    // Dot 1 is stored in bit 0, dot2 in bit 1, etc.
31    long? brailleDots;
32    // DOM keyboard event code.  This is present when command is standard_key
33    // and the braille display event represents a non-alphanumeric key such
34    // as an arrow key or function key.
35    // The value is as defined by the |code| property in
36    // http://www.w3.org/TR/uievents/#keyboard-event-interface
37    DOMString? standardKeyCode;
38    // DOM keyboard event character value.  This is present if the
39    // braille key event corresponds to a character.
40    DOMString? standardKeyChar;
41    // Whether the space key was pressed.
42    boolean? spaceKey;
43    // Whether the alt key was pressed.
44    boolean? altKey;
45    // Whether the shift key was pressed.
46    boolean? shiftKey;
47    // Whether the ctrl key was pressed.
48    boolean? ctrlKey;
49  };
50
51  // The current braille display state.
52  dictionary DisplayState {
53    // Whether a braille display is currently available.
54    boolean available;
55    // Number of rows of braille cells on the currently connected display.
56    long? textRowCount;
57    // Number of columns of braille cells on the currently connected display.
58    long? textColumnCount;
59  };
60
61  callback DisplayStateCallback = void(DisplayState result);
62
63  interface Functions {
64    // Gets the current display state.
65    static void getDisplayState(DisplayStateCallback callback);
66    // Write the given dot patterns to the display.  The buffer contains one
67    // byte for each braille cell on the display, starting from the leftmost
68    // cell. Each byte contains a bit pattern indicating which dots should be
69    // raised in the corresponding cell with the low-order bit representing
70    // dot 1 and so on until bit 7 which corresponds to dot 8.  If the number
71    // of bytes in the buffer is not equal to the display size, the buffer
72    // will either be clipped or padded with blank cells on the right. The
73    // buffer is a 2D array compressed into 1D. The |columns| and |rows|
74    // parameters give the original 2D dimensions of the buffer. To access
75    // an element cells[r][c], simply access cells[r * columns + c].
76    static void writeDots(ArrayBuffer cells, long columns, long rows);
77  };
78
79  interface Events {
80    // Fired when a braille display is connected or disconnected.
81    static void onDisplayStateChanged(DisplayState state);
82    // Fired when an input event is received from the display.
83    static void onKeyEvent(KeyEvent event);
84  };
85};
86