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

Side by Side Diff: chrome/browser/chromeos/login/network_selection_view.cc

Issue 8436002: [cros] Remove Views implementation for login/OOBE. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 9 years, 1 month 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
OLDNEW
(Empty)
1 // Copyright (c) 2011 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/network_selection_view.h"
6
7 #include <signal.h>
8 #include <sys/types.h>
9
10 #include <string>
11
12 #include "base/utf_string_conversions.h"
13 #include "chrome/browser/chromeos/login/helper.h"
14 #include "chrome/browser/chromeos/login/keyboard_switch_menu.h"
15 #include "chrome/browser/chromeos/login/language_switch_menu.h"
16 #include "chrome/browser/chromeos/login/proxy_settings_dialog.h"
17 #include "chrome/browser/chromeos/login/rounded_rect_painter.h"
18 #include "chrome/browser/chromeos/login/views_network_screen_actor.h"
19 #include "chrome/browser/chromeos/login/wizard_accessibility_helper.h"
20 #include "chrome/browser/chromeos/status/network_dropdown_button.h"
21 #include "grit/chromium_strings.h"
22 #include "grit/generated_resources.h"
23 #include "grit/theme_resources.h"
24 #include "ui/base/l10n/l10n_util.h"
25 #include "ui/base/resource/resource_bundle.h"
26 #include "ui/gfx/color_utils.h"
27 #include "ui/gfx/size.h"
28 #include "views/controls/button/text_button.h"
29 #include "views/controls/label.h"
30 #include "views/controls/link.h"
31 #include "views/controls/throbber.h"
32 #include "views/layout/fill_layout.h"
33 #include "views/layout/grid_layout.h"
34 #include "views/layout/layout_constants.h"
35 #include "views/widget/widget.h"
36 #include "views/window/non_client_view.h"
37
38 using views::Background;
39 using views::GridLayout;
40 using views::Label;
41 using views::View;
42 using views::Widget;
43
44 namespace {
45
46 enum kLayoutColumnsets {
47 STANDARD_ROW,
48 THROBBER_ROW,
49 };
50
51 enum kContentsLayoutColumnsets {
52 WELCOME_ROW,
53 CONTENTS_ROW,
54 };
55
56 // Grid layout constants.
57 const int kBorderSize = 10;
58 const int kWelcomeTitlePadding = 10;
59 const int kPaddingColumnWidth = 55;
60 const int kMediumPaddingColumnWidth = 20;
61 const int kControlPaddingRow = 15;
62
63 // Fixed size for language/keyboard/network controls height.
64 const int kSelectionBoxHeight = 29;
65
66 // Menu button is drawn using our custom icons in resources. See
67 // TextButtonBorder::OnPaint() for details. So this offset compensate
68 // horizontal size, eaten by those icons.
69 const int kMenuHorizontalOffset = -3;
70
71 // Vertical addition to the menu window to make it appear exactly below
72 // MenuButton.
73 const int kMenuVerticalOffset = -1;
74
75 // Offset that compensates menu width so that it matches
76 // menu button visual width when being in pushed state.
77 const int kMenuWidthOffset = 6;
78
79 const SkColor kWelcomeColor = 0xFFCDD3D6;
80
81 // Initializes menu button default properties.
82 static void InitMenuButtonProperties(views::MenuButton* menu_button) {
83 menu_button->set_focusable(true);
84 menu_button->SetEnabledColor(SK_ColorBLACK);
85 menu_button->SetHighlightColor(SK_ColorBLACK);
86 menu_button->SetHoverColor(SK_ColorBLACK);
87 static_cast<views::TextButtonBorder*>(menu_button->border())->
88 copy_normal_set_to_hot_set();
89 menu_button->set_animate_on_state_change(false);
90 // Menu is positioned by bottom right corner of the MenuButton.
91 menu_button->set_menu_offset(kMenuHorizontalOffset, kMenuVerticalOffset);
92 }
93
94 static void SetMenuButtonFont(views::MenuButton* menu_button,
95 const gfx::Font& font) {
96 menu_button->SetFont(font);
97 chromeos::CorrectMenuButtonFontSize(menu_button);
98 }
99
100 } // namespace
101
102 namespace chromeos {
103
104 // NetworkDropdownButton with custom Activate() behavior.
105 class NetworkControlReportOnActivate : public NetworkDropdownButton {
106 public:
107 NetworkControlReportOnActivate(bool browser_mode,
108 gfx::NativeWindow parent_window,
109 ViewsNetworkScreenActor* actor)
110 : NetworkDropdownButton(browser_mode, parent_window, false),
111 actor_(actor) {}
112
113 // Overridden from MenuButton:
114 virtual bool Activate() {
115 actor_->ClearErrors();
116 return MenuButton::Activate();
117 }
118
119 private:
120 ViewsNetworkScreenActor* actor_;
121
122 DISALLOW_COPY_AND_ASSIGN(NetworkControlReportOnActivate);
123 };
124
125 // MenuButton with custom processing on focus events.
126 class NotifyingMenuButton : public DropDownButton {
127 public:
128 NotifyingMenuButton(views::ButtonListener* listener,
129 const string16& text,
130 views::ViewMenuDelegate* menu_delegate,
131 bool show_menu_marker,
132 ViewsNetworkScreenActor* actor)
133 : DropDownButton(listener, text, menu_delegate, show_menu_marker),
134 actor_(actor) {}
135
136 // Overridden from View:
137 virtual void OnFocus() OVERRIDE {
138 actor_->ClearErrors();
139 GetWidget()->NotifyAccessibilityEvent(
140 this, ui::AccessibilityTypes::EVENT_FOCUS, true);
141 }
142
143 private:
144 ViewsNetworkScreenActor* actor_;
145
146 DISALLOW_COPY_AND_ASSIGN(NotifyingMenuButton);
147 };
148
149 NetworkSelectionView::NetworkSelectionView(ViewsNetworkScreenActor* actor)
150 : entire_screen_view_(NULL),
151 contents_view_(NULL),
152 languages_menubutton_(NULL),
153 keyboards_menubutton_(NULL),
154 welcome_label_(NULL),
155 select_language_label_(NULL),
156 select_keyboard_label_(NULL),
157 select_network_label_(NULL),
158 connecting_network_label_(NULL),
159 network_dropdown_(NULL),
160 continue_button_(NULL),
161 throbber_(CreateDefaultSmoothedThrobber()),
162 proxy_settings_link_(NULL),
163 show_keyboard_button_(false),
164 actor_(actor) {
165 }
166
167 NetworkSelectionView::~NetworkSelectionView() {
168 throbber_->Stop();
169 throbber_ = NULL;
170 }
171
172 void NetworkSelectionView::AddControlsToLayout(
173 views::GridLayout* contents_layout) {
174 // Padding rows will be resized.
175 const int kPadding = 0;
176 if (IsConnecting()) {
177 contents_layout->AddPaddingRow(1, kPadding);
178 contents_layout->StartRow(0, THROBBER_ROW);
179 contents_layout->AddView(connecting_network_label_);
180 contents_layout->AddView(throbber_);
181 contents_layout->AddPaddingRow(1, kPadding);
182 } else {
183 contents_layout->AddPaddingRow(1, kPadding);
184 contents_layout->StartRow(0, STANDARD_ROW);
185 contents_layout->AddView(select_language_label_);
186 contents_layout->AddView(languages_menubutton_, 1, 1,
187 GridLayout::FILL, GridLayout::FILL,
188 languages_menubutton_->GetPreferredSize().width(),
189 kSelectionBoxHeight);
190 if (show_keyboard_button_) {
191 contents_layout->AddPaddingRow(0, kControlPaddingRow);
192 contents_layout->StartRow(0, STANDARD_ROW);
193 contents_layout->AddView(select_keyboard_label_);
194 contents_layout->AddView(
195 keyboards_menubutton_, 1, 1,
196 GridLayout::FILL, GridLayout::FILL,
197 keyboards_menubutton_->GetPreferredSize().width(),
198 kSelectionBoxHeight);
199 }
200 contents_layout->AddPaddingRow(0, kControlPaddingRow);
201 contents_layout->StartRow(0, STANDARD_ROW);
202 contents_layout->AddView(select_network_label_);
203 contents_layout->AddView(network_dropdown_, 1, 1,
204 GridLayout::FILL, GridLayout::FILL,
205 network_dropdown_->GetPreferredSize().width(),
206 kSelectionBoxHeight);
207 contents_layout->AddPaddingRow(0, kControlPaddingRow);
208 contents_layout->StartRow(0, STANDARD_ROW);
209 contents_layout->SkipColumns(1);
210 contents_layout->AddView(proxy_settings_link_, 1, 1,
211 GridLayout::LEADING, GridLayout::CENTER);
212 contents_layout->AddPaddingRow(0, kControlPaddingRow);
213 contents_layout->StartRow(0, STANDARD_ROW);
214 contents_layout->SkipColumns(1);
215 contents_layout->AddView(continue_button_, 1, 1,
216 GridLayout::LEADING, GridLayout::CENTER);
217 contents_layout->AddPaddingRow(1, kPadding);
218 }
219 }
220
221 void NetworkSelectionView::InitLayout() {
222 gfx::Size screen_size = actor_->GetScreenSize();
223 const int widest_label = std::max(
224 std::max(
225 select_language_label_->GetPreferredSize().width(),
226 select_keyboard_label_->GetPreferredSize().width()),
227 select_network_label_->GetPreferredSize().width());
228 const int dropdown_width = screen_size.width() - 2 * kBorderSize -
229 2 * kPaddingColumnWidth - kMediumPaddingColumnWidth - widest_label;
230 actor_->language_switch_menu()->SetFirstLevelMenuWidth(
231 dropdown_width - kMenuWidthOffset);
232 actor_->keyboard_switch_menu()->SetMinimumWidth(
233 dropdown_width - kMenuWidthOffset);
234 network_dropdown_->SetFirstLevelMenuWidth(dropdown_width - kMenuWidthOffset);
235
236 // Define layout and column set for entire screen (title + screen).
237 SetLayoutManager(new views::FillLayout);
238 views::GridLayout* screen_layout = new views::GridLayout(entire_screen_view_);
239 entire_screen_view_->SetLayoutManager(screen_layout);
240
241 views::ColumnSet* column_set = screen_layout->AddColumnSet(WELCOME_ROW);
242 const int welcome_width = screen_size.width() - 2 * kWelcomeTitlePadding -
243 2 * kBorderSize;
244 column_set->AddPaddingColumn(0, kWelcomeTitlePadding + kBorderSize);
245 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 0,
246 GridLayout::FIXED, welcome_width, welcome_width);
247 column_set->AddPaddingColumn(0, kWelcomeTitlePadding + kBorderSize);
248 column_set = screen_layout->AddColumnSet(CONTENTS_ROW);
249 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 0,
250 GridLayout::FIXED, screen_size.width(), screen_size.width());
251 screen_layout->StartRow(0, WELCOME_ROW);
252 screen_layout->AddView(welcome_label_);
253 screen_layout->StartRow(1, CONTENTS_ROW);
254 screen_layout->AddView(contents_view_);
255
256 // Define layout and column set for screen contents.
257 views::GridLayout* contents_layout = new views::GridLayout(contents_view_);
258 contents_view_->SetLayoutManager(contents_layout);
259
260 column_set = contents_layout->AddColumnSet(STANDARD_ROW);
261 column_set->AddPaddingColumn(1, kPaddingColumnWidth);
262 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 0,
263 GridLayout::FIXED, widest_label, widest_label);
264 column_set->AddPaddingColumn(0, kMediumPaddingColumnWidth);
265 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 0,
266 GridLayout::FIXED, dropdown_width, dropdown_width);
267 column_set->AddPaddingColumn(1, kPaddingColumnWidth);
268
269 const int h_padding = 30;
270 column_set = contents_layout->AddColumnSet(THROBBER_ROW);
271 column_set->AddPaddingColumn(1, h_padding);
272 column_set->AddColumn(GridLayout::TRAILING, GridLayout::CENTER, 0,
273 GridLayout::USE_PREF, 0, 0);
274 column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing);
275 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 1,
276 GridLayout::USE_PREF, 0, 0);
277 column_set->AddPaddingColumn(1, h_padding);
278
279 AddControlsToLayout(contents_layout);
280 }
281
282 void NetworkSelectionView::Init() {
283 contents_view_ = new views::View();
284
285 entire_screen_view_ = new views::View();
286 AddChildView(entire_screen_view_);
287
288 // Use rounded rect background.
289 views::Painter* painter = CreateWizardPainter(
290 &BorderDefinition::kScreenBorder);
291 contents_view_->set_background(
292 views::Background::CreateBackgroundPainter(true, painter));
293 SkColor background_color = color_utils::AlphaBlend(
294 BorderDefinition::kScreenBorder.top_color,
295 BorderDefinition::kScreenBorder.bottom_color, 128);
296
297 welcome_label_ = new views::Label();
298 welcome_label_->SetEnabledColor(kWelcomeColor);
299 welcome_label_->SetBackgroundColor(background_color);
300 welcome_label_->SetMultiLine(true);
301
302 select_language_label_ = new views::Label();
303 select_language_label_->SetBackgroundColor(background_color);
304
305 languages_menubutton_ = new NotifyingMenuButton(
306 NULL, string16(), actor_->language_switch_menu(), true, actor_);
307 InitMenuButtonProperties(languages_menubutton_);
308
309 select_keyboard_label_ = new views::Label();
310 select_keyboard_label_->SetBackgroundColor(background_color);
311
312 keyboards_menubutton_ = new DropDownButton(
313 NULL /* listener */, string16(), actor_->keyboard_switch_menu(),
314 true /* show_menu_marker */);
315 InitMenuButtonProperties(keyboards_menubutton_);
316
317 select_network_label_ = new views::Label();
318 select_network_label_->SetBackgroundColor(background_color);
319
320 network_dropdown_ = new NetworkControlReportOnActivate(false,
321 GetNativeWindow(),
322 actor_);
323 InitMenuButtonProperties(network_dropdown_);
324
325 connecting_network_label_ = new views::Label();
326 connecting_network_label_->SetBackgroundColor(background_color);
327 connecting_network_label_->SetVisible(false);
328
329 proxy_settings_link_ = new views::Link();
330 proxy_settings_link_->set_listener(this);
331 proxy_settings_link_->SetVisible(true);
332 proxy_settings_link_->set_focusable(true);
333 proxy_settings_link_->SetBackgroundColor(background_color);
334 proxy_settings_link_->SetEnabledColor(login::kLinkColor);
335 proxy_settings_link_->SetPressedColor(login::kLinkColor);
336
337 UpdateLocalizedStringsAndFonts();
338 }
339
340 void NetworkSelectionView::UpdateLocalizedStringsAndFonts() {
341 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
342 gfx::Font welcome_label_font = rb.GetFont(ResourceBundle::LargeFont).
343 DeriveFont(kWelcomeTitleFontDelta, gfx::Font::BOLD);
344 gfx::Font select_label_font = rb.GetFont(ResourceBundle::MediumFont).
345 DeriveFont(kNetworkSelectionLabelFontDelta);
346 const gfx::Font& base_font = rb.GetFont(ResourceBundle::BaseFont);
347
348 SetMenuButtonFont(languages_menubutton_, base_font);
349 languages_menubutton_->SetText(
350 actor_->language_switch_menu()->GetCurrentLocaleName());
351 SetMenuButtonFont(keyboards_menubutton_, base_font);
352 keyboards_menubutton_->SetText(
353 actor_->keyboard_switch_menu()->GetCurrentKeyboardName());
354 welcome_label_->SetFont(welcome_label_font);
355 welcome_label_->SetText(
356 l10n_util::GetStringUTF16(IDS_NETWORK_SELECTION_TITLE));
357 select_language_label_->SetFont(select_label_font);
358 select_language_label_->SetText(
359 l10n_util::GetStringUTF16(IDS_LANGUAGE_SELECTION_SELECT));
360 languages_menubutton_->SetAccessibleName(
361 l10n_util::GetStringUTF16(IDS_LANGUAGE_SELECTION_SELECT));
362 select_keyboard_label_->SetFont(select_label_font);
363 select_keyboard_label_->SetText(
364 l10n_util::GetStringUTF16(IDS_KEYBOARD_SELECTION_SELECT));
365 keyboards_menubutton_->SetAccessibleName(
366 l10n_util::GetStringUTF16(IDS_KEYBOARD_SELECTION_SELECT));
367 select_network_label_->SetFont(select_label_font);
368 select_network_label_->SetText(
369 l10n_util::GetStringUTF16(IDS_NETWORK_SELECTION_SELECT));
370 SetMenuButtonFont(network_dropdown_, base_font);
371 network_dropdown_->SetAccessibleName(
372 l10n_util::GetStringUTF16(IDS_NETWORK_SELECTION_SELECT));
373 proxy_settings_link_->SetFont(base_font);
374 proxy_settings_link_->SetText(
375 l10n_util::GetStringUTF16(IDS_OPTIONS_PROXIES_CONFIGURE_BUTTON));
376 connecting_network_label_->SetFont(rb.GetFont(ResourceBundle::MediumFont));
377 RecreateNativeControls();
378 UpdateConnectingNetworkLabel();
379 network_dropdown_->Refresh();
380 InitLayout();
381 }
382
383 ////////////////////////////////////////////////////////////////////////////////
384 // views::View: implementation:
385
386 bool NetworkSelectionView::OnKeyPressed(const views::KeyEvent&) {
387 if (actor_->IsErrorShown()) {
388 actor_->ClearErrors();
389 return true;
390 }
391 return false;
392 }
393
394 void NetworkSelectionView::OnLocaleChanged() {
395 show_keyboard_button_ = true;
396 UpdateLocalizedStringsAndFonts();
397 // Proxy settings dialog contains localized title. Zap it.
398 proxy_settings_dialog_.reset(NULL);
399
400 Layout();
401 SchedulePaint();
402 }
403
404 bool NetworkSelectionView::SkipDefaultKeyEventProcessing(
405 const views::KeyEvent& e) {
406 return true;
407 }
408
409 ////////////////////////////////////////////////////////////////////////////////
410 // NetworkSelectionView, public:
411
412 gfx::NativeWindow NetworkSelectionView::GetNativeWindow() const {
413 return GetWidget()->GetNativeWindow();
414 }
415
416 views::View* NetworkSelectionView::GetNetworkControlView() const {
417 return network_dropdown_;
418 }
419
420 void NetworkSelectionView::ShowConnectingStatus(bool connecting,
421 const string16& network_id) {
422 network_id_ = network_id;
423 UpdateConnectingNetworkLabel();
424 select_language_label_->SetVisible(!connecting);
425 languages_menubutton_->SetVisible(!connecting);
426 select_keyboard_label_->SetVisible(!connecting);
427 keyboards_menubutton_->SetVisible(!connecting);
428 select_network_label_->SetVisible(!connecting);
429 network_dropdown_->SetVisible(!connecting);
430 continue_button_->SetVisible(!connecting);
431 proxy_settings_link_->SetVisible(!connecting);
432 connecting_network_label_->SetVisible(connecting);
433 InitLayout();
434 Layout();
435 if (connecting) {
436 throbber_->Start();
437 network_dropdown_->CancelMenu();
438 } else {
439 throbber_->Stop();
440 }
441 }
442
443 bool NetworkSelectionView::IsConnecting() const {
444 return connecting_network_label_->IsVisible();
445 }
446
447 void NetworkSelectionView::EnableContinue(bool enabled) {
448 if (continue_button_)
449 continue_button_->SetEnabled(enabled);
450 }
451
452 bool NetworkSelectionView::IsContinueEnabled() const {
453 return continue_button_ && continue_button_->IsEnabled();
454 }
455
456 ////////////////////////////////////////////////////////////////////////////////
457 // views::LinkListener implementation:
458 void NetworkSelectionView::LinkClicked(views::Link* source, int) {
459 actor_->ClearErrors();
460 if (source == proxy_settings_link_) {
461 if (!proxy_settings_dialog_.get()) {
462 proxy_settings_dialog_.reset(
463 new ProxySettingsDialog(this, GetNativeWindow()));
464 }
465 proxy_settings_dialog_->Show();
466 }
467 }
468
469 ////////////////////////////////////////////////////////////////////////////////
470 // NetworkSelectionView, private:
471
472 void NetworkSelectionView::RecreateNativeControls() {
473 // There is no way to get native button preferred size after the button was
474 // sized so delete and recreate the button on text update.
475 bool is_continue_enabled = IsContinueEnabled();
476 delete continue_button_;
477 continue_button_ = new login::WideButton(
478 actor_,
479 l10n_util::GetStringUTF16(IDS_NETWORK_SELECTION_CONTINUE_BUTTON));
480 continue_button_->SetEnabled(is_continue_enabled);
481 }
482
483 void NetworkSelectionView::UpdateConnectingNetworkLabel() {
484 connecting_network_label_->SetText(l10n_util::GetStringFUTF16(
485 IDS_NETWORK_SELECTION_CONNECTING, network_id_));
486 }
487
488 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/network_selection_view.h ('k') | chrome/browser/chromeos/login/new_user_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698