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.
5 #ifndef CHROME_BROWSER_UI_VIEWS_TRANSLATE_TRANSLATE_BUBBLE_VIEW_H_
6 #define CHROME_BROWSER_UI_VIEWS_TRANSLATE_TRANSLATE_BUBBLE_VIEW_H_
11 #include "base/basictypes.h"
12 #include "chrome/browser/translate/chrome_translate_client.h"
13 #include "chrome/browser/ui/translate/language_combobox_model.h"
14 #include "chrome/browser/ui/translate/translate_bubble_model.h"
15 #include "chrome/browser/ui/views/managed_full_screen_bubble_delegate_view.h"
16 #include "components/translate/core/common/translate_errors.h"
17 #include "content/public/browser/web_contents_observer.h"
18 #include "ui/views/controls/button/button.h"
19 #include "ui/views/controls/combobox/combobox_listener.h"
20 #include "ui/views/controls/link_listener.h"
33 class SimpleComboboxModel
;
36 class TranslateBubbleView
: public ManagedFullScreenBubbleDelegateView
,
37 public views::ButtonListener
,
38 public views::ComboboxListener
,
39 public views::LinkListener
,
40 public content::WebContentsObserver
{
42 ~TranslateBubbleView() override
;
44 // Shows the Translate bubble.
46 // |is_user_gesture| is true when the bubble is shown on the user's delibarate
48 static void ShowBubble(views::View
* anchor_view
,
49 content::WebContents
* web_contents
,
50 translate::TranslateStep step
,
51 translate::TranslateErrors::Type error_type
,
52 bool is_user_gesture
);
54 // Closes the current bubble if existing.
55 static void CloseBubble();
57 // If true, the Translate bubble is being shown.
58 static bool IsShowing();
60 // Returns the bubble view currently shown. This may return NULL.
61 static TranslateBubbleView
* GetCurrentBubble();
63 TranslateBubbleModel
* model() { return model_
.get(); }
65 // views::BubbleDelegateView methods.
67 void ButtonPressed(views::Button
* sender
, const ui::Event
& event
) override
;
69 // views::WidgetDelegate method.
70 void WindowClosing() override
;
72 // views::View methods.
73 bool AcceleratorPressed(const ui::Accelerator
& accelerator
) override
;
74 gfx::Size
GetPreferredSize() const override
;
76 // views::CombboxListener methods.
77 void OnPerformAction(views::Combobox
* combobox
) override
;
79 // views::LinkListener method.
80 void LinkClicked(views::Link
* source
, int event_flags
) override
;
82 // content::WebContentsObserver method.
83 void WebContentsDestroyed() override
;
85 // Returns the current view state.
86 TranslateBubbleModel::ViewState
GetViewState() const;
91 LINK_ID_LANGUAGE_SETTINGS
,
98 BUTTON_ID_SHOW_ORIGINAL
,
100 BUTTON_ID_ALWAYS_TRANSLATE
,
105 COMBOBOX_ID_SOURCE_LANGUAGE
,
106 COMBOBOX_ID_TARGET_LANGUAGE
,
109 friend class TranslateBubbleViewTest
;
110 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest
, TranslateButton
);
111 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest
, AdvancedLink
);
112 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest
, ShowOriginalButton
);
113 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest
, TryAgainButton
);
114 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest
,
115 AlwaysTranslateCheckboxAndCancelButton
);
116 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest
,
117 AlwaysTranslateCheckboxAndDoneButton
);
118 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest
, DoneButton
);
119 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest
,
120 DoneButtonWithoutTranslating
);
121 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest
,
122 CancelButtonReturningBeforeTranslate
);
123 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest
,
124 CancelButtonReturningAfterTranslate
);
125 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest
, CancelButtonReturningError
);
127 TranslateBubbleView(views::View
* anchor_view
,
128 scoped_ptr
<TranslateBubbleModel
> model
,
129 translate::TranslateErrors::Type error_type
,
130 content::WebContents
* web_contents
);
132 // Returns the current child view.
133 views::View
* GetCurrentView() const;
135 // Handles the event when the user presses a button.
136 void HandleButtonPressed(ButtonID sender_id
);
138 // Handles the event when the user clicks a link.
139 void HandleLinkClicked(LinkID sender_id
);
141 // Handles the event when the user changes an index of a combobox.
142 void HandleComboboxPerformAction(ComboboxID sender_id
);
144 // Updates the visibilities of child views according to the current view type.
145 void UpdateChildVisibilities();
147 // Creates the 'before translate' view. Caller takes ownership of the returned
149 views::View
* CreateViewBeforeTranslate();
151 // Creates the 'translating' view. Caller takes ownership of the returned
153 views::View
* CreateViewTranslating();
155 // Creates the 'after translate' view. Caller takes ownership of the returned
157 views::View
* CreateViewAfterTranslate();
159 // Creates the 'error' view. Caller takes ownership of the returned view.
160 views::View
* CreateViewError();
162 // Creates the 'advanced' view. Caller takes ownership of the returned view.
163 views::View
* CreateViewAdvanced();
165 // Switches the view type.
166 void SwitchView(TranslateBubbleModel::ViewState view_state
);
168 // Switches to the error view.
169 void SwitchToErrorView(translate::TranslateErrors::Type error_type
);
171 // Updates the advanced view.
172 void UpdateAdvancedView();
174 static TranslateBubbleView
* translate_bubble_view_
;
176 views::View
* before_translate_view_
;
177 views::View
* translating_view_
;
178 views::View
* after_translate_view_
;
179 views::View
* error_view_
;
180 views::View
* advanced_view_
;
182 scoped_ptr
<ui::SimpleComboboxModel
> denial_combobox_model_
;
183 scoped_ptr
<LanguageComboboxModel
> source_language_combobox_model_
;
184 scoped_ptr
<LanguageComboboxModel
> target_language_combobox_model_
;
186 views::Combobox
* denial_combobox_
;
187 views::Combobox
* source_language_combobox_
;
188 views::Combobox
* target_language_combobox_
;
190 views::Checkbox
* always_translate_checkbox_
;
192 views::LabelButton
* advanced_cancel_button_
;
193 views::LabelButton
* advanced_done_button_
;
195 scoped_ptr
<TranslateBubbleModel
> model_
;
197 translate::TranslateErrors::Type error_type_
;
199 // Whether the window is an incognito window.
200 const bool is_in_incognito_window_
;
202 // Whether the translation is acutually executed.
203 bool translate_executed_
;
205 // Whether one of denial buttons is clicked.
206 bool denial_button_clicked_
;
208 DISALLOW_COPY_AND_ASSIGN(TranslateBubbleView
);
211 #endif // CHROME_BROWSER_UI_VIEWS_TRANSLATE_TRANSLATE_BUBBLE_VIEW_H_