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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 [settingsButton_ setDefaultOpacity:0.6]; | 187 [settingsButton_ setDefaultOpacity:0.6]; |
188 [settingsButton_ setHoverImage:image]; | 188 [settingsButton_ setHoverImage:image]; |
189 [settingsButton_ setHoverOpacity:0.9]; | 189 [settingsButton_ setHoverOpacity:0.9]; |
190 [settingsButton_ setPressedImage:image]; | 190 [settingsButton_ setPressedImage:image]; |
191 [settingsButton_ setPressedOpacity:1.0]; | 191 [settingsButton_ setPressedOpacity:1.0]; |
192 [[settingsButton_ cell] setHighlightsBy:NSNoCellMask]; | 192 [[settingsButton_ cell] setHighlightsBy:NSNoCellMask]; |
193 [self checkMouseAndUpdateSettingsButtonVisibility]; | 193 [self checkMouseAndUpdateSettingsButtonVisibility]; |
194 | 194 |
195 // Update layout of controls in the titlebar. | 195 // Update layout of controls in the titlebar. |
196 [self updateCloseButtonLayout]; | 196 [self updateCloseButtonLayout]; |
197 [self updateIconAndTitleLayout]; | |
198 | 197 |
199 // Set autoresizing behavior: glued to edges on left, top and right. | 198 // Set autoresizing behavior: glued to edges on left, top and right. |
200 [self setAutoresizingMask:(NSViewMinYMargin | NSViewWidthSizable)]; | 199 [self setAutoresizingMask:(NSViewMinYMargin | NSViewWidthSizable)]; |
201 | 200 |
202 [[NSNotificationCenter defaultCenter] | 201 [[NSNotificationCenter defaultCenter] |
203 addObserver:self | 202 addObserver:self |
204 selector:@selector(didChangeTheme:) | 203 selector:@selector(didChangeTheme:) |
205 name:kBrowserThemeDidChangeNotification | 204 name:kBrowserThemeDidChangeNotification |
206 object:nil]; | 205 object:nil]; |
207 // Register for various window focus changes, so we can update our custom | 206 [[NSNotificationCenter defaultCenter] |
208 // titlebar appropriately. | 207 addObserver:self |
| 208 selector:@selector(didChangeFrame:) |
| 209 name:NSViewFrameDidChangeNotification |
| 210 object:self]; |
209 [[NSNotificationCenter defaultCenter] | 211 [[NSNotificationCenter defaultCenter] |
210 addObserver:self | 212 addObserver:self |
211 selector:@selector(didChangeMainWindow:) | 213 selector:@selector(didChangeMainWindow:) |
212 name:NSWindowDidBecomeMainNotification | 214 name:NSWindowDidBecomeMainNotification |
213 object:[self window]]; | 215 object:[self window]]; |
214 [[NSNotificationCenter defaultCenter] | 216 [[NSNotificationCenter defaultCenter] |
215 addObserver:self | 217 addObserver:self |
216 selector:@selector(didChangeMainWindow:) | 218 selector:@selector(didChangeMainWindow:) |
217 name:NSWindowDidResignMainNotification | 219 name:NSWindowDidResignMainNotification |
218 object:[self window]]; | 220 object:[self window]]; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 } | 295 } |
294 | 296 |
295 - (void)mouseEntered:(NSEvent*)event { | 297 - (void)mouseEntered:(NSEvent*)event { |
296 [[closeButton_ cell] setHighlighted:YES]; | 298 [[closeButton_ cell] setHighlighted:YES]; |
297 } | 299 } |
298 | 300 |
299 - (void)mouseExited:(NSEvent*)event { | 301 - (void)mouseExited:(NSEvent*)event { |
300 [[closeButton_ cell] setHighlighted:NO]; | 302 [[closeButton_ cell] setHighlighted:NO]; |
301 } | 303 } |
302 | 304 |
| 305 - (void)didChangeFrame:(NSNotification*)notification { |
| 306 [self updateIconAndTitleLayout]; |
| 307 } |
| 308 |
303 - (void)didChangeTheme:(NSNotification*)notification { | 309 - (void)didChangeTheme:(NSNotification*)notification { |
304 [self setNeedsDisplay:YES]; | 310 [self setNeedsDisplay:YES]; |
305 } | 311 } |
306 | 312 |
307 - (void)didChangeMainWindow:(NSNotification*)notification { | 313 - (void)didChangeMainWindow:(NSNotification*)notification { |
308 [self setNeedsDisplay:YES]; | 314 [self setNeedsDisplay:YES]; |
309 [self checkMouseAndUpdateSettingsButtonVisibility]; | 315 [self checkMouseAndUpdateSettingsButtonVisibility]; |
310 } | 316 } |
311 | 317 |
312 - (void)mouseDown:(NSEvent*)event { | 318 - (void)mouseDown:(NSEvent*)event { |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 - (BOOL)isDrawingAttention { | 410 - (BOOL)isDrawingAttention { |
405 return isDrawingAttention_; | 411 return isDrawingAttention_; |
406 } | 412 } |
407 | 413 |
408 | 414 |
409 // (Private/TestingAPI) | 415 // (Private/TestingAPI) |
410 - (PanelWindowControllerCocoa*)controller { | 416 - (PanelWindowControllerCocoa*)controller { |
411 return controller_; | 417 return controller_; |
412 } | 418 } |
413 | 419 |
| 420 - (NSTextField*)title { |
| 421 return title_; |
| 422 } |
| 423 |
414 - (void)simulateCloseButtonClick { | 424 - (void)simulateCloseButtonClick { |
415 [[closeButton_ cell] performClick:closeButton_]; | 425 [[closeButton_ cell] performClick:closeButton_]; |
416 } | 426 } |
417 | 427 |
418 - (void)pressLeftMouseButtonTitlebar { | 428 - (void)pressLeftMouseButtonTitlebar { |
419 NSEvent* event = MakeMouseEvent(NSLeftMouseDown, NSZeroPoint, 0); | 429 NSEvent* event = MakeMouseEvent(NSLeftMouseDown, NSZeroPoint, 0); |
420 [self mouseDown:event]; | 430 [self mouseDown:event]; |
421 } | 431 } |
422 | 432 |
423 - (void)releaseLeftMouseButtonTitlebar { | 433 - (void)releaseLeftMouseButtonTitlebar { |
(...skipping 26 matching lines...) Expand all Loading... |
450 } | 460 } |
451 | 461 |
452 - (void)checkMouseAndUpdateSettingsButtonVisibility { | 462 - (void)checkMouseAndUpdateSettingsButtonVisibility { |
453 BOOL mouseOverWindow = NSPointInRect([NSEvent mouseLocation], | 463 BOOL mouseOverWindow = NSPointInRect([NSEvent mouseLocation], |
454 [[self window] frame]); | 464 [[self window] frame]); |
455 [self updateSettingsButtonVisibility:mouseOverWindow]; | 465 [self updateSettingsButtonVisibility:mouseOverWindow]; |
456 } | 466 } |
457 | 467 |
458 @end | 468 @end |
459 | 469 |
OLD | NEW |