| 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 #include "chrome/browser/cocoa/page_info_window_mac.h" | 5 #include "chrome/browser/cocoa/page_info_window_mac.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
| 10 #include "base/scoped_cftyperef.h" | 10 #include "base/scoped_cftyperef.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 } // namespace browser | 60 } // namespace browser |
| 61 | 61 |
| 62 PageInfoWindowMac::PageInfoWindowMac(PageInfoWindowController* controller, | 62 PageInfoWindowMac::PageInfoWindowMac(PageInfoWindowController* controller, |
| 63 Profile* profile, | 63 Profile* profile, |
| 64 const GURL& url, | 64 const GURL& url, |
| 65 const NavigationEntry::SSLStatus& ssl, | 65 const NavigationEntry::SSLStatus& ssl, |
| 66 bool show_history) | 66 bool show_history) |
| 67 : controller_(controller), | 67 : controller_(controller), |
| 68 model_(new PageInfoModel(profile, url, ssl, show_history, this)), | 68 model_(new PageInfoModel(profile, url, ssl, show_history, this)), |
| 69 cert_id_(ssl.cert_id()) { | 69 cert_id_(ssl.cert_id()) { |
| 70 Init(); | |
| 71 } | 70 } |
| 72 | 71 |
| 73 PageInfoWindowMac::PageInfoWindowMac(PageInfoWindowController* controller, | 72 PageInfoWindowMac::PageInfoWindowMac(PageInfoWindowController* controller, |
| 74 PageInfoModel* model) | 73 PageInfoModel* model) |
| 75 : controller_(controller), | 74 : controller_(controller), |
| 76 model_(model), | 75 model_(model), |
| 77 cert_id_(0) { | 76 cert_id_(0) { |
| 78 Init(); | |
| 79 } | 77 } |
| 80 | 78 |
| 81 // static | 79 // static |
| 82 void PageInfoWindowMac::ShowPageInfo(gfx::NativeWindow parent, | 80 void PageInfoWindowMac::ShowPageInfo(gfx::NativeWindow parent, |
| 83 Profile* profile, | 81 Profile* profile, |
| 84 const GURL& url, | 82 const GURL& url, |
| 85 const NavigationEntry::SSLStatus& ssl, | 83 const NavigationEntry::SSLStatus& ssl, |
| 86 bool show_history) { | 84 bool show_history) { |
| 87 // The controller will clean itself up after the NSWindow it manages closes. | 85 // The controller will clean itself up after the NSWindow it manages closes. |
| 88 // We do not manage it as it owns us. | 86 // We do not manage it as it owns us. |
| 89 PageInfoWindowController* controller = | 87 PageInfoWindowController* controller = |
| 90 [[PageInfoWindowController alloc] init]; | 88 [[PageInfoWindowController alloc] init]; |
| 91 PageInfoWindowMac* page_info = new PageInfoWindowMac(controller, | 89 PageInfoWindowMac* page_info = new PageInfoWindowMac(controller, |
| 92 profile, | 90 profile, |
| 93 url, | 91 url, |
| 94 ssl, | 92 ssl, |
| 95 show_history); | 93 show_history); |
| 96 [controller setPageInfo:page_info]; | 94 [controller setPageInfo:page_info]; |
| 97 page_info->LayoutSections(); | 95 page_info->LayoutSections(); |
| 98 page_info->Show(); | 96 page_info->Show(); |
| 99 } | 97 } |
| 100 | 98 |
| 101 void PageInfoWindowMac::Init() { | |
| 102 // Load the image refs. | |
| 103 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
| 104 good_image_.reset([rb.GetNSImageNamed(IDR_PAGEINFO_GOOD) retain]); | |
| 105 DCHECK_GE(kImageSize, [good_image_ size].width); | |
| 106 DCHECK_GE(kImageSize, [good_image_ size].height); | |
| 107 bad_image_.reset([rb.GetNSImageNamed(IDR_PAGEINFO_BAD) retain]); | |
| 108 DCHECK_GE(kImageSize, [bad_image_ size].width); | |
| 109 DCHECK_GE(kImageSize, [bad_image_ size].height); | |
| 110 } | |
| 111 | |
| 112 PageInfoWindowMac::~PageInfoWindowMac() { | 99 PageInfoWindowMac::~PageInfoWindowMac() { |
| 113 } | 100 } |
| 114 | 101 |
| 115 void PageInfoWindowMac::ShowCertDialog(int) { | 102 void PageInfoWindowMac::ShowCertDialog(int) { |
| 116 DCHECK(cert_id_ != 0); | 103 DCHECK(cert_id_ != 0); |
| 117 ShowCertificateViewerByID([controller_ window], cert_id_); | 104 ShowCertificateViewerByID([controller_ window], cert_id_); |
| 118 } | 105 } |
| 119 | 106 |
| 120 void PageInfoWindowMac::ModelChanged() { | 107 void PageInfoWindowMac::ModelChanged() { |
| 121 LayoutSections(); | 108 LayoutSections(); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 [text_field setFrame:text_field_rect]; | 193 [text_field setFrame:text_field_rect]; |
| 207 | 194 |
| 208 // Insert the image subview. | 195 // Insert the image subview. |
| 209 NSRect image_view_rect = | 196 NSRect image_view_rect = |
| 210 NSMakeRect(kBoxHorizontalSpacing, | 197 NSMakeRect(kBoxHorizontalSpacing, |
| 211 box_height - (kImageSize + kBoxTopSpacing), | 198 box_height - (kImageSize + kBoxTopSpacing), |
| 212 kImageSize, kImageSize); | 199 kImageSize, kImageSize); |
| 213 scoped_nsobject<NSImageView> image_view( | 200 scoped_nsobject<NSImageView> image_view( |
| 214 [[NSImageView alloc] initWithFrame:image_view_rect]); | 201 [[NSImageView alloc] initWithFrame:image_view_rect]); |
| 215 [image_view setImageFrameStyle:NSImageFrameNone]; | 202 [image_view setImageFrameStyle:NSImageFrameNone]; |
| 216 [image_view setImage:(info.state == PageInfoModel::SECTION_STATE_OK) ? | 203 [image_view setImage:model_->GetIconImage(info.icon_id)]; |
| 217 good_image_.get() : bad_image_.get()]; | |
| 218 | 204 |
| 219 // Add the box to the list of new subviews. | 205 // Add the box to the list of new subviews. |
| 220 [box addSubview:image_view.get()]; | 206 [box addSubview:image_view.get()]; |
| 221 [box addSubview:text_field.get()]; | 207 [box addSubview:text_field.get()]; |
| 222 [subviews addObject:box.get()]; | 208 [subviews addObject:box.get()]; |
| 223 } | 209 } |
| 224 | 210 |
| 225 // Replace the window's content. | 211 // Replace the window's content. |
| 226 [[[controller_ window] contentView] setSubviews:subviews]; | 212 [[[controller_ window] contentView] setSubviews:subviews]; |
| 227 | 213 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 243 [cert_button setEnabled:YES]; | 229 [cert_button setEnabled:YES]; |
| 244 } | 230 } |
| 245 } | 231 } |
| 246 | 232 |
| 247 // Resize the window. Only animate if the window is visible, otherwise it | 233 // Resize the window. Only animate if the window is visible, otherwise it |
| 248 // could be "growing" while it's opening, looking awkward. | 234 // could be "growing" while it's opening, looking awkward. |
| 249 [[controller_ window] setFrame:window_frame | 235 [[controller_ window] setFrame:window_frame |
| 250 display:YES | 236 display:YES |
| 251 animate:[[controller_ window] isVisible]]; | 237 animate:[[controller_ window] isVisible]]; |
| 252 } | 238 } |
| OLD | NEW |