<commit_before>import Foundation
import Shared
import WebImage
import Storage

struct TopSiteCellUX {
    static let TitleInsetPercent: CGFloat = 0.66
    static let TitleBackgroundColor = UIColor(colorLiteralRed: 1, green: 1, blue: 1, alpha: 0.7)
    static let TitleTextColor = UIColor.blackColor()
    static let TitleFont = DynamicFontHelper.defaultHelper.DefaultSmallFont
    static let SelectedOverlayColor = UIColor(white: 0.0, alpha: 0.25)
    static let CellCornerRadius: CGFloat = 4
    static let TitleOffset: CGFloat = 5
    static let OverlayColor = UIColor(white: 0.0, alpha: 0.25)
    static let IconSize = CGSize(width: 32, height: 32)
}

/*
 *  The TopSite cell that appears in the ASHorizontalScrollView.
*/
class TopSiteItemCell: UICollectionViewCell {

    lazy private var imageView: UIImageView = {
        let imageView = UIImageView()
        imageView.layer.masksToBounds = true
        return imageView
    }()

    lazy private var titleLabel: UILabel = {
        let titleLabel = UILabel()
        titleLabel.layer.masksToBounds = true
        titleLabel.textAlignment = .Center
        titleLabel.font = TopSiteCellUX.TitleFont
        titleLabel.textColor = TopSiteCellUX.TitleTextColor
        titleLabel.backgroundColor = UIColor.clearColor()
        return titleLabel
    }()

    lazy var selectedOverlay: UIView = {
        let selectedOverlay = UIView()
        selectedOverlay.backgroundColor = TopSiteCellUX.OverlayColor
        selectedOverlay.hidden = true
        return selectedOverlay
    }()

