OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 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/login/eula_view.h" |
| 6 |
| 7 #include <signal.h> |
| 8 #include <sys/types.h> |
| 9 #include <string> |
| 10 |
| 11 #include "app/l10n_util.h" |
| 12 #include "app/resource_bundle.h" |
| 13 #include "base/utf_string_conversions.h" |
| 14 #include "chrome/browser/chromeos/login/network_screen_delegate.h" |
| 15 #include "chrome/browser/chromeos/login/rounded_rect_painter.h" |
| 16 #include "chrome/browser/chromeos/login/screen_observer.h" |
| 17 #include "chrome/installer/util/google_update_settings.h" |
| 18 #include "grit/chromium_strings.h" |
| 19 #include "grit/generated_resources.h" |
| 20 #include "grit/theme_resources.h" |
| 21 #include "views/controls/button/checkbox.h" |
| 22 #include "views/controls/button/native_button.h" |
| 23 #include "views/controls/label.h" |
| 24 #include "views/controls/textfield/textfield.h" |
| 25 #include "views/grid_layout.h" |
| 26 #include "views/standard_layout.h" |
| 27 |
| 28 namespace { |
| 29 |
| 30 const int kBorderSize = 10; |
| 31 const int kMargin = 20; |
| 32 const int kLastButtonHorizontalMargin = 10; |
| 33 const int kTextMargin = 10; |
| 34 const int kCheckBowWidth = 22; |
| 35 |
| 36 // Fake EULA texts. TODO(glotov): implement reading actual file. |
| 37 const wchar_t kLoremIpsum[] = L"Lorem ipsum dolor sit amet, " |
| 38 L"consectetur adipisicing elit, sed do eiusmod tempor incididunt ut" |
| 39 L"labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud " |
| 40 L"exercitation ullamco laboris nisi ut aliquip ex ea commodo " |
| 41 L"consequat. Duis aute irure dolor in reprehenderit in voluptate velit " |
| 42 L"esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat " |
| 43 L"cupidatat non proident, sunt in culpa qui officia deserunt mollit anim " |
| 44 L"id est laborum.\n"; |
| 45 const wchar_t kFakeGoogleEula[] = L"\nGoogle Chrome Terms of Service\n" |
| 46 L"These Terms of Service apply to the executable code version of " |
| 47 L"Google Chrome. "; |
| 48 const wchar_t kFakeOemEula[] = L"\nYBH Terms of Service\n"; |
| 49 |
| 50 enum kLayoutColumnsets { |
| 51 SINGLE_CONTROL_ROW, |
| 52 SINGLE_CONTROL_WITH_SHIFT_ROW, |
| 53 SINGLE_LINK_WITH_SHIFT_ROW, |
| 54 LAST_ROW |
| 55 }; |
| 56 |
| 57 } // namespace |
| 58 |
| 59 namespace chromeos { |
| 60 |
| 61 EulaView::EulaView(chromeos::ScreenObserver* observer) |
| 62 : google_eula_text_(NULL), |
| 63 usage_statistics_checkbox_(NULL), |
| 64 learn_more_link_(NULL), |
| 65 oem_eula_text_(NULL), |
| 66 system_security_settings_link_(NULL), |
| 67 cancel_button_(NULL), |
| 68 continue_button_(NULL), |
| 69 observer_(observer) { |
| 70 } |
| 71 |
| 72 EulaView::~EulaView() { |
| 73 } |
| 74 |
| 75 void EulaView::Init() { |
| 76 // Use rounded rect background. |
| 77 views::Painter* painter = CreateWizardPainter( |
| 78 &BorderDefinition::kScreenBorder); |
| 79 set_background( |
| 80 views::Background::CreateBackgroundPainter(true, painter)); |
| 81 |
| 82 // Layout created controls. |
| 83 static const int kPadding = kBorderSize + kMargin; |
| 84 views::GridLayout* layout = new views::GridLayout(this); |
| 85 SetLayoutManager(layout); |
| 86 views::ColumnSet* column_set = layout->AddColumnSet(SINGLE_CONTROL_ROW); |
| 87 column_set->AddPaddingColumn(0, kPadding); |
| 88 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, |
| 89 views::GridLayout::USE_PREF, 0, 0); |
| 90 column_set->AddPaddingColumn(0, kPadding); |
| 91 |
| 92 column_set = layout->AddColumnSet(SINGLE_CONTROL_WITH_SHIFT_ROW); |
| 93 column_set->AddPaddingColumn(0, kPadding + kTextMargin); |
| 94 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, |
| 95 views::GridLayout::USE_PREF, 0, 0); |
| 96 column_set->AddPaddingColumn(0, kPadding); |
| 97 |
| 98 column_set = layout->AddColumnSet(SINGLE_LINK_WITH_SHIFT_ROW); |
| 99 column_set->AddPaddingColumn(0, kPadding + kTextMargin + kCheckBowWidth); |
| 100 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1, |
| 101 views::GridLayout::USE_PREF, 0, 0); |
| 102 column_set->AddPaddingColumn(0, kPadding); |
| 103 |
| 104 column_set = layout->AddColumnSet(LAST_ROW); |
| 105 column_set->AddPaddingColumn(0, kPadding + kTextMargin); |
| 106 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1, |
| 107 views::GridLayout::USE_PREF, 0, 0); |
| 108 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0, |
| 109 views::GridLayout::USE_PREF, 0, 0); |
| 110 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); |
| 111 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0, |
| 112 views::GridLayout::USE_PREF, 0, 0); |
| 113 column_set->AddPaddingColumn(0, kLastButtonHorizontalMargin + kBorderSize); |
| 114 |
| 115 layout->AddPaddingRow(0, kPadding); |
| 116 layout->StartRow(1, SINGLE_CONTROL_ROW); |
| 117 google_eula_text_ = new views::Textfield(views::Textfield::STYLE_MULTILINE); |
| 118 google_eula_text_->SetReadOnly(true); |
| 119 google_eula_text_->SetFocusable(true); |
| 120 google_eula_text_->SetHorizontalMargins(kTextMargin, kTextMargin); |
| 121 layout->AddView(google_eula_text_); |
| 122 |
| 123 layout->StartRow(0, SINGLE_CONTROL_WITH_SHIFT_ROW); |
| 124 usage_statistics_checkbox_ = new views::Checkbox(); |
| 125 usage_statistics_checkbox_->SetMultiLine(true); |
| 126 usage_statistics_checkbox_->SetChecked( |
| 127 GoogleUpdateSettings::GetCollectStatsConsent()); |
| 128 layout->AddView(usage_statistics_checkbox_); |
| 129 |
| 130 layout->StartRow(0, SINGLE_LINK_WITH_SHIFT_ROW); |
| 131 learn_more_link_ = new views::Link(); |
| 132 learn_more_link_->SetController(this); |
| 133 layout->AddView(learn_more_link_); |
| 134 |
| 135 layout->AddPaddingRow(0, kRelatedControlSmallVerticalSpacing); |
| 136 layout->StartRow(1, SINGLE_CONTROL_ROW); |
| 137 oem_eula_text_ = new views::Textfield(views::Textfield::STYLE_MULTILINE); |
| 138 oem_eula_text_->SetReadOnly(true); |
| 139 oem_eula_text_->SetFocusable(true); |
| 140 oem_eula_text_->SetHorizontalMargins(kTextMargin, kTextMargin); |
| 141 layout->AddView(oem_eula_text_); |
| 142 |
| 143 layout->AddPaddingRow(0, kRelatedControlSmallVerticalSpacing); |
| 144 layout->StartRow(0, LAST_ROW); |
| 145 system_security_settings_link_ = new views::Link(); |
| 146 system_security_settings_link_->SetController(this); |
| 147 layout->AddView(system_security_settings_link_); |
| 148 |
| 149 cancel_button_ = new views::NativeButton(this, std::wstring()); |
| 150 cancel_button_->SetEnabled(false); |
| 151 layout->AddView(cancel_button_); |
| 152 |
| 153 continue_button_ = new views::NativeButton(this, std::wstring()); |
| 154 layout->AddView(continue_button_); |
| 155 layout->AddPaddingRow(0, kPadding); |
| 156 |
| 157 UpdateLocalizedStrings(); |
| 158 } |
| 159 |
| 160 void EulaView::UpdateLocalizedStrings() { |
| 161 google_eula_text_->SetText(WideToUTF16(kFakeGoogleEula) + |
| 162 WideToUTF16(kLoremIpsum) + |
| 163 WideToUTF16(kLoremIpsum)); |
| 164 oem_eula_text_->SetText(WideToUTF16(kFakeOemEula) + |
| 165 WideToUTF16(kLoremIpsum) + |
| 166 WideToUTF16(kLoremIpsum)); |
| 167 usage_statistics_checkbox_->SetLabel( |
| 168 l10n_util::GetString(IDS_EULA_CHECKBOX_ENABLE_LOGGING)); |
| 169 learn_more_link_->SetText( |
| 170 l10n_util::GetString(IDS_LEARN_MORE)); |
| 171 system_security_settings_link_->SetText( |
| 172 l10n_util::GetString(IDS_EULA_SYSTEM_SECURITY_SETTINGS_LINK)); |
| 173 continue_button_->SetLabel( |
| 174 l10n_util::GetString(IDS_EULA_ACCEPT_AND_CONTINUE_BUTTON)); |
| 175 cancel_button_->SetLabel( |
| 176 l10n_util::GetString(IDS_CANCEL)); |
| 177 } |
| 178 |
| 179 //////////////////////////////////////////////////////////////////////////////// |
| 180 // views::View: implementation: |
| 181 |
| 182 void EulaView::LocaleChanged() { |
| 183 UpdateLocalizedStrings(); |
| 184 Layout(); |
| 185 } |
| 186 |
| 187 //////////////////////////////////////////////////////////////////////////////// |
| 188 // views::ButtonListener implementation: |
| 189 |
| 190 void EulaView::ButtonPressed(views::Button* sender, const views::Event& event) { |
| 191 if (sender == continue_button_) { |
| 192 if (usage_statistics_checkbox_) { |
| 193 GoogleUpdateSettings::SetCollectStatsConsent( |
| 194 usage_statistics_checkbox_->checked()); |
| 195 } |
| 196 observer_->OnExit(ScreenObserver::EULA_ACCEPTED); |
| 197 } |
| 198 // TODO(glotov): handle cancel button. |
| 199 } |
| 200 |
| 201 //////////////////////////////////////////////////////////////////////////////// |
| 202 // views::LinkController implementation: |
| 203 |
| 204 void EulaView::LinkActivated(views::Link* source, int event_flags) { |
| 205 // TODO(glotov): handle link clicks. |
| 206 } |
| 207 |
| 208 } // namespace chromeos |
OLD | NEW |