| 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 #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" |
| 11 #include "base/mac/scoped_nsautorelease_pool.h" | 11 #include "base/mac/scoped_nsautorelease_pool.h" |
| 12 #include "chrome/browser/themes/theme_service.h" | 12 #include "chrome/browser/themes/theme_service.h" |
| 13 #import "chrome/browser/ui/cocoa/hover_image_button.h" | 13 #import "chrome/browser/ui/cocoa/hover_image_button.h" |
| 14 #import "chrome/browser/ui/cocoa/nsview_additions.h" | 14 #import "chrome/browser/ui/cocoa/nsview_additions.h" |
| 15 #import "chrome/browser/ui/cocoa/themed_window.h" | 15 #import "chrome/browser/ui/cocoa/themed_window.h" |
| 16 #import "chrome/browser/ui/cocoa/tracking_area.h" | 16 #import "chrome/browser/ui/cocoa/tracking_area.h" |
| 17 #import "chrome/browser/ui/panels/panel_window_controller_cocoa.h" | 17 #import "chrome/browser/ui/panels/panel_window_controller_cocoa.h" |
| 18 #include "grit/theme_resources_standard.h" | 18 #include "grit/theme_resources_standard.h" |
| 19 #import "third_party/GTM/AppKit/GTMNSBezierPath+RoundRect.h" | 19 #import "third_party/GTM/AppKit/GTMNSBezierPath+RoundRect.h" |
| 20 #import "third_party/GTM/AppKit/GTMNSColor+Luminance.h" | 20 #import "third_party/GTM/AppKit/GTMNSColor+Luminance.h" |
| 21 #include "ui/gfx/mac/nsimage_cache.h" | 21 #include "ui/gfx/mac/nsimage_cache.h" |
| 22 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" | 22 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
| 23 | 23 |
| 24 const int kRoundedCornerSize = 3; | |
| 25 const int kButtonPadding = 8; | 24 const int kButtonPadding = 8; |
| 26 const int kIconAndTextPadding = 5; | 25 const int kIconAndTextPadding = 5; |
| 27 | 26 |
| 28 // Distance that user needs to move the mouse in order to start the drag. | 27 // Distance that user needs to move the mouse in order to start the drag. |
| 29 // Threshold is needed to differentiate drags from attempts to click the | 28 // Threshold is needed to differentiate drags from attempts to click the |
| 30 // titlebar with a twitch of the mouse pointer. | 29 // titlebar with a twitch of the mouse pointer. |
| 31 const int kDragThreshold = 3; | 30 const int kDragThreshold = 3; |
| 32 | 31 |
| 33 // 'Glint' is a speck of light that moves across the titlebar to attract a bit | 32 // 'Glint' is a speck of light that moves across the titlebar to attract a bit |
| 34 // more attention using movement in addition to color of the titlebar. | 33 // more attention using movement in addition to color of the titlebar. |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 // Initialize the settings button. | 279 // Initialize the settings button. |
| 281 NSImage* image = gfx::GetCachedImageWithName(@"balloon_wrench.pdf"); | 280 NSImage* image = gfx::GetCachedImageWithName(@"balloon_wrench.pdf"); |
| 282 [settingsButton_ setDefaultImage:image]; | 281 [settingsButton_ setDefaultImage:image]; |
| 283 [settingsButton_ setDefaultOpacity:0.6]; | 282 [settingsButton_ setDefaultOpacity:0.6]; |
| 284 [settingsButton_ setHoverImage:image]; | 283 [settingsButton_ setHoverImage:image]; |
| 285 [settingsButton_ setHoverOpacity:0.9]; | 284 [settingsButton_ setHoverOpacity:0.9]; |
| 286 [settingsButton_ setPressedImage:image]; | 285 [settingsButton_ setPressedImage:image]; |
| 287 [settingsButton_ setPressedOpacity:1.0]; | 286 [settingsButton_ setPressedOpacity:1.0]; |
| 288 [[settingsButton_ cell] setHighlightsBy:NSNoCellMask]; | 287 [[settingsButton_ cell] setHighlightsBy:NSNoCellMask]; |
| 289 [self checkMouseAndUpdateSettingsButtonVisibility]; | 288 [self checkMouseAndUpdateSettingsButtonVisibility]; |
| 289 [self updateWrenchLayout]; |
| 290 | 290 |
| 291 [self updateCloseButtonLayout]; | 291 [self updateCloseButtonLayout]; |
| 292 | 292 |
| 293 // Set autoresizing behavior: glued to edges on left, top and right. | 293 // Set autoresizing behavior: glued to edges on left, top and right. |
| 294 [self setAutoresizingMask:(NSViewMinYMargin | NSViewWidthSizable)]; | 294 [self setAutoresizingMask:(NSViewMinYMargin | NSViewWidthSizable)]; |
| 295 | 295 |
| 296 [[NSNotificationCenter defaultCenter] | 296 [[NSNotificationCenter defaultCenter] |
| 297 addObserver:self | 297 addObserver:self |
| 298 selector:@selector(didChangeTheme:) | 298 selector:@selector(didChangeTheme:) |
| 299 name:kBrowserThemeDidChangeNotification | 299 name:kBrowserThemeDidChangeNotification |
| (...skipping 27 matching lines...) Expand all Loading... |
| 327 [self addSubview:icon_ positioned:NSWindowBelow relativeTo:overlay_]; | 327 [self addSubview:icon_ positioned:NSWindowBelow relativeTo:overlay_]; |
| 328 [icon_ setWantsLayer:YES]; | 328 [icon_ setWantsLayer:YES]; |
| 329 } | 329 } |
| 330 [self updateIconAndTitleLayout]; | 330 [self updateIconAndTitleLayout]; |
| 331 } | 331 } |
| 332 | 332 |
| 333 - (NSView*)icon { | 333 - (NSView*)icon { |
| 334 return icon_; | 334 return icon_; |
| 335 } | 335 } |
| 336 | 336 |
| 337 - (void)updateWrenchLayout { |
| 338 NSRect bounds = [self bounds]; |
| 339 NSRect settingsButtonFrame = [settingsButtonWrapper_ frame]; |
| 340 settingsButtonFrame.origin.x = NSWidth(bounds) - NSWidth(settingsButtonFrame); |
| 341 settingsButtonFrame.origin.y = |
| 342 (NSHeight(bounds) - NSHeight(settingsButtonFrame)) / 2; |
| 343 [settingsButtonWrapper_ setFrame:settingsButtonFrame]; |
| 344 } |
| 345 |
| 337 - (void)updateCloseButtonLayout { | 346 - (void)updateCloseButtonLayout { |
| 338 NSRect buttonFrame = [closeButton_ frame]; | 347 NSRect buttonFrame = [closeButton_ frame]; |
| 339 NSRect bounds = [self bounds]; | 348 NSRect bounds = [self bounds]; |
| 340 | 349 |
| 341 buttonFrame.origin.x = kButtonPadding; | 350 buttonFrame.origin.x = kButtonPadding; |
| 342 // Lower Close Button's frame 1 px to avoid it 'peeking' in MINIMIZED mode. | 351 // Lower Close Button's frame 1 px to avoid it 'peeking' in MINIMIZED mode. |
| 343 buttonFrame.origin.y = (NSHeight(bounds) - NSHeight(buttonFrame)) / 2 - 1; | 352 buttonFrame.origin.y = (NSHeight(bounds) - NSHeight(buttonFrame)) / 2 - 1; |
| 344 [closeButton_ setFrame:buttonFrame]; | 353 [closeButton_ setFrame:buttonFrame]; |
| 345 if (!closeButtonTrackingArea_.get()) { | 354 if (!closeButtonTrackingArea_.get()) { |
| 346 closeButtonTrackingArea_.reset( | 355 closeButtonTrackingArea_.reset( |
| 347 [[CrTrackingArea alloc] initWithRect:[closeButton_ bounds] | 356 [[CrTrackingArea alloc] initWithRect:[closeButton_ bounds] |
| 348 options:(NSTrackingMouseEnteredAndExited | | 357 options:(NSTrackingMouseEnteredAndExited | |
| 349 NSTrackingActiveAlways) | 358 NSTrackingActiveAlways) |
| 350 proxiedOwner:self | 359 proxiedOwner:self |
| 351 userInfo:nil]); | 360 userInfo:nil]); |
| 352 NSWindow* panelWindow = [self window]; | 361 NSWindow* panelWindow = [self window]; |
| 353 [closeButtonTrackingArea_.get() clearOwnerWhenWindowWillClose:panelWindow]; | 362 [closeButtonTrackingArea_.get() clearOwnerWhenWindowWillClose:panelWindow]; |
| 354 [closeButton_ addTrackingArea:closeButtonTrackingArea_.get()]; | 363 [closeButton_ addTrackingArea:closeButtonTrackingArea_.get()]; |
| 355 } | 364 } |
| 356 } | 365 } |
| 357 | 366 |
| 358 - (void)updateIconAndTitleLayout { | 367 - (void)updateIconAndTitleLayout { |
| 359 NSRect closeButtonFrame = [closeButton_ frame]; | 368 NSRect closeButtonFrame = [closeButton_ frame]; |
| 360 NSRect iconFrame = [icon_ frame]; | 369 NSRect iconFrame = [icon_ frame]; |
| 370 // NSTextField for title_ is set to Layout:Truncate, LineBreaks:TruncateTail |
| 371 // in Interface Builder so it is sized in a single-line mode. |
| 361 [title_ sizeToFit]; | 372 [title_ sizeToFit]; |
| 362 NSRect titleFrame = [title_ frame]; | 373 NSRect titleFrame = [title_ frame]; |
| 363 NSRect settingsButtonFrame = [settingsButtonWrapper_ frame]; | 374 NSRect settingsButtonFrame = [settingsButtonWrapper_ frame]; |
| 364 NSRect bounds = [self bounds]; | 375 NSRect bounds = [self bounds]; |
| 365 | 376 |
| 366 // Place the icon and title at the center of the titlebar. | 377 // Place the icon and title at the center of the titlebar. |
| 367 int iconWidthWithPadding = NSWidth(iconFrame) + kIconAndTextPadding; | 378 int iconWidthWithPadding = NSWidth(iconFrame) + kIconAndTextPadding; |
| 368 int titleWidth = NSWidth(titleFrame); | 379 int titleWidth = NSWidth(titleFrame); |
| 369 int availableWidth = NSWidth(bounds) - kButtonPadding * 4 - | 380 int availableWidth = NSWidth(bounds) - kButtonPadding * 4 - |
| 370 NSWidth(closeButtonFrame) - NSWidth(settingsButtonFrame); | 381 NSWidth(closeButtonFrame) - NSWidth(settingsButtonFrame); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 396 | 407 |
| 397 - (void)mouseEntered:(NSEvent*)event { | 408 - (void)mouseEntered:(NSEvent*)event { |
| 398 [[closeButton_ cell] setHighlighted:YES]; | 409 [[closeButton_ cell] setHighlighted:YES]; |
| 399 } | 410 } |
| 400 | 411 |
| 401 - (void)mouseExited:(NSEvent*)event { | 412 - (void)mouseExited:(NSEvent*)event { |
| 402 [[closeButton_ cell] setHighlighted:NO]; | 413 [[closeButton_ cell] setHighlighted:NO]; |
| 403 } | 414 } |
| 404 | 415 |
| 405 - (void)didChangeFrame:(NSNotification*)notification { | 416 - (void)didChangeFrame:(NSNotification*)notification { |
| 417 [self updateWrenchLayout]; |
| 406 [self updateIconAndTitleLayout]; | 418 [self updateIconAndTitleLayout]; |
| 407 } | 419 } |
| 408 | 420 |
| 409 - (void)didChangeTheme:(NSNotification*)notification { | 421 - (void)didChangeTheme:(NSNotification*)notification { |
| 410 [self setNeedsDisplay:YES]; | 422 [self setNeedsDisplay:YES]; |
| 411 } | 423 } |
| 412 | 424 |
| 413 - (void)didChangeMainWindow:(NSNotification*)notification { | 425 - (void)didChangeMainWindow:(NSNotification*)notification { |
| 414 [self setNeedsDisplay:YES]; | 426 [self setNeedsDisplay:YES]; |
| 415 [self checkMouseAndUpdateSettingsButtonVisibility]; | 427 [self checkMouseAndUpdateSettingsButtonVisibility]; |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 639 } | 651 } |
| 640 | 652 |
| 641 - (void)checkMouseAndUpdateSettingsButtonVisibility { | 653 - (void)checkMouseAndUpdateSettingsButtonVisibility { |
| 642 BOOL mouseOverWindow = NSPointInRect([NSEvent mouseLocation], | 654 BOOL mouseOverWindow = NSPointInRect([NSEvent mouseLocation], |
| 643 [[self window] frame]); | 655 [[self window] frame]); |
| 644 [self updateSettingsButtonVisibility:mouseOverWindow]; | 656 [self updateSettingsButtonVisibility:mouseOverWindow]; |
| 645 } | 657 } |
| 646 | 658 |
| 647 @end | 659 @end |
| 648 | 660 |
| OLD | NEW |