Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(165)

Side by Side Diff: chrome/browser/chromeos/profiles/multiprofiles_intro_view.cc

Issue 93633007: Created optional multiprofiles introduction dialog. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 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 #include "chrome/browser/chromeos/profiles/multiprofiles_intro_view.h"
6
7 #include "base/prefs/pref_service.h"
8 #include "chrome/browser/chromeos/login/login_display_host_impl.h"
9 #include "chrome/browser/chromeos/login/user_adding_screen.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/profiles/profile_manager.h"
12 #include "chrome/browser/ui/browser_finder.h"
13 #include "chrome/browser/ui/browser_window.h"
14 #include "chrome/common/pref_names.h"
15 #include "grit/generated_resources.h"
16 #include "ui/base/l10n/l10n_util.h"
17 #include "ui/base/resource/resource_bundle.h"
18 #include "ui/views/controls/button/checkbox.h"
19 #include "ui/views/controls/label.h"
20 #include "ui/views/layout/grid_layout.h"
21 #include "ui/views/widget/widget.h"
22 #include "ui/views/window/dialog_delegate.h"
23
24 namespace chromeos {
25
26 namespace {
27
28 gfx::NativeWindow GetDialogParent() {
29 if (chromeos::LoginDisplayHostImpl::default_host()) {
30 return chromeos::LoginDisplayHostImpl::default_host()->GetNativeWindow();
31 } else {
32 Browser* browser = chrome::FindTabbedBrowser(
33 ProfileManager::GetDefaultProfileOrOffTheRecord(),
34 true,
35 chrome::HOST_DESKTOP_TYPE_ASH);
36 if (browser)
37 return browser->window()->GetNativeWindow();
38 }
39 return NULL;
40 }
41
42 // Default width/height of the dialog.
43 const int kDefaultWidth = 600;
44 const int kDefaultHeight = 250;
45
46 const int kPaddingToMessage = 30;
47 const int kPaddingToCheckBox = 50;
48
49 ////////////////////////////////////////////////////////////////////////////////
50 // Dialog for multi-profiles introduction.
51 class MultiprofilesIntroView : public views::DialogDelegateView {
52 public:
53 MultiprofilesIntroView();
54 virtual ~MultiprofilesIntroView();
55
56 static void ShowDialog(gfx::NativeWindow owning_window);
57
58 virtual bool Accept() OVERRIDE;
59
60 // views::WidgetDelegate overrides
61 virtual ui::ModalType GetModalType() const OVERRIDE;
62 virtual base::string16 GetWindowTitle() const OVERRIDE;
63
64 // views::View overrides
65 virtual gfx::Size GetPreferredSize() OVERRIDE;
66
67 private:
68 void InitDialog();
69
70 scoped_ptr<views::Checkbox> no_show_checkbox_;
71 };
72
73 ////////////////////////////////////////////////////////////////////////////////
74 // MultiprofilesIntroView implementation.
75
76 MultiprofilesIntroView::MultiprofilesIntroView() {
77 }
78
79 MultiprofilesIntroView::~MultiprofilesIntroView() {
80 }
81
82 // static
83 void MultiprofilesIntroView::ShowDialog(gfx::NativeWindow owning_window) {
84 MultiprofilesIntroView* dialog_view =
85 new MultiprofilesIntroView();
86 views::DialogDelegate::CreateDialogWidget(dialog_view, NULL, owning_window);
dzhioev (left Google) 2013/12/20 03:39:01 I think your choice of owning_window is not right.
merkulova 2014/01/10 15:16:52 Done.
87 dialog_view->InitDialog();
88 views::Widget* widget = dialog_view->GetWidget();
89 DCHECK(widget);
90 widget->Show();
91 }
92
93 bool MultiprofilesIntroView::Accept() {
94 PrefService* prefs = ProfileManager::GetActiveUserProfile()->GetPrefs();
95 prefs->SetBoolean(prefs::kMultiProfileIntroShowDismissed,
96 no_show_checkbox_->checked());
dzhioev (left Google) 2013/12/20 03:39:01 nit: fix indent
merkulova 2014/01/10 15:16:52 Done.
97 UserAddingScreen::Get()->Start();
98 return true;
99 }
100
101 ui::ModalType MultiprofilesIntroView::GetModalType() const {
102 return ui::MODAL_TYPE_SYSTEM;
103 }
104
105 base::string16 MultiprofilesIntroView::GetWindowTitle() const {
106 return l10n_util::GetStringUTF16(IDS_MULTIPROFILES_INTRO_HEADLINE);
107 }
108
109 gfx::Size MultiprofilesIntroView::GetPreferredSize() {
110 return gfx::Size(kDefaultWidth, kDefaultHeight);
dzhioev (left Google) 2013/12/20 03:39:01 I think default implementation of GetPreferredSize
merkulova 2014/01/10 15:16:52 As discussed offline, it's the easiest way to set
111 }
112
113 void MultiprofilesIntroView::InitDialog() {
114 // Create the views and layout manager and set them up.
115 views::GridLayout* grid_layout = views::GridLayout::CreatePanel(this);
116 SetLayoutManager(grid_layout);
117 views::ColumnSet* column_set = grid_layout->AddColumnSet(0);
118 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
119 views::GridLayout::USE_PREF, 0, 0);
120
121 // Explanation string
122 views::Label* label = new views::Label(
123 l10n_util::GetStringUTF16(IDS_MULTIPROFILES_INTRO_MESSAGE));
124 label->SetFont(ui::ResourceBundle::GetSharedInstance().GetFont(
dzhioev (left Google) 2013/12/20 03:39:01 Is it necessary? Isn't BaseFont set by default? Mo
merkulova 2014/01/10 15:16:52 Done.
125 ui::ResourceBundle::BaseFont));
126 label->SetMultiLine(true);
127 label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
128 label->SetAllowCharacterBreak(true);
129 grid_layout->StartRow(0, 0);
130 grid_layout->AddView(label);
131
132 // Next explanation string
133 grid_layout->AddPaddingRow(0, kPaddingToMessage);
134 views::Label* lower_label = new views::Label(
135 l10n_util::GetStringUTF16(IDS_MULTIPROFILES_INTRO_EXPLANATION));
136 lower_label->SetFont(ui::ResourceBundle::GetSharedInstance().GetFont(
137 ui::ResourceBundle::BaseFont));
138 lower_label->SetMultiLine(true);
139 lower_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
140 lower_label->SetAllowCharacterBreak(true);
141 grid_layout->StartRow(0, 0);
142 grid_layout->AddView(lower_label);
143
144 // No-show again checkbox
145 grid_layout->AddPaddingRow(0, kPaddingToCheckBox);
146 no_show_checkbox_.reset(new views::Checkbox(
147 l10n_util::GetStringUTF16(IDS_MULTIPROFILES_INTRO_NOSHOW_AGAIN)));
148 no_show_checkbox_->SetChecked(true);
149 grid_layout->StartRow(0, 0);
150 grid_layout->AddView(no_show_checkbox_.get());
151
152 grid_layout->Layout(this);
dzhioev (left Google) 2013/12/20 03:39:01 Is this call needed?
merkulova 2014/01/10 15:16:52 Yes, it's necessary. Done.
153 }
154
155 } // namespace
156
157 ////////////////////////////////////////////////////////////////////////////////
158 // Factory function.
159
160 namespace multiprofiles {
161
162 bool IntroDialog() {
163 gfx::NativeWindow parent = GetDialogParent();
164 MultiprofilesIntroView::ShowDialog(parent);
165 return true;
dzhioev (left Google) 2013/12/20 03:39:01 Why do we need return value if it is always true a
merkulova 2014/01/10 15:16:52 Done.
166 }
167
168 } // namespace multiprofiles
169
170 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698