| 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" |
| (...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 735 bool LocationBarViewMac::IsSecureConnection( | 735 bool LocationBarViewMac::IsSecureConnection( |
| 736 security_state::SecurityLevel level) const { | 736 security_state::SecurityLevel level) const { |
| 737 return level == security_state::SECURE || | 737 return level == security_state::SECURE || |
| 738 level == security_state::EV_SECURE; | 738 level == security_state::EV_SECURE; |
| 739 } | 739 } |
| 740 | 740 |
| 741 void LocationBarViewMac::UpdateAccessibilityView( | 741 void LocationBarViewMac::UpdateAccessibilityView( |
| 742 LocationBarDecoration* decoration) { | 742 LocationBarDecoration* decoration) { |
| 743 if (!decoration->IsVisible()) | 743 if (!decoration->IsVisible()) |
| 744 return; | 744 return; |
| 745 NSRect r = | 745 NSRect apparent_frame = |
| 746 [[field_ cell] frameForDecoration:decoration inFrame:[field_ frame]]; | 746 [[field_ cell] frameForDecoration:decoration inFrame:[field_ frame]]; |
| 747 [decoration->GetAccessibilityView() setFrame:r]; | 747 |
| 748 [decoration->GetAccessibilityView() setNeedsDisplayInRect:r]; | 748 // This is a bit subtle: |
| 749 decoration->UpdateAccessibilityView(); | 749 // The decorations' accessibility views can become key to allow keyboard |
| 750 // 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 |
| 752 // before its leading decorations, the omnibox would sort before its own |
| 753 // leading decorations, which was logical but visually unintuitive. Therefore, |
| 754 // 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 |
| 756 // frame (see DecorationAccessibilityView) so that they still paint their |
| 757 // focus rings at the right place. |
| 758 // |
| 759 // 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 |
| 761 // https://crbug.com/715627. |
| 762 NSRect real_frame = apparent_frame; |
| 763 int left_index = [[field_ cell] leadingDecorationIndex:decoration]; |
| 764 |
| 765 // 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 |
| 767 // threshold is just a guess. |
| 768 DCHECK_LT(left_index, 10); |
| 769 if (left_index != -1) |
| 770 real_frame.origin.x = [field_ frame].origin.x - left_index - 1; |
| 771 |
| 772 decoration->UpdateAccessibilityView(apparent_frame); |
| 773 [decoration->GetAccessibilityView() setFrame:real_frame]; |
| 774 [decoration->GetAccessibilityView() setNeedsDisplayInRect:apparent_frame]; |
| 750 } | 775 } |
| 751 | 776 |
| 752 std::vector<LocationBarDecoration*> LocationBarViewMac::GetDecorations() { | 777 std::vector<LocationBarDecoration*> LocationBarViewMac::GetDecorations() { |
| 753 std::vector<LocationBarDecoration*> decorations; | 778 std::vector<LocationBarDecoration*> decorations; |
| 754 // TODO(ellyjones): content setting decorations aren't included right now, nor | 779 // TODO(ellyjones): content setting decorations aren't included right now, nor |
| 755 // are page actions and the keyword hint. | 780 // are page actions and the keyword hint. |
| 756 decorations.push_back(location_icon_decoration_.get()); | 781 decorations.push_back(location_icon_decoration_.get()); |
| 757 decorations.push_back(selected_keyword_decoration_.get()); | 782 decorations.push_back(selected_keyword_decoration_.get()); |
| 758 decorations.push_back(security_state_bubble_decoration_.get()); | 783 decorations.push_back(security_state_bubble_decoration_.get()); |
| 759 decorations.push_back(save_credit_card_decoration_.get()); | 784 decorations.push_back(save_credit_card_decoration_.get()); |
| 760 decorations.push_back(star_decoration_.get()); | 785 decorations.push_back(star_decoration_.get()); |
| 761 decorations.push_back(translate_decoration_.get()); | 786 decorations.push_back(translate_decoration_.get()); |
| 762 decorations.push_back(zoom_decoration_.get()); | 787 decorations.push_back(zoom_decoration_.get()); |
| 763 decorations.push_back(manage_passwords_decoration_.get()); | 788 decorations.push_back(manage_passwords_decoration_.get()); |
| 764 return decorations; | 789 return decorations; |
| 765 } | 790 } |
| 766 | 791 |
| 767 void LocationBarViewMac::OnDefaultZoomLevelChanged() { | 792 void LocationBarViewMac::OnDefaultZoomLevelChanged() { |
| 768 if (UpdateZoomDecoration(/*default_zoom_changed=*/true)) | 793 if (UpdateZoomDecoration(/*default_zoom_changed=*/true)) |
| 769 OnDecorationsChanged(); | 794 OnDecorationsChanged(); |
| 770 } | 795 } |
| 771 | 796 |
| 772 std::vector<NSView*> LocationBarViewMac::GetDecorationAccessibilityViews() { | 797 std::vector<NSView*> LocationBarViewMac::GetDecorationAccessibilityViews() { |
| 773 std::vector<LocationBarDecoration*> decorations = GetDecorations(); | 798 std::vector<LocationBarDecoration*> decorations = GetDecorations(); |
| 774 std::vector<NSView*> views; | 799 std::vector<NSView*> views; |
| 775 for (auto* decoration : decorations) | 800 for (auto* decoration : decorations) |
| 776 views.push_back(decoration->GetAccessibilityView()); | 801 views.push_back(decoration->GetAccessibilityView()); |
| 777 return views; | 802 return views; |
| 778 } | 803 } |
| OLD | NEW |