| OLD | NEW | 
|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "ui/message_center/cocoa/settings_entry_view.h" | 5 #import "ui/message_center/cocoa/settings_entry_view.h" | 
| 6 | 6 | 
| 7 #include <algorithm> | 7 #include <algorithm> | 
| 8 | 8 | 
| 9 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" | 
| 10 #include "grit/ui_resources.h" | 10 #include "grit/ui_resources.h" | 
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 49 // The amount of space we want, based on the spec and the intrinsic text space | 49 // The amount of space we want, based on the spec and the intrinsic text space | 
| 50 // included by Cocoa. | 50 // included by Cocoa. | 
| 51 const int kCorrectedIconTextPadding = | 51 const int kCorrectedIconTextPadding = | 
| 52     kInternalHorizontalSpacing - kIntrinsicTextLeftPadding; | 52     kInternalHorizontalSpacing - kIntrinsicTextLeftPadding; | 
| 53 | 53 | 
| 54 // We want a certain amount of space to the right of the learn more button, | 54 // We want a certain amount of space to the right of the learn more button, | 
| 55 // this metric incorporates the intrinsic learn more blank space to compute it. | 55 // this metric incorporates the intrinsic learn more blank space to compute it. | 
| 56 const int kCorrectedEntryRightPadding = | 56 const int kCorrectedEntryRightPadding = | 
| 57     kInternalHorizontalSpacing - kIntrinsicLearnMorePadding; | 57     kInternalHorizontalSpacing - kIntrinsicLearnMorePadding; | 
| 58 | 58 | 
|  | 59 //////////////////////////////////////////////////////////////////////////////// | 
|  | 60 | 
|  | 61 @interface MCSettingsButton : NSButton | 
|  | 62 @end | 
|  | 63 | 
|  | 64 @implementation MCSettingsButton | 
|  | 65 // drawRect: needs to fill the button with a background, otherwise we don't get | 
|  | 66 // subpixel antialiasing. | 
|  | 67 - (void)drawRect:(NSRect)dirtyRect { | 
|  | 68   NSColor* color = gfx::SkColorToCalibratedNSColor( | 
|  | 69       message_center::kMessageCenterBackgroundColor); | 
|  | 70   [color set]; | 
|  | 71   NSRectFill(dirtyRect); | 
|  | 72   [super drawRect:dirtyRect]; | 
|  | 73 } | 
|  | 74 @end | 
|  | 75 | 
| 59 @interface MCSettingsButtonCell : NSButtonCell { | 76 @interface MCSettingsButtonCell : NSButtonCell { | 
| 60   // A checkbox's regular image is the checkmark image. This additional image | 77   // A checkbox's regular image is the checkmark image. This additional image | 
| 61   // is used for the favicon or app icon shown next to the checkmark. | 78   // is used for the favicon or app icon shown next to the checkmark. | 
| 62   base::scoped_nsobject<NSImage> extraImage_; | 79   base::scoped_nsobject<NSImage> extraImage_; | 
| 63 } | 80 } | 
| 64 - (void)setExtraImage:(NSImage*)extraImage; | 81 - (void)setExtraImage:(NSImage*)extraImage; | 
| 65 @end | 82 @end | 
| 66 | 83 | 
| 67 @implementation MCSettingsButtonCell | 84 @implementation MCSettingsButtonCell | 
|  | 85 - (BOOL)isOpaque { | 
|  | 86   return YES; | 
|  | 87 } | 
|  | 88 | 
| 68 - (void)setExtraImage:(NSImage*)extraImage { | 89 - (void)setExtraImage:(NSImage*)extraImage { | 
| 69   extraImage_.reset([extraImage retain]); | 90   extraImage_.reset([extraImage retain]); | 
| 70 } | 91 } | 
| 71 | 92 | 
| 72 - (NSRect)drawTitle:(NSAttributedString*)title | 93 - (NSRect)drawTitle:(NSAttributedString*)title | 
| 73           withFrame:(NSRect)frame | 94           withFrame:(NSRect)frame | 
| 74              inView:(NSView*)controlView { | 95              inView:(NSView*)controlView { | 
| 75   CGFloat inset = kCorrectedCheckmarkRightPadding; | 96   CGFloat inset = kCorrectedCheckmarkRightPadding; | 
| 76   // drawTitle:withFrame:inView: draws the checkmark image. Draw the extra | 97   // drawTitle:withFrame:inView: draws the checkmark image. Draw the extra | 
| 77   // image as part of the checkbox's text. | 98   // image as part of the checkbox's text. | 
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 126       rect.size.width += kEntryIconSize + kCorrectedIconTextPadding; | 147       rect.size.width += kEntryIconSize + kCorrectedIconTextPadding; | 
| 127 | 148 | 
| 128     if (NSPointInRect(point, rect)) | 149     if (NSPointInRect(point, rect)) | 
| 129       result = NSCellHitContentArea | NSCellHitTrackableArea; | 150       result = NSCellHitContentArea | NSCellHitTrackableArea; | 
| 130   } | 151   } | 
| 131   return result; | 152   return result; | 
| 132 } | 153 } | 
| 133 @end | 154 @end | 
| 134 | 155 | 
| 135 @implementation MCSettingsEntryView | 156 @implementation MCSettingsEntryView | 
| 136 |  | 
| 137 - (id)initWithController:(MCSettingsController*)controller | 157 - (id)initWithController:(MCSettingsController*)controller | 
| 138                 notifier:(message_center::Notifier*)notifier | 158                 notifier:(message_center::Notifier*)notifier | 
| 139                    frame:(NSRect)frame | 159                    frame:(NSRect)frame | 
| 140             hasSeparator:(BOOL)hasSeparator { | 160             hasSeparator:(BOOL)hasSeparator { | 
| 141   if ((self = [super initWithFrame:frame])) { | 161   if ((self = [super initWithFrame:frame])) { | 
| 142     [self setBoxType:NSBoxCustom]; | 162     [self setBoxType:NSBoxCustom]; | 
| 143     [self setBorderType:NSNoBorder]; | 163     [self setBorderType:NSNoBorder]; | 
| 144     [self setTitlePosition:NSNoTitle]; | 164     [self setTitlePosition:NSNoTitle]; | 
| 145     [self setContentViewMargins:NSZeroSize]; | 165     [self setContentViewMargins:NSZeroSize]; | 
| 146 | 166 | 
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 211     [learnMoreButton_ setHoverImage:rb.GetNativeImageNamed( | 231     [learnMoreButton_ setHoverImage:rb.GetNativeImageNamed( | 
| 212         IDR_NOTIFICATION_ADVANCED_SETTINGS_HOVER).ToNSImage()]; | 232         IDR_NOTIFICATION_ADVANCED_SETTINGS_HOVER).ToNSImage()]; | 
| 213     [learnMoreButton_ setPressedImage:rb.GetNativeImageNamed( | 233     [learnMoreButton_ setPressedImage:rb.GetNativeImageNamed( | 
| 214         IDR_NOTIFICATION_ADVANCED_SETTINGS_PRESSED).ToNSImage()]; | 234         IDR_NOTIFICATION_ADVANCED_SETTINGS_PRESSED).ToNSImage()]; | 
| 215     [learnMoreButton_ setBordered:NO]; | 235     [learnMoreButton_ setBordered:NO]; | 
| 216     [learnMoreButton_ setTarget:self]; | 236     [learnMoreButton_ setTarget:self]; | 
| 217     [learnMoreButton_ setAction:@selector(learnMoreClicked:)]; | 237     [learnMoreButton_ setAction:@selector(learnMoreClicked:)]; | 
| 218   } | 238   } | 
| 219 | 239 | 
| 220   if (!checkbox_.get()) { | 240   if (!checkbox_.get()) { | 
| 221     checkbox_.reset([[NSButton alloc] initWithFrame:checkboxFrame]); | 241     checkbox_.reset([[MCSettingsButton alloc] initWithFrame:checkboxFrame]); | 
| 222     [self addSubview:checkbox_]; | 242     [self addSubview:checkbox_]; | 
| 223   } else { | 243   } else { | 
| 224     [checkbox_ setFrame:checkboxFrame]; | 244     [checkbox_ setFrame:checkboxFrame]; | 
| 225   } | 245   } | 
| 226 | 246 | 
| 227   base::scoped_nsobject<MCSettingsButtonCell> cell([[MCSettingsButtonCell alloc] | 247   base::scoped_nsobject<MCSettingsButtonCell> cell([[MCSettingsButtonCell alloc] | 
| 228       initTextCell:base::SysUTF16ToNSString(notifier_->name)]); | 248       initTextCell:base::SysUTF16ToNSString(notifier_->name)]); | 
| 229   if ([notifierIcon_ isValid]) | 249   if ([notifierIcon_ isValid]) | 
| 230     [cell setExtraImage:notifierIcon_]; | 250     [cell setExtraImage:notifierIcon_]; | 
| 231 | 251 | 
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 264 | 284 | 
| 265 // Testing API ///////////////////////////////////////////////////////////////// | 285 // Testing API ///////////////////////////////////////////////////////////////// | 
| 266 | 286 | 
| 267 - (void)clickLearnMore { | 287 - (void)clickLearnMore { | 
| 268   [learnMoreButton_ performClick:nil]; | 288   [learnMoreButton_ performClick:nil]; | 
| 269 } | 289 } | 
| 270 | 290 | 
| 271 @end | 291 @end | 
| 272 | 292 | 
| 273 /////////////////////////////////////////////////////////////////////////////// | 293 /////////////////////////////////////////////////////////////////////////////// | 
| OLD | NEW | 
|---|