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 #include "ios/chrome/browser/ui/omnibox/omnibox_view_ios.h" | 5 #include "ios/chrome/browser/ui/omnibox/omnibox_view_ios.h" |
6 | 6 |
7 #import <CoreText/CoreText.h> | 7 #import <CoreText/CoreText.h> |
8 #import <MobileCoreServices/MobileCoreServices.h> | 8 #import <MobileCoreServices/MobileCoreServices.h> |
9 | 9 |
10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/ios/device_util.h" | 12 #include "base/ios/device_util.h" |
| 13 #include "base/ios/ios_util.h" |
13 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
14 #include "base/metrics/user_metrics.h" | 15 #include "base/metrics/user_metrics.h" |
15 #include "base/metrics/user_metrics_action.h" | 16 #include "base/metrics/user_metrics_action.h" |
16 #include "base/strings/string16.h" | 17 #include "base/strings/string16.h" |
17 #include "base/strings/sys_string_conversions.h" | 18 #include "base/strings/sys_string_conversions.h" |
18 #include "components/omnibox/browser/autocomplete_input.h" | 19 #include "components/omnibox/browser/autocomplete_input.h" |
19 #include "components/omnibox/browser/autocomplete_match.h" | 20 #include "components/omnibox/browser/autocomplete_match.h" |
20 #include "components/omnibox/browser/omnibox_edit_model.h" | 21 #include "components/omnibox/browser/omnibox_edit_model.h" |
21 #include "components/omnibox/browser/omnibox_popup_model.h" | 22 #include "components/omnibox/browser/omnibox_popup_model.h" |
22 #include "components/toolbar/toolbar_model.h" | 23 #include "components/toolbar/toolbar_model.h" |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 ignore_popup_updates_(false), | 174 ignore_popup_updates_(false), |
174 attributing_display_string_(nil) { | 175 attributing_display_string_(nil) { |
175 DCHECK(field_); | 176 DCHECK(field_); |
176 popup_view_.reset(new OmniboxPopupViewIOS(this, model(), positioner)); | 177 popup_view_.reset(new OmniboxPopupViewIOS(this, model(), positioner)); |
177 field_delegate_.reset( | 178 field_delegate_.reset( |
178 [[AutocompleteTextFieldDelegate alloc] initWithEditView:this]); | 179 [[AutocompleteTextFieldDelegate alloc] initWithEditView:this]); |
179 [field_ setDelegate:field_delegate_]; | 180 [field_ setDelegate:field_delegate_]; |
180 [field_ addTarget:field_delegate_ | 181 [field_ addTarget:field_delegate_ |
181 action:@selector(textFieldDidChange:) | 182 action:@selector(textFieldDidChange:) |
182 forControlEvents:UIControlEventEditingChanged]; | 183 forControlEvents:UIControlEventEditingChanged]; |
| 184 use_strikethrough_workaround_ = base::ios::IsRunningOnOrLater(10, 3, 0); |
183 } | 185 } |
184 | 186 |
185 OmniboxViewIOS::~OmniboxViewIOS() { | 187 OmniboxViewIOS::~OmniboxViewIOS() { |
186 // |field_| outlives this object. | 188 // |field_| outlives this object. |
187 [field_ setDelegate:nil]; | 189 [field_ setDelegate:nil]; |
188 | 190 |
189 [field_ removeTarget:field_delegate_ | 191 [field_ removeTarget:field_delegate_ |
190 action:@selector(textFieldDidChange:) | 192 action:@selector(textFieldDidChange:) |
191 forControlEvents:UIControlEventEditingChanged]; | 193 forControlEvents:UIControlEventEditingChanged]; |
192 | 194 |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
639 | 641 |
640 if ((security_level == security_state::NONE) || | 642 if ((security_level == security_state::NONE) || |
641 (security_level == security_state::HTTP_SHOW_WARNING)) { | 643 (security_level == security_state::HTTP_SHOW_WARNING)) { |
642 return; | 644 return; |
643 } | 645 } |
644 | 646 |
645 DCHECK_NE(security_state::SECURITY_WARNING, security_level); | 647 DCHECK_NE(security_state::SECURITY_WARNING, security_level); |
646 DCHECK_NE(security_state::SECURE_WITH_POLICY_INSTALLED_CERT, security_level); | 648 DCHECK_NE(security_state::SECURE_WITH_POLICY_INSTALLED_CERT, security_level); |
647 | 649 |
648 if (security_level == security_state::DANGEROUS) { | 650 if (security_level == security_state::DANGEROUS) { |
| 651 if (use_strikethrough_workaround_) { |
| 652 // Workaround: Add extra attribute to allow strikethough to apply on iOS |
| 653 // 10.3+. See https://crbug.com/699702 for discussion. |
| 654 [attributing_display_string_ |
| 655 addAttribute:NSBaselineOffsetAttributeName |
| 656 value:@0 |
| 657 range:NSMakeRange(0, [attributing_display_string_ length])]; |
| 658 } |
| 659 |
649 // Add a strikethrough through the scheme. | 660 // Add a strikethrough through the scheme. |
650 [attributing_display_string_ | 661 [attributing_display_string_ |
651 addAttribute:NSStrikethroughStyleAttributeName | 662 addAttribute:NSStrikethroughStyleAttributeName |
652 value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] | 663 value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] |
653 range:range.ToNSRange()]; | 664 range:range.ToNSRange()]; |
654 } | 665 } |
655 | 666 |
656 UIColor* color = GetSecureTextColor(security_level, [field_ incognito]); | 667 UIColor* color = GetSecureTextColor(security_level, [field_ incognito]); |
657 if (color) { | 668 if (color) { |
658 [attributing_display_string_ addAttribute:NSForegroundColorAttributeName | 669 [attributing_display_string_ addAttribute:NSForegroundColorAttributeName |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
844 // is being left out for now because it was not present before the OmniboxView | 855 // is being left out for now because it was not present before the OmniboxView |
845 // rewrite. | 856 // rewrite. |
846 #if 0 | 857 #if 0 |
847 // When editing is in progress, the url text is not colored, so there is | 858 // When editing is in progress, the url text is not colored, so there is |
848 // nothing to emphasize. (Calling SetText() in that situation would also be | 859 // nothing to emphasize. (Calling SetText() in that situation would also be |
849 // harmful, as it would reset the carat position to the end of the text.) | 860 // harmful, as it would reset the carat position to the end of the text.) |
850 if (!IsEditingOrEmpty()) | 861 if (!IsEditingOrEmpty()) |
851 SetText(GetText()); | 862 SetText(GetText()); |
852 #endif | 863 #endif |
853 } | 864 } |
OLD | NEW |