OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/autofill/autofill_popup_view_cocoa.h" | 5 #import "chrome/browser/ui/cocoa/autofill/autofill_popup_view_cocoa.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
9 #include "chrome/browser/ui/autofill/autofill_popup_controller.h" | 9 #include "chrome/browser/ui/autofill/autofill_popup_controller.h" |
10 #include "chrome/browser/ui/autofill/popup_constants.h" | 10 #include "chrome/browser/ui/autofill/popup_constants.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 | 65 |
66 @end | 66 @end |
67 | 67 |
68 @implementation AutofillPopupViewCocoa | 68 @implementation AutofillPopupViewCocoa |
69 | 69 |
70 #pragma mark - | 70 #pragma mark - |
71 #pragma mark Initialisers | 71 #pragma mark Initialisers |
72 | 72 |
73 - (id)initWithFrame:(NSRect)frame { | 73 - (id)initWithFrame:(NSRect)frame { |
74 NOTREACHED(); | 74 NOTREACHED(); |
75 return [self initWithController:NULL frame:frame]; | 75 return [self initWithController:NULL frame:frame delegate:NULL]; |
76 } | 76 } |
77 | 77 |
78 - (id)initWithController:(autofill::AutofillPopupController*)controller | 78 - (id)initWithController:(autofill::AutofillPopupController*)controller |
79 frame:(NSRect)frame { | 79 frame:(NSRect)frame |
| 80 delegate:(autofill::AutofillPopupViewBridgeDelegate*)delegate { |
80 self = [super initWithDelegate:controller frame:frame]; | 81 self = [super initWithDelegate:controller frame:frame]; |
81 if (self) | 82 if (self) { |
82 controller_ = controller; | 83 controller_ = controller; |
| 84 bridge_delegate_ = delegate; |
| 85 } |
83 | 86 |
84 return self; | 87 return self; |
85 } | 88 } |
86 | 89 |
87 #pragma mark - | 90 #pragma mark - |
88 #pragma mark NSView implementation: | 91 #pragma mark NSView implementation: |
89 | 92 |
90 - (void)drawRect:(NSRect)dirtyRect { | 93 - (void)drawRect:(NSRect)dirtyRect { |
91 // If the view is in the process of being destroyed, don't bother drawing. | 94 // If the view is in the process of being destroyed, don't bother drawing. |
92 if (!controller_) | 95 if (!controller_) |
93 return; | 96 return; |
94 | 97 |
95 [self drawBackgroundAndBorder]; | 98 [self drawBackgroundAndBorder]; |
96 | 99 |
97 for (size_t i = 0; i < controller_->GetLineCount(); ++i) { | 100 for (size_t i = 0; i < controller_->GetLineCount(); ++i) { |
98 // Skip rows outside of the dirty rect. | 101 // Skip rows outside of the dirty rect. |
99 NSRect rowBounds = | 102 NSRect rowBounds = |
100 NSRectFromCGRect(controller_->GetRowBounds(i).ToCGRect()); | 103 NSRectFromCGRect(bridge_delegate_->GetRowBounds(i).ToCGRect()); |
101 if (!NSIntersectsRect(rowBounds, dirtyRect)) | 104 if (!NSIntersectsRect(rowBounds, dirtyRect)) |
102 continue; | 105 continue; |
103 const autofill::Suggestion& suggestion = controller_->GetSuggestionAt(i); | 106 const autofill::Suggestion& suggestion = controller_->GetSuggestionAt(i); |
104 | 107 |
105 if (suggestion.frontend_id == autofill::POPUP_ITEM_ID_SEPARATOR) { | 108 if (suggestion.frontend_id == autofill::POPUP_ITEM_ID_SEPARATOR) { |
106 [self drawSeparatorWithBounds:rowBounds]; | 109 [self drawSeparatorWithBounds:rowBounds]; |
107 continue; | 110 continue; |
108 } | 111 } |
109 | 112 |
110 // Additional offset applied to the text in the vertical direction. | 113 // Additional offset applied to the text in the vertical direction. |
(...skipping 16 matching lines...) Expand all Loading... |
127 | 130 |
128 - (void)controllerDestroyed { | 131 - (void)controllerDestroyed { |
129 // Since the |controller_| either already has been destroyed or is about to | 132 // Since the |controller_| either already has been destroyed or is about to |
130 // be, about the only thing we can safely do with it is to null it out. | 133 // be, about the only thing we can safely do with it is to null it out. |
131 controller_ = NULL; | 134 controller_ = NULL; |
132 [super delegateDestroyed]; | 135 [super delegateDestroyed]; |
133 } | 136 } |
134 | 137 |
135 - (void)invalidateRow:(size_t)row { | 138 - (void)invalidateRow:(size_t)row { |
136 NSRect dirty_rect = | 139 NSRect dirty_rect = |
137 NSRectFromCGRect(controller_->GetRowBounds(row).ToCGRect()); | 140 NSRectFromCGRect(bridge_delegate_->GetRowBounds(row).ToCGRect()); |
138 [self setNeedsDisplayInRect:dirty_rect]; | 141 [self setNeedsDisplayInRect:dirty_rect]; |
139 } | 142 } |
140 | 143 |
141 #pragma mark - | 144 #pragma mark - |
142 #pragma mark Private API: | 145 #pragma mark Private API: |
143 | 146 |
144 - (void)drawSuggestionWithName:(NSString*)name | 147 - (void)drawSuggestionWithName:(NSString*)name |
145 subtext:(NSString*)subtext | 148 subtext:(NSString*)subtext |
146 index:(size_t)index | 149 index:(size_t)index |
147 bounds:(NSRect)bounds | 150 bounds:(NSRect)bounds |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 [subtext drawAtPoint:NSMakePoint(x, y) withAttributes:subtextAttributes]; | 248 [subtext drawAtPoint:NSMakePoint(x, y) withAttributes:subtextAttributes]; |
246 x += rightAlign ? 0 : subtextSize.width; | 249 x += rightAlign ? 0 : subtextSize.width; |
247 return x; | 250 return x; |
248 } | 251 } |
249 | 252 |
250 - (NSImage*)iconAtIndex:(size_t)index { | 253 - (NSImage*)iconAtIndex:(size_t)index { |
251 const base::string16& icon = controller_->GetSuggestionAt(index).icon; | 254 const base::string16& icon = controller_->GetSuggestionAt(index).icon; |
252 if (icon.empty()) | 255 if (icon.empty()) |
253 return nil; | 256 return nil; |
254 | 257 |
255 int iconId = controller_->GetIconResourceID(icon); | 258 int iconId = bridge_delegate_->GetIconResourceID(icon); |
256 DCHECK_NE(-1, iconId); | 259 DCHECK_NE(-1, iconId); |
257 | 260 |
258 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 261 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
259 return rb.GetNativeImageNamed(iconId).ToNSImage(); | 262 return rb.GetNativeImageNamed(iconId).ToNSImage(); |
260 } | 263 } |
261 | 264 |
262 @end | 265 @end |
OLD | NEW |