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 TranslateBubbleModel::Observer, | |
| 35 public views::BubbleDelegateView, | |
| 36 public views::ButtonListener, | |
| 37 public views::ComboboxListener, | |
| 38 public views::LinkListener { | |
| 39 public: | |
| 40 // Shows the Translate bubble. | |
| 41 static void ShowBubble(views::View* anchor_view, | |
| 42 content::WebContents* web_contents, | |
| 43 TranslateBubbleModel::ViewType type, | |
| 44 Browser* browser); | |
| 45 | |
| 46 // If true, the Translate bubble is being shown. | |
| 47 static bool IsShowing(); | |
| 48 | |
| 49 virtual ~TranslateBubbleView(); | |
| 50 | |
| 51 TranslateBubbleView(views::View* anchor_view, | |
| 52 scoped_ptr<TranslateBubbleModel> model, | |
| 53 bool is_in_incognito_window, | |
| 54 Browser* browser); | |
| 55 | |
| 56 TranslateBubbleModel::ViewType view_type() const { | |
| 57 return model_->view_type(); | |
| 58 } | |
| 59 | |
| 60 // public TranslateBubbleModel::Observer methods. | |
| 61 virtual void OnViewTypeChanged( | |
| 62 TranslateBubbleModel::ViewType view_type) OVERRIDE; | |
| 63 | |
| 64 // views::BubbleDelegateView methods. | |
| 65 virtual void Init() OVERRIDE; | |
| 66 virtual void ButtonPressed(views::Button* sender, | |
| 67 const ui::Event& event) OVERRIDE; | |
| 68 | |
| 69 // views::WidgetDelegate method. | |
| 70 virtual void WindowClosing() OVERRIDE; | |
| 71 | |
| 72 // views::View methods. | |
| 73 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; | |
| 74 virtual gfx::Size GetPreferredSize() OVERRIDE; | |
| 75 | |
| 76 // views::CombboxListener method. | |
| 77 virtual void OnSelectedIndexChanged(views::Combobox* combobox) OVERRIDE; | |
| 78 | |
| 79 // views::LinkListener method. | |
| 80 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE; | |
| 81 | |
| 82 private: | |
| 83 enum { | |
|
sky
2013/10/15 16:10:40
Use named enums, that way you can cast in switch s
hajimehoshi
2013/10/16 07:35:06
Done.
| |
| 84 LINK_ID_ADVANCED, | |
| 85 LINK_ID_LEARN_MORE, | |
| 86 }; | |
| 87 | |
| 88 enum { | |
| 89 BUTTON_ID_TRANSLATE, | |
| 90 BUTTON_ID_DONE, | |
| 91 BUTTON_ID_CANCEL, | |
| 92 BUTTON_ID_SHOW_ORIGINAL, | |
| 93 BUTTON_ID_TRY_AGAIN, | |
| 94 BUTTON_ID_ALWAYS_TRANSLATE, | |
| 95 }; | |
| 96 | |
| 97 enum { | |
| 98 COMBOBOX_ID_DENIAL, | |
| 99 COMBOBOX_ID_SOURCE_LANGUAGE, | |
| 100 COMBOBOX_ID_TARGET_LANGUAGE, | |
| 101 }; | |
| 102 | |
| 103 friend class TranslateBubbleViewTest; | |
| 104 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, TranslateButton); | |
| 105 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, AdvancedLink); | |
| 106 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, ShowOriginalButton); | |
| 107 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, TryAgainButton); | |
| 108 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, AlwaysTranslateCheckbox); | |
| 109 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, DoneButton); | |
| 110 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, | |
| 111 CancelButtonReturningBeforeTranslate); | |
| 112 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, | |
| 113 CancelButtonReturningAfterTranslate); | |
| 114 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, CancelButtonReturningError); | |
| 115 | |
| 116 // Handles the event when the user presses a button. | |
| 117 void HandleButtonPressed(int sender_id); | |
| 118 | |
| 119 // Handles the event when the user clicks a link. | |
| 120 void HandleLinkClicked(int sender_id); | |
| 121 | |
| 122 // Updates the visibilities of child views according to the current view type. | |
| 123 void UpdateChildVisibilities(); | |
| 124 | |
| 125 // Creates the 'before translate' view. Caller takes ownership of the returned | |
| 126 // view. | |
| 127 views::View* CreateViewBeforeTranslate(); | |
| 128 | |
| 129 // Creates the 'translating' view. Caller takes ownership of the returned | |
| 130 // view. | |
| 131 views::View* CreateViewTranslating(); | |
| 132 | |
| 133 // Creates the 'after translate' view. Caller takes ownership of the returned | |
| 134 // view. | |
| 135 views::View* CreateViewAfterTranslate(); | |
| 136 | |
| 137 // Creates the 'error' view. Caller takes ownership of the returned view. | |
| 138 views::View* CreateViewError(); | |
| 139 | |
| 140 // Creates the 'advanced' view. Caller takes ownership of the returned view. | |
| 141 views::View* CreateViewAdvanced(); | |
| 142 | |
| 143 // Switches the view type. | |
| 144 void SwitchView(TranslateBubbleModel::ViewType view_type); | |
| 145 | |
| 146 // Updates the advanced view. | |
| 147 void UpdateAdvancedView(); | |
| 148 | |
| 149 static TranslateBubbleView* translate_bubble_view_; | |
| 150 | |
| 151 scoped_ptr<LanguageComboboxModel> source_language_combobox_model_; | |
| 152 scoped_ptr<LanguageComboboxModel> target_language_combobox_model_; | |
| 153 | |
| 154 views::Combobox* source_language_combobox_; | |
| 155 views::Combobox* target_language_combobox_; | |
| 156 views::Checkbox* always_translate_checkbox_; | |
| 157 | |
| 158 scoped_ptr<TranslateBubbleModel> model_; | |
| 159 | |
| 160 // Whether the window is an incognito window. | |
| 161 bool is_in_incognito_window_; | |
| 162 | |
| 163 // The browser to open the help URL into a new tab. | |
| 164 Browser* browser_; | |
| 165 | |
| 166 // Whether the translation is acutually executed. | |
| 167 bool translate_executed_; | |
| 168 | |
| 169 DISALLOW_COPY_AND_ASSIGN(TranslateBubbleView); | |
| 170 }; | |
| 171 | |
| 172 #endif // CHROME_BROWSER_UI_VIEWS_TRANSLATE_TRANSLATE_BUBBLE_VIEW_H_ | |
| OLD | NEW |