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_impl.h" |
| 21 #include "chrome/common/url_constants.h" | |
| 20 #include "chrome/grit/generated_resources.h" | 22 #include "chrome/grit/generated_resources.h" |
| 21 #include "components/translate/core/browser/translate_ui_delegate.h" | 23 #include "components/translate/core/browser/translate_ui_delegate.h" |
| 22 #include "content/public/browser/browser_context.h" | 24 #include "content/public/browser/browser_context.h" |
| 25 #include "content/public/common/referrer.h" | |
| 23 #include "grit/components_strings.h" | 26 #include "grit/components_strings.h" |
| 24 #include "ui/base/cocoa/cocoa_base_utils.h" | 27 #include "ui/base/cocoa/cocoa_base_utils.h" |
| 25 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" | 28 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" |
| 26 #import "ui/base/cocoa/window_size_constants.h" | 29 #import "ui/base/cocoa/window_size_constants.h" |
| 27 #include "ui/base/l10n/l10n_util.h" | 30 #include "ui/base/l10n/l10n_util.h" |
| 28 #include "ui/base/models/combobox_model.h" | 31 #include "ui/base/models/combobox_model.h" |
| 29 | 32 |
| 30 // TODO(hajimehoshi): This class is almost same as that of views. Refactor them. | 33 // TODO(hajimehoshi): This class is almost same as that of views. Refactor them. |
| 31 class TranslateDenialComboboxModel : public ui::ComboboxModel { | 34 class TranslateDenialComboboxModel : public ui::ComboboxModel { |
| 32 public: | 35 public: |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 - (NSButton*)addCheckbox:(NSString*)title | 96 - (NSButton*)addCheckbox:(NSString*)title |
| 94 toView:(NSView*)view; | 97 toView:(NSView*)view; |
| 95 - (NSPopUpButton*)addPopUpButton:(ui::ComboboxModel*)model | 98 - (NSPopUpButton*)addPopUpButton:(ui::ComboboxModel*)model |
| 96 action:(SEL)action | 99 action:(SEL)action |
| 97 toView:(NSView*)view; | 100 toView:(NSView*)view; |
| 98 - (void)handleNopeButtonPressed; | 101 - (void)handleNopeButtonPressed; |
| 99 - (void)handleDoneButtonPressed; | 102 - (void)handleDoneButtonPressed; |
| 100 - (void)handleCancelButtonPressed; | 103 - (void)handleCancelButtonPressed; |
| 101 - (void)handleShowOriginalButtonPressed; | 104 - (void)handleShowOriginalButtonPressed; |
| 102 - (void)handleAdvancedLinkButtonPressed; | 105 - (void)handleAdvancedLinkButtonPressed; |
| 106 - (void)handleLanguageSettingsLinkButtonPressed; | |
| 103 - (void)handleDenialPopUpButtonNopeSelected; | 107 - (void)handleDenialPopUpButtonNopeSelected; |
| 104 - (void)handleDenialPopUpButtonNeverTranslateLanguageSelected; | 108 - (void)handleDenialPopUpButtonNeverTranslateLanguageSelected; |
| 105 - (void)handleDenialPopUpButtonNeverTranslateSiteSelected; | 109 - (void)handleDenialPopUpButtonNeverTranslateSiteSelected; |
| 106 - (void)handleSourceLanguagePopUpButtonSelectedItemChanged:(id)sender; | 110 - (void)handleSourceLanguagePopUpButtonSelectedItemChanged:(id)sender; |
| 107 - (void)handleTargetLanguagePopUpButtonSelectedItemChanged:(id)sender; | 111 - (void)handleTargetLanguagePopUpButtonSelectedItemChanged:(id)sender; |
| 108 | 112 |
| 109 @end | 113 @end |
| 110 | 114 |
| 111 @implementation TranslateBubbleController | 115 @implementation TranslateBubbleController |
| 112 | 116 |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 429 // Buttons | 433 // Buttons |
| 430 advancedDoneButton_ = | 434 advancedDoneButton_ = |
| 431 [self addButton:l10n_util::GetNSStringWithFixup(IDS_DONE) | 435 [self addButton:l10n_util::GetNSStringWithFixup(IDS_DONE) |
| 432 action:@selector(handleDoneButtonPressed) | 436 action:@selector(handleDoneButtonPressed) |
| 433 toView:view]; | 437 toView:view]; |
| 434 advancedCancelButton_ = | 438 advancedCancelButton_ = |
| 435 [self addButton:l10n_util::GetNSStringWithFixup(IDS_CANCEL) | 439 [self addButton:l10n_util::GetNSStringWithFixup(IDS_CANCEL) |
| 436 action:@selector(handleCancelButtonPressed) | 440 action:@selector(handleCancelButtonPressed) |
| 437 toView:view]; | 441 toView:view]; |
| 438 | 442 |
| 443 NSString* message = l10n_util::GetNSStringWithFixup( | |
| 444 IDS_TRANSLATE_BUBBLE_LANGUAGE_SETTINGS); | |
| 445 advancedLanguageSettingsLinkButton_ = | |
| 446 [self addLinkButtonWithText:message | |
|
groby-ooo-7-16
2016/05/12 01:23:40
I think advancedLanguageSettingsLinkButton_ can be
ftang
2016/05/12 04:45:21
Done.
| |
| 447 action:@selector(handleLanguageSettingsLinkButtonPres sed) | |
| 448 toView:view]; | |
| 449 | |
| 439 // Layout | 450 // Layout |
| 440 CGFloat textLabelWidth = NSWidth([sourceLanguageLabel frame]); | 451 CGFloat textLabelWidth = NSWidth([sourceLanguageLabel frame]); |
| 441 if (textLabelWidth < NSWidth([targetLanguageLabel frame])) | 452 if (textLabelWidth < NSWidth([targetLanguageLabel frame])) |
| 442 textLabelWidth = NSWidth([targetLanguageLabel frame]); | 453 textLabelWidth = NSWidth([targetLanguageLabel frame]); |
| 443 | 454 |
| 444 CGFloat yPos = 0; | 455 CGFloat yPos = 0; |
| 445 | 456 |
| 446 [advancedDoneButton_ setFrameOrigin:NSMakePoint(0, yPos)]; | 457 [advancedDoneButton_ setFrameOrigin:NSMakePoint(0, yPos)]; |
| 447 [advancedCancelButton_ setFrameOrigin:NSMakePoint(0, yPos)]; | 458 [advancedCancelButton_ setFrameOrigin:NSMakePoint(0, yPos)]; |
| 448 | 459 |
| 449 yPos += NSHeight([advancedDoneButton_ frame]) + | 460 [advancedLanguageSettingsLinkButton_ setFrameOrigin:NSMakePoint(0, yPos)]; |
| 461 | |
| 462 // The height of the buttons and link are different. Place the | |
| 463 // origin of the link up. | |
|
groby-ooo-7-16
2016/05/12 01:23:40
Up relative to what? Do you mean center it w/ the
ftang
2016/05/12 04:45:21
Done.
| |
| 464 yPos = (NSHeight([advancedDoneButton_ frame]) - | |
| 465 NSHeight([advancedLanguageSettingsLinkButton_ frame])) / 2; | |
| 466 | |
| 467 [advancedLanguageSettingsLinkButton_ setFrameOrigin:NSMakePoint(0, yPos)]; | |
| 468 | |
| 469 yPos = NSHeight([advancedDoneButton_ frame]) + | |
| 450 kUnrelatedControlVerticalSpacing; | 470 kUnrelatedControlVerticalSpacing; |
| 451 | 471 |
| 452 if (alwaysTranslateCheckbox_) { | 472 if (alwaysTranslateCheckbox_) { |
| 453 [alwaysTranslateCheckbox_ setFrameOrigin:NSMakePoint(textLabelWidth, yPos)]; | 473 [alwaysTranslateCheckbox_ setFrameOrigin:NSMakePoint(textLabelWidth, yPos)]; |
| 454 | 474 |
| 455 yPos += NSHeight([alwaysTranslateCheckbox_ frame]) + | 475 yPos += NSHeight([alwaysTranslateCheckbox_ frame]) + |
| 456 kRelatedControlVerticalSpacing; | 476 kRelatedControlVerticalSpacing; |
| 457 } | 477 } |
| 458 | 478 |
| 459 CGFloat diffY = [[sourcePopUpButton cell] | 479 CGFloat diffY = [[sourcePopUpButton cell] |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 623 | 643 |
| 624 - (void)handleShowOriginalButtonPressed { | 644 - (void)handleShowOriginalButtonPressed { |
| 625 model_->RevertTranslation(); | 645 model_->RevertTranslation(); |
| 626 [self close]; | 646 [self close]; |
| 627 } | 647 } |
| 628 | 648 |
| 629 - (void)handleAdvancedLinkButtonPressed { | 649 - (void)handleAdvancedLinkButtonPressed { |
| 630 [self switchView:TranslateBubbleModel::VIEW_STATE_ADVANCED]; | 650 [self switchView:TranslateBubbleModel::VIEW_STATE_ADVANCED]; |
| 631 } | 651 } |
| 632 | 652 |
| 653 - (void)handleLanguageSettingsLinkButtonPressed { | |
| 654 GURL url = chrome::GetSettingsUrl(chrome::kLanguageOptionsSubPage); | |
|
groby-ooo-7-16
2016/05/12 01:23:39
It would be nice if this could be a shared functio
ftang
2016/05/12 04:45:21
are you talking about TranslateBubbleModel ?
ftang
2016/05/12 06:16:02
I try to move it to TranslateBubbleModel or Transl
| |
| 655 webContents_->OpenURL( | |
| 656 content::OpenURLParams(url, content::Referrer(), NEW_FOREGROUND_TAB, | |
| 657 ui::PAGE_TRANSITION_LINK, false)); | |
| 658 [self close]; | |
| 659 } | |
| 660 | |
| 633 - (void)handleDenialPopUpButtonNopeSelected { | 661 - (void)handleDenialPopUpButtonNopeSelected { |
| 634 model_->DeclineTranslation(); | 662 model_->DeclineTranslation(); |
| 635 [self close]; | 663 [self close]; |
| 636 } | 664 } |
| 637 | 665 |
| 638 - (void)handleDenialPopUpButtonNeverTranslateLanguageSelected { | 666 - (void)handleDenialPopUpButtonNeverTranslateLanguageSelected { |
| 639 model_->DeclineTranslation(); | 667 model_->DeclineTranslation(); |
| 640 model_->SetNeverTranslateLanguage(true); | 668 model_->SetNeverTranslateLanguage(true); |
| 641 [self close]; | 669 [self close]; |
| 642 } | 670 } |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 653 [self updateAdvancedView]; | 681 [self updateAdvancedView]; |
| 654 } | 682 } |
| 655 | 683 |
| 656 - (void)handleTargetLanguagePopUpButtonSelectedItemChanged:(id)sender { | 684 - (void)handleTargetLanguagePopUpButtonSelectedItemChanged:(id)sender { |
| 657 NSPopUpButton* button = base::mac::ObjCCastStrict<NSPopUpButton>(sender); | 685 NSPopUpButton* button = base::mac::ObjCCastStrict<NSPopUpButton>(sender); |
| 658 model_->UpdateTargetLanguageIndex([button indexOfSelectedItem]); | 686 model_->UpdateTargetLanguageIndex([button indexOfSelectedItem]); |
| 659 [self updateAdvancedView]; | 687 [self updateAdvancedView]; |
| 660 } | 688 } |
| 661 | 689 |
| 662 @end | 690 @end |
| OLD | NEW |