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/task_manager_win.cc

Issue 115378: Move Always On Top setting out of Window/WindowDelegate and into task manager... (Closed) Base URL: svn://chrome-svn.corp.google.com/chrome/trunk/src/
Patch Set: '' Created 11 years, 7 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
« no previous file with comments | « no previous file | chrome/browser/views/chrome_views_delegate.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) 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/task_manager.h" 5 #include "chrome/browser/task_manager.h"
6 6
7 #include "base/stats_table.h" 7 #include "base/stats_table.h"
8 #include "chrome/app/chrome_dll_resource.h"
8 #include "chrome/browser/browser_list.h" 9 #include "chrome/browser/browser_list.h"
9 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
10 #include "chrome/common/pref_names.h" 11 #include "chrome/common/pref_names.h"
11 #include "chrome/common/pref_service.h" 12 #include "chrome/common/pref_service.h"
12 #include "grit/chromium_strings.h" 13 #include "grit/chromium_strings.h"
13 #include "grit/generated_resources.h" 14 #include "grit/generated_resources.h"
14 #include "grit/theme_resources.h" 15 #include "grit/theme_resources.h"
15 #include "views/accelerator.h" 16 #include "views/accelerator.h"
16 #include "views/background.h" 17 #include "views/background.h"
17 #include "views/controls/button/native_button.h" 18 #include "views/controls/button/native_button.h"
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 virtual void GetSelection(std::vector<int>* selection); 184 virtual void GetSelection(std::vector<int>* selection);
184 virtual void GetFocused(std::vector<int>* focused); 185 virtual void GetFocused(std::vector<int>* focused);
185 virtual void OpenWindow(); 186 virtual void OpenWindow();
186 187
187 // ButtonListener implementation. 188 // ButtonListener implementation.
188 virtual void ButtonPressed(views::Button* sender); 189 virtual void ButtonPressed(views::Button* sender);
189 190
190 // views::DialogDelegate 191 // views::DialogDelegate
191 virtual bool CanResize() const; 192 virtual bool CanResize() const;
192 virtual bool CanMaximize() const; 193 virtual bool CanMaximize() const;
193 virtual bool IsAlwaysOnTop() const; 194 virtual bool ExecuteWindowsCommand(int command_id);
194 virtual bool HasAlwaysOnTopMenu() const;
195 virtual std::wstring GetWindowTitle() const; 195 virtual std::wstring GetWindowTitle() const;
196 virtual std::wstring GetWindowName() const; 196 virtual std::wstring GetWindowName() const;
197 virtual int GetDialogButtons() const; 197 virtual int GetDialogButtons() const;
198 virtual void WindowClosing(); 198 virtual void WindowClosing();
199 virtual void DeleteDelegate(); 199 virtual void DeleteDelegate();
200 virtual views::View* GetContentsView(); 200 virtual views::View* GetContentsView();
201 201
202 // views::TableViewObserver implementation. 202 // views::TableViewObserver implementation.
203 virtual void OnSelectionChanged(); 203 virtual void OnSelectionChanged();
204 virtual void OnDoubleClick(); 204 virtual void OnDoubleClick();
205 virtual void OnKeyDown(unsigned short virtual_keycode); 205 virtual void OnKeyDown(unsigned short virtual_keycode);
206 206
207 // views::LinkController implementation. 207 // views::LinkController implementation.
208 virtual void LinkActivated(views::Link* source, int event_flags); 208 virtual void LinkActivated(views::Link* source, int event_flags);
209 209
210 // Called by the column picker to pick up any new stat counters that 210 // Called by the column picker to pick up any new stat counters that
211 // may have appeared since last time. 211 // may have appeared since last time.
212 void UpdateStatsCounters(); 212 void UpdateStatsCounters();
213 213
214 // Menu::Delegate 214 // Menu::Delegate
215 virtual void ShowContextMenu(views::View* source, 215 virtual void ShowContextMenu(views::View* source,
216 int x, 216 int x,
217 int y, 217 int y,
218 bool is_mouse_gesture); 218 bool is_mouse_gesture);
219 virtual bool IsItemChecked(int id) const; 219 virtual bool IsItemChecked(int id) const;
220 virtual void ExecuteCommand(int id); 220 virtual void ExecuteCommand(int id);
221 221
222 private: 222 private:
223 // Initialize the state of the always-on-top setting as the window is shown.
jcampan 2009/05/14 21:15:09 Nit: Initializes
224 void InitAlwaysOnTopState();
225
226 // Adds an always on top item to the window's system menu.
227 void AddAlwaysOnTopSystemMenuItem();
228
229 // Restores saved always on top state from a previous session.
230 bool GetSavedAlwaysOnTopState(bool* always_on_top) const;
231
223 scoped_ptr<views::NativeButton> kill_button_; 232 scoped_ptr<views::NativeButton> kill_button_;
224 scoped_ptr<views::Link> about_memory_link_; 233 scoped_ptr<views::Link> about_memory_link_;
225 views::GroupTableView* tab_table_; 234 views::GroupTableView* tab_table_;
226 235
227 TaskManager* task_manager_; 236 TaskManager* task_manager_;
228 237
229 TaskManagerModel* model_; 238 TaskManagerModel* model_;
230 239
231 // all possible columns, not necessarily visible 240 // all possible columns, not necessarily visible
232 std::vector<views::TableColumn> columns_; 241 std::vector<views::TableColumn> columns_;
233 242
234 scoped_ptr<TaskManagerTableModel> table_model_; 243 scoped_ptr<TaskManagerTableModel> table_model_;
235 244
245 // True when the Task Manager window should be shown on top of other windows.
246 bool is_always_on_top_;
247
248 // We need to own the text of the menu, the Windows API does not copy it.
249 std::wstring always_on_top_menu_text_;
250
236 DISALLOW_COPY_AND_ASSIGN(TaskManagerViewImpl); 251 DISALLOW_COPY_AND_ASSIGN(TaskManagerViewImpl);
237 }; 252 };
238 253
239 TaskManagerViewImpl::TaskManagerViewImpl(TaskManager* task_manager, 254 TaskManagerViewImpl::TaskManagerViewImpl(TaskManager* task_manager,
240 TaskManagerModel* model) 255 TaskManagerModel* model)
241 : task_manager_(task_manager), 256 : task_manager_(task_manager),
242 model_(model) { 257 model_(model),
258 is_always_on_top_(false) {
243 Init(); 259 Init();
244 } 260 }
245 261
246 TaskManagerViewImpl::~TaskManagerViewImpl() { 262 TaskManagerViewImpl::~TaskManagerViewImpl() {
247 } 263 }
248 264
249 void TaskManagerViewImpl::Init() { 265 void TaskManagerViewImpl::Init() {
250 table_model_.reset(new TaskManagerTableModel(model_)); 266 table_model_.reset(new TaskManagerTableModel(model_));
251 267
252 columns_.push_back(views::TableColumn(IDS_TASK_MANAGER_PAGE_COLUMN, 268 columns_.push_back(views::TableColumn(IDS_TASK_MANAGER_PAGE_COLUMN,
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 if (tab_table_->ItemHasTheFocus(i)) 419 if (tab_table_->ItemHasTheFocus(i))
404 focused->insert(focused->begin(), i); 420 focused->insert(focused->begin(), i);
405 } 421 }
406 } 422 }
407 423
408 void TaskManagerViewImpl::OpenWindow() { 424 void TaskManagerViewImpl::OpenWindow() {
409 if (window()) { 425 if (window()) {
410 window()->Activate(); 426 window()->Activate();
411 } else { 427 } else {
412 views::Window::CreateChromeWindow(NULL, gfx::Rect(), this); 428 views::Window::CreateChromeWindow(NULL, gfx::Rect(), this);
429 InitAlwaysOnTopState();
413 model_->StartUpdating(); 430 model_->StartUpdating();
414 window()->Show(); 431 window()->Show();
415 } 432 }
416 } 433 }
417 434
418 // ButtonListener implementation. 435 // ButtonListener implementation.
419 void TaskManagerViewImpl::ButtonPressed(views::Button* sender) { 436 void TaskManagerViewImpl::ButtonPressed(views::Button* sender) {
420 if (sender == kill_button_.get()) 437 if (sender == kill_button_.get())
421 task_manager_->KillSelectedProcesses(); 438 task_manager_->KillSelectedProcesses();
422 } 439 }
423 440
424 // DialogDelegate implementation. 441 // DialogDelegate implementation.
425 bool TaskManagerViewImpl::CanResize() const { 442 bool TaskManagerViewImpl::CanResize() const {
426 return true; 443 return true;
427 } 444 }
428 445
429 bool TaskManagerViewImpl::CanMaximize() const { 446 bool TaskManagerViewImpl::CanMaximize() const {
430 return true; 447 return true;
431 } 448 }
432 449
433 bool TaskManagerViewImpl::IsAlwaysOnTop() const { 450 bool TaskManagerViewImpl::ExecuteWindowsCommand(int command_id) {
434 return true; 451 if (command_id == IDC_ALWAYS_ON_TOP) {
452 is_always_on_top_ = !is_always_on_top_;
453
454 // Change the menu check state.
455 HMENU system_menu = GetSystemMenu(GetWindow()->GetNativeWindow(), FALSE);
456 MENUITEMINFO menu_info;
457 memset(&menu_info, 0, sizeof(MENUITEMINFO));
458 menu_info.cbSize = sizeof(MENUITEMINFO);
459 BOOL r = GetMenuItemInfo(system_menu, IDC_ALWAYS_ON_TOP,
460 FALSE, &menu_info);
461 DCHECK(r);
462 menu_info.fMask = MIIM_STATE;
463 if (is_always_on_top_)
464 menu_info.fState = MFS_CHECKED;
465 r = SetMenuItemInfo(system_menu, IDC_ALWAYS_ON_TOP, FALSE, &menu_info);
466
467 // Now change the actual window's behavior.
468 window()->SetIsAlwaysOnTop(is_always_on_top_);
469
470 // Save the state.
471 if (g_browser_process->local_state()) {
472 DictionaryValue* window_preferences =
473 g_browser_process->local_state()->GetMutableDictionary(
474 GetWindowName().c_str());
475 window_preferences->SetBoolean(L"always_on_top", is_always_on_top_);
476 }
477 return true;
478 }
479 return false;
435 } 480 }
436 481
437 bool TaskManagerViewImpl::HasAlwaysOnTopMenu() const {
438 return true;
439 };
440
441 std::wstring TaskManagerViewImpl::GetWindowTitle() const { 482 std::wstring TaskManagerViewImpl::GetWindowTitle() const {
442 return l10n_util::GetString(IDS_TASK_MANAGER_TITLE); 483 return l10n_util::GetString(IDS_TASK_MANAGER_TITLE);
443 } 484 }
444 485
445 std::wstring TaskManagerViewImpl::GetWindowName() const { 486 std::wstring TaskManagerViewImpl::GetWindowName() const {
446 return prefs::kTaskManagerWindowPlacement; 487 return prefs::kTaskManagerWindowPlacement;
447 } 488 }
448 489
449 int TaskManagerViewImpl::GetDialogButtons() const { 490 int TaskManagerViewImpl::GetDialogButtons() const {
450 return MessageBoxFlags::DIALOGBUTTON_NONE; 491 return MessageBoxFlags::DIALOGBUTTON_NONE;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 } 548 }
508 549
509 bool TaskManagerViewImpl::IsItemChecked(int id) const { 550 bool TaskManagerViewImpl::IsItemChecked(int id) const {
510 return tab_table_->IsColumnVisible(id); 551 return tab_table_->IsColumnVisible(id);
511 } 552 }
512 553
513 void TaskManagerViewImpl::ExecuteCommand(int id) { 554 void TaskManagerViewImpl::ExecuteCommand(int id) {
514 tab_table_->SetColumnVisibility(id, !tab_table_->IsColumnVisible(id)); 555 tab_table_->SetColumnVisibility(id, !tab_table_->IsColumnVisible(id));
515 } 556 }
516 557
558 void TaskManagerViewImpl::InitAlwaysOnTopState() {
559 is_always_on_top_ = false;
560 if (GetSavedAlwaysOnTopState(&is_always_on_top_))
561 window()->SetIsAlwaysOnTop(is_always_on_top_);
562 AddAlwaysOnTopSystemMenuItem();
563 }
564
565 void TaskManagerViewImpl::AddAlwaysOnTopSystemMenuItem() {
566 // The Win32 API requires that we own the text.
567 always_on_top_menu_text_ = l10n_util::GetString(IDS_ALWAYS_ON_TOP);
568
569 // Let's insert a menu to the window.
570 HMENU system_menu = ::GetSystemMenu(GetWindow()->GetNativeWindow(), FALSE);
571 int index = ::GetMenuItemCount(system_menu) - 1;
572 if (index < 0) {
573 // Paranoia check.
574 NOTREACHED();
575 index = 0;
576 }
577 // First we add the separator.
578 MENUITEMINFO menu_info;
579 memset(&menu_info, 0, sizeof(MENUITEMINFO));
580 menu_info.cbSize = sizeof(MENUITEMINFO);
581 menu_info.fMask = MIIM_FTYPE;
582 menu_info.fType = MFT_SEPARATOR;
583 ::InsertMenuItem(system_menu, index, TRUE, &menu_info);
584
585 // Then the actual menu.
586 menu_info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING | MIIM_STATE;
587 menu_info.fType = MFT_STRING;
588 menu_info.fState = MFS_ENABLED;
589 if (is_always_on_top_)
590 menu_info.fState |= MFS_CHECKED;
591 menu_info.wID = IDC_ALWAYS_ON_TOP;
592 menu_info.dwTypeData = const_cast<wchar_t*>(always_on_top_menu_text_.c_str());
593 ::InsertMenuItem(system_menu, index, TRUE, &menu_info);
594 }
595
596 bool TaskManagerViewImpl::GetSavedAlwaysOnTopState(bool* always_on_top) const {
597 if (!g_browser_process->local_state())
598 return false;
599
600 const DictionaryValue* dictionary =
601 g_browser_process->local_state()->GetDictionary(GetWindowName().c_str());
602 return dictionary && dictionary->GetBoolean(L"always_on_top", always_on_top) & &
jcampan 2009/05/14 21:15:09 Nit: is it more than 80 chars?
603 always_on_top;
604 }
605
517 } // namespace 606 } // namespace
518 607
519 void TaskManager::Init() { 608 void TaskManager::Init() {
520 view_.reset(new TaskManagerViewImpl(this, model_.get())); 609 view_.reset(new TaskManagerViewImpl(this, model_.get()));
521 } 610 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/views/chrome_views_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698