diff options
author | droger@chromium.org <droger@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-02 16:01:29 +0000 |
---|---|---|
committer | droger@chromium.org <droger@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-02 16:01:29 +0000 |
commit | dbe9bfab6e9b264b1b339e8c1c422f0b5dfa2a6c (patch) | |
tree | e644b6d42f97c38a12541ac8a2f13fcb849725fe | |
parent | 603ed1e862e48615acadc96724749529487f8947 (diff) | |
download | chromium_src-dbe9bfab6e9b264b1b339e8c1c422f0b5dfa2a6c.zip chromium_src-dbe9bfab6e9b264b1b339e8c1c422f0b5dfa2a6c.tar.gz chromium_src-dbe9bfab6e9b264b1b339e8c1c422f0b5dfa2a6c.tar.bz2 |
Move TranslateInfoBarDelegate and OptionsMenuModel to the Translate component.
To solve the dependency on chrome_command_ids, this CL removes the
IDC_OPTIONS_TRANSLATE_* constants and instead defines the command IDs
locally in the file, which is an approach already used at several other places in
the code.
To solve the dependency on themes, the icon ID for the translate infobar is no
longer hardcoded, but fetched from the translate client instead.
BUG=371845
TBR=estade, joaodasilva
Review URL: https://codereview.chromium.org/284313008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@274252 0039d316-1c4b-4281-b951-d872f2087c98
28 files changed, 160 insertions, 131 deletions
diff --git a/build/ios/grit_whitelist.txt b/build/ios/grit_whitelist.txt index 045c704..d66c0edd 100644 --- a/build/ios/grit_whitelist.txt +++ b/build/ios/grit_whitelist.txt @@ -984,8 +984,23 @@ IDS_TOOLTIP_STAR IDS_TOUCH_EVENTS_DESCRIPTION IDS_TOUCH_EVENTS_NAME IDS_TRANSLATE_INFOBAR_ACCEPT +IDS_TRANSLATE_INFOBAR_AFTER_MESSAGE +IDS_TRANSLATE_INFOBAR_AFTER_MESSAGE_AUTODETERMINED_SOURCE_LANGUAGE IDS_TRANSLATE_INFOBAR_BEFORE_MESSAGE IDS_TRANSLATE_INFOBAR_DENY +IDS_TRANSLATE_INFOBAR_ERROR_CANT_CONNECT +IDS_TRANSLATE_INFOBAR_ERROR_CANT_TRANSLATE +IDS_TRANSLATE_INFOBAR_ERROR_SAME_LANGUAGE +IDS_TRANSLATE_INFOBAR_OPTIONS_ABOUT +IDS_TRANSLATE_INFOBAR_OPTIONS_ALWAYS +IDS_TRANSLATE_INFOBAR_OPTIONS_NEVER_TRANSLATE_LANG +IDS_TRANSLATE_INFOBAR_OPTIONS_NEVER_TRANSLATE_SITE +IDS_TRANSLATE_INFOBAR_OPTIONS_REPORT_ERROR +IDS_TRANSLATE_INFOBAR_RETRY +IDS_TRANSLATE_INFOBAR_REVERT +IDS_TRANSLATE_INFOBAR_TRANSLATING_TO +IDS_TRANSLATE_INFOBAR_UNKNOWN_PAGE_LANGUAGE +IDS_TRANSLATE_INFOBAR_UNSUPPORTED_PAGE_LANGUAGE IDS_UPGRADE_AVAILABLE IDS_UPGRADE_AVAILABLE_BUTTON IDS_WEB_FONT_FAMILY diff --git a/chrome/app/chrome_command_ids.h b/chrome/app/chrome_command_ids.h index b7aa189..1deaa8d 100644 --- a/chrome/app/chrome_command_ids.h +++ b/chrome/app/chrome_command_ids.h @@ -237,13 +237,8 @@ #define IDC_WRITING_DIRECTION_RTL 41123 // Translate -#define IDC_TRANSLATE_OPTIONS_ALWAYS 42000 -#define IDC_TRANSLATE_OPTIONS_NEVER_TRANSLATE_LANG 42001 -#define IDC_TRANSLATE_OPTIONS_NEVER_TRANSLATE_SITE 42002 -#define IDC_TRANSLATE_REPORT_BAD_LANGUAGE_DETECTION 42003 -#define IDC_TRANSLATE_OPTIONS_ABOUT 42004 -#define IDC_TRANSLATE_ORIGINAL_LANGUAGE_BASE 42100 -#define IDC_TRANSLATE_TARGET_LANGUAGE_BASE 42400 +#define IDC_TRANSLATE_ORIGINAL_LANGUAGE_BASE 42100 +#define IDC_TRANSLATE_TARGET_LANGUAGE_BASE 42400 // Speech input #define IDC_TOGGLE_SPEECH_INPUT 42500 diff --git a/chrome/browser/autofill/autofill_interactive_uitest.cc b/chrome/browser/autofill/autofill_interactive_uitest.cc index 6d78c92..1842bf2 100644 --- a/chrome/browser/autofill/autofill_interactive_uitest.cc +++ b/chrome/browser/autofill/autofill_interactive_uitest.cc @@ -19,7 +19,6 @@ #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/profiles/profile.h" -#include "chrome/browser/translate/translate_infobar_delegate.h" #include "chrome/browser/translate/translate_service.h" #include "chrome/browser/translate/translate_tab_helper.h" #include "chrome/browser/ui/browser.h" @@ -40,6 +39,7 @@ #include "components/infobars/core/confirm_infobar_delegate.h" #include "components/infobars/core/infobar.h" #include "components/infobars/core/infobar_manager.h" +#include "components/translate/core/browser/translate_infobar_delegate.h" #include "content/public/browser/navigation_controller.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" diff --git a/chrome/browser/policy/policy_browsertest.cc b/chrome/browser/policy/policy_browsertest.cc index 8ef2caa..c3ccb92 100644 --- a/chrome/browser/policy/policy_browsertest.cc +++ b/chrome/browser/policy/policy_browsertest.cc @@ -57,7 +57,6 @@ #include "chrome/browser/search_engines/template_url_service.h" #include "chrome/browser/search_engines/template_url_service_factory.h" #include "chrome/browser/translate/translate_browser_test_utils.h" -#include "chrome/browser/translate/translate_infobar_delegate.h" #include "chrome/browser/translate/translate_service.h" #include "chrome/browser/translate/translate_tab_helper.h" #include "chrome/browser/ui/bookmarks/bookmark_bar.h" @@ -89,6 +88,7 @@ #include "components/policy/core/common/policy_pref_names.h" #include "components/policy/core/common/policy_service.h" #include "components/policy/core/common/policy_service_impl.h" +#include "components/translate/core/browser/translate_infobar_delegate.h" #include "content/public/browser/browser_child_process_host_iterator.h" #include "content/public/browser/browser_context.h" #include "content/public/browser/browser_thread.h" diff --git a/chrome/browser/translate/translate_browsertest.cc b/chrome/browser/translate/translate_browsertest.cc index d24840f..0f2c02b 100644 --- a/chrome/browser/translate/translate_browsertest.cc +++ b/chrome/browser/translate/translate_browsertest.cc @@ -8,7 +8,6 @@ #include "base/strings/utf_string_conversions.h" #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/infobars/infobar_service.h" -#include "chrome/browser/translate/translate_infobar_delegate.h" #include "chrome/browser/translate/translate_service.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/tabs/tab_strip_model.h" @@ -16,6 +15,7 @@ #include "chrome/test/base/test_switches.h" #include "chrome/test/base/ui_test_utils.h" #include "components/infobars/core/infobar.h" +#include "components/translate/core/browser/translate_infobar_delegate.h" #include "components/translate/core/browser/translate_manager.h" #include "components/translate/core/browser/translate_script.h" #include "components/translate/core/common/translate_switches.h" diff --git a/chrome/browser/translate/translate_manager_render_view_host_unittest.cc b/chrome/browser/translate/translate_manager_render_view_host_unittest.cc index db74fe4..8e9d444 100644 --- a/chrome/browser/translate/translate_manager_render_view_host_unittest.cc +++ b/chrome/browser/translate/translate_manager_render_view_host_unittest.cc @@ -15,7 +15,6 @@ #include "chrome/browser/extensions/test_extension_system.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_util.h" -#include "chrome/browser/translate/translate_infobar_delegate.h" #include "chrome/browser/translate/translate_service.h" #include "chrome/browser/translate/translate_tab_helper.h" #include "chrome/browser/ui/translate/translate_bubble_factory.h" @@ -31,6 +30,7 @@ #include "components/translate/content/common/translate_messages.h" #include "components/translate/core/browser/translate_accept_languages.h" #include "components/translate/core/browser/translate_download_manager.h" +#include "components/translate/core/browser/translate_infobar_delegate.h" #include "components/translate/core/browser/translate_language_list.h" #include "components/translate/core/browser/translate_manager.h" #include "components/translate/core/browser/translate_prefs.h" diff --git a/chrome/browser/translate/translate_tab_helper.cc b/chrome/browser/translate/translate_tab_helper.cc index 668e7f1..ac2190f 100644 --- a/chrome/browser/translate/translate_tab_helper.cc +++ b/chrome/browser/translate/translate_tab_helper.cc @@ -13,7 +13,6 @@ #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/translate/translate_accept_languages_factory.h" -#include "chrome/browser/translate/translate_infobar_delegate.h" #include "chrome/browser/translate/translate_service.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_finder.h" @@ -26,6 +25,7 @@ #include "components/translate/core/browser/page_translated_details.h" #include "components/translate/core/browser/translate_accept_languages.h" #include "components/translate/core/browser/translate_download_manager.h" +#include "components/translate/core/browser/translate_infobar_delegate.h" #include "components/translate/core/browser/translate_manager.h" #include "components/translate/core/browser/translate_prefs.h" #include "components/translate/core/common/language_detection_details.h" @@ -34,6 +34,7 @@ #include "content/public/browser/notification_service.h" #include "content/public/browser/render_view_host.h" #include "content/public/browser/web_contents.h" +#include "grit/theme_resources.h" #include "net/http/http_status_code.h" #include "url/gurl.h" @@ -209,6 +210,13 @@ TranslateAcceptLanguages* TranslateTabHelper::GetTranslateAcceptLanguages() { return GetTranslateAcceptLanguages(web_contents()->GetBrowserContext()); } +int TranslateTabHelper::GetInfobarIconID() const { + return IDR_INFOBAR_TRANSLATE; +} + +// TranslateTabHelper::CreateInfoBar() is implemented in platform-specific +// files. + bool TranslateTabHelper::IsTranslatableURL(const GURL& url) { return TranslateService::IsTranslatableURL(url); } diff --git a/chrome/browser/translate/translate_tab_helper.h b/chrome/browser/translate/translate_tab_helper.h index d497cbd..cab6239 100644 --- a/chrome/browser/translate/translate_tab_helper.h +++ b/chrome/browser/translate/translate_tab_helper.h @@ -92,6 +92,9 @@ class TranslateTabHelper virtual PrefService* GetPrefs() OVERRIDE; virtual scoped_ptr<TranslatePrefs> GetTranslatePrefs() OVERRIDE; virtual TranslateAcceptLanguages* GetTranslateAcceptLanguages() OVERRIDE; + virtual int GetInfobarIconID() const OVERRIDE; + virtual scoped_ptr<infobars::InfoBar> CreateInfoBar( + scoped_ptr<TranslateInfoBarDelegate> delegate) const OVERRIDE; virtual void ShowTranslateUI(translate::TranslateStep step, const std::string source_language, const std::string target_language, diff --git a/chrome/browser/ui/android/infobars/infobar_android.cc b/chrome/browser/ui/android/infobars/infobar_android.cc index dcf30eb..544e6ee2 100644 --- a/chrome/browser/ui/android/infobars/infobar_android.cc +++ b/chrome/browser/ui/android/infobars/infobar_android.cc @@ -14,18 +14,6 @@ #include "jni/InfoBar_jni.h" -// InfoBar -------------------------------------------------------------------- - -// Static constants defined in infobar.h. We don't really use them for anything -// but they are required. The values are copied from the GTK implementation. -const int infobars::InfoBar::kSeparatorLineHeight = 1; -const int infobars::InfoBar::kDefaultArrowTargetHeight = 9; -const int infobars::InfoBar::kMaximumArrowTargetHeight = 24; -const int infobars::InfoBar::kDefaultArrowTargetHalfWidth = - kDefaultArrowTargetHeight; -const int infobars::InfoBar::kMaximumArrowTargetHalfWidth = 14; -const int infobars::InfoBar::kDefaultBarTargetHeight = 36; - // InfoBarAndroid ------------------------------------------------------------- InfoBarAndroid::InfoBarAndroid(scoped_ptr<infobars::InfoBarDelegate> delegate) diff --git a/chrome/browser/ui/android/infobars/translate_infobar.cc b/chrome/browser/ui/android/infobars/translate_infobar.cc index ab53bdb..f1dd161 100644 --- a/chrome/browser/ui/android/infobars/translate_infobar.cc +++ b/chrome/browser/ui/android/infobars/translate_infobar.cc @@ -7,17 +7,17 @@ #include "base/android/jni_android.h" #include "base/android/jni_array.h" #include "base/android/jni_weak_ref.h" -#include "chrome/browser/translate/translate_infobar_delegate.h" +#include "chrome/browser/translate/translate_tab_helper.h" +#include "components/translate/core/browser/translate_infobar_delegate.h" #include "grit/generated_resources.h" #include "jni/TranslateInfoBarDelegate_jni.h" #include "ui/base/l10n/l10n_util.h" -// TranslateInfoBarDelegate --------------------------------------------------- +// TranslateTabHelper ---------------------------------------------------------- -// static -scoped_ptr<infobars::InfoBar> TranslateInfoBarDelegate::CreateInfoBar( - scoped_ptr<TranslateInfoBarDelegate> delegate) { +scoped_ptr<infobars::InfoBar> TranslateTabHelper::CreateInfoBar( + scoped_ptr<TranslateInfoBarDelegate> delegate) const { return scoped_ptr<infobars::InfoBar>(new TranslateInfoBar(delegate.Pass())); } diff --git a/chrome/browser/ui/cocoa/infobars/translate_infobar_base.h b/chrome/browser/ui/cocoa/infobars/translate_infobar_base.h index 87256c7..d975f66 100644 --- a/chrome/browser/ui/cocoa/infobars/translate_infobar_base.h +++ b/chrome/browser/ui/cocoa/infobars/translate_infobar_base.h @@ -9,9 +9,9 @@ #import "base/mac/scoped_nsobject.h" #include "base/memory/scoped_ptr.h" -#include "chrome/browser/translate/options_menu_model.h" -#include "chrome/browser/translate/translate_infobar_delegate.h" #import "chrome/browser/ui/cocoa/infobars/infobar_controller.h" +#include "components/translate/core/browser/options_menu_model.h" +#include "components/translate/core/browser/translate_infobar_delegate.h" #include "components/translate/core/common/translate_errors.h" // The base class for the three translate infobars. This class does all of the diff --git a/chrome/browser/ui/cocoa/infobars/translate_infobar_base.mm b/chrome/browser/ui/cocoa/infobars/translate_infobar_base.mm index b5be91b5..331b3dd 100644 --- a/chrome/browser/ui/cocoa/infobars/translate_infobar_base.mm +++ b/chrome/browser/ui/cocoa/infobars/translate_infobar_base.mm @@ -7,7 +7,7 @@ #include "base/logging.h" #include "base/strings/sys_string_conversions.h" #include "chrome/app/chrome_command_ids.h" -#include "chrome/browser/translate/translate_infobar_delegate.h" +#import "chrome/browser/translate/translate_tab_helper.h" #import "chrome/browser/ui/cocoa/hover_close_button.h" #include "chrome/browser/ui/cocoa/infobars/after_translate_infobar_controller.h" #import "chrome/browser/ui/cocoa/infobars/before_translate_infobar_controller.h" @@ -17,6 +17,7 @@ #import "chrome/browser/ui/cocoa/infobars/infobar_gradient_view.h" #import "chrome/browser/ui/cocoa/infobars/infobar_utilities.h" #include "chrome/browser/ui/cocoa/infobars/translate_message_infobar_controller.h" +#include "components/translate/core/browser/translate_infobar_delegate.h" #include "grit/components_strings.h" #include "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTweaker.h" #include "ui/base/l10n/l10n_util.h" @@ -27,9 +28,8 @@ using InfoBarUtilities::VerifyControlOrderAndSpacing; using InfoBarUtilities::CreateLabel; using InfoBarUtilities::AddMenuItem; -// static -scoped_ptr<infobars::InfoBar> TranslateInfoBarDelegate::CreateInfoBar( - scoped_ptr<TranslateInfoBarDelegate> delegate) { +scoped_ptr<infobars::InfoBar> TranslateTabHelper::CreateInfoBar( + scoped_ptr<TranslateInfoBarDelegate> delegate) const { scoped_ptr<InfoBarCocoa> infobar( new InfoBarCocoa(delegate.PassAs<infobars::InfoBarDelegate>())); base::scoped_nsobject<TranslateInfoBarControllerBase> infobar_controller; diff --git a/chrome/browser/ui/cocoa/infobars/translate_infobar_unittest.mm b/chrome/browser/ui/cocoa/infobars/translate_infobar_unittest.mm index a0463a7..8d8234f 100644 --- a/chrome/browser/ui/cocoa/infobars/translate_infobar_unittest.mm +++ b/chrome/browser/ui/cocoa/infobars/translate_infobar_unittest.mm @@ -7,15 +7,15 @@ #import "base/mac/scoped_nsobject.h" #import "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" -#import "chrome/app/chrome_command_ids.h" // For translate menu command ids. #include "chrome/browser/infobars/infobar_service.h" -#import "chrome/browser/translate/translate_infobar_delegate.h" #import "chrome/browser/translate/translate_tab_helper.h" #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" #import "chrome/browser/ui/cocoa/infobars/before_translate_infobar_controller.h" #import "chrome/browser/ui/cocoa/infobars/infobar_cocoa.h" #import "chrome/browser/ui/cocoa/infobars/translate_infobar_base.h" #include "chrome/test/base/testing_profile.h" +#import "components/translate/core/browser/options_menu_model.h" +#import "components/translate/core/browser/translate_infobar_delegate.h" #include "components/translate/core/browser/translate_language_list.h" #include "components/translate/core/browser/translate_manager.h" #import "content/public/browser/web_contents.h" @@ -96,10 +96,12 @@ class TranslationInfoBarTest : public CocoaProfileTest { error = TranslateErrors::NETWORK; [[infobar_controller_ view] removeFromSuperview]; + TranslateTabHelper* translate_tab_helper = + TranslateTabHelper::FromWebContents(web_contents_.get()); scoped_ptr<TranslateInfoBarDelegate> delegate( new MockTranslateInfoBarDelegate(web_contents_.get(), type, error)); scoped_ptr<infobars::InfoBar> infobar( - TranslateInfoBarDelegate::CreateInfoBar(delegate.Pass())); + translate_tab_helper->CreateInfoBar(delegate.Pass())); if (infobar_) infobar_->CloseSoon(); infobar_ = static_cast<InfoBarCocoa*>(infobar.release()); @@ -203,9 +205,9 @@ TEST_F(TranslationInfoBarTest, OptionsMenuItemsHookedUp) { { // Can't mock these effectively, so just check that the tag is set // correctly. - EXPECT_EQ(IDC_TRANSLATE_REPORT_BAD_LANGUAGE_DETECTION, + EXPECT_EQ(OptionsMenuModel::REPORT_BAD_DETECTION, [reportBadLanguageItem tag]); - EXPECT_EQ(IDC_TRANSLATE_OPTIONS_ABOUT, [aboutTranslateItem tag]); + EXPECT_EQ(OptionsMenuModel::ABOUT_TRANSLATE, [aboutTranslateItem tag]); } } diff --git a/chrome/browser/ui/views/infobars/after_translate_infobar.cc b/chrome/browser/ui/views/infobars/after_translate_infobar.cc index afbaf2c..babeaaa 100644 --- a/chrome/browser/ui/views/infobars/after_translate_infobar.cc +++ b/chrome/browser/ui/views/infobars/after_translate_infobar.cc @@ -5,9 +5,9 @@ #include "chrome/browser/ui/views/infobars/after_translate_infobar.h" #include "base/strings/utf_string_conversions.h" -#include "chrome/browser/translate/options_menu_model.h" -#include "chrome/browser/translate/translate_infobar_delegate.h" #include "chrome/browser/ui/views/infobars/translate_language_menu_model.h" +#include "components/translate/core/browser/options_menu_model.h" +#include "components/translate/core/browser/translate_infobar_delegate.h" #include "grit/components_strings.h" #include "ui/base/l10n/l10n_util.h" #include "ui/views/controls/button/label_button.h" diff --git a/chrome/browser/ui/views/infobars/before_translate_infobar.cc b/chrome/browser/ui/views/infobars/before_translate_infobar.cc index a4ee273..085bb9b 100644 --- a/chrome/browser/ui/views/infobars/before_translate_infobar.cc +++ b/chrome/browser/ui/views/infobars/before_translate_infobar.cc @@ -5,9 +5,9 @@ #include "chrome/browser/ui/views/infobars/before_translate_infobar.h" #include "base/strings/utf_string_conversions.h" -#include "chrome/browser/translate/options_menu_model.h" -#include "chrome/browser/translate/translate_infobar_delegate.h" #include "chrome/browser/ui/views/infobars/translate_language_menu_model.h" +#include "components/translate/core/browser/options_menu_model.h" +#include "components/translate/core/browser/translate_infobar_delegate.h" #include "grit/components_strings.h" #include "ui/base/l10n/l10n_util.h" #include "ui/views/controls/button/label_button.h" diff --git a/chrome/browser/ui/views/infobars/translate_infobar_base.cc b/chrome/browser/ui/views/infobars/translate_infobar_base.cc index 5227ce0..5f1a753 100644 --- a/chrome/browser/ui/views/infobars/translate_infobar_base.cc +++ b/chrome/browser/ui/views/infobars/translate_infobar_base.cc @@ -5,12 +5,12 @@ #include "chrome/browser/ui/views/infobars/translate_infobar_base.h" #include "base/strings/utf_string_conversions.h" -#include "chrome/browser/translate/translate_infobar_delegate.h" #include "chrome/browser/translate/translate_tab_helper.h" #include "chrome/browser/ui/views/infobars/after_translate_infobar.h" #include "chrome/browser/ui/views/infobars/before_translate_infobar.h" #include "chrome/browser/ui/views/infobars/translate_message_infobar.h" #include "components/infobars/core/infobar.h" +#include "components/translate/core/browser/translate_infobar_delegate.h" #include "grit/theme_resources.h" #include "ui/base/resource/resource_bundle.h" #include "ui/gfx/animation/slide_animation.h" @@ -19,11 +19,10 @@ #include "ui/views/controls/label.h" -// TranslateInfoBarDelegate --------------------------------------------------- +// TranslateTabHelper ---------------------------------------------------------- -// static -scoped_ptr<infobars::InfoBar> TranslateInfoBarDelegate::CreateInfoBar( - scoped_ptr<TranslateInfoBarDelegate> delegate) { +scoped_ptr<infobars::InfoBar> TranslateTabHelper::CreateInfoBar( + scoped_ptr<TranslateInfoBarDelegate> delegate) const { if (delegate->translate_step() == translate::TRANSLATE_STEP_BEFORE_TRANSLATE) { return scoped_ptr<infobars::InfoBar>( diff --git a/chrome/browser/ui/views/infobars/translate_language_menu_model.cc b/chrome/browser/ui/views/infobars/translate_language_menu_model.cc index 6c2ae66..ab15d64 100644 --- a/chrome/browser/ui/views/infobars/translate_language_menu_model.cc +++ b/chrome/browser/ui/views/infobars/translate_language_menu_model.cc @@ -4,8 +4,8 @@ #include "chrome/browser/ui/views/infobars/translate_language_menu_model.h" -#include "chrome/browser/translate/translate_infobar_delegate.h" #include "chrome/browser/ui/views/infobars/translate_infobar_base.h" +#include "components/translate/core/browser/translate_infobar_delegate.h" TranslateLanguageMenuModel::TranslateLanguageMenuModel( LanguageType language_type, diff --git a/chrome/browser/ui/views/infobars/translate_message_infobar.cc b/chrome/browser/ui/views/infobars/translate_message_infobar.cc index f4d02f1..4d284c6 100644 --- a/chrome/browser/ui/views/infobars/translate_message_infobar.cc +++ b/chrome/browser/ui/views/infobars/translate_message_infobar.cc @@ -4,7 +4,7 @@ #include "chrome/browser/ui/views/infobars/translate_message_infobar.h" -#include "chrome/browser/translate/translate_infobar_delegate.h" +#include "components/translate/core/browser/translate_infobar_delegate.h" #include "ui/views/controls/button/label_button.h" #include "ui/views/controls/label.h" diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index e0e51e5..0f4ae5a 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -2522,12 +2522,8 @@ 'browser/thumbnails/thumbnailing_algorithm.h', 'browser/thumbnails/thumbnailing_context.cc', 'browser/thumbnails/thumbnailing_context.h', - 'browser/translate/options_menu_model.cc', - 'browser/translate/options_menu_model.h', 'browser/translate/translate_accept_languages_factory.cc', 'browser/translate/translate_accept_languages_factory.h', - 'browser/translate/translate_infobar_delegate.cc', - 'browser/translate/translate_infobar_delegate.h', 'browser/translate/translate_service.cc', 'browser/translate/translate_service.h', 'browser/translate/translate_tab_helper.cc', diff --git a/components/infobars.gypi b/components/infobars.gypi index 07522b9..cb9c2b1 100644 --- a/components/infobars.gypi +++ b/components/infobars.gypi @@ -21,6 +21,7 @@ 'infobars/core/confirm_infobar_delegate.h', 'infobars/core/infobar.cc', 'infobars/core/infobar.h', + 'infobars/core/infobar_android.cc', 'infobars/core/infobar_container.cc', 'infobars/core/infobar_container.h', 'infobars/core/infobar_delegate.cc', diff --git a/components/infobars/core/infobar_android.cc b/components/infobars/core/infobar_android.cc new file mode 100644 index 0000000..60258f8 --- /dev/null +++ b/components/infobars/core/infobar_android.cc @@ -0,0 +1,15 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "components/infobars/core/infobar.h" + +// Static constants defined in infobar.h. We don't really use them for anything +// but they are required. The values are copied from the GTK implementation. +const int infobars::InfoBar::kSeparatorLineHeight = 1; +const int infobars::InfoBar::kDefaultArrowTargetHeight = 9; +const int infobars::InfoBar::kMaximumArrowTargetHeight = 24; +const int infobars::InfoBar::kDefaultArrowTargetHalfWidth = + kDefaultArrowTargetHeight; +const int infobars::InfoBar::kMaximumArrowTargetHalfWidth = 14; +const int infobars::InfoBar::kDefaultBarTargetHeight = 36; diff --git a/components/translate.gypi b/components/translate.gypi index 00ec959..5a15611 100644 --- a/components/translate.gypi +++ b/components/translate.gypi @@ -9,11 +9,14 @@ 'type': 'static_library', 'dependencies': [ '../base/base.gyp:base', + '../base/base.gyp:base_i18n', '../google_apis/google_apis.gyp:google_apis', '../net/net.gyp:net', '../ui/base/ui_base.gyp:ui_base', '../url/url.gyp:url_lib', 'components_resources.gyp:components_resources', + 'components_strings.gyp:components_strings', + 'infobars_core', 'language_usage_metrics', 'pref_registry', 'translate_core_common', @@ -24,6 +27,8 @@ 'sources': [ 'translate/core/browser/language_state.cc', 'translate/core/browser/language_state.h', + 'translate/core/browser/options_menu_model.cc', + 'translate/core/browser/options_menu_model.h', 'translate/core/browser/page_translated_details.h', 'translate/core/browser/translate_accept_languages.cc', 'translate/core/browser/translate_accept_languages.h', @@ -36,6 +41,8 @@ 'translate/core/browser/translate_error_details.h', 'translate/core/browser/translate_event_details.cc', 'translate/core/browser/translate_event_details.h', + 'translate/core/browser/translate_infobar_delegate.cc', + 'translate/core/browser/translate_infobar_delegate.h', 'translate/core/browser/translate_language_list.cc', 'translate/core/browser/translate_language_list.h', 'translate/core/browser/translate_manager.cc', diff --git a/components/translate/DEPS b/components/translate/DEPS index e13509a..2497825 100644 --- a/components/translate/DEPS +++ b/components/translate/DEPS @@ -1,4 +1,5 @@ include_rules = [ + "+components/infobars", "+components/language_usage_metrics", "+components/pref_registry", "+google_apis", diff --git a/chrome/browser/translate/options_menu_model.cc b/components/translate/core/browser/options_menu_model.cc index 19fc5c2..1bed639 100644 --- a/chrome/browser/translate/options_menu_model.cc +++ b/components/translate/core/browser/options_menu_model.cc @@ -1,15 +1,13 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/translate/options_menu_model.h" +#include "components/translate/core/browser/options_menu_model.h" #include "base/metrics/histogram.h" -#include "chrome/app/chrome_command_ids.h" -#include "chrome/browser/translate/translate_infobar_delegate.h" #include "components/translate/core/browser/translate_driver.h" +#include "components/translate/core/browser/translate_infobar_delegate.h" #include "grit/components_strings.h" -#include "grit/locale_settings.h" #include "ui/base/l10n/l10n_util.h" namespace { @@ -23,8 +21,7 @@ const char kAboutGoogleTranslateURL[] = } // namespace -OptionsMenuModel::OptionsMenuModel( - TranslateInfoBarDelegate* translate_delegate) +OptionsMenuModel::OptionsMenuModel(TranslateInfoBarDelegate* translate_delegate) : ui::SimpleMenuModel(this), translate_infobar_delegate_(translate_delegate) { // |translate_delegate| must already be owned. @@ -43,26 +40,25 @@ OptionsMenuModel::OptionsMenuModel( // Incognito mode does not get any preferences related items. if (!translate_delegate->is_off_the_record()) { if (!autodetermined_source_language) { - AddCheckItem(IDC_TRANSLATE_OPTIONS_ALWAYS, + AddCheckItem(ALWAYS_TRANSLATE, l10n_util::GetStringFUTF16(IDS_TRANSLATE_INFOBAR_OPTIONS_ALWAYS, original_language, target_language)); - AddCheckItem(IDC_TRANSLATE_OPTIONS_NEVER_TRANSLATE_LANG, - l10n_util::GetStringFUTF16( - IDS_TRANSLATE_INFOBAR_OPTIONS_NEVER_TRANSLATE_LANG, - original_language)); + AddCheckItem(NEVER_TRANSLATE_LANGUAGE, + l10n_util::GetStringFUTF16( + IDS_TRANSLATE_INFOBAR_OPTIONS_NEVER_TRANSLATE_LANG, + original_language)); } - AddCheckItem(IDC_TRANSLATE_OPTIONS_NEVER_TRANSLATE_SITE, - l10n_util::GetStringUTF16( - IDS_TRANSLATE_INFOBAR_OPTIONS_NEVER_TRANSLATE_SITE)); + AddCheckItem(NEVER_TRANSLATE_SITE, + l10n_util::GetStringUTF16( + IDS_TRANSLATE_INFOBAR_OPTIONS_NEVER_TRANSLATE_SITE)); AddSeparator(ui::NORMAL_SEPARATOR); } if (!autodetermined_source_language) { - AddItem(IDC_TRANSLATE_REPORT_BAD_LANGUAGE_DETECTION, + AddItem(REPORT_BAD_DETECTION, l10n_util::GetStringFUTF16(IDS_TRANSLATE_INFOBAR_OPTIONS_REPORT_ERROR, original_language)); } - AddItemWithStringId(IDC_TRANSLATE_OPTIONS_ABOUT, - IDS_TRANSLATE_INFOBAR_OPTIONS_ABOUT); + AddItemWithStringId(ABOUT_TRANSLATE, IDS_TRANSLATE_INFOBAR_OPTIONS_ABOUT); } OptionsMenuModel::~OptionsMenuModel() { @@ -70,13 +66,13 @@ OptionsMenuModel::~OptionsMenuModel() { bool OptionsMenuModel::IsCommandIdChecked(int command_id) const { switch (command_id) { - case IDC_TRANSLATE_OPTIONS_NEVER_TRANSLATE_LANG: + case NEVER_TRANSLATE_LANGUAGE: return !translate_infobar_delegate_->IsTranslatableLanguageByPrefs(); - case IDC_TRANSLATE_OPTIONS_NEVER_TRANSLATE_SITE: + case NEVER_TRANSLATE_SITE: return translate_infobar_delegate_->IsSiteBlacklisted(); - case IDC_TRANSLATE_OPTIONS_ALWAYS: + case ALWAYS_TRANSLATE: return translate_infobar_delegate_->ShouldAlwaysTranslate(); default: @@ -88,11 +84,11 @@ bool OptionsMenuModel::IsCommandIdChecked(int command_id) const { bool OptionsMenuModel::IsCommandIdEnabled(int command_id) const { switch (command_id) { - case IDC_TRANSLATE_OPTIONS_NEVER_TRANSLATE_LANG : - case IDC_TRANSLATE_OPTIONS_NEVER_TRANSLATE_SITE : + case NEVER_TRANSLATE_LANGUAGE: + case NEVER_TRANSLATE_SITE: return !translate_infobar_delegate_->ShouldAlwaysTranslate(); - case IDC_TRANSLATE_OPTIONS_ALWAYS : + case ALWAYS_TRANSLATE: return (translate_infobar_delegate_->IsTranslatableLanguageByPrefs() && !translate_infobar_delegate_->IsSiteBlacklisted()); @@ -103,29 +99,30 @@ bool OptionsMenuModel::IsCommandIdEnabled(int command_id) const { } bool OptionsMenuModel::GetAcceleratorForCommandId( - int command_id, ui::Accelerator* accelerator) { + int command_id, + ui::Accelerator* accelerator) { return false; } void OptionsMenuModel::ExecuteCommand(int command_id, int event_flags) { switch (command_id) { - case IDC_TRANSLATE_OPTIONS_NEVER_TRANSLATE_LANG: + case NEVER_TRANSLATE_LANGUAGE: translate_infobar_delegate_->ToggleTranslatableLanguageByPrefs(); break; - case IDC_TRANSLATE_OPTIONS_NEVER_TRANSLATE_SITE: + case NEVER_TRANSLATE_SITE: translate_infobar_delegate_->ToggleSiteBlacklist(); break; - case IDC_TRANSLATE_OPTIONS_ALWAYS: + case ALWAYS_TRANSLATE: translate_infobar_delegate_->ToggleAlwaysTranslate(); break; - case IDC_TRANSLATE_REPORT_BAD_LANGUAGE_DETECTION: + case REPORT_BAD_DETECTION: translate_infobar_delegate_->ReportLanguageDetectionError(); break; - case IDC_TRANSLATE_OPTIONS_ABOUT: { + case ABOUT_TRANSLATE: { TranslateDriver* translate_driver = translate_infobar_delegate_->GetTranslateDriver(); if (translate_driver) diff --git a/chrome/browser/translate/options_menu_model.h b/components/translate/core/browser/options_menu_model.h index f178ca1..7cb65b8 100644 --- a/chrome/browser/translate/options_menu_model.h +++ b/components/translate/core/browser/options_menu_model.h @@ -1,9 +1,9 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_TRANSLATE_OPTIONS_MENU_MODEL_H_ -#define CHROME_BROWSER_TRANSLATE_OPTIONS_MENU_MODEL_H_ +#ifndef COMPONENTS_TRANSLATE_CORE_BROWSER_OPTIONS_MENU_MODEL_H_ +#define COMPONENTS_TRANSLATE_CORE_BROWSER_OPTIONS_MENU_MODEL_H_ #include "ui/base/models/simple_menu_model.h" @@ -14,6 +14,15 @@ class TranslateInfoBarDelegate; class OptionsMenuModel : public ui::SimpleMenuModel, public ui::SimpleMenuModel::Delegate { public: + // Command IDs of the items in this menu; exposed for testing. + enum CommandID { + ABOUT_TRANSLATE = 0, + ALWAYS_TRANSLATE, + NEVER_TRANSLATE_LANGUAGE, + NEVER_TRANSLATE_SITE, + REPORT_BAD_DETECTION + }; + explicit OptionsMenuModel(TranslateInfoBarDelegate* translate_delegate); virtual ~OptionsMenuModel(); @@ -31,4 +40,4 @@ class OptionsMenuModel : public ui::SimpleMenuModel, DISALLOW_COPY_AND_ASSIGN(OptionsMenuModel); }; -#endif // CHROME_BROWSER_TRANSLATE_OPTIONS_MENU_MODEL_H_ +#endif // COMPONENTS_TRANSLATE_CORE_BROWSER_OPTIONS_MENU_MODEL_H_ diff --git a/components/translate/core/browser/translate_client.h b/components/translate/core/browser/translate_client.h index 6a2c377..38fcdea 100644 --- a/components/translate/core/browser/translate_client.h +++ b/components/translate/core/browser/translate_client.h @@ -8,6 +8,7 @@ #include <string> #include "base/memory/ref_counted.h" +#include "base/memory/scoped_ptr.h" #include "components/translate/core/browser/translate_prefs.h" #include "components/translate/core/browser/translate_step.h" #include "components/translate/core/common/translate_errors.h" @@ -16,6 +17,11 @@ class GURL; class PrefService; class TranslateAcceptLanguages; class TranslateDriver; +class TranslateInfoBarDelegate; + +namespace infobars { +class InfoBar; +} // A client interface that needs to be supplied to TranslateManager by the // embedder. @@ -36,6 +42,13 @@ class TranslateClient { // Returns the associated TranslateAcceptLanguages. virtual TranslateAcceptLanguages* GetTranslateAcceptLanguages() = 0; + // Returns the resource ID of the icon to be shown for the Translate infobars. + virtual int GetInfobarIconID() const = 0; + + // Returns a translate infobar that owns |delegate|. + virtual scoped_ptr<infobars::InfoBar> CreateInfoBar( + scoped_ptr<TranslateInfoBarDelegate> delegate) const = 0; + // Called when the embedder should present UI to the user corresponding to the // user's current |step|. virtual void ShowTranslateUI(translate::TranslateStep step, diff --git a/chrome/browser/translate/translate_infobar_delegate.cc b/components/translate/core/browser/translate_infobar_delegate.cc index db277ad..69ff12a 100644 --- a/chrome/browser/translate/translate_infobar_delegate.cc +++ b/components/translate/core/browser/translate_infobar_delegate.cc @@ -1,8 +1,8 @@ -// Copyright 2012 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/translate/translate_infobar_delegate.h" +#include "components/translate/core/browser/translate_infobar_delegate.h" #include <algorithm> @@ -18,8 +18,6 @@ #include "components/translate/core/browser/translate_manager.h" #include "components/translate/core/common/translate_constants.h" #include "grit/components_strings.h" -#include "grit/theme_resources.h" -#include "third_party/icu/source/i18n/unicode/coll.h" #include "ui/base/l10n/l10n_util.h" namespace { @@ -29,17 +27,17 @@ namespace { // so we are more aggressive about showing the shortcut to never translate. // The "Always Translate" option is always shown on iOS and Android. #if defined(OS_ANDROID) - const int kAlwaysTranslateMinCount = 1; - const int kNeverTranslateMinCount = 1; +const int kAlwaysTranslateMinCount = 1; +const int kNeverTranslateMinCount = 1; #elif defined(OS_IOS) - // The iOS implementation, like the Android implementation, shows the "Never - // translate" infobar after two denials. There is an offset of one because on - // Android the last event is not counted. - const int kAlwaysTranslateMinCount = 1; - const int kNeverTranslateMinCount = 2; +// The iOS implementation, like the Android implementation, shows the "Never +// translate" infobar after two denials. There is an offset of one because on +// Android the last event is not counted. +const int kAlwaysTranslateMinCount = 1; +const int kNeverTranslateMinCount = 2; #else - const int kAlwaysTranslateMinCount = 3; - const int kNeverTranslateMinCount = 3; +const int kAlwaysTranslateMinCount = 3; +const int kNeverTranslateMinCount = 3; #endif } // namespace @@ -77,10 +75,11 @@ void TranslateInfoBarDelegate::Create( } // Do not create the after translate infobar if we are auto translating. + TranslateClient* translate_client = translate_manager->translate_client(); if (((step == translate::TRANSLATE_STEP_AFTER_TRANSLATE) || (step == translate::TRANSLATE_STEP_TRANSLATING)) && - translate_manager->translate_client()->GetTranslateDriver() - ->GetLanguageState().InTranslateNavigation()) { + translate_client->GetTranslateDriver()->GetLanguageState() + .InTranslateNavigation()) { return; } @@ -98,7 +97,7 @@ void TranslateInfoBarDelegate::Create( } // Add the new delegate. - scoped_ptr<infobars::InfoBar> infobar(CreateInfoBar( + scoped_ptr<infobars::InfoBar> infobar(translate_client->CreateInfoBar( scoped_ptr<TranslateInfoBarDelegate>(new TranslateInfoBarDelegate( translate_manager, is_off_the_record, step, old_delegate, original_language, target_language, error_type, @@ -109,7 +108,6 @@ void TranslateInfoBarDelegate::Create( infobar_manager->AddInfoBar(infobar.Pass()); } - void TranslateInfoBarDelegate::UpdateOriginalLanguageIndex( size_t language_index) { ui_delegate_.UpdateOriginalLanguageIndex(language_index); @@ -139,7 +137,7 @@ void TranslateInfoBarDelegate::TranslationDeclined() { } bool TranslateInfoBarDelegate::IsTranslatableLanguageByPrefs() { - TranslateClient* client = GetTranslateClient(); + TranslateClient* client = translate_manager_->translate_client(); scoped_ptr<TranslatePrefs> translate_prefs(client->GetTranslatePrefs()); TranslateAcceptLanguages* accept_languages = client->GetTranslateAcceptLanguages(); @@ -186,7 +184,7 @@ void TranslateInfoBarDelegate::AlwaysTranslatePageLanguage() { void TranslateInfoBarDelegate::NeverTranslatePageLanguage() { DCHECK(!ui_delegate_.IsLanguageBlocked()); ui_delegate_.SetLanguageBlocked(true); - infobar()->RemoveSelf(); + infobar()->RemoveSelf(); } base::string16 TranslateInfoBarDelegate::GetMessageInfoBarText() { @@ -340,16 +338,6 @@ TranslateInfoBarDelegate::TranslateInfoBarDelegate( background_animation_ = is_error() ? NORMAL_TO_ERROR : ERROR_TO_NORMAL; } -TranslateClient* TranslateInfoBarDelegate::GetTranslateClient() { - if (!translate_manager_) - return NULL; - - return translate_manager_->translate_client(); -} - -// TranslateInfoBarDelegate::CreateInfoBar() is implemented in platform-specific -// files. - void TranslateInfoBarDelegate::InfoBarDismissed() { if (step_ != translate::TRANSLATE_STEP_BEFORE_TRANSLATE) return; @@ -360,7 +348,7 @@ void TranslateInfoBarDelegate::InfoBarDismissed() { } int TranslateInfoBarDelegate::GetIconID() const { - return IDR_INFOBAR_TRANSLATE; + return translate_manager_->translate_client()->GetInfobarIconID(); } infobars::InfoBarDelegate::Type TranslateInfoBarDelegate::GetInfoBarType() diff --git a/chrome/browser/translate/translate_infobar_delegate.h b/components/translate/core/browser/translate_infobar_delegate.h index 5248e32..cf53825 100644 --- a/chrome/browser/translate/translate_infobar_delegate.h +++ b/components/translate/core/browser/translate_infobar_delegate.h @@ -1,9 +1,9 @@ -// Copyright 2011 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_TRANSLATE_TRANSLATE_INFOBAR_DELEGATE_H_ -#define CHROME_BROWSER_TRANSLATE_TRANSLATE_INFOBAR_DELEGATE_H_ +#ifndef COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_INFOBAR_DELEGATE_H_ +#define COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_INFOBAR_DELEGATE_H_ #include <string> #include <utility> @@ -189,14 +189,6 @@ class TranslateInfoBarDelegate : public infobars::InfoBarDelegate { friend class TranslationInfoBarTest; typedef std::pair<std::string, base::string16> LanguageNamePair; - // Returns a translate infobar that owns |delegate|. - static scoped_ptr<infobars::InfoBar> CreateInfoBar( - scoped_ptr<TranslateInfoBarDelegate> delegate); - - // Gets the TranslateClient associated with this object. - // May return NULL if the client has been destroyed. - TranslateClient* GetTranslateClient(); - // InfoBarDelegate: virtual void InfoBarDismissed() OVERRIDE; virtual int GetIconID() const OVERRIDE; @@ -226,4 +218,4 @@ class TranslateInfoBarDelegate : public infobars::InfoBarDelegate { DISALLOW_COPY_AND_ASSIGN(TranslateInfoBarDelegate); }; -#endif // CHROME_BROWSER_TRANSLATE_TRANSLATE_INFOBAR_DELEGATE_H_ +#endif // COMPONENTS_TRANSLATE_CORE_BROWSER_TRANSLATE_INFOBAR_DELEGATE_H_ |