| 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/device_chooser_content_view_cocoa.h" | 5 #import "chrome/browser/ui/cocoa/device_chooser_content_view_cocoa.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 // ------------------------------------ | 395 // ------------------------------------ |
| 396 // | Chooser title | | 396 // | Chooser title | |
| 397 // | -------------------------------- | | 397 // | -------------------------------- | |
| 398 // | | option 0 | | | 398 // | | option 0 | | |
| 399 // | | option 1 | | | 399 // | | option 1 | | |
| 400 // | | option 2 | | | 400 // | | option 2 | | |
| 401 // | | | | | 401 // | | | | |
| 402 // | | | | | 402 // | | | | |
| 403 // | | | | | 403 // | | | | |
| 404 // | -------------------------------- | | 404 // | -------------------------------- | |
| 405 // | [ Connect ] [ Cancel ] | | 405 // | [ Cancel ] [ Connect ] | |
| 406 // |----------------------------------| | 406 // |----------------------------------| |
| 407 // | Get help | | 407 // | Get help | |
| 408 // ------------------------------------ | 408 // ------------------------------------ |
| 409 | 409 |
| 410 // Determine the dimensions of the chooser. | 410 // Determine the dimensions of the chooser. |
| 411 // Once the height and width are set, the buttons and permission menus can | 411 // Once the height and width are set, the buttons and permission menus can |
| 412 // be laid out correctly. | 412 // be laid out correctly. |
| 413 NSRect chooserFrame = NSMakeRect(0, 0, kChooserWidth, kChooserHeight); | 413 NSRect chooserFrame = NSMakeRect(0, 0, kChooserWidth, kChooserHeight); |
| 414 | 414 |
| 415 if ((self = [super initWithFrame:chooserFrame])) { | 415 if ((self = [super initWithFrame:chooserFrame])) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 427 IDS_BLUETOOTH_DEVICE_CHOOSER_TURN_ON_BLUETOOTH_LINK_TEXT)]; | 427 IDS_BLUETOOTH_DEVICE_CHOOSER_TURN_ON_BLUETOOTH_LINK_TEXT)]; |
| 428 CGFloat adapterOffHelpButtonWidth = NSWidth([adapterOffHelpButton_ frame]); | 428 CGFloat adapterOffHelpButtonWidth = NSWidth([adapterOffHelpButton_ frame]); |
| 429 CGFloat adapterOffHelpButtonHeight = | 429 CGFloat adapterOffHelpButtonHeight = |
| 430 NSHeight([adapterOffHelpButton_ frame]); | 430 NSHeight([adapterOffHelpButton_ frame]); |
| 431 | 431 |
| 432 // Adapter turned off message. | 432 // Adapter turned off message. |
| 433 adapterOffMessage_ = CreateLabel(l10n_util::GetNSStringF( | 433 adapterOffMessage_ = CreateLabel(l10n_util::GetNSStringF( |
| 434 IDS_BLUETOOTH_DEVICE_CHOOSER_TURN_ADAPTER_OFF, base::string16())); | 434 IDS_BLUETOOTH_DEVICE_CHOOSER_TURN_ADAPTER_OFF, base::string16())); |
| 435 CGFloat adapterOffMessageWidth = NSWidth([adapterOffMessage_ frame]); | 435 CGFloat adapterOffMessageWidth = NSWidth([adapterOffMessage_ frame]); |
| 436 | 436 |
| 437 // Cancel button. |
| 438 cancelButton_ = [self createCancelButton]; |
| 439 CGFloat cancelButtonWidth = NSWidth([cancelButton_ frame]); |
| 440 CGFloat cancelButtonHeight = NSHeight([cancelButton_ frame]); |
| 441 |
| 437 // Connect button. | 442 // Connect button. |
| 438 connectButton_ = [self createConnectButton]; | 443 connectButton_ = [self createConnectButton]; |
| 439 CGFloat connectButtonWidth = NSWidth([connectButton_ frame]); | 444 CGFloat connectButtonWidth = NSWidth([connectButton_ frame]); |
| 440 CGFloat connectButtonHeight = NSHeight([connectButton_ frame]); | |
| 441 | |
| 442 // Cancel button. | |
| 443 cancelButton_ = [self createCancelButton]; | |
| 444 CGFloat cancelButtonWidth = NSWidth([cancelButton_ frame]); | |
| 445 | 445 |
| 446 // Separator. | 446 // Separator. |
| 447 separator_ = [self createSeparator]; | 447 separator_ = [self createSeparator]; |
| 448 | 448 |
| 449 // Help button. | 449 // Help button. |
| 450 CGFloat helpButtonWidth = 0.0f; | 450 CGFloat helpButtonWidth = 0.0f; |
| 451 CGFloat helpButtonHeight = 0.0f; | 451 CGFloat helpButtonHeight = 0.0f; |
| 452 if (chooserController_->ShouldShowFootnoteView()) { | 452 if (chooserController_->ShouldShowFootnoteView()) { |
| 453 helpButton_ = | 453 helpButton_ = |
| 454 [self createHyperlinkButtonWithText: | 454 [self createHyperlinkButtonWithText: |
| (...skipping 18 matching lines...) Expand all Loading... |
| 473 rescanButton_ = | 473 rescanButton_ = |
| 474 [self createHyperlinkButtonWithText: | 474 [self createHyperlinkButtonWithText: |
| 475 l10n_util::GetNSString(IDS_BLUETOOTH_DEVICE_CHOOSER_RE_SCAN)]; | 475 l10n_util::GetNSString(IDS_BLUETOOTH_DEVICE_CHOOSER_RE_SCAN)]; |
| 476 | 476 |
| 477 // ScollView embedding with TableView. | 477 // ScollView embedding with TableView. |
| 478 CGFloat scrollViewWidth = kChooserWidth - 2 * kMarginX; | 478 CGFloat scrollViewWidth = kChooserWidth - 2 * kMarginX; |
| 479 CGFloat scrollViewHeight = | 479 CGFloat scrollViewHeight = |
| 480 kChooserHeight - 2 * kMarginY - | 480 kChooserHeight - 2 * kMarginY - |
| 481 (chooserController_->ShouldShowFootnoteView() ? 4 * kVerticalPadding | 481 (chooserController_->ShouldShowFootnoteView() ? 4 * kVerticalPadding |
| 482 : 2 * kVerticalPadding) - | 482 : 2 * kVerticalPadding) - |
| 483 titleHeight - connectButtonHeight - helpButtonHeight; | 483 titleHeight - cancelButtonHeight - helpButtonHeight; |
| 484 CGFloat scrollViewOriginX = kMarginX; | 484 CGFloat scrollViewOriginX = kMarginX; |
| 485 CGFloat scrollViewOriginY = | 485 CGFloat scrollViewOriginY = |
| 486 kMarginY + helpButtonHeight + | 486 kMarginY + helpButtonHeight + |
| 487 (chooserController_->ShouldShowFootnoteView() ? 3 * kVerticalPadding | 487 (chooserController_->ShouldShowFootnoteView() ? 3 * kVerticalPadding |
| 488 : kVerticalPadding) + | 488 : kVerticalPadding) + |
| 489 connectButtonHeight; | 489 cancelButtonHeight; |
| 490 NSRect scrollFrame = NSMakeRect(scrollViewOriginX, scrollViewOriginY, | 490 NSRect scrollFrame = NSMakeRect(scrollViewOriginX, scrollViewOriginY, |
| 491 scrollViewWidth, scrollViewHeight); | 491 scrollViewWidth, scrollViewHeight); |
| 492 scrollView_.reset([[NSScrollView alloc] initWithFrame:scrollFrame]); | 492 scrollView_.reset([[NSScrollView alloc] initWithFrame:scrollFrame]); |
| 493 [scrollView_ setBorderType:NSBezelBorder]; | 493 [scrollView_ setBorderType:NSBezelBorder]; |
| 494 [scrollView_ setHasVerticalScroller:YES]; | 494 [scrollView_ setHasVerticalScroller:YES]; |
| 495 [scrollView_ setHasHorizontalScroller:YES]; | 495 [scrollView_ setHasHorizontalScroller:YES]; |
| 496 [scrollView_ setAutohidesScrollers:YES]; | 496 [scrollView_ setAutohidesScrollers:YES]; |
| 497 [scrollView_ setDrawsBackground:NO]; | 497 [scrollView_ setDrawsBackground:NO]; |
| 498 | 498 |
| 499 // TableView. | 499 // TableView. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 adapterOffMessageOriginY)]; | 551 adapterOffMessageOriginY)]; |
| 552 [adapterOffMessage_ setHidden:YES]; | 552 [adapterOffMessage_ setHidden:YES]; |
| 553 [self addSubview:adapterOffMessage_]; | 553 [self addSubview:adapterOffMessage_]; |
| 554 | 554 |
| 555 // ScollView and Spinner. Only one of them is shown. | 555 // ScollView and Spinner. Only one of them is shown. |
| 556 [scrollView_ setDocumentView:tableView_]; | 556 [scrollView_ setDocumentView:tableView_]; |
| 557 [self addSubview:scrollView_]; | 557 [self addSubview:scrollView_]; |
| 558 [spinner_ setHidden:YES]; | 558 [spinner_ setHidden:YES]; |
| 559 [self addSubview:spinner_]; | 559 [self addSubview:spinner_]; |
| 560 | 560 |
| 561 // Connect button. | 561 // Cancel button. |
| 562 CGFloat connectButtonOriginX = kChooserWidth - kMarginX - | 562 CGFloat cancelButtonOriginX = kChooserWidth - kMarginX - |
| 563 kHorizontalPadding - connectButtonWidth - | 563 kHorizontalPadding - cancelButtonWidth - |
| 564 cancelButtonWidth; | 564 connectButtonWidth; |
| 565 CGFloat connectButtonOriginY = | 565 CGFloat cancelButtonOriginY = |
| 566 kMarginY + helpButtonHeight + | 566 kMarginY + helpButtonHeight + |
| 567 (chooserController_->ShouldShowFootnoteView() ? 2 * kVerticalPadding | 567 (chooserController_->ShouldShowFootnoteView() ? 2 * kVerticalPadding |
| 568 : 0.0f); | 568 : 0.0f); |
| 569 [cancelButton_ |
| 570 setFrameOrigin:NSMakePoint(cancelButtonOriginX, cancelButtonOriginY)]; |
| 571 [self addSubview:cancelButton_]; |
| 572 |
| 573 // Connect button. |
| 574 CGFloat connectButtonOriginX = |
| 575 kChooserWidth - kMarginX - connectButtonWidth; |
| 576 CGFloat connectButtonOriginY = cancelButtonOriginY; |
| 569 [connectButton_ | 577 [connectButton_ |
| 570 setFrameOrigin:NSMakePoint(connectButtonOriginX, connectButtonOriginY)]; | 578 setFrameOrigin:NSMakePoint(connectButtonOriginX, connectButtonOriginY)]; |
| 571 [connectButton_ setEnabled:NO]; | 579 [connectButton_ setEnabled:NO]; |
| 572 [self addSubview:connectButton_]; | 580 [self addSubview:connectButton_]; |
| 573 | 581 |
| 574 // Cancel button. | |
| 575 CGFloat cancelButtonOriginX = kChooserWidth - kMarginX - cancelButtonWidth; | |
| 576 CGFloat cancelButtonOriginY = connectButtonOriginY; | |
| 577 [cancelButton_ | |
| 578 setFrameOrigin:NSMakePoint(cancelButtonOriginX, cancelButtonOriginY)]; | |
| 579 [self addSubview:cancelButton_]; | |
| 580 | |
| 581 if (chooserController_->ShouldShowFootnoteView()) { | 582 if (chooserController_->ShouldShowFootnoteView()) { |
| 582 // Separator. | 583 // Separator. |
| 583 CGFloat separatorOriginX = 0.0f; | 584 CGFloat separatorOriginX = 0.0f; |
| 584 separatorOriginY_ = kMarginY + helpButtonHeight + kVerticalPadding; | 585 separatorOriginY_ = kMarginY + helpButtonHeight + kVerticalPadding; |
| 585 [separator_ | 586 [separator_ |
| 586 setFrameOrigin:NSMakePoint(separatorOriginX, separatorOriginY_)]; | 587 setFrameOrigin:NSMakePoint(separatorOriginX, separatorOriginY_)]; |
| 587 [self addSubview:separator_]; | 588 [self addSubview:separator_]; |
| 588 | 589 |
| 589 // Help button. | 590 // Help button. |
| 590 CGFloat helpButtonOriginX = kMarginX; | 591 CGFloat helpButtonOriginX = kMarginX; |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 902 | 903 |
| 903 - (void)drawRect:(NSRect)rect { | 904 - (void)drawRect:(NSRect)rect { |
| 904 [[NSColor colorWithCalibratedWhite:245.0f / 255.0f alpha:1.0f] setFill]; | 905 [[NSColor colorWithCalibratedWhite:245.0f / 255.0f alpha:1.0f] setFill]; |
| 905 NSRect footnoteFrame = | 906 NSRect footnoteFrame = |
| 906 NSMakeRect(0.0f, 0.0f, kChooserWidth, separatorOriginY_); | 907 NSMakeRect(0.0f, 0.0f, kChooserWidth, separatorOriginY_); |
| 907 NSRectFill(footnoteFrame); | 908 NSRectFill(footnoteFrame); |
| 908 [super drawRect:footnoteFrame]; | 909 [super drawRect:footnoteFrame]; |
| 909 } | 910 } |
| 910 | 911 |
| 911 @end | 912 @end |
| OLD | NEW |