Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/constrained_window/constrained_window_button.h" | 5 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h" |
| 6 | 6 |
| 7 #import <Carbon/Carbon.h> // kVK_Return. | |
| 8 | |
| 7 #include "base/mac/scoped_nsobject.h" | 9 #include "base/mac/scoped_nsobject.h" |
| 8 #import "chrome/browser/ui/cocoa/key_equivalent_constants.h" | 10 #import "chrome/browser/ui/cocoa/key_equivalent_constants.h" |
| 9 #include "skia/ext/skia_utils_mac.h" | 11 #include "skia/ext/skia_utils_mac.h" |
| 10 #import "third_party/molokocacao/NSBezierPath+MCAdditions.h" | 12 #import "third_party/molokocacao/NSBezierPath+MCAdditions.h" |
| 11 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" | 13 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
| 12 | 14 |
| 13 @interface ConstrainedWindowButton () | 15 @interface ConstrainedWindowButton () |
| 14 - (BOOL)isMouseReallyInside; | 16 - (BOOL)isMouseReallyInside; |
| 15 @end | 17 @end |
| 16 | 18 |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 238 + (void)DrawBorderForPath:(NSBezierPath*)path | 240 + (void)DrawBorderForPath:(NSBezierPath*)path |
| 239 withCell:(id<ConstrainedWindowButtonDrawableCell>)cell | 241 withCell:(id<ConstrainedWindowButtonDrawableCell>)cell |
| 240 inView:(NSView*)view { | 242 inView:(NSView*)view { |
| 241 if ([[[view window] firstResponder] isEqual:view]) | 243 if ([[[view window] firstResponder] isEqual:view]) |
| 242 [[NSColor colorWithCalibratedRed:0.30 green:0.57 blue:1.0 alpha:1.0] set]; | 244 [[NSColor colorWithCalibratedRed:0.30 green:0.57 blue:1.0 alpha:1.0] set]; |
| 243 else | 245 else |
| 244 [GetButtonBorderColor(cellButtonState(cell)) set]; | 246 [GetButtonBorderColor(cellButtonState(cell)) set]; |
| 245 [path stroke]; | 247 [path stroke]; |
| 246 } | 248 } |
| 247 | 249 |
| 250 - (BOOL)canBecomeKeyView { | |
| 251 return YES; | |
| 252 } | |
| 253 | |
| 254 - (void)keyDown:(NSEvent*)event { | |
| 255 // Since there is no default button in the bubble, it is safe to activate | |
| 256 // all buttons on Enter as well, and be consistent with the Windows | |
| 257 // implementation. | |
| 258 if ([event keyCode] == kVK_Return) | |
|
Robert Sesek
2016/03/25 20:16:03
Return is not typically how buttons are invoked on
juncai
2016/03/25 20:31:54
The space works without this change to -keyDown:.
| |
| 259 [self performClick:self]; | |
| 260 else | |
| 261 [super keyDown:event]; | |
| 262 } | |
| 263 | |
| 248 @end | 264 @end |
| 249 | 265 |
| 250 @implementation ConstrainedWindowButtonCell | 266 @implementation ConstrainedWindowButtonCell |
| 251 | 267 |
| 252 @synthesize isMouseInside = isMouseInside_; | 268 @synthesize isMouseInside = isMouseInside_; |
| 253 | 269 |
| 254 - (void)drawBezelWithFrame:(NSRect)frame inView:(NSView*)controlView { | 270 - (void)drawBezelWithFrame:(NSRect)frame inView:(NSView*)controlView { |
| 255 // Inset to leave room for shadow. | 271 // Inset to leave room for shadow. |
| 256 --frame.size.height; | 272 --frame.size.height; |
| 257 | 273 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 281 size.width += kButtonPaddingX * 2; | 297 size.width += kButtonPaddingX * 2; |
| 282 return size; | 298 return size; |
| 283 } | 299 } |
| 284 | 300 |
| 285 - (NSAttributedString*)getAttributedTitle { | 301 - (NSAttributedString*)getAttributedTitle { |
| 286 return GetButtonAttributedString( | 302 return GetButtonAttributedString( |
| 287 [self title], [self keyEquivalent], self); | 303 [self title], [self keyEquivalent], self); |
| 288 } | 304 } |
| 289 | 305 |
| 290 @end | 306 @end |
| OLD | NEW |