| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 #include "chrome/browser/ui/cocoa/browser/zoom_bubble_controller.h" | 5 #include "chrome/browser/ui/cocoa/browser/zoom_bubble_controller.h" |
| 6 | 6 |
| 7 #include "base/mac/foundation_util.h" | 7 #include "base/mac/foundation_util.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "chrome/browser/chrome_page_zoom.h" | 9 #include "chrome/browser/chrome_page_zoom.h" |
| 10 #import "chrome/browser/ui/cocoa/info_bubble_window.h" | 10 #import "chrome/browser/ui/cocoa/info_bubble_window.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 void SetZoomBubbleAutoCloseDelayForTesting(NSTimeInterval time_interval) { | 67 void SetZoomBubbleAutoCloseDelayForTesting(NSTimeInterval time_interval) { |
| 68 gAutoCloseDelay = time_interval; | 68 gAutoCloseDelay = time_interval; |
| 69 } | 69 } |
| 70 | 70 |
| 71 } // namespace chrome | 71 } // namespace chrome |
| 72 | 72 |
| 73 @implementation ZoomBubbleController | 73 @implementation ZoomBubbleController |
| 74 | 74 |
| 75 - (id)initWithParentWindow:(NSWindow*)parentWindow | 75 - (id)initWithParentWindow:(NSWindow*)parentWindow |
| 76 closeObserver:(void(^)(ZoomBubbleController*))closeObserver { | 76 closeObserver:(void(^)(ZoomBubbleController*))closeObserver { |
| 77 scoped_nsobject<InfoBubbleWindow> window([[InfoBubbleWindow alloc] | 77 base::scoped_nsobject<InfoBubbleWindow> window( |
| 78 initWithContentRect:NSMakeRect(0, 0, 200, 100) | 78 [[InfoBubbleWindow alloc] initWithContentRect:NSMakeRect(0, 0, 200, 100) |
| 79 styleMask:NSBorderlessWindowMask | 79 styleMask:NSBorderlessWindowMask |
| 80 backing:NSBackingStoreBuffered | 80 backing:NSBackingStoreBuffered |
| 81 defer:NO]); | 81 defer:NO]); |
| 82 if ((self = [super initWithWindow:window | 82 if ((self = [super initWithWindow:window |
| 83 parentWindow:parentWindow | 83 parentWindow:parentWindow |
| 84 anchoredAt:NSZeroPoint])) { | 84 anchoredAt:NSZeroPoint])) { |
| 85 closeObserver_.reset(Block_copy(closeObserver)); | 85 closeObserver_.reset(Block_copy(closeObserver)); |
| 86 | 86 |
| 87 ui::NativeTheme* nativeTheme = ui::NativeTheme::instance(); | 87 ui::NativeTheme* nativeTheme = ui::NativeTheme::instance(); |
| 88 [[self bubble] setAlignment:info_bubble::kAlignRightEdgeToAnchorEdge]; | 88 [[self bubble] setAlignment:info_bubble::kAlignRightEdgeToAnchorEdge]; |
| 89 [[self bubble] setArrowLocation:info_bubble::kNoArrow]; | 89 [[self bubble] setArrowLocation:info_bubble::kNoArrow]; |
| 90 [[self bubble] setBackgroundColor: | 90 [[self bubble] setBackgroundColor: |
| 91 gfx::SkColorToCalibratedNSColor(nativeTheme->GetSystemColor( | 91 gfx::SkColorToCalibratedNSColor(nativeTheme->GetSystemColor( |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 NSButton* zoomInButton = [self addButtonWithTitleID:IDS_ZOOM_PLUS2 | 201 NSButton* zoomInButton = [self addButtonWithTitleID:IDS_ZOOM_PLUS2 |
| 202 fontSize:kZoomInOutButtonFontSize | 202 fontSize:kZoomInOutButtonFontSize |
| 203 action:@selector(zoomIn:)]; | 203 action:@selector(zoomIn:)]; |
| 204 rect.origin.x += NSWidth(rect); | 204 rect.origin.x += NSWidth(rect); |
| 205 rect.size.width = kZoomInOutButtonWidth; | 205 rect.size.width = kZoomInOutButtonWidth; |
| 206 [zoomInButton setFrame:rect]; | 206 [zoomInButton setFrame:rect]; |
| 207 | 207 |
| 208 // Separator view. | 208 // Separator view. |
| 209 rect.origin.x += NSWidth(rect); | 209 rect.origin.x += NSWidth(rect); |
| 210 rect.size.width = 1; | 210 rect.size.width = 1; |
| 211 scoped_nsobject<NSBox> separatorView([[NSBox alloc] initWithFrame:rect]); | 211 base::scoped_nsobject<NSBox> separatorView( |
| 212 [[NSBox alloc] initWithFrame:rect]); |
| 212 [separatorView setBoxType:NSBoxCustom]; | 213 [separatorView setBoxType:NSBoxCustom]; |
| 213 ui::NativeTheme* nativeTheme = ui::NativeTheme::instance(); | 214 ui::NativeTheme* nativeTheme = ui::NativeTheme::instance(); |
| 214 [separatorView setBorderColor: | 215 [separatorView setBorderColor: |
| 215 gfx::SkColorToCalibratedNSColor(nativeTheme->GetSystemColor( | 216 gfx::SkColorToCalibratedNSColor(nativeTheme->GetSystemColor( |
| 216 ui::NativeTheme::kColorId_MenuSeparatorColor))]; | 217 ui::NativeTheme::kColorId_MenuSeparatorColor))]; |
| 217 [[[self window] contentView] addSubview:separatorView]; | 218 [[[self window] contentView] addSubview:separatorView]; |
| 218 | 219 |
| 219 // Reset zoom button. | 220 // Reset zoom button. |
| 220 NSButton* resetButton = | 221 NSButton* resetButton = |
| 221 [self addButtonWithTitleID:IDS_ZOOM_SET_DEFAULT_SHORT | 222 [self addButtonWithTitleID:IDS_ZOOM_SET_DEFAULT_SHORT |
| (...skipping 12 matching lines...) Expand all Loading... |
| 234 } | 235 } |
| 235 | 236 |
| 236 - (void)autoCloseBubble { | 237 - (void)autoCloseBubble { |
| 237 if (!autoClose_) | 238 if (!autoClose_) |
| 238 return; | 239 return; |
| 239 [self close]; | 240 [self close]; |
| 240 } | 241 } |
| 241 | 242 |
| 242 - (NSAttributedString*)attributedStringWithString:(NSString*)string | 243 - (NSAttributedString*)attributedStringWithString:(NSString*)string |
| 243 fontSize:(CGFloat)fontSize { | 244 fontSize:(CGFloat)fontSize { |
| 244 scoped_nsobject<NSMutableParagraphStyle> paragraphStyle( | 245 base::scoped_nsobject<NSMutableParagraphStyle> paragraphStyle( |
| 245 [[NSMutableParagraphStyle alloc] init]); | 246 [[NSMutableParagraphStyle alloc] init]); |
| 246 [paragraphStyle setAlignment:NSCenterTextAlignment]; | 247 [paragraphStyle setAlignment:NSCenterTextAlignment]; |
| 247 NSDictionary* attributes = @{ | 248 NSDictionary* attributes = @{ |
| 248 NSFontAttributeName: | 249 NSFontAttributeName: |
| 249 [NSFont systemFontOfSize:fontSize], | 250 [NSFont systemFontOfSize:fontSize], |
| 250 NSForegroundColorAttributeName: | 251 NSForegroundColorAttributeName: |
| 251 [NSColor colorWithCalibratedWhite:0.58 alpha:1.0], | 252 [NSColor colorWithCalibratedWhite:0.58 alpha:1.0], |
| 252 NSParagraphStyleAttributeName: | 253 NSParagraphStyleAttributeName: |
| 253 paragraphStyle.get() | 254 paragraphStyle.get() |
| 254 }; | 255 }; |
| 255 return [[[NSAttributedString alloc] | 256 return [[[NSAttributedString alloc] |
| 256 initWithString:string | 257 initWithString:string |
| 257 attributes:attributes] autorelease]; | 258 attributes:attributes] autorelease]; |
| 258 } | 259 } |
| 259 | 260 |
| 260 - (NSButton*)addButtonWithTitleID:(int)titleID | 261 - (NSButton*)addButtonWithTitleID:(int)titleID |
| 261 fontSize:(CGFloat)fontSize | 262 fontSize:(CGFloat)fontSize |
| 262 action:(SEL)action { | 263 action:(SEL)action { |
| 263 scoped_nsobject<NSButton> button( | 264 base::scoped_nsobject<NSButton> button( |
| 264 [[ZoomHoverButton alloc] initWithFrame:NSZeroRect]); | 265 [[ZoomHoverButton alloc] initWithFrame:NSZeroRect]); |
| 265 NSString* title = l10n_util::GetNSStringWithFixup(titleID); | 266 NSString* title = l10n_util::GetNSStringWithFixup(titleID); |
| 266 [button setAttributedTitle:[self attributedStringWithString:title | 267 [button setAttributedTitle:[self attributedStringWithString:title |
| 267 fontSize:fontSize]]; | 268 fontSize:fontSize]]; |
| 268 [[button cell] setBordered:NO]; | 269 [[button cell] setBordered:NO]; |
| 269 [button setTarget:self]; | 270 [button setTarget:self]; |
| 270 [button setAction:action]; | 271 [button setAction:action]; |
| 271 [[[self window] contentView] addSubview:button]; | 272 [[[self window] contentView] addSubview:button]; |
| 272 return button.autorelease(); | 273 return button.autorelease(); |
| 273 } | 274 } |
| 274 | 275 |
| 275 - (NSTextField*)addZoomPercentTextField { | 276 - (NSTextField*)addZoomPercentTextField { |
| 276 scoped_nsobject<NSTextField> textField( | 277 base::scoped_nsobject<NSTextField> textField( |
| 277 [[NSTextField alloc] initWithFrame:NSZeroRect]); | 278 [[NSTextField alloc] initWithFrame:NSZeroRect]); |
| 278 [textField setEditable:NO]; | 279 [textField setEditable:NO]; |
| 279 [textField setBordered:NO]; | 280 [textField setBordered:NO]; |
| 280 [textField setDrawsBackground:NO]; | 281 [textField setDrawsBackground:NO]; |
| 281 [[[self window] contentView] addSubview:textField]; | 282 [[[self window] contentView] addSubview:textField]; |
| 282 return textField.autorelease(); | 283 return textField.autorelease(); |
| 283 } | 284 } |
| 284 | 285 |
| 285 - (void)updateAutoCloseTimer { | 286 - (void)updateAutoCloseTimer { |
| 286 [NSObject cancelPreviousPerformRequestsWithTarget:self | 287 [NSObject cancelPreviousPerformRequestsWithTarget:self |
| (...skipping 18 matching lines...) Expand all Loading... |
| 305 ui::NativeTheme::kColorId_FocusedMenuItemBackgroundColor)) set]; | 306 ui::NativeTheme::kColorId_FocusedMenuItemBackgroundColor)) set]; |
| 306 NSRectFillUsingOperation(bounds, NSCompositeSourceOver); | 307 NSRectFillUsingOperation(bounds, NSCompositeSourceOver); |
| 307 } | 308 } |
| 308 | 309 |
| 309 [[self cell] drawTitle:[self attributedTitle] | 310 [[self cell] drawTitle:[self attributedTitle] |
| 310 withFrame:bounds | 311 withFrame:bounds |
| 311 inView:self]; | 312 inView:self]; |
| 312 } | 313 } |
| 313 | 314 |
| 314 @end | 315 @end |
| OLD | NEW |