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

Side by Side Diff: ios/chrome/search_widget_extension/search_widget_view_controller.mm

Issue 2858253002: Adding search widget UI and functionality. (Closed)
Patch Set: Created 3 years, 7 months 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
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/search_widget_extension/search_widget_view_controller.h" 5 #import "ios/chrome/search_widget_extension/search_widget_view_controller.h"
6 6
7 #import <NotificationCenter/NotificationCenter.h> 7 #import <NotificationCenter/NotificationCenter.h>
8 8
9 #include "base/ios/ios_util.h" 9 #include "base/ios/ios_util.h"
10 #include "base/mac/foundation_util.h" 10 #include "base/mac/foundation_util.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 delegate:nil]; 61 delegate:nil];
62 } 62 }
63 return self; 63 return self;
64 } 64 }
65 65
66 #pragma mark - UIViewController 66 #pragma mark - UIViewController
67 67
68 - (void)viewDidLoad { 68 - (void)viewDidLoad {
69 [super viewDidLoad]; 69 [super viewDidLoad];
70 70
71 UIVibrancyEffect* primary;
72 UIVibrancyEffect* secondary;
73 if (base::ios::IsRunningOnIOS10OrLater()) {
74 primary = [UIVibrancyEffect widgetPrimaryVibrancyEffect];
75 secondary = [UIVibrancyEffect widgetSecondaryVibrancyEffect];
76 } else {
77 primary = [UIVibrancyEffect notificationCenterVibrancyEffect];
78 secondary = [UIVibrancyEffect notificationCenterVibrancyEffect];
79 }
80
71 // A local variable is necessary here as the property is declared weak and the 81 // A local variable is necessary here as the property is declared weak and the
72 // object would be deallocated before being retained by the addSubview call. 82 // object would be deallocated before being retained by the addSubview call.
73 SearchWidgetView* widgetView = 83 SearchWidgetView* widgetView =
74 [[SearchWidgetView alloc] initWithActionTarget:self]; 84 [[SearchWidgetView alloc] initWithActionTarget:self
85 primaryVibrancyEffect:primary
86 secondaryVibrancyEffect:secondary];
75 self.widgetView = widgetView; 87 self.widgetView = widgetView;
76 [self.view addSubview:self.widgetView]; 88 [self.view addSubview:self.widgetView];
77 89
78 if (base::ios::IsRunningOnIOS10OrLater()) { 90 if (base::ios::IsRunningOnIOS10OrLater()) {
79 self.extensionContext.widgetLargestAvailableDisplayMode = 91 self.extensionContext.widgetLargestAvailableDisplayMode =
80 NCWidgetDisplayModeExpanded; 92 NCWidgetDisplayModeExpanded;
81 } 93 }
82 94
83 self.widgetView.translatesAutoresizingMaskIntoConstraints = NO; 95 self.widgetView.translatesAutoresizingMaskIntoConstraints = NO;
84 96
85 NSLayoutConstraint* heightAnchor = [self.widgetView.heightAnchor
86 constraintEqualToAnchor:self.view.heightAnchor];
87 heightAnchor.priority = 900;
88
89 [NSLayoutConstraint activateConstraints:@[ 97 [NSLayoutConstraint activateConstraints:@[
stkhapugin 2017/05/04 13:12:09 I think you can replace this code with a helper th
lody 2017/05/05 17:05:44 Done.
90 [self.widgetView.leadingAnchor 98 [self.widgetView.leadingAnchor
91 constraintEqualToAnchor:self.view.leadingAnchor], 99 constraintEqualToAnchor:self.view.leadingAnchor],
92 [self.widgetView.widthAnchor constraintEqualToAnchor:self.view.widthAnchor],
93 [self.widgetView.trailingAnchor 100 [self.widgetView.trailingAnchor
94 constraintEqualToAnchor:self.view.trailingAnchor], 101 constraintEqualToAnchor:self.view.trailingAnchor],
95 heightAnchor, 102 [self.widgetView.bottomAnchor
103 constraintEqualToAnchor:self.view.bottomAnchor],
96 [self.widgetView.topAnchor constraintEqualToAnchor:self.view.topAnchor], 104 [self.widgetView.topAnchor constraintEqualToAnchor:self.view.topAnchor],
97 ]]; 105 ]];
98 } 106 }
99 107
100 - (void)viewWillAppear:(BOOL)animated { 108 - (void)viewWillAppear:(BOOL)animated {
101 [super viewWillAppear:animated]; 109 [super viewWillAppear:animated];
102 [self updateWidget]; 110 [self updateWidget];
103 } 111 }
104 112
105 - (void)widgetPerformUpdateWithCompletionHandler: 113 - (void)widgetPerformUpdateWithCompletionHandler:
(...skipping 10 matching lines...) Expand all
116 [self.widgetView updateCopiedURL:self.copiedURL.absoluteString]; 124 [self.widgetView updateCopiedURL:self.copiedURL.absoluteString];
117 return YES; 125 return YES;
118 } 126 }
119 return NO; 127 return NO;
120 } 128 }
121 129
122 #pragma mark - NCWidgetProviding 130 #pragma mark - NCWidgetProviding
123 131
124 - (void)widgetActiveDisplayModeDidChange:(NCWidgetDisplayMode)activeDisplayMode 132 - (void)widgetActiveDisplayModeDidChange:(NCWidgetDisplayMode)activeDisplayMode
125 withMaximumSize:(CGSize)maxSize { 133 withMaximumSize:(CGSize)maxSize {
134 // Set the copied URL section here so that the fitting size is correctly
135 // calculated.
136 [self.widgetView
137 setCopiedURLVisible:(activeDisplayMode == NCWidgetDisplayModeExpanded)];
126 CGSize fittingSize = [self.widgetView 138 CGSize fittingSize = [self.widgetView
stkhapugin 2017/05/04 13:12:09 Please add a newline and a comment for line 138 an
lody 2017/05/05 17:05:44 Done.
127 systemLayoutSizeFittingSize:UILayoutFittingCompressedSize]; 139 systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
128 if (fittingSize.height > maxSize.height) { 140 if (fittingSize.height > maxSize.height) {
129 self.preferredContentSize = maxSize; 141 self.preferredContentSize = maxSize;
130 } else { 142 } else {
131 self.preferredContentSize = fittingSize; 143 self.preferredContentSize = fittingSize;
132 } 144 }
133 } 145 }
134 146
135 #pragma mark - WidgetViewActionTarget 147 #pragma mark - WidgetViewActionTarget
136 148
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 }; 227 };
216 } 228 }
217 return @{ 229 return @{
218 timePrefKey : [NSDate date], 230 timePrefKey : [NSDate date],
219 appPrefKey : @"TodayExtension", 231 appPrefKey : @"TodayExtension",
220 commandPrefKey : command, 232 commandPrefKey : command,
221 }; 233 };
222 } 234 }
223 235
224 @end 236 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698