Skip to content

Commit

Permalink
Merge pull request #7360 from keymanapp/change/web/drop-alignInputs
Browse files Browse the repository at this point in the history
chore(web): drops alignInputs, hideInputs 📴
  • Loading branch information
jahorton authored Oct 17, 2022
2 parents 66f9c52 + d9cd488 commit 690a282
Show file tree
Hide file tree
Showing 8 changed files with 5 additions and 221 deletions.
21 changes: 5 additions & 16 deletions web/source/kmwbase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ namespace com.keyman {
_MasterDocument = null; // Document with controller (to allow iframes to distinguish local/master control)
_HotKeys = []; // Array of document-level hotkey objects
warned = false; // Warning flag (to prevent multiple warnings)
baseFont = 'sans-serif'; // Default font for mapped input elements
appliedFont = ''; // Chain of fonts to be applied to mapped input elements
fontCheckTimer = null; // Timer for testing loading of embedded fonts
baseFont = 'sans-serif'; // Default page font (utilized by the OSK)
appliedFont = ''; // Chain of fonts to be applied to OSK elements
srcPath = ''; // Path to folder containing executing keymanweb script
rootPath = ''; // Path to server root
protocol = ''; // Protocol used for the KMW script.
Expand Down Expand Up @@ -113,12 +112,13 @@ namespace com.keyman {
getKeyboardPath(f, p?){return f;}
KC_(n, ln, Pelem){return '';}
handleRotationEvents(){}
// Will serve as an API function for a workaround, in case of future touch-alignment issues.
/**
* Legacy API function for touch-alias issue workarounds
* Touch-aliases have been eliminated, though.
*
* This function is deprecated in 16.0, with plans for removal in 17.0.
*/
['alignInputs'](eleList?: HTMLElement[]){}
hideInputs() {};
namespaceID(Pstub) {};
preserveID(Pk) {};

Expand Down Expand Up @@ -232,17 +232,6 @@ namespace com.keyman {
return metadata;
}

/**
* Expose font testing to allow checking that SpecialOSK or custom font has
* been correctly loaded by browser
*
* @param {string} fName font-family name
* @return {boolean} true if available
**/
['isFontAvailable'](fName: string): boolean {
return this.util.checkFont({'family':fName});
}

/**
* Function addEventListener
* Scope Public
Expand Down
13 changes: 0 additions & 13 deletions web/source/kmwembedded.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,6 @@ namespace com.keyman.osk {
};
}

VisualKeyboard.prototype.waitForFonts = function(this: VisualKeyboard, kfd, ofd) {
// a dummy function; it's only really used for 'native' KMW.
return true;
}

SuggestionManager.prototype.platformHold = function(this: SuggestionManager, suggestionObj: BannerSuggestion, isCustom: boolean) {
// Parallels VisualKeyboard.prototype.touchHold, but for predictive suggestions instead of keystrokes.
let suggestionEle = suggestionObj.div;
Expand Down Expand Up @@ -228,14 +223,6 @@ namespace com.keyman.text {
*/
keymanweb.domManager._SetTargDir = function(Ptarg){};

/**
* Align input fields (should not be needed with KMEI, KMEA)
*
* @param {object} eleList A list of specific elements to align. If nil, selects all elements.
*
**/
keymanweb.alignInputs = function(eleList: HTMLElement[]) {};

/**
* Use rotation events to adjust OSK element positions and scaling if necessary
*/
Expand Down
20 changes: 0 additions & 20 deletions web/source/kmwnative.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,26 +90,6 @@ if(!window['keyman']['initialized']) {
return (rx.test(Lfilename) ? '' : keymanweb.options['keyboards']) + Lfilename;
}

/**
* Align input fields (should not be needed with KMEI, KMEA), making them visible if previously hidden.
*
* @param {object} eleList A list of specific elements to align. If nil, selects all elements.
*
**/
keymanweb.alignInputs = function(eleList: HTMLElement[]) {
// no-op
}

/**
* Programatically hides all input fields with underlying elements. Restore with .alignInputs.
*
* @param {boolean} align align and make visible, else hide
*
**/
keymanweb.hideInputs = function() {
// no-op.
}

/**
* Test if caret position is determined from the active element, or
* from the synthesized overlay element (touch devices)
Expand Down
2 changes: 0 additions & 2 deletions web/source/kmwrotation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ namespace com.keyman {
}

resolve() {
this.keyman.alignInputs();

var osk = this.keyman.osk;
osk.hideLanguageMenu();

Expand Down
113 changes: 0 additions & 113 deletions web/source/kmwutils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1021,119 +1021,6 @@ namespace com.keyman {
return this.keyman.protocol+'//'+path;
}
}

/**
* Return the appropriate test string for a given font
*
* TODO: Tidy up and remove arrays once 'sample' included in font metadata
*
* @param {Object} fd font meta-data object
* @return {string} string to compare width
*
*/
testString(fd): string {
var fontName=fd['family'],
i,s='BESbswy';

if('sample' in fd && typeof(fd['sample']) == 'string') {
return s+fd['sample'];
}

var f=['TamilWeb','TibetanWeb','LatinWeb','CherokeeWeb',
'EgyptianWeb','SinhalaWeb','KhmerWeb','ArabicWeb',
'BurmeseWeb','LaoWeb','OriyaWeb','GeezWeb'],
t=['\u0BBE\u0BF5','\u0F7F\u0FD0','\u02B0\u02A4','\u13D0\u13C9',
'\uA723\uF7D3','\u0DD8\u0DA3','\u17D6\u178E','\u0639\u06B3',
'\u1038\u1024','\u0EC0\u0EDD','\u0B03\u0B06','\u1361\u132C'];

for(i=0; i<f.length; i++) {
if(fontName == f[i]) {
return s+t[i];
}
}

return s;
}

/**
* Test if a font is installed (or available) on the target platform
*
* @param {Object} fd font structure
* @return {boolean} true if font available
*/
checkFont(fd): boolean {
var fontReady=false, fontName=fd['family'];

// Create an absolute positioned div and two paragraph elements with spans for the test string.
// The paragraph elements ensure that the spans are measured from the same point, otherwise
// pixel rounding can result in different widths for the same string and styles.
// Using a separate invisible DIV is more reliable than other positioning.
var d=document.createElement('DIV'), ds=d.style,
p1=document.createElement('P'),
p2=document.createElement('P'),
t1=document.createElement('SPAN'), s1=t1.style,
t2=document.createElement('SPAN'), s2=t2.style;

ds.position='absolute';
ds.top='10px';
ds.left='10px';
ds.visibility='hidden';
document.body.appendChild(d);
d.appendChild(p1);
d.appendChild(p2);
p1.appendChild(t1);
p2.appendChild(t2);

// Firefox fails without the !important prefix on the fallback font,
// apparently applying the same font to both elements.
// But it also fails to distinguish the two if !important is added to the test font!
// *** TODO: See if still true after changes Dec 2013 ***
// Must apply !important tag to font-family, but must apply it to the CSS style, not the JS object member
// c.f. http://stackoverflow.com/questions/462537/overriding-important-style-using-javascript
t1.setAttribute('style','font-family:monospace !important');
s2.fontFamily=fontName+',monospace';
s1.fontSize=s2.fontSize='24px'; // Not too large, to avoid wrapping or overflow

// Include narrow and wide characters from each unique script
t1.innerHTML=t2.innerHTML=this.testString(fd);

// Compare the actual width of each span. Checking monospace, serif,
// and sans-serif helps to avoid falsely reporting the font as ready
// The width must be different for all three tests.
if(t1.offsetWidth != t2.offsetWidth) {
t1.setAttribute('style','font-family:sans-serif !important');
s2.fontFamily=fontName+',sans-serif';
if(t1.offsetWidth != t2.offsetWidth) {
t1.setAttribute('style','font-family:serif !important');
s2.fontFamily=fontName+',serif';
}
}

fontReady=(t1.offsetWidth != t2.offsetWidth);

// Delete test elements
p1.removeChild(t1);
p2.removeChild(t2);
d.removeChild(p1);
d.removeChild(p2);
document.body.removeChild(d);

return fontReady;
}

/**
* Check a font descriptor for font availability, returning true if undefined
*
* @param {Object} fd font descriptor member of keyboard stub
* @return {boolean}
**/
checkFontDescriptor(fd): boolean {
if(typeof(fd) == 'undefined' || typeof(fd['family']) != 'string') {
return true;
}

return this.checkFont(fd);
}
}
}

