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

Side by Side Diff: ios/chrome/browser/passwords/password_generation_prompt_view_controller.mm

Issue 2585233003: Upstream Chrome on iOS source code [2/11]. (Closed)
Patch Set: Created 4 years 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #import "ios/chrome/browser/passwords/password_generation_prompt_view_controller .h"
6
7 #import <UIKit/UIKit.h>
8
9 #include "base/ios/weak_nsobject.h"
10 #include "base/mac/scoped_nsobject.h"
11 #import "ios/chrome/browser/passwords/password_generation_prompt_view.h"
12 #import "ios/chrome/browser/ui/rtl_geometry.h"
13 #import "ios/chrome/browser/ui/uikit_ui_util.h"
14 #import "ios/third_party/material_components_ios/src/components/Dialogs/src/Mate rialDialogs.h"
15
16 namespace {
17 // Material Design Component constraints.
18 const CGFloat kMDCPadding = 24;
19 const CGFloat kMDCMargin = 40;
20
21 // Maximum size of the dialog.
22 const CGFloat kPrefWidth = 450;
23 const CGFloat kPrefHeight = 500;
24
25 } // namespace
26
27 @interface PasswordGenerationPromptViewController () {
28 base::scoped_nsobject<NSString> _password;
29 base::WeakNSObject<UIViewController> _viewController;
30 base::WeakNSObject<PasswordGenerationPromptDialog> _contentView;
31 }
32
33 // Returns the maximum size of the dialog.
34 - (CGFloat)maxDialogWidth;
35
36 @end
37
38 @implementation PasswordGenerationPromptViewController
39
40 - (CGFloat)maxDialogWidth {
41 CGFloat screenWidth = [[UIScreen mainScreen] bounds].size.width;
42 return MIN(kPrefWidth, screenWidth - 2 * kMDCMargin);
43 }
44
45 - (instancetype)initWithPassword:(NSString*)password
46 contentView:(PasswordGenerationPromptDialog*)contentView
47 viewController:(UIViewController*)viewController {
48 self = [super initWithNibName:nil bundle:nil];
49 if (self) {
50 _password.reset([password copy]);
51 _viewController.reset(viewController);
52 _contentView.reset(contentView);
53 self.modalPresentationStyle = UIModalPresentationCustom;
54 self.transitioningDelegate =
55 [[[MDCDialogTransitionController alloc] init] autorelease];
56 }
57 return self;
58 }
59
60 - (void)viewDidLoad {
61 [super viewDidLoad];
62
63 self.view.backgroundColor = [UIColor whiteColor];
64
65 [_contentView configureGlobalViewWithPassword:_password];
66 [_contentView setTranslatesAutoresizingMaskIntoConstraints:NO];
67
68 self.preferredContentSize = CGSizeMake([self maxDialogWidth], kPrefHeight);
69
70 [self.view addSubview:_contentView];
71
72 NSArray* constraints = @[
73 @"V:|-(MDCPadding)-[view]", @"H:|-(MDCPadding)-[view]-(MDCPadding)-|"
74 ];
75 NSDictionary* viewsDictionary = @{ @"view" : _contentView };
76 NSDictionary* metrics = @{ @"MDCPadding" : @(kMDCPadding) };
77
78 ApplyVisualConstraintsWithMetricsAndOptions(
79 constraints, viewsDictionary, metrics, LayoutOptionForRTLSupport());
80 }
81
82 - (void)viewDidLayoutSubviews {
83 CGSize currentSize = CGSizeMake(
84 [self maxDialogWidth], [_contentView frame].size.height + kMDCPadding);
85 self.preferredContentSize = currentSize;
86 }
87
88 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698