Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/translate/translate_bubble_controller.h" | 5 #import "chrome/browser/ui/cocoa/translate/translate_bubble_controller.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/mac/foundation_util.h" | 9 #include "base/mac/foundation_util.h" |
| 10 #include "base/mac/scoped_nsobject.h" | 10 #include "base/mac/scoped_nsobject.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/strings/sys_string_conversions.h" | 12 #include "base/strings/sys_string_conversions.h" |
| 13 #include "chrome/browser/ui/chrome_pages.h" | |
| 13 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 14 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 14 #import "chrome/browser/ui/cocoa/bubble_combobox.h" | 15 #import "chrome/browser/ui/cocoa/bubble_combobox.h" |
| 15 #import "chrome/browser/ui/cocoa/info_bubble_view.h" | 16 #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
| 16 #import "chrome/browser/ui/cocoa/info_bubble_window.h" | 17 #import "chrome/browser/ui/cocoa/info_bubble_window.h" |
| 17 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" | 18 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" |
| 18 #include "chrome/browser/ui/translate/language_combobox_model.h" | 19 #include "chrome/browser/ui/translate/language_combobox_model.h" |
| 19 #include "chrome/browser/ui/translate/translate_bubble_model_impl.h" | 20 #include "chrome/browser/ui/translate/translate_bubble_model.h" |
| 21 #include "chrome/browser/ui/translate/translate_bubble_view_state_transition.h" | |
| 22 #include "chrome/common/url_constants.h" | |
| 20 #include "chrome/grit/generated_resources.h" | 23 #include "chrome/grit/generated_resources.h" |
| 21 #include "components/translate/core/browser/translate_ui_delegate.h" | 24 #include "components/translate/core/browser/translate_ui_delegate.h" |
| 22 #include "content/public/browser/browser_context.h" | 25 #include "content/public/browser/browser_context.h" |
| 26 #include "content/public/common/referrer.h" | |
| 23 #include "grit/components_strings.h" | 27 #include "grit/components_strings.h" |
| 24 #include "ui/base/cocoa/cocoa_base_utils.h" | 28 #include "ui/base/cocoa/cocoa_base_utils.h" |
| 25 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" | 29 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" |
| 26 #import "ui/base/cocoa/window_size_constants.h" | 30 #import "ui/base/cocoa/window_size_constants.h" |
| 27 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
| 28 #include "ui/base/models/combobox_model.h" | 32 #include "ui/base/models/combobox_model.h" |
| 29 | 33 |
| 30 // TODO(hajimehoshi): This class is almost same as that of views. Refactor them. | 34 // TODO(hajimehoshi): This class is almost same as that of views. Refactor them. |
| 31 class TranslateDenialComboboxModel : public ui::ComboboxModel { | 35 class TranslateDenialComboboxModel : public ui::ComboboxModel { |
| 32 public: | 36 public: |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 - (NSButton*)addCheckbox:(NSString*)title | 97 - (NSButton*)addCheckbox:(NSString*)title |
| 94 toView:(NSView*)view; | 98 toView:(NSView*)view; |
| 95 - (NSPopUpButton*)addPopUpButton:(ui::ComboboxModel*)model | 99 - (NSPopUpButton*)addPopUpButton:(ui::ComboboxModel*)model |
| 96 action:(SEL)action | 100 action:(SEL)action |
| 97 toView:(NSView*)view; | 101 toView:(NSView*)view; |
| 98 - (void)handleNopeButtonPressed; | 102 - (void)handleNopeButtonPressed; |
| 99 - (void)handleDoneButtonPressed; | 103 - (void)handleDoneButtonPressed; |
| 100 - (void)handleCancelButtonPressed; | 104 - (void)handleCancelButtonPressed; |
| 101 - (void)handleShowOriginalButtonPressed; | 105 - (void)handleShowOriginalButtonPressed; |
| 102 - (void)handleAdvancedLinkButtonPressed; | 106 - (void)handleAdvancedLinkButtonPressed; |
| 107 - (void)handleLanguageSettingsLinkButtonPressed; | |
| 103 - (void)handleDenialPopUpButtonNopeSelected; | 108 - (void)handleDenialPopUpButtonNopeSelected; |
| 104 - (void)handleDenialPopUpButtonNeverTranslateLanguageSelected; | 109 - (void)handleDenialPopUpButtonNeverTranslateLanguageSelected; |
| 105 - (void)handleDenialPopUpButtonNeverTranslateSiteSelected; | 110 - (void)handleDenialPopUpButtonNeverTranslateSiteSelected; |
| 106 - (void)handleSourceLanguagePopUpButtonSelectedItemChanged:(id)sender; | 111 - (void)handleSourceLanguagePopUpButtonSelectedItemChanged:(id)sender; |
| 107 - (void)handleTargetLanguagePopUpButtonSelectedItemChanged:(id)sender; | 112 - (void)handleTargetLanguagePopUpButtonSelectedItemChanged:(id)sender; |
| 108 | 113 |
| 109 @end | 114 @end |
| 110 | 115 |
| 111 @implementation TranslateBubbleController | 116 @implementation TranslateBubbleController |
| 112 | 117 |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 433 // Buttons | 438 // Buttons |
| 434 advancedDoneButton_ = | 439 advancedDoneButton_ = |
| 435 [self addButton:l10n_util::GetNSStringWithFixup(IDS_DONE) | 440 [self addButton:l10n_util::GetNSStringWithFixup(IDS_DONE) |
| 436 action:@selector(handleDoneButtonPressed) | 441 action:@selector(handleDoneButtonPressed) |
| 437 toView:view]; | 442 toView:view]; |
| 438 advancedCancelButton_ = | 443 advancedCancelButton_ = |
| 439 [self addButton:l10n_util::GetNSStringWithFixup(IDS_CANCEL) | 444 [self addButton:l10n_util::GetNSStringWithFixup(IDS_CANCEL) |
| 440 action:@selector(handleCancelButtonPressed) | 445 action:@selector(handleCancelButtonPressed) |
| 441 toView:view]; | 446 toView:view]; |
| 442 | 447 |
| 448 NSString* message = l10n_util::GetNSStringWithFixup( | |
| 449 IDS_TRANSLATE_BUBBLE_LANGUAGE_SETTINGS); | |
| 450 action = @selector(handleLanguageSettingsLinkButtonPressed); | |
| 451 NSButton* advancedLanguageSettingsLinkButton = | |
|
groby-ooo-7-16
2016/05/18 23:08:16
Why is this a button? Should this be a hyperlink?
ftang
2016/05/18 23:57:42
I just reuse the pre-existing addLinkButtonWithTex
groby-ooo-7-16
2016/05/19 01:38:09
I was thinking of HyperLinkTextView - but addLinkB
| |
| 452 [self addLinkButtonWithText:message | |
| 453 action:action | |
| 454 toView:view]; | |
| 455 | |
| 443 // Layout | 456 // Layout |
| 444 CGFloat textLabelWidth = NSWidth([sourceLanguageLabel frame]); | 457 CGFloat textLabelWidth = NSWidth([sourceLanguageLabel frame]); |
| 445 if (textLabelWidth < NSWidth([targetLanguageLabel frame])) | 458 if (textLabelWidth < NSWidth([targetLanguageLabel frame])) |
| 446 textLabelWidth = NSWidth([targetLanguageLabel frame]); | 459 textLabelWidth = NSWidth([targetLanguageLabel frame]); |
| 447 | 460 |
| 448 CGFloat yPos = 0; | 461 CGFloat yPos = 0; |
| 449 | 462 |
| 450 [advancedDoneButton_ setFrameOrigin:NSMakePoint(0, yPos)]; | 463 [advancedDoneButton_ setFrameOrigin:NSMakePoint(0, yPos)]; |
| 451 [advancedCancelButton_ setFrameOrigin:NSMakePoint(0, yPos)]; | 464 [advancedCancelButton_ setFrameOrigin:NSMakePoint(0, yPos)]; |
| 452 | 465 |
| 453 yPos += NSHeight([advancedDoneButton_ frame]) + | 466 [advancedLanguageSettingsLinkButton setFrameOrigin:NSMakePoint(0, yPos)]; |
| 467 | |
| 468 // Vertical center the advancedLanguageSettingsLinkButton with the | |
| 469 // advancedDoneButton_. | |
| 470 yPos = (NSHeight([advancedDoneButton_ frame]) - | |
|
groby-ooo-7-16
2016/05/19 01:38:09
You don't want to center this with the button - yo
| |
| 471 NSHeight([advancedLanguageSettingsLinkButton frame])) / 2; | |
| 472 | |
| 473 [advancedLanguageSettingsLinkButton setFrameOrigin:NSMakePoint(0, yPos)]; | |
| 474 | |
| 475 yPos = NSHeight([advancedDoneButton_ frame]) + | |
| 454 kUnrelatedControlVerticalSpacing; | 476 kUnrelatedControlVerticalSpacing; |
| 455 | 477 |
| 456 if (alwaysTranslateCheckbox_) { | 478 if (alwaysTranslateCheckbox_) { |
| 457 [alwaysTranslateCheckbox_ setFrameOrigin:NSMakePoint(textLabelWidth, yPos)]; | 479 [alwaysTranslateCheckbox_ setFrameOrigin:NSMakePoint(textLabelWidth, yPos)]; |
| 458 | 480 |
| 459 yPos += NSHeight([alwaysTranslateCheckbox_ frame]) + | 481 yPos += NSHeight([alwaysTranslateCheckbox_ frame]) + |
| 460 kRelatedControlVerticalSpacing; | 482 kRelatedControlVerticalSpacing; |
| 461 } | 483 } |
| 462 | 484 |
| 463 CGFloat diffY = [[sourcePopUpButton cell] | 485 CGFloat diffY = [[sourcePopUpButton cell] |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 627 | 649 |
| 628 - (void)handleShowOriginalButtonPressed { | 650 - (void)handleShowOriginalButtonPressed { |
| 629 model_->RevertTranslation(); | 651 model_->RevertTranslation(); |
| 630 [self close]; | 652 [self close]; |
| 631 } | 653 } |
| 632 | 654 |
| 633 - (void)handleAdvancedLinkButtonPressed { | 655 - (void)handleAdvancedLinkButtonPressed { |
| 634 [self switchView:TranslateBubbleModel::VIEW_STATE_ADVANCED]; | 656 [self switchView:TranslateBubbleModel::VIEW_STATE_ADVANCED]; |
| 635 } | 657 } |
| 636 | 658 |
| 659 - (void)handleLanguageSettingsLinkButtonPressed { | |
| 660 GURL url = chrome::GetSettingsUrl(chrome::kLanguageOptionsSubPage); | |
| 661 webContents_->OpenURL( | |
| 662 content::OpenURLParams(url, content::Referrer(), NEW_FOREGROUND_TAB, | |
| 663 ui::PAGE_TRANSITION_LINK, false)); | |
| 664 translate::ReportUiAction(translate::SETTINGS_LINK_CLICKED); | |
| 665 [self close]; | |
| 666 } | |
| 667 | |
| 637 - (void)handleDenialPopUpButtonNopeSelected { | 668 - (void)handleDenialPopUpButtonNopeSelected { |
| 638 model_->DeclineTranslation(); | 669 model_->DeclineTranslation(); |
| 639 [self close]; | 670 [self close]; |
| 640 } | 671 } |
| 641 | 672 |
| 642 - (void)handleDenialPopUpButtonNeverTranslateLanguageSelected { | 673 - (void)handleDenialPopUpButtonNeverTranslateLanguageSelected { |
| 643 model_->DeclineTranslation(); | 674 model_->DeclineTranslation(); |
| 644 model_->SetNeverTranslateLanguage(true); | 675 model_->SetNeverTranslateLanguage(true); |
| 645 [self close]; | 676 [self close]; |
| 646 } | 677 } |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 657 [self updateAdvancedView]; | 688 [self updateAdvancedView]; |
| 658 } | 689 } |
| 659 | 690 |
| 660 - (void)handleTargetLanguagePopUpButtonSelectedItemChanged:(id)sender { | 691 - (void)handleTargetLanguagePopUpButtonSelectedItemChanged:(id)sender { |
| 661 NSPopUpButton* button = base::mac::ObjCCastStrict<NSPopUpButton>(sender); | 692 NSPopUpButton* button = base::mac::ObjCCastStrict<NSPopUpButton>(sender); |
| 662 model_->UpdateTargetLanguageIndex([button indexOfSelectedItem]); | 693 model_->UpdateTargetLanguageIndex([button indexOfSelectedItem]); |
| 663 [self updateAdvancedView]; | 694 [self updateAdvancedView]; |
| 664 } | 695 } |
| 665 | 696 |
| 666 @end | 697 @end |
| OLD | NEW |