BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / content_settings / cookie_tree_node.mm
blob44b97d051810b1561dab13707bcd1e3b196ae349
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
3 // found in the LICENSE file.
5 #import "chrome/browser/ui/cocoa/content_settings/cookie_tree_node.h"
7 #include "base/strings/sys_string_conversions.h"
9 @implementation CocoaCookieTreeNode
11 - (id)initWithNode:(CookieTreeNode*)node {
12   if ((self = [super init])) {
13     DCHECK(node);
14     treeNode_ = node;
15     [self rebuild];
16   }
17   return self;
20 - (void)rebuild {
21   title_.reset([base::SysUTF16ToNSString(treeNode_->GetTitle()) retain]);
22   children_.reset();
23   // The tree node assumes ownership of the cookie details object
24   details_.reset([[CocoaCookieDetails createFromCookieTreeNode:(treeNode_)]
25       retain]);
28 - (NSString*)title {
29   return title_.get();
32 - (CocoaCookieDetailsType)nodeType {
33   return [details_.get() type];
36 - (ui::TreeModelNode*)treeNode {
37   return treeNode_;
40 - (NSMutableArray*)mutableChildren {
41   if (!children_.get()) {
42     const int childCount = treeNode_->child_count();
43     children_.reset([[NSMutableArray alloc] initWithCapacity:childCount]);
44     for (int i = 0; i < childCount; ++i) {
45       CookieTreeNode* child = treeNode_->GetChild(i);
46       base::scoped_nsobject<CocoaCookieTreeNode> childNode(
47           [[CocoaCookieTreeNode alloc] initWithNode:child]);
48       [children_ addObject:childNode.get()];
49     }
50   }
51   return children_.get();
54 - (NSArray*)children {
55   return [self mutableChildren];
58 - (BOOL)isLeaf {
59   return [self nodeType] != kCocoaCookieDetailsTypeFolder;
62 - (NSString*)description {
63   NSString* format =
64       @"<CocoaCookieTreeNode @ %p (title=%@, nodeType=%d, childCount=%u)";
65   return [NSString stringWithFormat:format, self, [self title],
66       [self nodeType], [[self children] count]];
69 - (CocoaCookieDetails*)details {
70   return details_;
73 @end