diff options
author | petersont@google.com <petersont@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-10 22:12:19 +0000 |
---|---|---|
committer | petersont@google.com <petersont@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-10 22:12:19 +0000 |
commit | b7937d5ba2a47d0016933fae4f856e83e5a57afb (patch) | |
tree | d8d77aa380b72a5d92a810ebe41e9fb312808a4d /chrome | |
parent | 2f668e22a495259d53772c6cc055547cd26cd7f1 (diff) | |
download | chromium_src-b7937d5ba2a47d0016933fae4f856e83e5a57afb.zip chromium_src-b7937d5ba2a47d0016933fae4f856e83e5a57afb.tar.gz chromium_src-b7937d5ba2a47d0016933fae4f856e83e5a57afb.tar.bz2 |
Double clicking on an item in the task manager should bring the relevant tab forward.
Review URL: http://codereview.chromium.org/1822
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2026 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/task_manager.cc | 50 | ||||
-rw-r--r-- | chrome/browser/task_manager.h | 14 | ||||
-rw-r--r-- | chrome/browser/task_manager_resource_providers.cc | 4 | ||||
-rw-r--r-- | chrome/browser/task_manager_resource_providers.h | 2 | ||||
-rw-r--r-- | chrome/views/group_table_view.cc | 1 | ||||
-rw-r--r-- | chrome/views/table_view.cc | 8 | ||||
-rw-r--r-- | chrome/views/table_view.h | 32 |
7 files changed, 101 insertions, 10 deletions
diff --git a/chrome/browser/task_manager.cc b/chrome/browser/task_manager.cc index 7cb75ff..5d9b8f0 100644 --- a/chrome/browser/task_manager.cc +++ b/chrome/browser/task_manager.cc @@ -511,12 +511,15 @@ class TaskManagerContents : public ChromeViews::View, virtual void ViewHierarchyChanged(bool is_add, ChromeViews::View* parent, ChromeViews::View* child); void GetSelection(std::vector<int>* selection); + void GetFocused(std::vector<int>* focused); // NativeButton::Listener implementation. virtual void ButtonPressed(ChromeViews::NativeButton* sender); // ChromeViews::TableViewObserver implementation. virtual void OnSelectionChanged(); + virtual void OnDoubleClick(); + virtual void OnKeyDown(unsigned short virtual_keycode); // ChromeViews::LinkController implementation. virtual void LinkActivated(ChromeViews::Link* source, int event_flags); @@ -721,6 +724,16 @@ void TaskManagerContents::GetSelection(std::vector<int>* selection) { } } +void TaskManagerContents::GetFocused(std::vector<int>* focused) { + DCHECK(focused); + int row_count = tab_table_->RowCount(); + for (int i = 0; i < row_count; ++i) { + // The TableView returns the selection starting from the end. + if (tab_table_->ItemHasTheFocus(i)) + focused->insert(focused->begin(), i); + } +} + // NativeButton::Listener implementation. void TaskManagerContents::ButtonPressed(ChromeViews::NativeButton* sender) { if (sender == kill_button_) @@ -733,6 +746,15 @@ void TaskManagerContents::OnSelectionChanged() { tab_table_->SelectedRowCount() > 0); } +void TaskManagerContents::OnDoubleClick() { + task_manager_->ActivateFocusedTab(); +} + +void TaskManagerContents::OnKeyDown(unsigned short virtual_keycode) { + if (virtual_keycode == VK_RETURN) + task_manager_->ActivateFocusedTab(); +} + // ChromeViews::LinkController implementation void TaskManagerContents::LinkActivated(ChromeViews::Link* source, int event_flags) { @@ -826,6 +848,34 @@ void TaskManager::KillSelectedProcesses() { } } +void TaskManager::ActivateFocusedTab() { + std::vector<int> focused; + contents_->GetFocused(&focused); + int focused_size = static_cast<int>(focused.size()); + + DCHECK(focused_size == 1); + + // Gracefully return if there is not exactly one item in focus. + if (focused_size != 1) + return; + + // Otherwise, the one focused thing should be one the user intends to bring + // forth, so get see if GetTabContents returns non-null. If it does, activate + // those contents. + int index = focused[0]; + + // GetTabContents returns a pointer to the relevant tab contents for the + // resource. If the index doesn't correspond to a Tab (i.e. refers to the + // Browser process or a plugin), GetTabContents will return NULL. + TabContents* chosen_tab_contents = + table_model_->resources_[index]->GetTabContents(); + + if (!chosen_tab_contents) + return; + + chosen_tab_contents->Activate(); +} + void TaskManager::AddResourceProvider(ResourceProvider* provider) { table_model_->AddResourceProvider(provider); } diff --git a/chrome/browser/task_manager.h b/chrome/browser/task_manager.h index 9b8687f..d35b1c2 100644 --- a/chrome/browser/task_manager.h +++ b/chrome/browser/task_manager.h @@ -5,6 +5,9 @@ #ifndef CHROME_BROWSER_TASK_MANAGER_H__ #define CHROME_BROWSER_TASK_MANAGER_H__ +#include <map> +#include <vector> + #include "base/lock.h" #include "base/singleton.h" #include "base/ref_counted.h" @@ -12,6 +15,7 @@ #include "chrome/views/dialog_delegate.h" #include "chrome/views/group_table_view.h" #include "chrome/browser/cache_manager_host.h" +#include "chrome/browser/tab_contents.h" #include "net/url_request/url_request_job_tracker.h" class MessageLoop; @@ -42,10 +46,16 @@ class TaskManager : public ChromeViews::DialogDelegate { // Resources from similar processes are grouped together by the task manager. class Resource { public: + virtual ~Resource() {} + virtual std::wstring GetTitle() const = 0; virtual SkBitmap GetIcon() const = 0; virtual HANDLE GetProcess() const = 0; + // A helper function for ActivateFocusedTab. Returns NULL by default + // because not all resources have an assoiciated tab. + virtual TabContents* GetTabContents() const {return NULL;} + // Whether this resource does report the network usage accurately. // This controls whether 0 or N/A is displayed when no bytes have been // reported as being read. This is because some plugins do not report the @@ -99,6 +109,10 @@ class TaskManager : public ChromeViews::DialogDelegate { // Terminates the selected tab(s) in the list. void KillSelectedProcesses(); + // Activates the browser tab associated with the focused row in the task + // manager table. This happens when the user double clicks or hits return. + void ActivateFocusedTab(); + void AddResourceProvider(ResourceProvider* provider); void RemoveResourceProvider(ResourceProvider* provider); diff --git a/chrome/browser/task_manager_resource_providers.cc b/chrome/browser/task_manager_resource_providers.cc index ad34101..b3fe407 100644 --- a/chrome/browser/task_manager_resource_providers.cc +++ b/chrome/browser/task_manager_resource_providers.cc @@ -62,6 +62,10 @@ HANDLE TaskManagerWebContentsResource::GetProcess() const { return process_; } +TabContents* TaskManagerWebContentsResource::GetTabContents() const { + return dynamic_cast<TabContents*>(web_contents_); +} + //////////////////////////////////////////////////////////////////////////////// // TaskManagerWebContentsResourceProvider class //////////////////////////////////////////////////////////////////////////////// diff --git a/chrome/browser/task_manager_resource_providers.h b/chrome/browser/task_manager_resource_providers.h index cd300f8..bece876 100644 --- a/chrome/browser/task_manager_resource_providers.h +++ b/chrome/browser/task_manager_resource_providers.h @@ -24,6 +24,8 @@ class TaskManagerWebContentsResource : public TaskManager::Resource { std::wstring GetTitle() const; SkBitmap GetIcon() const; HANDLE GetProcess() const; + TabContents* GetTabContents() const; + // WebContents always provide the network usage. bool SupportNetworkUsage() const { return true; } void SetSupportNetworkUsage() { }; diff --git a/chrome/views/group_table_view.cc b/chrome/views/group_table_view.cc index 4bc3f2b..5088997 100644 --- a/chrome/views/group_table_view.cc +++ b/chrome/views/group_table_view.cc @@ -87,6 +87,7 @@ void GroupTableView::OnKeyDown(unsigned short virtual_keycode) { // for the list view control to actually switch the focus, the right item // will be selected. if ((virtual_keycode != VK_UP) && (virtual_keycode != VK_DOWN)) { + TableView::OnKeyDown(virtual_keycode); return; } diff --git a/chrome/views/table_view.cc b/chrome/views/table_view.cc index 2ca2f37..6d1bc60 100644 --- a/chrome/views/table_view.cc +++ b/chrome/views/table_view.cc @@ -880,7 +880,7 @@ void TableView::UpdateListViewCache0(int start, int length, bool add) { std::wstring text = model_->GetText(i, visible_columns_[0]); item.iItem = i; item.pszText = const_cast<LPWSTR>(text.c_str()); - item.state = INDEXTOSTATEIMAGEMASK(model_->IsChecked(i) ? 2 : 1) ; + item.state = INDEXTOSTATEIMAGEMASK(model_->IsChecked(i) ? 2 : 1); ListView_SetItem(list_view_, &item); } } @@ -935,6 +935,12 @@ void TableView::OnSelectedStateChanged(int item, bool is_selected) { } } +void TableView::OnKeyDown(unsigned short virtual_keycode) { + if (!ignore_listview_change_ && table_view_observer_) { + table_view_observer_->OnKeyDown(virtual_keycode); + } +} + void TableView::OnCheckedStateChanged(int item, bool is_checked) { if (!ignore_listview_change_) { model_->SetChecked(item, is_checked); diff --git a/chrome/views/table_view.h b/chrome/views/table_view.h index db86537..30f28f8 100644 --- a/chrome/views/table_view.h +++ b/chrome/views/table_view.h @@ -7,6 +7,9 @@ #include <windows.h> +#include <map> +#include <vector> + #include "base/logging.h" #include "chrome/common/l10n_util.h" #include "chrome/views/native_control.h" @@ -130,8 +133,14 @@ struct TableColumn { LEFT, RIGHT, CENTER }; - TableColumn() : id(0), title(), alignment(LEFT), width(-1), percent(), min_visible_width(0) {} - + TableColumn() + : id(0), + title(), + alignment(LEFT), + width(-1), + percent(), + min_visible_width(0) { + } TableColumn(int id, const std::wstring title, Alignment alignment, int width) : id(id), title(title), @@ -194,7 +203,8 @@ struct TableColumn { int width; float percent; - // The minimum width required for all items in this column (including the header) + // The minimum width required for all items in this column + // (including the header) // to be visible. int min_visible_width; }; @@ -217,11 +227,16 @@ class TableSelectionIterator { // TableViewObserver is notified about the TableView selection. class TableViewObserver { public: + virtual ~TableViewObserver() {} + // Invoked when the selection changes. virtual void OnSelectionChanged() = 0; // Optional method invoked when the user double clicks on the table. virtual void OnDoubleClick() {} + + // Optional method invoked when the user hits a key with the table in focus. + virtual void OnKeyDown(unsigned short virtual_keycode) {} }; class TableView : public NativeControl, @@ -340,6 +355,10 @@ class TableView : public NativeControl, // Notification from the ListView that the used double clicked the table. virtual void OnDoubleClick(); + // Subclasses can implement this method if they need to be notified of a key + // press event. Other wise, it appeals to table_view_observer_ + virtual void OnKeyDown(unsigned short virtual_keycode); + // Invoked to customize the colors or font at a particular cell. If you // change the colors or font, return true. This is only invoked if // SetCustomColorsEnabled(true) has been invoked. @@ -357,10 +376,6 @@ class TableView : public NativeControl, virtual void PostPaint(int row, int column, bool selected, const CRect& bounds, HDC device_context) { } - // Subclasses can implement this method if they need to be notified of a key - // press event. - virtual void OnKeyDown(unsigned short virtual_keycode) {} - virtual HWND CreateNativeControl(HWND parent_container); virtual LRESULT OnNotify(int w_param, LPNMHDR l_param); @@ -374,7 +389,7 @@ class TableView : public NativeControl, // cast from GetWindowLongPtr would break the pointer if it is pointing to a // subclass (in the OO sense of TableView). struct TableViewWrapper { - TableViewWrapper(TableView* view) : table_view(view) { } + explicit TableViewWrapper(TableView* view) : table_view(view) { } TableView* table_view; }; @@ -496,7 +511,6 @@ class TableView : public NativeControl, DISALLOW_COPY_AND_ASSIGN(TableView); }; - } #endif // CHROME_VIEWS_TABLE_VIEW_H_ |