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

Side by Side Diff: chrome/installer/mac/app/InstallerWindowController.m

Issue 2293923005: General comment cleaning / refactoring for Mac Installer (Closed)
Patch Set: Ivan fixes Created 4 years, 3 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 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 "InstallerWindowController.h" 5 #import "InstallerWindowController.h"
6 6
7 #import "AppDelegate.h" 7 #import "AppDelegate.h"
8 8
9 @interface InstallerWindowController () { 9 @interface InstallerWindowController () {
10 NSButton* importButton_; 10 NSButton* importButton_;
11 NSButton* defaultBrowserButton_; 11 NSButton* defaultBrowserButton_;
12 NSButton* optInButton_; 12 NSButton* optInButton_;
13 NSButton* launchButton_; 13 NSButton* launchButton_;
14 NSTextField* statusDescription_; 14 NSTextField* statusDescription_;
15 NSTextField* downloadProgressDescription_; 15 NSTextField* downloadProgressDescription_;
16 NSProgressIndicator* progressBar_; 16 NSProgressIndicator* progressBar_;
17 } 17 }
18 @end 18 @end
19 19
20 @implementation InstallerWindowController 20 @implementation InstallerWindowController
21 21
22 // Most buttons have the same style and differ only by their title, this method 22 // Simplify styling and naming buttons.
23 // simplifies styling the buttons and provides an argument for the title.
24 - (void)stylizeButton:(NSButton*)button withTitle:(NSString*)title { 23 - (void)stylizeButton:(NSButton*)button withTitle:(NSString*)title {
25 button.buttonType = NSSwitchButton; 24 button.buttonType = NSSwitchButton;
26 button.bezelStyle = NSRoundedBezelStyle; 25 button.bezelStyle = NSRoundedBezelStyle;
27 button.title = title; 26 button.title = title;
28 } 27 }
29 28
30 // Similar to stylizeButton except works with NSTextField objects instead.
31 - (void)stylizeTextField:(NSTextField*)textField
32 withDescription:(NSString*)description {
33 textField.backgroundColor = NSColor.clearColor;
34 textField.textColor = NSColor.blackColor;
35 textField.stringValue = description;
36 textField.bezeled = NO;
37 textField.editable = NO;
38 }
39
40 // Positions and stylizes buttons. 29 // Positions and stylizes buttons.
41 - (void)setUpButtons { 30 - (void)setUpButtons {
42 importButton_ = [[NSButton alloc] initWithFrame:NSMakeRect(30, 20, 300, 25)]; 31 importButton_ = [[NSButton alloc] initWithFrame:NSMakeRect(30, 20, 300, 25)];
43 [self stylizeButton:importButton_ 32 [self stylizeButton:importButton_
44 withTitle:@"Import from... Wait import what?"]; 33 withTitle:@"Import from... Wait import what?"];
45 34
46 defaultBrowserButton_.state = NSOnState; 35 defaultBrowserButton_.state = NSOnState;
47 defaultBrowserButton_ = 36 defaultBrowserButton_ =
48 [[NSButton alloc] initWithFrame:NSMakeRect(30, 45, 300, 25)]; 37 [[NSButton alloc] initWithFrame:NSMakeRect(30, 45, 300, 25)];
49 [self stylizeButton:defaultBrowserButton_ 38 [self stylizeButton:defaultBrowserButton_
50 withTitle:@"Make Chrome the default browser."]; 39 withTitle:@"Make Chrome the default browser."];
51 40
52 optInButton_ = [[NSButton alloc] initWithFrame:NSMakeRect(30, 70, 300, 25)]; 41 optInButton_ = [[NSButton alloc] initWithFrame:NSMakeRect(30, 70, 300, 25)];
53 [self stylizeButton:optInButton_ withTitle:@"Say yes to UMA."]; 42 [self stylizeButton:optInButton_ withTitle:@"Say yes to UMA."];
54 43
55 launchButton_ = [[NSButton alloc] initWithFrame:NSMakeRect(310, 6, 100, 50)]; 44 launchButton_ = [[NSButton alloc] initWithFrame:NSMakeRect(310, 6, 100, 50)];
56 launchButton_.buttonType = NSPushOnPushOffButton; 45 launchButton_.buttonType = NSPushOnPushOffButton;
57 launchButton_.bezelStyle = NSRoundedBezelStyle; 46 launchButton_.bezelStyle = NSRoundedBezelStyle;
58 launchButton_.title = @"Launch"; 47 launchButton_.title = @"Launch";
59 [launchButton_ setEnabled:NO]; 48 [launchButton_ setEnabled:NO];
60 [launchButton_ setAction:@selector(launchButtonClicked)]; 49 [launchButton_ setAction:@selector(launchButtonClicked)];
61 } 50 }
62 51
52 // Simplfy styling NSTextField objects.
53 - (void)stylizeTextField:(NSTextField*)textField
54 withDescription:(NSString*)description {
55 textField.backgroundColor = NSColor.clearColor;
56 textField.textColor = NSColor.blackColor;
57 textField.stringValue = description;
58 textField.bezeled = NO;
59 textField.editable = NO;
60 }
61
63 // Positions and stylizes textfields. 62 // Positions and stylizes textfields.
64 - (void)setUpTextfields { 63 - (void)setUpTextfields {
65 statusDescription_ = 64 statusDescription_ =
66 [[NSTextField alloc] initWithFrame:NSMakeRect(20, 95, 300, 20)]; 65 [[NSTextField alloc] initWithFrame:NSMakeRect(20, 95, 300, 20)];
67 [self stylizeTextField:statusDescription_ 66 [self stylizeTextField:statusDescription_
68 withDescription:@"Working on it! While you're waiting..."]; 67 withDescription:@"Working on it! While you're waiting..."];
69 68
70 downloadProgressDescription_ = 69 downloadProgressDescription_ =
71 [[NSTextField alloc] initWithFrame:NSMakeRect(20, 160, 300, 20)]; 70 [[NSTextField alloc] initWithFrame:NSMakeRect(20, 160, 300, 20)];
72 [self stylizeTextField:downloadProgressDescription_ 71 [self stylizeTextField:downloadProgressDescription_
73 withDescription:@"Downloading... "]; 72 withDescription:@"Downloading... "];
74 } 73 }
75 74
76 // Positions and stylizes the progressbar for download and install. 75 // Positions and stylizes the progressbar for download and install.
77 - (void)setUpProgressBar { 76 - (void)setUpProgressBar {
78 progressBar_ = 77 progressBar_ =
79 [[NSProgressIndicator alloc] initWithFrame:NSMakeRect(15, 125, 400, 50)]; 78 [[NSProgressIndicator alloc] initWithFrame:NSMakeRect(15, 125, 400, 50)];
80 progressBar_.indeterminate = NO; 79 progressBar_.indeterminate = NO;
81 progressBar_.style = NSProgressIndicatorBarStyle; 80 progressBar_.style = NSProgressIndicatorBarStyle;
82 progressBar_.maxValue = 100.0; 81 progressBar_.maxValue = 100.0;
83 progressBar_.minValue = 0.0; 82 progressBar_.minValue = 0.0;
84 progressBar_.doubleValue = 0.0; 83 progressBar_.doubleValue = 0.0;
85 } 84 }
86 85
87 // Positions and adds the rest of the UI elements to main window. Prevents 86 // Positions the main window and adds the rest of the UI elements to it.
88 // resizing the window so that the absolute position will look the same on all 87 // Prevents resizing the window so that the absolute position will look the same
89 // computers. Window is hidden until all positioning is finished. 88 // on all computers. Window is hidden until all positioning is finished.
90 - (id)initWithWindow:(NSWindow*)window { 89 - (id)initWithWindow:(NSWindow*)window {
91 if (self = [super initWithWindow:window]) { 90 if (self = [super initWithWindow:window]) {
92 [window setFrame:NSMakeRect(0, 0, 430, 220) display:YES]; 91 [window setFrame:NSMakeRect(0, 0, 430, 220) display:YES];
93 [window center]; 92 [window center];
94 [window setStyleMask:[window styleMask] & ~NSResizableWindowMask]; 93 [window setStyleMask:[window styleMask] & ~NSResizableWindowMask];
95 94
96 [self setUpButtons]; 95 [self setUpButtons];
97 [self setUpProgressBar]; 96 [self setUpProgressBar];
98 [self setUpTextfields]; 97 [self setUpTextfields];
99 98
100 [window.contentView addSubview:importButton_]; 99 [window.contentView addSubview:importButton_];
101 [window.contentView addSubview:defaultBrowserButton_]; 100 [window.contentView addSubview:defaultBrowserButton_];
102 [window.contentView addSubview:optInButton_]; 101 [window.contentView addSubview:optInButton_];
103 [window.contentView addSubview:launchButton_]; 102 [window.contentView addSubview:launchButton_];
104 [window.contentView addSubview:progressBar_]; 103 [window.contentView addSubview:progressBar_];
105 [window.contentView addSubview:statusDescription_]; 104 [window.contentView addSubview:statusDescription_];
106 [window.contentView addSubview:downloadProgressDescription_]; 105 [window.contentView addSubview:downloadProgressDescription_];
107 [NSApp activateIgnoringOtherApps:YES]; 106 [NSApp activateIgnoringOtherApps:YES];
108 [window makeKeyAndOrderFront:self]; 107 [window makeKeyAndOrderFront:self];
109 } 108 }
110 return self; 109 return self;
111 } 110 }
112 111
113 - (void)updateStatusDescription:(NSString*)text { 112 - (void)updateStatusDescription:(NSString*)text {
114 // First setStringValue statement is required to clear the original string. 113 // TODO: This method somehow causes ghosting of the previous string's contents
115 // Omitting the first line will cause occasional ghosting of the previous 114 // after a redraw. The below line of code is a temporary hack to clear the
116 // string. 115 // ghosting behavior, but it should be replaced with a legitimate bug fix.
117 // TODO: Find a real solution to the ghosting problem. 116 downloadProgressDescription_.stringValue = @"";
118 // downloadProgressDescription_.stringValue = @"";
119 downloadProgressDescription_.stringValue = text; 117 downloadProgressDescription_.stringValue = text;
120 } 118 }
121 119
122 - (void)updateDownloadProgress:(double)progressPercent { 120 - (void)updateDownloadProgress:(double)progressPercent {
123 if (progressPercent > 0.0) { 121 if (progressPercent > 0.0) {
124 progressBar_.doubleValue = progressPercent; 122 progressBar_.doubleValue = progressPercent;
125 } else { 123 } else {
124 // After the progress bar is made indeterminate, it will not need to track
125 // determinate progress any more. Therefore, there is nothing implemented to
126 // set indeterminate to NO.
126 progressBar_.doubleValue = 0.0; 127 progressBar_.doubleValue = 0.0;
127 progressBar_.indeterminate = YES; 128 progressBar_.indeterminate = YES;
128 [progressBar_ startAnimation:nil]; 129 [progressBar_ startAnimation:nil];
129 } 130 }
130 } 131 }
131 132
132 - (void)enableLaunchButton { 133 - (void)enableLaunchButton {
133 [launchButton_ setEnabled:YES]; 134 [launchButton_ setEnabled:YES];
134 } 135 }
135 136
136 - (void)launchButtonClicked { 137 - (void)launchButtonClicked {
137 // TODO: Launch the app and start ejecting disk. 138 // TODO: Launch the app and start ejecting disk.
138 [NSApp terminate:nil]; 139 [NSApp terminate:nil];
139 } 140 }
140 141
141 - (BOOL)isUserMetricsChecked { 142 - (BOOL)isUserMetricsChecked {
142 return optInButton_.state == NSOnState; 143 return optInButton_.state == NSOnState;
143 } 144 }
144 145
145 - (BOOL)isDefaultBrowserChecked { 146 - (BOOL)isDefaultBrowserChecked {
146 return defaultBrowserButton_.state == NSOnState; 147 return defaultBrowserButton_.state == NSOnState;
147 } 148 }
148 149
149 @end 150 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698