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

Unified Diff: chrome/browser/ui/cocoa/omnibox/omnibox_popup_cell.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: Respond to feedback. 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
« no previous file with comments | « no previous file | chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/cocoa/omnibox/omnibox_popup_cell.mm
diff --git a/chrome/browser/ui/cocoa/omnibox/omnibox_popup_cell.mm b/chrome/browser/ui/cocoa/omnibox/omnibox_popup_cell.mm
index 693ef769066bf8a0d1a04a57c0c23069142b8bb1..5098dc026bec635c6cc00cc4021dcb1cc58a2d66 100644
--- a/chrome/browser/ui/cocoa/omnibox/omnibox_popup_cell.mm
+++ b/chrome/browser/ui/cocoa/omnibox/omnibox_popup_cell.mm
@@ -152,6 +152,19 @@ NSFont* SmallFont() {
return OmniboxViewMac::GetSmallFont();
}
+// Sets the writing direction to |direction| for a given |range| of
+// |attributedString|.
+void SetTextDirectionForRange(NSMutableAttributedString* attributedString,
+ NSWritingDirection direction,
+ NSRange range) {
+ base::scoped_nsobject<NSMutableParagraphStyle> paragraph_style(
+ [[NSMutableParagraphStyle alloc] init]);
+ [paragraph_style setBaseWritingDirection:direction];
+ [attributedString addAttribute:NSParagraphStyleAttributeName
+ value:paragraph_style
+ range:range];
+}
+
NSAttributedString* CreateAnswerStringHelper(const base::string16& text,
NSInteger style_type,
bool is_bold,
@@ -363,6 +376,10 @@ NSAttributedString* CreateClassifiedAttributedString(
}
if (0 != (i->style & ACMatchClassification::URL)) {
+ // URLs have their text direction set to to LTR (avoids RTL characters
+ // making the URL render from right to left, as per RFC 3987 Section 4.1).
+ SetTextDirectionForRange(attributedString, NSWritingDirectionLeftToRight,
+ range);
[attributedString addAttribute:NSForegroundColorAttributeName
value:URLTextColor(is_dark_theme)
range:range];
« no previous file with comments | « no previous file | chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698