Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
merge mozilla-central to fx-team
Browse files Browse the repository at this point in the history
  • Loading branch information
BavarianTomcat committed Aug 8, 2013
2 parents 21cfa8f + 2e97412 commit 4eb4d06
Show file tree
Hide file tree
Showing 455 changed files with 4,153 additions and 4,057 deletions.
1 change: 0 additions & 1 deletion accessible/src/generic/BaseAccessibles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "States.h"

#include "nsGUIEvent.h"
#include "nsILink.h"
#include "nsINameSpaceManager.h"
#include "nsIURI.h"

Expand Down
1 change: 0 additions & 1 deletion accessible/src/generic/ImageAccessible.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include "nsGenericHTMLElement.h"
#include "nsIDocument.h"
#include "nsIImageLoadingContent.h"
#include "nsILink.h"
#include "nsIPresShell.h"
#include "nsIServiceManager.h"
#include "nsIDOMHTMLImageElement.h"
Expand Down
159 changes: 146 additions & 13 deletions b2g/chrome/content/forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ let FormAssistant = {
addMessageListener("Forms:Select:Blur", this);
addMessageListener("Forms:SetSelectionRange", this);
addMessageListener("Forms:ReplaceSurroundingText", this);
addMessageListener("Forms:GetText", this);
addMessageListener("Forms:Input:SendKey", this);
addMessageListener("Forms:GetContext", this);
},

