OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/views/about_network_dialog.h" | 5 #include "chrome/browser/views/about_network_dialog.h" |
6 | 6 |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "base/thread.h" | 8 #include "base/thread.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/views/standard_layout.h" | 10 #include "chrome/browser/views/standard_layout.h" |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 void JobTracker::OnBytesRead(URLRequestJob* job, int byte_count) { | 258 void JobTracker::OnBytesRead(URLRequestJob* job, int byte_count) { |
259 } | 259 } |
260 | 260 |
261 // The singleton job tracker associated with the dialog. | 261 // The singleton job tracker associated with the dialog. |
262 JobTracker* tracker = NULL; | 262 JobTracker* tracker = NULL; |
263 | 263 |
264 } // namespace | 264 } // namespace |
265 | 265 |
266 // AboutNetworkDialog ---------------------------------------------------------- | 266 // AboutNetworkDialog ---------------------------------------------------------- |
267 | 267 |
268 AboutNetworkDialog::AboutNetworkDialog() : tracking_(false) { | 268 AboutNetworkDialog::AboutNetworkDialog() |
| 269 : track_toggle_(NULL), |
| 270 show_button_(NULL), |
| 271 clear_button_(NULL), |
| 272 tracking_(false) { |
269 SetupControls(); | 273 SetupControls(); |
270 tracker = new JobTracker(this); | 274 tracker = new JobTracker(this); |
271 tracker->AddRef(); | 275 tracker->AddRef(); |
272 } | 276 } |
273 | 277 |
274 AboutNetworkDialog::~AboutNetworkDialog() { | 278 AboutNetworkDialog::~AboutNetworkDialog() { |
275 active_dialog = NULL; | 279 active_dialog = NULL; |
276 tracker->Release(); | 280 tracker->Release(); |
277 tracker = NULL; | 281 tracker = NULL; |
278 } | 282 } |
279 | 283 |
280 // static | 284 // static |
281 void AboutNetworkDialog::RunDialog() { | 285 void AboutNetworkDialog::RunDialog() { |
282 if (!active_dialog) { | 286 if (!active_dialog) { |
283 active_dialog = new AboutNetworkDialog; | 287 active_dialog = new AboutNetworkDialog; |
284 views::Window::CreateChromeWindow(NULL, gfx::Rect(), active_dialog)->Show(); | 288 views::Window::CreateChromeWindow(NULL, gfx::Rect(), active_dialog)->Show(); |
285 } else { | 289 } else { |
286 // TOOD(brettw) it would be nice to focus the existing window. | 290 // TOOD(brettw) it would be nice to focus the existing window. |
287 } | 291 } |
288 } | 292 } |
289 | 293 |
290 void AboutNetworkDialog::AppendText(const std::wstring& text) { | 294 void AboutNetworkDialog::SetupButtonColumnSet(views::ColumnSet* set) { |
291 text_field_->AppendText(text); | 295 set->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER, |
| 296 33.33f, views::GridLayout::FIXED, 0, 0); |
| 297 set->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER, |
| 298 33.33f, views::GridLayout::FIXED, 0, 0); |
| 299 set->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER, |
| 300 33.33f, views::GridLayout::FIXED, 0, 0); |
292 } | 301 } |
293 | 302 |
294 void AboutNetworkDialog::SetupControls() { | 303 void AboutNetworkDialog::AddButtonControlsToLayout(views::GridLayout* layout) { |
295 views::GridLayout* layout = CreatePanelGridLayout(this); | |
296 SetLayoutManager(layout); | |
297 | |
298 track_toggle_ = new views::TextButton(kStartTrackingLabel); | 304 track_toggle_ = new views::TextButton(kStartTrackingLabel); |
299 track_toggle_->SetListener(this, 1); | 305 track_toggle_->SetListener(this, 1); |
300 show_button_ = new views::TextButton(kShowCurrentLabel); | 306 show_button_ = new views::TextButton(kShowCurrentLabel); |
301 show_button_->SetListener(this, 2); | 307 show_button_->SetListener(this, 2); |
302 clear_button_ = new views::TextButton(kClearLabel); | 308 clear_button_ = new views::TextButton(kClearLabel); |
303 clear_button_->SetListener(this, 3); | 309 clear_button_->SetListener(this, 3); |
304 | 310 |
305 text_field_ = new views::TextField(static_cast<views::TextField::StyleFlags>( | |
306 views::TextField::STYLE_MULTILINE)); | |
307 text_field_->SetReadOnly(true); | |
308 | |
309 // TODO(brettw): We may want to add this in the future. It can't be called | |
310 // from here, though, since the hwnd for the field hasn't been created yet. | |
311 // | |
312 // This raises the maximum number of chars from 32K to some large maximum, | |
313 // probably 2GB. 32K is not nearly enough for our use-case. | |
314 //SendMessageW(text_field_->GetNativeComponent(), EM_SETLIMITTEXT, 0, 0); | |
315 | |
316 static const int first_column_set = 1; | |
317 views::ColumnSet* column_set = layout->AddColumnSet(first_column_set); | |
318 column_set->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER, | |
319 33.33f, views::GridLayout::FIXED, 0, 0); | |
320 column_set->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER, | |
321 33.33f, views::GridLayout::FIXED, 0, 0); | |
322 column_set->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER, | |
323 33.33f, views::GridLayout::FIXED, 0, 0); | |
324 | |
325 static const int text_column_set = 2; | |
326 column_set = layout->AddColumnSet(text_column_set); | |
327 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 100.0f
, | |
328 views::GridLayout::FIXED, 0, 0); | |
329 | |
330 layout->StartRow(0, first_column_set); | |
331 layout->AddView(track_toggle_); | 311 layout->AddView(track_toggle_); |
332 layout->AddView(show_button_); | 312 layout->AddView(show_button_); |
333 layout->AddView(clear_button_); | 313 layout->AddView(clear_button_); |
334 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); | |
335 layout->StartRow(1.0f, text_column_set); | |
336 layout->AddView(text_field_); | |
337 } | |
338 | |
339 gfx::Size AboutNetworkDialog::GetPreferredSize() { | |
340 return gfx::Size(800, 400); | |
341 } | |
342 | |
343 views::View* AboutNetworkDialog::GetContentsView() { | |
344 return this; | |
345 } | |
346 | |
347 int AboutNetworkDialog::GetDialogButtons() const { | |
348 // Don't want OK or Cancel. | |
349 return 0; | |
350 } | |
351 | |
352 std::wstring AboutNetworkDialog::GetWindowTitle() const { | |
353 return L"about:network"; | |
354 } | |
355 | |
356 void AboutNetworkDialog::Layout() { | |
357 GetLayoutManager()->Layout(this); | |
358 } | |
359 | |
360 bool AboutNetworkDialog::CanResize() const { | |
361 return true; | |
362 } | 314 } |
363 | 315 |
364 void AboutNetworkDialog::ButtonPressed(views::BaseButton* button) { | 316 void AboutNetworkDialog::ButtonPressed(views::BaseButton* button) { |
365 if (button == track_toggle_) { | 317 if (button == track_toggle_) { |
366 if (tracking_) { | 318 if (tracking_) { |
367 track_toggle_->SetText(kStartTrackingLabel); | 319 track_toggle_->SetText(kStartTrackingLabel); |
368 tracking_ = false; | 320 tracking_ = false; |
369 tracker->StopTracking(); | 321 tracker->StopTracking(); |
370 } else { | 322 } else { |
371 track_toggle_->SetText(kStopTrackingLabel); | 323 track_toggle_->SetText(kStopTrackingLabel); |
372 tracking_ = true; | 324 tracking_ = true; |
373 tracker->StartTracking(); | 325 tracker->StartTracking(); |
374 } | 326 } |
375 track_toggle_->SchedulePaint(); | 327 track_toggle_->SchedulePaint(); |
376 } else if (button == show_button_) { | 328 } else if (button == show_button_) { |
377 tracker->ReportStatus(); | 329 tracker->ReportStatus(); |
378 } else if (button == clear_button_) { | 330 } else if (button == clear_button_) { |
379 text_field_->SetText(std::wstring()); | 331 text_field()->SetText(std::wstring()); |
380 } | 332 } |
381 } | 333 } |
OLD | NEW |