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_VIEW_H_ |
6 #define CHROME_BROWSER_UI_VIEWS_TRY_CHROME_DIALOG_VIEW_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_TRY_CHROME_DIALOG_VIEW_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" | |
15 #include "ui/gfx/font_list.h" | |
12 #include "ui/gfx/geometry/rect.h" | 16 #include "ui/gfx/geometry/rect.h" |
13 #include "ui/gfx/geometry/size.h" | 17 #include "ui/gfx/geometry/size.h" |
14 #include "ui/gfx/native_widget_types.h" | 18 #include "ui/gfx/native_widget_types.h" |
15 #include "ui/views/controls/button/button.h" | 19 #include "ui/views/controls/button/button.h" |
16 #include "ui/views/controls/link_listener.h" | |
17 | 20 |
18 namespace views { | 21 namespace views { |
19 class RadioButton; | |
20 class Checkbox; | |
21 class Widget; | 22 class Widget; |
22 } | 23 } |
23 | 24 |
24 // This class displays a modal dialog using the views system. The dialog asks | 25 // 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 | 26 // 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: | 27 // resulting actions are up to the caller. |
28 // | |
29 // The layout is as follows: | |
27 // | 30 // |
28 // +-----------------------------------------------+ | 31 // +-----------------------------------------------+ |
29 // | |icon| There is a new, safer version [x] | | 32 // | |icon| Header text. [x] | |
30 // | |icon| of Google Chrome available | | 33 // | | |
31 // | [o] Try it out (already installed) | | 34 // | Body text. | |
32 // | [ ] Uninstall Google Chrome | | 35 // | [ Open Chrome ] [No Thanks] | |
33 // | [ OK ] [Don't bug me] | | |
34 // | _why_am_I_seeing this?_ | | |
35 // +-----------------------------------------------+ | 36 // +-----------------------------------------------+ |
36 // | 37 // |
37 // Another flavor looks like: | 38 // Some variants do not have body text, or only have one button. |
38 // +-----------------------------------------------+ | 39 class TryChromeDialogView : public views::ButtonListener { |
sky
2017/06/23 17:45:52
I would expect a class named View to be a View, bu
sky
2017/06/23 17:45:52
Is there a test for this class? At a minimum you s
skare_
2017/06/24 01:08:59
yes, there is a preexisting test, though it's the
skare_
2017/06/24 01:09:00
Named TryChromeDialog within this file, renamed th
| |
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: | 40 public: |
59 // Receives a handle to the active modal dialog, or NULL when the active | 41 // Receives a handle to the active modal dialog, or NULL when the active |
60 // dialog is dismissed. | 42 // dialog is dismissed. |
61 typedef base::Callback<void(gfx::NativeWindow active_dialog)> | 43 typedef base::Callback<void(gfx::NativeWindow active_dialog)> |
62 ActiveModalDialogListener; | 44 ActiveModalDialogListener; |
63 | 45 |
64 enum Result { | 46 enum Result { |
65 TRY_CHROME, // Launch chrome right now. | 47 OPEN_CHROME, // Launch chrome right now. |
66 TRY_CHROME_AS_DEFAULT, // Launch chrome and make it the default. | 48 NOT_NOW, // Don't launch chrome. Exit now. |
67 NOT_NOW, // Don't launch chrome. Exit now. | 49 DIALOG_ERROR, // An error occurred creating the dialog. |
68 UNINSTALL_CHROME, // Initiate chrome uninstall and exit. | |
69 DIALOG_ERROR, // An error occurred creating the dialog. | |
70 COUNT | 50 COUNT |
71 }; | 51 }; |
72 | 52 |
73 // Shows a modal dialog asking the user to give chrome another try. See | 53 // 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, | 54 // above for the possible outcomes of the function. This is an experimental, |
75 // non-localized dialog. | 55 // non-localized dialog. |
76 // |flavor| can be 0, 1, 2 or 3 and selects what strings to present. | 56 // |group| selects what strings to present and what controls are shown. |
sky
2017/06/23 17:45:53
Can group be an enum, that helps document what the
skare_
2017/06/24 01:09:00
It's passed in as an integer through the experimen
grt (UTC plus 2)
2017/06/24 20:55:11
kExperiments (in the .cc file) effectively describ
sky
2017/06/26 16:12:05
Agreed, keep it as an int.
| |
77 // |listener| will be notified when the dialog becomes active and when it is | 57 // |listener| will be notified when the dialog becomes active and when it is |
78 // dismissed. | 58 // dismissed. |
79 // Note that the dialog has no parent and it will position itself in a lower | 59 // 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 | 60 // corner of the screen or near the Chrome taskbar button. |
81 // entry in the taskbar. | 61 // The dialog does not steal focus and does not have an entry in the taskbar. |
82 static Result Show(size_t flavor, | 62 static Result Show(size_t group, |
83 const ActiveModalDialogListener& listener); | 63 const ActiveModalDialogListener& listener, |
sky
2017/06/23 17:45:52
The callback should take the welcome_page as a val
skare_
2017/06/24 01:09:00
I'll change Result to carry this info.
grt (UTC plus 2)
2017/06/24 20:55:11
i don't understand the suggestion. by "the callbac
| |
64 StartupBrowserCreator::WelcomeBackPage* welcome_page); | |
65 | |
84 private: | 66 private: |
85 // Indicates whether the dialog is modal | 67 // Indicates whether the dialog is modal |
86 enum class kDialogType { | 68 enum class kDialogType { |
sky
2017/06/23 17:45:52
This is super confusing as enums should not have k
skare_
2017/06/24 01:09:00
Done.
| |
87 MODAL, // Modal dialog. | 69 MODAL, // Modal dialog. |
88 MODELESS, // Modeless dialog. | 70 MODELESS, // Modeless dialog. |
89 }; | 71 }; |
90 | 72 |
91 // Indicates the usage type. Chrome or tests. | 73 // Indicates the usage type. Chrome or tests. |
92 enum class kUsageType { | 74 enum class kUsageType { |
93 FOR_CHROME, | 75 FOR_CHROME, |
94 FOR_TESTING, | 76 FOR_TESTING, |
95 }; | 77 }; |
96 | 78 |
97 friend class TryChromeDialogTest; | 79 friend class TryChromeDialogTest; |
98 | 80 |
99 explicit TryChromeDialogView(size_t flavor); | 81 explicit TryChromeDialogView(size_t group); |
sky
2017/06/23 17:45:53
Document what group is here.
skare_
2017/06/24 01:09:00
Done.
| |
100 ~TryChromeDialogView() override; | 82 ~TryChromeDialogView() override; |
101 | 83 |
102 // Helper function to show the dialog. | 84 // Helper function to show the dialog. |
103 // The |dialog_type| parameter indicates whether the dialog is modal. | 85 // The |dialog_type| parameter indicates whether the dialog is modal. |
104 // The |usage_type| parameter indicates whether this is being invoked by | 86 // The |usage_type| parameter indicates whether this is being invoked by |
105 // chrome or a test. | 87 // chrome or a test. |
106 Result ShowDialog(const ActiveModalDialogListener& listener, | 88 Result ShowDialog(const ActiveModalDialogListener& listener, |
107 kDialogType dialog_type, | 89 kDialogType dialog_type, |
108 kUsageType usage_type); | 90 kUsageType usage_type); |
109 | 91 |
110 // Returns a screen rectangle that is fit to show the window. In particular | 92 // 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 | 93 // 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 | 94 // 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 | 95 // 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. | 96 // does not compete with the standard place of the start menu. |
115 gfx::Rect ComputeWindowPosition(const gfx::Size& size, bool is_RTL); | 97 gfx::Rect ComputeWindowPosition(const gfx::Size& size, bool is_RTL); |
116 | 98 |
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 | |
121 // views::ButtonListener: | 99 // views::ButtonListener: |
122 // We have two buttons and according to what the user clicked we set |result_| | 100 // 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. | 101 // and we should always close and end the modal loop. |
124 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | 102 void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
125 | 103 |
126 // views::LinkListener: | 104 // Controls which experiment group to use for varying the layout and controls. |
127 // If the user selects the link we need to fire off the default browser that | 105 size_t group_; |
sky
2017/06/23 17:45:52
const
skare_
2017/06/24 01:09:00
Done.
| |
128 // by some convoluted logic should not be chrome. | |
129 void LinkClicked(views::Link* source, int event_flags) override; | |
130 | 106 |
131 // Controls which flavor of the heading text to use. | 107 // Font list used by text and buttons. |
132 size_t flavor_; | 108 gfx::FontList font_list_; |
133 | 109 |
134 // We don't own any of these pointers. The |popup_| owns itself and owns the | 110 // Bounds for Chrome icon on taskbar if pinned. Empty if not pinned. |
135 // other views. | 111 // TODO(skare): Pull from https://codereview.chromium.org/2900653002 |
112 gfx::Rect chrome_taskbar_rect_; | |
113 | |
114 // Time when the toast was displayed. | |
115 base::Time time_shown_; | |
sky
2017/06/23 17:45:52
const.
And remember that time can go backwards. Wh
skare_
2017/06/24 01:09:00
(const done, ->TimeTicks outstanding) -
@nikunjb
sky
2017/07/18 17:10:31
Was this comment resolved? Again, I think you shou
skare_
2017/07/21 03:11:35
used ticks to compute the delta, Time::Now() for t
| |
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(TryChromeDialogView); |
144 }; | 127 }; |
145 | 128 |
146 #endif // CHROME_BROWSER_UI_VIEWS_TRY_CHROME_DIALOG_VIEW_H_ | 129 #endif // CHROME_BROWSER_UI_VIEWS_TRY_CHROME_DIALOG_VIEW_H_ |
OLD | NEW |