| 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 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "chrome/browser/themes/theme_service.h" |
| 11 #import "chrome/browser/ui/cocoa/themed_window.h" |
| 10 #import "chrome/browser/ui/cocoa/tracking_area.h" | 12 #import "chrome/browser/ui/cocoa/tracking_area.h" |
| 11 #import "chrome/browser/ui/panels/panel_window_controller_cocoa.h" | 13 #import "chrome/browser/ui/panels/panel_window_controller_cocoa.h" |
| 12 #import "third_party/GTM/AppKit/GTMNSBezierPath+RoundRect.h" | 14 #import "third_party/GTM/AppKit/GTMNSBezierPath+RoundRect.h" |
| 15 #include "ui/base/theme_provider.h" |
| 13 | 16 |
| 14 const int kRoundedCornerSize = 6; | 17 const int kRoundedCornerSize = 6; |
| 15 const int kCloseButtonLeftPadding = 8; | 18 const int kCloseButtonLeftPadding = 8; |
| 16 | 19 |
| 17 @implementation PanelTitlebarViewCocoa | 20 @implementation PanelTitlebarViewCocoa |
| 18 | 21 |
| 19 - (id)initWithFrame:(NSRect)frame { | 22 - (id)initWithFrame:(NSRect)frame { |
| 20 if ((self = [super initWithFrame:frame])) { | 23 if ((self = [super initWithFrame:frame])) { |
| 21 // Create standard OSX Close Button. | 24 // Create standard OSX Close Button. |
| 22 closeButton_ = [NSWindow standardWindowButton:NSWindowCloseButton | 25 closeButton_ = [NSWindow standardWindowButton:NSWindowCloseButton |
| (...skipping 15 matching lines...) Expand all Loading... |
| 38 [[self controller] closePanel]; | 41 [[self controller] closePanel]; |
| 39 } | 42 } |
| 40 | 43 |
| 41 - (void)drawRect:(NSRect)rect { | 44 - (void)drawRect:(NSRect)rect { |
| 42 NSBezierPath* path = | 45 NSBezierPath* path = |
| 43 [NSBezierPath gtm_bezierPathWithRoundRect:[self bounds] | 46 [NSBezierPath gtm_bezierPathWithRoundRect:[self bounds] |
| 44 topLeftCornerRadius:kRoundedCornerSize | 47 topLeftCornerRadius:kRoundedCornerSize |
| 45 topRightCornerRadius:kRoundedCornerSize | 48 topRightCornerRadius:kRoundedCornerSize |
| 46 bottomLeftCornerRadius:0.0 | 49 bottomLeftCornerRadius:0.0 |
| 47 bottomRightCornerRadius:0.0]; | 50 bottomRightCornerRadius:0.0]; |
| 48 // TODO(dimich): paint theme image here. | 51 [path addClip]; |
| 49 [[NSColor colorWithDeviceRed:1 green:1 blue:0 alpha:0.9] setFill]; | 52 NSPoint phase = [[self window] themePatternPhase]; |
| 50 [path fill]; | 53 [[NSGraphicsContext currentContext] setPatternPhase:phase]; |
| 51 [[NSColor colorWithCalibratedWhite:0.4 alpha:1.0] set]; | 54 [self drawBackgroundWithOpaque:YES]; |
| 52 NSPoint from = [self bounds].origin; | |
| 53 NSPoint to = NSMakePoint(from.x + NSWidth([self bounds]), from.y); | |
| 54 [NSBezierPath strokeLineFromPoint:from toPoint:to]; | |
| 55 } | 55 } |
| 56 | 56 |
| 57 - (void)attach { | 57 - (void)attach { |
| 58 // Interface Builder can not put a view as a sibling of contentView, | 58 // Interface Builder can not put a view as a sibling of contentView, |
| 59 // so need to do it here. Placing the titleView as a last child of | 59 // so need to do it here. Placing the titleView as a last child of |
| 60 // internal view allows it to draw on top of the titlebar. | 60 // internal view allows it to draw on top of the titlebar. |
| 61 [[[[controller_ window] contentView] superview] addSubview:self]; | 61 [[[[controller_ window] contentView] superview] addSubview:self]; |
| 62 | 62 |
| 63 // Figure out the rectangle of the titlebar and set us on top of it. | 63 // Figure out the rectangle of the titlebar and set us on top of it. |
| 64 // The titlebar covers window's root view where not covered by contentView. | 64 // The titlebar covers window's root view where not covered by contentView. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 77 NSMaxY(rootViewBounds) - NSMaxY(contentFrame)); | 77 NSMaxY(rootViewBounds) - NSMaxY(contentFrame)); |
| 78 [self setFrame:titlebarFrame]; | 78 [self setFrame:titlebarFrame]; |
| 79 | 79 |
| 80 // Update layout of controls in the titlebar. | 80 // Update layout of controls in the titlebar. |
| 81 [self updateCloseButtonLayout]; | 81 [self updateCloseButtonLayout]; |
| 82 | 82 |
| 83 // Set autoresizing behavior: glued to edges on left, top and right. | 83 // Set autoresizing behavior: glued to edges on left, top and right. |
| 84 [self setAutoresizingMask:(NSViewMinYMargin | NSViewWidthSizable)]; | 84 [self setAutoresizingMask:(NSViewMinYMargin | NSViewWidthSizable)]; |
| 85 } | 85 } |
| 86 | 86 |
| 87 - (void)setTitle:(NSString*)newTitle { |
| 88 // TODO(dcheng): Implement. |
| 89 } |
| 90 |
| 87 - (void)updateCloseButtonLayout { | 91 - (void)updateCloseButtonLayout { |
| 88 NSRect buttonBounds = [closeButton_ bounds]; | 92 NSRect buttonBounds = [closeButton_ bounds]; |
| 89 NSRect bounds = [self bounds]; | 93 NSRect bounds = [self bounds]; |
| 90 | 94 |
| 91 int x = kCloseButtonLeftPadding; | 95 int x = kCloseButtonLeftPadding; |
| 92 int y = (NSHeight(bounds) - NSHeight(buttonBounds)) / 2; | 96 int y = (NSHeight(bounds) - NSHeight(buttonBounds)) / 2; |
| 93 NSRect buttonFrame = NSMakeRect(x, | 97 NSRect buttonFrame = NSMakeRect(x, |
| 94 y, | 98 y, |
| 95 NSWidth(buttonBounds), | 99 NSWidth(buttonBounds), |
| 96 NSHeight(buttonBounds)); | 100 NSHeight(buttonBounds)); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 125 return controller_; | 129 return controller_; |
| 126 } | 130 } |
| 127 | 131 |
| 128 // (Private/TestingAPI) | 132 // (Private/TestingAPI) |
| 129 - (void)simulateCloseButtonClick { | 133 - (void)simulateCloseButtonClick { |
| 130 [[closeButton_ cell] performClick:closeButton_]; | 134 [[closeButton_ cell] performClick:closeButton_]; |
| 131 } | 135 } |
| 132 | 136 |
| 133 @end | 137 @end |
| 134 | 138 |
| OLD | NEW |