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_TRANSLATE_TRANSLATE_BUBBLE_VIEW_STATE_TRANSITION_H_
6 #define CHROME_BROWSER_UI_TRANSLATE_TRANSLATE_BUBBLE_VIEW_STATE_TRANSITION_H_
7 
8 #include "base/macros.h"
9 #include "chrome/browser/ui/translate/translate_bubble_model.h"
10 
11 namespace translate {
12 
13 enum TranslateBubbleUiEvent {
14   // Update TranslateBubbleUiEvent in enums.xml when making changes.
15   // Start with 1 to match existing UMA values: see http://crbug.com/612558
16   // The user clicked the advanced option.
17   SET_STATE_OPTIONS = 1,
18 
19   // The user clicked "Done" and went back from the advanced option.
20   LEAVE_STATE_OPTIONS = 2,
21 
22   // The user clicked the advanced link.
23   // [DEPRECATED] ADVANCED_LINK_CLICKED = 3,
24 
25   // The user checked the "always translate" checkbox.
26   ALWAYS_TRANSLATE_CHECKED = 4,
27 
28   // The user unchecked the "always translate" checkbox.
29   ALWAYS_TRANSLATE_UNCHECKED = 5,
30 
31   // The user selected "Nope" in the "Options" menu.
32   // [DEPRECATED] NOPE_MENU_CLICKED = 6,
33 
34   // The user selected "Never translate language" in the "Options" menu.
35   NEVER_TRANSLATE_LANGUAGE_MENU_CLICKED = 7,
36 
37   // The user selected "Never translate this site" in the "Options" menu.
38   NEVER_TRANSLATE_SITE_MENU_CLICKED = 8,
39 
40   // The user clicked the "Translate" button.
41   TRANSLATE_BUTTON_CLICKED = 9,
42 
43   // The user clicked the "Done" button.
44   DONE_BUTTON_CLICKED = 10,
45 
46   // The user clicked the "Cancel" button.
47   CANCEL_BUTTON_CLICKED = 11,
48 
49   // The user clicked the "Closed" [X] button.
50   CLOSE_BUTTON_CLICKED = 12,
51 
52   // The user clicked the "Try Again" button.
53   TRY_AGAIN_BUTTON_CLICKED = 13,
54 
55   // The user clicked the "Show Original" button.
56   SHOW_ORIGINAL_BUTTON_CLICKED = 14,
57 
58   // The user clicked the "Settings" link.
59   // [DEPRECATED] SETTINGS_LINK_CLICKED = 15,
60 
61   // The user changed the "Source language".
62   SOURCE_LANGUAGE_MENU_CLICKED = 16,
63 
64   // The user changed the "Target language".
65   TARGET_LANGUAGE_MENU_CLICKED = 17,
66 
67   // The user activated the translate page action icon.
68   PAGE_ACTION_ICON_ACTIVATED = 18,
69 
70   // The user deactivated the translate page action icon.
71   PAGE_ACTION_ICON_DEACTIVATED = 19,
72 
73   // The translate bubble was shown to the user.
74   BUBBLE_SHOWN = 20,
75 
76   // The translate bugbble could not be shown to the user, for various reasons.
77   BUBBLE_NOT_SHOWN_WINDOW_NOT_VALID = 21,
78   BUBBLE_NOT_SHOWN_WINDOW_MINIMIZED = 22,
79   BUBBLE_NOT_SHOWN_WINDOW_NOT_ACTIVE = 23,
80   BUBBLE_NOT_SHOWN_WEB_CONTENTS_NOT_ACTIVE = 24,
81   BUBBLE_NOT_SHOWN_EDITABLE_FIELD_IS_ACTIVE = 25,
82 
83   // The user clicked the advanced menu item.
84   ADVANCED_MENU_CLICKED = 26,
85 
86   // The user clicked the advanced button.
87   // [DEPRECATED] ADVANCED_BUTTON_CLICKED = 27,
88 
89   TRANSLATE_BUBBLE_UI_EVENT_MAX
90 };
91 
92 // Logs metrics for the user's TranslateBubbleUiEvent |action|.
93 void ReportUiAction(translate::TranslateBubbleUiEvent action);
94 
95 }  // namespace translate
96 
97 // The class which manages the transition of the view state of the Translate
98 // bubble.
99 class TranslateBubbleViewStateTransition {
100  public:
101   explicit TranslateBubbleViewStateTransition(
102       TranslateBubbleModel::ViewState view_state);
103 
view_state()104   TranslateBubbleModel::ViewState view_state() const { return view_state_; }
105 
106   // Transitions the view state.
107   void SetViewState(TranslateBubbleModel::ViewState view_state);
108 
109   // Goes back from the 'Advanced' view state.
110   void GoBackFromAdvanced();
111 
112  private:
113   // The current view type.
114   TranslateBubbleModel::ViewState view_state_;
115 
116   // The view type. When the current view type is not 'Advanced' view, this is
117   // equivalent to |view_state_|. Otherwise, this is the previous view type
118   // before the user opens the 'Advanced' view. This is used to navigate when
119   // pressing 'Cancel' button on the 'Advanced' view.
120   TranslateBubbleModel::ViewState view_state_before_advanced_view_;
121 
122   DISALLOW_COPY_AND_ASSIGN(TranslateBubbleViewStateTransition);
123 };
124 
125 #endif  // CHROME_BROWSER_UI_TRANSLATE_TRANSLATE_BUBBLE_VIEW_STATE_TRANSITION_H_
126