Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Fix #6190: Make URL origin-only/leading truncated until edited
Browse files Browse the repository at this point in the history
This change matches Chrome iOS and Safari where the full URL is not displayed
  • Loading branch information
kylehickinson committed Nov 18, 2022
1 parent 95f5e5c commit 3aa153e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 60 deletions.
28 changes: 9 additions & 19 deletions Client/Frontend/Browser/Toolbars/UrlBar/TabLocationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ class TabLocationView: UIView {
urlTextField.clipsToBounds = true
urlTextField.textColor = .braveLabel
urlTextField.isEnabled = false
urlTextField.defaultTextAttributes[.paragraphStyle] = {
let paragraphStyle = (urlTextField
.defaultTextAttributes[.paragraphStyle, default: NSParagraphStyle.default] as! NSParagraphStyle)
.mutableCopy() as! NSMutableParagraphStyle
paragraphStyle.alignment = .center
paragraphStyle.lineBreakMode = .byTruncatingHead
return paragraphStyle
}()
// Remove the default drop interaction from the URL text field so that our
// custom drop interaction on the BVC can accept dropped URLs.
if let dropInteraction = urlTextField.textDropInteraction {
Expand Down Expand Up @@ -406,8 +414,7 @@ class TabLocationView: UIView {
}

fileprivate func updateTextWithURL() {
(urlTextField as? DisplayTextField)?.hostString = url?.withoutWWW.host ?? ""
urlTextField.text = url?.withoutWWW.schemelessAbsoluteString.trim("/")
urlTextField.text = url?.origin.url?.schemelessAbsoluteDisplayString
}
}

Expand Down Expand Up @@ -474,8 +481,6 @@ extension TabLocationView {

class DisplayTextField: UITextField {
weak var accessibilityActionsSource: AccessibilityActionsSource?
var hostString: String = ""
let pathPadding: CGFloat = 5.0

override var accessibilityCustomActions: [UIAccessibilityCustomAction]? {
get {
Expand All @@ -494,21 +499,6 @@ class DisplayTextField: UITextField {
override var canBecomeFirstResponder: Bool {
return false
}

// This override is done in case the eTLD+1 string overflows the width of textField.
// In that case the textRect is adjusted to show right aligned and truncate left.
// Since this textField changes with WebView domain change, performance implications are low.
override func textRect(forBounds bounds: CGRect) -> CGRect {
var rect: CGRect = super.textRect(forBounds: bounds)

if let size: CGSize = (self.hostString as NSString?)?.size(withAttributes: [.font: self.font!]) {
if size.width > self.bounds.width {
rect.origin.x = rect.origin.x - (size.width + pathPadding - self.bounds.width)
rect.size.width = size.width + pathPadding
}
}
return rect
}
}

private class CustomSeparatorView: UIView {
Expand Down
41 changes: 0 additions & 41 deletions Tests/ClientTests/DisplayTextFieldTest.swift

This file was deleted.

0 comments on commit 3aa153e

Please sign in to comment.