OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import "ios/chrome/browser/ui/find_bar/find_bar_text_field.h" |
| 6 |
| 7 #include "base/i18n/rtl.h" |
| 8 #import "ios/chrome/browser/find_in_page/find_in_page_controller.h" |
| 9 #include "ios/chrome/grit/ios_strings.h" |
| 10 #include "ui/base/l10n/l10n_util_mac.h" |
| 11 |
| 12 namespace { |
| 13 // Find bar left padding |
| 14 const CGFloat kFindBarLeftPadding = 16; |
| 15 } // anonymous namespace |
| 16 |
| 17 @implementation FindBarTextField |
| 18 |
| 19 @synthesize overlayWidth = _overlayWidth; |
| 20 |
| 21 #pragma mark - UIView |
| 22 |
| 23 - (instancetype)initWithFrame:(CGRect)frame { |
| 24 self = [super initWithFrame:frame]; |
| 25 if (self) { |
| 26 self.textAlignment = NSTextAlignmentNatural; |
| 27 self.accessibilityLabel = |
| 28 l10n_util::GetNSStringWithFixup(IDS_IOS_PLACEHOLDER_FIND_IN_PAGE); |
| 29 } |
| 30 return self; |
| 31 } |
| 32 |
| 33 #pragma mark - Public methods |
| 34 |
| 35 - (void)setOverlayWidth:(CGFloat)overlayWidth { |
| 36 _overlayWidth = overlayWidth; |
| 37 [self setNeedsLayout]; |
| 38 } |
| 39 |
| 40 #pragma mark - UITextField |
| 41 |
| 42 - (CGRect)textRectForBounds:(CGRect)bounds { |
| 43 return [self editingRectForBounds:bounds]; |
| 44 } |
| 45 |
| 46 - (CGRect)editingRectForBounds:(CGRect)bounds { |
| 47 // Reduce the width by the width of the overlay + padding for both sides of |
| 48 // the text. |
| 49 bounds.size.width -= _overlayWidth + 2 * kFindBarLeftPadding; |
| 50 bounds.origin.x += kFindBarLeftPadding; |
| 51 |
| 52 // Shift the text to the right side of the overlay for RTL languages. |
| 53 if (base::i18n::IsRTL()) |
| 54 bounds.origin.x += _overlayWidth; |
| 55 return bounds; |
| 56 } |
| 57 |
| 58 @end |
OLD | NEW |