1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 package org.mozilla.fenix.components.toolbar.interactor
7 import mozilla.components.ui.tabcounter.TabCounterMenu
8 import org.mozilla.fenix.components.toolbar.BrowserToolbarController
9 import org.mozilla.fenix.components.toolbar.BrowserToolbarMenuController
10 import org.mozilla.fenix.components.toolbar.ToolbarMenu
13 * Interface for the browser toolbar interactor. This interface is implemented by objects that
14 * want to respond to user interaction on the browser toolbar.
16 interface BrowserToolbarInteractor {
17 fun onBrowserToolbarPaste(text: String)
18 fun onBrowserToolbarPasteAndGo(text: String)
19 fun onBrowserToolbarClicked()
20 fun onBrowserToolbarMenuItemTapped(item: ToolbarMenu.Item)
21 fun onTabCounterClicked()
22 fun onTabCounterMenuItemTapped(item: TabCounterMenu.Item)
23 fun onScrolled(offset: Int)
24 fun onReaderModePressed(enabled: Boolean)
27 * Navigates to the Home screen. Called when a user taps on the Home button.
29 fun onHomeButtonClicked()
32 * Deletes all tabs and navigates to the Home screen. Called when a user taps on the erase button.
34 fun onEraseButtonClicked()
37 * Opens the shopping bottom sheet. Called when the user interacts with the shopping cfr action.
39 fun onShoppingCfrActionClicked()
42 * Updates the settings for the shopping CFR. Called when the user dismisses the shopping cfr action.
44 fun onShoppingCfrDismiss()
47 * Opens the translation bottom sheet. Called when the user interacts with the translation
50 fun onTranslationsButtonClicked()
54 * The default implementation of [BrowserToolbarInteractor].
56 * @property browserToolbarController [BrowserToolbarController] to which user actions can be
57 * delegated for all interactions on the browser toolbar.
58 * @property menuController [BrowserToolbarMenuController] to which user actions can be delegated
59 * for all interactions on the the browser toolbar menu.
61 class DefaultBrowserToolbarInteractor(
62 private val browserToolbarController: BrowserToolbarController,
63 private val menuController: BrowserToolbarMenuController,
64 ) : BrowserToolbarInteractor {
66 override fun onTabCounterClicked() {
67 browserToolbarController.handleTabCounterClick()
70 override fun onTabCounterMenuItemTapped(item: TabCounterMenu.Item) {
71 browserToolbarController.handleTabCounterItemInteraction(item)
74 override fun onBrowserToolbarPaste(text: String) {
75 browserToolbarController.handleToolbarPaste(text)
78 override fun onBrowserToolbarPasteAndGo(text: String) {
79 browserToolbarController.handleToolbarPasteAndGo(text)
82 override fun onBrowserToolbarClicked() {
83 browserToolbarController.handleToolbarClick()
86 override fun onBrowserToolbarMenuItemTapped(item: ToolbarMenu.Item) {
87 menuController.handleToolbarItemInteraction(item)
90 override fun onScrolled(offset: Int) {
91 browserToolbarController.handleScroll(offset)
94 override fun onReaderModePressed(enabled: Boolean) {
95 browserToolbarController.handleReaderModePressed(enabled)
98 override fun onHomeButtonClicked() {
99 browserToolbarController.handleHomeButtonClick()
102 override fun onEraseButtonClicked() {
103 browserToolbarController.handleEraseButtonClick()
106 override fun onShoppingCfrActionClicked() {
107 browserToolbarController.handleShoppingCfrActionClick()
110 override fun onShoppingCfrDismiss() {
111 browserToolbarController.handleShoppingCfrDismiss()
114 override fun onTranslationsButtonClicked() {
115 browserToolbarController.handleTranslationsButtonClick()