Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_UI_VIEWS_TRANSLATE_TRANSLATE_BUBBLE_VIEW_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_TRANSLATE_TRANSLATE_BUBBLE_VIEW_H_ |
| 6 #define CHROME_BROWSER_UI_VIEWS_TRANSLATE_TRANSLATE_BUBBLE_VIEW_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_TRANSLATE_TRANSLATE_BUBBLE_VIEW_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/strings/utf_string_conversions.h" | |
| 13 #include "chrome/browser/translate/chrome_translate_client.h" | 14 #include "chrome/browser/translate/chrome_translate_client.h" |
| 14 #include "chrome/browser/ui/translate/language_combobox_model.h" | 15 #include "chrome/browser/ui/translate/language_combobox_model.h" |
| 15 #include "chrome/browser/ui/translate/translate_bubble_model.h" | 16 #include "chrome/browser/ui/translate/translate_bubble_model.h" |
| 16 #include "chrome/browser/ui/translate/translate_bubble_test_utils.h" | 17 #include "chrome/browser/ui/translate/translate_bubble_test_utils.h" |
| 17 #include "chrome/browser/ui/views/location_bar/location_bar_bubble_delegate_view .h" | 18 #include "chrome/browser/ui/views/location_bar/location_bar_bubble_delegate_view .h" |
| 18 #include "components/translate/core/common/translate_errors.h" | 19 #include "components/translate/core/common/translate_errors.h" |
| 19 #include "content/public/browser/web_contents_observer.h" | 20 #include "content/public/browser/web_contents_observer.h" |
| 21 #include "ui/base/models/simple_menu_model.h" | |
| 20 #include "ui/views/controls/button/button.h" | 22 #include "ui/views/controls/button/button.h" |
| 23 #include "ui/views/controls/button/menu_button_listener.h" | |
| 21 #include "ui/views/controls/combobox/combobox_listener.h" | 24 #include "ui/views/controls/combobox/combobox_listener.h" |
| 22 #include "ui/views/controls/link_listener.h" | 25 #include "ui/views/controls/link_listener.h" |
| 26 #include "ui/views/controls/menu/menu_runner.h" | |
| 27 #include "ui/views/controls/styled_label_listener.h" | |
| 23 | 28 |
| 24 class Browser; | 29 class Browser; |
| 25 class PrefService; | 30 class PrefService; |
|
msw
2016/05/03 22:33:34
optional nit: Remove this; it's not used.
ftang
2016/05/03 23:55:42
Done.
| |
| 26 | 31 |
| 32 namespace gfx { | |
| 33 class Range; | |
|
msw
2016/05/03 22:33:35
Remove this; it should be included via styled_labe
ftang
2016/05/03 23:55:42
Done.
| |
| 34 } | |
| 35 | |
| 27 namespace views { | 36 namespace views { |
| 28 class Checkbox; | 37 class Checkbox; |
| 29 class GridLayout; | 38 class GridLayout; |
|
msw
2016/05/03 22:33:35
optional nit: Remove this; it's not used.
ftang
2016/05/03 23:55:42
Done.
| |
| 30 class LabelButton; | 39 class LabelButton; |
| 31 class Link; | 40 class Link; |
|
msw
2016/05/03 22:33:35
optional nit: Remove this; it should be included v
ftang
2016/05/03 23:55:42
Done.
| |
| 32 class View; | 41 class View; |
| 42 class StyledLabel; | |
|
msw
2016/05/03 22:33:35
Remove this; it should be included via styled_labe
ftang
2016/05/03 23:55:42
Done.
| |
| 33 } | 43 } |
| 34 | 44 |
| 35 namespace ui { | 45 namespace ui { |
| 36 class SimpleComboboxModel; | 46 class SimpleComboboxModel; |
| 37 } | 47 } |
| 38 | 48 |
| 39 class TranslateBubbleView : public LocationBarBubbleDelegateView, | 49 class TranslateBubbleView : public LocationBarBubbleDelegateView, |
| 40 public views::ButtonListener, | 50 public views::ButtonListener, |
| 41 public views::ComboboxListener, | 51 public views::ComboboxListener, |
| 42 public views::LinkListener, | 52 public views::LinkListener, |
| 53 public views::MenuButtonListener, | |
| 54 public ui::SimpleMenuModel::Delegate, | |
| 55 public views::StyledLabelListener, | |
| 43 public content::WebContentsObserver { | 56 public content::WebContentsObserver { |
| 44 public: | 57 public: |
| 45 // Commands shown in the action-style combobox. The value corresponds to the | 58 // Commands shown in the action-style combobox. The value corresponds to the |
| 46 // position in the combobox menu. Gaps will become separators. | 59 // position in the combobox menu. Gaps will become separators. |
| 47 enum class DenialComboboxIndex { | 60 enum class DenialComboboxIndex { |
| 48 DONT_TRANSLATE = 0, | 61 DONT_TRANSLATE = 0, |
| 49 NEVER_TRANSLATE_LANGUAGE = 1, | 62 NEVER_TRANSLATE_LANGUAGE = 1, |
| 50 NEVER_TRANSLATE_SITE = 3, | 63 NEVER_TRANSLATE_SITE = 3, |
| 51 MENU_SIZE = 4, | 64 MENU_SIZE = 4, |
| 52 }; | 65 }; |
| 53 | 66 |
| 67 enum DenialMenuItem { NEVER_TRANSLATE_LANGUAGE, NEVER_TRANSLATE_SITE }; | |
|
msw
2016/05/03 22:33:35
nit: add a comment "// Item IDs for the denial but
ftang
2016/05/03 23:55:42
Done.
| |
| 68 | |
| 54 ~TranslateBubbleView() override; | 69 ~TranslateBubbleView() override; |
| 55 | 70 |
| 56 // Shows the Translate bubble. Returns the newly created bubble's Widget or | 71 // Shows the Translate bubble. Returns the newly created bubble's Widget or |
| 57 // nullptr in cases when the bubble already exists or when the bubble is not | 72 // nullptr in cases when the bubble already exists or when the bubble is not |
| 58 // created. | 73 // created. |
| 59 // | 74 // |
| 60 // |is_user_gesture| is true when the bubble is shown on the user's deliberate | 75 // |is_user_gesture| is true when the bubble is shown on the user's deliberate |
| 61 // action. | 76 // action. |
| 62 static views::Widget* ShowBubble(views::View* anchor_view, | 77 static views::Widget* ShowBubble(views::View* anchor_view, |
| 63 content::WebContents* web_contents, | 78 content::WebContents* web_contents, |
| 64 translate::TranslateStep step, | 79 translate::TranslateStep step, |
| 65 translate::TranslateErrors::Type error_type, | 80 translate::TranslateErrors::Type error_type, |
| 66 DisplayReason reason); | 81 DisplayReason reason); |
| 67 | 82 |
| 68 // Closes the current bubble if it exists. | 83 // Closes the current bubble if it exists. |
| 69 static void CloseCurrentBubble(); | 84 static void CloseCurrentBubble(); |
| 70 | 85 |
| 71 // Returns the bubble view currently shown. This may return NULL. | 86 // Returns the bubble view currently shown. This may return NULL. |
| 72 static TranslateBubbleView* GetCurrentBubble(); | 87 static TranslateBubbleView* GetCurrentBubble(); |
| 73 | 88 |
| 74 TranslateBubbleModel* model() { return model_.get(); } | 89 TranslateBubbleModel* model() { return model_.get(); } |
| 75 | 90 |
| 76 // views::BubbleDialogDelegateView methods. | 91 // views::BubbleDialogDelegateView methods. |
| 77 void Init() override; | 92 void Init() override; |
| 78 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | 93 void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
| 79 | 94 |
| 80 // views::WidgetDelegate method. | 95 // views::WidgetDelegate methods. |
| 96 bool ShouldShowCloseButton() const override; | |
| 81 void WindowClosing() override; | 97 void WindowClosing() override; |
| 82 | 98 |
| 83 // views::View methods. | 99 // views::View methods. |
| 84 bool AcceleratorPressed(const ui::Accelerator& accelerator) override; | 100 bool AcceleratorPressed(const ui::Accelerator& accelerator) override; |
| 85 gfx::Size GetPreferredSize() const override; | 101 gfx::Size GetPreferredSize() const override; |
| 86 | 102 |
| 87 // views::CombboxListener methods. | 103 // views::CombboxListener methods. |
| 88 void OnPerformAction(views::Combobox* combobox) override; | 104 void OnPerformAction(views::Combobox* combobox) override; |
| 89 | 105 |
| 90 // views::LinkListener method. | 106 // views::LinkListener method. |
| 91 void LinkClicked(views::Link* source, int event_flags) override; | 107 void LinkClicked(views::Link* source, int event_flags) override; |
| 92 | 108 |
| 109 // views::MenuButtonListener method. | |
| 110 void OnMenuButtonClicked(views::MenuButton* source, | |
| 111 const gfx::Point& point, | |
| 112 const ui::Event* event) override; | |
| 113 | |
| 114 // ui::SimpleMenuModel::Delegate methods. | |
| 115 bool IsCommandIdChecked(int command_id) const override; | |
| 116 bool IsCommandIdEnabled(int command_id) const override; | |
| 117 bool GetAcceleratorForCommandId(int command_id, | |
| 118 ui::Accelerator* accelerator) override; | |
| 119 void ExecuteCommand(int command_id, int event_flags) override; | |
| 120 | |
| 121 // views::StyledLabelListener method. | |
| 122 void StyledLabelLinkClicked(views::StyledLabel* label, | |
| 123 const gfx::Range& range, | |
| 124 int event_flags) override; | |
| 125 | |
| 93 // content::WebContentsObserver method. | 126 // content::WebContentsObserver method. |
| 94 void WebContentsDestroyed() override; | 127 void WebContentsDestroyed() override; |
| 95 | 128 |
| 129 // Overridden from views::WidgetObserver: | |
| 130 void OnWidgetClosing(views::Widget* widget) override; | |
| 131 | |
| 96 // Returns the current view state. | 132 // Returns the current view state. |
| 97 TranslateBubbleModel::ViewState GetViewState() const; | 133 TranslateBubbleModel::ViewState GetViewState() const; |
| 98 | 134 |
| 99 private: | 135 private: |
| 100 enum LinkID { | 136 enum LinkID { |
| 101 LINK_ID_ADVANCED, | 137 LINK_ID_ADVANCED, |
| 102 LINK_ID_LANGUAGE_SETTINGS, | 138 LINK_ID_LANGUAGE_SETTINGS, |
| 103 }; | 139 }; |
| 104 | 140 |
| 105 enum ButtonID { | 141 enum ButtonID { |
| 106 BUTTON_ID_TRANSLATE, | 142 BUTTON_ID_TRANSLATE, |
| 107 BUTTON_ID_DONE, | 143 BUTTON_ID_DONE, |
| 108 BUTTON_ID_CANCEL, | 144 BUTTON_ID_CANCEL, |
| 109 BUTTON_ID_SHOW_ORIGINAL, | 145 BUTTON_ID_SHOW_ORIGINAL, |
| 110 BUTTON_ID_TRY_AGAIN, | 146 BUTTON_ID_TRY_AGAIN, |
| 111 BUTTON_ID_ALWAYS_TRANSLATE, | 147 BUTTON_ID_ALWAYS_TRANSLATE, |
| 112 }; | 148 }; |
| 113 | 149 |
| 114 enum ComboboxID { | 150 enum ComboboxID { |
| 115 COMBOBOX_ID_DENIAL, | 151 COMBOBOX_ID_DENIAL, |
| 116 COMBOBOX_ID_SOURCE_LANGUAGE, | 152 COMBOBOX_ID_SOURCE_LANGUAGE, |
| 117 COMBOBOX_ID_TARGET_LANGUAGE, | 153 COMBOBOX_ID_TARGET_LANGUAGE, |
| 118 }; | 154 }; |
| 119 | 155 |
| 120 friend class TranslateBubbleViewTest; | 156 friend class TranslateBubbleViewTest; |
| 121 friend void ::translate::test_utils::PressTranslate(::Browser*); | 157 friend void ::translate::test_utils::PressTranslate(::Browser*); |
| 122 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, TranslateButton); | 158 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, TranslateButton); |
| 159 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, TranslateButtonIn2016Q2UI); | |
| 160 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, CloseButtonIn2016Q2UI); | |
| 123 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, AdvancedLink); | 161 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, AdvancedLink); |
| 162 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, AdvancedLinkIn2016Q2UI); | |
| 124 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, ShowOriginalButton); | 163 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, ShowOriginalButton); |
| 125 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, TryAgainButton); | 164 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, TryAgainButton); |
| 126 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, | 165 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, |
| 127 AlwaysTranslateCheckboxAndCancelButton); | 166 AlwaysTranslateCheckboxAndCancelButton); |
| 128 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, | 167 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, |
| 129 AlwaysTranslateCheckboxAndDoneButton); | 168 AlwaysTranslateCheckboxAndDoneButton); |
| 130 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, DoneButton); | 169 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, DoneButton); |
| 131 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, | 170 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, |
| 132 DoneButtonWithoutTranslating); | 171 DoneButtonWithoutTranslating); |
| 133 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, | 172 FRIEND_TEST_ALL_PREFIXES(TranslateBubbleViewTest, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 176 | 215 |
| 177 // Switches the view type. | 216 // Switches the view type. |
| 178 void SwitchView(TranslateBubbleModel::ViewState view_state); | 217 void SwitchView(TranslateBubbleModel::ViewState view_state); |
| 179 | 218 |
| 180 // Switches to the error view. | 219 // Switches to the error view. |
| 181 void SwitchToErrorView(translate::TranslateErrors::Type error_type); | 220 void SwitchToErrorView(translate::TranslateErrors::Type error_type); |
| 182 | 221 |
| 183 // Updates the advanced view. | 222 // Updates the advanced view. |
| 184 void UpdateAdvancedView(); | 223 void UpdateAdvancedView(); |
| 185 | 224 |
| 225 void ReportUiAction(int action); | |
|
msw
2016/05/03 22:33:34
nit: add a comment "Logs metrics for the user's Tr
msw
2016/05/03 22:33:34
Pass |action| as a TranslateBubbleUiEvent, not an
ftang
2016/05/03 23:55:42
Done.
ftang
2016/05/03 23:55:42
Done.
| |
| 226 | |
| 186 static TranslateBubbleView* translate_bubble_view_; | 227 static TranslateBubbleView* translate_bubble_view_; |
| 187 | 228 |
| 188 views::View* before_translate_view_; | 229 views::View* before_translate_view_; |
| 189 views::View* translating_view_; | 230 views::View* translating_view_; |
| 190 views::View* after_translate_view_; | 231 views::View* after_translate_view_; |
| 191 views::View* error_view_; | 232 views::View* error_view_; |
| 192 views::View* advanced_view_; | 233 views::View* advanced_view_; |
| 193 | 234 |
| 194 std::unique_ptr<ui::SimpleComboboxModel> denial_combobox_model_; | 235 std::unique_ptr<ui::SimpleComboboxModel> denial_combobox_model_; |
| 195 std::unique_ptr<LanguageComboboxModel> source_language_combobox_model_; | 236 std::unique_ptr<LanguageComboboxModel> source_language_combobox_model_; |
| 196 std::unique_ptr<LanguageComboboxModel> target_language_combobox_model_; | 237 std::unique_ptr<LanguageComboboxModel> target_language_combobox_model_; |
| 197 | 238 |
| 198 views::Combobox* denial_combobox_; | 239 views::Combobox* denial_combobox_; |
| 199 views::Combobox* source_language_combobox_; | 240 views::Combobox* source_language_combobox_; |
| 200 views::Combobox* target_language_combobox_; | 241 views::Combobox* target_language_combobox_; |
| 201 | 242 |
| 202 views::Checkbox* always_translate_checkbox_; | 243 views::Checkbox* always_translate_checkbox_; |
| 203 | 244 |
| 204 views::LabelButton* advanced_cancel_button_; | 245 views::LabelButton* advanced_cancel_button_; |
| 205 views::LabelButton* advanced_done_button_; | 246 views::LabelButton* advanced_done_button_; |
| 206 | 247 |
| 248 views::MenuButton* denial_menu_button_; | |
| 249 | |
|
msw
2016/05/03 22:33:34
nit: remove blank line
ftang
2016/05/03 23:55:42
Done.
| |
| 250 std::unique_ptr<ui::SimpleMenuModel> denial_menu_model_; | |
| 251 | |
|
msw
2016/05/03 22:33:34
nit: remove blank line
ftang
2016/05/03 23:55:42
Done.
| |
| 252 std::unique_ptr<views::MenuRunner> denial_menu_runner_; | |
| 253 | |
| 207 std::unique_ptr<TranslateBubbleModel> model_; | 254 std::unique_ptr<TranslateBubbleModel> model_; |
| 208 | 255 |
| 209 translate::TranslateErrors::Type error_type_; | 256 translate::TranslateErrors::Type error_type_; |
| 210 | 257 |
| 211 // Whether the window is an incognito window. | 258 // Whether the window is an incognito window. |
| 212 const bool is_in_incognito_window_; | 259 const bool is_in_incognito_window_; |
| 213 | 260 |
| 214 // Whether the translation is acutually executed. | 261 // Use the new (2016 Q2) translate UI. |
| 215 bool translate_executed_; | 262 bool use_2016_q2_ui_; |
| 216 | 263 |
| 217 DISALLOW_COPY_AND_ASSIGN(TranslateBubbleView); | 264 DISALLOW_COPY_AND_ASSIGN(TranslateBubbleView); |
| 218 }; | 265 }; |
| 219 | 266 |
| 220 #endif // CHROME_BROWSER_UI_VIEWS_TRANSLATE_TRANSLATE_BUBBLE_VIEW_H_ | 267 #endif // CHROME_BROWSER_UI_VIEWS_TRANSLATE_TRANSLATE_BUBBLE_VIEW_H_ |
| OLD | NEW |