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/bindings/connection', |
| 11 'ui/keyboard/webui/keyboard.mojom', |
| 12 'content/public/renderer/service_provider', |
| 13 ], function(connector, keyboard, serviceProvider) { |
| 14 'use strict'; |
| 15 function KeyboardImpl(kbd) { |
| 16 console.log('Creating KeyboardImpl'); |
| 17 this.keyboard_ = kbd; |
| 18 mojo_api = this; |
| 19 } |
| 20 |
| 21 KeyboardImpl.prototype = Object.create(keyboard.KeyboardAPIStub.prototype); |
| 22 |
| 23 KeyboardImpl.prototype.onTextInputTypeChanged = function(input_type) { |
| 24 console.log('Text input changed: ' + input_type); |
| 25 input_focused_event.forEach(function(listener) { |
| 26 listener({type: input_type}); |
| 27 }); |
| 28 }; |
| 29 |
| 30 return function() { |
| 31 connection = new connector.Connection( |
| 32 serviceProvider.connectToService( |
| 33 keyboard.KeyboardUIHandlerMojoProxy.NAME_), |
| 34 KeyboardImpl, |
| 35 keyboard.KeyboardUIHandlerMojoProxy); |
| 36 }; |
| 37 }); |
| 38 |
| 39 chrome.virtualKeyboardPrivate = {}; |
| 40 chrome.virtualKeyboardPrivate.sendKeyEvent = function(event) { |
| 41 if (!mojo_api) |
| 42 return; |
| 43 console.log('sending key event: ' + event.type); |
| 44 mojo_api.keyboard_.sendKeyEvent(event.type, |
| 45 event.charValue, |
| 46 event.keyCode, |
| 47 event.keyName, |
| 48 event.modifiers); |
| 49 }; |
| 50 chrome.virtualKeyboardPrivate.hideKeyboard = function() { |
| 51 if (!mojo_api) |
| 52 return; |
| 53 mojo_api.keyboard_.hideKeyboard(); |
| 54 }; |
| 55 chrome.virtualKeyboardPrivate.moveCursor = function() {}; |
| 56 chrome.virtualKeyboardPrivate.lockKeyboard = function() {}; |
| 57 chrome.virtualKeyboardPrivate.keyboardLoaded = function() {}; |
| 58 chrome.virtualKeyboardPrivate.getKeyboardConfig = function() {}; |
| 59 |
| 60 function BrowserEvent() { |
| 61 this.listeners_ = []; |
| 62 }; |
| 63 |
| 64 BrowserEvent.prototype.addListener = function(callback) { |
| 65 this.listeners_.push(callback); |
| 66 }; |
| 67 |
| 68 BrowserEvent.prototype.forEach = function(callback) { |
| 69 for (var i = 0; i < this.listeners_.length; ++i) |
| 70 callback(this.listeners_[i]); |
| 71 }; |
| 72 |
| 73 input_focused_event = new BrowserEvent; |
| 74 chrome.virtualKeyboardPrivate.onTextInputBoxFocused = input_focused_event; |
| 75 } |
OLD | NEW |