| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/cocoa/page_info_bubble_controller.h" | 5 #import "chrome/browser/cocoa/page_info_bubble_controller.h" |
| 6 | 6 |
| 7 #include "app/l10n_util_mac.h" | 7 #include "app/l10n_util_mac.h" |
| 8 #include "app/resource_bundle.h" | |
| 9 #include "base/sys_string_conversions.h" | 8 #include "base/sys_string_conversions.h" |
| 10 #include "chrome/browser/cert_store.h" | 9 #include "chrome/browser/cert_store.h" |
| 11 #include "chrome/browser/certificate_viewer.h" | 10 #include "chrome/browser/certificate_viewer.h" |
| 12 #import "chrome/browser/cocoa/browser_window_controller.h" | 11 #import "chrome/browser/cocoa/browser_window_controller.h" |
| 13 #import "chrome/browser/cocoa/location_bar/location_bar_view_mac.h" | 12 #import "chrome/browser/cocoa/location_bar/location_bar_view_mac.h" |
| 14 #import "chrome/browser/cocoa/info_bubble_view.h" | 13 #import "chrome/browser/cocoa/info_bubble_view.h" |
| 15 #import "chrome/browser/cocoa/info_bubble_window.h" | 14 #import "chrome/browser/cocoa/info_bubble_window.h" |
| 16 #include "chrome/browser/profile.h" | 15 #include "chrome/browser/profile.h" |
| 17 #include "grit/generated_resources.h" | 16 #include "grit/generated_resources.h" |
| 18 #include "grit/theme_resources.h" | |
| 19 #include "net/base/cert_status_flags.h" | 17 #include "net/base/cert_status_flags.h" |
| 20 #include "net/base/x509_certificate.h" | 18 #include "net/base/x509_certificate.h" |
| 21 #import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" | 19 #import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" |
| 22 | 20 |
| 23 @interface PageInfoBubbleController (Private) | 21 @interface PageInfoBubbleController (Private) |
| 24 - (PageInfoModel*)model; | 22 - (PageInfoModel*)model; |
| 25 - (NSButton*)certificateButtonWithFrame:(NSRect)frame; | 23 - (NSButton*)certificateButtonWithFrame:(NSRect)frame; |
| 26 - (NSImage*)statusIconForState:(PageInfoModel::SectionInfoState)state; | |
| 27 - (void)configureTextFieldAsLabel:(NSTextField*)textField; | 24 - (void)configureTextFieldAsLabel:(NSTextField*)textField; |
| 28 - (CGFloat)addTitleViewForInfo:(const PageInfoModel::SectionInfo&)info | 25 - (CGFloat)addTitleViewForInfo:(const PageInfoModel::SectionInfo&)info |
| 29 toSubviews:(NSMutableArray*)subviews | 26 toSubviews:(NSMutableArray*)subviews |
| 30 atPoint:(NSPoint)point; | 27 atPoint:(NSPoint)point; |
| 31 - (CGFloat)addDescriptionViewForInfo:(const PageInfoModel::SectionInfo&)info | 28 - (CGFloat)addDescriptionViewForInfo:(const PageInfoModel::SectionInfo&)info |
| 32 toSubviews:(NSMutableArray*)subviews | 29 toSubviews:(NSMutableArray*)subviews |
| 33 atPoint:(NSPoint)point; | 30 atPoint:(NSPoint)point; |
| 34 - (CGFloat)addCertificateButtonToSubviews:(NSMutableArray*)subviews | 31 - (CGFloat)addCertificateButtonToSubviews:(NSMutableArray*)subviews |
| 35 atOffset:(CGFloat)offset; | 32 atOffset:(CGFloat)offset; |
| 36 - (void)addImageViewForInfo:(const PageInfoModel::SectionInfo&)info | 33 - (void)addImageViewForInfo:(const PageInfoModel::SectionInfo&)info |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 styleMask:NSBorderlessWindowMask | 139 styleMask:NSBorderlessWindowMask |
| 143 backing:NSBackingStoreBuffered | 140 backing:NSBackingStoreBuffered |
| 144 defer:NO]); | 141 defer:NO]); |
| 145 | 142 |
| 146 NSPoint anchorPoint = AnchorPointFromParentWindow(parentWindow, 0); | 143 NSPoint anchorPoint = AnchorPointFromParentWindow(parentWindow, 0); |
| 147 if ((self = [super initWithWindow:window.get() | 144 if ((self = [super initWithWindow:window.get() |
| 148 parentWindow:parentWindow | 145 parentWindow:parentWindow |
| 149 anchoredAt:anchorPoint])) { | 146 anchoredAt:anchorPoint])) { |
| 150 model_.reset(model); | 147 model_.reset(model); |
| 151 bridge_.reset(bridge); | 148 bridge_.reset(bridge); |
| 152 | |
| 153 // Load the image refs. | |
| 154 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
| 155 okImage_.reset([rb.GetNSImageNamed(IDR_PAGEINFO_GOOD) retain]); | |
| 156 DCHECK_GE(kImageSize, [okImage_ size].width); | |
| 157 DCHECK_GE(kImageSize, [okImage_ size].height); | |
| 158 warningMinorImage_.reset( | |
| 159 [rb.GetNSImageNamed(IDR_PAGEINFO_WARNING_MINOR) retain]); | |
| 160 DCHECK_GE(kImageSize, [warningMinorImage_ size].width); | |
| 161 DCHECK_GE(kImageSize, [warningMinorImage_ size].height); | |
| 162 warningMajorImage_.reset( | |
| 163 [rb.GetNSImageNamed(IDR_PAGEINFO_WARNING_MAJOR) retain]); | |
| 164 DCHECK_GE(kImageSize, [warningMajorImage_ size].width); | |
| 165 DCHECK_GE(kImageSize, [warningMajorImage_ size].height); | |
| 166 errorImage_.reset([rb.GetNSImageNamed(IDR_PAGEINFO_BAD) retain]); | |
| 167 DCHECK_GE(kImageSize, [errorImage_ size].width); | |
| 168 DCHECK_GE(kImageSize, [errorImage_ size].height); | |
| 169 | |
| 170 [[self bubble] setArrowLocation:info_bubble::kTopLeft]; | 149 [[self bubble] setArrowLocation:info_bubble::kTopLeft]; |
| 171 | |
| 172 [self performLayout]; | 150 [self performLayout]; |
| 173 } | 151 } |
| 174 return self; | 152 return self; |
| 175 } | 153 } |
| 176 | 154 |
| 177 - (PageInfoModel*)model { | 155 - (PageInfoModel*)model { |
| 178 return model_.get(); | 156 return model_.get(); |
| 179 } | 157 } |
| 180 | 158 |
| 181 - (IBAction)showCertWindow:(id)sender { | 159 - (IBAction)showCertWindow:(id)sender { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 195 | 173 |
| 196 // Keep the new subviews in an array that gets replaced at the end. | 174 // Keep the new subviews in an array that gets replaced at the end. |
| 197 NSMutableArray* subviews = [NSMutableArray array]; | 175 NSMutableArray* subviews = [NSMutableArray array]; |
| 198 | 176 |
| 199 // Build the window from bottom-up because Cocoa's coordinate origin is the | 177 // Build the window from bottom-up because Cocoa's coordinate origin is the |
| 200 // lower left. | 178 // lower left. |
| 201 for (int i = model_->GetSectionCount() - 1; i >= 0; --i) { | 179 for (int i = model_->GetSectionCount() - 1; i >= 0; --i) { |
| 202 PageInfoModel::SectionInfo info = model_->GetSectionInfo(i); | 180 PageInfoModel::SectionInfo info = model_->GetSectionInfo(i); |
| 203 | 181 |
| 204 // Only certain sections have images. This affects the X position. | 182 // Only certain sections have images. This affects the X position. |
| 205 BOOL hasImage = info.type == PageInfoModel::SECTION_INFO_IDENTITY || | 183 BOOL hasImage = model_->GetIconImage(info.icon_id) != nil; |
| 206 info.type == PageInfoModel::SECTION_INFO_CONNECTION; | |
| 207 CGFloat xPosition = (hasImage ? kTextXPosition : kTextXPositionNoImage); | 184 CGFloat xPosition = (hasImage ? kTextXPosition : kTextXPositionNoImage); |
| 208 | 185 |
| 209 if (info.type == PageInfoModel::SECTION_INFO_IDENTITY) { | 186 if (info.type == PageInfoModel::SECTION_INFO_IDENTITY) { |
| 210 offset += [self addCertificateButtonToSubviews:subviews | 187 offset += [self addCertificateButtonToSubviews:subviews |
| 211 atOffset:offset]; | 188 atOffset:offset]; |
| 212 } | 189 } |
| 213 | 190 |
| 214 // Create the description of the state. | 191 // Create the description of the state. |
| 215 offset += [self addDescriptionViewForInfo:info | 192 offset += [self addDescriptionViewForInfo:info |
| 216 toSubviews:subviews | 193 toSubviews:subviews |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 NSButton* certButton = [[[NSButton alloc] initWithFrame:frame] autorelease]; | 244 NSButton* certButton = [[[NSButton alloc] initWithFrame:frame] autorelease]; |
| 268 [certButton setTitle: | 245 [certButton setTitle: |
| 269 l10n_util::GetNSStringWithFixup(IDS_PAGEINFO_CERT_INFO_BUTTON)]; | 246 l10n_util::GetNSStringWithFixup(IDS_PAGEINFO_CERT_INFO_BUTTON)]; |
| 270 [certButton setButtonType:NSMomentaryPushInButton]; | 247 [certButton setButtonType:NSMomentaryPushInButton]; |
| 271 [certButton setBezelStyle:NSRoundRectBezelStyle]; | 248 [certButton setBezelStyle:NSRoundRectBezelStyle]; |
| 272 [certButton setTarget:self]; | 249 [certButton setTarget:self]; |
| 273 [certButton setAction:@selector(showCertWindow:)]; | 250 [certButton setAction:@selector(showCertWindow:)]; |
| 274 return certButton; | 251 return certButton; |
| 275 } | 252 } |
| 276 | 253 |
| 277 // Returns a weak reference to the NSImage instance to used, or nil if none, for | |
| 278 // the specified info |state|. | |
| 279 - (NSImage*)statusIconForState:(PageInfoModel::SectionInfoState)state { | |
| 280 switch (state) { | |
| 281 case PageInfoModel::SECTION_STATE_OK: | |
| 282 return okImage_.get(); | |
| 283 case PageInfoModel::SECTION_STATE_WARNING_MINOR: | |
| 284 return warningMinorImage_.get(); | |
| 285 case PageInfoModel::SECTION_STATE_WARNING_MAJOR: | |
| 286 return warningMajorImage_.get(); | |
| 287 case PageInfoModel::SECTION_STATE_ERROR: | |
| 288 return errorImage_.get(); | |
| 289 default: | |
| 290 return nil; | |
| 291 } | |
| 292 } | |
| 293 | |
| 294 // Sets proprties on the given |field| to act as the title or description labels | 254 // Sets proprties on the given |field| to act as the title or description labels |
| 295 // in the bubble. | 255 // in the bubble. |
| 296 - (void)configureTextFieldAsLabel:(NSTextField*)textField { | 256 - (void)configureTextFieldAsLabel:(NSTextField*)textField { |
| 297 [textField setEditable:NO]; | 257 [textField setEditable:NO]; |
| 298 [textField setDrawsBackground:NO]; | 258 [textField setDrawsBackground:NO]; |
| 299 [textField setBezeled:NO]; | 259 [textField setBezeled:NO]; |
| 300 } | 260 } |
| 301 | 261 |
| 302 // Adds the title text field at the given x,y position, and returns the y | 262 // Adds the title text field at the given x,y position, and returns the y |
| 303 // position for the next element. | 263 // position for the next element. |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 // does not affect the next Y position because the image is placed next to | 329 // does not affect the next Y position because the image is placed next to |
| 370 // a text field that is larger and accounts for the image's size. | 330 // a text field that is larger and accounts for the image's size. |
| 371 - (void)addImageViewForInfo:(const PageInfoModel::SectionInfo&)info | 331 - (void)addImageViewForInfo:(const PageInfoModel::SectionInfo&)info |
| 372 toSubviews:(NSMutableArray*)subviews | 332 toSubviews:(NSMutableArray*)subviews |
| 373 atOffset:(CGFloat)offset { | 333 atOffset:(CGFloat)offset { |
| 374 NSRect frame = NSMakeRect(kFramePadding, offset - kImageSize, kImageSize, | 334 NSRect frame = NSMakeRect(kFramePadding, offset - kImageSize, kImageSize, |
| 375 kImageSize); | 335 kImageSize); |
| 376 scoped_nsobject<NSImageView> imageView( | 336 scoped_nsobject<NSImageView> imageView( |
| 377 [[NSImageView alloc] initWithFrame:frame]); | 337 [[NSImageView alloc] initWithFrame:frame]); |
| 378 [imageView setImageFrameStyle:NSImageFrameNone]; | 338 [imageView setImageFrameStyle:NSImageFrameNone]; |
| 379 [imageView setImage:[self statusIconForState:info.state]]; | 339 [imageView setImage:model_->GetIconImage(info.icon_id)]; |
| 380 [subviews addObject:imageView.get()]; | 340 [subviews addObject:imageView.get()]; |
| 381 } | 341 } |
| 382 | 342 |
| 383 @end | 343 @end |
| OLD | NEW |