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

Side by Side Diff: chrome/browser/ui/cocoa/sad_tab_view.mm

Issue 6358008: [Mac] Organize some files into chrome/browser/ui/cocoa/tab_contents/.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 11 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
(Empty)
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/cocoa/sad_tab_view.h"
6
7 #include "app/resource_bundle.h"
8 #include "base/logging.h"
9 #import "chrome/browser/ui/cocoa/hyperlink_button_cell.h"
10 #include "grit/theme_resources.h"
11 #import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h"
12
13 // Offset above vertical middle of page where contents of page start.
14 static const CGFloat kSadTabOffset = -64;
15 // Padding between icon and title.
16 static const CGFloat kIconTitleSpacing = 20;
17 // Padding between title and message.
18 static const CGFloat kTitleMessageSpacing = 15;
19 // Padding between message and link.
20 static const CGFloat kMessageLinkSpacing = 15;
21 // Paddings on left and right of page.
22 static const CGFloat kTabHorzMargin = 13;
23
24 @implementation SadTabView
25
26 - (void)awakeFromNib {
27 // Load resource for image and set it.
28 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
29 NSImage* image = rb.GetNativeImageNamed(IDR_SAD_TAB);
30 DCHECK(image);
31 [image_ setImage:image];
32
33 // Set font for title.
34 NSFont* titleFont = [NSFont boldSystemFontOfSize:[NSFont systemFontSize]];
35 [title_ setFont:titleFont];
36
37 // Set font for message.
38 NSFont* messageFont = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]];
39 [message_ setFont:messageFont];
40
41 // If necessary, set font and color for link.
42 if (linkButton_) {
43 [linkButton_ setFont:messageFont];
44 [linkCell_ setTextColor:[NSColor whiteColor]];
45 }
46
47 // Initialize background color.
48 NSColor* backgroundColor = [[NSColor colorWithCalibratedRed:(35.0f/255.0f)
49 green:(48.0f/255.0f)
50 blue:(64.0f/255.0f)
51 alpha:1.0] retain];
52 backgroundColor_.reset(backgroundColor);
53 }
54
55 - (void)drawRect:(NSRect)dirtyRect {
56 // Paint background.
57 [backgroundColor_ set];
58 NSRectFill(dirtyRect);
59 }
60
61 - (void)resizeSubviewsWithOldSize:(NSSize)oldSize {
62 NSRect newBounds = [self bounds];
63 CGFloat maxWidth = NSWidth(newBounds) - (kTabHorzMargin * 2);
64 BOOL callSizeToFit = (messageSize_.width == 0);
65
66 // Set new frame origin for image.
67 NSRect iconFrame = [image_ frame];
68 CGFloat iconX = (maxWidth - NSWidth(iconFrame)) / 2;
69 CGFloat iconY =
70 MIN(((NSHeight(newBounds) - NSHeight(iconFrame)) / 2) - kSadTabOffset,
71 NSHeight(newBounds) - NSHeight(iconFrame));
72 iconX = floor(iconX);
73 iconY = floor(iconY);
74 [image_ setFrameOrigin:NSMakePoint(iconX, iconY)];
75
76 // Set new frame origin for title.
77 if (callSizeToFit)
78 [title_ sizeToFit];
79 NSRect titleFrame = [title_ frame];
80 CGFloat titleX = (maxWidth - NSWidth(titleFrame)) / 2;
81 CGFloat titleY = iconY - kIconTitleSpacing - NSHeight(titleFrame);
82 [title_ setFrameOrigin:NSMakePoint(titleX, titleY)];
83
84 // Set new frame for message, wrapping or unwrapping the text if necessary.
85 if (callSizeToFit) {
86 [message_ sizeToFit];
87 messageSize_ = [message_ frame].size;
88 }
89 NSRect messageFrame = [message_ frame];
90 if (messageSize_.width > maxWidth) { // Need to wrap message.
91 [message_ setFrameSize:NSMakeSize(maxWidth, messageSize_.height)];
92 CGFloat heightChange =
93 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:message_];
94 messageFrame.size.width = maxWidth;
95 messageFrame.size.height = messageSize_.height + heightChange;
96 messageFrame.origin.x = kTabHorzMargin;
97 } else {
98 if (!callSizeToFit) {
99 [message_ sizeToFit];
100 messageFrame = [message_ frame];
101 }
102 messageFrame.origin.x = (maxWidth - NSWidth(messageFrame)) / 2;
103 }
104 messageFrame.origin.y =
105 titleY - kTitleMessageSpacing - NSHeight(messageFrame);
106 [message_ setFrame:messageFrame];
107
108 if (linkButton_) {
109 if (callSizeToFit)
110 [linkButton_ sizeToFit];
111 // Set new frame origin for link.
112 NSRect linkFrame = [linkButton_ frame];
113 CGFloat linkX = (maxWidth - NSWidth(linkFrame)) / 2;
114 CGFloat linkY =
115 NSMinY(messageFrame) - kMessageLinkSpacing - NSHeight(linkFrame);
116 [linkButton_ setFrameOrigin:NSMakePoint(linkX, linkY)];
117 }
118 }
119
120 - (void)removeLinkButton {
121 if (linkButton_) {
122 [linkButton_ removeFromSuperview];
123 linkButton_ = nil;
124 }
125 }
126
127 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698