| 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 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 return [self bestAlignmentForText:[self text]]; | 277 return [self bestAlignmentForText:[self text]]; |
| 278 } | 278 } |
| 279 return NSTextAlignmentNatural; | 279 return NSTextAlignmentNatural; |
| 280 } | 280 } |
| 281 | 281 |
| 282 - (NSTextAlignment)preEditTextAlignment { | 282 - (NSTextAlignment)preEditTextAlignment { |
| 283 // If the pre-edit text is wider than the omnibox, right-align the text so it | 283 // 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. | 284 // ends at the same x coord as the blue selection box. |
| 285 CGSize textSize = | 285 CGSize textSize = |
| 286 [_preEditStaticLabel.text cr_pixelAlignedSizeWithFont:_font]; | 286 [_preEditStaticLabel.text cr_pixelAlignedSizeWithFont:_font]; |
| 287 BOOL isLTR = [self bestTextAlignment] == NSTextAlignmentLeft; | 287 // Note, this does not need to support RTL, as URLs are always LTR. |
| 288 return textSize.width < _preEditStaticLabel.frame.size.width | 288 return textSize.width < _preEditStaticLabel.frame.size.width |
| 289 ? (isLTR ? NSTextAlignmentLeft : NSTextAlignmentRight) | 289 ? NSTextAlignmentLeft |
| 290 : (isLTR ? NSTextAlignmentRight : NSTextAlignmentLeft); | 290 : NSTextAlignmentRight; |
| 291 } | 291 } |
| 292 | 292 |
| 293 - (void)layoutSubviews { | 293 - (void)layoutSubviews { |
| 294 [super layoutSubviews]; | 294 [super layoutSubviews]; |
| 295 if ([self isPreEditing]) { | 295 if ([self isPreEditing]) { |
| 296 CGRect rect = [self preEditLabelRectForBounds:self.bounds]; | 296 CGRect rect = [self preEditLabelRectForBounds:self.bounds]; |
| 297 [_preEditStaticLabel setFrame:rect]; | 297 [_preEditStaticLabel setFrame:rect]; |
| 298 | 298 |
| 299 // Update text alignment since the pre-edit label's frame changed. | 299 // Update text alignment since the pre-edit label's frame changed. |
| 300 _preEditStaticLabel.textAlignment = [self preEditTextAlignment]; | 300 _preEditStaticLabel.textAlignment = [self preEditTextAlignment]; |
| (...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1015 // Disable the RTL arrow menu item. The omnibox sets alignment based on the | 1015 // Disable the RTL arrow menu item. The omnibox sets alignment based on the |
| 1016 // text in the field, and should not be overridden. | 1016 // text in the field, and should not be overridden. |
| 1017 if ([NSStringFromSelector(action) hasPrefix:@"makeTextWritingDirection"]) { | 1017 if ([NSStringFromSelector(action) hasPrefix:@"makeTextWritingDirection"]) { |
| 1018 return NO; | 1018 return NO; |
| 1019 } | 1019 } |
| 1020 | 1020 |
| 1021 return [super canPerformAction:action withSender:sender]; | 1021 return [super canPerformAction:action withSender:sender]; |
| 1022 } | 1022 } |
| 1023 | 1023 |
| 1024 @end | 1024 @end |
| OLD | NEW |