OLD | NEW |
---|---|
1 // Copyright (c) 2010 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/cocoa/page_info_bubble_controller.h" | 5 #import "chrome/browser/ui/cocoa/page_info_bubble_controller.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "app/l10n_util_mac.h" | 8 #include "app/l10n_util_mac.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/sys_string_conversions.h" | 10 #include "base/sys_string_conversions.h" |
11 #include "base/task.h" | 11 #include "base/task.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
46 - (CGFloat)addSeparatorToSubviews:(NSMutableArray*)subviews | 46 - (CGFloat)addSeparatorToSubviews:(NSMutableArray*)subviews |
47 atOffset:(CGFloat)offset; | 47 atOffset:(CGFloat)offset; |
48 - (NSPoint)anchorPointForWindowWithHeight:(CGFloat)bubbleHeight | 48 - (NSPoint)anchorPointForWindowWithHeight:(CGFloat)bubbleHeight |
49 parentWindow:(NSWindow*)parent; | 49 parentWindow:(NSWindow*)parent; |
50 @end | 50 @end |
51 | 51 |
52 // This simple NSView subclass is used as the single subview of the page info | 52 // This simple NSView subclass is used as the single subview of the page info |
53 // bubble's window's contentView. Drawing is flipped so that layout of the | 53 // bubble's window's contentView. Drawing is flipped so that layout of the |
54 // sections is easier. Apple recommends flipping the coordinate origin when | 54 // sections is easier. Apple recommends flipping the coordinate origin when |
55 // doing a lot of text layout because it's more natural. | 55 // doing a lot of text layout because it's more natural. |
56 @interface PageInfoContentView : NSView { | 56 @interface PageInfoContentView : NSView |
57 } | |
58 @end | 57 @end |
59 @implementation PageInfoContentView | 58 @implementation PageInfoContentView |
60 - (BOOL)isFlipped { | 59 - (BOOL)isFlipped { |
61 return YES; | 60 return YES; |
62 } | 61 } |
63 @end | 62 @end |
64 | 63 |
65 namespace { | 64 namespace { |
66 | 65 |
67 // The width of the window, in view coordinates. The height will be determined | 66 // The width of the window, in view coordinates. The height will be determined |
68 // by the content. | 67 // by the content. |
69 const NSInteger kWindowWidth = 380; | 68 const CGFloat kWindowWidth = 380; |
70 | 69 |
71 // Spacing in between sections. | 70 // Spacing in between sections. |
72 const NSInteger kVerticalSpacing = 10; | 71 const CGFloat kVerticalSpacing = 10; |
73 | 72 |
74 // Padding along on the X-axis between the window frame and content. | 73 // Padding along on the X-axis between the window frame and content. |
75 const NSInteger kFramePadding = 10; | 74 const CGFloat kFramePadding = 10; |
76 | 75 |
77 // Spacing between the optional headline and description text views. | 76 // Spacing between the optional headline and description text views. |
78 const NSInteger kHeadlineSpacing = 2; | 77 const CGFloat kHeadlineSpacing = 2; |
79 | 78 |
80 // Spacing between the image and the text. | 79 // Spacing between the image and the text. |
81 const NSInteger kImageSpacing = 10; | 80 const CGFloat kImageSpacing = 10; |
82 | 81 |
83 // Square size of the image. | 82 // Square size of the image. |
84 const CGFloat kImageSize = 30; | 83 const CGFloat kImageSize = 30; |
85 | 84 |
86 // The X position of the text fields. Variants for with and without an image. | 85 // The X position of the text fields. Variants for with and without an image. |
87 const CGFloat kTextXPositionNoImage = kFramePadding; | 86 const CGFloat kTextXPositionNoImage = kFramePadding; |
88 const CGFloat kTextXPosition = kTextXPositionNoImage + kImageSize + | 87 const CGFloat kTextXPosition = kTextXPositionNoImage + kImageSize + |
89 kImageSpacing; | 88 kImageSpacing; |
90 | 89 |
91 // Width of the text fields. | 90 // Width of the text fields. |
92 const CGFloat kTextWidth = kWindowWidth - (kImageSize + kImageSpacing + | 91 const CGFloat kTextWidth = kWindowWidth - (kImageSize + kImageSpacing + |
93 kFramePadding * 2); | 92 kFramePadding * 2); |
94 | 93 |
95 // Bridge that listens for change notifications from the model. | 94 // Bridge that listens for change notifications from the model. |
96 class PageInfoModelBubbleBridge : public PageInfoModel::PageInfoModelObserver { | 95 class PageInfoModelBubbleBridge : public PageInfoModel::PageInfoModelObserver { |
pink (ping after 24hrs)
2011/01/24 19:22:23
worth adding a DISALLOW_COPY_AND_ASSIGN on this?
Robert Sesek
2011/01/24 19:55:17
Done.
| |
97 public: | 96 public: |
98 PageInfoModelBubbleBridge() | 97 PageInfoModelBubbleBridge() |
99 : controller_(nil), | 98 : controller_(nil), |
100 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)) { | 99 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)) { |
101 } | 100 } |
102 | 101 |
103 // PageInfoModelObserver implementation. | 102 // PageInfoModelObserver implementation. |
104 virtual void ModelChanged() { | 103 virtual void ModelChanged() { |
105 // Check to see if a layout has already been scheduled. | 104 // Check to see if a layout has already been scheduled. |
106 if (!task_factory_.empty()) | 105 if (!task_factory_.empty()) |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
160 | 159 |
161 } // namespace browser | 160 } // namespace browser |
162 | 161 |
163 @implementation PageInfoBubbleController | 162 @implementation PageInfoBubbleController |
164 | 163 |
165 @synthesize certID = certID_; | 164 @synthesize certID = certID_; |
166 | 165 |
167 - (id)initWithPageInfoModel:(PageInfoModel*)model | 166 - (id)initWithPageInfoModel:(PageInfoModel*)model |
168 modelObserver:(PageInfoModel::PageInfoModelObserver*)bridge | 167 modelObserver:(PageInfoModel::PageInfoModelObserver*)bridge |
169 parentWindow:(NSWindow*)parentWindow { | 168 parentWindow:(NSWindow*)parentWindow { |
169 DCHECK(parentWindow); | |
170 | |
170 // Use an arbitrary height because it will be changed by the bridge. | 171 // Use an arbitrary height because it will be changed by the bridge. |
171 NSRect contentRect = NSMakeRect(0, 0, kWindowWidth, 0); | 172 NSRect contentRect = NSMakeRect(0, 0, kWindowWidth, 0); |
172 // Create an empty window into which content is placed. | 173 // Create an empty window into which content is placed. |
173 scoped_nsobject<InfoBubbleWindow> window( | 174 scoped_nsobject<InfoBubbleWindow> window( |
174 [[InfoBubbleWindow alloc] initWithContentRect:contentRect | 175 [[InfoBubbleWindow alloc] initWithContentRect:contentRect |
175 styleMask:NSBorderlessWindowMask | 176 styleMask:NSBorderlessWindowMask |
176 backing:NSBackingStoreBuffered | 177 backing:NSBackingStoreBuffered |
177 defer:NO]); | 178 defer:NO]); |
178 | 179 |
179 if ((self = [super initWithWindow:window.get() | 180 if ((self = [super initWithWindow:window.get() |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
387 | 388 |
388 return NSHeight([certButton frame]); | 389 return NSHeight([certButton frame]); |
389 } | 390 } |
390 | 391 |
391 // Adds the state image at a pre-determined x position and the given y. This | 392 // Adds the state image at a pre-determined x position and the given y. This |
392 // does not affect the next Y position because the image is placed next to | 393 // does not affect the next Y position because the image is placed next to |
393 // a text field that is larger and accounts for the image's size. | 394 // a text field that is larger and accounts for the image's size. |
394 - (void)addImageViewForInfo:(const PageInfoModel::SectionInfo&)info | 395 - (void)addImageViewForInfo:(const PageInfoModel::SectionInfo&)info |
395 toSubviews:(NSMutableArray*)subviews | 396 toSubviews:(NSMutableArray*)subviews |
396 atOffset:(CGFloat)offset { | 397 atOffset:(CGFloat)offset { |
397 NSRect frame = NSMakeRect(kFramePadding, offset, kImageSize, | 398 NSRect frame = |
398 kImageSize); | 399 NSMakeRect(kFramePadding, offset, kImageSize, kImageSize); |
399 scoped_nsobject<NSImageView> imageView( | 400 scoped_nsobject<NSImageView> imageView( |
400 [[NSImageView alloc] initWithFrame:frame]); | 401 [[NSImageView alloc] initWithFrame:frame]); |
401 [imageView setImageFrameStyle:NSImageFrameNone]; | 402 [imageView setImageFrameStyle:NSImageFrameNone]; |
402 [imageView setImage:model_->GetIconImage(info.icon_id)]; | 403 [imageView setImage:model_->GetIconImage(info.icon_id)]; |
403 [subviews addObject:imageView.get()]; | 404 [subviews addObject:imageView.get()]; |
404 } | 405 } |
405 | 406 |
406 // Adds the help center button that explains the icons. Returns the y position | 407 // Adds the help center button that explains the icons. Returns the y position |
407 // delta for the next offset. | 408 // delta for the next offset. |
408 - (CGFloat)addHelpButtonToSubviews:(NSMutableArray*)subviews | 409 - (CGFloat)addHelpButtonToSubviews:(NSMutableArray*)subviews |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
452 LocationBarViewMac* locationBar = [controller locationBarBridge]; | 453 LocationBarViewMac* locationBar = [controller locationBarBridge]; |
453 if (locationBar) { | 454 if (locationBar) { |
454 NSPoint bubblePoint = locationBar->GetPageInfoBubblePoint(); | 455 NSPoint bubblePoint = locationBar->GetPageInfoBubblePoint(); |
455 origin = [parent convertBaseToScreen:bubblePoint]; | 456 origin = [parent convertBaseToScreen:bubblePoint]; |
456 } | 457 } |
457 } | 458 } |
458 return origin; | 459 return origin; |
459 } | 460 } |
460 | 461 |
461 @end | 462 @end |
OLD | NEW |