| 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/location_bar/autocomplete_text_field_cell.h" | 5 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/mac/foundation_util.h" | 8 #include "base/mac/foundation_util.h" |
| 9 #include "base/mac/mac_logging.h" | 9 #include "base/mac/mac_logging.h" |
| 10 #include "chrome/browser/search/search.h" | 10 #include "chrome/browser/search/search.h" |
| 11 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h" | 11 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h" |
| 12 #import "chrome/browser/ui/cocoa/location_bar/location_bar_decoration.h" | 12 #import "chrome/browser/ui/cocoa/location_bar/location_bar_decoration.h" |
| 13 #import "extensions/common/feature_switch.h" | 13 #import "extensions/common/feature_switch.h" |
| 14 #include "grit/theme_resources.h" | 14 #include "grit/theme_resources.h" |
| 15 #import "third_party/mozilla/NSPasteboard+Utils.h" | 15 #import "third_party/mozilla/NSPasteboard+Utils.h" |
| 16 #import "ui/base/cocoa/appkit_utils.h" | 16 #import "ui/base/cocoa/appkit_utils.h" |
| 17 #import "ui/base/cocoa/nsview_additions.h" | 17 #import "ui/base/cocoa/nsview_additions.h" |
| 18 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" | 18 #include "ui/base/cocoa/scoped_cg_context_smooth_fonts.h" |
| 19 | 19 |
| 20 using extensions::FeatureSwitch; | 20 using extensions::FeatureSwitch; |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 // Matches the clipping radius of |GradientButtonCell|. | 24 // Matches the clipping radius of |GradientButtonCell|. |
| 25 const CGFloat kCornerRadius = 3.0; | 25 const CGFloat kCornerRadius = 3.0; |
| 26 | 26 |
| 27 // How far to inset the left- and right-hand decorations from the field's | 27 // How far to inset the left- and right-hand decorations from the field's |
| 28 // bounds. | 28 // bounds. |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 decorationFrames[i], -(kDecorationHorizontalPad + 1) / 2, 2); | 339 decorationFrames[i], -(kDecorationHorizontalPad + 1) / 2, 2); |
| 340 decorations[i]->DrawWithBackgroundInFrame( | 340 decorations[i]->DrawWithBackgroundInFrame( |
| 341 background_frame, decorationFrames[i], controlView); | 341 background_frame, decorationFrames[i], controlView); |
| 342 } | 342 } |
| 343 } | 343 } |
| 344 | 344 |
| 345 // NOTE: This function must closely match the logic in | 345 // NOTE: This function must closely match the logic in |
| 346 // |-textFrameForFrame:|. | 346 // |-textFrameForFrame:|. |
| 347 | 347 |
| 348 // Superclass draws text portion WRT original |cellFrame|. | 348 // Superclass draws text portion WRT original |cellFrame|. |
| 349 // Even though -isOpaque is NO due to rounded corners, we know that the text | 349 ui::ScopedCGContextSmoothFonts fontSmoothing; |
| 350 // will be drawn on top of an opaque area, therefore it is safe to enable | 350 [super drawInteriorWithFrame:cellFrame inView:controlView]; |
| 351 // font smoothing. | |
| 352 { | |
| 353 gfx::ScopedNSGraphicsContextSaveGState scopedGState; | |
| 354 NSGraphicsContext* context = [NSGraphicsContext currentContext]; | |
| 355 CGContextRef cgContext = static_cast<CGContextRef>([context graphicsPort]); | |
| 356 CGContextSetShouldSmoothFonts(cgContext, true); | |
| 357 [super drawInteriorWithFrame:cellFrame inView:controlView]; | |
| 358 } | |
| 359 } | 351 } |
| 360 | 352 |
| 361 - (LocationBarDecoration*)decorationForEvent:(NSEvent*)theEvent | 353 - (LocationBarDecoration*)decorationForEvent:(NSEvent*)theEvent |
| 362 inRect:(NSRect)cellFrame | 354 inRect:(NSRect)cellFrame |
| 363 ofView:(AutocompleteTextField*)controlView | 355 ofView:(AutocompleteTextField*)controlView |
| 364 { | 356 { |
| 365 const BOOL flipped = [controlView isFlipped]; | 357 const BOOL flipped = [controlView isFlipped]; |
| 366 const NSPoint location = | 358 const NSPoint location = |
| 367 [controlView convertPoint:[theEvent locationInWindow] fromView:nil]; | 359 [controlView convertPoint:[theEvent locationInWindow] fromView:nil]; |
| 368 | 360 |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 | 668 |
| 677 - (void)handleFocusEvent:(NSEvent*)event | 669 - (void)handleFocusEvent:(NSEvent*)event |
| 678 ofView:(AutocompleteTextField*)controlView { | 670 ofView:(AutocompleteTextField*)controlView { |
| 679 if ([controlView observer]) { | 671 if ([controlView observer]) { |
| 680 const bool controlDown = ([event modifierFlags] & NSControlKeyMask) != 0; | 672 const bool controlDown = ([event modifierFlags] & NSControlKeyMask) != 0; |
| 681 [controlView observer]->OnSetFocus(controlDown); | 673 [controlView observer]->OnSetFocus(controlDown); |
| 682 } | 674 } |
| 683 } | 675 } |
| 684 | 676 |
| 685 @end | 677 @end |
| OLD | NEW |