Chromium Code Reviews| 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 "chrome/browser/ui/cocoa/chooser_content_view_cocoa.h" | 5 #import "chrome/browser/ui/cocoa/chooser_content_view_cocoa.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 39 // Separator alpha value. | 39 // Separator alpha value. |
| 40 const CGFloat kSeparatorAlphaValue = 0.6f; | 40 const CGFloat kSeparatorAlphaValue = 0.6f; |
| 41 | 41 |
| 42 // Separator height. | 42 // Separator height. |
| 43 const CGFloat kSeparatorHeight = 1.0f; | 43 const CGFloat kSeparatorHeight = 1.0f; |
| 44 | 44 |
| 45 } // namespace | 45 } // namespace |
| 46 | 46 |
| 47 class ChooserContentViewController : public ChooserController::View { | 47 class ChooserContentViewController : public ChooserController::View { |
| 48 public: | 48 public: |
| 49 ChooserContentViewController(ChooserController* chooser_controller, | 49 ChooserContentViewController(ChooserContentViewCocoa* chooser_content_view, |
| 50 ChooserController* chooser_controller, | |
| 50 NSTableView* table_view, | 51 NSTableView* table_view, |
| 51 SpinnerView* spinner, | 52 SpinnerView* spinner, |
| 52 NSTextField* status, | 53 NSTextField* status, |
| 53 NSButton* rescan_button); | 54 NSButton* rescan_button); |
| 54 ~ChooserContentViewController() override; | 55 ~ChooserContentViewController() override; |
| 55 | 56 |
| 56 // ChooserController::View: | 57 // ChooserController::View: |
| 57 void OnOptionsInitialized() override; | 58 void OnOptionsInitialized() override; |
| 58 void OnOptionAdded(size_t index) override; | 59 void OnOptionAdded(size_t index) override; |
| 59 void OnOptionRemoved(size_t index) override; | 60 void OnOptionRemoved(size_t index) override; |
| 60 void OnAdapterEnabledChanged(bool enabled) override; | 61 void OnAdapterEnabledChanged(bool enabled) override; |
| 61 void OnRefreshStateChanged(bool refreshing) override; | 62 void OnRefreshStateChanged(bool refreshing) override; |
| 62 | 63 |
| 63 void UpdateTableView(); | 64 void UpdateTableView(); |
| 64 | 65 |
| 65 private: | 66 private: |
| 67 ChooserContentViewCocoa* chooser_content_view_; | |
| 66 ChooserController* chooser_controller_; | 68 ChooserController* chooser_controller_; |
| 67 NSTableView* table_view_; | 69 NSTableView* table_view_; |
| 68 SpinnerView* spinner_; | 70 SpinnerView* spinner_; |
| 69 NSTextField* status_; | 71 NSTextField* status_; |
| 70 NSButton* rescan_button_; | 72 NSButton* rescan_button_; |
| 71 | 73 |
| 72 DISALLOW_COPY_AND_ASSIGN(ChooserContentViewController); | 74 DISALLOW_COPY_AND_ASSIGN(ChooserContentViewController); |
| 73 }; | 75 }; |
| 74 | 76 |
| 75 ChooserContentViewController::ChooserContentViewController( | 77 ChooserContentViewController::ChooserContentViewController( |
| 78 ChooserContentViewCocoa* chooser_content_view, | |
| 76 ChooserController* chooser_controller, | 79 ChooserController* chooser_controller, |
| 77 NSTableView* table_view, | 80 NSTableView* table_view, |
| 78 SpinnerView* spinner, | 81 SpinnerView* spinner, |
| 79 NSTextField* status, | 82 NSTextField* status, |
| 80 NSButton* rescan_button) | 83 NSButton* rescan_button) |
| 81 : chooser_controller_(chooser_controller), | 84 : chooser_content_view_(chooser_content_view), |
| 85 chooser_controller_(chooser_controller), | |
| 82 table_view_(table_view), | 86 table_view_(table_view), |
| 83 spinner_(spinner), | 87 spinner_(spinner), |
| 84 status_(status), | 88 status_(status), |
| 85 rescan_button_(rescan_button) { | 89 rescan_button_(rescan_button) { |
| 86 DCHECK(chooser_controller_); | 90 DCHECK(chooser_controller_); |
| 87 DCHECK(table_view_); | 91 DCHECK(table_view_); |
| 88 DCHECK(spinner_); | 92 DCHECK(spinner_); |
| 89 DCHECK(status_); | 93 DCHECK(status_); |
| 90 DCHECK(rescan_button_); | 94 DCHECK(rescan_button_); |
| 91 chooser_controller_->set_view(this); | 95 chooser_controller_->set_view(this); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 // of a previously selected row. | 133 // of a previously selected row. |
| 130 [table_view_ deselectAll:nil]; | 134 [table_view_ deselectAll:nil]; |
| 131 UpdateTableView(); | 135 UpdateTableView(); |
| 132 [table_view_ setHidden:NO]; | 136 [table_view_ setHidden:NO]; |
| 133 | 137 |
| 134 [spinner_ setHidden:YES]; | 138 [spinner_ setHidden:YES]; |
| 135 | 139 |
| 136 [status_ setHidden:YES]; | 140 [status_ setHidden:YES]; |
| 137 // When adapter is enabled, show |rescan_button_|; otherwise hide it. | 141 // When adapter is enabled, show |rescan_button_|; otherwise hide it. |
| 138 [rescan_button_ setHidden:enabled ? NO : YES]; | 142 [rescan_button_ setHidden:enabled ? NO : YES]; |
| 143 | |
| 144 [chooser_content_view_ updateView]; | |
| 139 } | 145 } |
| 140 | 146 |
| 141 void ChooserContentViewController::OnRefreshStateChanged(bool refreshing) { | 147 void ChooserContentViewController::OnRefreshStateChanged(bool refreshing) { |
| 142 if (refreshing) { | 148 if (refreshing) { |
| 143 // No row is selected since the chooser is refreshing. | 149 // No row is selected since the chooser is refreshing. |
| 144 // This will also disable the OK button if it was enabled because | 150 // This will also disable the OK button if it was enabled because |
| 145 // of a previously selected row. | 151 // of a previously selected row. |
| 146 [table_view_ deselectAll:nil]; | 152 [table_view_ deselectAll:nil]; |
| 147 UpdateTableView(); | 153 UpdateTableView(); |
| 148 } | 154 } |
| 149 | 155 |
| 150 // When refreshing and no option available yet, hide |table_view_| and show | 156 // When refreshing and no option available yet, hide |table_view_| and show |
| 151 // |spinner_|. Otherwise show |table_view_| and hide |spinner_|. | 157 // |spinner_|. Otherwise show |table_view_| and hide |spinner_|. |
| 152 bool table_view_hidden = | 158 bool table_view_hidden = |
| 153 refreshing && (chooser_controller_->NumOptions() == 0); | 159 refreshing && (chooser_controller_->NumOptions() == 0); |
| 154 [table_view_ setHidden:table_view_hidden ? YES : NO]; | 160 [table_view_ setHidden:table_view_hidden ? YES : NO]; |
| 155 [spinner_ setHidden:table_view_hidden ? NO : YES]; | 161 [spinner_ setHidden:table_view_hidden ? NO : YES]; |
| 156 | 162 |
| 157 // When refreshing, show |status_| and hide |rescan_button_|. | 163 // When refreshing, show |status_| and hide |rescan_button_|. |
| 158 // When complete, show |rescan_button_| and hide |status_|. | 164 // When complete, show |rescan_button_| and hide |status_|. |
| 159 [status_ setHidden:refreshing ? NO : YES]; | 165 [status_ setHidden:refreshing ? NO : YES]; |
| 160 [rescan_button_ setHidden:refreshing ? YES : NO]; | 166 [rescan_button_ setHidden:refreshing ? YES : NO]; |
| 167 | |
| 168 [chooser_content_view_ updateView]; | |
| 161 } | 169 } |
| 162 | 170 |
| 163 void ChooserContentViewController::UpdateTableView() { | 171 void ChooserContentViewController::UpdateTableView() { |
| 164 [table_view_ setEnabled:chooser_controller_->NumOptions() > 0]; | 172 [table_view_ setEnabled:chooser_controller_->NumOptions() > 0]; |
| 165 [table_view_ reloadData]; | 173 [table_view_ reloadData]; |
| 166 } | 174 } |
| 167 | 175 |
| 168 @implementation ChooserContentViewCocoa | 176 @implementation ChooserContentViewCocoa |
| 169 | 177 |
| 170 - (instancetype)initWithChooserTitle:(NSString*)chooserTitle | 178 - (instancetype)initWithChooserTitle:(NSString*)chooserTitle |
|
Robert Sesek
2016/08/08 18:53:03
For follow-up CL, I'd maybe restructure init to be
juncai
2016/08/08 19:17:39
Added TODO.
| |
| 171 chooserController: | 179 chooserController: |
| 172 (std::unique_ptr<ChooserController>)chooserController { | 180 (std::unique_ptr<ChooserController>)chooserController { |
| 173 // ------------------------------------ | 181 // ------------------------------------ |
| 174 // | Chooser title | | 182 // | Chooser title | |
| 175 // | -------------------------------- | | 183 // | -------------------------------- | |
| 176 // | | option 0 | | | 184 // | | option 0 | | |
| 177 // | | option 1 | | | 185 // | | option 1 | | |
| 178 // | | option 2 | | | 186 // | | option 2 | | |
| 179 // | | | | | 187 // | | | | |
| 180 // | | | | | 188 // | | | | |
| 181 // | | | | | 189 // | | | | |
| 182 // | -------------------------------- | | 190 // | -------------------------------- | |
| 183 // | [ Connect ] [ Cancel ] | | 191 // | [ Connect ] [ Cancel ] | |
| 184 // |----------------------------------| | 192 // |----------------------------------| |
| 185 // | Not seeing your device? Get help | | 193 // | Not seeing your device? Get help | |
| 186 // ------------------------------------ | 194 // ------------------------------------ |
| 187 | 195 |
| 188 // Determine the dimensions of the chooser. | 196 // Determine the dimensions of the chooser. |
| 189 // Once the height and width are set, the buttons and permission menus can | 197 // Once the height and width are set, the buttons and permission menus can |
| 190 // be laid out correctly. | 198 // be laid out correctly. |
| 191 NSRect chooserFrame = NSMakeRect(0, 0, kChooserWidth, kChooserHeight); | 199 NSRect chooserFrame = NSMakeRect(0, 0, kChooserWidth, kChooserHeight); |
| 192 | 200 |
| 193 if ((self = [super initWithFrame:chooserFrame])) { | 201 if ((self = [super initWithFrame:chooserFrame])) { |
| 194 chooserController_ = std::move(chooserController); | 202 chooserController_ = std::move(chooserController); |
| 195 | 203 |
| 196 // Create the views. | 204 // Create the views. |
| 197 // Title. | 205 // Title. |
| 198 titleView_ = [self createChooserTitle:chooserTitle]; | 206 titleView_ = [self createChooserTitle:chooserTitle]; |
| 199 CGFloat titleHeight = NSHeight([titleView_ frame]); | 207 titleHeight_ = NSHeight([titleView_ frame]); |
| 200 | 208 |
| 201 // Status. | 209 // Status. |
| 202 status_ = [self createTextField:l10n_util::GetNSString( | 210 status_ = [self createTextField:l10n_util::GetNSString( |
| 203 IDS_BLUETOOTH_DEVICE_CHOOSER_SCANNING)]; | 211 IDS_BLUETOOTH_DEVICE_CHOOSER_SCANNING)]; |
| 212 CGFloat statusWidth = kChooserWidth / 2 - kMarginX; | |
| 213 // The height is arbitrary as it will be adjusted later. | |
| 214 [status_ setFrameSize:NSMakeSize(statusWidth, 0.0f)]; | |
| 215 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:status_]; | |
| 216 statusHeight_ = NSHeight([status_ frame]); | |
| 204 | 217 |
| 205 // Re-scan button. | 218 // Re-scan button. |
| 206 rescanButton_ = | 219 rescanButton_ = |
| 207 [self createHyperlinkButtonWithText: | 220 [self createHyperlinkButtonWithText: |
| 208 l10n_util::GetNSString(IDS_BLUETOOTH_DEVICE_CHOOSER_RE_SCAN)]; | 221 l10n_util::GetNSString(IDS_BLUETOOTH_DEVICE_CHOOSER_RE_SCAN)]; |
| 222 rescanButtonHeight_ = NSHeight([rescanButton_ frame]); | |
| 209 | 223 |
| 210 // Connect button. | 224 // Connect button. |
| 211 connectButton_ = [self createConnectButton]; | 225 connectButton_ = [self createConnectButton]; |
| 212 CGFloat connectButtonWidth = NSWidth([connectButton_ frame]); | 226 connectButtonWidth_ = NSWidth([connectButton_ frame]); |
| 213 CGFloat connectButtonHeight = NSHeight([connectButton_ frame]); | 227 connectButtonHeight_ = NSHeight([connectButton_ frame]); |
| 214 | 228 |
| 215 // Cancel button. | 229 // Cancel button. |
| 216 cancelButton_ = [self createCancelButton]; | 230 cancelButton_ = [self createCancelButton]; |
| 217 CGFloat cancelButtonWidth = NSWidth([cancelButton_ frame]); | 231 cancelButtonWidth_ = NSWidth([cancelButton_ frame]); |
| 232 cancelButtonHeight_ = NSHeight([cancelButton_ frame]); | |
| 233 | |
| 234 CGFloat buttonRowHeight = | |
| 235 std::max(connectButtonHeight_, cancelButtonHeight_); | |
| 218 | 236 |
| 219 // Separator. | 237 // Separator. |
| 220 separator_ = [self createSeparator]; | 238 separator_ = [self createSeparator]; |
| 221 | 239 |
| 222 // Message. | 240 // Message. |
| 223 message_ = [self createTextField:l10n_util::GetNSStringF( | 241 message_ = [self createTextField:l10n_util::GetNSStringF( |
| 224 IDS_DEVICE_CHOOSER_FOOTNOTE_TEXT, | 242 IDS_DEVICE_CHOOSER_FOOTNOTE_TEXT, |
| 225 base::string16())]; | 243 base::string16())]; |
| 226 CGFloat messageWidth = NSWidth([message_ frame]); | 244 CGFloat messageWidth = NSWidth([message_ frame]); |
| 227 CGFloat messageHeight = NSHeight([message_ frame]); | 245 messageHeight_ = NSHeight([message_ frame]); |
| 228 | 246 |
| 229 // Help button. | 247 // Help button. |
| 230 helpButton_ = [self | 248 helpButton_ = [self |
| 231 createHyperlinkButtonWithText: | 249 createHyperlinkButtonWithText: |
| 232 l10n_util::GetNSString(IDS_DEVICE_CHOOSER_GET_HELP_LINK_TEXT)]; | 250 l10n_util::GetNSString(IDS_DEVICE_CHOOSER_GET_HELP_LINK_TEXT)]; |
| 233 | 251 |
| 234 // ScollView embedding with TableView. | 252 // ScollView embedding with TableView. |
| 235 CGFloat scrollViewWidth = kChooserWidth - 2 * kMarginX; | 253 noStatusOrRescanButtonShown_.scroll_view_frame = |
| 236 CGFloat scrollViewHeight = kChooserHeight - 2 * kMarginY - | 254 [self calculateScrollViewFrame:buttonRowHeight]; |
| 237 4 * kVerticalPadding - titleHeight - | 255 scrollView_.reset([[NSScrollView alloc] |
| 238 connectButtonHeight - messageHeight; | 256 initWithFrame:noStatusOrRescanButtonShown_.scroll_view_frame]); |
| 239 CGFloat scrollViewOriginX = kMarginX; | |
| 240 CGFloat scrollViewOriginY = | |
| 241 kMarginY + messageHeight + 3 * kVerticalPadding + connectButtonHeight; | |
| 242 NSRect scrollFrame = NSMakeRect(scrollViewOriginX, scrollViewOriginY, | |
| 243 scrollViewWidth, scrollViewHeight); | |
| 244 scrollView_.reset([[NSScrollView alloc] initWithFrame:scrollFrame]); | |
| 245 [scrollView_ setBorderType:NSBezelBorder]; | 257 [scrollView_ setBorderType:NSBezelBorder]; |
| 246 [scrollView_ setHasVerticalScroller:YES]; | 258 [scrollView_ setHasVerticalScroller:YES]; |
| 247 [scrollView_ setHasHorizontalScroller:YES]; | 259 [scrollView_ setHasHorizontalScroller:YES]; |
| 248 [scrollView_ setAutohidesScrollers:YES]; | 260 [scrollView_ setAutohidesScrollers:YES]; |
| 249 | 261 |
| 250 // TableView. | 262 // TableView. |
| 251 tableView_.reset([[NSTableView alloc] initWithFrame:NSZeroRect]); | 263 tableView_.reset([[NSTableView alloc] initWithFrame:NSZeroRect]); |
| 252 tableColumn_.reset([[NSTableColumn alloc] initWithIdentifier:@""]); | 264 tableColumn_.reset([[NSTableColumn alloc] initWithIdentifier:@""]); |
| 253 [tableColumn_ setWidth:(scrollViewWidth - kMarginX)]; | 265 [tableColumn_ |
| 266 setWidth:(noStatusOrRescanButtonShown_.scroll_view_frame.size.width - | |
| 267 kMarginX)]; | |
| 254 [tableView_ addTableColumn:tableColumn_]; | 268 [tableView_ addTableColumn:tableColumn_]; |
| 255 // Make the column title invisible. | 269 // Make the column title invisible. |
| 256 [tableView_ setHeaderView:nil]; | 270 [tableView_ setHeaderView:nil]; |
| 257 [tableView_ setFocusRingType:NSFocusRingTypeNone]; | 271 [tableView_ setFocusRingType:NSFocusRingTypeNone]; |
| 258 | 272 |
| 259 // Spinner. | 273 // Spinner. |
| 260 // Set the spinner in the center of the scroll view. | 274 // Set the spinner in the center of the scroll view. |
| 275 // When |status_| is shown, it may affect the frame origin and size of the | |
| 276 // |scrollView_|, and since the |spinner_| is shown with the |status_|, | |
| 277 // its frame origin needs to be calculated according to the frame origin | |
| 278 // of |scrollView_| with |status_| shown. | |
| 279 NSRect scrollViewFrameWithStatusText = [self | |
| 280 calculateScrollViewFrame:std::max(statusHeight_, buttonRowHeight)]; | |
| 261 CGFloat spinnerOriginX = | 281 CGFloat spinnerOriginX = |
| 262 scrollViewOriginX + (scrollViewWidth - kSpinnerSize) / 2; | 282 scrollViewFrameWithStatusText.origin.x + |
| 283 (scrollViewFrameWithStatusText.size.width - kSpinnerSize) / 2; | |
| 263 CGFloat spinnerOriginY = | 284 CGFloat spinnerOriginY = |
| 264 scrollViewOriginY + (scrollViewHeight - kSpinnerSize) / 2; | 285 scrollViewFrameWithStatusText.origin.y + |
| 286 (scrollViewFrameWithStatusText.size.height - kSpinnerSize) / 2; | |
| 265 spinner_.reset([[SpinnerView alloc] | 287 spinner_.reset([[SpinnerView alloc] |
| 266 initWithFrame:NSMakeRect(spinnerOriginX, spinnerOriginY, kSpinnerSize, | 288 initWithFrame:NSMakeRect(spinnerOriginX, spinnerOriginY, kSpinnerSize, |
| 267 kSpinnerSize)]); | 289 kSpinnerSize)]); |
| 268 | 290 |
| 269 // Lay out the views. | 291 // Lay out the views. |
| 270 // Title. | 292 // Title. |
| 271 CGFloat titleOriginX = kMarginX; | 293 CGFloat titleOriginX = kMarginX; |
| 272 CGFloat titleOriginY = kChooserHeight - kMarginY - titleHeight; | 294 CGFloat titleOriginY = kChooserHeight - kMarginY - titleHeight_; |
| 273 [titleView_ setFrameOrigin:NSMakePoint(titleOriginX, titleOriginY)]; | 295 [titleView_ setFrameOrigin:NSMakePoint(titleOriginX, titleOriginY)]; |
| 274 [self addSubview:titleView_]; | 296 [self addSubview:titleView_]; |
| 275 | 297 |
| 276 // ScollView and Spinner. Only one of them is shown. | 298 // ScollView and Spinner. Only one of them is shown. |
| 277 [scrollView_ setDocumentView:tableView_]; | 299 [scrollView_ setDocumentView:tableView_]; |
| 278 [self addSubview:scrollView_]; | 300 [self addSubview:scrollView_]; |
| 279 [spinner_ setHidden:YES]; | 301 [spinner_ setHidden:YES]; |
| 280 [self addSubview:spinner_]; | 302 [self addSubview:spinner_]; |
| 281 | 303 |
| 282 // Status text field and Re-scan button. Only one of them is shown. | 304 // Status text field and Re-scan button. At most one of them is shown. |
| 283 CGFloat statusOriginX = kMarginX; | |
| 284 // Bottom-align with the text on the buttons. | |
| 285 CGFloat statusOriginY = kMarginY + messageHeight + 2 * kVerticalPadding + | |
| 286 (connectButtonHeight - [NSFont systemFontSize]) / 2; | |
| 287 [status_ setFrameOrigin:NSMakePoint(statusOriginX, statusOriginY)]; | |
| 288 [self addSubview:status_]; | 305 [self addSubview:status_]; |
| 289 [status_ setHidden:YES]; | 306 [status_ setHidden:YES]; |
| 290 [rescanButton_ setFrameOrigin:NSMakePoint(statusOriginX, statusOriginY)]; | 307 |
| 291 [rescanButton_ setTarget:self]; | 308 [rescanButton_ setTarget:self]; |
| 292 [rescanButton_ setAction:@selector(onRescan:)]; | 309 [rescanButton_ setAction:@selector(onRescan:)]; |
| 293 [self addSubview:rescanButton_]; | 310 [self addSubview:rescanButton_]; |
| 294 [rescanButton_ setHidden:YES]; | 311 [rescanButton_ setHidden:YES]; |
| 295 | 312 |
| 296 // Connect button. | 313 // Connect button. |
| 297 CGFloat connectButtonOriginX = kChooserWidth - kMarginX - | 314 noStatusOrRescanButtonShown_.connect_button_origin = |
| 298 kHorizontalPadding - connectButtonWidth - | 315 [self calculateConnectButtonOrigin:buttonRowHeight]; |
| 299 cancelButtonWidth; | |
| 300 CGFloat connectButtonOriginY = | |
| 301 kMarginY + messageHeight + 2 * kVerticalPadding; | |
| 302 [connectButton_ | 316 [connectButton_ |
| 303 setFrameOrigin:NSMakePoint(connectButtonOriginX, connectButtonOriginY)]; | 317 setFrameOrigin:noStatusOrRescanButtonShown_.connect_button_origin]; |
| 304 [connectButton_ setEnabled:NO]; | 318 [connectButton_ setEnabled:NO]; |
| 305 [self addSubview:connectButton_]; | 319 [self addSubview:connectButton_]; |
| 306 | 320 |
| 307 // Cancel button. | 321 // Cancel button. |
| 308 CGFloat cancelButtonOriginX = kChooserWidth - kMarginX - cancelButtonWidth; | 322 noStatusOrRescanButtonShown_.cancel_button_origin = |
| 309 CGFloat cancelButtonOriginY = connectButtonOriginY; | 323 [self calculateCancelButtonOrigin:buttonRowHeight]; |
| 310 [cancelButton_ | 324 [cancelButton_ |
| 311 setFrameOrigin:NSMakePoint(cancelButtonOriginX, cancelButtonOriginY)]; | 325 setFrameOrigin:noStatusOrRescanButtonShown_.cancel_button_origin]; |
| 312 [self addSubview:cancelButton_]; | 326 [self addSubview:cancelButton_]; |
| 313 | 327 |
| 314 // Separator. | 328 // Separator. |
| 315 CGFloat separatorOriginX = 0.0f; | 329 CGFloat separatorOriginX = 0.0f; |
| 316 CGFloat separatorOriginY = kMarginY + messageHeight + kVerticalPadding; | 330 CGFloat separatorOriginY = kMarginY + messageHeight_ + kVerticalPadding; |
| 317 [separator_ setFrameOrigin:NSMakePoint(separatorOriginX, separatorOriginY)]; | 331 [separator_ setFrameOrigin:NSMakePoint(separatorOriginX, separatorOriginY)]; |
| 318 [self addSubview:separator_]; | 332 [self addSubview:separator_]; |
| 319 | 333 |
| 320 // Message. | 334 // Message. |
| 321 CGFloat messageOriginX = kMarginX; | 335 CGFloat messageOriginX = kMarginX; |
| 322 CGFloat messageOriginY = kMarginY; | 336 CGFloat messageOriginY = kMarginY; |
| 323 [message_ setFrameOrigin:NSMakePoint(messageOriginX, messageOriginY)]; | 337 [message_ setFrameOrigin:NSMakePoint(messageOriginX, messageOriginY)]; |
| 324 [self addSubview:message_]; | 338 [self addSubview:message_]; |
| 325 | 339 |
| 326 // Help button. | 340 // Help button. |
| 327 CGFloat helpButtonOriginX = | 341 CGFloat helpButtonOriginX = |
| 328 kMarginX + messageWidth - kHorizontalPadding / 2; | 342 kMarginX + messageWidth - kHorizontalPadding / 2; |
| 329 CGFloat helpButtonOriginY = kMarginY; | 343 CGFloat helpButtonOriginY = kMarginY; |
| 330 [helpButton_ | 344 [helpButton_ |
| 331 setFrameOrigin:NSMakePoint(helpButtonOriginX, helpButtonOriginY)]; | 345 setFrameOrigin:NSMakePoint(helpButtonOriginX, helpButtonOriginY)]; |
| 332 [helpButton_ setTarget:self]; | 346 [helpButton_ setTarget:self]; |
| 333 [helpButton_ setAction:@selector(onHelpPressed:)]; | 347 [helpButton_ setAction:@selector(onHelpPressed:)]; |
| 334 [self addSubview:helpButton_]; | 348 [self addSubview:helpButton_]; |
| 335 | 349 |
| 350 // Calculate and cache the frame and origins values. | |
| 351 buttonRowHeight = std::max( | |
| 352 statusHeight_, std::max(connectButtonHeight_, cancelButtonHeight_)); | |
| 353 statusShown_ = {[self calculateScrollViewFrame:buttonRowHeight], | |
| 354 [self calculateConnectButtonOrigin:buttonRowHeight], | |
| 355 [self calculateCancelButtonOrigin:buttonRowHeight]}; | |
| 356 statusOrigin_ = [self calculateStatusOrigin:buttonRowHeight]; | |
| 357 | |
| 358 buttonRowHeight = | |
| 359 std::max(rescanButtonHeight_, | |
| 360 std::max(connectButtonHeight_, cancelButtonHeight_)); | |
| 361 rescanButtonShown_ = {[self calculateScrollViewFrame:buttonRowHeight], | |
| 362 [self calculateConnectButtonOrigin:buttonRowHeight], | |
| 363 [self calculateCancelButtonOrigin:buttonRowHeight]}; | |
| 364 rescanButtonOrigin_ = [self calculateRescanButtonOrigin:buttonRowHeight]; | |
| 365 | |
| 336 chooserContentViewController_.reset(new ChooserContentViewController( | 366 chooserContentViewController_.reset(new ChooserContentViewController( |
| 337 chooserController_.get(), tableView_.get(), spinner_.get(), | 367 self, chooserController_.get(), tableView_.get(), spinner_.get(), |
| 338 status_.get(), rescanButton_.get())); | 368 status_.get(), rescanButton_.get())); |
| 339 } | 369 } |
| 340 | 370 |
| 341 return self; | 371 return self; |
| 342 } | 372 } |
| 343 | 373 |
| 344 - (base::scoped_nsobject<NSTextField>)createChooserTitle:(NSString*)title { | 374 - (base::scoped_nsobject<NSTextField>)createChooserTitle:(NSString*)title { |
| 345 base::scoped_nsobject<NSTextField> titleView( | 375 base::scoped_nsobject<NSTextField> titleView( |
| 346 [[NSTextField alloc] initWithFrame:NSZeroRect]); | 376 [[NSTextField alloc] initWithFrame:NSZeroRect]); |
| 347 [titleView setDrawsBackground:NO]; | 377 [titleView setDrawsBackground:NO]; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 403 (NSString*)text { | 433 (NSString*)text { |
| 404 base::scoped_nsobject<NSButton> button( | 434 base::scoped_nsobject<NSButton> button( |
| 405 [[NSButton alloc] initWithFrame:NSZeroRect]); | 435 [[NSButton alloc] initWithFrame:NSZeroRect]); |
| 406 base::scoped_nsobject<HyperlinkButtonCell> cell( | 436 base::scoped_nsobject<HyperlinkButtonCell> cell( |
| 407 [[HyperlinkButtonCell alloc] initTextCell:text]); | 437 [[HyperlinkButtonCell alloc] initTextCell:text]); |
| 408 [button setCell:cell.get()]; | 438 [button setCell:cell.get()]; |
| 409 [button sizeToFit]; | 439 [button sizeToFit]; |
| 410 return button; | 440 return button; |
| 411 } | 441 } |
| 412 | 442 |
| 443 - (NSRect)calculateScrollViewFrame:(CGFloat)buttonRowHeight { | |
| 444 CGFloat originX = kMarginX; | |
| 445 CGFloat originY = | |
| 446 kMarginY + messageHeight_ + 3 * kVerticalPadding + buttonRowHeight; | |
| 447 CGFloat width = kChooserWidth - 2 * kMarginX; | |
| 448 CGFloat height = kChooserHeight - 2 * kMarginY - 4 * kVerticalPadding - | |
| 449 titleHeight_ - buttonRowHeight - messageHeight_; | |
| 450 return NSMakeRect(originX, originY, width, height); | |
| 451 } | |
| 452 | |
| 453 - (NSPoint)calculateStatusOrigin:(CGFloat)buttonRowHeight { | |
| 454 return NSMakePoint(kMarginX, kMarginY + messageHeight_ + | |
| 455 2 * kVerticalPadding + | |
| 456 (buttonRowHeight - statusHeight_) / 2); | |
| 457 } | |
| 458 | |
| 459 - (NSPoint)calculateRescanButtonOrigin:(CGFloat)buttonRowHeight { | |
| 460 return NSMakePoint(kMarginX, kMarginY + messageHeight_ + | |
| 461 2 * kVerticalPadding + | |
| 462 (buttonRowHeight - rescanButtonHeight_) / 2); | |
| 463 } | |
| 464 | |
| 465 - (NSPoint)calculateConnectButtonOrigin:(CGFloat)buttonRowHeight { | |
| 466 return NSMakePoint(kChooserWidth - kMarginX - kHorizontalPadding - | |
| 467 connectButtonWidth_ - cancelButtonWidth_, | |
| 468 kMarginY + messageHeight_ + 2 * kVerticalPadding + | |
| 469 (buttonRowHeight - connectButtonHeight_) / 2); | |
| 470 } | |
| 471 | |
| 472 - (NSPoint)calculateCancelButtonOrigin:(CGFloat)buttonRowHeight { | |
| 473 return NSMakePoint(kChooserWidth - kMarginX - cancelButtonWidth_, | |
| 474 kMarginY + messageHeight_ + 2 * kVerticalPadding + | |
| 475 (buttonRowHeight - cancelButtonHeight_) / 2); | |
| 476 } | |
| 477 | |
| 478 - (void)updateView { | |
| 479 FrameAndOrigin frameAndOrigin; | |
| 480 if (![status_ isHidden]) { | |
| 481 [status_ setFrameOrigin:statusOrigin_]; | |
| 482 frameAndOrigin = statusShown_; | |
| 483 } else if (![rescanButton_ isHidden]) { | |
| 484 [rescanButton_ setFrameOrigin:rescanButtonOrigin_]; | |
| 485 frameAndOrigin = rescanButtonShown_; | |
| 486 } else { | |
| 487 frameAndOrigin = noStatusOrRescanButtonShown_; | |
| 488 } | |
| 489 | |
| 490 [scrollView_ setFrame:frameAndOrigin.scroll_view_frame]; | |
| 491 [connectButton_ setFrameOrigin:frameAndOrigin.connect_button_origin]; | |
| 492 [cancelButton_ setFrameOrigin:frameAndOrigin.cancel_button_origin]; | |
| 493 } | |
| 494 | |
| 413 - (NSTableView*)tableView { | 495 - (NSTableView*)tableView { |
| 414 return tableView_.get(); | 496 return tableView_.get(); |
| 415 } | 497 } |
| 416 | 498 |
| 417 - (SpinnerView*)spinner { | 499 - (SpinnerView*)spinner { |
| 418 return spinner_.get(); | 500 return spinner_.get(); |
| 419 } | 501 } |
| 420 | 502 |
| 421 - (NSTextField*)status { | 503 - (NSTextField*)status { |
| 422 return status_.get(); | 504 return status_.get(); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 478 | 560 |
| 479 - (void)onRescan:(id)sender { | 561 - (void)onRescan:(id)sender { |
| 480 chooserController_->RefreshOptions(); | 562 chooserController_->RefreshOptions(); |
| 481 } | 563 } |
| 482 | 564 |
| 483 - (void)onHelpPressed:(id)sender { | 565 - (void)onHelpPressed:(id)sender { |
| 484 chooserController_->OpenHelpCenterUrl(); | 566 chooserController_->OpenHelpCenterUrl(); |
| 485 } | 567 } |
| 486 | 568 |
| 487 @end | 569 @end |
| OLD | NEW |