| 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_edit_view_controller.h" | 5 #import "ios/chrome/browser/ui/bookmarks/bookmark_edit_view_controller.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| 11 #include "base/ios/block_types.h" | 11 #include "base/ios/block_types.h" |
| 12 #include "base/ios/weak_nsobject.h" | 12 #include "base/ios/weak_nsobject.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/mac/bind_objc_block.h" | 14 #include "base/mac/bind_objc_block.h" |
| 15 #import "base/mac/foundation_util.h" | 15 #import "base/mac/foundation_util.h" |
| 16 #include "base/mac/objc_property_releaser.h" | 16 #include "base/mac/objc_release_properties.h" |
| 17 #include "base/mac/scoped_cftyperef.h" | 17 #include "base/mac/scoped_cftyperef.h" |
| 18 #include "base/mac/scoped_nsobject.h" | 18 #include "base/mac/scoped_nsobject.h" |
| 19 #include "base/strings/sys_string_conversions.h" | 19 #include "base/strings/sys_string_conversions.h" |
| 20 #include "components/bookmarks/browser/bookmark_model.h" | 20 #include "components/bookmarks/browser/bookmark_model.h" |
| 21 #include "components/url_formatter/url_fixer.h" | 21 #include "components/url_formatter/url_fixer.h" |
| 22 #include "ios/chrome/browser/bookmarks/bookmark_model_factory.h" | 22 #include "ios/chrome/browser/bookmarks/bookmark_model_factory.h" |
| 23 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 23 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| 24 #import "ios/chrome/browser/ui/bookmarks/bookmark_elevated_toolbar.h" | 24 #import "ios/chrome/browser/ui/bookmarks/bookmark_elevated_toolbar.h" |
| 25 #import "ios/chrome/browser/ui/bookmarks/bookmark_extended_button.h" | 25 #import "ios/chrome/browser/ui/bookmarks/bookmark_extended_button.h" |
| 26 #import "ios/chrome/browser/ui/bookmarks/bookmark_folder_view_controller.h" | 26 #import "ios/chrome/browser/ui/bookmarks/bookmark_folder_view_controller.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 } // namespace | 71 } // namespace |
| 72 | 72 |
| 73 @interface BookmarkEditViewController ()<BookmarkFolderViewControllerDelegate, | 73 @interface BookmarkEditViewController ()<BookmarkFolderViewControllerDelegate, |
| 74 BookmarkModelBridgeObserver, | 74 BookmarkModelBridgeObserver, |
| 75 BookmarkTextFieldItemDelegate, | 75 BookmarkTextFieldItemDelegate, |
| 76 TextFieldValidation> { | 76 TextFieldValidation> { |
| 77 // Flag to ignore bookmark model changes notifications. | 77 // Flag to ignore bookmark model changes notifications. |
| 78 BOOL _ignoresBookmarkModelChanges; | 78 BOOL _ignoresBookmarkModelChanges; |
| 79 | 79 |
| 80 std::unique_ptr<bookmarks::BookmarkModelBridge> _modelBridge; | 80 std::unique_ptr<bookmarks::BookmarkModelBridge> _modelBridge; |
| 81 | |
| 82 base::mac::ObjCPropertyReleaser _propertyReleaser_BookmarkEditViewController; | |
| 83 } | 81 } |
| 84 | 82 |
| 85 // The bookmark this controller displays or edits. | 83 // The bookmark this controller displays or edits. |
| 86 // Redefined to be readwrite. | 84 // Redefined to be readwrite. |
| 87 @property(nonatomic, assign) const BookmarkNode* bookmark; | 85 @property(nonatomic, assign) const BookmarkNode* bookmark; |
| 88 | 86 |
| 89 // Reference to the bookmark model. | 87 // Reference to the bookmark model. |
| 90 @property(nonatomic, assign) BookmarkModel* bookmarkModel; | 88 @property(nonatomic, assign) BookmarkModel* bookmarkModel; |
| 91 | 89 |
| 92 // The parent of the bookmark. This may be different from |bookmark->parent()| | 90 // The parent of the bookmark. This may be different from |bookmark->parent()| |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 @synthesize URLItem = _URLItem; | 159 @synthesize URLItem = _URLItem; |
| 162 | 160 |
| 163 #pragma mark - Lifecycle | 161 #pragma mark - Lifecycle |
| 164 | 162 |
| 165 - (instancetype)initWithBookmark:(const BookmarkNode*)bookmark | 163 - (instancetype)initWithBookmark:(const BookmarkNode*)bookmark |
| 166 browserState:(ios::ChromeBrowserState*)browserState { | 164 browserState:(ios::ChromeBrowserState*)browserState { |
| 167 DCHECK(bookmark); | 165 DCHECK(bookmark); |
| 168 DCHECK(browserState); | 166 DCHECK(browserState); |
| 169 self = [super initWithStyle:CollectionViewControllerStyleAppBar]; | 167 self = [super initWithStyle:CollectionViewControllerStyleAppBar]; |
| 170 if (self) { | 168 if (self) { |
| 171 _propertyReleaser_BookmarkEditViewController.Init( | |
| 172 self, [BookmarkEditViewController class]); | |
| 173 DCHECK(!bookmark->is_folder()); | 169 DCHECK(!bookmark->is_folder()); |
| 174 DCHECK(!browserState->IsOffTheRecord()); | 170 DCHECK(!browserState->IsOffTheRecord()); |
| 175 _bookmark = bookmark; | 171 _bookmark = bookmark; |
| 176 _bookmarkModel = | 172 _bookmarkModel = |
| 177 ios::BookmarkModelFactory::GetForBrowserState(browserState); | 173 ios::BookmarkModelFactory::GetForBrowserState(browserState); |
| 178 | 174 |
| 179 _folder = bookmark->parent(); | 175 _folder = bookmark->parent(); |
| 180 | 176 |
| 181 // Set up the bookmark model oberver. | 177 // Set up the bookmark model oberver. |
| 182 _modelBridge.reset( | 178 _modelBridge.reset( |
| 183 new bookmarks::BookmarkModelBridge(self, _bookmarkModel)); | 179 new bookmarks::BookmarkModelBridge(self, _bookmarkModel)); |
| 184 | 180 |
| 185 _browserState = browserState; | 181 _browserState = browserState; |
| 186 } | 182 } |
| 187 return self; | 183 return self; |
| 188 } | 184 } |
| 189 | 185 |
| 190 - (void)dealloc { | 186 - (void)dealloc { |
| 191 _folderViewController.delegate = nil; | 187 _folderViewController.delegate = nil; |
| 188 base::mac::ReleaseProperties(self); |
| 192 [super dealloc]; | 189 [super dealloc]; |
| 193 } | 190 } |
| 194 | 191 |
| 195 #pragma mark View lifecycle | 192 #pragma mark View lifecycle |
| 196 | 193 |
| 197 - (void)viewDidLoad { | 194 - (void)viewDidLoad { |
| 198 [super viewDidLoad]; | 195 [super viewDidLoad]; |
| 199 self.collectionView.backgroundColor = [UIColor whiteColor]; | 196 self.collectionView.backgroundColor = [UIColor whiteColor]; |
| 200 self.view.accessibilityIdentifier = @"Single Bookmark Editor"; | 197 self.view.accessibilityIdentifier = @"Single Bookmark Editor"; |
| 201 | 198 |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 base::WeakNSObject<BookmarkEditViewController> weakSelf(self); | 583 base::WeakNSObject<BookmarkEditViewController> weakSelf(self); |
| 587 return @[ [UIKeyCommand cr_keyCommandWithInput:UIKeyInputEscape | 584 return @[ [UIKeyCommand cr_keyCommandWithInput:UIKeyInputEscape |
| 588 modifierFlags:Cr_UIKeyModifierNone | 585 modifierFlags:Cr_UIKeyModifierNone |
| 589 title:nil | 586 title:nil |
| 590 action:^{ | 587 action:^{ |
| 591 [weakSelf dismiss]; | 588 [weakSelf dismiss]; |
| 592 }] ]; | 589 }] ]; |
| 593 } | 590 } |
| 594 | 591 |
| 595 @end | 592 @end |
| OLD | NEW |