Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(859)

Unified Diff: chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm

Issue 2839893003: cocoa: allow omnibox decorations to become key (Closed)
Patch Set: fix nits Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/cocoa/location_bar/location_bar_decoration.mm ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm
diff --git a/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm b/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm
index 4b59a6a66a91374d3070697eb15adbd6afd3e568..855e5e14b899ce188d84198d4ebc0fbb5c8bceb0 100644
--- a/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm
+++ b/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm
@@ -742,11 +742,36 @@ new ManagePasswordsDecoration(command_updater, this)),
LocationBarDecoration* decoration) {
if (!decoration->IsVisible())
return;
- NSRect r =
+ NSRect apparent_frame =
[[field_ cell] frameForDecoration:decoration inFrame:[field_ frame]];
- [decoration->GetAccessibilityView() setFrame:r];
- [decoration->GetAccessibilityView() setNeedsDisplayInRect:r];
- decoration->UpdateAccessibilityView();
+
+ // This is a bit subtle:
+ // The decorations' accessibility views can become key to allow keyboard
+ // access to the location bar decorations, but Cocoa's automatic key view loop
+ // sorts by top-left coordinate. Since the omnibox's top-left coordinate is
+ // before its leading decorations, the omnibox would sort before its own
+ // leading decorations, which was logical but visually unintuitive. Therefore,
+ // for leading decorations, this method moves their frame to be "just before"
+ // the omnibox in automatic key view loop order, and gives them an apparent
+ // frame (see DecorationAccessibilityView) so that they still paint their
+ // focus rings at the right place.
+ //
+ // TODO(lgrey): This hack doesn't work in RTL layouts, but the layout of the
+ // omnibox is currently screwed up in RTL layouts anyway. See
+ // https://crbug.com/715627.
+ NSRect real_frame = apparent_frame;
+ int left_index = [[field_ cell] leadingDecorationIndex:decoration];
+
+ // If there are ever too many leading views, the fake x-coords might land
+ // before the button preceding the omnibox in the key view order. This
+ // threshold is just a guess.
+ DCHECK_LT(left_index, 10);
+ if (left_index != -1)
+ real_frame.origin.x = [field_ frame].origin.x - left_index - 1;
+
+ decoration->UpdateAccessibilityView(apparent_frame);
+ [decoration->GetAccessibilityView() setFrame:real_frame];
+ [decoration->GetAccessibilityView() setNeedsDisplayInRect:apparent_frame];
}
std::vector<LocationBarDecoration*> LocationBarViewMac::GetDecorations() {
« no previous file with comments | « chrome/browser/ui/cocoa/location_bar/location_bar_decoration.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698