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

Side by Side Diff: chrome/browser/cocoa/bookmark_editor_controller.mm

Issue 343042: Original discussion in CL for 337010. See http://codereview.chromium.org/337... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "app/l10n_util.h"
5 #include "base/logging.h" 6 #include "base/logging.h"
6 #include "base/mac_util.h" 7 #include "base/mac_util.h"
7 #include "base/sys_string_conversions.h" 8 #include "base/sys_string_conversions.h"
8 #include "chrome/browser/bookmarks/bookmark_editor.h" 9 #include "chrome/browser/bookmarks/bookmark_editor.h"
9 #include "chrome/browser/bookmarks/bookmark_model.h" 10 #include "chrome/browser/bookmarks/bookmark_model.h"
10 #include "chrome/browser/profile.h" 11 #include "chrome/browser/profile.h"
12 #import "chrome/browser/cocoa/bookmark_tree_browser_cell.h"
11 #import "chrome/browser/cocoa/bookmark_editor_controller.h" 13 #import "chrome/browser/cocoa/bookmark_editor_controller.h"
14 #include "grit/generated_resources.h"
12 15
13 @interface BookmarkEditorController (Private) 16 @interface BookmarkEditorController (Private)
14 17
15 // Grab the url from the text field and convert. 18 // Grab the url from the text field and convert.
16 - (GURL)GURLFromUrlField; 19 - (GURL)GURLFromUrlField;
17 20
21 // Given a cell in the folder browser, make that cell editable so that the
22 // bookmark folder name can be modified by the user.
23 - (void)editFolderNameInCell:(BookmarkTreeBrowserCell*)cell;
24
25 // The action called by the bookmark folder name cell being edited by
26 // the user when editing has been completed (such as by pressing <return>).
27 - (void)cellEditingCompleted:(id)sender;
28
29 // Update the folder name from the current edit in the given cell
30 // and return the focus to the folder tree browser.
31 - (void)saveFolderNameForCell:(BookmarkTreeBrowserCell*)cell;
32
33 // A custom action handler called by the bookmark folder browser when the
34 // user has double-clicked on a folder name.
35 - (void)browserDoubleClicked:(id)sender;
36
18 // Determine and returns the rightmost selected/highlighted element (node) 37 // Determine and returns the rightmost selected/highlighted element (node)
19 // in the bookmark tree view if the tree view is showing, otherwise returns 38 // in the bookmark tree view if the tree view is showing, otherwise returns
20 // the original parentNode_. If the tree view is showing but nothing is 39 // the original parentNode_. If the tree view is showing but nothing is
21 // selected then return the root node. 40 // selected then return the root node. This assumes that leaf nodes (pure
22 - (const BookmarkNode*)selectedParentNode; 41 // bookmarks) are not being presented.
42 - (const BookmarkNode*)selectedNode;
23 43
24 // Select/highlight the given node within the browser tree view. If the 44 // Select/highlight the given node within the browser tree view. If the
25 // node is not found then the selection will not be changed. 45 // node is nil then select the bookmark bar.
26 - (void)selectNodeInBrowser:(const BookmarkNode*)node; 46 - (void)selectNodeInBrowser:(const BookmarkNode*)node;
27 47
28 @end 48 @end
29 49
30 // static; implemented for each platform. 50 // static; implemented for each platform.
31 void BookmarkEditor::Show(gfx::NativeWindow parent_hwnd, 51 void BookmarkEditor::Show(gfx::NativeWindow parent_hwnd,
32 Profile* profile, 52 Profile* profile,
33 const BookmarkNode* parent, 53 const BookmarkNode* parent,
34 const EditDetails& details, 54 const EditDetails& details,
35 Configuration configuration, 55 Configuration configuration,
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 // Get a ping when the URL or name text fields change; 144 // Get a ping when the URL or name text fields change;
125 // trigger an initial ping to set things up. 145 // trigger an initial ping to set things up.
126 [nameField_ setDelegate:self]; 146 [nameField_ setDelegate:self];
127 [urlField_ setDelegate:self]; 147 [urlField_ setDelegate:self];
128 [self controlTextDidChange:nil]; 148 [self controlTextDidChange:nil];
129 149
130 if (configuration_ != BookmarkEditor::SHOW_TREE) { 150 if (configuration_ != BookmarkEditor::SHOW_TREE) {
131 // Remember the NSBrowser's height; we will shrink our frame by that 151 // Remember the NSBrowser's height; we will shrink our frame by that
132 // much. 152 // much.
133 NSRect frame = [[self window] frame]; 153 NSRect frame = [[self window] frame];
134 CGFloat browserHeight = [browser_ frame].size.height; 154 CGFloat browserHeight = [folderBrowser_ frame].size.height;
135 frame.size.height -= browserHeight; 155 frame.size.height -= browserHeight;
136 frame.origin.y += browserHeight; 156 frame.origin.y += browserHeight;
137 // Remove the NSBrowser and "new folder" button. 157 // Remove the NSBrowser and "new folder" button.
138 [browser_ removeFromSuperview]; 158 [folderBrowser_ removeFromSuperview];
139 [newFolderButton_ removeFromSuperview]; 159 [newFolderButton_ removeFromSuperview];
140 // Finally, commit the size change. 160 // Finally, commit the size change.
141 [[self window] setFrame:frame display:YES]; 161 [[self window] setFrame:frame display:YES];
142 } 162 }
143 }
144 163
145 - (void)selectNodeInBrowser:(const BookmarkNode*)node { 164 [folderBrowser_ setCellClass:[BookmarkTreeBrowserCell class]];
146 DCHECK(configuration_ == BookmarkEditor::SHOW_TREE); 165 [folderBrowser_ setDoubleAction:@selector(browserDoubleClicked:)];
147 // Find and select the node in the browser by walking
148 // back to the root node, then selecting forward.
149 std::deque<NSInteger> rowsToSelect;
150 const BookmarkNode* nodeParent = node->GetParent();
151 // There should always be a parent node.
152 DCHECK(nodeParent);
153 while (nodeParent) {
154 int nodeRow = IndexOfFolderChild(node);
155 rowsToSelect.push_front(nodeRow);
156 node = nodeParent;
157 nodeParent = nodeParent->GetParent();
158 }
159 for (std::deque<NSInteger>::size_type column = 0;
160 column < rowsToSelect.size();
161 ++column) {
162 [browser_ selectRow:rowsToSelect[column] inColumn:column];
163 }
164 [self controlTextDidChange:nil];
165 } 166 }
166 167
167 - (void)windowDidLoad { 168 - (void)windowDidLoad {
168 if (configuration_ == BookmarkEditor::SHOW_TREE) { 169 if (configuration_ == BookmarkEditor::SHOW_TREE) {
169 // Find and select the |parent| bookmark node. 170 // Find and select the |parent| bookmark node in the folder tree browser.
170 [self selectNodeInBrowser:parentNode_]; 171 [self selectNodeInBrowser:parentNode_];
171 } 172 }
172 } 173 }
173 174
174 /* TODO(jrg): 175 /* TODO(jrg):
175 // Implementing this informal protocol allows us to open the sheet 176 // Implementing this informal protocol allows us to open the sheet
176 // somewhere other than at the top of the window. NOTE: this means 177 // somewhere other than at the top of the window. NOTE: this means
177 // that I, the controller, am also the window's delegate. 178 // that I, the controller, am also the window's delegate.
178 - (NSRect)window:(NSWindow*)window willPositionSheet:(NSWindow*)sheet 179 - (NSRect)window:(NSWindow*)window willPositionSheet:(NSWindow*)sheet
179 usingRect:(NSRect)rect { 180 usingRect:(NSRect)rect {
180 // adjust rect.origin.y to be the bottom of the toolbar 181 // adjust rect.origin.y to be the bottom of the toolbar
181 return rect; 182 return rect;
182 } 183 }
183 */ 184 */
184 185
185 // TODO(jrg): consider NSModalSession. 186 // TODO(jrg): consider NSModalSession.
186 - (void)runAsModalSheet { 187 - (void)runAsModalSheet {
187 [NSApp beginSheet:[self window] 188 [NSApp beginSheet:[self window]
188 modalForWindow:parentWindow_ 189 modalForWindow:parentWindow_
189 modalDelegate:self 190 modalDelegate:self
190 didEndSelector:@selector(didEndSheet:returnCode:contextInfo:) 191 didEndSelector:@selector(didEndSheet:returnCode:contextInfo:)
191 contextInfo:nil]; 192 contextInfo:nil];
192 } 193 }
193 194
194 // TODO(jrg) 195 - (void)selectNodeInBrowser:(const BookmarkNode*)node {
195 - (IBAction)newFolder:(id)sender { 196 DCHECK(configuration_ == BookmarkEditor::SHOW_TREE);
196 NOTIMPLEMENTED(); 197 std::deque<NSInteger> rowsToSelect;
198 const BookmarkNode* nodeParent = nil;
199 if (node) {
200 nodeParent = node->GetParent();
201 // There should always be a parent node.
202 DCHECK(nodeParent);
203 while (nodeParent) {
204 int nodeRow = IndexOfFolderChild(node);
205 rowsToSelect.push_front(nodeRow);
206 node = nodeParent;
207 nodeParent = nodeParent->GetParent();
208 }
209 } else {
210 BookmarkModel* model = profile_->GetBookmarkModel();
211 nodeParent = model->GetBookmarkBarNode();
212 rowsToSelect.push_front(0);
213 }
214 for (std::deque<NSInteger>::size_type column = 0;
215 column < rowsToSelect.size();
216 ++column) {
217 [folderBrowser_ selectRow:rowsToSelect[column] inColumn:column];
218 }
219 [self controlTextDidChange:nil];
197 } 220 }
198 221
199 - (IBAction)cancel:(id)sender { 222 - (const BookmarkNode*)selectedNode {
200 [NSApp endSheet:[self window]]; 223 BookmarkModel* model = profile_->GetBookmarkModel();
224 const BookmarkNode* selectedNode = NULL;
225 // Determine a new parent node only if the browser is showing.
226 if (configuration_ == BookmarkEditor::SHOW_TREE) {
227 selectedNode = model->root_node();
228 NSInteger column = 0;
229 NSInteger selectedRow = [folderBrowser_ selectedRowInColumn:column];
230 while (selectedRow >= 0) {
231 selectedNode = GetFolderChildForParent(selectedNode,
232 selectedRow);
233 ++column;
234 selectedRow = [folderBrowser_ selectedRowInColumn:column];
235 }
236 } else {
237 // If the tree is not showing then we use the original parent.
238 selectedNode = parentNode_;
239 }
240 return selectedNode;
201 } 241 }
202 242
243 #pragma mark New Folder Handler & Folder Cell Editing
244
245 - (void)editFolderNameInCell:(BookmarkTreeBrowserCell*)cell {
246 DCHECK([cell isKindOfClass:[BookmarkTreeBrowserCell class]]);
247 [cell setEditable:YES];
248 [cell setTarget:self];
249 [cell setAction:@selector(cellEditingCompleted:)];
250 [cell setSendsActionOnEndEditing:YES];
251 currentEditCell_.reset([cell retain]);
252 NSMatrix* matrix = [cell matrix];
253 // Set the delegate so that we get called when editing wants to complete.
254 [matrix setDelegate:self];
255 [matrix selectText:self];
256 }
257
258 - (void)cellEditingCompleted:(id)sender {
259 DCHECK([sender isKindOfClass:[NSMatrix class]]);
260 BookmarkTreeBrowserCell* cell = [sender selectedCell];
261 DCHECK([cell isKindOfClass:[BookmarkTreeBrowserCell class]]);
262 [self saveFolderNameForCell:cell];
263 }
264
265 - (void)saveFolderNameForCell:(BookmarkTreeBrowserCell*)cell {
266 DCHECK([cell isKindOfClass:[BookmarkTreeBrowserCell class]]);
267 // It's possible that the cell can get reused so clean things up
268 // to prevent inadvertant notifications.
269 [cell setTarget:nil];
270 [cell setAction:nil];
271 [cell setEditable:NO];
272 [cell setSendsActionOnEndEditing:NO];
273 // Force a responder change here to force the editing of the cell's text
274 // to complete otherwise the call to -[cell title] could return stale text.
275 [[folderBrowser_ window] makeFirstResponder:folderBrowser_];
276 const BookmarkNode* bookmarkNode = [cell bookmarkNode];
277 BookmarkModel* model = profile_->GetBookmarkModel();
278 NSString* newTitle = [cell title];
279 model->SetTitle(bookmarkNode, base::SysNSStringToWide(newTitle));
280 currentEditCell_.reset();
281 }
282
283 - (void)browserDoubleClicked:(id)sender {
284 BookmarkTreeBrowserCell* cell = [folderBrowser_ selectedCell];
285 DCHECK([cell isKindOfClass:[BookmarkTreeBrowserCell class]]);
286 [self editFolderNameInCell:cell];
287 }
288
289 - (IBAction)newFolder:(id)sender {
290 BookmarkModel* model = profile_->GetBookmarkModel();
291 const BookmarkNode* newParentNode = [self selectedNode];
292 int newIndex = newParentNode->GetChildCount();
293 std::wstring newFolderString =
294 l10n_util::GetString(IDS_BOOMARK_EDITOR_NEW_FOLDER_NAME);
295 const BookmarkNode* newFolder = model->AddGroup(newParentNode, newIndex,
296 newFolderString);
297 [self selectNodeInBrowser:newFolder];
298 BookmarkTreeBrowserCell* cell = [folderBrowser_ selectedCell];
299 [self editFolderNameInCell:cell];
300 }
301
302 #pragma mark Bookmark Editing
303
203 // If possible, return a valid GURL from the URL text field. 304 // If possible, return a valid GURL from the URL text field.
204 - (GURL)GURLFromUrlField { 305 - (GURL)GURLFromUrlField {
205 NSString* url = [urlField_ stringValue]; 306 NSString* url = [urlField_ stringValue];
206 GURL newURL = GURL([url UTF8String]); 307 GURL newURL = GURL([url UTF8String]);
207 if (!newURL.is_valid()) { 308 if (!newURL.is_valid()) {
208 // Mimic observed friendliness from Windows 309 // Mimic observed friendliness from Windows
209 newURL = GURL([[NSString stringWithFormat:@"http://%@", url] UTF8String]); 310 newURL = GURL([[NSString stringWithFormat:@"http://%@", url] UTF8String]);
210 } 311 }
211 return newURL; 312 return newURL;
212 } 313 }
213 314
214 - (const BookmarkNode*)selectedParentNode {
215 BookmarkModel* model = profile_->GetBookmarkModel();
216 const BookmarkNode* selectedParentNode = NULL;
217 // Determine a new parent node only if the browser is showing.
218 if (configuration_ == BookmarkEditor::SHOW_TREE) {
219 selectedParentNode = model->root_node();
220 NSInteger column = 0;
221 NSInteger selectedRow = [browser_ selectedRowInColumn:column];
222 while (selectedRow >= 0) {
223 selectedParentNode = GetFolderChildForParent(selectedParentNode,
224 selectedRow);
225 ++column;
226 selectedRow = [browser_ selectedRowInColumn:column];
227 }
228 } else {
229 // If the tree is not showing then we use the original parent.
230 selectedParentNode = parentNode_;
231 }
232 return selectedParentNode;
233 }
234
235 // Enable the OK button if there is a bookmark name and there is a valid URL. 315 // Enable the OK button if there is a bookmark name and there is a valid URL.
236 // We set ourselves as the delegate of urlField_ so this gets called. 316 // We set ourselves as the delegate of urlField_ so this gets called.
237 // (Yes, setting ourself as a delegate automatically registers us for 317 // (Yes, setting ourself as a delegate automatically registers us for
238 // the notification.) 318 // the notification.)
239 - (void)controlTextDidChange:(NSNotification*)aNotification { 319 - (void)controlTextDidChange:(NSNotification*)aNotification {
240 // Name must not be empty, but it can be whitespace. 320 // Name must not be empty, but it can be whitespace.
241 NSString* name = [nameField_ stringValue]; 321 NSString* name = [nameField_ stringValue];
242 GURL newURL = [self GURLFromUrlField]; 322 GURL newURL = [self GURLFromUrlField];
243 [okButton_ setEnabled:([name length] != 0 && newURL.is_valid()) ? YES : NO]; 323 [okButton_ setEnabled:([name length] != 0 && newURL.is_valid()) ? YES : NO];
244 } 324 }
245 325
246 // The ok: action is connected to the OK button in the Edit Bookmark window 326 // The ok: action is connected to the OK button in the Edit Bookmark window
247 // of the BookmarkEditor.xib. The the bookmark's name and URL are assumed 327 // of the BookmarkEditor.xib. The the bookmark's name and URL are assumed
248 // to be valid (otherwise the OK button should not be enabled). If the 328 // to be valid (otherwise the OK button should not be enabled). If the
249 // bookmark previously existed then it is removed from its old folder. 329 // bookmark previously existed then it is removed from its old folder.
250 // The bookmark is then added to its new folder. If the folder has not 330 // The bookmark is then added to its new folder. If the folder has not
251 // changed then the bookmark stays in its original position (index) otherwise 331 // changed then the bookmark stays in its original position (index) otherwise
252 // it is added to the end of the new folder. 332 // it is added to the end of the new folder.
253 - (IBAction)ok:(id)sender { 333 - (IBAction)ok:(id)sender {
254 NSString* name = [nameField_ stringValue]; 334 NSString* name = [nameField_ stringValue];
255 std::wstring newTitle = base::SysNSStringToWide(name); 335 std::wstring newTitle = base::SysNSStringToWide(name);
256 GURL newURL = [self GURLFromUrlField]; 336 GURL newURL = [self GURLFromUrlField];
257 if (!newURL.is_valid()) { 337 if (!newURL.is_valid()) {
258 // Shouldn't be reached -- OK button disabled if not valid! 338 // Shouldn't be reached -- OK button disabled if not valid!
259 NOTREACHED(); 339 NOTREACHED();
260 return; 340 return;
261 } 341 }
262 342
263 // Determine where the new/replacement bookmark is to go. 343 // Determine where the new/replacement bookmark is to go.
264 const BookmarkNode* newParentNode = [self selectedParentNode]; 344 const BookmarkNode* newParentNode = [self selectedNode];
265 BookmarkModel* model = profile_->GetBookmarkModel(); 345 BookmarkModel* model = profile_->GetBookmarkModel();
266 int newIndex = newParentNode->GetChildCount(); 346 int newIndex = newParentNode->GetChildCount();
267 if (node_ && parentNode_) { 347 if (node_ && parentNode_) {
268 // Replace the old bookmark with the updated bookmark. 348 // Replace the old bookmark with the updated bookmark.
269 int oldIndex = parentNode_->IndexOfChild(node_); 349 int oldIndex = parentNode_->IndexOfChild(node_);
270 if (oldIndex >= 0) 350 if (oldIndex >= 0)
271 model->Remove(parentNode_, oldIndex); 351 model->Remove(parentNode_, oldIndex);
272 if (parentNode_ == newParentNode) 352 if (parentNode_ == newParentNode)
273 newIndex = oldIndex; 353 newIndex = oldIndex;
274 } 354 }
275 // Add bookmark as new node at the end of the newly selected folder. 355 // Add bookmark as new node at the end of the newly selected folder.
276 const BookmarkNode* node = model->AddURL(newParentNode, newIndex, 356 const BookmarkNode* node = model->AddURL(newParentNode, newIndex,
277 newTitle, newURL); 357 newTitle, newURL);
278 // Honor handler semantics: callback on node creation. 358 // Honor handler semantics: callback on node creation.
279 if (handler_.get()) 359 if (handler_.get())
280 handler_->NodeCreated(node); 360 handler_->NodeCreated(node);
281 [NSApp endSheet:[self window]]; 361 [NSApp endSheet:[self window]];
282 } 362 }
283 363
364 - (IBAction)cancel:(id)sender {
365 [NSApp endSheet:[self window]];
366 }
367
284 - (void)didEndSheet:(NSWindow*)sheet 368 - (void)didEndSheet:(NSWindow*)sheet
285 returnCode:(int)returnCode 369 returnCode:(int)returnCode
286 contextInfo:(void*)contextInfo { 370 contextInfo:(void*)contextInfo {
371 // If a folder name cell is being edited then force it to end editing
372 // so that any changes are recorded.
373 BookmarkTreeBrowserCell* currentEditCell = currentEditCell_.get();
374 if (currentEditCell) {
375 [self saveFolderNameForCell:currentEditCell];
376 currentEditCell_.reset();
377 }
287 // This is probably unnecessary but it feels cleaner since the 378 // This is probably unnecessary but it feels cleaner since the
288 // delegate of a text field can be automatically registered for 379 // delegate of a text field can be automatically registered for
289 // notifications. 380 // notifications.
290 [nameField_ setDelegate:nil]; 381 [nameField_ setDelegate:nil];
291 [urlField_ setDelegate:nil]; 382 [urlField_ setDelegate:nil];
292 383
293 [[self window] orderOut:self]; 384 [[self window] orderOut:self];
294 385
295 // BookmarkEditor::Show() will create us then run away. Unusually 386 // BookmarkEditor::Show() will create us then run away. Unusually
296 // for a controller, we are responsible for deallocating ourself. 387 // for a controller, we are responsible for deallocating ourself.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 420
330 // Given a column number, determine the parent bookmark folder node for the 421 // Given a column number, determine the parent bookmark folder node for the
331 // bookmarks being shown in that column. This is done by scanning forward 422 // bookmarks being shown in that column. This is done by scanning forward
332 // from column zero and following the selected row for each column up 423 // from column zero and following the selected row for each column up
333 // to the parent of the desired column. 424 // to the parent of the desired column.
334 - (const BookmarkNode*)parentNodeForColumn:(NSInteger)column { 425 - (const BookmarkNode*)parentNodeForColumn:(NSInteger)column {
335 DCHECK(column >= 0); 426 DCHECK(column >= 0);
336 BookmarkModel* model = profile_->GetBookmarkModel(); 427 BookmarkModel* model = profile_->GetBookmarkModel();
337 const BookmarkNode* node = model->root_node(); 428 const BookmarkNode* node = model->root_node();
338 for (NSInteger i = 0; i < column; ++i) { 429 for (NSInteger i = 0; i < column; ++i) {
339 NSInteger selectedRowInColumn = [browser_ selectedRowInColumn:i]; 430 NSInteger selectedRowInColumn = [folderBrowser_ selectedRowInColumn:i];
340 node = node->GetChild(selectedRowInColumn); 431 node = GetFolderChildForParent(node, selectedRowInColumn);
341 } 432 }
342 return node; 433 return node;
343 } 434 }
344 435
345 // This implementation returns the number of folders contained in the parent 436 // This implementation returns the number of folders contained in the parent
346 // folder node for this column. 437 // folder node for this column.
347 // TOTO(mrossetti): Decide if bookmark (i.e. non-folder) nodes should be 438 // TOTO(mrossetti): Decide if bookmark (i.e. non-folder) nodes should be
348 // shown, perhaps in gray. 439 // shown, perhaps in gray.
349 - (NSInteger)browser:(NSBrowser*)sender numberOfRowsInColumn:(NSInteger)col { 440 - (NSInteger)browser:(NSBrowser*)sender numberOfRowsInColumn:(NSInteger)col {
350 NSInteger rowCount = 0; 441 NSInteger rowCount = 0;
351 const BookmarkNode* parentNode = [self parentNodeForColumn:col]; 442 const BookmarkNode* parentNode = [self parentNodeForColumn:col];
352 if (parentNode) { 443 if (parentNode) {
353 int childCount = parentNode->GetChildCount(); 444 int childCount = parentNode->GetChildCount();
354 for (int i = 0; i < childCount; ++i) { 445 for (int i = 0; i < childCount; ++i) {
355 const BookmarkNode* childNode = parentNode->GetChild(i); 446 const BookmarkNode* childNode = parentNode->GetChild(i);
356 if (childNode->type() != BookmarkNode::URL) 447 if (childNode->type() != BookmarkNode::URL)
357 ++rowCount; 448 ++rowCount;
358 } 449 }
359 } 450 }
360 return rowCount; 451 return rowCount;
361 } 452 }
362 453
363 - (void)browser:(NSBrowser*)sender 454 - (void)browser:(NSBrowser*)sender
364 willDisplayCell:(NSBrowserCell*)cell 455 willDisplayCell:(NSBrowserCell*)cell
365 atRow:(NSInteger)row 456 atRow:(NSInteger)row
366 column:(NSInteger)column { 457 column:(NSInteger)column {
367 DCHECK(row >= 0); // Trust AppKit, but verify. 458 DCHECK(row >= 0); // Trust AppKit, but verify.
368 DCHECK(column >= 0); 459 DCHECK(column >= 0);
460 DCHECK([cell isKindOfClass:[BookmarkTreeBrowserCell class]]);
369 const BookmarkNode* parentNode = [self parentNodeForColumn:column]; 461 const BookmarkNode* parentNode = [self parentNodeForColumn:column];
370 const BookmarkNode* childNode = GetFolderChildForParent(parentNode, row); 462 const BookmarkNode* childNode = GetFolderChildForParent(parentNode, row);
371 DCHECK(childNode); 463 DCHECK(childNode);
372 [cell setTitle:base::SysWideToNSString(childNode->GetTitle())]; 464 BookmarkTreeBrowserCell* browserCell =
373 [cell setLeaf:childNode->GetChildCount() == 0]; 465 static_cast<BookmarkTreeBrowserCell*>(cell);
466 [browserCell setTitle:base::SysWideToNSString(childNode->GetTitle())];
467 [browserCell setBookmarkNode:childNode];
468 [browserCell setMatrix:[folderBrowser_ matrixInColumn:column]];
374 } 469 }
375 470
376 @end // BookmarkEditorController 471 @end // BookmarkEditorController
377 472
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/bookmark_editor_controller.h ('k') | chrome/browser/cocoa/bookmark_editor_controller_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698