Skip to content

Commit

Permalink
Fixed input handling in Firefox 2
Browse files Browse the repository at this point in the history
Firefox 2 is loading avim.xul, so the <script>s in moz18Overlay.xul were causing two instances of AVIM to conflict with one another. moz18Overlay is about duplicating elements that go into sets (since the sets in Firefox 2 have IDs), not about duplicating all the functionality of avim.xul.

Put in some defensive checks due to missing menus or APIs in Firefox 2.

Fixes #159.
  • Loading branch information
1ec5 committed Dec 31, 2015
1 parent b7d9494 commit 95d5739
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 19 deletions.
15 changes: 8 additions & 7 deletions content/avim.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,8 @@ function AVIM() {
let enabledBcId = $(broadcasterIds.enabled);
if (enabledBcId) {
setCheckedState(enabledBcId, AVIMConfig.onOff);
if (isMac) {
let inlineKey = $("avim-enabled-key-inline");
inlineKey.setAttribute("keytext", "\u2303\u2303");
}
let inlineKey = isMac && $("avim-enabled-key-inline");
if (inlineKey) inlineKey.setAttribute("keytext", "\u2303\u2303");
}

// Disable methods and options if AVIM is disabled
Expand Down Expand Up @@ -752,7 +750,8 @@ addEventListener("load", function load(/* evt */) {
avim.onKeyPress(evt);
}, true);

if ("gMultiProcessBrowser" in win && win.gMultiProcessBrowser) {
let isE10s = "gMultiProcessBrowser" in win && win.gMultiProcessBrowser;
if (isE10s) {
messageManager.loadFrameScript("chrome://avim/content/frame.js", true);
messageManager.addMessageListener("AVIM:readyforprefs",
avim.onFrameReadyForPrefs);
Expand All @@ -761,8 +760,10 @@ addEventListener("load", function load(/* evt */) {

addEventListener("unload", function unload(/* evt */) {
removeEventListener("unload", unload, false);
messageManager.removeMessageListener("AVIM:keypress",
avim.onFrameKeyPress);
if (isE10s) {
messageManager.removeMessageListener("AVIM:keypress",
avim.onFrameKeyPress);
}
avim.unregisterPrefs();
}, false);
}, false);
Expand Down
25 changes: 16 additions & 9 deletions content/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,8 @@ function splice(outer, evt) {
return result;
}

const focusMgr = Cc["@mozilla.org/focus-manager;1"].getService(Ci.nsIFocusManager);
const focusMgr = Cc["@mozilla.org/focus-manager;1"] &&
Cc["@mozilla.org/focus-manager;1"].getService(Ci.nsIFocusManager);

/**
* Returns the native (HTML, XUL) element that an editor is currently editing.
Expand Down Expand Up @@ -420,6 +421,7 @@ function insertSyllableOverlay(node, word) {
if (!doc) return;
let winUtils = win.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
if (!("sendQueryContentEvent" in winUtils)) return;

// Get the word's bounding rect relative to the outermost window's viewport
// (which may be confined to the browser in e10s).
Expand All @@ -432,12 +434,10 @@ function insertSyllableOverlay(node, word) {
sel.offset - word.length,
word.length, 0, 0);
// sendQueryContentEvent() returns metrics in LayoutDevice pixels.
let scale = 1 / winUtils.screenPixelsPerCSSPixel;

// To ensure visibility regardless of the background, use the effective text
// color as the outline color.
let color = winUtils.getVisitedDependentComputedStyle(node.parentElement,
null, "color");
let scale = 1;
if ("screenPixelsPerCSSPixel" in winUtils) {
scale /= winUtils.screenPixelsPerCSSPixel;
}

let overlay = doc.createElementNS(HTML_NS, "div");
// Subject the overlay to AVIM's user agent stylesheet.
Expand All @@ -446,7 +446,14 @@ function insertSyllableOverlay(node, word) {
overlay.style.top = textRect.top * scale + "px";
overlay.style.width = textRect.width * scale + "px";
overlay.style.height = textRect.height * scale + "px";
overlay.style.outlineColor = color;

if ("getVisitedDependentComputedStyle" in winUtils) {
// To ensure visibility regardless of the background, use the effective
// text color as the outline color.
let color = winUtils.getVisitedDependentComputedStyle(node.parentElement,
null, "color");
overlay.style.outlineColor = color;
}

// Document.insertAnonymousContent() is unavailable in XUL, but that's OK
// because extensions and themes are unlikely to muck with the overlay.
Expand Down Expand Up @@ -952,8 +959,8 @@ addEventListener("keypress", function (evt) {
doc = origTarget.ownerDocument;
}

let handler = getSpecializedHandler(origTarget, doc);
try {
let handler = getSpecializedHandler(origTarget, doc);
handleSpecialized(handler, evt);
} catch (exc) {
// $if{Debug}
Expand Down
15 changes: 12 additions & 3 deletions content/moz18Overlay.xul
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
<!DOCTYPE overlay SYSTEM "chrome://avim/locale/avim.dtd">

<overlay id="avim-overlay" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/x-javascript;version=1.7" src="chrome://avim/content/avim.js" />
<script type="application/x-javascript;version=1.7" src="chrome://avim/content/frame.js" />

<commandset id="baseMenuCommandSet">
<command id="avim-enabled-cmd" oncommand="avim.toggle();" />
<command id="avim-prev-method-cmd" oncommand="avim.cycleMethod(-1);" />
<command id="avim-next-method-cmd" oncommand="avim.cycleMethod(1);" />
<command id="avim-spell-cmd" oncommand="avim.toggleSpell();" />
<command id="avim-oldaccents-cmd" oncommand="avim.toggleDauCu();" />
<command id="avim-insert-syllable-cmd" oncommand="avim.sendTextEvent('brokesyllable');" />
<command id="avim-delete-diacritic-cmd" oncommand="avim.sendTextEvent('deleteddiacritic');" />
</commandset>

<keyset id="baseMenuKeyset">
Expand All @@ -24,6 +23,10 @@
<!-- Options -->
<key id="avim-spell-key" modifiers="&avim-spell.modifiers;" key="&avim-spell.key;" command="avim-spell-cmd" />
<key id="avim-oldaccents-key" modifiers="&avim-oldaccents.modifiers;" key="&avim-oldaccents.key;" command="avim-oldaccents-cmd" />

<!-- Text commands -->
<key id="avim-insert-syllable-key" modifiers="shift" key=" " keytext="&avim-insert-syllable.keytext;" />
<key id="avim-delete-diacritic-key" modifiers="shift" keycode="VK_BACK" />
</keyset>

<broadcasterset id="mainBroadcasterSet">
Expand All @@ -40,6 +43,12 @@
<!-- Options -->
<broadcaster id="avim-spell-bc" name="avim-spell" type="checkbox" label="&avim-spell.label;" accesskey="&avim-spell.accesskey;" statustext="&avim-spell.description;" autocheck="false" command="avim-spell-cmd" />
<broadcaster id="avim-oldaccents-bc" name="avim-oldaccents" type="checkbox" label="&avim-oldaccents.label;" accesskey="&avim-oldaccents.accesskey;" statustext="&avim-oldaccents.description;" autocheck="false" command="avim-oldaccents-cmd" />

<!-- Text commands -->
<broadcaster id="avim-insert-syllable-bc" label="&avim-insert-syllable.label;" accesskey="&avim-insert-syllable.accesskey;" command="avim-insert-syllable-cmd" />
<broadcaster id="avim-delete-diacritic-bc" label="&avim-delete-diacritic.label;" accesskey="&avim-delete-diacritic.accesskey;" command="avim-delete-diacritic-cmd" />

<broadcaster id="avim-status-bc" label="&AVIM.label;" />
</broadcasterset>

<!-- Toolbar buttons -->
Expand Down

0 comments on commit 95d5739

Please sign in to comment.