Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2013 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_VIEWS_TRANSLATE_TRANSLATE_BUBBLE_VIEW_H_ | |
| 6 #define CHROME_BROWSER_UI_VIEWS_TRANSLATE_TRANSLATE_BUBBLE_VIEW_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/basictypes.h" | |
| 11 #include "chrome/browser/ui/translate/language_combobox_model.h" | |
| 12 #include "chrome/browser/ui/translate/translate_bubble_model.h" | |
| 13 #include "ui/views/bubble/bubble_delegate.h" | |
| 14 #include "ui/views/controls/button/button.h" | |
| 15 #include "ui/views/controls/combobox/combobox_listener.h" | |
| 16 #include "ui/views/controls/link_listener.h" | |
| 17 | |
| 18 class Browser; | |
| 19 class PrefService; | |
| 20 class TranslateBubbleModel; | |
| 21 | |
| 22 namespace content { | |
| 23 class WebContents; | |
| 24 } | |
| 25 | |
| 26 namespace views { | |
| 27 class Checkbox; | |
| 28 class GridLayout; | |
| 29 class LabelButton; | |
| 30 class Link; | |
| 31 class View; | |
| 32 } | |
| 33 | |
| 34 class TranslateBubbleView : public views::BubbleDelegateView, | |
| 35 public views::ButtonListener, | |
| 36 public views::ComboboxListener, | |
| 37 public views::LinkListener { | |
| 38 public: | |
| 39 // Shows the Translate bubble. | |
| 40 static void ShowBubble(views::View* anchor_view, | |
| 41 content::WebContents* web_contents, | |
| 42 TranslateBubbleModel::ViewState type, | |
| 43 Browser* browser); | |
| 44 | |
| 45 // If true, the Translate bubble is being shown. | |
| 46 static bool IsShowing(); | |
| 47 | |
| 48 virtual ~TranslateBubbleView(); | |
|
sky
2013/10/16 14:32:36
constructor is typically before destructor. Also,
hajimehoshi
2013/10/17 05:45:42
Done.
| |
| 49 | |
| 50 TranslateBubbleView(views::View* anchor_view, | |
| 51 scoped_ptr<TranslateBubbleModel> model, | |
| 52 bool is_in_incognito_window, | |
| 53 Browser* browser); | |
| 54 | |
| 55 // views::BubbleDelegateView methods. | |
| 56 virtual void Init() OVERRIDE; | |
| 57 virtual void ButtonPressed(views::Button* sender, | |
| 58 const ui::Event& event) OVERRIDE; | |
| 59 | |
| 60 // views::WidgetDelegate method. | |
| 61 virtual void WindowClosing() OVERRIDE; | |
| 62 | |
| 63 // views::View methods. | |
| 64 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; | |
| 65 virtual gfx::Size GetPreferredSize() OVERRIDE; | |
| 66 | |
| 67 // views::CombboxListener method. | |
| 68 virtual void OnSelectedIndexChanged(views::Combobox* combobox) OVERRIDE; | |
| 69 | |
| 70 // views::LinkListener method. | |
| 71 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE; | |
| 72 | |
| 73 // Returns the current view state. | |
| 74 TranslateBubbleModel::ViewState GetViewState() const; | |
| 75 | |
| 76 private: | |
| 77 enum LinkID { | |
| 78 LINK_ID_ADVANCED, | |
| 79 LINK_ID_LEARN_MORE, | |
| 80 }; | |
| 81 | |
| 82 enum ButtonID { | |
| 83 BUTTON_ID_TRANSLATE, | |
| 84 BUTTON_ID_DONE, | |
| 85 BUTTON_ID_CANCEL, | |
| 86 BUTTON_ID_SHOW_ORIGINAL, | |
| 87 BUTTON_ID_TRY_AGAIN, | |
| 88 BUTTON_ID_ALWAYS_TRANSLATE, | |
| 89 }; | |
| 90 | |
| 91 enum ComboboxID { | |
| 92 COMBOBOX_ID_DENIAL, | |
| 93 COMBOBOX_ID_SOURCE_LANGUAGE, | |
| 94 COMBOBOX_ID_TARGET_LANGUAGE, | |
| 95 }; | |
| 96 | |
| 97 friend class TranslateBubbleViewTest; | |
| 98 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, TranslateButton); | |
| 99 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, AdvancedLink); | |
| 100 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, ShowOriginalButton); | |
| 101 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, TryAgainButton); | |
| 102 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, AlwaysTranslateCheckbox); | |
| 103 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, DoneButton); | |
| 104 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, | |
| 105 CancelButtonReturningBeforeTranslate); | |
| 106 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, | |
| 107 CancelButtonReturningAfterTranslate); | |
| 108 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, CancelButtonReturningError); | |
| 109 | |
| 110 // Handles the event when the user presses a button. | |
| 111 void HandleButtonPressed(ButtonID sender_id); | |
| 112 | |
| 113 // Handles the event when the user clicks a link. | |
| 114 void HandleLinkClicked(LinkID sender_id); | |
| 115 | |
| 116 // Updates the visibilities of child views according to the current view type. | |
| 117 void UpdateChildVisibilities(); | |
| 118 | |
| 119 // Creates the 'before translate' view. Caller takes ownership of the returned | |
| 120 // view. | |
| 121 views::View* CreateViewBeforeTranslate(); | |
| 122 | |
| 123 // Creates the 'translating' view. Caller takes ownership of the returned | |
| 124 // view. | |
| 125 views::View* CreateViewTranslating(); | |
| 126 | |
| 127 // Creates the 'after translate' view. Caller takes ownership of the returned | |
| 128 // view. | |
| 129 views::View* CreateViewAfterTranslate(); | |
| 130 | |
| 131 // Creates the 'error' view. Caller takes ownership of the returned view. | |
| 132 views::View* CreateViewError(); | |
| 133 | |
| 134 // Creates the 'advanced' view. Caller takes ownership of the returned view. | |
| 135 views::View* CreateViewAdvanced(); | |
| 136 | |
| 137 // Switches the view type. | |
| 138 void SwitchView(TranslateBubbleModel::ViewState view_state); | |
| 139 | |
| 140 // Updates the advanced view. | |
| 141 void UpdateAdvancedView(); | |
| 142 | |
| 143 static TranslateBubbleView* translate_bubble_view_; | |
| 144 | |
| 145 scoped_ptr<LanguageComboboxModel> source_language_combobox_model_; | |
| 146 scoped_ptr<LanguageComboboxModel> target_language_combobox_model_; | |
| 147 | |
| 148 views::Combobox* source_language_combobox_; | |
| 149 views::Combobox* target_language_combobox_; | |
| 150 views::Checkbox* always_translate_checkbox_; | |
| 151 | |
| 152 scoped_ptr<TranslateBubbleModel> model_; | |
| 153 | |
| 154 // Whether the window is an incognito window. | |
| 155 bool is_in_incognito_window_; | |
| 156 | |
| 157 // The browser to open the help URL into a new tab. | |
| 158 Browser* browser_; | |
| 159 | |
| 160 // Whether the translation is acutually executed. | |
| 161 bool translate_executed_; | |
| 162 | |
| 163 DISALLOW_COPY_AND_ASSIGN(TranslateBubbleView); | |
| 164 }; | |
| 165 | |
| 166 #endif // CHROME_BROWSER_UI_VIEWS_TRANSLATE_TRANSLATE_BUBBLE_VIEW_H_ | |
| OLD | NEW |