Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Commit

Permalink
Bug 1864760 - Added actions to Toolbar and MenuButton to hide and sho…
Browse files Browse the repository at this point in the history
…w the menu button
  • Loading branch information
HarrisonOg committed Jan 29, 2024
1 parent cc65693 commit b9399fa
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,20 @@ class BrowserToolbar @JvmOverloads constructor(
edit.removeEditActionEnd(action)
}

/**
* Hides the menu button in display mode.
*/
override fun hideMenuButton() {
display.hideMenuButton()
}

/**
* Shows the menu button in display mode.
*/
override fun showMenuButton() {
display.showMenuButton()
}

/**
* Switches to URL editing mode.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,20 @@ class DisplayToolbar internal constructor(
internal fun removeNavigationAction(action: Toolbar.Action) {
views.navigationActions.removeAction(action)
}

/**
* Hides the menu button in display mode.
*/
internal fun hideMenuButton() {
views.menu.setShouldBeHidden(true)
}

/**
* Shows the menu button in display mode.
*/
internal fun showMenuButton() {
views.menu.setShouldBeHidden(false)
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ internal class MenuButton(

fun setColorFilter(@ColorInt color: Int) = impl.setColorFilter(color)

/**
* Hides the menu button.
*
* @param shouldBeHidden A [Boolean] that determines the visibility of the menu button.
*/
fun setShouldBeHidden(shouldBeHidden: Boolean) {
impl.isVisible = !shouldBeHidden && shouldBeVisible()
}

@VisibleForTesting
internal fun shouldBeVisible() = impl.menuBuilder != null || impl.menuController != null
}
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,30 @@ class BrowserToolbarTest {
verify(edit).removeEditActionEnd(action)
}

@Test
fun `WHEN hideMenuButton is sent to BrowserToolbar THEN it will be forwarded to the DisplayToolbar`() {
val toolbar = BrowserToolbar(testContext)

val display: DisplayToolbar = mock()
toolbar.display = display

toolbar.hideMenuButton()

verify(display).hideMenuButton()
}

@Test
fun `WHEN showMenuButton is sent to BrowserToolbar THEN it will be forwarded to the DisplayToolbar`() {
val toolbar = BrowserToolbar(testContext)

val display: DisplayToolbar = mock()
toolbar.display = display

toolbar.showMenuButton()

verify(display).showMenuButton()
}

@Test
fun `cast to view`() {
// Given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,16 @@ interface Toolbar {
*/
fun removeEditActionEnd(action: Action)

/**
* Hides the menu button in display mode.
*/
fun hideMenuButton()

/**
* Shows the menu button in display mode.
*/
fun showMenuButton()

/**
* Casts this toolbar to an Android View object.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ class CustomTabSessionTitleObserverTest {
override fun addEditActionStart(action: Toolbar.Action) = Unit
override fun addEditActionEnd(action: Toolbar.Action) = Unit
override fun removeEditActionEnd(action: Toolbar.Action) = Unit
override fun hideMenuButton() = Unit
override fun showMenuButton() = Unit
override fun setOnEditListener(listener: Toolbar.OnEditListener) = Unit
override fun displayMode() = Unit
override fun editMode(cursorPlacement: Toolbar.CursorPlacement) = Unit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ class ToolbarAutocompleteFeatureTest {
fail()
}

override fun hideMenuButton() {
fail()
}

override fun showMenuButton() {
fail()
}

override fun invalidateActions() {
fail()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ class ToolbarInteractorTest {
fail()
}

override fun hideMenuButton() {
fail()
}

override fun showMenuButton() {
fail()
}

override fun invalidateActions() {
fail()
}
Expand Down
4 changes: 4 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ permalink: /changelog/

* **all components**
* All new usages of the `concept-fetch` component to make fetch requests now have conservative-mode off by default. Current features will continue to use conservative mode until individually updated.

* **browser-toolbar**
* Add `showMenuButton` and `hideMenuButton` API to `BrowserToolbar` and `DisplayToolbar` to allow hiding and showing of the menu button in
the `BrowserToolbar` [Bug 1864760](https://bugzilla.mozilla.org/show_bug.cgi?id=1864760)

# 123.0
* [Commits](https://github.com/mozilla-mobile/firefox-android/compare/releases_v122..releases_v123)
Expand Down

0 comments on commit b9399fa

Please sign in to comment.