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 #import "base/mac/scoped_nsobject.h" | 10 #import "base/mac/scoped_nsobject.h" |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 return [super startTrackingAt:startPoint inView:controlView]; | 339 return [super startTrackingAt:startPoint inView:controlView]; |
340 } | 340 } |
341 | 341 |
342 // Since we have our own drawWithFrame:, we need to also have our own | 342 // Since we have our own drawWithFrame:, we need to also have our own |
343 // logic for determining when the mouse is inside for honoring this | 343 // logic for determining when the mouse is inside for honoring this |
344 // request. | 344 // request. |
345 - (void)setShowsBorderOnlyWhileMouseInside:(BOOL)showOnly { | 345 - (void)setShowsBorderOnlyWhileMouseInside:(BOOL)showOnly { |
346 [super setShowsBorderOnlyWhileMouseInside:showOnly]; | 346 [super setShowsBorderOnlyWhileMouseInside:showOnly]; |
347 if (showOnly) { | 347 if (showOnly) { |
348 [self updateTrackingAreas]; | 348 [self updateTrackingAreas]; |
349 if ([self tag] == kMaterialStandardButtonTypeWithLimitedClickFeedback) | |
350 [self setHighlighted:isMouseInside_]; | |
351 } else { | 349 } else { |
352 if (trackingArea_) { | 350 if (trackingArea_) { |
353 [[self controlView] removeTrackingArea:trackingArea_]; | 351 [[self controlView] removeTrackingArea:trackingArea_]; |
354 trackingArea_.reset(nil); | 352 trackingArea_.reset(nil); |
355 if (isMouseInside_) { | 353 if (isMouseInside_) { |
356 isMouseInside_ = NO; | 354 isMouseInside_ = NO; |
357 [[self controlView] setNeedsDisplay:YES]; | 355 [[self controlView] setNeedsDisplay:YES]; |
358 } | 356 } |
359 } | 357 } |
360 } | 358 } |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 // TODO(viettrungluu): clean this up. | 576 // TODO(viettrungluu): clean this up. |
579 - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { | 577 - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { |
580 NSRect innerFrame; | 578 NSRect innerFrame; |
581 NSBezierPath* innerPath = nil; | 579 NSBezierPath* innerPath = nil; |
582 [self getDrawParamsForFrame:cellFrame | 580 [self getDrawParamsForFrame:cellFrame |
583 inView:controlView | 581 inView:controlView |
584 innerFrame:&innerFrame | 582 innerFrame:&innerFrame |
585 innerPath:&innerPath | 583 innerPath:&innerPath |
586 clipPath:NULL]; | 584 clipPath:NULL]; |
587 | 585 |
588 BOOL pressed = ([((NSControl*)[self controlView]) isEnabled] && | 586 BOOL enabled = [((NSControl*)[self controlView]) isEnabled]; |
589 [self isHighlighted]); | 587 BOOL pressed = enabled && [self isHighlighted]; |
590 NSWindow* window = [controlView window]; | 588 NSWindow* window = [controlView window]; |
591 const ui::ThemeProvider* themeProvider = [window themeProvider]; | 589 const ui::ThemeProvider* themeProvider = [window themeProvider]; |
592 BOOL active = [window isKeyWindow] || [window isMainWindow]; | 590 BOOL active = [window isKeyWindow] || [window isMainWindow]; |
593 | 591 |
594 // Stroke the borders and appropriate fill gradient. If we're borderless, the | 592 // Stroke the borders and appropriate fill gradient. If we're borderless, the |
595 // only time we want to draw the inner gradient is if we're highlighted or if | 593 // only time we want to draw the inner gradient is if we're highlighted or if |
596 // we're drawing the focus ring manually. In Material Design, the "border" is | 594 // we're drawing the focus ring manually. In Material Design, the "border" is |
597 // actually a highlight, which should be drawn if | 595 // actually a highlight, which should be drawn if |
598 // |showsBorderOnlyWhileMouseInside| is true. | 596 // |showsBorderOnlyWhileMouseInside| is true. |
599 BOOL hasMaterialHighlight = | 597 BOOL hasMaterialHighlight = |
600 [self tag] == kMaterialStandardButtonTypeWithLimitedClickFeedback && | 598 [self tag] == kMaterialStandardButtonTypeWithLimitedClickFeedback && |
601 ![self showsBorderOnlyWhileMouseInside]; | 599 ![self showsBorderOnlyWhileMouseInside] && |
| 600 enabled; |
602 if (([self isBordered] && ![self showsBorderOnlyWhileMouseInside]) || | 601 if (([self isBordered] && ![self showsBorderOnlyWhileMouseInside]) || |
603 pressed || [self isMouseInside] || [self isContinuousPulsing] || | 602 pressed || [self isMouseInside] || [self isContinuousPulsing] || |
604 hasMaterialHighlight) { | 603 hasMaterialHighlight) { |
605 // When pulsing we want the bookmark to stand out a little more. | 604 // When pulsing we want the bookmark to stand out a little more. |
606 BOOL showClickedGradient = pressed || | 605 BOOL showClickedGradient = pressed || |
607 (pulseState_ == gradient_button_cell::kPulsingContinuous); | 606 (pulseState_ == gradient_button_cell::kPulsingContinuous); |
608 BOOL showHighlightGradient = [self isHighlighted] || hasMaterialHighlight; | 607 BOOL showHighlightGradient = [self isHighlighted] || hasMaterialHighlight; |
609 | 608 |
610 [self drawBorderAndFillForTheme:themeProvider | 609 [self drawBorderAndFillForTheme:themeProvider |
611 controlView:controlView | 610 controlView:controlView |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
852 options:options | 851 options:options |
853 owner:self | 852 owner:self |
854 userInfo:nil]); | 853 userInfo:nil]); |
855 if (isMouseInside_ != mouseInView) { | 854 if (isMouseInside_ != mouseInView) { |
856 [self setMouseInside:mouseInView animate:NO]; | 855 [self setMouseInside:mouseInView animate:NO]; |
857 [controlView setNeedsDisplay:YES]; | 856 [controlView setNeedsDisplay:YES]; |
858 } | 857 } |
859 } | 858 } |
860 | 859 |
861 @end | 860 @end |
OLD | NEW |