OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/toolbar/tools_menu_button_observer_bridge.h" | 5 #import "ios/chrome/browser/ui/toolbar/tools_menu_button_observer_bridge.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "components/reading_list/core/reading_list_model.h" | 9 #include "components/reading_list/core/reading_list_model.h" |
10 #import "ios/chrome/browser/ui/toolbar/toolbar_tools_menu_button.h" | 10 #import "ios/chrome/browser/ui/toolbar/toolbar_tools_menu_button.h" |
11 | 11 |
12 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
13 #error "This file requires ARC support." | |
14 #endif | |
15 | |
16 @interface ToolsMenuButtonObserverBridge () | 12 @interface ToolsMenuButtonObserverBridge () |
17 - (void)updateButtonWithModel:(const ReadingListModel*)model; | 13 - (void)updateButtonWithModel:(const ReadingListModel*)model; |
18 - (void)buttonPressed:(UIButton*)sender; | 14 - (void)buttonPressed:(UIButton*)sender; |
19 @end | 15 @end |
20 | 16 |
21 @implementation ToolsMenuButtonObserverBridge { | 17 @implementation ToolsMenuButtonObserverBridge { |
22 ToolbarToolsMenuButton* _button; | 18 base::scoped_nsobject<ToolbarToolsMenuButton> _button; |
23 ReadingListModel* _model; | 19 ReadingListModel* _model; |
24 std::unique_ptr<ReadingListModelBridge> _modelBridge; | 20 std::unique_ptr<ReadingListModelBridge> _modelBridge; |
25 } | 21 } |
26 | 22 |
27 - (instancetype)initWithModel:(ReadingListModel*)readingListModel | 23 - (instancetype)initWithModel:(ReadingListModel*)readingListModel |
28 toolbarButton:(ToolbarToolsMenuButton*)button { | 24 toolbarButton:(ToolbarToolsMenuButton*)button { |
29 self = [super init]; | 25 self = [super init]; |
30 if (self) { | 26 if (self) { |
31 _button = button; | 27 _button.reset([button retain]); |
32 _model = readingListModel; | 28 _model = readingListModel; |
33 [_button addTarget:self | 29 [_button addTarget:self |
34 action:@selector(buttonPressed:) | 30 action:@selector(buttonPressed:) |
35 forControlEvents:UIControlEventTouchUpInside]; | 31 forControlEvents:UIControlEventTouchUpInside]; |
36 _modelBridge = base::MakeUnique<ReadingListModelBridge>(self, _model); | 32 _modelBridge = base::MakeUnique<ReadingListModelBridge>(self, _model); |
37 } | 33 } |
38 return self; | 34 return self; |
39 } | 35 } |
40 | 36 |
41 - (void)updateButtonWithModel:(const ReadingListModel*)model { | 37 - (void)updateButtonWithModel:(const ReadingListModel*)model { |
(...skipping 25 matching lines...) Expand all Loading... |
67 } | 63 } |
68 | 64 |
69 - (void)readingListModel:(const ReadingListModel*)model | 65 - (void)readingListModel:(const ReadingListModel*)model |
70 didAddEntry:(const GURL&)url | 66 didAddEntry:(const GURL&)url |
71 entrySource:(reading_list::EntrySource)source { | 67 entrySource:(reading_list::EntrySource)source { |
72 if (source == reading_list::ADDED_VIA_CURRENT_APP) | 68 if (source == reading_list::ADDED_VIA_CURRENT_APP) |
73 [_button triggerAnimation]; | 69 [_button triggerAnimation]; |
74 } | 70 } |
75 | 71 |
76 @end | 72 @end |
OLD | NEW |