| 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 #include "chrome/browser/ui/cocoa/gradient_button_cell.h" | 5 #include "chrome/browser/ui/cocoa/gradient_button_cell.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/mac/mac_util.h" |
| 10 #import "base/mac/scoped_nsobject.h" | 11 #import "base/mac/scoped_nsobject.h" |
| 11 #import "chrome/browser/themes/theme_properties.h" | 12 #import "chrome/browser/themes/theme_properties.h" |
| 12 #import "chrome/browser/themes/theme_service.h" | 13 #import "chrome/browser/themes/theme_service.h" |
| 13 #import "chrome/browser/ui/cocoa/rect_path_utils.h" | 14 #import "chrome/browser/ui/cocoa/rect_path_utils.h" |
| 14 #import "chrome/browser/ui/cocoa/themed_window.h" | 15 #import "chrome/browser/ui/cocoa/themed_window.h" |
| 15 #include "grit/theme_resources.h" | 16 #include "grit/theme_resources.h" |
| 16 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSColor+Luminance.h" | 17 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSColor+Luminance.h" |
| 17 #import "ui/base/cocoa/nsgraphics_context_additions.h" | 18 #import "ui/base/cocoa/nsgraphics_context_additions.h" |
| 18 #import "ui/base/cocoa/nsview_additions.h" | 19 #import "ui/base/cocoa/nsview_additions.h" |
| 19 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" | 20 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
| (...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 innerFrame:&innerFrame | 522 innerFrame:&innerFrame |
| 522 innerPath:&innerPath | 523 innerPath:&innerPath |
| 523 clipPath:NULL]; | 524 clipPath:NULL]; |
| 524 | 525 |
| 525 BOOL pressed = ([((NSControl*)[self controlView]) isEnabled] && | 526 BOOL pressed = ([((NSControl*)[self controlView]) isEnabled] && |
| 526 [self isHighlighted]); | 527 [self isHighlighted]); |
| 527 NSWindow* window = [controlView window]; | 528 NSWindow* window = [controlView window]; |
| 528 ui::ThemeProvider* themeProvider = [window themeProvider]; | 529 ui::ThemeProvider* themeProvider = [window themeProvider]; |
| 529 BOOL active = [window isKeyWindow] || [window isMainWindow]; | 530 BOOL active = [window isKeyWindow] || [window isMainWindow]; |
| 530 | 531 |
| 532 // Draw custom focus ring only if AppKit won't draw one automatically. |
| 533 // The new focus ring APIs became available with 10.7, but did not get |
| 534 // applied to buttons (only editable text fields) until 10.8. |
| 535 BOOL shouldDrawFocusRing = base::mac::IsOSLionOrEarlier() && |
| 536 [self showsFirstResponder]; |
| 537 |
| 531 // Stroke the borders and appropriate fill gradient. If we're borderless, the | 538 // Stroke the borders and appropriate fill gradient. If we're borderless, the |
| 532 // only time we want to draw the inner gradient is if we're highlighted or if | 539 // only time we want to draw the inner gradient is if we're highlighted or if |
| 533 // we're the first responder (when "Full Keyboard Access" is turned on). | 540 // we're drawing the focus ring manually. |
| 534 if (([self isBordered] && ![self showsBorderOnlyWhileMouseInside]) || | 541 if (([self isBordered] && ![self showsBorderOnlyWhileMouseInside]) || |
| 535 pressed || | 542 pressed || |
| 536 [self isMouseInside] || | 543 [self isMouseInside] || |
| 537 [self isContinuousPulsing] || | 544 [self isContinuousPulsing] || |
| 538 [self showsFirstResponder]) { | 545 shouldDrawFocusRing) { |
| 539 | 546 |
| 540 // When pulsing we want the bookmark to stand out a little more. | 547 // When pulsing we want the bookmark to stand out a little more. |
| 541 BOOL showClickedGradient = pressed || | 548 BOOL showClickedGradient = pressed || |
| 542 (pulseState_ == gradient_button_cell::kPulsingContinuous); | 549 (pulseState_ == gradient_button_cell::kPulsingContinuous); |
| 543 | 550 |
| 544 [self drawBorderAndFillForTheme:themeProvider | 551 [self drawBorderAndFillForTheme:themeProvider |
| 545 controlView:controlView | 552 controlView:controlView |
| 546 innerPath:innerPath | 553 innerPath:innerPath |
| 547 showClickedGradient:showClickedGradient | 554 showClickedGradient:showClickedGradient |
| 548 showHighlightGradient:[self isHighlighted] | 555 showHighlightGradient:[self isHighlighted] |
| (...skipping 13 matching lines...) Expand all Loading... |
| 562 active ? ThemeProperties::COLOR_TOOLBAR_BUTTON_STROKE : | 569 active ? ThemeProperties::COLOR_TOOLBAR_BUTTON_STROKE : |
| 563 ThemeProperties::COLOR_TOOLBAR_BUTTON_STROKE_INACTIVE) : | 570 ThemeProperties::COLOR_TOOLBAR_BUTTON_STROKE_INACTIVE) : |
| 564 [NSColor blackColor]; | 571 [NSColor blackColor]; |
| 565 | 572 |
| 566 [[stroke colorWithAlphaComponent:0.2] set]; | 573 [[stroke colorWithAlphaComponent:0.2] set]; |
| 567 NSRectFillUsingOperation(NSInsetRect(borderRect, 0, 2), | 574 NSRectFillUsingOperation(NSInsetRect(borderRect, 0, 2), |
| 568 NSCompositeSourceOver); | 575 NSCompositeSourceOver); |
| 569 } | 576 } |
| 570 [self drawInteriorWithFrame:innerFrame inView:controlView]; | 577 [self drawInteriorWithFrame:innerFrame inView:controlView]; |
| 571 | 578 |
| 572 // Draws the blue focus ring. | 579 if (shouldDrawFocusRing) { |
| 573 if ([self showsFirstResponder]) { | |
| 574 gfx::ScopedNSGraphicsContextSaveGState scoped_state; | 580 gfx::ScopedNSGraphicsContextSaveGState scoped_state; |
| 575 const CGFloat lineWidth = [controlView cr_lineWidth]; | 581 const CGFloat lineWidth = [controlView cr_lineWidth]; |
| 576 // insetX = 1.0 is used for the drawing of blue highlight so that this | 582 // insetX = 1.0 is used for the drawing of blue highlight so that this |
| 577 // highlight won't be too near the bookmark toolbar itself, in case we | 583 // highlight won't be too near the bookmark toolbar itself, in case we |
| 578 // draw bookmark buttons in bookmark toolbar. | 584 // draw bookmark buttons in bookmark toolbar. |
| 579 rect_path_utils::FrameRectWithInset(rect_path_utils::RoundedCornerAll, | 585 rect_path_utils::FrameRectWithInset(rect_path_utils::RoundedCornerAll, |
| 580 NSInsetRect(cellFrame, 0, lineWidth), | 586 NSInsetRect(cellFrame, 0, lineWidth), |
| 581 1.0, // insetX | 587 1.0, // insetX |
| 582 0.0, // insetY | 588 0.0, // insetY |
| 583 3.0, // outerRadius | 589 3.0, // outerRadius |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 781 options:options | 787 options:options |
| 782 owner:self | 788 owner:self |
| 783 userInfo:nil]); | 789 userInfo:nil]); |
| 784 if (isMouseInside_ != mouseInView) { | 790 if (isMouseInside_ != mouseInView) { |
| 785 [self setMouseInside:mouseInView animate:NO]; | 791 [self setMouseInside:mouseInView animate:NO]; |
| 786 [controlView setNeedsDisplay:YES]; | 792 [controlView setNeedsDisplay:YES]; |
| 787 } | 793 } |
| 788 } | 794 } |
| 789 | 795 |
| 790 @end | 796 @end |
| OLD | NEW |