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

Side by Side Diff: chrome/browser/views/options/user_data_page_view.cc

Issue 160598: Add files to browser/sync. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 4 months 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 | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2006-2008 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 #ifdef CHROME_PERSONALIZATION
6
7 #include "chrome/browser/views/user_data_page_view.h"
8
9 #include "app/l10n_util.h"
10 #include "base/path_service.h"
11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/profile.h"
13 #include "chrome/browser/profile_manager.h"
14 #include "chrome/browser/sync/auth_error_state.h"
15 #include "chrome/browser/sync/personalization_strings.h"
16 #include "chrome/browser/sync/profile_sync_service.h"
17 #include "chrome/browser/sync/sync_status_ui_helper.h"
18 #include "chrome/browser/views/clear_browsing_data.h"
19 #include "chrome/browser/views/importer_view.h"
20 #include "chrome/browser/views/options/options_group_view.h"
21 #include "chrome/browser/views/options/options_page_view.h"
22 #include "chrome/common/chrome_paths.h"
23 #include "chrome/common/pref_member.h"
24 #include "chrome/common/pref_service.h"
25 #include "grit/generated_resources.h"
26 #include "third_party/skia/include/core/SkColor.h"
27 #include "views/background.h"
28 #include "views/controls/button/native_button.h"
29 #include "views/controls/label.h"
30 #include "views/controls/link.h"
31 #include "views/controls/table/table_view.h"
32 #include "views/grid_layout.h"
33 #include "views/standard_layout.h"
34 #include "views/view.h"
35 #include "views/widget/widget.h"
36 #include "views/window/window.h"
37
38 // Background color for the status label when it's showing an error.
39 static const SkColor kSyncLabelErrorBgColor = SkColorSetRGB(0xff, 0x9a, 0x9a);
40
41 static views::Background* CreateErrorBackground() {
42 return views::Background::CreateSolidBackground(kSyncLabelErrorBgColor);
43 }
44
45 UserDataPageView::UserDataPageView(Profile* profile)
46 : OptionsPageView(profile),
47 sync_group_(NULL),
48 sync_status_label_(NULL),
49 sync_action_link_(NULL),
50 sync_start_stop_button_(NULL),
51 sync_service_(profile->GetProfilePersonalization()->sync_service()) {
52 DCHECK(sync_service_);
53 sync_service_->AddObserver(this);
54 }
55
56 UserDataPageView::~UserDataPageView() {
57 sync_service_->RemoveObserver(this);
58 }
59
60 void UserDataPageView::ButtonPressed(views::Button* sender) {
61 DCHECK(sender == sync_start_stop_button_);
62 if (!sync_service_->IsSyncEnabledByUser()) {
63 // Sync has not been enabled yet.
64 sync_service_->EnableForUser();
65 } else {
66 sync_service_->DisableForUser();
67 }
68 }
69
70 void UserDataPageView::LinkActivated(views::Link* source, int event_flags) {
71 DCHECK_EQ(source, sync_action_link_);
72 sync_service_->ShowLoginDialog();
73 }
74
75 void UserDataPageView::InitControlLayout() {
76 using views::GridLayout;
77 using views::ColumnSet;
78
79 GridLayout* layout = new GridLayout(this);
80 layout->SetInsets(5, 5, 5, 5);
81 SetLayoutManager(layout);
82
83 const int single_column_view_set_id = 0;
84 ColumnSet* column_set = layout->AddColumnSet(single_column_view_set_id);
85 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1,
86 GridLayout::USE_PREF, 0, 0);
87 layout->StartRow(0, single_column_view_set_id);
88 InitSyncGroup();
89 layout->AddView(sync_group_);
90 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
91 }
92
93 void UserDataPageView::NotifyPrefChanged(const std::wstring* pref_name) {
94 }
95
96 void UserDataPageView::OnStateChanged() {
97 // If the UI controls are not yet initialized, then don't do anything. This
98 // can happen if the Options dialog is up, but the User Data tab is not yet
99 // clicked.
100 if (IsInitialized())
101 Layout();
102 }
103
104 void UserDataPageView::HighlightGroup(OptionsGroup highlight_group) {
105 }
106
107 void UserDataPageView::Layout() {
108 UpdateControls();
109 // We need to Layout twice - once to get the width of the contents box...
110 View::Layout();
111 int sync_group_width = sync_group_->GetContentsWidth();
112 sync_status_label_->SetBounds(0, 0, sync_group_width, 0);
113 // ... and twice to get the height of multi-line items correct.
114 View::Layout();
115 }
116
117 void UserDataPageView::InitSyncGroup() {
118 sync_status_label_ = new views::Label;
119 sync_status_label_->SetMultiLine(true);
120 sync_status_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
121
122 sync_action_link_ = new views::Link();
123 sync_action_link_->set_collapse_when_hidden(true);
124 sync_action_link_->SetController(this);
125
126 sync_start_stop_button_ = new views::NativeButton(this, std::wstring());
127
128 using views::GridLayout;
129 using views::ColumnSet;
130
131 views::View* contents = new views::View;
132 GridLayout* layout = new GridLayout(contents);
133 contents->SetLayoutManager(layout);
134
135 const int single_column_view_set_id = 0;
136 ColumnSet* column_set = layout->AddColumnSet(single_column_view_set_id);
137 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 1,
138 GridLayout::USE_PREF, 0, 0);
139
140 // Currently we add the status label and the link in two rows. This is not
141 // the same as the mocks. If we add label and the link in two columns to make
142 // it look like the mocks then we can have a UI layout issue. If the label
143 // has text that fits in one line, the appearance is fine. But if the label
144 // has text with multiple lines, the appearance can be a bit detached. See
145 // bug 1648522 for details.
146 // TODO(munjal): Change the layout after we fix bug 1648522.
147 layout->StartRow(0, single_column_view_set_id);
148 layout->AddView(sync_status_label_);
149 layout->StartRow(0, single_column_view_set_id);
150 layout->AddView(sync_action_link_);
151 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
152 layout->StartRow(0, single_column_view_set_id);
153 layout->AddView(sync_start_stop_button_);
154
155 sync_group_ = new OptionsGroupView(contents,
156 kSyncGroupName,
157 std::wstring(),
158 true);
159 }
160
161 void UserDataPageView::UpdateControls() {
162 std::wstring status_label;
163 std::wstring link_label;
164 std::wstring button_label;
165 bool sync_enabled = sync_service_->IsSyncEnabledByUser();
166 bool status_has_error = SyncStatusUIHelper::GetLabels(sync_service_,
167 &status_label, &link_label) == SyncStatusUIHelper::SYNC_ERROR;
168 button_label = sync_enabled ? kStopSyncButtonLabel :
169 sync_service_->SetupInProgress() ? UTF8ToWide(kSettingUpText)
170 : kStartSyncButtonLabel;
171
172 sync_status_label_->SetText(status_label);
173 sync_start_stop_button_->SetEnabled(!sync_service_->WizardIsVisible());
174 sync_start_stop_button_->SetLabel(button_label);
175 sync_action_link_->SetText(link_label);
176 sync_action_link_->SetVisible(!link_label.empty());
177 if (status_has_error) {
178 sync_status_label_->set_background(CreateErrorBackground());
179 sync_action_link_->set_background(CreateErrorBackground());
180 } else {
181 sync_status_label_->set_background(NULL);
182 sync_action_link_->set_background(NULL);
183 }
184 }
185
186 #endif // CHROME_PERSONALIZATION
OLDNEW
« no previous file with comments | « chrome/browser/views/options/user_data_page_view.h ('k') | chrome/browser/views/sync/sync_setup_flow.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698