Chromium Code Reviews| 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 | |
|
lgrey
2017/04/25 21:11:39
Do you know if the top-left thing holds in RTL?
I
Elly Fong-Jones
2017/04/26 16:50:01
It seems to proceed from the top right instead.
| |
| 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(ellyjones): what happens in RTL layouts? | |
| 760 NSRect real_frame = apparent_frame; | |
| 761 int left_index = [[field_ cell] leadingDecorationIndex:decoration]; | |
| 762 if (left_index != -1) | |
| 763 real_frame.origin.x = [field_ frame].origin.x - left_index - 1; | |
|
Mark Mentovai
2017/04/25 20:44:31
Can we have so many decorations that something’s x
Elly Fong-Jones
2017/04/26 16:50:01
Added a DCHECK.
| |
| 764 | |
| 765 decoration->UpdateAccessibilityView(apparent_frame); | |
| 766 [decoration->GetAccessibilityView() setFrame:real_frame]; | |
| 767 [decoration->GetAccessibilityView() setNeedsDisplayInRect:apparent_frame]; | |
| 750 } | 768 } |
| 751 | 769 |
| 752 std::vector<LocationBarDecoration*> LocationBarViewMac::GetDecorations() { | 770 std::vector<LocationBarDecoration*> LocationBarViewMac::GetDecorations() { |
| 753 std::vector<LocationBarDecoration*> decorations; | 771 std::vector<LocationBarDecoration*> decorations; |
| 754 // TODO(ellyjones): content setting decorations aren't included right now, nor | 772 // TODO(ellyjones): content setting decorations aren't included right now, nor |
| 755 // are page actions and the keyword hint. | 773 // are page actions and the keyword hint. |
| 756 decorations.push_back(location_icon_decoration_.get()); | 774 decorations.push_back(location_icon_decoration_.get()); |
| 757 decorations.push_back(selected_keyword_decoration_.get()); | 775 decorations.push_back(selected_keyword_decoration_.get()); |
| 758 decorations.push_back(security_state_bubble_decoration_.get()); | 776 decorations.push_back(security_state_bubble_decoration_.get()); |
| 759 decorations.push_back(save_credit_card_decoration_.get()); | 777 decorations.push_back(save_credit_card_decoration_.get()); |
| 760 decorations.push_back(star_decoration_.get()); | 778 decorations.push_back(star_decoration_.get()); |
| 761 decorations.push_back(translate_decoration_.get()); | 779 decorations.push_back(translate_decoration_.get()); |
| 762 decorations.push_back(zoom_decoration_.get()); | 780 decorations.push_back(zoom_decoration_.get()); |
| 763 decorations.push_back(manage_passwords_decoration_.get()); | 781 decorations.push_back(manage_passwords_decoration_.get()); |
| 764 return decorations; | 782 return decorations; |
| 765 } | 783 } |
| 766 | 784 |
| 767 void LocationBarViewMac::OnDefaultZoomLevelChanged() { | 785 void LocationBarViewMac::OnDefaultZoomLevelChanged() { |
| 768 if (UpdateZoomDecoration(/*default_zoom_changed=*/true)) | 786 if (UpdateZoomDecoration(/*default_zoom_changed=*/true)) |
| 769 OnDecorationsChanged(); | 787 OnDecorationsChanged(); |
| 770 } | 788 } |
| 771 | 789 |
| 772 std::vector<NSView*> LocationBarViewMac::GetDecorationAccessibilityViews() { | 790 std::vector<NSView*> LocationBarViewMac::GetDecorationAccessibilityViews() { |
| 773 std::vector<LocationBarDecoration*> decorations = GetDecorations(); | 791 std::vector<LocationBarDecoration*> decorations = GetDecorations(); |
| 774 std::vector<NSView*> views; | 792 std::vector<NSView*> views; |
| 775 for (auto* decoration : decorations) | 793 for (auto* decoration : decorations) |
| 776 views.push_back(decoration->GetAccessibilityView()); | 794 views.push_back(decoration->GetAccessibilityView()); |
| 777 return views; | 795 return views; |
| 778 } | 796 } |
| OLD | NEW |