| 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::ViewType type, |
| 43 Browser* browser); |
| 44 |
| 45 // If true, the Translate bubble is being shown. |
| 46 static bool IsShowing(); |
| 47 |
| 48 virtual ~TranslateBubbleView(); |
| 49 |
| 50 TranslateBubbleView(views::View* anchor_view, |
| 51 scoped_ptr<TranslateBubbleModel> model, |
| 52 TranslateBubbleModel::ViewType type, |
| 53 bool is_in_incognito_window, |
| 54 Browser* browser); |
| 55 |
| 56 // views::BubbleDelegateView methods. |
| 57 virtual void Init() OVERRIDE; |
| 58 virtual void ButtonPressed(views::Button* sender, |
| 59 const ui::Event& event) OVERRIDE; |
| 60 |
| 61 // views::WidgetDelegate method. |
| 62 virtual void WindowClosing() OVERRIDE; |
| 63 |
| 64 // views::View methods. |
| 65 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; |
| 66 virtual gfx::Size GetPreferredSize() OVERRIDE; |
| 67 |
| 68 // views::CombboxListener method. |
| 69 virtual void OnSelectedIndexChanged(views::Combobox* combobox) OVERRIDE; |
| 70 |
| 71 // views::LinkListener method. |
| 72 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE; |
| 73 |
| 74 private: |
| 75 enum { |
| 76 LINK_ID_ADVANCED, |
| 77 LINK_ID_LEARN_MORE, |
| 78 }; |
| 79 |
| 80 enum { |
| 81 BUTTON_ID_TRANSLATE, |
| 82 BUTTON_ID_DONE, |
| 83 BUTTON_ID_CANCEL, |
| 84 BUTTON_ID_SHOW_ORIGINAL, |
| 85 BUTTON_ID_TRY_AGAIN, |
| 86 BUTTON_ID_ALWAYS_TRANSLATE, |
| 87 }; |
| 88 |
| 89 enum { |
| 90 COMBOBOX_ID_DENIAL, |
| 91 COMBOBOX_ID_SOURCE_LANGUAGE, |
| 92 COMBOBOX_ID_TARGET_LANGUAGE, |
| 93 }; |
| 94 |
| 95 friend class TranslateBubbleViewTest; |
| 96 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, TranslateButton); |
| 97 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, AdvancedLink); |
| 98 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, ShowOriginalButton); |
| 99 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, TryAgainButton); |
| 100 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, AlwaysTranslateCheckbox); |
| 101 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, DoneButton); |
| 102 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, |
| 103 CancelButtonReturningBeforeTranslate); |
| 104 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, |
| 105 CancelButtonReturningAfterTranslate); |
| 106 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, CancelButtonReturningError); |
| 107 |
| 108 // Handles the event when the user presses a button. |
| 109 void HandleButtonPressed(int sender_id); |
| 110 |
| 111 // Handles the event when the user clicks a link. |
| 112 void HandleLinkClicked(int sender_id); |
| 113 |
| 114 // Switches the view according to |type|. |
| 115 void SwitchView(TranslateBubbleModel::ViewType type); |
| 116 |
| 117 // Updates the visibilities of child views according to the current |
| 118 // |view_type_|. Contrary to SwitchView, this doesn't change anything but |
| 119 // the visibilities. |
| 120 void UpdateChildVisibilities(); |
| 121 |
| 122 // Creates the 'before translate' view. Caller takes ownership of the returned |
| 123 // view. |
| 124 views::View* CreateViewBeforeTranslate(); |
| 125 |
| 126 // Creates the 'translating' view. Caller takes ownership of the returned |
| 127 // view. |
| 128 views::View* CreateViewTranslating(); |
| 129 |
| 130 // Creates the 'after translate' view. Caller takes ownership of the returned |
| 131 // view. |
| 132 views::View* CreateViewAfterTranslate(); |
| 133 |
| 134 // Creates the 'error' view. Caller takes ownership of the returned view. |
| 135 views::View* CreateViewError(); |
| 136 |
| 137 // Creates the 'advanced' view. Caller takes ownership of the returned view. |
| 138 views::View* CreateViewAdvanced(); |
| 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 // The view type |
| 155 TranslateBubbleModel::ViewType view_type_; |
| 156 |
| 157 // The view type. When the current view type is not 'Advanced' view, this is |
| 158 // equivalent to |view_type_|. Otherwise, this is the previous view type |
| 159 // before the user opens the 'Advanced' view. This is used to navigate when |
| 160 // pressing 'Cancel' button on the 'Advanced' view. |
| 161 TranslateBubbleModel::ViewType view_type_before_advanced_view_; |
| 162 |
| 163 // Whether the window is an incognito window. |
| 164 bool is_in_incognito_window_; |
| 165 |
| 166 // The browser to open the help URL into a new tab. |
| 167 Browser* browser_; |
| 168 |
| 169 // Whether the translation is acutually executed. |
| 170 bool translate_executed_; |
| 171 |
| 172 DISALLOW_COPY_AND_ASSIGN(TranslateBubbleView); |
| 173 }; |
| 174 |
| 175 #endif // CHROME_BROWSER_UI_VIEWS_TRANSLATE_TRANSLATE_BUBBLE_VIEW_H_ |
| OLD | NEW |