Commit 79ce172f authored by Jeff Boek's avatar Jeff Boek Committed by Sebastian Kaspari
Browse files

Fixes #2658 - Adds the ability to long click the urlView

parent d40c2afe
......@@ -506,6 +506,13 @@ class BrowserToolbar @JvmOverloads constructor(
displayToolbar.menuBuilder = menuBuilder
}
/**
* Set a LongClickListener to the urlView of the toolbar.
*/
fun setOnUrlLongClickListener(handler: ((View) -> Boolean)?) {
displayToolbar.setOnUrlLongClickListener(handler)
}
internal fun onUrlEntered(url: String) {
if (urlCommitListener?.invoke(url) != false) {
// Return to display mode if there's no urlCommitListener or if it returned true. This lets
......
......@@ -284,6 +284,13 @@ internal class DisplayToolbar(
invalidateActions(navigationActions + pageActions + browserActions)
}
/**
* Set a LongClickListener to the urlView of the toolbar.
*/
internal fun setOnUrlLongClickListener(handler: ((View) -> Boolean)?) {
urlView.setOnLongClickListener(handler)
}
// We measure the views manually to avoid overhead by using complex ViewGroup implementations
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
// This toolbar is using the full size provided by the parent
......
......@@ -503,6 +503,27 @@ class BrowserToolbarTest {
assertFalse(displayToolbar.onUrlClicked())
}
@Test
fun `onUrlLongClick is forwarded to the display toolbar`() {
val toolbar = BrowserToolbar(context)
var hasBeenLongClicked = false
toolbar.setOnUrlLongClickListener {
hasBeenLongClicked = true
true
}
toolbar.displayToolbar.urlView.performLongClick()
assertTrue(hasBeenLongClicked)
hasBeenLongClicked = false
toolbar.setOnUrlLongClickListener(null)
toolbar.displayToolbar.urlView.performLongClick()
assertFalse(hasBeenLongClicked)
}
@Test
fun `layout of children will factor in padding`() {
val toolbar = BrowserToolbar(context)
......
......@@ -627,6 +627,44 @@ class DisplayToolbarTest {
verify(toolbar).editMode()
}
@Test
fun `urlView delegates long click when set`() {
val toolbar = mock(BrowserToolbar::class.java)
val displayToolbar = DisplayToolbar(context, toolbar)
var longUrlClicked = false
displayToolbar.setOnUrlLongClickListener {
longUrlClicked = true
false
}
assertFalse(longUrlClicked)
displayToolbar.urlView.performLongClick()
assertTrue(longUrlClicked)
}
@Test
fun `urlView longClickListener can be unset`() {
val toolbar = mock(BrowserToolbar::class.java)
val displayToolbar = DisplayToolbar(context, toolbar)
var longClicked = false
displayToolbar.setOnUrlLongClickListener {
longClicked = true
true
}
displayToolbar.urlView.performLongClick()
assertTrue(longClicked)
longClicked = false
displayToolbar.setOnUrlLongClickListener(null)
displayToolbar.urlView.performLongClick()
assertFalse(longClicked)
}
@Test
fun `iconView changes image resource when site security changes`() {
val toolbar = mock(BrowserToolbar::class.java)
......
......@@ -23,6 +23,7 @@ permalink: /changelog/
* **browser-toolbar**
* Adds `browserToolbarProgressBarGravity` attr with options `top` and `bottom` (default).
* Adds the ability to long click the urlView
# 0.49.0
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment