Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(341)

Side by Side Diff: chrome/browser/ui/cocoa/autofill/autofill_popup_view_cocoa.mm

Issue 1570783003: [Autofill] Move functions from the AutofillPopupController to AutofillPopupLayoutModel (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove scoped_ptr and rename mac delegate Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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::AutofillPopupViewCocoaDelegate*)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 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 = NSRectFromCGRect(delegate_->GetRowBounds(i).ToCGRect());
100 NSRectFromCGRect(controller_->GetRowBounds(i).ToCGRect());
101 if (!NSIntersectsRect(rowBounds, dirtyRect)) 103 if (!NSIntersectsRect(rowBounds, dirtyRect))
102 continue; 104 continue;
103 const autofill::Suggestion& suggestion = controller_->GetSuggestionAt(i); 105 const autofill::Suggestion& suggestion = controller_->GetSuggestionAt(i);
104 106
105 if (suggestion.frontend_id == autofill::POPUP_ITEM_ID_SEPARATOR) { 107 if (suggestion.frontend_id == autofill::POPUP_ITEM_ID_SEPARATOR) {
106 [self drawSeparatorWithBounds:rowBounds]; 108 [self drawSeparatorWithBounds:rowBounds];
107 continue; 109 continue;
108 } 110 }
109 111
110 // Additional offset applied to the text in the vertical direction. 112 // Additional offset applied to the text in the vertical direction.
(...skipping 15 matching lines...) Expand all
126 #pragma mark Public API: 128 #pragma mark Public API:
127 129
128 - (void)controllerDestroyed { 130 - (void)controllerDestroyed {
129 // Since the |controller_| either already has been destroyed or is about to 131 // 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. 132 // be, about the only thing we can safely do with it is to null it out.
131 controller_ = NULL; 133 controller_ = NULL;
132 [super delegateDestroyed]; 134 [super delegateDestroyed];
133 } 135 }
134 136
135 - (void)invalidateRow:(size_t)row { 137 - (void)invalidateRow:(size_t)row {
136 NSRect dirty_rect = 138 NSRect dirty_rect = NSRectFromCGRect(delegate_->GetRowBounds(row).ToCGRect());
137 NSRectFromCGRect(controller_->GetRowBounds(row).ToCGRect());
138 [self setNeedsDisplayInRect:dirty_rect]; 139 [self setNeedsDisplayInRect:dirty_rect];
139 } 140 }
140 141
141 #pragma mark - 142 #pragma mark -
142 #pragma mark Private API: 143 #pragma mark Private API:
143 144
144 - (void)drawSuggestionWithName:(NSString*)name 145 - (void)drawSuggestionWithName:(NSString*)name
145 subtext:(NSString*)subtext 146 subtext:(NSString*)subtext
146 index:(size_t)index 147 index:(size_t)index
147 bounds:(NSRect)bounds 148 bounds:(NSRect)bounds
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 [subtext drawAtPoint:NSMakePoint(x, y) withAttributes:subtextAttributes]; 246 [subtext drawAtPoint:NSMakePoint(x, y) withAttributes:subtextAttributes];
246 x += rightAlign ? 0 : subtextSize.width; 247 x += rightAlign ? 0 : subtextSize.width;
247 return x; 248 return x;
248 } 249 }
249 250
250 - (NSImage*)iconAtIndex:(size_t)index { 251 - (NSImage*)iconAtIndex:(size_t)index {
251 const base::string16& icon = controller_->GetSuggestionAt(index).icon; 252 const base::string16& icon = controller_->GetSuggestionAt(index).icon;
252 if (icon.empty()) 253 if (icon.empty())
253 return nil; 254 return nil;
254 255
255 int iconId = controller_->GetIconResourceID(icon); 256 int iconId = delegate_->GetIconResourceID(icon);
256 DCHECK_NE(-1, iconId); 257 DCHECK_NE(-1, iconId);
257 258
258 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 259 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
259 return rb.GetNativeImageNamed(iconId).ToNSImage(); 260 return rb.GetNativeImageNamed(iconId).ToNSImage();
260 } 261 }
261 262
262 @end 263 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698