Commit 7d0f29cf authored by ellyjones's avatar ellyjones Committed by Commit bot

cocoa: don't draw focus rings over the URL scheme in the location bar

The security state decoration looks like this:

  Secure |

The divider is included in the bounds, and then the location bar text is placed
just after this decoration; because of that, the focus ring on the security
state decoration (which is exterior to the decoration, like Cocoa focus rings
usually are) draws over the top of the start of the location bar text. This
change:

1) Introduces LocationBarDecoration::GetRealFocusRingBounds() to allow each
   decoration to control its focus ring bounds if it needs to
2) Overrides that method in SecurityStateBubbleDecoration to inset the focus
   ring on the right side

BUG=715909

Review-Url: https://codereview.chromium.org/2847903003
Cr-Commit-Position: refs/heads/master@{#468096}
parent 7dd3a053
......@@ -153,6 +153,11 @@ class LocationBarDecoration {
// different from its frame in the Cocoa sense).
void UpdateAccessibilityView(NSRect apparent_frame);
// Computes the real bounds the focus ring should be drawn around for this
// decoration. Some decorations include visual spacing or separators in their
// bounds, but these should not be encompassed by the focus ring.
virtual NSRect GetRealFocusRingBounds(NSRect bounds) const;
DecorationMouseState state() const { return state_; }
bool active() const { return active_; }
......
......@@ -104,7 +104,8 @@ const CGFloat kBackgroundFrameYInset = 2.0;
}
- (NSRect)focusRingMaskBounds {
return [[self superview] convertRect:apparentFrame_ toView:self];
return owner_->GetRealFocusRingBounds(
[[self superview] convertRect:apparentFrame_ toView:self]);
}
@end
......@@ -184,6 +185,10 @@ void LocationBarDecoration::UpdateAccessibilityView(NSRect apparent_frame) {
[v setApparentFrame:apparent_frame];
}
NSRect LocationBarDecoration::GetRealFocusRingBounds(NSRect bounds) const {
return bounds;
}
void LocationBarDecoration::DrawInFrame(NSRect frame, NSView* control_view) {
NOTREACHED();
}
......
......@@ -73,6 +73,7 @@ class SecurityStateBubbleDecoration : public BubbleDecoration,
bool AcceptsMousePress() override;
NSPoint GetBubblePointInFrame(NSRect frame) override;
NSString* GetToolTip() override;
NSRect GetRealFocusRingBounds(NSRect apparent_frame) const override;
// BubbleDecoration:
NSColor* GetBackgroundBorderColor() override;
......@@ -111,6 +112,11 @@ class SecurityStateBubbleDecoration : public BubbleDecoration,
LocationBarViewMac* owner_; // weak
// Distance in points to inset the right edge of the focus ring by. This is
// used by |GetRealFocusRingBounds| to prevent the focus ring from including
// the divider bar. This is recomputed every time this object is drawn.
int focus_ring_right_inset_ = 0;
// Used to disable find bar animations when testing.
bool disable_animations_during_testing_;
......
......@@ -151,6 +151,7 @@ void SecurityStateBubbleDecoration::DrawInFrame(NSRect frame,
CGFloat text_left_offset = NSMinX(decoration_frame);
CGFloat text_right_offset = NSMaxX(decoration_frame);
const BOOL is_rtl = cocoa_l10n_util::ShouldDoExperimentalRTLLayout();
focus_ring_right_inset_ = 0;
if (image_) {
// The image should fade in if we're animating in.
CGFloat image_alpha =
......@@ -247,6 +248,12 @@ void SecurityStateBubbleDecoration::DrawInFrame(NSRect frame,
divider_color = [divider_color colorWithAlphaComponent:divider_alpha];
[divider_color set];
[line stroke];
focus_ring_right_inset_ = DividerPadding() + line_width;
} else {
// When mouse-hovered, the divider isn't drawn, but the padding for it is
// still present to separate the button from the location bar text.
focus_ring_right_inset_ = DividerPadding();
}
}
}
......@@ -292,6 +299,12 @@ NSString* SecurityStateBubbleDecoration::GetToolTip() {
stringWithFormat:@"%@. %@", full_label_.get(), tooltip_icon_text];
}
NSRect SecurityStateBubbleDecoration::GetRealFocusRingBounds(
NSRect bounds) const {
bounds.size.width -= focus_ring_right_inset_;
return bounds;
}
//////////////////////////////////////////////////////////////////
// SecurityStateBubbleDecoration::BubbleDecoration:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment