Skip to content

Commit

Permalink
Issue mozilla-mobile#11890: Add a new action container in the EditToo…
Browse files Browse the repository at this point in the history
…lbar
  • Loading branch information
gabrielluong committed Mar 24, 2022
1 parent 32e8798 commit 802b57e
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,17 @@ class BrowserToolbar @JvmOverloads constructor(
}

/**
* Adds an action to be displayed on the right of the URL in edit mode.
* Adds an action to be displayed at the start of the URL in edit mode.
*/
override fun addEditAction(action: Toolbar.Action) {
edit.addEditAction(action)
override fun addEditActionStart(action: Toolbar.Action) {
edit.addEditActionStart(action)
}

/**
* Adds an action to be displayed at the end of the URL in edit mode.
*/
override fun addEditActionEnd(action: Toolbar.Action) {
edit.addEditActionEnd(action)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,16 @@ private const val AUTOCOMPLETE_QUERY_THREADS = 3
* Sub-component of the browser toolbar responsible for allowing the user to edit the URL ("edit mode").
*
* Structure:
* +------+---------------------------+---------+------+
* | icon | url | actions | exit |
* +------+---------------------------+---------+------+
* +------+--------------------+---------------------------+------------------+------+
* | icon | edit actions start | url | edit actions end | exit |
* +------+--------------------+---------------------------+------------------+------+
*
* - icon: Optional icon that will be shown in front of the URL.
* - url: Editable URL of the currently displayed website
* - actions: Optional action icons injected by other components (e.g. barcode scanner)
* - edit actions start: Optional action icons injected by other components in front of the URL
* (e.g. search engines).
* - url: Editable URL of the currently displayed website.
* - edit actions end: Optional action icons injected by other components after the URL
* (e.g. barcode scanner).
* - exit: Button that switches back to display mode or invoke an app-defined callback.
*/
@Suppress("LargeClass")
Expand Down Expand Up @@ -87,9 +90,10 @@ class EditToolbar internal constructor(

@VisibleForTesting(otherwise = PRIVATE)
internal val views = EditToolbarViews(
background = rootView.findViewById<ImageView>(R.id.mozac_browser_toolbar_background),
icon = rootView.findViewById<ImageView>(R.id.mozac_browser_toolbar_edit_icon),
editActions = rootView.findViewById<ActionContainer>(R.id.mozac_browser_toolbar_edit_actions),
background = rootView.findViewById(R.id.mozac_browser_toolbar_background),
icon = rootView.findViewById(R.id.mozac_browser_toolbar_edit_icon),
editActionsStart = rootView.findViewById(R.id.mozac_browser_toolbar_edit_actions_start),
editActionsEnd = rootView.findViewById(R.id.mozac_browser_toolbar_edit_actions_end),
clear = rootView.findViewById<ImageView>(R.id.mozac_browser_toolbar_clear_view).apply {
setOnClickListener {
onClear()
Expand Down Expand Up @@ -232,11 +236,16 @@ class EditToolbar internal constructor(
}

internal fun invalidateActions() {
views.editActions.invalidateActions()
views.editActionsStart.invalidateActions()
views.editActionsEnd.invalidateActions()
}

internal fun addEditAction(action: Toolbar.Action) {
views.editActions.addAction(action)
internal fun addEditActionStart(action: Toolbar.Action) {
views.editActionsStart.addAction(action)
}

internal fun addEditActionEnd(action: Toolbar.Action) {
views.editActionsEnd.addAction(action)
}

/**
Expand Down Expand Up @@ -327,7 +336,8 @@ class EditToolbar internal constructor(
internal class EditToolbarViews(
val background: ImageView,
val icon: ImageView,
val editActions: ActionContainer,
val editActionsStart: ActionContainer,
val editActionsEnd: ActionContainer,
val clear: ImageView,
val url: InlineAutocompleteEditText
)
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@
tools:ignore="ContentDescription"
android:layout_marginTop="8dp" />

<mozilla.components.browser.toolbar.internal.ActionContainer
android:id="@+id/mozac_browser_toolbar_edit_actions_start"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginTop="8dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toEndOf="@id/mozac_browser_toolbar_edit_icon"
mozac:actionContainerItemSize="56dp"
tools:layout_width="56dp" />

<mozilla.components.ui.autocomplete.InlineAutocompleteEditText
android:id="@+id/mozac_browser_toolbar_edit_url_view"
android:layout_width="0dp"
Expand All @@ -50,12 +60,12 @@
android:background="#00000000"
android:textSize="15sp"
app:layout_goneMarginStart="8dp"
app:layout_constraintStart_toEndOf="@id/mozac_browser_toolbar_edit_icon"
app:layout_constraintEnd_toStartOf="@id/mozac_browser_toolbar_edit_actions"
app:layout_constraintStart_toEndOf="@id/mozac_browser_toolbar_edit_actions_start"
app:layout_constraintEnd_toStartOf="@id/mozac_browser_toolbar_edit_actions_end"
app:layout_constraintTop_toTopOf="parent" />

<mozilla.components.browser.toolbar.internal.ActionContainer
android:id="@+id/mozac_browser_toolbar_edit_actions"
android:id="@+id/mozac_browser_toolbar_edit_actions_end"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginTop="8dp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ class BrowserToolbarTest {
}

@Test
fun `add edit action will be forwarded to edit toolbar`() {
fun `add edit action start will be forwarded to edit toolbar`() {
val toolbar = BrowserToolbar(testContext)

val edit: EditToolbar = mock()
Expand All @@ -444,9 +444,25 @@ class BrowserToolbarTest {
// Do nothing
}

toolbar.addEditAction(action)
toolbar.addEditActionStart(action)

verify(edit).addEditAction(action)
verify(edit).addEditActionStart(action)
}

@Test
fun `add edit action end will be forwarded to edit toolbar`() {
val toolbar = BrowserToolbar(testContext)

val edit: EditToolbar = mock()
toolbar.edit = edit

val action = BrowserToolbar.Button(mock(), "QR code scanner") {
// Do nothing
}

toolbar.addEditActionEnd(action)

verify(edit).addEditActionEnd(action)
}

@Test
Expand Down Expand Up @@ -511,6 +527,19 @@ class BrowserToolbarTest {
verify(display).invalidateActions()
}

@Test
fun `invalidate actions is forwarded to edit toolbar`() {
val toolbar = BrowserToolbar(testContext)
val edit: EditToolbar = mock()
toolbar.edit = edit

verify(edit, never()).invalidateActions()

toolbar.invalidateActions()

verify(edit).invalidateActions()
}

@Test
fun `search terms (if set) are forwarded to edit toolbar instead of URL`() {
val toolbar = BrowserToolbar(testContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,12 @@ interface Toolbar {
/**
* Adds an action to be displayed in edit mode.
*/
fun addEditAction(action: Action)
fun addEditActionStart(action: Action)

/**
* Adds an action to be displayed in edit mode.
*/
fun addEditActionEnd(action: Action)

/**
* Casts this toolbar to an Android View object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ class CustomTabSessionTitleObserverTest {
override fun removePageAction(action: Toolbar.Action) = Unit
override fun addNavigationAction(action: Toolbar.Action) = Unit
override fun removeNavigationAction(action: Toolbar.Action) = Unit
override fun addEditAction(action: Toolbar.Action) = Unit
override fun addEditActionStart(action: Toolbar.Action) = Unit
override fun addEditActionEnd(action: Toolbar.Action) = Unit
override fun setOnEditListener(listener: Toolbar.OnEditListener) = Unit
override fun displayMode() = Unit
override fun editMode() = Unit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ class ToolbarAutocompleteFeatureTest {
fail()
}

override fun addEditAction(action: Toolbar.Action) {
override fun addEditActionStart(action: Toolbar.Action) {
fail()
}

override fun addEditActionEnd(action: Toolbar.Action) {
fail()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ class ToolbarInteractorTest {
fail()
}

override fun addEditAction(action: Toolbar.Action) {
override fun addEditActionStart(action: Toolbar.Action) {
fail()
}

override fun addEditActionEnd(action: Toolbar.Action) {
fail()
}

Expand Down
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ permalink: /changelog/

* **browser-toolbar**
* Removed reflective access to non-public SDK APIs controlling the sensitivity of the gesture detector following which sparingly and for very short time a pinch/spread to zoom gesture might be identified first as a scroll gesture and move the toolbar a little before snapping to it's original position.
* ⚠️ **This is a breaking change**: Replaced `addEditAction` in `BrowserToolbar` with `addEditActionStart` and `addEditActionEnd` to add actions to the left and right of the URL in edit mode. [#11890](/~https://github.com/mozilla-mobile/android-components/issues/11890)

* **feature-session**
* 🆕 New `ScreenOrientationFeature` to enable support for setting a requested screen orientation as part of supporting the ScreenOrientation web APIs.
Expand Down

0 comments on commit 802b57e

Please sign in to comment.