| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" | 5 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #import "base/mac/mac_util.h" | 8 #import "base/mac/mac_util.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "base/strings/sys_string_conversions.h" | 12 #include "base/strings/sys_string_conversions.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
| 15 #include "chrome/app/chrome_command_ids.h" | 15 #include "chrome/app/chrome_command_ids.h" |
| 16 #import "chrome/browser/app_controller_mac.h" | 16 #import "chrome/browser/app_controller_mac.h" |
| 17 #include "chrome/browser/command_updater.h" | 17 #include "chrome/browser/command_updater.h" |
| 18 #include "chrome/browser/defaults.h" | 18 #include "chrome/browser/defaults.h" |
| 19 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" | 19 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/search_engines/template_url_service_factory.h" | 21 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 22 #include "chrome/browser/translate/chrome_translate_client.h" | 22 #include "chrome/browser/translate/chrome_translate_client.h" |
| 23 #include "chrome/browser/translate/translate_service.h" | 23 #include "chrome/browser/translate/translate_service.h" |
| 24 #include "chrome/browser/ui/autofill/save_card_bubble_controller_impl.h" | 24 #include "chrome/browser/ui/autofill/save_card_bubble_controller_impl.h" |
| 25 #include "chrome/browser/ui/browser_list.h" | 25 #include "chrome/browser/ui/browser_list.h" |
| 26 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 26 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 27 #import "chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa.h
" | 27 #import "chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa.h
" |
| 28 #import "chrome/browser/ui/cocoa/first_run_bubble_controller.h" | 28 #import "chrome/browser/ui/cocoa/first_run_bubble_controller.h" |
| 29 #import "chrome/browser/ui/cocoa/info_bubble_view.h" | 29 #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
| 30 #import "chrome/browser/ui/cocoa/l10n_util.h" |
| 30 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h" | 31 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h" |
| 31 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h" | 32 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h" |
| 32 #import "chrome/browser/ui/cocoa/location_bar/content_setting_decoration.h" | 33 #import "chrome/browser/ui/cocoa/location_bar/content_setting_decoration.h" |
| 33 #import "chrome/browser/ui/cocoa/location_bar/keyword_hint_decoration.h" | 34 #import "chrome/browser/ui/cocoa/location_bar/keyword_hint_decoration.h" |
| 34 #import "chrome/browser/ui/cocoa/location_bar/location_icon_decoration.h" | 35 #import "chrome/browser/ui/cocoa/location_bar/location_icon_decoration.h" |
| 35 #import "chrome/browser/ui/cocoa/location_bar/manage_passwords_decoration.h" | 36 #import "chrome/browser/ui/cocoa/location_bar/manage_passwords_decoration.h" |
| 36 #import "chrome/browser/ui/cocoa/location_bar/save_credit_card_decoration.h" | 37 #import "chrome/browser/ui/cocoa/location_bar/save_credit_card_decoration.h" |
| 37 #import "chrome/browser/ui/cocoa/location_bar/security_state_bubble_decoration.h
" | 38 #import "chrome/browser/ui/cocoa/location_bar/security_state_bubble_decoration.h
" |
| 38 #import "chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.h" | 39 #import "chrome/browser/ui/cocoa/location_bar/selected_keyword_decoration.h" |
| 39 #import "chrome/browser/ui/cocoa/location_bar/star_decoration.h" | 40 #import "chrome/browser/ui/cocoa/location_bar/star_decoration.h" |
| (...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 735 bool LocationBarViewMac::IsSecureConnection( | 736 bool LocationBarViewMac::IsSecureConnection( |
| 736 security_state::SecurityLevel level) const { | 737 security_state::SecurityLevel level) const { |
| 737 return level == security_state::SECURE || | 738 return level == security_state::SECURE || |
| 738 level == security_state::EV_SECURE; | 739 level == security_state::EV_SECURE; |
| 739 } | 740 } |
| 740 | 741 |
| 741 void LocationBarViewMac::UpdateAccessibilityView( | 742 void LocationBarViewMac::UpdateAccessibilityView( |
| 742 LocationBarDecoration* decoration) { | 743 LocationBarDecoration* decoration) { |
| 743 if (!decoration->IsVisible()) | 744 if (!decoration->IsVisible()) |
| 744 return; | 745 return; |
| 746 // This uses |frame| instead of |bounds| because the accessibility views are |
| 747 // parented to the toolbar. |
| 745 NSRect apparent_frame = | 748 NSRect apparent_frame = |
| 746 [[field_ cell] frameForDecoration:decoration inFrame:[field_ frame]]; | 749 [[field_ cell] frameForDecoration:decoration inFrame:[field_ frame]]; |
| 747 | 750 |
| 748 // This is a bit subtle: | 751 // This is a bit subtle: |
| 749 // The decorations' accessibility views can become key to allow keyboard | 752 // The decorations' accessibility views can become key to allow keyboard |
| 750 // access to the location bar decorations, but Cocoa's automatic key view loop | 753 // access to the location bar decorations, but Cocoa's automatic key view loop |
| 751 // sorts by top-left coordinate. Since the omnibox's top-left coordinate is | 754 // sorts by top-left coordinate. Since the omnibox's top-left coordinate is |
| 752 // before its leading decorations, the omnibox would sort before its own | 755 // before its leading decorations, the omnibox would sort before its own |
| 753 // leading decorations, which was logical but visually unintuitive. Therefore, | 756 // leading decorations, which was logical but visually unintuitive. Therefore, |
| 754 // for leading decorations, this method moves their frame to be "just before" | 757 // for leading decorations, this method moves their frame to be "just before" |
| 755 // the omnibox in automatic key view loop order, and gives them an apparent | 758 // the omnibox in automatic key view loop order, and gives them an apparent |
| 756 // frame (see DecorationAccessibilityView) so that they still paint their | 759 // frame (see DecorationAccessibilityView) so that they still paint their |
| 757 // focus rings at the right place. | 760 // focus rings at the right place. |
| 758 // | 761 // |
| 759 // TODO(lgrey): This hack doesn't work in RTL layouts, but the layout of the | 762 // TODO(lgrey): This hack doesn't work in RTL layouts, but the layout of the |
| 760 // omnibox is currently screwed up in RTL layouts anyway. See | 763 // omnibox is currently screwed up in RTL layouts anyway. See |
| 761 // https://crbug.com/715627. | 764 // https://crbug.com/715627. |
| 762 NSRect real_frame = apparent_frame; | 765 NSRect real_frame = apparent_frame; |
| 763 int left_index = [[field_ cell] leadingDecorationIndex:decoration]; | 766 int left_index = [[field_ cell] leadingDecorationIndex:decoration]; |
| 764 | 767 |
| 765 // If there are ever too many leading views, the fake x-coords might land | 768 // If there are ever too many leading views, the fake x-coords might land |
| 766 // before the button preceding the omnibox in the key view order. This | 769 // before the button preceding the omnibox in the key view order. This |
| 767 // threshold is just a guess. | 770 // threshold is just a guess. |
| 768 DCHECK_LT(left_index, 10); | 771 DCHECK_LT(left_index, 10); |
| 769 if (left_index != -1) | 772 if (left_index != -1) { |
| 770 real_frame.origin.x = [field_ frame].origin.x - left_index - 1; | 773 CGFloat delta = left_index + 1; |
| 771 | 774 real_frame.origin.x = |
| 775 cocoa_l10n_util::ShouldDoExperimentalRTLLayout() |
| 776 ? NSMaxX([field_ frame]) + delta - NSWidth(real_frame) |
| 777 : NSMinX([field_ frame]) - delta; |
| 778 } |
| 772 decoration->UpdateAccessibilityView(apparent_frame); | 779 decoration->UpdateAccessibilityView(apparent_frame); |
| 773 [decoration->GetAccessibilityView() setFrame:real_frame]; | 780 [decoration->GetAccessibilityView() setFrame:real_frame]; |
| 774 [decoration->GetAccessibilityView() setNeedsDisplayInRect:apparent_frame]; | 781 [decoration->GetAccessibilityView() setNeedsDisplayInRect:apparent_frame]; |
| 775 } | 782 } |
| 776 | 783 |
| 777 std::vector<LocationBarDecoration*> LocationBarViewMac::GetDecorations() { | 784 std::vector<LocationBarDecoration*> LocationBarViewMac::GetDecorations() { |
| 778 std::vector<LocationBarDecoration*> decorations; | 785 std::vector<LocationBarDecoration*> decorations; |
| 779 // TODO(ellyjones): content setting decorations aren't included right now, nor | 786 // TODO(ellyjones): content setting decorations aren't included right now, nor |
| 780 // are page actions and the keyword hint. | 787 // are page actions and the keyword hint. |
| 781 decorations.push_back(location_icon_decoration_.get()); | 788 decorations.push_back(location_icon_decoration_.get()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 794 OnDecorationsChanged(); | 801 OnDecorationsChanged(); |
| 795 } | 802 } |
| 796 | 803 |
| 797 std::vector<NSView*> LocationBarViewMac::GetDecorationAccessibilityViews() { | 804 std::vector<NSView*> LocationBarViewMac::GetDecorationAccessibilityViews() { |
| 798 std::vector<LocationBarDecoration*> decorations = GetDecorations(); | 805 std::vector<LocationBarDecoration*> decorations = GetDecorations(); |
| 799 std::vector<NSView*> views; | 806 std::vector<NSView*> views; |
| 800 for (auto* decoration : decorations) | 807 for (auto* decoration : decorations) |
| 801 views.push_back(decoration->GetAccessibilityView()); | 808 views.push_back(decoration->GetAccessibilityView()); |
| 802 return views; | 809 return views; |
| 803 } | 810 } |
| OLD | NEW |