Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(507)

Side by Side Diff: chrome/browser/ui/cocoa/translate/translate_bubble_controller.mm

Issue 1975653002: add 'langauge settings' link to the translate bubble advanced view (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: revised based on review feedback Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/metrics/histogram_macros.h"
13 #include "base/strings/sys_string_conversions.h" 13 #include "base/strings/sys_string_conversions.h"
14 #include "chrome/browser/ui/chrome_pages.h"
14 #import "chrome/browser/ui/cocoa/browser_window_controller.h" 15 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
15 #import "chrome/browser/ui/cocoa/bubble_combobox.h" 16 #import "chrome/browser/ui/cocoa/bubble_combobox.h"
16 #import "chrome/browser/ui/cocoa/info_bubble_view.h" 17 #import "chrome/browser/ui/cocoa/info_bubble_view.h"
17 #import "chrome/browser/ui/cocoa/info_bubble_window.h" 18 #import "chrome/browser/ui/cocoa/info_bubble_window.h"
18 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" 19 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h"
19 #include "chrome/browser/ui/translate/language_combobox_model.h" 20 #include "chrome/browser/ui/translate/language_combobox_model.h"
20 #include "chrome/browser/ui/translate/translate_bubble_model_impl.h" 21 #include "chrome/browser/ui/translate/translate_bubble_model.h"
21 #include "chrome/browser/ui/translate/translate_bubble_view_state_transition.h" 22 #include "chrome/browser/ui/translate/translate_bubble_view_state_transition.h"
23 #include "chrome/common/url_constants.h"
22 #include "chrome/grit/generated_resources.h" 24 #include "chrome/grit/generated_resources.h"
23 #include "components/translate/core/browser/translate_ui_delegate.h" 25 #include "components/translate/core/browser/translate_ui_delegate.h"
24 #include "content/public/browser/browser_context.h" 26 #include "content/public/browser/browser_context.h"
27 #include "content/public/common/referrer.h"
25 #include "grit/components_strings.h" 28 #include "grit/components_strings.h"
26 #include "ui/base/cocoa/cocoa_base_utils.h" 29 #include "ui/base/cocoa/cocoa_base_utils.h"
27 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" 30 #import "ui/base/cocoa/controls/hyperlink_button_cell.h"
28 #import "ui/base/cocoa/window_size_constants.h" 31 #import "ui/base/cocoa/window_size_constants.h"
29 #include "ui/base/l10n/l10n_util.h" 32 #include "ui/base/l10n/l10n_util.h"
30 #include "ui/base/models/combobox_model.h" 33 #include "ui/base/models/combobox_model.h"
31 34
32 // TODO(hajimehoshi): This class is almost same as that of views. Refactor them. 35 // TODO(hajimehoshi): This class is almost same as that of views. Refactor them.
33 class TranslateDenialComboboxModel : public ui::ComboboxModel { 36 class TranslateDenialComboboxModel : public ui::ComboboxModel {
34 public: 37 public:
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 action:(SEL)action 99 action:(SEL)action
97 toView:(NSView*)view; 100 toView:(NSView*)view;
98 - (NSPopUpButton*)addPopUpButton:(ui::ComboboxModel*)model 101 - (NSPopUpButton*)addPopUpButton:(ui::ComboboxModel*)model
99 action:(SEL)action 102 action:(SEL)action
100 toView:(NSView*)view; 103 toView:(NSView*)view;
101 - (void)handleAlwaysTranslateCheckboxPressed; 104 - (void)handleAlwaysTranslateCheckboxPressed;
102 - (void)handleDoneButtonPressed; 105 - (void)handleDoneButtonPressed;
103 - (void)handleCancelButtonPressed; 106 - (void)handleCancelButtonPressed;
104 - (void)handleShowOriginalButtonPressed; 107 - (void)handleShowOriginalButtonPressed;
105 - (void)handleAdvancedLinkButtonPressed; 108 - (void)handleAdvancedLinkButtonPressed;
109 - (void)handleLanguageSettingsLinkButtonPressed;
106 - (void)handleDenialPopUpButtonNopeSelected; 110 - (void)handleDenialPopUpButtonNopeSelected;
107 - (void)handleDenialPopUpButtonNeverTranslateLanguageSelected; 111 - (void)handleDenialPopUpButtonNeverTranslateLanguageSelected;
108 - (void)handleDenialPopUpButtonNeverTranslateSiteSelected; 112 - (void)handleDenialPopUpButtonNeverTranslateSiteSelected;
109 - (void)handleSourceLanguagePopUpButtonSelectedItemChanged:(id)sender; 113 - (void)handleSourceLanguagePopUpButtonSelectedItemChanged:(id)sender;
110 - (void)handleTargetLanguagePopUpButtonSelectedItemChanged:(id)sender; 114 - (void)handleTargetLanguagePopUpButtonSelectedItemChanged:(id)sender;
111 115
112 @end 116 @end
113 117
114 @implementation TranslateBubbleController 118 @implementation TranslateBubbleController
115 119
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 // Buttons 442 // Buttons
439 advancedDoneButton_ = 443 advancedDoneButton_ =
440 [self addButton:l10n_util::GetNSStringWithFixup(IDS_DONE) 444 [self addButton:l10n_util::GetNSStringWithFixup(IDS_DONE)
441 action:@selector(handleDoneButtonPressed) 445 action:@selector(handleDoneButtonPressed)
442 toView:view]; 446 toView:view];
443 advancedCancelButton_ = 447 advancedCancelButton_ =
444 [self addButton:l10n_util::GetNSStringWithFixup(IDS_CANCEL) 448 [self addButton:l10n_util::GetNSStringWithFixup(IDS_CANCEL)
445 action:@selector(handleCancelButtonPressed) 449 action:@selector(handleCancelButtonPressed)
446 toView:view]; 450 toView:view];
447 451
452 NSString* message = l10n_util::GetNSStringWithFixup(
453 IDS_TRANSLATE_BUBBLE_LANGUAGE_SETTINGS);
454 action = @selector(handleLanguageSettingsLinkButtonPressed);
455 NSButton* languageSettingsLinkButton =
456 [self addLinkButtonWithText:message
457 action:action
458 toView:view];
459
448 // Layout 460 // Layout
449 CGFloat textLabelWidth = NSWidth([sourceLanguageLabel frame]); 461 CGFloat textLabelWidth = NSWidth([sourceLanguageLabel frame]);
450 if (textLabelWidth < NSWidth([targetLanguageLabel frame])) 462 if (textLabelWidth < NSWidth([targetLanguageLabel frame]))
451 textLabelWidth = NSWidth([targetLanguageLabel frame]); 463 textLabelWidth = NSWidth([targetLanguageLabel frame]);
452 464
453 CGFloat yPos = 0; 465 CGFloat yPos = 0;
454 466
455 [advancedDoneButton_ setFrameOrigin:NSMakePoint(0, yPos)]; 467 [advancedDoneButton_ setFrameOrigin:NSMakePoint(0, yPos)];
456 [advancedCancelButton_ setFrameOrigin:NSMakePoint(0, yPos)]; 468 [advancedCancelButton_ setFrameOrigin:NSMakePoint(0, yPos)];
457 469
458 yPos += NSHeight([advancedDoneButton_ frame]) + 470 [languageSettingsLinkButton setFrameOrigin:NSMakePoint(0, yPos)];
471
472 // Vertical center the languageSettingsLinkButton with the
473 // advancedDoneButton_. Move the link position by 1px to make the baseline of
474 // the text inside the link vertically align with the text inside the buttons.
475 yPos = 1 + floor((NSHeight([advancedDoneButton_ frame]) -
476 NSHeight([languageSettingsLinkButton frame])) / 2);
477 [languageSettingsLinkButton setFrameOrigin:NSMakePoint(0, yPos)];
478
479 yPos = NSHeight([advancedDoneButton_ frame]) +
459 kUnrelatedControlVerticalSpacing; 480 kUnrelatedControlVerticalSpacing;
460 481
461 if (alwaysTranslateCheckbox_) { 482 if (alwaysTranslateCheckbox_) {
462 [alwaysTranslateCheckbox_ setFrameOrigin:NSMakePoint(textLabelWidth, yPos)]; 483 [alwaysTranslateCheckbox_ setFrameOrigin:NSMakePoint(textLabelWidth, yPos)];
463 484
464 yPos += NSHeight([alwaysTranslateCheckbox_ frame]) + 485 yPos += NSHeight([alwaysTranslateCheckbox_ frame]) +
465 kRelatedControlVerticalSpacing; 486 kRelatedControlVerticalSpacing;
466 } 487 }
467 488
468 CGFloat diffY = [[sourcePopUpButton cell] 489 CGFloat diffY = [[sourcePopUpButton cell]
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 translate::ReportUiAction(translate::SHOW_ORIGINAL_BUTTON_CLICKED); 662 translate::ReportUiAction(translate::SHOW_ORIGINAL_BUTTON_CLICKED);
642 model_->RevertTranslation(); 663 model_->RevertTranslation();
643 [self close]; 664 [self close];
644 } 665 }
645 666
646 - (void)handleAdvancedLinkButtonPressed { 667 - (void)handleAdvancedLinkButtonPressed {
647 translate::ReportUiAction(translate::ADVANCED_LINK_CLICKED); 668 translate::ReportUiAction(translate::ADVANCED_LINK_CLICKED);
648 [self switchView:TranslateBubbleModel::VIEW_STATE_ADVANCED]; 669 [self switchView:TranslateBubbleModel::VIEW_STATE_ADVANCED];
649 } 670 }
650 671
672 - (void)handleLanguageSettingsLinkButtonPressed {
673 GURL url = chrome::GetSettingsUrl(chrome::kLanguageOptionsSubPage);
674 webContents_->OpenURL(
675 content::OpenURLParams(url, content::Referrer(), NEW_FOREGROUND_TAB,
676 ui::PAGE_TRANSITION_LINK, false));
677 translate::ReportUiAction(translate::SETTINGS_LINK_CLICKED);
678 [self close];
679 }
680
651 - (void)handleDenialPopUpButtonNopeSelected { 681 - (void)handleDenialPopUpButtonNopeSelected {
652 translate::ReportUiAction(translate::NOPE_MENU_CLICKED); 682 translate::ReportUiAction(translate::NOPE_MENU_CLICKED);
653 model_->DeclineTranslation(); 683 model_->DeclineTranslation();
654 [self close]; 684 [self close];
655 } 685 }
656 686
657 - (void)handleDenialPopUpButtonNeverTranslateLanguageSelected { 687 - (void)handleDenialPopUpButtonNeverTranslateLanguageSelected {
658 translate::ReportUiAction(translate::NEVER_TRANSLATE_LANGUAGE_MENU_CLICKED); 688 translate::ReportUiAction(translate::NEVER_TRANSLATE_LANGUAGE_MENU_CLICKED);
659 model_->DeclineTranslation(); 689 model_->DeclineTranslation();
660 model_->SetNeverTranslateLanguage(true); 690 model_->SetNeverTranslateLanguage(true);
(...skipping 15 matching lines...) Expand all
676 } 706 }
677 707
678 - (void)handleTargetLanguagePopUpButtonSelectedItemChanged:(id)sender { 708 - (void)handleTargetLanguagePopUpButtonSelectedItemChanged:(id)sender {
679 translate::ReportUiAction(translate::TARGET_LANGUAGE_MENU_CLICKED); 709 translate::ReportUiAction(translate::TARGET_LANGUAGE_MENU_CLICKED);
680 NSPopUpButton* button = base::mac::ObjCCastStrict<NSPopUpButton>(sender); 710 NSPopUpButton* button = base::mac::ObjCCastStrict<NSPopUpButton>(sender);
681 model_->UpdateTargetLanguageIndex([button indexOfSelectedItem]); 711 model_->UpdateTargetLanguageIndex([button indexOfSelectedItem]);
682 [self updateAdvancedView]; 712 [self updateAdvancedView];
683 } 713 }
684 714
685 @end 715 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698