| 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 <cmath> | 5 #include <cmath> |
| 6 | 6 |
| 7 #import "chrome/browser/ui/cocoa/location_bar/button_decoration.h" | 7 #import "chrome/browser/ui/cocoa/location_bar/button_decoration.h" |
| 8 #import "chrome/browser/ui/cocoa/nsview_additions.h" | |
| 9 | 8 |
| 10 #include "base/logging.h" | 9 #include "base/logging.h" |
| 11 | 10 |
| 12 ButtonDecoration::ButtonDecoration() | 11 ButtonDecoration::ButtonDecoration() |
| 13 : state_(kButtonStateNormal) { | 12 : state_(kButtonStateNormal) { |
| 14 } | 13 } |
| 15 | 14 |
| 16 ButtonDecoration::~ButtonDecoration() { | 15 ButtonDecoration::~ButtonDecoration() { |
| 17 } | 16 } |
| 18 | 17 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 40 NSImage* image = GetImage(); | 39 NSImage* image = GetImage(); |
| 41 if (image) { | 40 if (image) { |
| 42 const CGFloat image_width = [image size].width; | 41 const CGFloat image_width = [image size].width; |
| 43 if (image_width <= width) | 42 if (image_width <= width) |
| 44 return image_width; | 43 return image_width; |
| 45 } | 44 } |
| 46 return kOmittedWidth; | 45 return kOmittedWidth; |
| 47 } | 46 } |
| 48 | 47 |
| 49 void ButtonDecoration::DrawInFrame(NSRect frame, NSView* control_view) { | 48 void ButtonDecoration::DrawInFrame(NSRect frame, NSView* control_view) { |
| 50 // Get tne inner frame that excludes the border and the shadow, and draw the | 49 [GetImage() drawInRect:frame |
| 51 // image in there. Assumes that the button's images fit exactly inside that | |
| 52 // space. | |
| 53 NSRect innerFrame = NSInsetRect(frame, 0, 2 * [control_view cr_lineWidth]); | |
| 54 [GetImage() drawInRect:innerFrame | |
| 55 fromRect:NSZeroRect // Entire image | 50 fromRect:NSZeroRect // Entire image |
| 56 operation:NSCompositeSourceOver | 51 operation:NSCompositeSourceOver |
| 57 fraction:1.0 | 52 fraction:1.0 |
| 58 respectFlipped:YES | 53 respectFlipped:YES |
| 59 hints:nil]; | 54 hints:nil]; |
| 60 } | 55 } |
| 61 | 56 |
| 62 bool ButtonDecoration::OnMousePressed(NSRect frame) { | 57 bool ButtonDecoration::OnMousePressed(NSRect frame) { |
| 63 return false; | 58 return false; |
| 64 } | 59 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 88 DCHECK(hover_image_.get()); | 83 DCHECK(hover_image_.get()); |
| 89 return hover_image_.get(); | 84 return hover_image_.get(); |
| 90 case kButtonStatePressed: | 85 case kButtonStatePressed: |
| 91 DCHECK(pressed_image_.get()); | 86 DCHECK(pressed_image_.get()); |
| 92 return pressed_image_.get(); | 87 return pressed_image_.get(); |
| 93 default: | 88 default: |
| 94 NOTREACHED(); | 89 NOTREACHED(); |
| 95 return nil; | 90 return nil; |
| 96 } | 91 } |
| 97 } | 92 } |
| OLD | NEW |