Chromium Code Reviews| 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 (://32817402). |
|
rohitrao (ping after 24h)
2017/06/28 16:48:23
Is this a b/ url? Should we also link to the rada
rohitrao (ping after 24h)
2017/06/28 16:48:23
BOOL
justincohen
2017/06/28 21:38:06
Done.
justincohen
2017/06/28 21:38:06
The crbug url links to the b/ urls.
| |
| 464 // The bug relates to third party keyboards that check the value of | |
| 465 // textDocumentProxy.documentContextBeforeInput to show keyboard suggestions. | |
| 466 // It appears that calling setAttributedText during an EditingChanged | |
| 467 // UIControlEvent somehow triggers this bug. The reason we update the | |
| 468 // attributed text here is to change the colors of the omnibox (such as host, | |
| 469 // protocol) when !self.exiting, but also to hide real UITextField text under | |
|
rohitrao (ping after 24h)
2017/06/28 16:48:23
!self.editing.
Also in the CL description.
justincohen
2017/06/28 21:38:06
Done.
| |
| 470 // the _selection text when self.editing. Since we will correct the omnibox | |
| 471 // editing text color anytime |self.text| is different than |fieldText|, it | |
| 472 // seems it's OK to skip calling self.attributedText during the condition | |
| 473 // added below. If we change mobile omnibox to match desktop and also color | |
| 474 // the omnibox while self.editing, this workaround will no longer work. | |
| 475 BOOL updateText = YES; | |
| 476 // Before M61 branch point this should also go behind a Japanese flag, e.g. | |
| 477 // [self.textInputMode.primaryLanguage isEqualToString:@"ja-JP"] to be as | |
| 478 // restrictive as possible. | |
| 479 if (experimental_flags::IsThirdPartyKeyboardWorkaroundEnabled()) { | |
|
rohitrao (ping after 24h)
2017/06/28 16:48:23
Is this an expensive call? How about calling it o
justincohen
2017/06/28 21:38:06
It's fast, we call base::FeatureList::IsEnabled a
| |
| 480 updateText = | |
| 481 (!self.editing || ![self.text isEqualToString:fieldText.string]); | |
| 482 } | |
| 483 if (updateText) { | |
| 484 self.attributedText = fieldText; | |
| 485 } | |
| 462 | 486 |
| 463 // iOS changes the font to .LastResort when some unexpected unicode strings | 487 // iOS changes the font to .LastResort when some unexpected unicode strings |
| 464 // are used (e.g. 𝗲𝗺𝗽𝗵𝗮𝘀𝗶𝘀). Setting the NSFontAttributeName in the | 488 // are used (e.g. 𝗲𝗺𝗽𝗵𝗮𝘀𝗶𝘀). Setting the NSFontAttributeName in the |
| 465 // attributed string to -systemFontOfSize fixes part of the problem, but the | 489 // attributed string to -systemFontOfSize fixes part of the problem, but the |
| 466 // baseline changes so text is out of alignment. | 490 // baseline changes so text is out of alignment. |
| 467 [self setFont:_font]; | 491 [self setFont:_font]; |
| 468 // TODO(justincohen): Find a better place to put this, and consolidate it with | 492 // TODO(justincohen): Find a better place to put this, and consolidate it with |
| 469 // the same call in omniboxViewIOS. | 493 // the same call in omniboxViewIOS. |
| 470 [self updateTextDirection]; | 494 [self updateTextDirection]; |
| 471 } | 495 } |
| (...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 | 961 // Disable the RTL arrow menu item. The omnibox sets alignment based on the |
| 938 // text in the field, and should not be overridden. | 962 // text in the field, and should not be overridden. |
| 939 if ([NSStringFromSelector(action) hasPrefix:@"makeTextWritingDirection"]) { | 963 if ([NSStringFromSelector(action) hasPrefix:@"makeTextWritingDirection"]) { |
| 940 return NO; | 964 return NO; |
| 941 } | 965 } |
| 942 | 966 |
| 943 return [super canPerformAction:action withSender:sender]; | 967 return [super canPerformAction:action withSender:sender]; |
| 944 } | 968 } |
| 945 | 969 |
| 946 @end | 970 @end |
| OLD | NEW |