| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ios/chrome/browser/ui/bookmarks/bookmark_menu_item.h" | 5 #import "ios/chrome/browser/ui/bookmarks/bookmark_menu_item.h" |
| 6 | 6 |
| 7 #include "base/hash.h" | 7 #include "base/hash.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/mac/objc_property_releaser.h" | 9 #include "base/mac/objc_release_properties.h" |
| 10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
| 11 #include "components/bookmarks/browser/bookmark_node.h" | 11 #include "components/bookmarks/browser/bookmark_node.h" |
| 12 #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h" | 12 #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h" |
| 13 #include "ios/chrome/grit/ios_strings.h" | 13 #include "ios/chrome/grit/ios_strings.h" |
| 14 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
| 15 | 15 |
| 16 using bookmarks::BookmarkNode; | 16 using bookmarks::BookmarkNode; |
| 17 | 17 |
| 18 namespace bookmarks { | 18 namespace bookmarks { |
| 19 BOOL NumberIsValidMenuItemType(int number) { | 19 BOOL NumberIsValidMenuItemType(int number) { |
| 20 // Invalid and deprecated numbers. | 20 // Invalid and deprecated numbers. |
| 21 if (number < 1 || number > MenuItemLast) | 21 if (number < 1 || number > MenuItemLast) |
| 22 return NO; | 22 return NO; |
| 23 MenuItemType type = static_cast<MenuItemType>(number); | 23 MenuItemType type = static_cast<MenuItemType>(number); |
| 24 switch (type) { | 24 switch (type) { |
| 25 case MenuItemFolder: | 25 case MenuItemFolder: |
| 26 return YES; | 26 return YES; |
| 27 | 27 |
| 28 case MenuItemDivider: | 28 case MenuItemDivider: |
| 29 case MenuItemSectionHeader: | 29 case MenuItemSectionHeader: |
| 30 return NO; | 30 return NO; |
| 31 } | 31 } |
| 32 } | 32 } |
| 33 } // namespace bookmarks | 33 } // namespace bookmarks |
| 34 | 34 |
| 35 @interface BookmarkMenuItem () { | 35 @interface BookmarkMenuItem () |
| 36 base::mac::ObjCPropertyReleaser _propertyReleaser_BookmarkMenuItem; | |
| 37 } | |
| 38 // Redefined to be read-write. | 36 // Redefined to be read-write. |
| 39 @property(nonatomic, assign) const BookmarkNode* folder; | 37 @property(nonatomic, assign) const BookmarkNode* folder; |
| 40 @property(nonatomic, assign) const BookmarkNode* rootAncestor; | 38 @property(nonatomic, assign) const BookmarkNode* rootAncestor; |
| 41 // Redefined to be read-write. | 39 // Redefined to be read-write. |
| 42 @property(nonatomic, assign) bookmarks::MenuItemType type; | 40 @property(nonatomic, assign) bookmarks::MenuItemType type; |
| 43 // Redefined to be read-write. | 41 // Redefined to be read-write. |
| 44 @property(nonatomic, copy) NSString* sectionTitle; | 42 @property(nonatomic, copy) NSString* sectionTitle; |
| 45 @end | 43 @end |
| 46 | 44 |
| 47 @implementation BookmarkMenuItem | 45 @implementation BookmarkMenuItem |
| 48 @synthesize folder = _folder; | 46 @synthesize folder = _folder; |
| 49 @synthesize rootAncestor = _rootAncestor; | 47 @synthesize rootAncestor = _rootAncestor; |
| 50 @synthesize sectionTitle = _sectionTitle; | 48 @synthesize sectionTitle = _sectionTitle; |
| 51 @synthesize type = _type; | 49 @synthesize type = _type; |
| 52 | 50 |
| 53 - (instancetype)init { | 51 - (void)dealloc { |
| 54 self = [super init]; | 52 base::mac::ReleaseProperties(self); |
| 55 if (self) { | 53 [super dealloc]; |
| 56 _propertyReleaser_BookmarkMenuItem.Init(self, [BookmarkMenuItem class]); | |
| 57 } | |
| 58 return self; | |
| 59 } | 54 } |
| 60 | 55 |
| 61 - (UIAccessibilityTraits)accessibilityTraits { | 56 - (UIAccessibilityTraits)accessibilityTraits { |
| 62 switch (self.type) { | 57 switch (self.type) { |
| 63 case bookmarks::MenuItemFolder: | 58 case bookmarks::MenuItemFolder: |
| 64 return super.accessibilityTraits |= UIAccessibilityTraitButton; | 59 return super.accessibilityTraits |= UIAccessibilityTraitButton; |
| 65 case bookmarks::MenuItemSectionHeader: | 60 case bookmarks::MenuItemSectionHeader: |
| 66 return super.accessibilityTraits |= UIAccessibilityTraitHeader; | 61 return super.accessibilityTraits |= UIAccessibilityTraitHeader; |
| 67 case bookmarks::MenuItemDivider: | 62 case bookmarks::MenuItemDivider: |
| 68 return UIAccessibilityTraitNone; | 63 return UIAccessibilityTraitNone; |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 } | 204 } |
| 210 | 205 |
| 211 + (BookmarkMenuItem*)sectionMenuItemWithTitle:(NSString*)title { | 206 + (BookmarkMenuItem*)sectionMenuItemWithTitle:(NSString*)title { |
| 212 BookmarkMenuItem* item = [[[BookmarkMenuItem alloc] init] autorelease]; | 207 BookmarkMenuItem* item = [[[BookmarkMenuItem alloc] init] autorelease]; |
| 213 item.type = bookmarks::MenuItemSectionHeader; | 208 item.type = bookmarks::MenuItemSectionHeader; |
| 214 item.sectionTitle = title; | 209 item.sectionTitle = title; |
| 215 return item; | 210 return item; |
| 216 } | 211 } |
| 217 | 212 |
| 218 @end | 213 @end |
| OLD | NEW |