Expand Down
3 changes: 0 additions & 3 deletions web/source/osk/oskView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,9 +507,6 @@ namespace com.keyman.osk {
bs.height = 'auto';
bs.maxWidth = bs.maxHeight = '';
}

let keyman = com.keyman.singleton;
keyman.alignInputs();
}

public refreshLayoutIfNeeded(pending?: boolean) {
Expand Down
53 changes: 0 additions & 53 deletions web/source/osk/visualKeyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1349,9 +1349,6 @@ namespace com.keyman.osk {
util.addFontFaceStyleSheet(kfd);
util.addFontFaceStyleSheet(ofd);

// Temporarily hide duplicated elements on non-desktop browsers
keymanweb.hideInputs();

// Build the style string and append (or replace) the font style sheet
// Note: Some browsers do not download the font-face font until it is applied,
// so must apply style before testing for font availability
Expand All @@ -1361,11 +1358,6 @@ namespace com.keyman.osk {
customStyle = customStyle + activeKeyboard.oskStyling;

this.styleSheet = util.addStyleSheet(customStyle); //Build 360

// Wait until font is loaded then align duplicated input elements with page elements
if (this.waitForFonts(kfd, ofd)) {
keymanweb.alignInputs();
}
}

/**
Expand Down Expand Up @@ -1718,51 +1710,6 @@ namespace com.keyman.osk {
}
};

/**
* Wait until font is loaded before applying stylesheet - test each 100 ms
* @param {Object} kfd main font descriptor
* @param {Object} ofd secondary font descriptor (OSK only)
* @return {boolean}
*/
waitForFonts(kfd, ofd) {
let keymanweb = com.keyman.singleton;
let util = keymanweb.util;

let fontDefined = !!(kfd && kfd['files']);
kfd = fontDefined ? kfd : undefined;

let oskFontDefined = !!(ofd && ofd['files']);
ofd = oskFontDefined ? ofd : undefined;

// Automatically 'ready' if the descriptor is explicitly `undefined`.
// Thus, also covers the case where both are undefined.
var kReady = util.checkFontDescriptor(kfd), oReady = util.checkFontDescriptor(ofd);
if (kReady && oReady) {
return true;
}

keymanweb.fontCheckTimer = window.setInterval(function () {
if (util.checkFontDescriptor(kfd) && util.checkFontDescriptor(ofd)) {
window.clearInterval(keymanweb.fontCheckTimer);
keymanweb.fontCheckTimer = null;
keymanweb.alignInputs();
}
}, 100);

// Align anyway as best as can if font appears to remain uninstalled after 5 seconds
window.setTimeout(function () {
if (keymanweb.fontCheckTimer) {
window.clearInterval(keymanweb.fontCheckTimer);
keymanweb.fontCheckTimer = null;
keymanweb.alignInputs();
// Don't notify - this is a management issue, not anything the user needs to deal with
// TODO: Consider having an icon in the OSK with a bubble that indicates missing font
//util.alert('Unable to download the font normally used with '+ks['KN']+'.');
}
}, 5000);
return false;
};

shutdown() {
let keyman = com.keyman.singleton;

Expand Down
1 change: 0 additions & 1 deletion web/testing/inline-osk/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
document.getElementById('KeymanWebControl').appendChild(newOSK.element);
keyman.osk = newOSK;
newOSK.activeKeyboard = keyman.core.activeKeyboard;
keyman.alignInputs();
document.getElementById('ta1').focus();
}

Expand Down

0 comments on commit 690a282

Please sign in to comment.