<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import Foundation
import UIKit

protocol FindInPageBarDelegate: class {
    func findInPage(findInPage: FindInPageBar, didTextChange text: String)
    func findInPage(findInPage: FindInPageBar, didFindPreviousWithText text: String)
    func findInPage(findInPage: FindInPageBar, didFindNextWithText text: String)
    func findInPageDidPressClose(findInPage: FindInPageBar)
}

private struct FindInPageUX {
    static let ButtonColor = UIColor.blackColor()
    static let MatchCountColor = UIColor.lightGrayColor()
    static let MatchCountFont = UIConstants.DefaultChromeFont
    static let SearchTextColor = UIColor(rgb: 0xe66000)
    static let SearchTextFont = UIConstants.DefaultChromeFont
    static let TopBorderColor = UIColor(rgb: 0xEEEEEE)
}

class FindInPageBar: UIView {
    weak var delegate: FindInPageBarDelegate?
    private let searchText = UITextField()
    private let matchCountView = UILabel()
    private let previousButton = UIButton()
    private let nextButton = UIButton()

    var currentResult = 0 {
        didSet {
            matchCountView.text = "\(currentResult)/\(totalResults)"
        }
    }

    var totalResults = 0 {
        didSet {
            matchCountView.text = "\(currentResult)/\(totalResults)"
            previousButton.enabled = totalResults > 1
            nextButton.enabled = previousButton.enabled
        }
    }

