| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "ios/chrome/browser/ui/omnibox/omnibox_text_field_ios.h" | 5 #import "ios/chrome/browser/ui/omnibox/omnibox_text_field_ios.h" |
| 6 | 6 |
| 7 #import <CoreText/CoreText.h> | 7 #import <CoreText/CoreText.h> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 | 266 |
| 267 if ([NSLocale characterDirectionForLanguage:lang] == | 267 if ([NSLocale characterDirectionForLanguage:lang] == |
| 268 NSLocaleLanguageDirectionRightToLeft) { | 268 NSLocaleLanguageDirectionRightToLeft) { |
| 269 return NSTextAlignmentRight; | 269 return NSTextAlignmentRight; |
| 270 } | 270 } |
| 271 } | 271 } |
| 272 return NSTextAlignmentLeft; | 272 return NSTextAlignmentLeft; |
| 273 } | 273 } |
| 274 | 274 |
| 275 - (NSTextAlignment)bestTextAlignment { | 275 - (NSTextAlignment)bestTextAlignment { |
| 276 NSTextAlignment alignment; |
| 276 if ([self isFirstResponder]) { | 277 if ([self isFirstResponder]) { |
| 277 return [self bestAlignmentForText:[self text]]; | 278 alignment = [self bestAlignmentForText:[self text]]; |
| 279 } else { |
| 280 alignment = UseRTLLayout() ? NSTextAlignmentRight : NSTextAlignmentLeft; |
| 278 } | 281 } |
| 279 return NSTextAlignmentNatural; | 282 DCHECK(alignment == NSTextAlignmentLeft || alignment == NSTextAlignmentRight); |
| 283 return alignment; |
| 280 } | 284 } |
| 281 | 285 |
| 282 - (NSTextAlignment)preEditTextAlignment { | 286 - (NSTextAlignment)preEditTextAlignment { |
| 283 // If the pre-edit text is wider than the omnibox, right-align the text so it | 287 // If the pre-edit text is wider than the omnibox, right-align the text so it |
| 284 // ends at the same x coord as the blue selection box. | 288 // ends at the same x coord as the blue selection box. |
| 285 CGSize textSize = | 289 CGSize textSize = |
| 286 [_preEditStaticLabel.text cr_pixelAlignedSizeWithFont:_font]; | 290 [_preEditStaticLabel.text cr_pixelAlignedSizeWithFont:_font]; |
| 287 BOOL isLTR = [self bestTextAlignment] == NSTextAlignmentLeft; | 291 BOOL isLTR = [self bestTextAlignment] == NSTextAlignmentLeft; |
| 288 return textSize.width < _preEditStaticLabel.frame.size.width | 292 return textSize.width < _preEditStaticLabel.frame.size.width |
| 289 ? (isLTR ? NSTextAlignmentLeft : NSTextAlignmentRight) | 293 ? (isLTR ? NSTextAlignmentLeft : NSTextAlignmentRight) |
| (...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1034 // Disable the RTL arrow menu item. The omnibox sets alignment based on the | 1038 // Disable the RTL arrow menu item. The omnibox sets alignment based on the |
| 1035 // text in the field, and should not be overridden. | 1039 // text in the field, and should not be overridden. |
| 1036 if ([NSStringFromSelector(action) hasPrefix:@"makeTextWritingDirection"]) { | 1040 if ([NSStringFromSelector(action) hasPrefix:@"makeTextWritingDirection"]) { |
| 1037 return NO; | 1041 return NO; |
| 1038 } | 1042 } |
| 1039 | 1043 |
| 1040 return [super canPerformAction:action withSender:sender]; | 1044 return [super canPerformAction:action withSender:sender]; |
| 1041 } | 1045 } |
| 1042 | 1046 |
| 1043 @end | 1047 @end |
| OLD | NEW |