OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_TRY_CHROME_DIALOG_VIEW_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_TRY_CHROME_DIALOG_H_ |
6 #define CHROME_BROWSER_UI_VIEWS_TRY_CHROME_DIALOG_VIEW_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_TRY_CHROME_DIALOG_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/time/time.h" |
| 13 #include "chrome/browser/ui/startup/startup_browser_creator.h" |
| 14 #include "chrome/installer/util/experiment_storage.h" |
12 #include "ui/gfx/geometry/rect.h" | 15 #include "ui/gfx/geometry/rect.h" |
13 #include "ui/gfx/geometry/size.h" | 16 #include "ui/gfx/geometry/size.h" |
14 #include "ui/gfx/native_widget_types.h" | 17 #include "ui/gfx/native_widget_types.h" |
15 #include "ui/views/controls/button/button.h" | 18 #include "ui/views/controls/button/button.h" |
16 #include "ui/views/controls/link_listener.h" | |
17 | 19 |
18 namespace views { | 20 namespace views { |
19 class RadioButton; | |
20 class Checkbox; | |
21 class Widget; | 21 class Widget; |
22 } | 22 } |
23 | 23 |
24 // This class displays a modal dialog using the views system. The dialog asks | 24 // This class displays a modal dialog using the views system. The dialog asks |
25 // the user to give chrome another try. This class only handles the UI so the | 25 // the user to give Chrome another try. This class only handles the UI so the |
26 // resulting actions are up to the caller. One flavor looks like this: | 26 // resulting actions are up to the caller. |
| 27 // |
| 28 // The layout is as follows: |
27 // | 29 // |
28 // +-----------------------------------------------+ | 30 // +-----------------------------------------------+ |
29 // | |icon| There is a new, safer version [x] | | 31 // | |icon| Header text. [x] | |
30 // | |icon| of Google Chrome available | | 32 // | | |
31 // | [o] Try it out (already installed) | | 33 // | Body text. | |
32 // | [ ] Uninstall Google Chrome | | 34 // | [ Open Chrome ] [No Thanks] | |
33 // | [ OK ] [Don't bug me] | | |
34 // | _why_am_I_seeing this?_ | | |
35 // +-----------------------------------------------+ | 35 // +-----------------------------------------------+ |
36 // | 36 // |
37 // Another flavor looks like: | 37 // Some variants do not have body text, or only have one button. |
38 // +-----------------------------------------------+ | 38 class TryChromeDialog : public views::ButtonListener { |
39 // | |icon| There is a new, safer version [x] | | |
40 // | |icon| of Google Chrome available | | |
41 // | [o] Try it out (already installed) | | |
42 // | [ ] Don't bug me | | |
43 // | [ OK ] | | |
44 // +-----------------------------------------------+ | |
45 // | |
46 // And the 2013 version looks like: | |
47 // +-----------------------------------------------+ | |
48 // | |icon| There is a new version of [x] | | |
49 // | |icon| Google Chrome available | | |
50 // | [o] Try it out (already installed) | | |
51 // | [ ] Don't bug me | | |
52 // | --------------------------------------------- | | |
53 // | [x] Make it the default browser [ OK ] | | |
54 // +-----------------------------------------------+ | |
55 | |
56 class TryChromeDialogView : public views::ButtonListener, | |
57 public views::LinkListener { | |
58 public: | 39 public: |
59 // Receives a handle to the active modal dialog, or NULL when the active | 40 // Receives a handle to the active modal dialog, or NULL when the active |
60 // dialog is dismissed. | 41 // dialog is dismissed. |
61 typedef base::Callback<void(gfx::NativeWindow active_dialog)> | 42 typedef base::Callback<void(gfx::NativeWindow active_dialog)> |
62 ActiveModalDialogListener; | 43 ActiveModalDialogListener; |
63 | 44 |
64 enum Result { | 45 enum Result { |
65 TRY_CHROME, // Launch chrome right now. | 46 OPEN_CHROME_DEFAULT, // Launch Chrome right now. |
66 TRY_CHROME_AS_DEFAULT, // Launch chrome and make it the default. | 47 OPEN_CHROME_WELCOME, // Launch Chrome to the standard Welcome page. |
67 NOT_NOW, // Don't launch chrome. Exit now. | 48 OPEN_CHROME_WELCOME_WIN10, // Launch Chrome to the Win10 Welcome page. |
68 UNINSTALL_CHROME, // Initiate chrome uninstall and exit. | 49 NOT_NOW, // Don't launch chrome. Exit now. |
69 DIALOG_ERROR, // An error occurred creating the dialog. | 50 DIALOG_ERROR, // An error occurred creating the dialog. |
70 COUNT | 51 COUNT |
71 }; | 52 }; |
72 | 53 |
73 // Shows a modal dialog asking the user to give chrome another try. See | 54 // Shows a modal dialog asking the user to give chrome another try. See |
74 // above for the possible outcomes of the function. This is an experimental, | 55 // above for the possible outcomes of the function. This is an experimental, |
75 // non-localized dialog. | 56 // non-localized dialog. |
76 // |flavor| can be 0, 1, 2 or 3 and selects what strings to present. | 57 // |group| selects what strings to present and what controls are shown. |
77 // |listener| will be notified when the dialog becomes active and when it is | 58 // |listener| will be notified when the dialog becomes active and when it is |
78 // dismissed. | 59 // dismissed. |
79 // Note that the dialog has no parent and it will position itself in a lower | 60 // Note that the dialog has no parent and it will position itself in a lower |
80 // corner of the screen. The dialog does not steal focus and does not have an | 61 // corner of the screen or near the Chrome taskbar button. |
81 // entry in the taskbar. | 62 // The dialog does not steal focus and does not have an entry in the taskbar. |
82 static Result Show(size_t flavor, | 63 static Result Show(size_t group, const ActiveModalDialogListener& listener); |
83 const ActiveModalDialogListener& listener); | 64 |
84 private: | 65 private: |
85 // Indicates whether the dialog is modal | 66 // Indicates whether the dialog is modal |
86 enum class kDialogType { | 67 enum class DialogType { |
87 MODAL, // Modal dialog. | 68 MODAL, // Modal dialog. |
88 MODELESS, // Modeless dialog. | 69 MODELESS_FOR_TEST, // Modeless dialog. |
89 }; | 70 }; |
90 | 71 |
91 // Indicates the usage type. Chrome or tests. | 72 // Indicates the usage type. Chrome or tests. |
92 enum class kUsageType { | 73 enum class UsageType { |
93 FOR_CHROME, | 74 FOR_CHROME, |
94 FOR_TESTING, | 75 FOR_TESTING, |
95 }; | 76 }; |
96 | 77 |
97 friend class TryChromeDialogTest; | 78 friend class TryChromeDialogTest; |
98 | 79 |
99 explicit TryChromeDialogView(size_t flavor); | 80 // Creates a Try Chrome toast dialog. |group| signifies an experiment group |
100 ~TryChromeDialogView() override; | 81 // which dictactes messaging text and presence of ui elements. |
| 82 explicit TryChromeDialog(size_t group); |
| 83 ~TryChromeDialog() override; |
101 | 84 |
102 // Helper function to show the dialog. | 85 // Helper function to show the dialog. |
103 // The |dialog_type| parameter indicates whether the dialog is modal. | 86 // The |dialog_type| parameter indicates whether the dialog is modal. |
| 87 // Note that modeless invocation returns before the user has made a |
| 88 // selection, and is used in testing. |
104 // The |usage_type| parameter indicates whether this is being invoked by | 89 // The |usage_type| parameter indicates whether this is being invoked by |
105 // chrome or a test. | 90 // chrome or a test. |
106 Result ShowDialog(const ActiveModalDialogListener& listener, | 91 Result ShowDialog(const ActiveModalDialogListener& listener, |
107 kDialogType dialog_type, | 92 DialogType dialog_type, |
108 kUsageType usage_type); | 93 UsageType usage_type); |
109 | 94 |
110 // Returns a screen rectangle that is fit to show the window. In particular | 95 // Returns a screen rectangle that is fit to show the window. In particular |
111 // it has the following properties: a) is visible and b) is attached to the | 96 // it has the following properties: a) is visible and b) is attached to the |
112 // bottom of the working area. For LTR machines it returns a left side | 97 // bottom of the working area. For LTR machines it returns a left side |
113 // rectangle and for RTL it returns a right side rectangle so that the dialog | 98 // rectangle and for RTL it returns a right side rectangle so that the dialog |
114 // does not compete with the standard place of the start menu. | 99 // does not compete with the standard place of the start menu. |
115 gfx::Rect ComputeWindowPosition(const gfx::Size& size, bool is_RTL); | 100 gfx::Rect ComputePopupBounds(const gfx::Size& size, bool is_RTL); |
116 | |
117 // Create a windows region that looks like a toast of width |w| and height | |
118 // |h|. This is best effort, so we don't care much if the operation fails. | |
119 void SetToastRegion(HWND window, int w, int h); | |
120 | 101 |
121 // views::ButtonListener: | 102 // views::ButtonListener: |
122 // We have two buttons and according to what the user clicked we set |result_| | 103 // We have two buttons and according to what the user clicked we set |result_| |
123 // and we should always close and end the modal loop. | 104 // and we should always close and end the modal loop. |
124 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | 105 void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
125 | 106 |
126 // views::LinkListener: | 107 // Controls whether we're running in testing config. |
127 // If the user selects the link we need to fire off the default browser that | 108 // Experiment metrics setting is disabled in tests. |
128 // by some convoluted logic should not be chrome. | 109 UsageType usage_type_; |
129 void LinkClicked(views::Link* source, int event_flags) override; | |
130 | 110 |
131 // Controls which flavor of the heading text to use. | 111 // Controls which experiment group to use for varying the layout and controls. |
132 size_t flavor_; | 112 const size_t group_; |
133 | 113 |
134 // We don't own any of these pointers. The |popup_| owns itself and owns the | 114 // Time when the toast was displayed. |
135 // other views. | 115 base::TimeTicks time_shown_; |
| 116 |
| 117 // Unowned; |popup_| owns itself. |
136 views::Widget* popup_; | 118 views::Widget* popup_; |
137 views::RadioButton* try_chrome_; | 119 |
138 views::RadioButton* kill_chrome_; | 120 // Experiment feedback interface. |
139 views::RadioButton* dont_try_chrome_; | 121 installer::ExperimentStorage storage_; |
140 views::Checkbox* make_default_; | 122 |
| 123 // Result of displaying the dialog: accepted, dismissed, etc. |
141 Result result_; | 124 Result result_; |
142 | 125 |
143 DISALLOW_COPY_AND_ASSIGN(TryChromeDialogView); | 126 DISALLOW_COPY_AND_ASSIGN(TryChromeDialog); |
144 }; | 127 }; |
145 | 128 |
146 #endif // CHROME_BROWSER_UI_VIEWS_TRY_CHROME_DIALOG_VIEW_H_ | 129 #endif // CHROME_BROWSER_UI_VIEWS_TRY_CHROME_DIALOG_H_ |
OLD | NEW |