| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "chrome/browser/views/infobars/translate_infobars.h" | 5 #include "chrome/browser/views/infobars/translate_infobars.h" |
| 6 | 6 |
| 7 #include "app/gfx/canvas.h" | 7 #include "app/gfx/canvas.h" |
| 8 #include "app/l10n_util.h" | 8 #include "app/l10n_util.h" |
| 9 #include "app/resource_bundle.h" | 9 #include "app/resource_bundle.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 options_menu_button_ = CreateMenuButton(kMenuIDOptions, | 246 options_menu_button_ = CreateMenuButton(kMenuIDOptions, |
| 247 l10n_util::GetString(IDS_TRANSLATE_INFOBAR_OPTIONS)); | 247 l10n_util::GetString(IDS_TRANSLATE_INFOBAR_OPTIONS)); |
| 248 AddChildView(options_menu_button_); | 248 AddChildView(options_menu_button_); |
| 249 | 249 |
| 250 // Create state-dependent controls. | 250 // Create state-dependent controls. |
| 251 UpdateState(GetDelegate()->state()); | 251 UpdateState(GetDelegate()->state()); |
| 252 | 252 |
| 253 // Register for PAGE_TRANSLATED notification. | 253 // Register for PAGE_TRANSLATED notification. |
| 254 notification_registrar_.Add(this, NotificationType::PAGE_TRANSLATED, | 254 notification_registrar_.Add(this, NotificationType::PAGE_TRANSLATED, |
| 255 Source<TabContents>(GetDelegate()->tab_contents())); | 255 Source<TabContents>(GetDelegate()->tab_contents())); |
| 256 |
| 257 if (GetDelegate()->state() == TranslateInfoBarDelegate::kBeforeTranslate) |
| 258 UMA_HISTOGRAM_COUNTS("Translate.ShowBeforeTranslateInfobar", 1); |
| 256 } | 259 } |
| 257 | 260 |
| 258 TranslateInfoBar::~TranslateInfoBar() { | 261 TranslateInfoBar::~TranslateInfoBar() { |
| 259 } | 262 } |
| 260 | 263 |
| 261 void TranslateInfoBar::UpdateState( | 264 void TranslateInfoBar::UpdateState( |
| 262 TranslateInfoBarDelegate::TranslateState new_state) { | 265 TranslateInfoBarDelegate::TranslateState new_state) { |
| 263 // Create and initialize state-dependent controls if necessary. | 266 // Create and initialize state-dependent controls if necessary. |
| 264 switch (new_state) { | 267 switch (new_state) { |
| 265 case TranslateInfoBarDelegate::kAfterTranslate: | 268 case TranslateInfoBarDelegate::kAfterTranslate: |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 return true; | 544 return true; |
| 542 } | 545 } |
| 543 | 546 |
| 544 bool TranslateInfoBar::GetAcceleratorForCommandId(int command_id, | 547 bool TranslateInfoBar::GetAcceleratorForCommandId(int command_id, |
| 545 views::Accelerator* accelerator) { | 548 views::Accelerator* accelerator) { |
| 546 return false; | 549 return false; |
| 547 } | 550 } |
| 548 | 551 |
| 549 void TranslateInfoBar::ExecuteCommand(int command_id) { | 552 void TranslateInfoBar::ExecuteCommand(int command_id) { |
| 550 if (command_id >= IDC_TRANSLATE_TARGET_LANGUAGE_BASE) { | 553 if (command_id >= IDC_TRANSLATE_TARGET_LANGUAGE_BASE) { |
| 554 UMA_HISTOGRAM_COUNTS("Translate.ModifyTargetLang", 1); |
| 551 OnLanguageModified(target_language_menu_button_, | 555 OnLanguageModified(target_language_menu_button_, |
| 552 command_id - IDC_TRANSLATE_TARGET_LANGUAGE_BASE); | 556 command_id - IDC_TRANSLATE_TARGET_LANGUAGE_BASE); |
| 553 } else if (command_id >= IDC_TRANSLATE_ORIGINAL_LANGUAGE_BASE) { | 557 } else if (command_id >= IDC_TRANSLATE_ORIGINAL_LANGUAGE_BASE) { |
| 558 UMA_HISTOGRAM_COUNTS("Translate.ModifyOriginalLang", 1); |
| 554 OnLanguageModified(original_language_menu_button_, | 559 OnLanguageModified(original_language_menu_button_, |
| 555 command_id - IDC_TRANSLATE_ORIGINAL_LANGUAGE_BASE); | 560 command_id - IDC_TRANSLATE_ORIGINAL_LANGUAGE_BASE); |
| 556 } else { | 561 } else { |
| 557 switch (command_id) { | 562 switch (command_id) { |
| 558 case IDC_TRANSLATE_OPTIONS_NEVER_TRANSLATE_LANG: | 563 case IDC_TRANSLATE_OPTIONS_NEVER_TRANSLATE_LANG: |
| 564 UMA_HISTOGRAM_COUNTS("Translate.NeverTranslateLang", 1); |
| 559 GetDelegate()->ToggleLanguageBlacklist(); | 565 GetDelegate()->ToggleLanguageBlacklist(); |
| 560 break; | 566 break; |
| 561 | 567 |
| 562 case IDC_TRANSLATE_OPTIONS_NEVER_TRANSLATE_SITE: | 568 case IDC_TRANSLATE_OPTIONS_NEVER_TRANSLATE_SITE: |
| 569 UMA_HISTOGRAM_COUNTS("Translate.NeverTranslateSite", 1); |
| 563 GetDelegate()->ToggleSiteBlacklist(); | 570 GetDelegate()->ToggleSiteBlacklist(); |
| 564 break; | 571 break; |
| 565 | 572 |
| 566 case IDC_TRANSLATE_OPTIONS_ALWAYS: | 573 case IDC_TRANSLATE_OPTIONS_ALWAYS: |
| 574 UMA_HISTOGRAM_COUNTS("Translate.AlwaysTranslateLang", 1); |
| 567 GetDelegate()->ToggleAlwaysTranslate(); | 575 GetDelegate()->ToggleAlwaysTranslate(); |
| 568 break; | 576 break; |
| 569 | 577 |
| 570 case IDC_TRANSLATE_OPTIONS_ABOUT: { | 578 case IDC_TRANSLATE_OPTIONS_ABOUT: { |
| 571 TabContents* tab_contents = GetDelegate()->tab_contents(); | 579 TabContents* tab_contents = GetDelegate()->tab_contents(); |
| 572 if (tab_contents) { | 580 if (tab_contents) { |
| 573 string16 url = l10n_util::GetStringUTF16( | 581 string16 url = l10n_util::GetStringUTF16( |
| 574 IDS_ABOUT_GOOGLE_TRANSLATE_URL); | 582 IDS_ABOUT_GOOGLE_TRANSLATE_URL); |
| 575 tab_contents->OpenURL(GURL(url), GURL(), NEW_FOREGROUND_TAB, | 583 tab_contents->OpenURL(GURL(url), GURL(), NEW_FOREGROUND_TAB, |
| 576 PageTransition::LINK); | 584 PageTransition::LINK); |
| 577 } | 585 } |
| 578 break; | 586 break; |
| 579 } | 587 } |
| 580 | 588 |
| 581 default: | 589 default: |
| 582 NOTREACHED() << "Invalid command id from menu."; | 590 NOTREACHED() << "Invalid command id from menu."; |
| 583 break; | 591 break; |
| 584 } | 592 } |
| 585 } | 593 } |
| 586 } | 594 } |
| 587 | 595 |
| 588 // TranslateInfoBar, views::ButtonListener overrides: -------------------------- | 596 // TranslateInfoBar, views::ButtonListener overrides: -------------------------- |
| 589 | 597 |
| 590 void TranslateInfoBar::ButtonPressed( | 598 void TranslateInfoBar::ButtonPressed( |
| 591 views::Button* sender, const views::Event& event) { | 599 views::Button* sender, const views::Event& event) { |
| 592 if (sender == accept_button_) { | 600 if (sender == accept_button_) { |
| 593 GetDelegate()->Translate(); | 601 GetDelegate()->Translate(); |
| 594 UpdateState(GetDelegate()->state()); | 602 UpdateState(GetDelegate()->state()); |
| 603 UMA_HISTOGRAM_COUNTS("Translate.Translate", 1); |
| 595 } else if (sender == deny_button_) { | 604 } else if (sender == deny_button_) { |
| 596 GetDelegate()->TranslationDeclined(); | 605 GetDelegate()->TranslationDeclined(); |
| 606 UMA_HISTOGRAM_COUNTS("Translate.DeclineTranslate", 1); |
| 597 RemoveInfoBar(); | 607 RemoveInfoBar(); |
| 598 } else { // Let base InfoBar handle close button. | 608 } else { // Let base InfoBar handle close button. |
| 599 InfoBar::ButtonPressed(sender, event); | 609 InfoBar::ButtonPressed(sender, event); |
| 600 } | 610 } |
| 601 } | 611 } |
| 602 | 612 |
| 603 // TranslateInfoBar, NotificationObserver overrides: --------------------------- | 613 // TranslateInfoBar, NotificationObserver overrides: --------------------------- |
| 604 | 614 |
| 605 void TranslateInfoBar::Observe(NotificationType type, | 615 void TranslateInfoBar::Observe(NotificationType type, |
| 606 const NotificationSource& source, const NotificationDetails& details) { | 616 const NotificationSource& source, const NotificationDetails& details) { |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 738 inline int TranslateInfoBar::GetSpacingAfterFirstLanguageButton() const { | 748 inline int TranslateInfoBar::GetSpacingAfterFirstLanguageButton() const { |
| 739 return (GetDelegate()->state() == TranslateInfoBarDelegate::kBeforeTranslate ? | 749 return (GetDelegate()->state() == TranslateInfoBarDelegate::kBeforeTranslate ? |
| 740 10 : kButtonInLabelSpacing); | 750 10 : kButtonInLabelSpacing); |
| 741 } | 751 } |
| 742 | 752 |
| 743 // TranslateInfoBarDelegate, InfoBarDelegate overrides: ------------------ | 753 // TranslateInfoBarDelegate, InfoBarDelegate overrides: ------------------ |
| 744 | 754 |
| 745 InfoBar* TranslateInfoBarDelegate::CreateInfoBar() { | 755 InfoBar* TranslateInfoBarDelegate::CreateInfoBar() { |
| 746 return new TranslateInfoBar(this); | 756 return new TranslateInfoBar(this); |
| 747 } | 757 } |
| OLD | NEW |