1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_UI_GTK_INFOBARS_TRANSLATE_INFOBAR_BASE_GTK_H_ 6 #define CHROME_BROWSER_UI_GTK_INFOBARS_TRANSLATE_INFOBAR_BASE_GTK_H_ 7 #pragma once 8 9 #include "chrome/browser/ui/gtk/infobars/infobar_gtk.h" 10 #include "ui/base/animation/animation_delegate.h" 11 12 class MenuGtk; 13 class OptionsMenuModel; 14 class TranslateInfoBarDelegate; 15 16 // This class contains some of the base functionality that translate infobars 17 // use. 18 class TranslateInfoBarBase : public InfoBar, 19 public ui::AnimationDelegate { 20 public: 21 explicit TranslateInfoBarBase(TranslateInfoBarDelegate* delegate); 22 virtual ~TranslateInfoBarBase(); 23 24 // Initializes the infobar widgets. Should be called after the object has been 25 // created. 26 virtual void Init(); 27 28 // Overridden from InfoBar: 29 virtual void GetTopColor(InfoBarDelegate::Type type, 30 double* r, double* g, double *b); 31 virtual void GetBottomColor(InfoBarDelegate::Type type, 32 double* r, double* g, double *b); 33 34 // Overridden from ui::AnimationDelegate: 35 virtual void AnimationProgressed(const ui::Animation* animation); 36 37 protected: 38 // Sub-classes that want to have the options menu button showing sould 39 // override and return true. 40 virtual bool ShowOptionsMenuButton() const; 41 42 // Creates a label with the appropriate font and color for the translate 43 // infobars. 44 GtkWidget* CreateLabel(const std::string& text); 45 46 // Creates a combobox that displays the languages currently available. 47 // |selected_language| is the language index (as used in the 48 // TranslateInfoBarDelegate) that should be selected initially. 49 // |exclude_language| is the language index of the language that should not be 50 // included in the list (TranslateInfoBarDelegate::kNoIndex means no language 51 // excluded). 52 GtkWidget* CreateLanguageCombobox(size_t selected_language, 53 size_t exclude_language); 54 55 // Given an above-constructed combobox, returns the currently selected 56 // language id. 57 static size_t GetLanguageComboboxActiveId(GtkComboBox* combo); 58 59 // Convenience to retrieve the TranslateInfoBarDelegate for this infobar. 60 TranslateInfoBarDelegate* GetDelegate() const; 61 62 private: 63 // Builds a button with an arrow in it to emulate the menu-button style from 64 // the windows version. 65 static GtkWidget* BuildOptionsMenuButton(); 66 67 // The menu displayed when the Options button is pressed. 68 scoped_ptr<OptionsMenuModel> options_menu_model_; 69 scoped_ptr<MenuGtk> options_menu_menu_; 70 71 CHROMEGTK_CALLBACK_0(TranslateInfoBarBase, void, OnOptionsClicked); 72 73 // A percentage to average the normal page action background with the error 74 // background. When 0, the infobar background should be pure PAGE_ACTION_TYPE. 75 // When 1, the infobar background should be pure WARNING_TYPE. 76 double background_error_percent_; 77 78 // Changes the color of the background from normal to error color and back. 79 scoped_ptr<ui::SlideAnimation> background_color_animation_; 80 81 DISALLOW_COPY_AND_ASSIGN(TranslateInfoBarBase); 82 }; 83 84 #endif // CHROME_BROWSER_UI_GTK_INFOBARS_TRANSLATE_INFOBAR_BASE_GTK_H_ 85