Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(504)

Side by Side Diff: chrome/browser/ui/panels/panel_titlebar_view_cocoa.mm

Issue 9956145: Remove wrench button from panel. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix per feedback Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 [self removeTrackingArea:closeButtonTrackingArea_.get()]; 116 [self removeTrackingArea:closeButtonTrackingArea_.get()];
117 [[NSNotificationCenter defaultCenter] removeObserver:self]; 117 [[NSNotificationCenter defaultCenter] removeObserver:self];
118 [self stopGlintAnimation]; 118 [self stopGlintAnimation];
119 [super dealloc]; 119 [super dealloc];
120 } 120 }
121 121
122 - (void)onCloseButtonClick:(id)sender { 122 - (void)onCloseButtonClick:(id)sender {
123 [controller_ closePanel]; 123 [controller_ closePanel];
124 } 124 }
125 125
126 - (void)onSettingsButtonClick:(id)sender {
127 [controller_ runSettingsMenu:settingsButton_];
128 }
129
130 - (void)drawRect:(NSRect)rect { 126 - (void)drawRect:(NSRect)rect {
131 ThemeService* theme = 127 ThemeService* theme =
132 static_cast<ThemeService*>([[self window] themeProvider]); 128 static_cast<ThemeService*>([[self window] themeProvider]);
133 129
134 [title_ setAlphaValue:1.0]; 130 [title_ setAlphaValue:1.0];
135 [icon_ setAlphaValue:1.0]; 131 [icon_ setAlphaValue:1.0];
136 132
137 NSColor* strokeColor = nil; 133 NSColor* strokeColor = nil;
138 NSColor* titleColor = nil; 134 NSColor* titleColor = nil;
139 135
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 NSMaxY(contentFrame), 266 NSMaxY(contentFrame),
271 NSWidth(contentFrame), 267 NSWidth(contentFrame),
272 NSMaxY(rootViewBounds) - NSMaxY(contentFrame)); 268 NSMaxY(rootViewBounds) - NSMaxY(contentFrame));
273 [self setFrame:titlebarFrame]; 269 [self setFrame:titlebarFrame];
274 270
275 [title_ setWantsLayer:YES]; 271 [title_ setWantsLayer:YES];
276 [title_ setFont:[NSFont boldSystemFontOfSize:[NSFont systemFontSize]]]; 272 [title_ setFont:[NSFont boldSystemFontOfSize:[NSFont systemFontSize]]];
277 // This draws nice tight shadow, 'sinking' text into the background. 273 // This draws nice tight shadow, 'sinking' text into the background.
278 [[title_ cell] setBackgroundStyle:NSBackgroundStyleRaised]; 274 [[title_ cell] setBackgroundStyle:NSBackgroundStyleRaised];
279 275
280 // Initialize the settings button.
281 NSImage* image = gfx::GetCachedImageWithName(@"balloon_wrench.pdf");
282 [settingsButton_ setDefaultImage:image];
283 [settingsButton_ setDefaultOpacity:0.6];
284 [settingsButton_ setHoverImage:image];
285 [settingsButton_ setHoverOpacity:0.9];
286 [settingsButton_ setPressedImage:image];
287 [settingsButton_ setPressedOpacity:1.0];
288 [[settingsButton_ cell] setHighlightsBy:NSNoCellMask];
289 [self checkMouseAndUpdateSettingsButtonVisibility];
290 [self updateWrenchLayout];
291
292 [self updateCloseButtonLayout]; 276 [self updateCloseButtonLayout];
293 277
294 // Set autoresizing behavior: glued to edges on left, top and right. 278 // Set autoresizing behavior: glued to edges on left, top and right.
295 [self setAutoresizingMask:(NSViewMinYMargin | NSViewWidthSizable)]; 279 [self setAutoresizingMask:(NSViewMinYMargin | NSViewWidthSizable)];
296 280
297 [[NSNotificationCenter defaultCenter] 281 [[NSNotificationCenter defaultCenter]
298 addObserver:self 282 addObserver:self
299 selector:@selector(didChangeTheme:) 283 selector:@selector(didChangeTheme:)
300 name:kBrowserThemeDidChangeNotification 284 name:kBrowserThemeDidChangeNotification
301 object:nil]; 285 object:nil];
(...skipping 26 matching lines...) Expand all
328 [self addSubview:icon_ positioned:NSWindowBelow relativeTo:overlay_]; 312 [self addSubview:icon_ positioned:NSWindowBelow relativeTo:overlay_];
329 [icon_ setWantsLayer:YES]; 313 [icon_ setWantsLayer:YES];
330 } 314 }
331 [self updateIconAndTitleLayout]; 315 [self updateIconAndTitleLayout];
332 } 316 }
333 317
334 - (NSView*)icon { 318 - (NSView*)icon {
335 return icon_; 319 return icon_;
336 } 320 }
337 321
338 - (void)updateWrenchLayout {
339 NSRect bounds = [self bounds];
340 NSRect settingsButtonFrame = [settingsButtonWrapper_ frame];
341 settingsButtonFrame.origin.x = NSWidth(bounds) - NSWidth(settingsButtonFrame);
342 settingsButtonFrame.origin.y =
343 (NSHeight(bounds) - NSHeight(settingsButtonFrame)) / 2;
344 [settingsButtonWrapper_ setFrame:settingsButtonFrame];
345 }
346
347 - (void)updateCloseButtonLayout { 322 - (void)updateCloseButtonLayout {
348 NSRect buttonFrame = [closeButton_ frame]; 323 NSRect buttonFrame = [closeButton_ frame];
349 NSRect bounds = [self bounds]; 324 NSRect bounds = [self bounds];
350 325
351 buttonFrame.origin.x = kButtonPadding; 326 buttonFrame.origin.x = kButtonPadding;
352 // Lower Close Button's frame 1 px to avoid it 'peeking' in MINIMIZED mode. 327 // Lower Close Button's frame 1 px to avoid it 'peeking' in MINIMIZED mode.
353 buttonFrame.origin.y = (NSHeight(bounds) - NSHeight(buttonFrame)) / 2 - 1; 328 buttonFrame.origin.y = (NSHeight(bounds) - NSHeight(buttonFrame)) / 2 - 1;
354 [closeButton_ setFrame:buttonFrame]; 329 [closeButton_ setFrame:buttonFrame];
355 if (!closeButtonTrackingArea_.get()) { 330 if (!closeButtonTrackingArea_.get()) {
356 closeButtonTrackingArea_.reset( 331 closeButtonTrackingArea_.reset(
357 [[CrTrackingArea alloc] initWithRect:[closeButton_ bounds] 332 [[CrTrackingArea alloc] initWithRect:[closeButton_ bounds]
358 options:(NSTrackingMouseEnteredAndExited | 333 options:(NSTrackingMouseEnteredAndExited |
359 NSTrackingActiveAlways) 334 NSTrackingActiveAlways)
360 proxiedOwner:self 335 proxiedOwner:self
361 userInfo:nil]); 336 userInfo:nil]);
362 NSWindow* panelWindow = [self window]; 337 NSWindow* panelWindow = [self window];
363 [closeButtonTrackingArea_.get() clearOwnerWhenWindowWillClose:panelWindow]; 338 [closeButtonTrackingArea_.get() clearOwnerWhenWindowWillClose:panelWindow];
364 [closeButton_ addTrackingArea:closeButtonTrackingArea_.get()]; 339 [closeButton_ addTrackingArea:closeButtonTrackingArea_.get()];
365 } 340 }
366 } 341 }
367 342
368 - (void)updateIconAndTitleLayout { 343 - (void)updateIconAndTitleLayout {
369 NSRect closeButtonFrame = [closeButton_ frame]; 344 NSRect closeButtonFrame = [closeButton_ frame];
370 NSRect iconFrame = [icon_ frame]; 345 NSRect iconFrame = [icon_ frame];
371 // NSTextField for title_ is set to Layout:Truncate, LineBreaks:TruncateTail 346 // NSTextField for title_ is set to Layout:Truncate, LineBreaks:TruncateTail
372 // in Interface Builder so it is sized in a single-line mode. 347 // in Interface Builder so it is sized in a single-line mode.
373 [title_ sizeToFit]; 348 [title_ sizeToFit];
374 NSRect titleFrame = [title_ frame]; 349 NSRect titleFrame = [title_ frame];
375 NSRect settingsButtonFrame = [settingsButtonWrapper_ frame];
376 NSRect bounds = [self bounds]; 350 NSRect bounds = [self bounds];
377 351
378 // Place the icon and title at the center of the titlebar. 352 // Place the icon and title at the center of the titlebar.
379 int iconWidthWithPadding = NSWidth(iconFrame) + kIconAndTextPadding; 353 int iconWidthWithPadding = NSWidth(iconFrame) + kIconAndTextPadding;
380 int titleWidth = NSWidth(titleFrame); 354 int titleWidth = NSWidth(titleFrame);
381 int availableWidth = NSWidth(bounds) - kButtonPadding * 4 - 355 int availableWidth = NSWidth(bounds) - kButtonPadding * 2 -
382 NSWidth(closeButtonFrame) - NSWidth(settingsButtonFrame); 356 NSWidth(closeButtonFrame);
383 if (iconWidthWithPadding + titleWidth > availableWidth) 357 if (iconWidthWithPadding + titleWidth > availableWidth)
384 titleWidth = availableWidth - iconWidthWithPadding; 358 titleWidth = availableWidth - iconWidthWithPadding;
385 int startX = kButtonPadding * 2 + NSWidth(closeButtonFrame) + 359 int startX = kButtonPadding * 2 + NSWidth(closeButtonFrame) +
386 (availableWidth - iconWidthWithPadding - titleWidth) / 2; 360 (availableWidth - iconWidthWithPadding - titleWidth) / 2;
387 361
388 iconFrame.origin.x = startX; 362 iconFrame.origin.x = startX;
389 iconFrame.origin.y = (NSHeight(bounds) - NSHeight(iconFrame)) / 2; 363 iconFrame.origin.y = (NSHeight(bounds) - NSHeight(iconFrame)) / 2;
390 [icon_ setFrame:iconFrame]; 364 [icon_ setFrame:iconFrame];
391 365
392 titleFrame.origin.x = startX + iconWidthWithPadding; 366 titleFrame.origin.x = startX + iconWidthWithPadding;
(...skipping 15 matching lines...) Expand all
408 382
409 - (void)mouseEntered:(NSEvent*)event { 383 - (void)mouseEntered:(NSEvent*)event {
410 [[closeButton_ cell] setHighlighted:YES]; 384 [[closeButton_ cell] setHighlighted:YES];
411 } 385 }
412 386
413 - (void)mouseExited:(NSEvent*)event { 387 - (void)mouseExited:(NSEvent*)event {
414 [[closeButton_ cell] setHighlighted:NO]; 388 [[closeButton_ cell] setHighlighted:NO];
415 } 389 }
416 390
417 - (void)didChangeFrame:(NSNotification*)notification { 391 - (void)didChangeFrame:(NSNotification*)notification {
418 [self updateWrenchLayout];
419 [self updateIconAndTitleLayout]; 392 [self updateIconAndTitleLayout];
420 } 393 }
421 394
422 - (void)didChangeTheme:(NSNotification*)notification { 395 - (void)didChangeTheme:(NSNotification*)notification {
423 [self setNeedsDisplay:YES]; 396 [self setNeedsDisplay:YES];
424 } 397 }
425 398
426 - (void)didChangeMainWindow:(NSNotification*)notification { 399 - (void)didChangeMainWindow:(NSNotification*)notification {
427 [self setNeedsDisplay:YES]; 400 [self setNeedsDisplay:YES];
428 [self checkMouseAndUpdateSettingsButtonVisibility];
429 } 401 }
430 402
431 - (void)mouseDown:(NSEvent*)event { 403 - (void)mouseDown:(NSEvent*)event {
432 if ([controller_ isDraggable]) { 404 if ([controller_ isDraggable]) {
433 dragState_ = PANEL_DRAG_CAN_START; 405 dragState_ = PANEL_DRAG_CAN_START;
434 NSWindow* window = [self window]; 406 NSWindow* window = [self window];
435 NSPoint mouseLocationInWindow = [event locationInWindow]; 407 NSPoint mouseLocationInWindow = [event locationInWindow];
436 dragStartLocation_ = [window convertBaseToScreen:mouseLocationInWindow]; 408 dragStartLocation_ = [window convertBaseToScreen:mouseLocationInWindow];
437 dragStartYOffset_ = NSMaxY([window frame]) - dragStartLocation_.y; 409 dragStartYOffset_ = NSMaxY([window frame]) - dragStartLocation_.y;
438 } 410 }
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 } 630 }
659 631
660 - (void)cancelDragTitlebar { 632 - (void)cancelDragTitlebar {
661 [self endDrag:YES]; 633 [self endDrag:YES];
662 } 634 }
663 635
664 - (void)finishDragTitlebar { 636 - (void)finishDragTitlebar {
665 [self endDrag:NO]; 637 [self endDrag:NO];
666 } 638 }
667 639
668 - (void)updateSettingsButtonVisibility:(BOOL)mouseOverWindow {
669 // The settings button is visible if the panel is main window or the mouse is
670 // over it.
671 BOOL shouldShowSettingsButton =
672 mouseOverWindow || [[self window] isMainWindow];
673 [[settingsButtonWrapper_ animator]
674 setAlphaValue:shouldShowSettingsButton ? 1.0 : 0.0];
675 }
676
677 - (void)checkMouseAndUpdateSettingsButtonVisibility {
678 BOOL mouseOverWindow = NSPointInRect([NSEvent mouseLocation],
679 [[self window] frame]);
680 [self updateSettingsButtonVisibility:mouseOverWindow];
681 }
682
683 @end 640 @end
684 641
OLDNEW
« no previous file with comments | « chrome/browser/ui/panels/panel_titlebar_view_cocoa.h ('k') | chrome/browser/ui/panels/panel_window_controller_cocoa.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698