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

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

Issue 3166028: Replace network combobox with network dropdown button (Closed)
Patch Set: Removed trailing spaces Created 10 years, 3 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 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 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 #include "chrome/browser/chromeos/login/network_selection_view.h" 5 #include "chrome/browser/chromeos/login/network_selection_view.h"
6 6
7 #include <signal.h> 7 #include <signal.h>
8 #include <sys/types.h> 8 #include <sys/types.h>
9 #include <string> 9 #include <string>
10 10
11 #include "app/l10n_util.h" 11 #include "app/l10n_util.h"
12 #include "app/resource_bundle.h" 12 #include "app/resource_bundle.h"
13 #include "base/utf_string_conversions.h" 13 #include "base/utf_string_conversions.h"
14 #include "chrome/browser/chromeos/login/network_screen_delegate.h" 14 #include "chrome/browser/chromeos/login/network_screen_delegate.h"
15 #include "chrome/browser/chromeos/login/rounded_rect_painter.h" 15 #include "chrome/browser/chromeos/login/rounded_rect_painter.h"
16 #include "chrome/browser/chromeos/login/language_switch_menu.h" 16 #include "chrome/browser/chromeos/login/language_switch_menu.h"
17 #include "chrome/browser/chromeos/status/network_dropdown_button.h"
17 #include "grit/chromium_strings.h" 18 #include "grit/chromium_strings.h"
18 #include "grit/generated_resources.h" 19 #include "grit/generated_resources.h"
19 #include "grit/theme_resources.h" 20 #include "grit/theme_resources.h"
20 #include "views/controls/button/native_button.h" 21 #include "views/controls/button/native_button.h"
21 #include "views/controls/combobox/combobox.h" 22 #include "views/controls/combobox/combobox.h"
22 #include "views/controls/label.h" 23 #include "views/controls/label.h"
23 #include "views/controls/throbber.h" 24 #include "views/controls/throbber.h"
24 #include "views/widget/widget.h" 25 #include "views/widget/widget.h"
25 #include "views/widget/widget_gtk.h" 26 #include "views/widget/widget_gtk.h"
26 #include "views/window/non_client_view.h" 27 #include "views/window/non_client_view.h"
(...skipping 13 matching lines...) Expand all
40 const int kContinueButtonSpacingX = 30; 41 const int kContinueButtonSpacingX = 30;
41 const int kSpacing = 25; 42 const int kSpacing = 25;
42 const int kHorizontalSpacing = 25; 43 const int kHorizontalSpacing = 25;
43 const int kSelectionBoxWidthMin = 200; 44 const int kSelectionBoxWidthMin = 200;
44 const int kSelectionBoxHeight = 29; 45 const int kSelectionBoxHeight = 29;
45 const int kSelectionBoxSpacing = 7; 46 const int kSelectionBoxSpacing = 7;
46 47
47 // Menu button is drawn using our custom icons in resources. See 48 // Menu button is drawn using our custom icons in resources. See
48 // TextButtonBorder::Paint() for details. So this offset compensate 49 // TextButtonBorder::Paint() for details. So this offset compensate
49 // horizontal size, eaten by those icons. 50 // horizontal size, eaten by those icons.
50 const int kMenuButtonHorizontalOffset = 1; 51 const int kMenuHorizontalOffset = -1;
51 52
52 // Vertical addition to the menu window to make it appear exactly below 53 // Vertical addition to the menu window to make it appear exactly below
53 // MenuButton. 54 // MenuButton.
54 const int kMenuButtonVerticalOffset = 3; 55 const int kMenuVerticalOffset = 3;
56
57 // Offset that compensates menu width so that it matches
58 // menu button visual width when being in pushed state.
59 const int kMenuWidthOffset = 6;
55 60
56 const SkColor kWelcomeColor = 0xFF1D6AB1; 61 const SkColor kWelcomeColor = 0xFF1D6AB1;
57 62
58 const int kThrobberFrameMs = 60; 63 const int kThrobberFrameMs = 60;
59 const int kThrobberStartDelayMs = 500; 64 const int kThrobberStartDelayMs = 500;
60 65
61 } // namespace 66 } // namespace
62 67
63 namespace chromeos { 68 namespace chromeos {
64 69
65 NetworkSelectionView::NetworkSelectionView(NetworkScreenDelegate* delegate) 70 NetworkSelectionView::NetworkSelectionView(NetworkScreenDelegate* delegate)
66 : network_combobox_(NULL), 71 : languages_menubutton_(NULL),
67 languages_menubutton_(NULL),
68 welcome_label_(NULL), 72 welcome_label_(NULL),
69 select_language_label_(NULL), 73 select_language_label_(NULL),
70 select_network_label_(NULL), 74 select_network_label_(NULL),
71 connecting_network_label_(NULL), 75 connecting_network_label_(NULL),
72 continue_button_(NULL), 76 continue_button_(NULL),
73 throbber_(NULL), 77 throbber_(NULL),
74 continue_button_order_index_(-1), 78 continue_button_order_index_(-1),
79 network_dropdown_(NULL),
75 delegate_(delegate) { 80 delegate_(delegate) {
76 } 81 }
77 82
78 NetworkSelectionView::~NetworkSelectionView() { 83 NetworkSelectionView::~NetworkSelectionView() {
79 network_combobox_->set_listener(NULL);
80 network_combobox_ = NULL;
81 throbber_->Stop(); 84 throbber_->Stop();
82 throbber_ = NULL; 85 throbber_ = NULL;
83 } 86 }
84 87
85 void NetworkSelectionView::Init() { 88 void NetworkSelectionView::Init() {
86 // Use rounded rect background. 89 // Use rounded rect background.
87 views::Painter* painter = CreateWizardPainter( 90 views::Painter* painter = CreateWizardPainter(
88 &BorderDefinition::kScreenBorder); 91 &BorderDefinition::kScreenBorder);
89 set_background( 92 set_background(
90 views::Background::CreateBackgroundPainter(true, painter)); 93 views::Background::CreateBackgroundPainter(true, painter));
(...skipping 16 matching lines...) Expand all
107 connecting_network_label_ = new views::Label(); 110 connecting_network_label_ = new views::Label();
108 connecting_network_label_->SetFont(rb.GetFont(ResourceBundle::MediumFont)); 111 connecting_network_label_->SetFont(rb.GetFont(ResourceBundle::MediumFont));
109 connecting_network_label_->SetVisible(false); 112 connecting_network_label_->SetVisible(false);
110 113
111 throbber_ = new views::SmoothedThrobber(kThrobberFrameMs); 114 throbber_ = new views::SmoothedThrobber(kThrobberFrameMs);
112 throbber_->SetFrames( 115 throbber_->SetFrames(
113 ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_SPINNER)); 116 ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_SPINNER));
114 throbber_->set_start_delay_ms(kThrobberStartDelayMs); 117 throbber_->set_start_delay_ms(kThrobberStartDelayMs);
115 AddChildView(throbber_); 118 AddChildView(throbber_);
116 119
117 network_combobox_ = new views::Combobox(delegate_);
118 network_combobox_->set_listener(delegate_);
119
120 languages_menubutton_ = new views::MenuButton( 120 languages_menubutton_ = new views::MenuButton(
121 NULL, std::wstring(), delegate_->language_switch_menu(), true); 121 NULL, std::wstring(), delegate_->language_switch_menu(), true);
122 languages_menubutton_->SetFocusable(true); 122 languages_menubutton_->SetFocusable(true);
123 languages_menubutton_->SetNormalHasBorder(true); 123 languages_menubutton_->SetNormalHasBorder(true);
124 delegate_->language_switch_menu()->set_menu_offset( 124 // Menu is positioned by bottom right corner of the MenuButton.
125 kMenuButtonHorizontalOffset, kMenuButtonVerticalOffset); 125 delegate_->language_switch_menu()->set_menu_offset(kMenuHorizontalOffset,
126 kMenuVerticalOffset);
126 127
127 AddChildView(welcome_label_); 128 AddChildView(welcome_label_);
128 AddChildView(select_language_label_); 129 AddChildView(select_language_label_);
129 AddChildView(select_network_label_); 130 AddChildView(select_network_label_);
130 AddChildView(connecting_network_label_); 131 AddChildView(connecting_network_label_);
131 AddChildView(languages_menubutton_); 132 AddChildView(languages_menubutton_);
132 AddChildView(network_combobox_); 133
134 network_dropdown_ = new NetworkDropdownButton(false, GetNativeWindow());
135 network_dropdown_->SetNormalHasBorder(true);
136 network_dropdown_->SetFocusable(true);
137 AddChildView(network_dropdown_);
133 138
134 UpdateLocalizedStrings(); 139 UpdateLocalizedStrings();
135 } 140 }
136 141
137 void NetworkSelectionView::UpdateLocalizedStrings() { 142 void NetworkSelectionView::UpdateLocalizedStrings() {
138 RecreateNativeControls(); 143 RecreateNativeControls();
139 languages_menubutton_->SetText( 144 languages_menubutton_->SetText(
140 delegate_->language_switch_menu()->GetCurrentLocaleName()); 145 delegate_->language_switch_menu()->GetCurrentLocaleName());
141 welcome_label_->SetText(l10n_util::GetStringF(IDS_NETWORK_SELECTION_TITLE, 146 welcome_label_->SetText(l10n_util::GetStringF(IDS_NETWORK_SELECTION_TITLE,
142 l10n_util::GetString(IDS_PRODUCT_OS_NAME))); 147 l10n_util::GetString(IDS_PRODUCT_OS_NAME)));
143 select_language_label_->SetText( 148 select_language_label_->SetText(
144 l10n_util::GetString(IDS_LANGUAGE_SELECTION_SELECT)); 149 l10n_util::GetString(IDS_LANGUAGE_SELECTION_SELECT));
145 select_network_label_->SetText( 150 select_network_label_->SetText(
146 l10n_util::GetString(IDS_NETWORK_SELECTION_SELECT)); 151 l10n_util::GetString(IDS_NETWORK_SELECTION_SELECT));
147 UpdateConnectingNetworkLabel(); 152 UpdateConnectingNetworkLabel();
148 } 153 }
149 154
150 //////////////////////////////////////////////////////////////////////////////// 155 ////////////////////////////////////////////////////////////////////////////////
151 // views::View: implementation: 156 // views::View: implementation:
152 157
153 void NetworkSelectionView::ChildPreferredSizeChanged(View* child) { 158 void NetworkSelectionView::ChildPreferredSizeChanged(View* child) {
154 Layout(); 159 Layout();
155 SchedulePaint(); 160 SchedulePaint();
156 } 161 }
157 162
158 void NetworkSelectionView::OnLocaleChanged() { 163 void NetworkSelectionView::OnLocaleChanged() {
159 UpdateLocalizedStrings(); 164 UpdateLocalizedStrings();
160
161 int index_to_restore = GetSelectedNetworkItem();
162 NetworkModelChanged();
163 index_to_restore = std::max(index_to_restore, 0);
164 index_to_restore = std::min<int>(index_to_restore,
165 delegate_->GetItemCount() - 1);
166 if (index_to_restore >= 0) {
167 // Only localized names of networking options has changed
168 // so we should restore networking option selected previously.
169 SetSelectedNetworkItem(index_to_restore);
170 }
171
172 Layout(); 165 Layout();
173 SchedulePaint(); 166 SchedulePaint();
174 } 167 }
175 168
176 gfx::Size NetworkSelectionView::GetPreferredSize() { 169 gfx::Size NetworkSelectionView::GetPreferredSize() {
177 return gfx::Size(width(), height()); 170 return gfx::Size(width(), height());
178 } 171 }
179 172
180 void NetworkSelectionView::Layout() { 173 void NetworkSelectionView::Layout() {
181 gfx::Insets insets = GetInsets(); 174 gfx::Insets insets = GetInsets();
182 int max_width = this->width() - insets.width() - 2 * kHorizontalSpacing; 175 int max_width = this->width() - insets.width() - 2 * kHorizontalSpacing;
183 welcome_label_->SizeToFit(max_width); 176 welcome_label_->SizeToFit(max_width);
184 int y = kWelcomeLabelY; 177 int y = kWelcomeLabelY;
185 y -= welcome_label_->GetPreferredSize().height() / 2; 178 y -= welcome_label_->GetPreferredSize().height() / 2;
186 179
187 welcome_label_->SetBounds( 180 welcome_label_->SetBounds(
188 (width() - welcome_label_->GetPreferredSize().width()) / 2, 181 (width() - welcome_label_->GetPreferredSize().width()) / 2,
189 y, 182 y,
190 welcome_label_->GetPreferredSize().width(), 183 welcome_label_->GetPreferredSize().width(),
191 welcome_label_->GetPreferredSize().height()); 184 welcome_label_->GetPreferredSize().height());
192 y += welcome_label_->GetPreferredSize().height() + kSpacing; 185 y += welcome_label_->GetPreferredSize().height() + kSpacing;
193 186
194 // Use menu preffered size to calculate boxes width accordingly. 187 // Use menu preffered size to calculate boxes width accordingly.
195 int box_width = delegate_->language_switch_menu()->GetFirstLevelMenuWidth() + 188 int box_width = delegate_->language_switch_menu()->GetFirstLevelMenuWidth() +
196 kMenuButtonHorizontalOffset * 2; 189 kMenuWidthOffset;
197 const int widest_label = std::max( 190 const int widest_label = std::max(
198 select_language_label_->GetPreferredSize().width(), 191 select_language_label_->GetPreferredSize().width(),
199 select_network_label_->GetPreferredSize().width()); 192 select_network_label_->GetPreferredSize().width());
200 if (box_width < kSelectionBoxWidthMin) { 193 if (box_width < kSelectionBoxWidthMin) {
201 box_width = kSelectionBoxWidthMin; 194 box_width = kSelectionBoxWidthMin;
202 delegate_->language_switch_menu()->SetFirstLevelMenuWidth( 195 delegate_->language_switch_menu()->SetFirstLevelMenuWidth(
203 box_width - kMenuButtonHorizontalOffset * 2); 196 box_width - kMenuWidthOffset);
204 } else if (widest_label + box_width + 2 * kHorizontalSpacing > width()) { 197 } else if (widest_label + box_width + 2 * kHorizontalSpacing > width()) {
205 box_width = width() - widest_label - 2 * kHorizontalSpacing; 198 box_width = width() - widest_label - 2 * kHorizontalSpacing;
206 } 199 }
207 const int labels_x = (width() - widest_label - box_width) / 2; 200 const int labels_x = (width() - widest_label - box_width) / 2;
208 select_language_label_->SetBounds( 201 select_language_label_->SetBounds(
209 labels_x, 202 labels_x,
210 y, 203 y,
211 select_language_label_->GetPreferredSize().width(), 204 select_language_label_->GetPreferredSize().width(),
212 select_language_label_->GetPreferredSize().height()); 205 select_language_label_->GetPreferredSize().height());
213 206
(...skipping 18 matching lines...) Expand all
232 connecting_network_label_->GetPreferredSize().height()); 225 connecting_network_label_->GetPreferredSize().height());
233 226
234 throbber_->SetBounds( 227 throbber_->SetBounds(
235 width() / 2 + connecting_network_label_->GetPreferredSize().width() / 2 + 228 width() / 2 + connecting_network_label_->GetPreferredSize().width() / 2 +
236 kHorizontalSpacing, 229 kHorizontalSpacing,
237 y + (connecting_network_label_->GetPreferredSize().height() - 230 y + (connecting_network_label_->GetPreferredSize().height() -
238 throbber_->GetPreferredSize().height()) / 2, 231 throbber_->GetPreferredSize().height()) / 2,
239 throbber_->GetPreferredSize().width(), 232 throbber_->GetPreferredSize().width(),
240 throbber_->GetPreferredSize().height()); 233 throbber_->GetPreferredSize().height());
241 234
242 network_combobox_->SetBounds(selection_box_x, y - label_y_offset, 235 network_dropdown_->SetBounds(selection_box_x, y - label_y_offset,
243 box_width, kSelectionBoxHeight); 236 box_width, kSelectionBoxHeight);
244 237
245 y = height() - continue_button_->GetPreferredSize().height() - kSpacing; 238 y = height() - continue_button_->GetPreferredSize().height() - kSpacing;
246 continue_button_->SetBounds( 239 continue_button_->SetBounds(
247 width() - kContinueButtonSpacingX - 240 width() - kContinueButtonSpacingX -
248 continue_button_->GetPreferredSize().width(), 241 continue_button_->GetPreferredSize().width(),
249 y, 242 y,
250 continue_button_->GetPreferredSize().width(), 243 continue_button_->GetPreferredSize().width(),
251 continue_button_->GetPreferredSize().height()); 244 continue_button_->GetPreferredSize().height());
252 245
253 // Need to refresh combobox layout explicitly. 246 // Need to refresh combobox layout explicitly.
254 network_combobox_->Layout();
255 continue_button_->Layout(); 247 continue_button_->Layout();
256 } 248 }
257 249
258 //////////////////////////////////////////////////////////////////////////////// 250 ////////////////////////////////////////////////////////////////////////////////
259 // NetworkSelectionView, public: 251 // NetworkSelectionView, public:
260 252
261 int NetworkSelectionView::GetSelectedNetworkItem() const {
262 return network_combobox_->selected_item();
263 }
264
265 void NetworkSelectionView::SetSelectedNetworkItem(int index) {
266 network_combobox_->SetSelectedItem(index);
267 }
268
269 gfx::NativeWindow NetworkSelectionView::GetNativeWindow() { 253 gfx::NativeWindow NetworkSelectionView::GetNativeWindow() {
270 return GTK_WINDOW(static_cast<WidgetGtk*>(GetWidget())->GetNativeView()); 254 return GTK_WINDOW(static_cast<WidgetGtk*>(GetWidget())->GetNativeView());
271 } 255 }
272 256
273 void NetworkSelectionView::NetworkModelChanged() {
274 network_combobox_->ModelChanged();
275 }
276
277 void NetworkSelectionView::ShowConnectingStatus(bool connecting, 257 void NetworkSelectionView::ShowConnectingStatus(bool connecting,
278 const string16& network_id) { 258 const string16& network_id) {
279 network_id_ = network_id; 259 network_id_ = network_id;
280 UpdateConnectingNetworkLabel(); 260 UpdateConnectingNetworkLabel();
281 select_language_label_->SetVisible(!connecting); 261 select_language_label_->SetVisible(!connecting);
282 languages_menubutton_->SetVisible(!connecting); 262 languages_menubutton_->SetVisible(!connecting);
283 select_network_label_->SetVisible(!connecting); 263 select_network_label_->SetVisible(!connecting);
284 network_combobox_->SetVisible(!connecting); 264 network_dropdown_->SetVisible(!connecting);
285 continue_button_->SetVisible(!connecting); 265 continue_button_->SetVisible(!connecting);
286 connecting_network_label_->SetVisible(connecting); 266 connecting_network_label_->SetVisible(connecting);
287 Layout(); 267 Layout();
288 if (connecting) { 268 if (connecting) {
289 throbber_->Start(); 269 throbber_->Start();
270 network_dropdown_->CancelMenu();
290 } else { 271 } else {
291 throbber_->Stop(); 272 throbber_->Stop();
292 } 273 }
293 } 274 }
294 275
295 void NetworkSelectionView::EnableContinue(bool enabled) { 276 void NetworkSelectionView::EnableContinue(bool enabled) {
296 if (continue_button_) 277 if (continue_button_)
297 continue_button_->SetEnabled(enabled); 278 continue_button_->SetEnabled(enabled);
298 } 279 }
299 280
(...skipping 13 matching lines...) Expand all
313 } 294 }
314 AddChildView(continue_button_order_index_, continue_button_); 295 AddChildView(continue_button_order_index_, continue_button_);
315 } 296 }
316 297
317 void NetworkSelectionView::UpdateConnectingNetworkLabel() { 298 void NetworkSelectionView::UpdateConnectingNetworkLabel() {
318 connecting_network_label_->SetText(l10n_util::GetStringF( 299 connecting_network_label_->SetText(l10n_util::GetStringF(
319 IDS_NETWORK_SELECTION_CONNECTING, UTF16ToWide(network_id_))); 300 IDS_NETWORK_SELECTION_CONNECTING, UTF16ToWide(network_id_)));
320 } 301 }
321 302
322 } // namespace chromeos 303 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/network_selection_view.h ('k') | chrome/browser/chromeos/login/wizard_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698