ignoredInputTypes: new Set([
Expand All @@ -203,8 +206,11 @@ let FormAssistant = {
isKeyboardOpened: false,
selectionStart: -1,
selectionEnd: -1,
textBeforeCursor: "",
textAfterCursor: "",
scrollIntoViewTimeout: null,
_focusedElement: null,
_focusCounter: 0, // up one for every time we focus a new element
_documentEncoder: null,
_editor: null,
_editing: false,
Expand All @@ -218,6 +224,7 @@ let FormAssistant = {
},
set focusedElement(val) {
this._focusCounter++;
this._focusedElement = val;
},
Expand Down Expand Up @@ -390,12 +397,34 @@ let FormAssistant = {
receiveMessage: function fa_receiveMessage(msg) {
let target = this.focusedElement;
let json = msg.json;
// To not break mozKeyboard contextId is optional
if ('contextId' in json &&
json.contextId !== this._focusCounter &&
json.requestId) {
// Ignore messages that are meant for a previously focused element
sendAsyncMessage("Forms:SequenceError", {
requestId: json.requestId,
error: "Expected contextId " + this._focusCounter +
" but was " + json.contextId
});
return;
}

if (!target) {
switch (msg.name) {
case "Forms:GetText":
sendAsyncMessage("Forms:GetText:Result:Error", {
requestId: json.requestId,
error: "No focused element"
});
break;
}
return;
}

this._editing = true;
let json = msg.json;
switch (msg.name) {
case "Forms:Input:Value": {
target.value = json.value;
Expand All @@ -406,6 +435,19 @@ let FormAssistant = {
break;
}

case "Forms:Input:SendKey":
["keydown", "keypress", "keyup"].forEach(function(type) {
domWindowUtils.sendKeyEvent(type, json.keyCode, json.charCode,
json.modifiers);
});

if (json.requestId) {
sendAsyncMessage("Forms:SendKey:Result:OK", {
requestId: json.requestId
});
}
break;

case "Forms:Select:Choice":
let options = target.options;
let valueChanged = false;
Expand Down Expand Up @@ -442,15 +484,58 @@ let FormAssistant = {
let end = json.selectionEnd;
setSelectionRange(target, start, end);
this.updateSelection();

if (json.requestId) {
sendAsyncMessage("Forms:SetSelectionRange:Result:OK", {
requestId: json.requestId,
selectioninfo: this.getSelectionInfo()
});
}
break;
}

case "Forms:ReplaceSurroundingText": {
let text = json.text;
let beforeLength = json.beforeLength;
let afterLength = json.afterLength;
replaceSurroundingText(target, text, this.selectionStart, beforeLength,
let selectionRange = getSelectionRange(target);

replaceSurroundingText(target, text, selectionRange[0], beforeLength,
afterLength);

if (json.requestId) {
sendAsyncMessage("Forms:ReplaceSurroundingText:Result:OK", {
requestId: json.requestId,
selectioninfo: this.getSelectionInfo()
});
}
break;
}

case "Forms:GetText": {
let isPlainTextField = target instanceof HTMLInputElement ||
target instanceof HTMLTextAreaElement;
let value = isPlainTextField ?
target.value :
getContentEditableText(target);

if (json.offset && json.length) {
value = value.substr(json.offset, json.length);
}
else if (json.offset) {
value = value.substr(json.offset);
}

sendAsyncMessage("Forms:GetText:Result:OK", {
requestId: json.requestId,
text: value
});
break;
}

case "Forms:GetContext": {
let obj = getJSON(target, this._focusCounter);
sendAsyncMessage("Forms:GetContext:Result:OK", obj);
break;
}
}
Expand Down Expand Up @@ -529,20 +614,47 @@ let FormAssistant = {
return false;
}

sendAsyncMessage("Forms:Input", getJSON(element));
sendAsyncMessage("Forms:Input", getJSON(element, this._focusCounter));
return true;
},

getSelectionInfo: function fa_getSelectionInfo() {
let element = this.focusedElement;
let range = getSelectionRange(element);

let isPlainTextField = element instanceof HTMLInputElement ||
element instanceof HTMLTextAreaElement;

let text = isPlainTextField ?
element.value :
getContentEditableText(element);

let textAround = getTextAroundCursor(text, range);

let changed = this.selectionStart !== range[0] ||
this.selectionEnd !== range[1] ||
this.textBeforeCursor !== textAround.before ||
this.textAfterCursor !== textAround.after;

this.selectionStart = range[0];
this.selectionEnd = range[1];
this.textBeforeCursor = textAround.before;
this.textAfterCursor = textAround.after;

return {
selectionStart: range[0],
selectionEnd: range[1],
textBeforeCursor: textAround.before,
textAfterCursor: textAround.after,
changed: changed
};
},

// Notify when the selection range changes
updateSelection: function fa_updateSelection() {
let range = getSelectionRange(this.focusedElement);
if (range[0] != this.selectionStart || range[1] != this.selectionEnd) {
this.selectionStart = range[0];
this.selectionEnd = range[1];
sendAsyncMessage("Forms:SelectionChange", {
selectionStart: range[0],
selectionEnd: range[1]
});
let selectionInfo = this.getSelectionInfo();
if (selectionInfo.changed) {
sendAsyncMessage("Forms:SelectionChange", this.getSelectionInfo());
}
}
};
Expand All @@ -568,7 +680,7 @@ function isContentEditable(element) {
return element.ownerDocument && element.ownerDocument.designMode == "on";
}

function getJSON(element) {
function getJSON(element, focusCounter) {
let type = element.type || "";
let value = element.value || "";
let max = element.max || "";
Expand Down Expand Up @@ -609,16 +721,37 @@ function getJSON(element) {
}

let range = getSelectionRange(element);
let textAround = getTextAroundCursor(value, range);

return {
"contextId": focusCounter,

"type": type.toLowerCase(),
"choices": getListForElement(element),
"value": value,
"inputmode": inputmode,
"selectionStart": range[0],
"selectionEnd": range[1],
"max": max,
"min": min
"min": min,
"lang": element.lang || "",
"textBeforeCursor": textAround.before,
"textAfterCursor": textAround.after
};
}

function getTextAroundCursor(value, range) {
let textBeforeCursor = range[0] < 100 ?
value.substr(0, range[0]) :
value.substr(range[0] - 100, 100);

let textAfterCursor = range[1] + 100 > value.length ?
value.substr(range[0], value.length) :
value.substr(range[0], range[1] - range[0] + 100);

return {
before: textBeforeCursor,
after: textAfterCursor
};
}

Expand Down
4 changes: 2 additions & 2 deletions b2g/components/B2GComponents.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ component {397a7fdf-2254-47be-b74e-76625a1a66d5} MozKeyboard.js
contract @mozilla.org/b2g-keyboard;1 {397a7fdf-2254-47be-b74e-76625a1a66d5}
category JavaScript-navigator-property mozKeyboard @mozilla.org/b2g-keyboard;1

component {5c7f4ce1-a946-4adc-89e6-c908226341a0} MozKeyboard.js
contract @mozilla.org/b2g-inputmethod;1 {5c7f4ce1-a946-4adc-89e6-c908226341a0}
component {4607330d-e7d2-40a4-9eb8-43967eae0142} MozKeyboard.js
contract @mozilla.org/b2g-inputmethod;1 {4607330d-e7d2-40a4-9eb8-43967eae0142}
category JavaScript-navigator-property mozInputMethod @mozilla.org/b2g-inputmethod;1

# DirectoryProvider.js
Expand Down
55 changes: 43 additions & 12 deletions b2g/components/Keyboard.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ let Keyboard = {
_messageNames: [
'SetValue', 'RemoveFocus', 'SetSelectedOption', 'SetSelectedOptions',
'SetSelectionRange', 'ReplaceSurroundingText', 'ShowInputMethodPicker',
'SwitchToNextInputMethod', 'HideInputMethod'
'SwitchToNextInputMethod', 'HideInputMethod',
'GetText', 'SendKey', 'GetContext'
],

get messageManager() {
Expand Down Expand Up @@ -58,6 +59,13 @@ let Keyboard = {
} else {
mm.addMessageListener('Forms:Input', this);
mm.addMessageListener('Forms:SelectionChange', this);
mm.addMessageListener('Forms:GetText:Result:OK', this);
mm.addMessageListener('Forms:GetText:Result:Error', this);
mm.addMessageListener('Forms:SetSelectionRange:Result:OK', this);
mm.addMessageListener('Forms:ReplaceSurroundingText:Result:OK', this);
mm.addMessageListener('Forms:SendKey:Result:OK', this);
mm.addMessageListener('Forms:SequenceError', this);
mm.addMessageListener('Forms:GetContext:Result:OK', this);

// When not running apps OOP, we need to load forms.js here since this
// won't happen from dom/ipc/preload.js
Expand Down Expand Up @@ -98,11 +106,20 @@ let Keyboard = {

switch (msg.name) {
case 'Forms:Input':
this.handleFormsInput(msg);
this.forwardEvent('Keyboard:FocusChange', msg);
break;
case 'Forms:SelectionChange':
this.handleFormsSelectionChange(msg);
case 'Forms:GetText:Result:OK':
case 'Forms:GetText:Result:Error':
case 'Forms:SetSelectionRange:Result:OK':
case 'Forms:ReplaceSurroundingText:Result:OK':
case 'Forms:SendKey:Result:OK':
case 'Forms:SequenceError':
case 'Forms:GetContext:Result:OK':
let name = msg.name.replace(/^Forms/, 'Keyboard');
this.forwardEvent(name, msg);
break;

case 'Keyboard:SetValue':
this.setValue(msg);
break;
Expand All @@ -127,21 +144,23 @@ let Keyboard = {
case 'Keyboard:ShowInputMethodPicker':
this.showInputMethodPicker();
break;
case 'Keyboard:GetText':
this.getText(msg);
break;
case 'Keyboard:SendKey':
this.sendKey(msg);
break;
case 'Keyboard:GetContext':
this.getContext(msg);
break;
}
},

handleFormsInput: function keyboardHandleFormsInput(msg) {
forwardEvent: function keyboardForwardEvent(newEventName, msg) {
this.messageManager = msg.target.QueryInterface(Ci.nsIFrameLoaderOwner)
.frameLoader.messageManager;

ppmm.broadcastAsyncMessage('Keyboard:FocusChange', msg.data);
},

handleFormsSelectionChange: function keyboardHandleFormsSelectionChange(msg) {
this.messageManager = msg.target.QueryInterface(Ci.nsIFrameLoaderOwner)
.frameLoader.messageManager;

ppmm.broadcastAsyncMessage('Keyboard:SelectionChange', msg.data);
ppmm.broadcastAsyncMessage(newEventName, msg.data);
},

setSelectedOption: function keyboardSetSelectedOption(msg) {
Expand Down Expand Up @@ -181,6 +200,18 @@ let Keyboard = {
browser.shell.sendChromeEvent({
type: "input-method-switch-to-next"
});
},

getText: function keyboardGetText(msg) {
this.messageManager.sendAsyncMessage('Forms:GetText', msg.data);
},

sendKey: function keyboardSendKey(msg) {
this.messageManager.sendAsyncMessage('Forms:Input:SendKey', msg.data);
},

getContext: function keyboardGetContext(msg) {
this.messageManager.sendAsyncMessage('Forms:GetContext', msg.data);
}
};

Expand Down
Loading

0 comments on commit 4eb4d06

Please sign in to comment.