    var text: String? {
        get {
            return searchText.text
        }

        set {
            searchText.text = newValue
            SELdidTextChange(searchText)
        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)

        backgroundColor = UIColor.whiteColor()

        searchText.addTarget(self, action: #selector(FindInPageBar.SELdidTextChange(_:)), forControlEvents: UIControlEvents.EditingChanged)
        searchText.textColor = FindInPageUX.SearchTextColor
        searchText.font = FindInPageUX.SearchTextFont
        searchText.autocapitalizationType = UITextAutocapitalizationType.None
        searchText.autocorrectionType = UITextAutocorrectionType.No
        addSubview(searchText)

        matchCountView.textColor = FindInPageUX.MatchCountColor
        matchCountView.font = FindInPageUX.MatchCountFont
        matchCountView.hidden = true
        addSubview(matchCountView)

        previousButton.setImage(UIImage(named: "find_previous"), forState: UIControlState.Normal)
        previousButton.setTitleColor(FindInPageUX.ButtonColor, forState: UIControlState.Normal)
        previousButton.accessibilityLabel = NSLocalizedString("Previous in-page result", tableName: "FindInPage", comment: "Accessibility label for previous result button in Find in Page Toolbar.")
        previousButton.addTarget(self, action: #selector(FindInPageBar.SELdidFindPrevious(_:)), forControlEvents: UIControlEvents.TouchUpInside)
        addSubview(previousButton)

        nextButton.setImage(UIImage(named: "find_next"), forState: UIControlState.Normal)
        nextButton.setTitleColor(FindInPageUX.ButtonColor, forState: UIControlState.Normal)
        nextButton.accessibilityLabel = NSLocalizedString("Next in-page result", tableName: "FindInPage", comment: "Accessibility label for next result button in Find in Page Toolbar.")
        nextButton.addTarget(self, action: #selector(FindInPageBar.SELdidFindNext(_:)), forControlEvents: UIControlEvents.TouchUpInside)
        addSubview(nextButton)

        let closeButton = UIButton()
        closeButton.setImage(UIImage(named: "find_close"), forState: UIControlState.Normal)
        closeButton.setTitleColor(FindInPageUX.ButtonColor, forState: UIControlState.Normal)
        closeButton.accessibilityLabel = NSLocalizedString("Done", tableName: "FindInPage", comment: "Done button in Find in Page Toolbar.")
        closeButton.addTarget(self, action: #selector(FindInPageBar.SELdidPressClose(_:)), forControlEvents: UIControlEvents.TouchUpInside)
        addSubview(closeButton)

        let topBorder = UIView()
        topBorder.backgroundColor = FindInPageUX.TopBorderColor
        addSubview(topBorder)

        searchText.snp_makeConstraints { make in<commit_msg>Bug 1270693 - Do not show the shortcuts bar under the Find In Page bar<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import Foundation
import UIKit

protocol FindInPageBarDelegate: class {
    func findInPage(findInPage: FindInPageBar, didTextChange text: String)
    func findInPage(findInPage: FindInPageBar, didFindPreviousWithText text: String)
    func findInPage(findInPage: FindInPageBar, didFindNextWithText text: String)
    func findInPageDidPressClose(findInPage: FindInPageBar)
}

private struct FindInPageUX {
    static let ButtonColor = UIColor.blackColor()
    static let MatchCountColor = UIColor.lightGrayColor()
    static let MatchCountFont = UIConstants.DefaultChromeFont
    static let SearchTextColor = UIColor(rgb: 0xe66000)
    static let SearchTextFont = UIConstants.DefaultChromeFont
    static let TopBorderColor = UIColor(rgb: 0xEEEEEE)
}

class FindInPageBar: UIView {
    weak var delegate: FindInPageBarDelegate?
    private let searchText = UITextField()
    private let matchCountView = UILabel()
    private let previousButton = UIButton()
    private let nextButton = UIButton()

    var currentResult = 0 {
        didSet {
            matchCountView.text = "\(currentResult)/\(totalResults)"
        }
    }

    var totalResults = 0 {
        didSet {
            matchCountView.text = "\(currentResult)/\(totalResults)"
            previousButton.enabled = totalResults > 1
            nextButton.enabled = previousButton.enabled
        }
    }

    var text: String? {
        get {
            return searchText.text
        }

        set {
            searchText.text = newValue
            SELdidTextChange(searchText)
        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)

        backgroundColor = UIColor.whiteColor()

        searchText.addTarget(self, action: #selector(FindInPageBar.SELdidTextChange(_:)), forControlEvents: UIControlEvents.EditingChanged)
        searchText.textColor = FindInPageUX.SearchTextColor
        searchText.font = FindInPageUX.SearchTextFont
        searchText.autocapitalizationType = UITextAutocapitalizationType.None
        searchText.autocorrectionType = UITextAutocorrectionType.No
        if #available(iOS 9.0, *) {
            searchText.inputAssistantItem.leadingBarButtonGroups = []
            searchText.inputAssistantItem.trailingBarButtonGroups = []
        }
        //searchText.delegate = self
        addSubview(searchText)

        matchCountView.textColor = FindInPageUX.MatchCountColor
        matchCountView.font = FindInPageUX.MatchCountFont
        matchCountView.hidden = true
        addSubview(matchCountView)

        previousButton.setImage(UIImage(named: "find_previous"), forState: UIControlState.Normal)
        previousButton.setTitleColor(FindInPageUX.ButtonColor, forState: UIControlState.Normal)
        previousButton.accessibilityLabel = NSLocalizedString("Previous in-page result", tableName: "FindInPage", comment: "Accessibility label for previous result button in Find in Page Toolbar.")
        previousButton.addTarget(self, action: #selector(FindInPageBar.SELdidFindPrevious(_:)), forControlEvents: UIControlEvents.TouchUpInside)
        addSubview(previousButton)

        nextButton.setImage(UIImage(named: "find_next"), forState: UIControlState.Normal)
        nextButton.setTitleColor(FindInPageUX.ButtonColor, forState: UIControlState.Normal)
        nextButton.accessibilityLabel = NSLocalizedString("Next in-page result", tableName: "FindInPage", comment: "Accessibility label for next result button in Find in Page Toolbar.")
        nextButton.addTarget(self, action: #selector(FindInPageBar.SELdidFindNext(_:)), forControlEvents: UIControlEvents.TouchUpInside)
        addSubview(nextButton)

        let closeButton = UIButton()
        closeButton.setImage(UIImage(named: "find_close"), forState: UIControlState.Normal)
        closeButton.setTitleColor(FindInPageUX.ButtonColor, forState: UIControlState.Normal)
        closeButton.accessibilityLabel = NSLocalizedString("Done", tableName: "FindInPage", comment: "Done button in Find in Page Toolbar.")
        closeButton.addTarget(self, action: #selector(FindInPageBar.SELdidPressClose(_:)), forControlEvents: UIControlEvents.TouchUpInside)
        addSubview(closeButton)

        let topBorder = UIView()
        topBorder.backgroundColor = FindInPageUX.TopBorderColor
        addSubview(topBorder)

        searchText.snp_makeConstraints { make in
{'fraction_non_alphanumeric': 0.08003108003108003, 'fraction_numerical': 0.004107004107004107, 'mean_word_length': 3.6853874154966197, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7547148', 'n_tokens_mistral': 2529, 'n_tokens_neox': 2475, 'n_words': 557}