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/translate/translate_bubble_test_utils.h"
16 #include "chrome/browser/ui/views/managed_full_screen_bubble_delegate_view.h"
17 #include "components/translate/core/common/translate_errors.h"
18 #include "content/public/browser/web_contents_observer.h"
19 #include "ui/views/controls/button/button.h"
20 #include "ui/views/controls/combobox/combobox_listener.h"
21 #include "ui/views/controls/link_listener.h"
35 class SimpleComboboxModel
;
38 class TranslateBubbleView
: public ManagedFullScreenBubbleDelegateView
,
39 public views::ButtonListener
,
40 public views::ComboboxListener
,
41 public views::LinkListener
,
42 public content::WebContentsObserver
{
44 ~TranslateBubbleView() override
;
46 // Shows the Translate bubble.
48 // |is_user_gesture| is true when the bubble is shown on the user's delibarate
50 static void ShowBubble(views::View
* anchor_view
,
51 content::WebContents
* web_contents
,
52 translate::TranslateStep step
,
53 translate::TranslateErrors::Type error_type
,
54 bool is_user_gesture
);
56 // Closes the current bubble if existing.
57 static void CloseBubble();
59 // Returns the bubble view currently shown. This may return NULL.
60 static TranslateBubbleView
* GetCurrentBubble();
62 TranslateBubbleModel
* model() { return model_
.get(); }
64 // views::BubbleDelegateView methods.
66 void ButtonPressed(views::Button
* sender
, const ui::Event
& event
) override
;
68 // views::WidgetDelegate method.
69 void WindowClosing() override
;
71 // views::View methods.
72 bool AcceleratorPressed(const ui::Accelerator
& accelerator
) override
;
73 gfx::Size
GetPreferredSize() const override
;
75 // views::CombboxListener methods.
76 void OnPerformAction(views::Combobox
* combobox
) override
;
78 // views::LinkListener method.
79 void LinkClicked(views::Link
* source
, int event_flags
) override
;
81 // content::WebContentsObserver method.
82 void WebContentsDestroyed() override
;
84 // Returns the current view state.
85 TranslateBubbleModel::ViewState
GetViewState() const;
90 LINK_ID_LANGUAGE_SETTINGS
,
97 BUTTON_ID_SHOW_ORIGINAL
,
99 BUTTON_ID_ALWAYS_TRANSLATE
,
104 COMBOBOX_ID_SOURCE_LANGUAGE
,
105 COMBOBOX_ID_TARGET_LANGUAGE
,
108 friend class TranslateBubbleViewTest
;
109 friend void ::translate::test_utils::PressTranslate(::Browser
*);
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_