Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2009 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 #include "chrome/browser/ui/cocoa/tab_contents/sad_tab_view.h" | 5 #include "chrome/browser/ui/cocoa/tab_contents/sad_tab_view.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/sys_string_conversions.h" | |
| 8 #import "chrome/browser/ui/cocoa/hyperlink_button_cell.h" | 9 #import "chrome/browser/ui/cocoa/hyperlink_button_cell.h" |
| 10 #include "chrome/browser/ui/cocoa/tab_contents/sad_tab_controller.h" | |
| 11 #import "chrome/browser/ui/cocoa/static_text_view.h" | |
| 12 #include "chrome/common/url_constants.h" | |
| 13 #include "grit/generated_resources.h" | |
| 9 #include "grit/theme_resources.h" | 14 #include "grit/theme_resources.h" |
| 10 #import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" | 15 #import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" |
| 16 #include "ui/base/l10n/l10n_util.h" | |
| 17 #include "ui/base/l10n/l10n_util_mac.h" | |
| 11 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
| 12 #include "ui/gfx/image/image.h" | 19 #include "ui/gfx/image/image.h" |
| 13 | 20 |
| 14 // Offset above vertical middle of page where contents of page start. | 21 // Offset above vertical middle of page where contents of page start. |
| 15 static const CGFloat kSadTabOffset = -64; | 22 static const CGFloat kSadTabOffset = -64; |
| 16 // Padding between icon and title. | 23 // Padding between icon and title. |
| 17 static const CGFloat kIconTitleSpacing = 20; | 24 static const CGFloat kIconTitleSpacing = 20; |
| 18 // Padding between title and message. | 25 // Padding between title and message. |
| 19 static const CGFloat kTitleMessageSpacing = 15; | 26 static const CGFloat kTitleMessageSpacing = 15; |
| 20 // Padding between message and link. | 27 // Padding between message and link. |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 32 [image_ setImage:image]; | 39 [image_ setImage:image]; |
| 33 | 40 |
| 34 // Set font for title. | 41 // Set font for title. |
| 35 NSFont* titleFont = [NSFont boldSystemFontOfSize:[NSFont systemFontSize]]; | 42 NSFont* titleFont = [NSFont boldSystemFontOfSize:[NSFont systemFontSize]]; |
| 36 [title_ setFont:titleFont]; | 43 [title_ setFont:titleFont]; |
| 37 | 44 |
| 38 // Set font for message. | 45 // Set font for message. |
| 39 NSFont* messageFont = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]; | 46 NSFont* messageFont = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]; |
| 40 [message_ setFont:messageFont]; | 47 [message_ setFont:messageFont]; |
| 41 | 48 |
| 42 // If necessary, set font and color for link. | 49 DCHECK(controller_); |
| 43 if (linkButton_) { | 50 [self initializeHelpText]; |
| 44 [linkButton_ setFont:messageFont]; | |
| 45 [linkCell_ setTextColor:[NSColor whiteColor]]; | |
| 46 } | |
| 47 | 51 |
| 48 // Initialize background color. | 52 // Initialize background color. |
| 49 NSColor* backgroundColor = [[NSColor colorWithCalibratedRed:(35.0f/255.0f) | 53 NSColor* backgroundColor = [[NSColor colorWithCalibratedRed:(35.0f/255.0f) |
| 50 green:(48.0f/255.0f) | 54 green:(48.0f/255.0f) |
| 51 blue:(64.0f/255.0f) | 55 blue:(64.0f/255.0f) |
| 52 alpha:1.0] retain]; | 56 alpha:1.0] retain]; |
| 53 backgroundColor_.reset(backgroundColor); | 57 backgroundColor_.reset(backgroundColor); |
| 54 } | 58 } |
| 55 | 59 |
| 56 - (void)drawRect:(NSRect)dirtyRect { | 60 - (void)drawRect:(NSRect)dirtyRect { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 99 if (!callSizeToFit) { | 103 if (!callSizeToFit) { |
| 100 [message_ sizeToFit]; | 104 [message_ sizeToFit]; |
| 101 messageFrame = [message_ frame]; | 105 messageFrame = [message_ frame]; |
| 102 } | 106 } |
| 103 messageFrame.origin.x = (maxWidth - NSWidth(messageFrame)) / 2; | 107 messageFrame.origin.x = (maxWidth - NSWidth(messageFrame)) / 2; |
| 104 } | 108 } |
| 105 messageFrame.origin.y = | 109 messageFrame.origin.y = |
| 106 titleY - kTitleMessageSpacing - NSHeight(messageFrame); | 110 titleY - kTitleMessageSpacing - NSHeight(messageFrame); |
| 107 [message_ setFrame:messageFrame]; | 111 [message_ setFrame:messageFrame]; |
| 108 | 112 |
| 109 if (linkButton_) { | 113 // Set new frame for help text and link. |
| 114 if (help_) { | |
| 110 if (callSizeToFit) | 115 if (callSizeToFit) |
| 111 [linkButton_ sizeToFit]; | 116 [help_.get() sizeToFit]; |
| 117 CGFloat helpHeight = [help_.get() frame].size.height; | |
| 118 [help_.get() setFrameSize:NSMakeSize(maxWidth, helpHeight)]; | |
| 112 // Set new frame origin for link. | 119 // Set new frame origin for link. |
| 113 NSRect linkFrame = [linkButton_ frame]; | 120 NSRect helpFrame = [help_.get() frame]; |
| 114 CGFloat linkX = (maxWidth - NSWidth(linkFrame)) / 2; | 121 CGFloat helpX = (maxWidth - NSWidth(helpFrame)) / 2; |
| 115 CGFloat linkY = | 122 CGFloat helpY = |
| 116 NSMinY(messageFrame) - kMessageLinkSpacing - NSHeight(linkFrame); | 123 NSMinY(messageFrame) - kMessageLinkSpacing - NSHeight(helpFrame); |
| 117 [linkButton_ setFrameOrigin:NSMakePoint(linkX, linkY)]; | 124 [help_.get() setFrameOrigin:NSMakePoint(helpX, helpY)]; |
| 118 } | 125 } |
| 119 } | 126 } |
| 120 | 127 |
| 121 - (void)removeLinkButton { | 128 - (void)removeHelpText { |
| 122 if (linkButton_) { | 129 if (help_.get()) { |
| 123 [linkButton_ removeFromSuperview]; | 130 [help_.get() removeFromSuperview]; |
| 124 linkButton_ = nil; | 131 help_.reset(nil); |
| 125 } | 132 } |
| 126 } | 133 } |
| 127 | 134 |
| 135 - (void)initializeHelpText { | |
| 136 // Replace the help placeholder NSTextField with the real help NSTextView. | |
| 137 // The former doesn't show links in a nice way, but the latter can't be added | |
| 138 // in IB without a containing scroll view, so create the NSTextView | |
| 139 // programmatically. Taken from -[InfoBarController initializeLabel]. | |
| 140 help_.reset([[StaticTextView alloc] initWithFrame:[helpPlaceholder_ frame]]); | |
| 141 [help_.get() setAutoresizingMask:[helpPlaceholder_ autoresizingMask]]; | |
| 142 [[helpPlaceholder_ superview] | |
| 143 replaceSubview:helpPlaceholder_ with:help_.get()]; | |
| 144 helpPlaceholder_ = nil; // Now released. | |
| 145 [help_.get() setDelegate:self]; | |
| 146 [help_.get() setEditable:NO]; | |
| 147 [help_.get() setDrawsBackground:NO]; | |
| 148 [help_.get() setHorizontallyResizable:NO]; | |
| 149 [help_.get() setVerticallyResizable:NO]; | |
| 150 [help_.get() setAlignment:NSCenterTextAlignment]; | |
|
Nico
2011/08/31 22:35:19
can you move the four :NO lines into the StaticTex
msw
2011/09/01 03:30:49
Done.
| |
| 151 | |
| 152 // Get the help text and link. | |
| 153 size_t linkOffset = 0; | |
| 154 NSString* helpMessage(base::SysUTF16ToNSString(l10n_util::GetStringFUTF16( | |
| 155 IDS_SAD_TAB_HELP_MESSAGE, string16(), &linkOffset))); | |
| 156 NSString* helpLink = l10n_util::GetNSString(IDS_SAD_TAB_HELP_LINK); | |
| 157 NSFont* font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]; | |
| 158 [help_.get() setMessageAndLink:helpMessage | |
| 159 withLink:helpLink | |
| 160 atOffset:linkOffset | |
| 161 font:font | |
| 162 messageColor:[NSColor whiteColor] | |
| 163 linkColor:[NSColor whiteColor]]; | |
| 164 } | |
| 165 | |
| 166 // Called when someone clicks on the embedded link. | |
| 167 - (BOOL) textView:(NSTextView*)textView | |
| 168 clickedOnLink:(id)link | |
| 169 atIndex:(NSUInteger)charIndex { | |
| 170 if (controller_) | |
| 171 [controller_ openLearnMoreAboutCrashLink:nil]; | |
| 172 return YES; | |
| 173 } | |
| 174 | |
| 128 @end | 175 @end |
| OLD | NEW |