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

Side by Side Diff: chrome/browser/ui/views/task_manager_view.cc

Issue 12026016: Implement new Task Manager and Edit Bookmark style, etc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comment. Created 7 years, 11 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
« no previous file with comments | « chrome/browser/ui/views/frame/browser_view.cc ('k') | chrome/test/base/test_browser_window.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/task_manager/task_manager.h" 5 #include "chrome/browser/task_manager/task_manager.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/metrics/stats_table.h" 9 #include "base/metrics/stats_table.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "chrome/app/chrome_command_ids.h" 11 #include "chrome/app/chrome_command_ids.h"
12 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/memory_purger.h" 13 #include "chrome/browser/memory_purger.h"
14 #include "chrome/browser/prefs/pref_service.h" 14 #include "chrome/browser/prefs/pref_service.h"
15 #include "chrome/browser/prefs/scoped_user_pref_update.h" 15 #include "chrome/browser/prefs/scoped_user_pref_update.h"
16 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/browser_list.h" 17 #include "chrome/browser/ui/browser_list.h"
17 #include "chrome/browser/ui/browser_window.h" 18 #include "chrome/browser/ui/browser_window.h"
18 #include "chrome/browser/ui/host_desktop.h" 19 #include "chrome/browser/ui/host_desktop.h"
19 #include "chrome/browser/ui/views/browser_dialogs.h" 20 #include "chrome/browser/ui/views/browser_dialogs.h"
20 #include "chrome/common/chrome_switches.h" 21 #include "chrome/common/chrome_switches.h"
21 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
22 #include "grit/chromium_strings.h" 23 #include "grit/chromium_strings.h"
23 #include "grit/generated_resources.h" 24 #include "grit/generated_resources.h"
24 #include "grit/theme_resources.h" 25 #include "grit/theme_resources.h"
25 #include "ui/base/accelerators/accelerator.h" 26 #include "ui/base/accelerators/accelerator.h"
(...skipping 12 matching lines...) Expand all
38 #include "ui/views/controls/table/group_table_view.h" 39 #include "ui/views/controls/table/group_table_view.h"
39 #include "ui/views/controls/table/table_view_observer.h" 40 #include "ui/views/controls/table/table_view_observer.h"
40 #include "ui/views/layout/layout_constants.h" 41 #include "ui/views/layout/layout_constants.h"
41 #include "ui/views/widget/widget.h" 42 #include "ui/views/widget/widget.h"
42 #include "ui/views/window/dialog_delegate.h" 43 #include "ui/views/window/dialog_delegate.h"
43 44
44 #if defined(OS_WIN) 45 #if defined(OS_WIN)
45 #include "win8/util/win8_util.h" 46 #include "win8/util/win8_util.h"
46 #endif 47 #endif
47 48
48 // The task manager window default size.
49 static const int kDefaultWidth = 460;
50 static const int kDefaultHeight = 270;
51
52 // Yellow highlight used when highlighting background resources. 49 // Yellow highlight used when highlighting background resources.
53 static const SkColor kBackgroundResourceHighlight = 50 static const SkColor kBackgroundResourceHighlight =
54 SkColorSetRGB(0xff, 0xf1, 0xcd); 51 SkColorSetRGB(0xff, 0xf1, 0xcd);
55 52
56 namespace { 53 namespace {
57 54
58 //////////////////////////////////////////////////////////////////////////////// 55 ////////////////////////////////////////////////////////////////////////////////
59 // TaskManagerTableModel class 56 // TaskManagerTableModel class
60 //////////////////////////////////////////////////////////////////////////////// 57 ////////////////////////////////////////////////////////////////////////////////
61 58
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 public views::ContextMenuController, 206 public views::ContextMenuController,
210 public ui::SimpleMenuModel::Delegate { 207 public ui::SimpleMenuModel::Delegate {
211 public: 208 public:
212 TaskManagerView(bool highlight_background_resources, 209 TaskManagerView(bool highlight_background_resources,
213 chrome::HostDesktopType desktop_type); 210 chrome::HostDesktopType desktop_type);
214 virtual ~TaskManagerView(); 211 virtual ~TaskManagerView();
215 212
216 // Shows the Task manager window, or re-activates an existing one. If 213 // Shows the Task manager window, or re-activates an existing one. If
217 // |highlight_background_resources| is true, highlights the background 214 // |highlight_background_resources| is true, highlights the background
218 // resources in the resource display. 215 // resources in the resource display.
219 static void Show(bool highlight_background_resources, 216 static void Show(bool highlight_background_resources, Browser* browser);
220 chrome::HostDesktopType desktop_type);
221 217
222 // views::View: 218 // views::View:
223 virtual void Layout() OVERRIDE; 219 virtual void Layout() OVERRIDE;
224 virtual gfx::Size GetPreferredSize() OVERRIDE; 220 virtual gfx::Size GetPreferredSize() OVERRIDE;
225 virtual void ViewHierarchyChanged(bool is_add, views::View* parent, 221 virtual void ViewHierarchyChanged(bool is_add, views::View* parent,
226 views::View* child) OVERRIDE; 222 views::View* child) OVERRIDE;
227 223
228 // views::ButtonListener: 224 // views::ButtonListener:
229 virtual void ButtonPressed(views::Button* sender, 225 virtual void ButtonPressed(views::Button* sender,
230 const ui::Event& event) OVERRIDE; 226 const ui::Event& event) OVERRIDE;
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 } else { 475 } else {
480 parent->RemoveChildView(kill_button_); 476 parent->RemoveChildView(kill_button_);
481 if (purge_memory_button_) 477 if (purge_memory_button_)
482 parent->RemoveChildView(purge_memory_button_); 478 parent->RemoveChildView(purge_memory_button_);
483 parent->RemoveChildView(about_memory_link_); 479 parent->RemoveChildView(about_memory_link_);
484 } 480 }
485 } 481 }
486 } 482 }
487 483
488 void TaskManagerView::Layout() { 484 void TaskManagerView::Layout() {
485 bool new_style = views::DialogDelegate::UseNewStyle();
489 gfx::Size size = kill_button_->GetPreferredSize(); 486 gfx::Size size = kill_button_->GetPreferredSize();
490 int prefered_width = size.width();
491 int prefered_height = size.height();
492
493 tab_table_->SetBounds(
494 x() + views::kPanelHorizMargin,
495 y() + views::kPanelVertMargin,
496 width() - 2 * views::kPanelHorizMargin,
497 height() - 2 * views::kPanelVertMargin - prefered_height);
498
499 // y-coordinate of button top left.
500 gfx::Rect parent_bounds = parent()->GetContentsBounds(); 487 gfx::Rect parent_bounds = parent()->GetContentsBounds();
501 int y_buttons = 488 int x = width() - size.width() - (new_style ? 0 : views::kPanelHorizMargin);
502 parent_bounds.bottom() - prefered_height - views::kButtonVEdgeMargin; 489 int y_buttons = new_style ? GetLocalBounds().bottom() - size.height() :
503 490 parent_bounds.bottom() - size.height() - views::kButtonVEdgeMargin;
504 kill_button_->SetBounds( 491 kill_button_->SetBounds(x, y_buttons, size.width(), size.height());
505 x() + width() - prefered_width - views::kPanelHorizMargin,
506 y_buttons,
507 prefered_width,
508 prefered_height);
509 492
510 if (purge_memory_button_) { 493 if (purge_memory_button_) {
511 size = purge_memory_button_->GetPreferredSize(); 494 size = purge_memory_button_->GetPreferredSize();
512 purge_memory_button_->SetBounds( 495 purge_memory_button_->SetBounds(
513 kill_button_->x() - size.width() - 496 kill_button_->x() - size.width() -
514 views::kUnrelatedControlHorizontalSpacing, 497 views::kUnrelatedControlHorizontalSpacing,
515 y_buttons, size.width(), size.height()); 498 y_buttons, size.width(), size.height());
516 } 499 }
517 500
518 size = about_memory_link_->GetPreferredSize(); 501 size = about_memory_link_->GetPreferredSize();
519 int link_prefered_width = size.width(); 502 about_memory_link_->SetBounds(new_style ? 0 : views::kPanelHorizMargin,
520 int link_prefered_height = size.height(); 503 y_buttons + (kill_button_->height() - size.height()) / 2,
521 // center between the two buttons horizontally, and line up with 504 size.width(), size.height());
522 // bottom of buttons vertically. 505
523 int link_y_offset = std::max(0, prefered_height - link_prefered_height) / 2; 506 gfx::Rect rect = GetLocalBounds();
524 about_memory_link_->SetBounds( 507 if (!new_style)
525 x() + views::kPanelHorizMargin, 508 rect.Inset(views::kPanelHorizMargin, views::kPanelVertMargin);
526 y_buttons + prefered_height - link_prefered_height - link_y_offset, 509 rect.Inset(0, 0, 0,
527 link_prefered_width, 510 kill_button_->height() + views::kUnrelatedControlVerticalSpacing);
528 link_prefered_height); 511 tab_table_->SetBoundsRect(rect);
529 } 512 }
530 513
531 gfx::Size TaskManagerView::GetPreferredSize() { 514 gfx::Size TaskManagerView::GetPreferredSize() {
532 return gfx::Size(kDefaultWidth, kDefaultHeight); 515 return gfx::Size(460, 270);
533 } 516 }
534 517
535 // static 518 // static
536 void TaskManagerView::Show(bool highlight_background_resources, 519 void TaskManagerView::Show(bool highlight_background_resources,
537 chrome::HostDesktopType desktop_type) { 520 Browser* browser) {
538 #if defined(OS_WIN) 521 #if defined(OS_WIN)
539 // In Windows Metro it's not good to open this native window. 522 // In Windows Metro it's not good to open this native window.
540 DCHECK(!win8::IsSingleWindowMetroMode()); 523 DCHECK(!win8::IsSingleWindowMetroMode());
541 #endif 524 #endif
525 const chrome::HostDesktopType desktop_type = browser->host_desktop_type();
542 526
543 if (instance_) { 527 if (instance_) {
544 if (instance_->highlight_background_resources_ != 528 if (instance_->highlight_background_resources_ !=
545 highlight_background_resources || 529 highlight_background_resources ||
546 instance_->desktop_type_ != desktop_type) { 530 instance_->desktop_type_ != desktop_type) {
547 instance_->GetWidget()->Close(); 531 instance_->GetWidget()->Close();
548 } else { 532 } else {
549 // If there's a Task manager window open already, just activate it. 533 // If there's a Task manager window open already, just activate it.
550 instance_->GetWidget()->Activate(); 534 instance_->GetWidget()->Activate();
551 return; 535 return;
552 } 536 }
553 } 537 }
554 instance_ = new TaskManagerView(highlight_background_resources, desktop_type); 538 instance_ = new TaskManagerView(highlight_background_resources, desktop_type);
555 539 DialogDelegateView::CreateDialogWidget(instance_,
556 views::Widget* widget = new views::Widget; 540 browser->window()->GetNativeWindow(), NULL);
557 views::Widget::InitParams params;
558 params.delegate = instance_;
559 if (DialogDelegate::UseNewStyle()) {
560 // TODO(msw): Use table_view_views or support dialog transparency and native
561 // controls (e.g. table_view_win) via a second dialog Widget (like bubbles).
562 // params.transparent = true;
563 params.remove_standard_frame = true;
564 }
565 params.top_level = true;
566 widget->Init(params);
567
568 instance_->InitAlwaysOnTopState(); 541 instance_->InitAlwaysOnTopState();
569 instance_->model_->StartUpdating(); 542 instance_->model_->StartUpdating();
570 instance_->GetWidget()->Show(); 543 instance_->GetWidget()->Show();
571 544
572 // Set the initial focus to the list of tasks. 545 // Set the initial focus to the list of tasks.
573 views::FocusManager* focus_manager = instance_->GetFocusManager(); 546 views::FocusManager* focus_manager = instance_->GetFocusManager();
574 if (focus_manager) 547 if (focus_manager)
575 focus_manager->SetFocusedView(instance_->tab_table_); 548 focus_manager->SetFocusedView(instance_->tab_table_);
576 } 549 }
577 550
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 g_browser_process->local_state()->GetDictionary(GetWindowName().c_str()); 747 g_browser_process->local_state()->GetDictionary(GetWindowName().c_str());
775 return dictionary && 748 return dictionary &&
776 dictionary->GetBoolean("always_on_top", always_on_top) && always_on_top; 749 dictionary->GetBoolean("always_on_top", always_on_top) && always_on_top;
777 } 750 }
778 751
779 } // namespace 752 } // namespace
780 753
781 namespace chrome { 754 namespace chrome {
782 755
783 // Declared in browser_dialogs.h so others don't need to depend on our header. 756 // Declared in browser_dialogs.h so others don't need to depend on our header.
784 void ShowTaskManager(chrome::HostDesktopType desktop_type) { 757 void ShowTaskManager(Browser* browser) {
785 TaskManagerView::Show(false, desktop_type); 758 TaskManagerView::Show(false, browser);
786 } 759 }
787 760
788 void ShowBackgroundPages(chrome::HostDesktopType desktop_type) { 761 void ShowBackgroundPages(Browser* browser) {
789 TaskManagerView::Show(true, desktop_type); 762 TaskManagerView::Show(true, browser);
790 } 763 }
791 764
792 } // namespace chrome 765 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/frame/browser_view.cc ('k') | chrome/test/base/test_browser_window.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698