mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-19 09:25:34 +00:00
[fenix] For https://github.com/mozilla-mobile/fenix/issues/16477: Switch to using an extension to update a11y collection info.
This commit is contained in:
parent
2302a589da
commit
1ed7efce41
@ -2,6 +2,8 @@
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
@file:Suppress("TooManyFunctions")
|
||||
|
||||
package org.mozilla.fenix.ext
|
||||
|
||||
import android.graphics.Rect
|
||||
@ -95,18 +97,42 @@ fun View.updateAccessibilityCollectionItemInfo(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the a11y collection info for a list.
|
||||
*/
|
||||
fun View.updateAccessibilityCollectionInfo(
|
||||
rowCount: Int,
|
||||
columnCount: Int
|
||||
) {
|
||||
this.accessibilityDelegate = object : View.AccessibilityDelegate() {
|
||||
override fun onInitializeAccessibilityNodeInfo(
|
||||
host: View?,
|
||||
info: AccessibilityNodeInfo?
|
||||
) {
|
||||
super.onInitializeAccessibilityNodeInfo(host, info)
|
||||
info?.collectionInfo = AccessibilityNodeInfo.CollectionInfo.obtain(
|
||||
rowCount,
|
||||
columnCount,
|
||||
false
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fills a [Rect] with data about a view's location in the screen.
|
||||
*
|
||||
* @see View.getLocationOnScreen
|
||||
* @see View.getRectWithViewLocation for a version of this that is relative to a window
|
||||
*/
|
||||
*/
|
||||
fun View.getRectWithScreenLocation(): Rect {
|
||||
val locationOnScreen = IntArray(2).apply { getLocationOnScreen(this) }
|
||||
return Rect(locationOnScreen[0],
|
||||
return Rect(
|
||||
locationOnScreen[0],
|
||||
locationOnScreen[1],
|
||||
locationOnScreen[0] + width,
|
||||
locationOnScreen[1] + height)
|
||||
locationOnScreen[1] + height
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -9,8 +9,6 @@ import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.accessibility.AccessibilityEvent
|
||||
import android.view.accessibility.AccessibilityNodeInfo
|
||||
import android.view.accessibility.AccessibilityNodeInfo.CollectionInfo
|
||||
import androidx.annotation.IdRes
|
||||
import androidx.cardview.widget.CardView
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
@ -52,6 +50,7 @@ import org.mozilla.fenix.components.toolbar.TabCounter.Companion.MAX_VISIBLE_TAB
|
||||
import org.mozilla.fenix.components.toolbar.TabCounter.Companion.SO_MANY_TABS_OPEN
|
||||
import org.mozilla.fenix.ext.components
|
||||
import org.mozilla.fenix.ext.settings
|
||||
import org.mozilla.fenix.ext.updateAccessibilityCollectionInfo
|
||||
import org.mozilla.fenix.tabtray.SaveToCollectionsButtonAdapter.MultiselectModeChange
|
||||
import org.mozilla.fenix.tabtray.TabTrayDialogFragmentState.Mode
|
||||
import java.text.NumberFormat
|
||||
@ -673,24 +672,11 @@ class TabTrayView(
|
||||
String.format(view.context.getString(R.string.open_tab_tray_plural), count.toString())
|
||||
}
|
||||
|
||||
view.tabsTray.accessibilityDelegate = object : View.AccessibilityDelegate() {
|
||||
override fun onInitializeAccessibilityNodeInfo(
|
||||
host: View?,
|
||||
info: AccessibilityNodeInfo?
|
||||
) {
|
||||
super.onInitializeAccessibilityNodeInfo(host, info)
|
||||
val isListTabView = view.context.settings().listTabView
|
||||
|
||||
val columnCount = if (isListTabView) 1 else getNumberOfGridColumns(view.context)
|
||||
val rowCount = count.toDouble().div(columnCount).roundToInt()
|
||||
|
||||
info?.collectionInfo = CollectionInfo.obtain(
|
||||
rowCount,
|
||||
columnCount,
|
||||
false
|
||||
)
|
||||
}
|
||||
}
|
||||
view.tabsTray.updateAccessibilityCollectionInfo(rowCount, columnCount)
|
||||
}
|
||||
|
||||
private fun updateTabCounter(count: Int): String {
|
||||
|
Loading…
Reference in New Issue
Block a user