Skip to content

Commit

Permalink
Fix brave#1019: Add 'Find in page' to search panel.
Browse files Browse the repository at this point in the history
  • Loading branch information
iccub committed Jul 9, 2019
1 parent 682e3e4 commit c17857e
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 4 deletions.
3 changes: 3 additions & 0 deletions BraveShared/BraveStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ extension Strings {
public static let FindInPagePreviousResultButtonAccessibilityLabel = NSLocalizedString("FindInPagePreviousResultButtonAccessibilityLabel", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Previous in-page result", comment: "Accessibility label for previous result button in Find in Page Toolbar.")
public static let FindInPageNextResultButtonAccessibilityLabel = NSLocalizedString("FindInPageNextResultButtonAccessibilityLabel", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Next in-page result", comment: "Accessibility label for next result button in Find in Page Toolbar.")
public static let FindInPageDoneButtonAccessibilityLabel = NSLocalizedString("FindInPageDoneButtonAccessibilityLabel", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Done", comment: "Done button in Find in Page Toolbar.")
public static let FindInPage = NSLocalizedString("FindInPage", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Find \"%@\"", comment: "Find text in page.")
}

// MARK:- ReaderModeBarView.swift
Expand All @@ -117,6 +118,8 @@ extension Strings {
public static let TabToolbarLockImageAccessibilityLabel = NSLocalizedString("TabToolbarLockImageAccessibilityLabel", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Secure connection", comment: "Accessibility label for the lock icon, which is only present if the connection is secure")
public static let TabToolbarReaderViewButtonAccessibilityLabel = NSLocalizedString("TabToolbarReaderViewButtonAccessibilityLabel", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Reader View", comment: "Accessibility label for the Reader View button")
public static let TabToolbarReaderViewButtonTitle = NSLocalizedString("TabToolbarReaderViewButtonTitle", tableName: "BraveShared", bundle: Bundle.braveShared, value: "Add to Reading List", comment: "Accessibility label for action adding current page to reading list.")
public static let FindOnPageSectionHeader = NSLocalizedString("FindOnPageSectionHeader", tableName: "BraveShared", bundle: Bundle.braveShared, value: "On this page", comment: "Section header for find in page option")
public static let SearchHistorySectionHeader = NSLocalizedString("FindOnPageSectionHeader", tableName: "BraveShared", bundle: Bundle.braveShared, value: "History and bookmarks", comment: "Section header for history and bookmarks option")
}

// MARK:- TabPeekViewController.swift
Expand Down
6 changes: 6 additions & 0 deletions Client/Assets/Images.xcassets/Search Bar/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "[email protected]",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "[email protected]",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions Client/Frontend/Browser/BrowserViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1948,6 +1948,17 @@ extension BrowserViewController: SearchViewControllerDelegate {
func searchViewController(_ searchViewController: SearchViewController, didHighlightText text: String, search: Bool) {
self.topToolbar.setLocation(text, search: search)
}

func searchViewController(_ searchViewController: SearchViewController, shouldFindInPage query: String) {
topToolbar.leaveOverlayMode()
updateFindInPageVisibility(visible: true)
findInPageBar?.text = query

}

func searchViewControllerAllowFindInPage() -> Bool {
return tabManager.selectedTab?.webView?.url?.isAboutHomeURL == false
}
}

extension BrowserViewController: TabManagerDelegate {
Expand Down
47 changes: 43 additions & 4 deletions Client/Frontend/Browser/Search/SearchViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import Shared
import Storage
import BraveShared

private enum SearchListSection: Int {
private enum SearchListSection: Int, CaseIterable {
case searchSuggestions
case findInPage
case bookmarksAndHistory
static let Count = 2
}

private struct SearchViewControllerUX {
Expand Down Expand Up @@ -46,6 +46,8 @@ protocol SearchViewControllerDelegate: class {
func searchViewController(_ searchViewController: SearchViewController, didLongPressSuggestion suggestion: String)
func presentSearchSettingsController()
func searchViewController(_ searchViewController: SearchViewController, didHighlightText text: String, search: Bool)
func searchViewController(_ searchViewController: SearchViewController, shouldFindInPage query: String)
func searchViewControllerAllowFindInPage() -> Bool
}

class SearchViewController: SiteTableViewController, KeyboardHelperDelegate, LoaderListener {
Expand Down Expand Up @@ -402,6 +404,8 @@ class SearchViewController: SiteTableViewController, KeyboardHelperDelegate, Loa
if let url = URL(string: site.url) {
searchDelegate?.searchViewController(self, didSelectURL: url)
}
} else if section == SearchListSection.findInPage {
searchDelegate?.searchViewController(self, shouldFindInPage: searchQuery)
}
}

Expand All @@ -420,9 +424,31 @@ class SearchViewController: SiteTableViewController, KeyboardHelperDelegate, Loa

return 0
}

func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
guard let searchSection = SearchListSection(rawValue: section) else { return nil }

switch searchSection {
case .searchSuggestions: return nil
case .findInPage: return Strings.FindOnPageSectionHeader
case .bookmarksAndHistory: return Strings.SearchHistorySectionHeader
}

}

override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 0
guard let searchSection = SearchListSection(rawValue: section) else { return 0 }
let headerHeight: CGFloat = 22

switch searchSection {
case .findInPage:
if let sd = searchDelegate, sd.searchViewControllerAllowFindInPage() {
return headerHeight
}
return 0
case .bookmarksAndHistory: return data.isEmpty ? 0 : headerHeight
default: return 0
}
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
Expand All @@ -432,6 +458,14 @@ class SearchViewController: SiteTableViewController, KeyboardHelperDelegate, Loa
suggestionCell.imageView?.isAccessibilityElement = true
suggestionCell.imageView?.accessibilityLabel = String(format: Strings.SearchSuggestionFromFormatText, searchEngines.defaultEngine().shortName)
return suggestionCell

case .findInPage:
let cell = TwoLineTableViewCell()
cell.textLabel?.text = String(format: Strings.FindInPage, searchQuery)
cell.imageView?.image = #imageLiteral(resourceName: "search_bar_find_in_page_icon")
cell.imageView?.contentMode = .center

return cell

case .bookmarksAndHistory:
let cell = super.tableView(tableView, cellForRowAt: indexPath)
Expand Down Expand Up @@ -459,11 +493,16 @@ class SearchViewController: SiteTableViewController, KeyboardHelperDelegate, Loa
return searchEngines.shouldShowSearchSuggestions && !searchQuery.looksLikeAURL() && !tabType.isPrivate ? 1 : 0
case .bookmarksAndHistory:
return data.count
case .findInPage:
if let sd = searchDelegate, sd.searchViewControllerAllowFindInPage() {
return 1
}
return 0
}
}

func numberOfSections(in tableView: UITableView) -> Int {
return SearchListSection.Count
return SearchListSection.allCases.count
}

func tableView(_ tableView: UITableView, didHighlightRowAt indexPath: IndexPath) {
Expand Down

0 comments on commit c17857e

Please sign in to comment.