| 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/ios/ios_util.h" | 10 #include "base/ios/ios_util.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/mac/foundation_util.h" | 12 #include "base/mac/foundation_util.h" |
| 13 | 13 |
| 14 #include "base/strings/sys_string_conversions.h" | 14 #include "base/strings/sys_string_conversions.h" |
| 15 #include "components/grit/components_scaled_resources.h" | 15 #include "components/grit/components_scaled_resources.h" |
| 16 #include "components/omnibox/browser/autocomplete_input.h" | 16 #include "components/omnibox/browser/autocomplete_input.h" |
| 17 #include "ios/chrome/browser/application_context.h" |
| 17 #include "ios/chrome/browser/autocomplete/autocomplete_scheme_classifier_impl.h" | 18 #include "ios/chrome/browser/autocomplete/autocomplete_scheme_classifier_impl.h" |
| 19 #include "ios/chrome/browser/experimental_flags.h" |
| 18 #import "ios/chrome/browser/ui/animation_util.h" | 20 #import "ios/chrome/browser/ui/animation_util.h" |
| 19 #include "ios/chrome/browser/ui/omnibox/omnibox_util.h" | 21 #include "ios/chrome/browser/ui/omnibox/omnibox_util.h" |
| 20 #import "ios/chrome/browser/ui/reversed_animation.h" | 22 #import "ios/chrome/browser/ui/reversed_animation.h" |
| 21 #include "ios/chrome/browser/ui/rtl_geometry.h" | 23 #include "ios/chrome/browser/ui/rtl_geometry.h" |
| 22 #include "ios/chrome/browser/ui/ui_util.h" | 24 #include "ios/chrome/browser/ui/ui_util.h" |
| 23 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 25 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
| 24 #import "ios/chrome/common/material_timing.h" | 26 #import "ios/chrome/common/material_timing.h" |
| 25 #include "ios/chrome/grit/ios_strings.h" | 27 #include "ios/chrome/grit/ios_strings.h" |
| 26 #include "ios/chrome/grit/ios_theme_resources.h" | 28 #include "ios/chrome/grit/ios_theme_resources.h" |
| 27 #include "skia/ext/skia_utils_ios.h" | 29 #include "skia/ext/skia_utils_ios.h" |
| (...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 [autocompleteText | 453 [autocompleteText |
| 452 addAttribute:NSBackgroundColorAttributeName | 454 addAttribute:NSBackgroundColorAttributeName |
| 453 value:[self selectedTextBackgroundColor] | 455 value:[self selectedTextBackgroundColor] |
| 454 range:NSMakeRange([fieldText length], autocompleteLength)]; | 456 range:NSMakeRange([fieldText length], autocompleteLength)]; |
| 455 [_selection setAttributedText:autocompleteText]; | 457 [_selection setAttributedText:autocompleteText]; |
| 456 [_selection setTextAlignment:[self bestTextAlignment]]; | 458 [_selection setTextAlignment:[self bestTextAlignment]]; |
| 457 } else { | 459 } else { |
| 458 [self clearAutocompleteText]; | 460 [self clearAutocompleteText]; |
| 459 } | 461 } |
| 460 | 462 |
| 461 self.attributedText = fieldText; | 463 // The following BOOL was introduced to workaround a UIKit bug |
| 464 // (crbug.com/737589, rdar/32817402). The bug relates to third party keyboards |
| 465 // that check the value of textDocumentProxy.documentContextBeforeInput to |
| 466 // show keyboard suggestions. It appears that calling setAttributedText during |
| 467 // an EditingChanged UIControlEvent somehow triggers this bug. The reason we |
| 468 // update the attributed text here is to change the colors of the omnibox |
| 469 // (such as host, protocol) when !self.editing, but also to hide real |
| 470 // UITextField text under the _selection text when self.editing. Since we will |
| 471 // correct the omnibox editing text color anytime |self.text| is different |
| 472 // than |fieldText|, it seems it's OK to skip calling self.attributedText |
| 473 // during the condition added below. If we change mobile omnibox to match |
| 474 // desktop and also color the omnibox while self.editing, this workaround will |
| 475 // no longer work. |
| 476 BOOL updateText = YES; |
| 477 // Before M61 branch point this should also go behind a Japanese flag, e.g. |
| 478 // [self.textInputMode.primaryLanguage isEqualToString:@"ja-JP"] to be as |
| 479 // restrictive as possible. |
| 480 if (experimental_flags::IsThirdPartyKeyboardWorkaroundEnabled()) { |
| 481 updateText = |
| 482 (!self.editing || ![self.text isEqualToString:fieldText.string]); |
| 483 } |
| 484 if (updateText) { |
| 485 self.attributedText = fieldText; |
| 486 } |
| 462 | 487 |
| 463 // iOS changes the font to .LastResort when some unexpected unicode strings | 488 // iOS changes the font to .LastResort when some unexpected unicode strings |
| 464 // are used (e.g. 𝗲𝗺𝗽𝗵𝗮𝘀𝗶𝘀). Setting the NSFontAttributeName in the | 489 // are used (e.g. 𝗲𝗺𝗽𝗵𝗮𝘀𝗶𝘀). Setting the NSFontAttributeName in the |
| 465 // attributed string to -systemFontOfSize fixes part of the problem, but the | 490 // attributed string to -systemFontOfSize fixes part of the problem, but the |
| 466 // baseline changes so text is out of alignment. | 491 // baseline changes so text is out of alignment. |
| 467 [self setFont:_font]; | 492 [self setFont:_font]; |
| 468 // TODO(justincohen): Find a better place to put this, and consolidate it with | 493 // TODO(justincohen): Find a better place to put this, and consolidate it with |
| 469 // the same call in omniboxViewIOS. | 494 // the same call in omniboxViewIOS. |
| 470 [self updateTextDirection]; | 495 [self updateTextDirection]; |
| 471 } | 496 } |
| (...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 937 // Disable the RTL arrow menu item. The omnibox sets alignment based on the | 962 // Disable the RTL arrow menu item. The omnibox sets alignment based on the |
| 938 // text in the field, and should not be overridden. | 963 // text in the field, and should not be overridden. |
| 939 if ([NSStringFromSelector(action) hasPrefix:@"makeTextWritingDirection"]) { | 964 if ([NSStringFromSelector(action) hasPrefix:@"makeTextWritingDirection"]) { |
| 940 return NO; | 965 return NO; |
| 941 } | 966 } |
| 942 | 967 |
| 943 return [super canPerformAction:action withSender:sender]; | 968 return [super canPerformAction:action withSender:sender]; |
| 944 } | 969 } |
| 945 | 970 |
| 946 @end | 971 @end |
| OLD | NEW |