Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(401)

Unified Diff: chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm

Issue 2126023003: Mac (Cocoa) Omnibox: Force text field to LTR context if it is a URL. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Formatting. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm
diff --git a/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm b/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm
index 06eb963f144210240db6fe9dcd0501a312335f49..0e45c3cd6c1f5a66f9008fe3bae0cfdedf9e7cb1 100644
--- a/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm
+++ b/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm
@@ -549,6 +549,7 @@ void OmniboxViewMac::EmphasizeURLComponents() {
}
void OmniboxViewMac::ApplyTextStyle(
+ bool force_ltr,
NSMutableAttributedString* attributedString) {
[attributedString addAttribute:NSFontAttributeName
value:GetNormalFieldFont()
@@ -562,6 +563,8 @@ void OmniboxViewMac::ApplyTextStyle(
[paragraph_style setMaximumLineHeight:line_height];
[paragraph_style setMinimumLineHeight:line_height];
[paragraph_style setLineBreakMode:NSLineBreakByTruncatingTail];
+ if (force_ltr)
tapted 2016/07/21 04:37:05 optional: I'd probably just use model()->CurrentTe
Matt Giuca 2016/07/21 04:55:37 Done.
+ [paragraph_style setBaseWritingDirection:NSWritingDirectionLeftToRight];
[attributedString addAttribute:NSParagraphStyleAttributeName
value:paragraph_style
range:NSMakeRange(0, [attributedString length])];
@@ -576,8 +579,12 @@ void OmniboxViewMac::ApplyTextAttributes(
}
NSRange as_entire_string = NSMakeRange(0, as_length);
bool in_dark_mode = [[field_ window] inIncognitoModeWithSystemTheme];
+ // If this is a URL, set the top-level paragraph direction to LTR (avoids RTL
+ // characters from making the URL render from right to left, as per RFC 3987
+ // Section 4.1).
+ bool force_ltr = model()->CurrentTextIsURL();
- ApplyTextStyle(attributedString);
+ ApplyTextStyle(force_ltr, attributedString);
// A kinda hacky way to add breaking at periods. This is what Safari does.
// This works for IDNs too, despite the "en_US".

Powered by Google App Engine
This is Rietveld 408576698