Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / ui / views / translate / translate_bubble_view.h
blob61506e8932cd9cb8a88452716c731e1c7712fbad
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_
8 #include <map>
9 #include <string>
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"
22 class PrefService;
24 namespace views {
25 class Checkbox;
26 class GridLayout;
27 class LabelButton;
28 class Link;
29 class View;
32 namespace ui {
33 class SimpleComboboxModel;
36 class TranslateBubbleView : public ManagedFullScreenBubbleDelegateView,
37 public views::ButtonListener,
38 public views::ComboboxListener,
39 public views::LinkListener,
40 public content::WebContentsObserver {
41 public:
42 ~TranslateBubbleView() override;
44 // Shows the Translate bubble.
46 // |is_user_gesture| is true when the bubble is shown on the user's delibarate
47 // action.
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 // Returns the bubble view currently shown. This may return NULL.
58 static TranslateBubbleView* GetCurrentBubble();
60 TranslateBubbleModel* model() { return model_.get(); }
62 // views::BubbleDelegateView methods.
63 void Init() override;
64 void ButtonPressed(views::Button* sender, const ui::Event& event) override;
66 // views::WidgetDelegate method.
67 void WindowClosing() override;
69 // views::View methods.
70 bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
71 gfx::Size GetPreferredSize() const override;
73 // views::CombboxListener methods.
74 void OnPerformAction(views::Combobox* combobox) override;
76 // views::LinkListener method.
77 void LinkClicked(views::Link* source, int event_flags) override;
79 // content::WebContentsObserver method.
80 void WebContentsDestroyed() override;
82 // Returns the current view state.
83 TranslateBubbleModel::ViewState GetViewState() const;
85 private:
86 enum LinkID {
87 LINK_ID_ADVANCED,
88 LINK_ID_LANGUAGE_SETTINGS,
91 enum ButtonID {
92 BUTTON_ID_TRANSLATE,
93 BUTTON_ID_DONE,
94 BUTTON_ID_CANCEL,
95 BUTTON_ID_SHOW_ORIGINAL,
96 BUTTON_ID_TRY_AGAIN,
97 BUTTON_ID_ALWAYS_TRANSLATE,
100 enum ComboboxID {
101 COMBOBOX_ID_DENIAL,
102 COMBOBOX_ID_SOURCE_LANGUAGE,
103 COMBOBOX_ID_TARGET_LANGUAGE,
106 friend class TranslateBubbleViewTest;
107 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, TranslateButton);
108 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, AdvancedLink);
109 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, ShowOriginalButton);
110 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, TryAgainButton);
111 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest,
112 AlwaysTranslateCheckboxAndCancelButton);
113 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest,
114 AlwaysTranslateCheckboxAndDoneButton);
115 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, DoneButton);
116 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest,
117 DoneButtonWithoutTranslating);
118 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest,
119 CancelButtonReturningBeforeTranslate);
120 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest,
121 CancelButtonReturningAfterTranslate);
122 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, CancelButtonReturningError);
124 TranslateBubbleView(views::View* anchor_view,
125 scoped_ptr<TranslateBubbleModel> model,
126 translate::TranslateErrors::Type error_type,
127 content::WebContents* web_contents);
129 // Returns the current child view.
130 views::View* GetCurrentView() const;
132 // Handles the event when the user presses a button.
133 void HandleButtonPressed(ButtonID sender_id);
135 // Handles the event when the user clicks a link.
136 void HandleLinkClicked(LinkID sender_id);
138 // Handles the event when the user changes an index of a combobox.
139 void HandleComboboxPerformAction(ComboboxID sender_id);
141 // Updates the visibilities of child views according to the current view type.
142 void UpdateChildVisibilities();
144 // Creates the 'before translate' view. Caller takes ownership of the returned
145 // view.
146 views::View* CreateViewBeforeTranslate();
148 // Creates the 'translating' view. Caller takes ownership of the returned
149 // view.
150 views::View* CreateViewTranslating();
152 // Creates the 'after translate' view. Caller takes ownership of the returned
153 // view.
154 views::View* CreateViewAfterTranslate();
156 // Creates the 'error' view. Caller takes ownership of the returned view.
157 views::View* CreateViewError();
159 // Creates the 'advanced' view. Caller takes ownership of the returned view.
160 views::View* CreateViewAdvanced();
162 // Switches the view type.
163 void SwitchView(TranslateBubbleModel::ViewState view_state);
165 // Switches to the error view.
166 void SwitchToErrorView(translate::TranslateErrors::Type error_type);
168 // Updates the advanced view.
169 void UpdateAdvancedView();
171 static TranslateBubbleView* translate_bubble_view_;
173 views::View* before_translate_view_;
174 views::View* translating_view_;
175 views::View* after_translate_view_;
176 views::View* error_view_;
177 views::View* advanced_view_;
179 scoped_ptr<ui::SimpleComboboxModel> denial_combobox_model_;
180 scoped_ptr<LanguageComboboxModel> source_language_combobox_model_;
181 scoped_ptr<LanguageComboboxModel> target_language_combobox_model_;
183 views::Combobox* denial_combobox_;
184 views::Combobox* source_language_combobox_;
185 views::Combobox* target_language_combobox_;
187 views::Checkbox* always_translate_checkbox_;
189 views::LabelButton* advanced_cancel_button_;
190 views::LabelButton* advanced_done_button_;
192 scoped_ptr<TranslateBubbleModel> model_;
194 translate::TranslateErrors::Type error_type_;
196 // Whether the window is an incognito window.
197 const bool is_in_incognito_window_;
199 // Whether the translation is acutually executed.
200 bool translate_executed_;
202 // Whether one of denial buttons is clicked.
203 bool denial_button_clicked_;
205 DISALLOW_COPY_AND_ASSIGN(TranslateBubbleView);
208 #endif // CHROME_BROWSER_UI_VIEWS_TRANSLATE_TRANSLATE_BUBBLE_VIEW_H_