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/metrics/histogram_macros.h" | |
| 12 #include "base/strings/sys_string_conversions.h" | 13 #include "base/strings/sys_string_conversions.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/browser/ui/translate/translate_bubble_view_state_transition.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" |
| 23 #include "grit/components_strings.h" | 25 #include "grit/components_strings.h" |
| 24 #include "ui/base/cocoa/cocoa_base_utils.h" | 26 #include "ui/base/cocoa/cocoa_base_utils.h" |
| 25 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" | 27 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" |
| 26 #import "ui/base/cocoa/window_size_constants.h" | 28 #import "ui/base/cocoa/window_size_constants.h" |
| 27 #include "ui/base/l10n/l10n_util.h" | 29 #include "ui/base/l10n/l10n_util.h" |
| 28 #include "ui/base/models/combobox_model.h" | 30 #include "ui/base/models/combobox_model.h" |
| 29 | 31 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 - (void)updateAdvancedView; | 86 - (void)updateAdvancedView; |
| 85 - (NSTextField*)addText:(NSString*)text | 87 - (NSTextField*)addText:(NSString*)text |
| 86 toView:(NSView*)view; | 88 toView:(NSView*)view; |
| 87 - (NSButton*)addLinkButtonWithText:(NSString*)text | 89 - (NSButton*)addLinkButtonWithText:(NSString*)text |
| 88 action:(SEL)action | 90 action:(SEL)action |
| 89 toView:(NSView*)view; | 91 toView:(NSView*)view; |
| 90 - (NSButton*)addButton:(NSString*)title | 92 - (NSButton*)addButton:(NSString*)title |
| 91 action:(SEL)action | 93 action:(SEL)action |
| 92 toView:(NSView*)view; | 94 toView:(NSView*)view; |
| 93 - (NSButton*)addCheckbox:(NSString*)title | 95 - (NSButton*)addCheckbox:(NSString*)title |
| 96 action:(SEL)action | |
| 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)handleAlwaysTranslateCheckboxPressed; |
| 99 - (void)handleDoneButtonPressed; | 102 - (void)handleDoneButtonPressed; |
| 100 - (void)handleCancelButtonPressed; | 103 - (void)handleCancelButtonPressed; |
| 101 - (void)handleShowOriginalButtonPressed; | 104 - (void)handleShowOriginalButtonPressed; |
| 102 - (void)handleAdvancedLinkButtonPressed; | 105 - (void)handleAdvancedLinkButtonPressed; |
| 103 - (void)handleDenialPopUpButtonNopeSelected; | 106 - (void)handleDenialPopUpButtonNopeSelected; |
| 104 - (void)handleDenialPopUpButtonNeverTranslateLanguageSelected; | 107 - (void)handleDenialPopUpButtonNeverTranslateLanguageSelected; |
| 105 - (void)handleDenialPopUpButtonNeverTranslateSiteSelected; | 108 - (void)handleDenialPopUpButtonNeverTranslateSiteSelected; |
| 106 - (void)handleSourceLanguagePopUpButtonSelectedItemChanged:(id)sender; | 109 - (void)handleSourceLanguagePopUpButtonSelectedItemChanged:(id)sender; |
| 107 - (void)handleTargetLanguagePopUpButtonSelectedItemChanged:(id)sender; | 110 - (void)handleTargetLanguagePopUpButtonSelectedItemChanged:(id)sender; |
| 111 - (void)reportUiAction:(translate::TranslateBubbleUiEvent)action; | |
| 108 | 112 |
| 109 @end | 113 @end |
| 110 | 114 |
| 111 @implementation TranslateBubbleController | 115 @implementation TranslateBubbleController |
| 112 | 116 |
| 113 @synthesize webContents = webContents_; | 117 @synthesize webContents = webContents_; |
| 114 | 118 |
| 115 - (id)initWithParentWindow:(BrowserWindowController*)controller | 119 - (id)initWithParentWindow:(BrowserWindowController*)controller |
| 116 model:(std::unique_ptr<TranslateBubbleModel>)model | 120 model:(std::unique_ptr<TranslateBubbleModel>)model |
| 117 webContents:(content::WebContents*)webContents { | 121 webContents:(content::WebContents*)webContents { |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 415 [self addPopUpButton:targetLanguageComboboxModel_.get() | 419 [self addPopUpButton:targetLanguageComboboxModel_.get() |
| 416 action:action | 420 action:action |
| 417 toView:view]; | 421 toView:view]; |
| 418 | 422 |
| 419 // 'Always translate' checkbox | 423 // 'Always translate' checkbox |
| 420 BOOL isIncognitoWindow = webContents_ ? | 424 BOOL isIncognitoWindow = webContents_ ? |
| 421 webContents_->GetBrowserContext()->IsOffTheRecord() : NO; | 425 webContents_->GetBrowserContext()->IsOffTheRecord() : NO; |
| 422 if (!isIncognitoWindow) { | 426 if (!isIncognitoWindow) { |
| 423 NSString* title = | 427 NSString* title = |
| 424 l10n_util::GetNSStringWithFixup(IDS_TRANSLATE_BUBBLE_ALWAYS); | 428 l10n_util::GetNSStringWithFixup(IDS_TRANSLATE_BUBBLE_ALWAYS); |
| 429 action = @selector(handleAlwaysTranslateCheckboxPressed); | |
| 425 alwaysTranslateCheckbox_ = [self addCheckbox:title | 430 alwaysTranslateCheckbox_ = [self addCheckbox:title |
| 431 action:action | |
| 426 toView:view]; | 432 toView:view]; |
| 427 } | 433 } |
| 428 | 434 |
| 429 // Buttons | 435 // Buttons |
| 430 advancedDoneButton_ = | 436 advancedDoneButton_ = |
| 431 [self addButton:l10n_util::GetNSStringWithFixup(IDS_DONE) | 437 [self addButton:l10n_util::GetNSStringWithFixup(IDS_DONE) |
| 432 action:@selector(handleDoneButtonPressed) | 438 action:@selector(handleDoneButtonPressed) |
| 433 toView:view]; | 439 toView:view]; |
| 434 advancedCancelButton_ = | 440 advancedCancelButton_ = |
| 435 [self addButton:l10n_util::GetNSStringWithFixup(IDS_CANCEL) | 441 [self addButton:l10n_util::GetNSStringWithFixup(IDS_CANCEL) |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 556 [button sizeToFit]; | 562 [button sizeToFit]; |
| 557 [button setTarget:self]; | 563 [button setTarget:self]; |
| 558 [button setAction:action]; | 564 [button setAction:action]; |
| 559 | 565 |
| 560 [view addSubview:button.get()]; | 566 [view addSubview:button.get()]; |
| 561 | 567 |
| 562 return button.get(); | 568 return button.get(); |
| 563 } | 569 } |
| 564 | 570 |
| 565 - (NSButton*)addCheckbox:(NSString*)title | 571 - (NSButton*)addCheckbox:(NSString*)title |
| 572 action:(SEL)action | |
| 566 toView:(NSView*)view { | 573 toView:(NSView*)view { |
| 567 base::scoped_nsobject<NSButton> button( | 574 base::scoped_nsobject<NSButton> button( |
| 568 [[NSButton alloc] initWithFrame:NSZeroRect]); | 575 [[NSButton alloc] initWithFrame:NSZeroRect]); |
| 569 [button setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; | 576 [button setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]]; |
| 570 [button setTitle:title]; | 577 [button setTitle:title]; |
| 571 [[button cell] setControlSize:NSSmallControlSize]; | 578 [[button cell] setControlSize:NSSmallControlSize]; |
| 572 [button setButtonType:NSSwitchButton]; | 579 [button setButtonType:NSSwitchButton]; |
| 573 [button sizeToFit]; | 580 [button sizeToFit]; |
| 581 [button setTarget:self]; | |
| 582 [button setAction:action]; | |
| 574 | 583 |
| 575 [view addSubview:button.get()]; | 584 [view addSubview:button.get()]; |
| 576 | 585 |
| 577 return button.get(); | 586 return button.get(); |
| 578 } | 587 } |
| 579 | 588 |
| 580 - (NSPopUpButton*)addPopUpButton:(ui::ComboboxModel*)model | 589 - (NSPopUpButton*)addPopUpButton:(ui::ComboboxModel*)model |
| 581 action:(SEL)action | 590 action:(SEL)action |
| 582 toView:(NSView*)view { | 591 toView:(NSView*)view { |
| 583 base::scoped_nsobject<NSPopUpButton> button( | 592 base::scoped_nsobject<NSPopUpButton> button( |
| 584 [[BubbleCombobox alloc] initWithFrame:NSZeroRect | 593 [[BubbleCombobox alloc] initWithFrame:NSZeroRect |
| 585 pullsDown:NO | 594 pullsDown:NO |
| 586 model:model]); | 595 model:model]); |
| 587 [button setTarget:self]; | 596 [button setTarget:self]; |
| 588 [button setAction:action]; | 597 [button setAction:action]; |
| 589 [button sizeToFit]; | 598 [button sizeToFit]; |
| 590 [view addSubview:button.get()]; | 599 [view addSubview:button.get()]; |
| 591 return button.get(); | 600 return button.get(); |
| 592 } | 601 } |
| 593 | 602 |
| 594 - (void)handleTranslateButtonPressed { | 603 - (void)handleTranslateButtonPressed { |
| 604 [self reportUiAction:translate::TRANSLATE_BUTTON_CLICKED]; | |
| 595 translateExecuted_ = YES; | 605 translateExecuted_ = YES; |
| 596 model_->Translate(); | 606 model_->Translate(); |
| 597 } | 607 } |
| 598 | 608 |
| 599 - (void)handleNopeButtonPressed { | 609 - (void)handleAlwaysTranslateCheckboxPressed { |
| 600 model_->DeclineTranslation(); | 610 [self reportUiAction:[alwaysTranslateCheckbox_ state] == NSOnState |
| 601 [self close]; | 611 ? translate::ALWAYS_TRANSLATE_CHECKED |
|
groby-ooo-7-16
2016/05/11 20:32:45
Does that match views semantics? (I.e. are we reco
ftang
2016/05/14 04:50:24
yes, this record the user's action, not their fina
| |
| 612 : translate::ALWAYS_TRANSLATE_UNCHECKED]; | |
| 602 } | 613 } |
| 603 | 614 |
| 604 - (void)handleDoneButtonPressed { | 615 - (void)handleDoneButtonPressed { |
| 616 [self reportUiAction:translate::DONE_BUTTON_CLICKED]; | |
| 605 if (alwaysTranslateCheckbox_) { | 617 if (alwaysTranslateCheckbox_) { |
| 606 model_->SetAlwaysTranslate( | 618 model_->SetAlwaysTranslate( |
| 607 [alwaysTranslateCheckbox_ state] == NSOnState); | 619 [alwaysTranslateCheckbox_ state] == NSOnState); |
| 608 } | 620 } |
| 609 if (model_->IsPageTranslatedInCurrentLanguages()) { | 621 if (model_->IsPageTranslatedInCurrentLanguages()) { |
| 610 model_->GoBackFromAdvanced(); | 622 model_->GoBackFromAdvanced(); |
| 611 [self performLayout]; | 623 [self performLayout]; |
| 612 } else { | 624 } else { |
| 613 translateExecuted_ = true; | 625 translateExecuted_ = true; |
| 614 model_->Translate(); | 626 model_->Translate(); |
| 615 [self switchView:TranslateBubbleModel::VIEW_STATE_TRANSLATING]; | 627 [self switchView:TranslateBubbleModel::VIEW_STATE_TRANSLATING]; |
| 616 } | 628 } |
| 617 } | 629 } |
| 618 | 630 |
| 619 - (void)handleCancelButtonPressed { | 631 - (void)handleCancelButtonPressed { |
| 632 [self reportUiAction:translate::CANCEL_BUTTON_CLICKED]; | |
| 620 model_->GoBackFromAdvanced(); | 633 model_->GoBackFromAdvanced(); |
| 621 [self performLayout]; | 634 [self performLayout]; |
| 622 } | 635 } |
| 623 | 636 |
| 624 - (void)handleShowOriginalButtonPressed { | 637 - (void)handleShowOriginalButtonPressed { |
| 638 [self reportUiAction:translate::SHOW_ORIGINAL_BUTTON_CLICKED]; | |
| 625 model_->RevertTranslation(); | 639 model_->RevertTranslation(); |
| 626 [self close]; | 640 [self close]; |
| 627 } | 641 } |
| 628 | 642 |
| 629 - (void)handleAdvancedLinkButtonPressed { | 643 - (void)handleAdvancedLinkButtonPressed { |
| 644 [self reportUiAction:translate::ADVANCED_LINK_CLICKED]; | |
| 630 [self switchView:TranslateBubbleModel::VIEW_STATE_ADVANCED]; | 645 [self switchView:TranslateBubbleModel::VIEW_STATE_ADVANCED]; |
| 631 } | 646 } |
| 632 | 647 |
| 633 - (void)handleDenialPopUpButtonNopeSelected { | 648 - (void)handleDenialPopUpButtonNopeSelected { |
| 649 [self reportUiAction:translate::NOPE_MENU_CLICKED]; | |
| 634 model_->DeclineTranslation(); | 650 model_->DeclineTranslation(); |
| 635 [self close]; | 651 [self close]; |
| 636 } | 652 } |
| 637 | 653 |
| 638 - (void)handleDenialPopUpButtonNeverTranslateLanguageSelected { | 654 - (void)handleDenialPopUpButtonNeverTranslateLanguageSelected { |
| 655 [self reportUiAction:translate::NEVER_TRANSLATE_LANGUAGE_MENU_CLICKED]; | |
| 639 model_->DeclineTranslation(); | 656 model_->DeclineTranslation(); |
| 640 model_->SetNeverTranslateLanguage(true); | 657 model_->SetNeverTranslateLanguage(true); |
| 641 [self close]; | 658 [self close]; |
| 642 } | 659 } |
| 643 | 660 |
| 644 - (void)handleDenialPopUpButtonNeverTranslateSiteSelected { | 661 - (void)handleDenialPopUpButtonNeverTranslateSiteSelected { |
| 662 [self reportUiAction:translate::NEVER_TRANSLATE_SITE_MENU_CLICKED]; | |
| 645 model_->DeclineTranslation(); | 663 model_->DeclineTranslation(); |
| 646 model_->SetNeverTranslateSite(true); | 664 model_->SetNeverTranslateSite(true); |
| 647 [self close]; | 665 [self close]; |
| 648 } | 666 } |
| 649 | 667 |
| 650 - (void)handleSourceLanguagePopUpButtonSelectedItemChanged:(id)sender { | 668 - (void)handleSourceLanguagePopUpButtonSelectedItemChanged:(id)sender { |
| 669 [self reportUiAction:translate::SOURCE_LANGUAGE_MENU_CLICKED]; | |
| 651 NSPopUpButton* button = base::mac::ObjCCastStrict<NSPopUpButton>(sender); | 670 NSPopUpButton* button = base::mac::ObjCCastStrict<NSPopUpButton>(sender); |
| 652 model_->UpdateOriginalLanguageIndex([button indexOfSelectedItem]); | 671 model_->UpdateOriginalLanguageIndex([button indexOfSelectedItem]); |
| 653 [self updateAdvancedView]; | 672 [self updateAdvancedView]; |
| 654 } | 673 } |
| 655 | 674 |
| 656 - (void)handleTargetLanguagePopUpButtonSelectedItemChanged:(id)sender { | 675 - (void)handleTargetLanguagePopUpButtonSelectedItemChanged:(id)sender { |
| 676 [self reportUiAction:translate::TARGET_LANGUAGE_MENU_CLICKED]; | |
| 657 NSPopUpButton* button = base::mac::ObjCCastStrict<NSPopUpButton>(sender); | 677 NSPopUpButton* button = base::mac::ObjCCastStrict<NSPopUpButton>(sender); |
| 658 model_->UpdateTargetLanguageIndex([button indexOfSelectedItem]); | 678 model_->UpdateTargetLanguageIndex([button indexOfSelectedItem]); |
| 659 [self updateAdvancedView]; | 679 [self updateAdvancedView]; |
| 660 } | 680 } |
| 661 | 681 |
| 682 - (void)reportUiAction:(translate::TranslateBubbleUiEvent)action { | |
|
groby-ooo-7-16
2016/05/11 20:32:45
Please make this shared between Views and OSX - no
ftang
2016/05/14 04:50:24
Done.
| |
| 683 UMA_HISTOGRAM_ENUMERATION("Translate.BubbleUiEvent", action, | |
| 684 translate::TRANSLATE_BUBBLE_UI_EVENT_MAX); | |
| 685 } | |
| 686 | |
| 662 @end | 687 @end |
| OLD | NEW |