OLD | NEW |
| (Empty) |
1 // Copyright 2014 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 var connection; | |
5 var mojo_api; | |
6 var input_focused_event; | |
7 | |
8 if (!chrome.virtualKeyboardPrivate) { | |
9 define('main', [ | |
10 'mojo/public/js/connection', | |
11 'ui/keyboard/webui/keyboard.mojom', | |
12 'content/public/renderer/service_provider', | |
13 ], function(connector, keyboard, serviceProvider) { | |
14 'use strict'; | |
15 function TextInputTypeObserverImpl(kbd) { | |
16 console.log('Creating TextInputTypeObserverImpl'); | |
17 this.keyboard_ = kbd; | |
18 mojo_api = this; | |
19 mojo_api.setTextInputTypeObserver( | |
20 connection.bindImpl(this, keyboard.TextInputTypeObserver)); | |
21 } | |
22 | |
23 TextInputTypeObserverImpl.prototype = Object.create( | |
24 keyboard.KeyboardAPI.stubClass.prototype); | |
25 | |
26 TextInputTypeObserverImpl.prototype.onTextInputTypeChanged = | |
27 function(input_type) { | |
28 console.log('Text input changed: ' + input_type); | |
29 input_focused_event.forEach(function(listener) { | |
30 listener({type: input_type}); | |
31 }); | |
32 }; | |
33 | |
34 return function() { | |
35 const KBDApi = keyboard.KeyboardUIHandlerMojo; | |
36 new TextInputObserverImpl(connection.bindHandleToProxy( | |
37 serviceProvider.connectToService(KBDApi.name), | |
38 KBDApi)); | |
39 }; | |
40 }); | |
41 | |
42 chrome.virtualKeyboardPrivate = {}; | |
43 chrome.virtualKeyboardPrivate.sendKeyEvent = function(event) { | |
44 if (!mojo_api) | |
45 return; | |
46 console.log('sending key event: ' + event.type); | |
47 mojo_api.keyboard_.sendKeyEvent(event.type, | |
48 event.charValue, | |
49 event.keyCode, | |
50 event.keyName, | |
51 event.modifiers); | |
52 }; | |
53 chrome.virtualKeyboardPrivate.hideKeyboard = function() { | |
54 if (!mojo_api) | |
55 return; | |
56 mojo_api.keyboard_.hideKeyboard(); | |
57 }; | |
58 chrome.virtualKeyboardPrivate.moveCursor = function() {}; | |
59 chrome.virtualKeyboardPrivate.lockKeyboard = function() {}; | |
60 chrome.virtualKeyboardPrivate.keyboardLoaded = function() {}; | |
61 chrome.virtualKeyboardPrivate.getKeyboardConfig = function(callback) { | |
62 callback({ | |
63 layout: 'qwerty', | |
64 a11ymode: false, | |
65 experimental: false, | |
66 features: [] | |
67 }); | |
68 }; | |
69 | |
70 function BrowserEvent() { | |
71 this.listeners_ = []; | |
72 }; | |
73 | |
74 BrowserEvent.prototype.addListener = function(callback) { | |
75 this.listeners_.push(callback); | |
76 }; | |
77 | |
78 BrowserEvent.prototype.forEach = function(callback) { | |
79 for (var i = 0; i < this.listeners_.length; ++i) | |
80 callback(this.listeners_[i]); | |
81 }; | |
82 | |
83 input_focused_event = new BrowserEvent; | |
84 chrome.virtualKeyboardPrivate.onTextInputBoxFocused = input_focused_event; | |
85 } | |
OLD | NEW |