Commit 9edf1b82 authored by Eitan Isaacson's avatar Eitan Isaacson
Browse files

Provide full menu item count to accessibility services.

We need to count buttons inside of toolbar items, and ignore dividers.

This fixes mozilla-mobile/fenix#2143
parent f3013ae5
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@ import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.WindowManager
import android.view.accessibility.AccessibilityNodeInfo
import android.widget.PopupWindow
import androidx.annotation.VisibleForTesting
import androidx.coordinatorlayout.widget.CoordinatorLayout
@@ -57,6 +58,13 @@ class BrowserMenu internal constructor(
            adapter = this@BrowserMenu.adapter
        }

        menuList?.setAccessibilityDelegate(object : View.AccessibilityDelegate() {
            override fun onInitializeAccessibilityNodeInfo(host: View?, info: AccessibilityNodeInfo?) {
                super.onInitializeAccessibilityNodeInfo(host, info)
                info?.collectionInfo = AccessibilityNodeInfo.CollectionInfo.obtain(adapter.interactiveCount, 0, false)
            }
        })

        return PopupWindow(
            view,
            WindowManager.LayoutParams.WRAP_CONTENT,
+1 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ internal class BrowserMenuAdapter(
    var menu: BrowserMenu? = null

    internal val visibleItems = items.filter { it.visible() }
    internal val interactiveCount = visibleItems.sumBy { it.interactiveCount() }
    private val inflater = LayoutInflater.from(context)

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
+7 −0
Original line number Diff line number Diff line
@@ -16,6 +16,13 @@ interface BrowserMenuItem {
     */
    val visible: () -> Boolean

    /**
     * Lambda expression that returns the number of interactive elements in this menu item.
     * For example, a simple item will have 1, divider will have 0, and a composite
     * item, like a tool bar, will have several.
     */
    val interactiveCount: () -> Int get() = { 1 }

    /**
     * Returns the layout resource ID of the layout to be inflated for showing a menu item of this
     * type.
+2 −0
Original line number Diff line number Diff line
@@ -15,6 +15,8 @@ import mozilla.components.browser.menu.R
class BrowserMenuDivider : BrowserMenuItem {
    override var visible: () -> Boolean = { true }

    override val interactiveCount: () -> Int = { 0 }

    override fun getLayoutResource() = R.layout.mozac_browser_menu_item_divider

    override fun bind(menu: BrowserMenu, view: View) = Unit
+2 −0
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@ class BrowserMenuItemToolbar(
) : BrowserMenuItem {
    override var visible: () -> Boolean = { true }

    override val interactiveCount: () -> Int = { items.size }

    override fun getLayoutResource() = R.layout.mozac_browser_menu_item_toolbar

    override fun bind(menu: BrowserMenu, view: View) {
Loading