2
0
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:
mcarare 2020-11-12 16:39:57 +02:00 committed by Mihai Adrian Carare
parent 2302a589da
commit 1ed7efce41
2 changed files with 34 additions and 22 deletions

View File

@ -2,6 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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, You can obtain one at http://mozilla.org/MPL/2.0/. */
@file:Suppress("TooManyFunctions")
package org.mozilla.fenix.ext package org.mozilla.fenix.ext
import android.graphics.Rect 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. * Fills a [Rect] with data about a view's location in the screen.
* *
* @see View.getLocationOnScreen * @see View.getLocationOnScreen
* @see View.getRectWithViewLocation for a version of this that is relative to a window * @see View.getRectWithViewLocation for a version of this that is relative to a window
*/ */
fun View.getRectWithScreenLocation(): Rect { fun View.getRectWithScreenLocation(): Rect {
val locationOnScreen = IntArray(2).apply { getLocationOnScreen(this) } val locationOnScreen = IntArray(2).apply { getLocationOnScreen(this) }
return Rect(locationOnScreen[0], return Rect(
locationOnScreen[0],
locationOnScreen[1], locationOnScreen[1],
locationOnScreen[0] + width, locationOnScreen[0] + width,
locationOnScreen[1] + height) locationOnScreen[1] + height
)
} }
/** /**

View File

@ -9,8 +9,6 @@ import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.view.accessibility.AccessibilityEvent import android.view.accessibility.AccessibilityEvent
import android.view.accessibility.AccessibilityNodeInfo
import android.view.accessibility.AccessibilityNodeInfo.CollectionInfo
import androidx.annotation.IdRes import androidx.annotation.IdRes
import androidx.cardview.widget.CardView import androidx.cardview.widget.CardView
import androidx.constraintlayout.widget.ConstraintLayout 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.components.toolbar.TabCounter.Companion.SO_MANY_TABS_OPEN
import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.settings import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.ext.updateAccessibilityCollectionInfo
import org.mozilla.fenix.tabtray.SaveToCollectionsButtonAdapter.MultiselectModeChange import org.mozilla.fenix.tabtray.SaveToCollectionsButtonAdapter.MultiselectModeChange
import org.mozilla.fenix.tabtray.TabTrayDialogFragmentState.Mode import org.mozilla.fenix.tabtray.TabTrayDialogFragmentState.Mode
import java.text.NumberFormat import java.text.NumberFormat
@ -673,24 +672,11 @@ class TabTrayView(
String.format(view.context.getString(R.string.open_tab_tray_plural), count.toString()) String.format(view.context.getString(R.string.open_tab_tray_plural), count.toString())
} }
view.tabsTray.accessibilityDelegate = object : View.AccessibilityDelegate() { val isListTabView = view.context.settings().listTabView
override fun onInitializeAccessibilityNodeInfo( val columnCount = if (isListTabView) 1 else getNumberOfGridColumns(view.context)
host: View?, val rowCount = count.toDouble().div(columnCount).roundToInt()
info: AccessibilityNodeInfo?
) {
super.onInitializeAccessibilityNodeInfo(host, info)
val isListTabView = view.context.settings().listTabView
val columnCount = if (isListTabView) 1 else getNumberOfGridColumns(view.context) view.tabsTray.updateAccessibilityCollectionInfo(rowCount, columnCount)
val rowCount = count.toDouble().div(columnCount).roundToInt()
info?.collectionInfo = CollectionInfo.obtain(
rowCount,
columnCount,
false
)
}
}
} }
private fun updateTabCounter(count: Int): String { private fun updateTabCounter(count: Int): String {