    override var selected: Bool {
        didSet {
            self.selectedOverlay.hidden = !selected
        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        isAccessibilityElement = true
        accessibilityIdentifier = "TopSite"
        contentView.layer.cornerRadius = TopSiteCellUX.CellCornerRadius
        contentView.layer.masksToBounds = true

        let titleWrapper = UIView()
        titleWrapper.backgroundColor = TopSiteCellUX.TitleBackgroundColor
        titleWrapper.layer.masksToBounds = true
        contentView.addSubview(titleWrapper)

        contentView.addSubview(titleLabel)
        contentView.addSubview(imageView)
        contentView.addSubview(selectedOverlay)

        let titleHeight = Int(frame.height - (frame.height * TopSiteCellUX.TitleInsetPercent))
        titleLabel.snp_makeConstraints { make in
            make.left.equalTo(self).offset(TopSiteCellUX.TitleOffset)
            make.right.equalTo(self).offset(-TopSiteCellUX.TitleOffset)
            make.height.equalTo(titleHeight)
            make.bottom.equalTo(self)
        }

        imageView.snp_makeConstraints { make in
            make.size.equalTo(TopSiteCellUX.IconSize)
            // Add an offset to the image to make it appear centered with the titleLabel
            make.center.equalTo(self.snp_center).offset(UIEdgeInsets(top: -CGFloat(titleHeight)/2, left: 0, bottom: 0, right: 0))
        }

        selectedOverlay.snp_makeConstraints { make in
            make.edges.equalTo(contentView)
        }

        titleWrapper.snp_makeConstraints { make in
            make.left.right.bottom.equalTo(self)
            make.height.equalTo(titleHeight)
        }

    }

    override func updateConstraints() {
        let height = Int(frame.height - (frame.height * TopSiteCellUX.TitleInsetPercent))
        titleLabel.snp_updateConstraints { make in
            make.height.equalTo(height)
        }
        super.updateConstraints()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override func prepareForReuse() {
        super.prepareForReuse()
        contentView.backgroundColor = UIColor.lightGrayColor()<commit_msg>Bug 1302905 - Add a border to TopSiteCells and allow white backgrounds. (#2098) r=sleroux<commit_after>import Foundation
import Shared
import WebImage
import Storage

struct TopSiteCellUX {
    static let TitleHeight: CGFloat = 32
    static let TitleBackgroundColor = UIColor(colorLiteralRed: 1, green: 1, blue: 1, alpha: 0.7)
    static let TitleTextColor = UIColor.blackColor()
    static let TitleFont = DynamicFontHelper.defaultHelper.DefaultSmallFont
    static let SelectedOverlayColor = UIColor(white: 0.0, alpha: 0.25)
    static let CellCornerRadius: CGFloat = 4
    static let TitleOffset: CGFloat = 5
    static let OverlayColor = UIColor(white: 0.0, alpha: 0.25)
    static let IconSize = CGSize(width: 32, height: 32)
    static let BorderColor = UIColor(white: 0, alpha: 0.1)
    static let BorderWidth: CGFloat = 0.5
}

/*
 *  The TopSite cell that appears in the ASHorizontalScrollView.
 */
class TopSiteItemCell: UICollectionViewCell {

    lazy private var imageView: UIImageView = {
        let imageView = UIImageView()
        imageView.layer.masksToBounds = true
        return imageView
    }()

    lazy private var titleLabel: UILabel = {
        let titleLabel = UILabel()
        titleLabel.layer.masksToBounds = true
        titleLabel.textAlignment = .Center
        titleLabel.font = TopSiteCellUX.TitleFont
        titleLabel.textColor = TopSiteCellUX.TitleTextColor
        titleLabel.backgroundColor = UIColor.clearColor()
        return titleLabel
    }()

    lazy var selectedOverlay: UIView = {
        let selectedOverlay = UIView()
        selectedOverlay.backgroundColor = TopSiteCellUX.OverlayColor
        selectedOverlay.hidden = true
        return selectedOverlay
    }()

    lazy var titleBorder: CALayer = {
        let border = CALayer()
        border.backgroundColor = TopSiteCellUX.BorderColor.CGColor
        return border
    }()

    override var selected: Bool {
        didSet {
            self.selectedOverlay.hidden = !selected
        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        isAccessibilityElement = true
        accessibilityIdentifier = "TopSite"
        contentView.layer.cornerRadius = TopSiteCellUX.CellCornerRadius
        contentView.layer.masksToBounds = true

        contentView.layer.borderWidth = TopSiteCellUX.BorderWidth
        contentView.layer.borderColor = TopSiteCellUX.BorderColor.CGColor

        let titleWrapper = UIView()
        titleWrapper.backgroundColor = TopSiteCellUX.TitleBackgroundColor
        titleWrapper.layer.masksToBounds = true
        contentView.addSubview(titleWrapper)

        contentView.addSubview(titleLabel)
        contentView.addSubview(imageView)
        contentView.addSubview(selectedOverlay)

        titleLabel.snp_makeConstraints { make in
            make.left.equalTo(self).offset(TopSiteCellUX.TitleOffset)
            make.right.equalTo(self).offset(-TopSiteCellUX.TitleOffset)
            make.height.equalTo(TopSiteCellUX.TitleHeight)
            make.bottom.equalTo(self)
        }

        imageView.snp_makeConstraints { make in
            make.size.equalTo(TopSiteCellUX.IconSize)
            // Add an offset to the image to make it appear centered with the titleLabel
            make.center.equalTo(self.snp_center).offset(UIEdgeInsets(top: -TopSiteCellUX.TitleHeight/2, left: 0, bottom: 0, right: 0))
        }

        selectedOverlay.snp_makeConstraints { make in
            make.edges.equalTo(contentView)
        }

        titleWrapper.snp_makeConstraints { make in
            make.left.right.bottom.equalTo(self)
            make.height.equalTo(TopSiteCellUX.TitleHeight)
        }

        // The titleBorder must appear ABOVE the titleLabel. Meaning it must be 0.5 pixels above of the titleWrapper frame.
        titleBorder.frame = CGRectMake(0, CGRectGetHeight(self.frame) - TopSiteCellUX.TitleHeight -  TopSiteCellUX.BorderWidth, CGRectGetWidth(self.frame), TopSiteCellUX.BorderWidth)
        self.contentView.layer.addSublayer(titleBorder)

    }

    override func layoutSubviews() {
        super.layoutSubviews()
        titleBorder.frame = CGRectMake(0, frame.height - TopSiteCellUX.TitleHeight -  TopSiteCellUX.BorderWidth, frame.width, TopSiteCellUX.BorderWidth)
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override func prepareForReuse() {
        super.prepareForReuse()
        contentView.backgroundColor = UIColor.lightGrayColor()
{'fraction_non_alphanumeric': 0.07850940665701882, 'fraction_numerical': 0.009044862518089725, 'mean_word_length': 2.851834649326521, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3866593', 'n_tokens_mistral': 2403, 'n_tokens_neox': 2332, 'n_words': 511}