Chromium Code Reviews| 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..c2955ec32168a66da0bf6da4bb0e9ca5d729418f 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,86 @@ 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)initWithFrame:(NSRect)frame andOwner:(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)initWithFrame:(NSRect)frame andOwner:(LocationBarDecoration*)owner { |
|
Mark Mentovai
2016/06/23 19:30:55
Is frame ever not NSZeroRect?
Elly Fong-Jones
2016/06/23 20:25:58
Hm. No, it's not. Changed this to not take that ar
|
| + if ((self = [super initWithFrame:frame])) { |
| + 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] |
| + initWithFrame:NSZeroRect |
| + andOwner: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 +156,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. |