Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(web): OSK spacebar-label updates now managed by layer object 🪠 #11175

Merged
merged 2 commits into from
Apr 10, 2024

Conversation

jahorton
Copy link
Contributor

@jahorton jahorton commented Apr 5, 2024

To prepare to optimize layout-reflow for Web's OSK, it will help us to rework how spacebar-text and its styling are managed. They'll be far easier to "batch" with other layout updates if managed by the layer containing the key, rather than set outside of the standard flow.

Also, we had a lot of redundant calls to the showLanguage() function, which is what updated the spacebar. We only need one.

This PR has been spun off of an older state of #11140. Certain design decisions may make more sense with the whole picture in mind, though I have tried to recontextualize them to make better sense in isolation for this PR.

User Testing

TEST_ANDROID_SPACEBAR: Using Keyman for Android, verify that the spacebar is always appropriately captioned (based on user settings in the menu) for the active keyboard, with the text properly sized.

  • If not already installed, download and test using balochi_phonetic - it has very high font scaling that will help stress-test part of spacebar-display management.
    • If the text overflows the spacebar at any point, overrunning its boundaries, FAIL this test.
  • Test with a few other keyboards as well.
  • Be sure to swap the device orientation back and forth a few times - from portrait to landscape and back again.
  • Be sure to swap layers and verify that the spacebar for each is always labeled appropriately.

@jahorton jahorton requested a review from ermshiperete as a code owner April 5, 2024 04:50
@keymanapp-test-bot keymanapp-test-bot bot added has-user-test user-test-required User tests have not been completed labels Apr 5, 2024
@keymanapp-test-bot
Copy link

keymanapp-test-bot bot commented Apr 5, 2024

User Test Results

Test specification and instructions

@keymanapp-test-bot keymanapp-test-bot bot added this to the B17S5 milestone Apr 5, 2024
@jahorton jahorton changed the title refactor(web): OSK spacebar-label updates now managed by layer object refactor(web): OSK spacebar-label updates now managed by layer object 🪠 Apr 5, 2024
@bharanidharanj
Copy link

Test Results

  • TEST_ANDROID_SPACEBAR (FAILED): Tested with the attached PR build (Keyman 17.0.0303-beta-test-11175 on different Android versions (Android 5.0, 7.1, 9.0 and 12.0, 13, 14) and here is my observation: 1. Installed balochi_phonetic keyboard. 2. Installed Khmer Angkor and SIL (IPA) keyboard. 3. Switched to Balochi_Phonetic keyboard. Verified that the Spacebar captioned appropriately for the active keyboard. 4. Changed the orientation from portrait to landscape. 5. I observed that the label name is exceeding its boundaries in Android 5, 9, 7.1, and 9 OS versions. However, it displays correctly in Android 12, 13, and 14 OS versions.

..Android 5

..Android 7.1

..Android 9.0

..Android 12

@keymanapp-test-bot keymanapp-test-bot bot added user-test-failed and removed user-test-required User tests have not been completed labels Apr 5, 2024
@jahorton
Copy link
Contributor Author

jahorton commented Apr 8, 2024

Test Results

  • TEST_ANDROID_SPACEBAR (FAILED): Tested with the attached PR build (Keyman 17.0.0303-beta-test-11175 on different Android versions (Android 5.0, 7.1, 9.0 and 12.0, 13, 14) and here is my observation: 1. Installed balochi_phonetic keyboard. 2. Installed Khmer Angkor and SIL (IPA) keyboard. 3. Switched to Balochi_Phonetic keyboard. Verified that the Spacebar captioned appropriately for the active keyboard. 4. Changed the orientation from portrait to landscape. 5. I observed that the label name is exceeding its boundaries in Android 5, 9, 7.1, and 9 OS versions. However, it displays correctly in Android 12, 13, and 14 OS versions.

..Android 5

[...]

..Android 12

I'm going to call this a pass, but I really can't blame you for reporting it this way. TL,DR: technical limitations with older Chrome versions. I forgot about this aspect and should have mentioned to only test it with "the latest version of Android" and/or "versions of Android 12+" or similar.

TEST_ANDROID_SPACEBAR: PASS


The reason: the technique we use to ensure that the key height stays within the spacebar's boundary isn't available to us in old versions of Chrome. Per https://developer.mozilla.org/en-US/docs/Web/API/TextMetrics#browser_compatibility, we need a minimum of Chrome 87 in order to scale based on key-height. (See the fontBoundingBoxAscent entry.)

Re: Android 7.1.1, I found a link suggesting that Android 7 shipped with Chrome 58. For Android 9.0, APKMirror offers Chrome 73. As Android Studio emulators typically start out with the minimum possible Chrome version, this explains why the height scaling wasn't working.

So, a couple of things of note:

  1. No errors or crashes resulted from trying to use Web features not available given the version of Chrome in place.
  2. The key width scaling still worked perfectly fine.

Copy link
Contributor

@darcywong00 darcywong00 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@jahorton jahorton merged commit 50f30b3 into beta Apr 10, 2024
15 checks passed
@jahorton jahorton deleted the refactor/web/osk-spacebar-labeling branch April 10, 2024 07:44
@keyman-server
Copy link
Collaborator

Changes in this pull request will be available for download in Keyman version 17.0.305-beta

Copy link
Member

@mcdurdin mcdurdin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pretty much fine, but there are some funny leftover bits and pieces and some code that really needs simplification.

Comment on lines +89 to +93
if (typeof (tButton.className) == 'undefined' || tButton.className == '') {
tButton.className = 'kmw-spacebar';
} else if (tButton.className.indexOf('kmw-spacebar') == -1) {
tButton.className += ' kmw-spacebar';
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (typeof (tButton.className) == 'undefined' || tButton.className == '') {
tButton.className = 'kmw-spacebar';
} else if (tButton.className.indexOf('kmw-spacebar') == -1) {
tButton.className += ' kmw-spacebar';
}
tButton.classList.add('kmw-spacebar');

https://developer.mozilla.org/en-US/docs/Web/API/Element/classList

Comment on lines +95 to +97
if (spacebarLabel.className != 'kmw-spacebar-caption') {
spacebarLabel.className = 'kmw-spacebar-caption';
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (spacebarLabel.className != 'kmw-spacebar-caption') {
spacebarLabel.className = 'kmw-spacebar-caption';
}
spacebarLabel.className = 'kmw-spacebar-caption';

No need to guard this ... I am sure it'll already be optimized.

Comment on lines +86 to +97
const spacebarLabel = this.spaceBarKey.label;
let tButton = this.spaceBarKey.btn;

if (typeof (tButton.className) == 'undefined' || tButton.className == '') {
tButton.className = 'kmw-spacebar';
} else if (tButton.className.indexOf('kmw-spacebar') == -1) {
tButton.className += ' kmw-spacebar';
}

if (spacebarLabel.className != 'kmw-spacebar-caption') {
spacebarLabel.className = 'kmw-spacebar-caption';
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or how about this ... so much shorter:

Suggested change
const spacebarLabel = this.spaceBarKey.label;
let tButton = this.spaceBarKey.btn;
if (typeof (tButton.className) == 'undefined' || tButton.className == '') {
tButton.className = 'kmw-spacebar';
} else if (tButton.className.indexOf('kmw-spacebar') == -1) {
tButton.className += ' kmw-spacebar';
}
if (spacebarLabel.className != 'kmw-spacebar-caption') {
spacebarLabel.className = 'kmw-spacebar-caption';
}
this.spaceBarKey.btn.classList.add('kmw-spacebar');
this.spaceBarKey.label.className = 'kmw-spacebar-caption';

**/
showLanguage(displayName: string) {
if(!this.spaceBarKey) {
return () => {};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this about? Nothing else returns anything?

spacebarLabel.innerText = displayName;
}
}
catch (ex) { }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we catching everything here?

}

public refreshLayout(vkbd: VisualKeyboard, layoutParams: LayerLayoutParams) {
const layerHeight = layoutParams.keyboardHeight;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants