-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CrOS Settings: Extract Languages L1 page to card element
This is done in preparation to create a reusable element that can live in the Languages page and the new System Preferences category. Screenshot: http://screen/7EtMz3ghNWkMXha.png Bug: b/297108916, b/263823772 Test: browser_tests --gtest_filter="OSSettingsOsLanguagesPage*" Change-Id: I8a31263ab1d1f6006605e2216491d9d8d7baaa12 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4812075 Reviewed-by: Michael Cui <mlcui@google.com> Reviewed-by: Xiaohui Chen <xiaohuic@chromium.org> Commit-Queue: Wes Okuhara <wesokuhara@google.com> Cr-Commit-Position: refs/heads/main@{#1188458}
- Loading branch information
Wes Okuhara
authored and
Chromium LUCI CQ
committed
Aug 25, 2023
1 parent
c9fff86
commit 9b42a1b
Showing
10 changed files
with
229 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
chrome/browser/resources/ash/settings/os_languages_page/language_settings_card.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<style include="settings-shared"></style> | ||
|
||
<settings-card header-text="$i18n{osLanguagesPageTitle}"> | ||
<cr-link-row | ||
id="languagesRow" | ||
label="$i18n{languagesPageTitle}" | ||
sub-label="[[getLanguageDisplayName_( | ||
languages.prospectiveUILanguage, languageHelper)]]" | ||
on-click="onLanguagesV2Click_" | ||
role-description="$i18n{subpageArrowRoleDescription}"> | ||
</cr-link-row> | ||
<cr-link-row | ||
id="inputRow" | ||
class="hr" | ||
label="$i18n{inputPageTitleV2}" | ||
sub-label="[[getInputMethodDisplayName_( | ||
languages.inputMethods.currentId, languageHelper)]]" | ||
on-click="onInputClick_" | ||
role-description="$i18n{subpageArrowRoleDescription}"> | ||
</cr-link-row> | ||
<template is="dom-if" if="[[smartInputsEnabled_]]"> | ||
<cr-link-row | ||
id="smartInputsRow" | ||
class="hr" | ||
label="$i18n{smartInputsTitle}" | ||
on-click="onSmartInputsClick_" | ||
role-description="$i18n{subpageArrowRoleDescription}"> | ||
</cr-link-row> | ||
</template> | ||
</settings-card> |
140 changes: 140 additions & 0 deletions
140
chrome/browser/resources/ash/settings/os_languages_page/language_settings_card.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
/** | ||
* @fileoverview | ||
* 'language-settings-card' is the card element containing language settings. | ||
*/ | ||
|
||
import 'chrome://resources/cr_elements/cr_link_row/cr_link_row.js'; | ||
import '../os_settings_page/settings_card.js'; | ||
import '../settings_shared.css.js'; | ||
|
||
import {I18nMixin} from 'chrome://resources/cr_elements/i18n_mixin.js'; | ||
import {loadTimeData} from 'chrome://resources/js/load_time_data.js'; | ||
import {PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js'; | ||
|
||
import {PrefsState} from '../common/types.js'; | ||
import {RouteOriginMixin} from '../route_origin_mixin.js'; | ||
import {Router, routes} from '../router.js'; | ||
|
||
import {getTemplate} from './language_settings_card.html.js'; | ||
import {LanguageHelper, LanguagesModel} from './languages_types.js'; | ||
|
||
// The IME ID for the Accessibility Common extension used by Dictation. | ||
const ACCESSIBILITY_COMMON_IME_ID = | ||
'_ext_ime_egfdjlfmgnehecnclamagfafdccgfndpdictation'; | ||
|
||
const LanguageSettingsCardElementBase = | ||
RouteOriginMixin(I18nMixin(PolymerElement)); | ||
|
||
export class LanguageSettingsCardElement extends | ||
LanguageSettingsCardElementBase { | ||
static get is() { | ||
return 'language-settings-card' as const; | ||
} | ||
|
||
static get template() { | ||
return getTemplate(); | ||
} | ||
|
||
static get properties() { | ||
return { | ||
prefs: { | ||
type: Object, | ||
notify: true, | ||
}, | ||
|
||
languages: Object, | ||
|
||
languageHelper: Object, | ||
|
||
/** | ||
* This is enabled when any of the smart inputs features are allowed. | ||
*/ | ||
smartInputsEnabled_: { | ||
type: Boolean, | ||
value() { | ||
return loadTimeData.getBoolean('allowEmojiSuggestion'); | ||
}, | ||
}, | ||
}; | ||
} | ||
|
||
// Public API: Bidirectional data flow. | ||
/** Passed down to children. Do not access without using PrefsMixin. */ | ||
prefs: PrefsState; | ||
|
||
// Public API: Downwards data flow. | ||
languages: LanguagesModel|undefined; | ||
languageHelper: LanguageHelper|undefined; | ||
|
||
// Internal state. | ||
private smartInputsEnabled_: boolean; | ||
|
||
constructor() { | ||
super(); | ||
|
||
/** RouteOriginMixin override */ | ||
this.route = routes.OS_LANGUAGES; | ||
} | ||
|
||
override ready(): void { | ||
super.ready(); | ||
|
||
this.addFocusConfig(routes.OS_LANGUAGES_LANGUAGES, '#languagesRow'); | ||
this.addFocusConfig(routes.OS_LANGUAGES_INPUT, '#inputRow'); | ||
this.addFocusConfig(routes.OS_LANGUAGES_SMART_INPUTS, '#smartInputsRow'); | ||
} | ||
|
||
private onLanguagesV2Click_(): void { | ||
Router.getInstance().navigateTo(routes.OS_LANGUAGES_LANGUAGES); | ||
} | ||
|
||
private onInputClick_(): void { | ||
Router.getInstance().navigateTo(routes.OS_LANGUAGES_INPUT); | ||
} | ||
|
||
private onSmartInputsClick_(): void { | ||
Router.getInstance().navigateTo(routes.OS_LANGUAGES_SMART_INPUTS); | ||
} | ||
|
||
/** | ||
* @param code The language code of the language. | ||
* @return The display name of the language specified. | ||
*/ | ||
private getLanguageDisplayName_(code: string|undefined): string { | ||
if (!code || !this.languageHelper) { | ||
return ''; | ||
} | ||
const language = this.languageHelper.getLanguage(code); | ||
if (!language) { | ||
return ''; | ||
} | ||
return language.displayName; | ||
} | ||
|
||
/** | ||
* @param id The input method ID. | ||
* @return The display name of the input method. | ||
*/ | ||
private getInputMethodDisplayName_(id: string|undefined): string { | ||
if (!id || !this.languageHelper) { | ||
return ''; | ||
} | ||
if (id === ACCESSIBILITY_COMMON_IME_ID) { | ||
return ''; | ||
} | ||
return this.languageHelper.getInputMethodDisplayName(id); | ||
} | ||
} | ||
|
||
customElements.define( | ||
LanguageSettingsCardElement.is, LanguageSettingsCardElement); | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
[LanguageSettingsCardElement.is]: LanguageSettingsCardElement; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.