| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/ui/panels/panel_titlebar_view_cocoa.h" | 5 #import "chrome/browser/ui/panels/panel_titlebar_view_cocoa.h" |
| 6 | 6 |
| 7 #include <Carbon/Carbon.h> // kVK_Escape | 7 #include <Carbon/Carbon.h> // kVK_Escape |
| 8 #import <Cocoa/Cocoa.h> | 8 #import <Cocoa/Cocoa.h> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 NSImage* image = gfx::GetCachedImageWithName(@"balloon_wrench.pdf"); | 205 NSImage* image = gfx::GetCachedImageWithName(@"balloon_wrench.pdf"); |
| 206 [settingsButton_ setDefaultImage:image]; | 206 [settingsButton_ setDefaultImage:image]; |
| 207 [settingsButton_ setDefaultOpacity:0.6]; | 207 [settingsButton_ setDefaultOpacity:0.6]; |
| 208 [settingsButton_ setHoverImage:image]; | 208 [settingsButton_ setHoverImage:image]; |
| 209 [settingsButton_ setHoverOpacity:0.9]; | 209 [settingsButton_ setHoverOpacity:0.9]; |
| 210 [settingsButton_ setPressedImage:image]; | 210 [settingsButton_ setPressedImage:image]; |
| 211 [settingsButton_ setPressedOpacity:1.0]; | 211 [settingsButton_ setPressedOpacity:1.0]; |
| 212 [[settingsButton_ cell] setHighlightsBy:NSNoCellMask]; | 212 [[settingsButton_ cell] setHighlightsBy:NSNoCellMask]; |
| 213 [self checkMouseAndUpdateSettingsButtonVisibility]; | 213 [self checkMouseAndUpdateSettingsButtonVisibility]; |
| 214 | 214 |
| 215 // Update layout of controls in the titlebar. | |
| 216 [self updateCloseButtonLayout]; | 215 [self updateCloseButtonLayout]; |
| 217 | 216 |
| 218 // Set autoresizing behavior: glued to edges on left, top and right. | 217 // Set autoresizing behavior: glued to edges on left, top and right. |
| 219 [self setAutoresizingMask:(NSViewMinYMargin | NSViewWidthSizable)]; | 218 [self setAutoresizingMask:(NSViewMinYMargin | NSViewWidthSizable)]; |
| 220 | 219 |
| 221 [[NSNotificationCenter defaultCenter] | 220 [[NSNotificationCenter defaultCenter] |
| 222 addObserver:self | 221 addObserver:self |
| 223 selector:@selector(didChangeTheme:) | 222 selector:@selector(didChangeTheme:) |
| 224 name:kBrowserThemeDidChangeNotification | 223 name:kBrowserThemeDidChangeNotification |
| 225 object:nil]; | 224 object:nil]; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 | 256 |
| 258 - (NSView*)icon { | 257 - (NSView*)icon { |
| 259 return icon_; | 258 return icon_; |
| 260 } | 259 } |
| 261 | 260 |
| 262 - (void)updateCloseButtonLayout { | 261 - (void)updateCloseButtonLayout { |
| 263 NSRect buttonFrame = [closeButton_ frame]; | 262 NSRect buttonFrame = [closeButton_ frame]; |
| 264 NSRect bounds = [self bounds]; | 263 NSRect bounds = [self bounds]; |
| 265 | 264 |
| 266 buttonFrame.origin.x = kButtonPadding; | 265 buttonFrame.origin.x = kButtonPadding; |
| 267 buttonFrame.origin.y = (NSHeight(bounds) - NSHeight(buttonFrame)) / 2; | 266 // Lower Close Button's frame 1 px to avoid it 'peeking' in MINIMIZED mode. |
| 267 buttonFrame.origin.y = (NSHeight(bounds) - NSHeight(buttonFrame)) / 2 - 1; |
| 268 [closeButton_ setFrame:buttonFrame]; | 268 [closeButton_ setFrame:buttonFrame]; |
| 269 | 269 if (!closeButtonTrackingArea_.get()) { |
| 270 DCHECK(!closeButtonTrackingArea_.get()); | 270 closeButtonTrackingArea_.reset( |
| 271 closeButtonTrackingArea_.reset( | 271 [[CrTrackingArea alloc] initWithRect:[closeButton_ bounds] |
| 272 [[CrTrackingArea alloc] initWithRect:buttonFrame | 272 options:(NSTrackingMouseEnteredAndExited | |
| 273 options:(NSTrackingMouseEnteredAndExited | | 273 NSTrackingActiveAlways) |
| 274 NSTrackingActiveAlways) | 274 proxiedOwner:self |
| 275 proxiedOwner:self | 275 userInfo:nil]); |
| 276 userInfo:nil]); | 276 NSWindow* panelWindow = [self window]; |
| 277 NSWindow* panelWindow = [self window]; | 277 [closeButtonTrackingArea_.get() clearOwnerWhenWindowWillClose:panelWindow]; |
| 278 [closeButtonTrackingArea_.get() clearOwnerWhenWindowWillClose:panelWindow]; | 278 [closeButton_ addTrackingArea:closeButtonTrackingArea_.get()]; |
| 279 [self addTrackingArea:closeButtonTrackingArea_.get()]; | 279 } |
| 280 } | 280 } |
| 281 | 281 |
| 282 - (void)updateIconAndTitleLayout { | 282 - (void)updateIconAndTitleLayout { |
| 283 NSRect closeButtonFrame = [closeButton_ frame]; | 283 NSRect closeButtonFrame = [closeButton_ frame]; |
| 284 NSRect iconFrame = [icon_ frame]; | 284 NSRect iconFrame = [icon_ frame]; |
| 285 [title_ sizeToFit]; | 285 [title_ sizeToFit]; |
| 286 NSRect titleFrame = [title_ frame]; | 286 NSRect titleFrame = [title_ frame]; |
| 287 NSRect settingsButtonFrame = [settingsButtonWrapper_ frame]; | 287 NSRect settingsButtonFrame = [settingsButtonWrapper_ frame]; |
| 288 NSRect bounds = [self bounds]; | 288 NSRect bounds = [self bounds]; |
| 289 | 289 |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 } | 497 } |
| 498 | 498 |
| 499 - (void)checkMouseAndUpdateSettingsButtonVisibility { | 499 - (void)checkMouseAndUpdateSettingsButtonVisibility { |
| 500 BOOL mouseOverWindow = NSPointInRect([NSEvent mouseLocation], | 500 BOOL mouseOverWindow = NSPointInRect([NSEvent mouseLocation], |
| 501 [[self window] frame]); | 501 [[self window] frame]); |
| 502 [self updateSettingsButtonVisibility:mouseOverWindow]; | 502 [self updateSettingsButtonVisibility:mouseOverWindow]; |
| 503 } | 503 } |
| 504 | 504 |
| 505 @end | 505 @end |
| 506 | 506 |
| OLD | NEW |