| Index: chrome/browser/ui/cocoa/location_bar/location_bar_decoration.mm
|
| diff --git a/chrome/browser/ui/cocoa/location_bar/location_bar_decoration.mm b/chrome/browser/ui/cocoa/location_bar/location_bar_decoration.mm
|
| index a0bbefd1ba6ee03f81e5392a8295f292bdffd8b0..cbdb2d21428457867555abeadbd3a28d86386c75 100644
|
| --- a/chrome/browser/ui/cocoa/location_bar/location_bar_decoration.mm
|
| +++ b/chrome/browser/ui/cocoa/location_bar/location_bar_decoration.mm
|
| @@ -21,15 +21,85 @@ const CGFloat kMaterialDividerIncognitoGrayScale = 1.0;
|
|
|
| } // namespace
|
|
|
| +// A DecorationAccessibilityView is a focusable, pressable button that is fully
|
| +// transparent and cannot be hit by mouse clicks. This is overlaid over a drawn
|
| +// decoration, to fake keyboard focus on the decoration and make it visible to
|
| +// VoiceOver.
|
| +@interface DecorationAccessibilityView : NSButton {
|
| + LocationBarDecoration* owner_; // weak
|
| +}
|
| +
|
| +// NSView:
|
| +- (id)initWithOwner:(LocationBarDecoration*)owner;
|
| +- (BOOL)acceptsFirstResponder;
|
| +- (void)drawRect:(NSRect)dirtyRect;
|
| +- (NSView*)hitTest:(NSPoint)aPoint;
|
| +
|
| +// This method is called when this DecorationAccessibilityView is activated.
|
| +- (void)actionDidHappen;
|
| +@end
|
| +
|
| +@implementation DecorationAccessibilityView
|
| +
|
| +- (id)initWithOwner:(LocationBarDecoration*)owner {
|
| + if ((self = [super initWithFrame:NSZeroRect])) {
|
| + self.bordered = NO;
|
| + self.focusRingType = NSFocusRingTypeExterior;
|
| + self->owner_ = owner;
|
| + [self setAction:@selector(actionDidHappen)];
|
| + [self setTarget:self];
|
| + }
|
| + return self;
|
| +}
|
| +
|
| +- (BOOL)acceptsFirstResponder {
|
| + // This NSView is only focusable if the owning LocationBarDecoration can
|
| + // accept mouse presses.
|
| + return owner_->AcceptsMousePress() ? YES : NO;
|
| +}
|
| +
|
| +- (void)drawRect:(NSRect)dirtyRect {
|
| + // Draw nothing. This NSView is fully transparent.
|
| +}
|
| +
|
| +- (NSView*)hitTest:(NSPoint)aPoint {
|
| + // Mouse clicks cannot hit this NSView.
|
| + return nil;
|
| +}
|
| +
|
| +- (void)actionDidHappen {
|
| + owner_->OnAccessibilityViewAction();
|
| +}
|
| +
|
| +@end
|
| +
|
| const CGFloat LocationBarDecoration::kOmittedWidth = 0.0;
|
| const SkColor LocationBarDecoration::kMaterialDarkModeTextColor = 0xCCFFFFFF;
|
|
|
| +LocationBarDecoration::LocationBarDecoration() {
|
| + accessibility_view_.reset(
|
| + [[DecorationAccessibilityView alloc] initWithOwner:this]);
|
| + [accessibility_view_.get() setHidden:YES];
|
| +}
|
| +
|
| +void LocationBarDecoration::OnAccessibilityViewAction() {
|
| + // Turn the action into a synthesized mouse click at the center of |this|.
|
| + NSRect frame = [accessibility_view_.get() frame];
|
| + NSPoint mousePoint = NSMakePoint(NSMidX(frame), NSMidY(frame));
|
| + OnMousePressed(frame, mousePoint);
|
| +}
|
| +
|
| +LocationBarDecoration::~LocationBarDecoration() {
|
| + [accessibility_view_.get() removeFromSuperview];
|
| +}
|
| +
|
| bool LocationBarDecoration::IsVisible() const {
|
| return visible_;
|
| }
|
|
|
| void LocationBarDecoration::SetVisible(bool visible) {
|
| visible_ = visible;
|
| + [accessibility_view_.get() setHidden:visible ? NO : YES];
|
| }
|
|
|
|
|
| @@ -85,6 +155,10 @@ NSFont* LocationBarDecoration::GetFont() const {
|
| return OmniboxViewMac::GetNormalFieldFont();
|
| }
|
|
|
| +NSView* LocationBarDecoration::GetAccessibilityView() {
|
| + return accessibility_view_.get();
|
| +}
|
| +
|
| NSPoint LocationBarDecoration::GetBubblePointInFrame(NSRect frame) {
|
| // Clients that use a bubble should implement this. Can't be abstract
|
| // because too many LocationBarDecoration subclasses don't use a bubble.
|
|
|