Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
| (...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 604 // DialogDelegate implementation. | 604 // DialogDelegate implementation. |
| 605 bool TaskManagerView::CanResize() const { | 605 bool TaskManagerView::CanResize() const { |
| 606 return true; | 606 return true; |
| 607 } | 607 } |
| 608 | 608 |
| 609 bool TaskManagerView::CanMaximize() const { | 609 bool TaskManagerView::CanMaximize() const { |
| 610 return true; | 610 return true; |
| 611 } | 611 } |
| 612 | 612 |
| 613 bool TaskManagerView::ExecuteWindowsCommand(int command_id) { | 613 bool TaskManagerView::ExecuteWindowsCommand(int command_id) { |
| 614 #if defined(OS_WIN) && !defined(USE_AURA) | |
| 614 if (command_id == IDC_ALWAYS_ON_TOP) { | 615 if (command_id == IDC_ALWAYS_ON_TOP) { |
| 615 is_always_on_top_ = !is_always_on_top_; | 616 is_always_on_top_ = !is_always_on_top_; |
| 616 | 617 |
| 617 // Change the menu check state. | 618 // Change the menu check state. |
| 618 HMENU system_menu = GetSystemMenu(GetWidget()->GetNativeWindow(), FALSE); | 619 HMENU system_menu = GetSystemMenu(GetWidget()->GetNativeWindow(), FALSE); |
| 619 MENUITEMINFO menu_info; | 620 MENUITEMINFO menu_info; |
| 620 memset(&menu_info, 0, sizeof(MENUITEMINFO)); | 621 memset(&menu_info, 0, sizeof(MENUITEMINFO)); |
| 621 menu_info.cbSize = sizeof(MENUITEMINFO); | 622 menu_info.cbSize = sizeof(MENUITEMINFO); |
| 622 BOOL r = GetMenuItemInfo(system_menu, IDC_ALWAYS_ON_TOP, | 623 BOOL r = GetMenuItemInfo(system_menu, IDC_ALWAYS_ON_TOP, |
| 623 FALSE, &menu_info); | 624 FALSE, &menu_info); |
| 624 DCHECK(r); | 625 DCHECK(r); |
| 625 menu_info.fMask = MIIM_STATE; | 626 menu_info.fMask = MIIM_STATE; |
| 626 if (is_always_on_top_) | 627 if (is_always_on_top_) |
| 627 menu_info.fState = MFS_CHECKED; | 628 menu_info.fState = MFS_CHECKED; |
| 628 r = SetMenuItemInfo(system_menu, IDC_ALWAYS_ON_TOP, FALSE, &menu_info); | 629 r = SetMenuItemInfo(system_menu, IDC_ALWAYS_ON_TOP, FALSE, &menu_info); |
| 629 | 630 |
| 630 // Now change the actual window's behavior. | 631 // Now change the actual window's behavior. |
| 631 GetWidget()->SetAlwaysOnTop(is_always_on_top_); | 632 GetWidget()->SetAlwaysOnTop(is_always_on_top_); |
| 632 | 633 |
| 633 // Save the state. | 634 // Save the state. |
| 634 if (g_browser_process->local_state()) { | 635 if (g_browser_process->local_state()) { |
| 635 DictionaryPrefUpdate update(g_browser_process->local_state(), | 636 DictionaryPrefUpdate update(g_browser_process->local_state(), |
| 636 WideToUTF8(GetWindowName()).c_str()); | 637 WideToUTF8(GetWindowName()).c_str()); |
| 637 DictionaryValue* window_preferences = update.Get(); | 638 DictionaryValue* window_preferences = update.Get(); |
| 638 window_preferences->SetBoolean("always_on_top", is_always_on_top_); | 639 window_preferences->SetBoolean("always_on_top", is_always_on_top_); |
| 639 } | 640 } |
| 640 return true; | 641 return true; |
| 641 } | 642 } |
| 643 #endif | |
|
sky
2011/09/06 17:22:48
#else NOTIMPLEMENTED?
| |
| 642 return false; | 644 return false; |
| 643 } | 645 } |
| 644 | 646 |
| 645 std::wstring TaskManagerView::GetWindowTitle() const { | 647 std::wstring TaskManagerView::GetWindowTitle() const { |
| 646 return UTF16ToWide(l10n_util::GetStringUTF16(IDS_TASK_MANAGER_TITLE)); | 648 return UTF16ToWide(l10n_util::GetStringUTF16(IDS_TASK_MANAGER_TITLE)); |
| 647 } | 649 } |
| 648 | 650 |
| 649 std::wstring TaskManagerView::GetWindowName() const { | 651 std::wstring TaskManagerView::GetWindowName() const { |
| 650 return UTF8ToWide(prefs::kTaskManagerWindowPlacement); | 652 return UTF8ToWide(prefs::kTaskManagerWindowPlacement); |
| 651 } | 653 } |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 728 int row_count = tab_table_->RowCount(); | 730 int row_count = tab_table_->RowCount(); |
| 729 for (int i = 0; i < row_count; ++i) { | 731 for (int i = 0; i < row_count; ++i) { |
| 730 if (tab_table_->ItemHasTheFocus(i)) { | 732 if (tab_table_->ItemHasTheFocus(i)) { |
| 731 task_manager_->ActivateProcess(i); | 733 task_manager_->ActivateProcess(i); |
| 732 break; | 734 break; |
| 733 } | 735 } |
| 734 } | 736 } |
| 735 } | 737 } |
| 736 | 738 |
| 737 void TaskManagerView::AddAlwaysOnTopSystemMenuItem() { | 739 void TaskManagerView::AddAlwaysOnTopSystemMenuItem() { |
| 740 #if defined(OS_WIN) && !defined(USE_AURA) | |
| 738 // The Win32 API requires that we own the text. | 741 // The Win32 API requires that we own the text. |
| 739 always_on_top_menu_text_ = | 742 always_on_top_menu_text_ = |
| 740 UTF16ToWide(l10n_util::GetStringUTF16(IDS_ALWAYS_ON_TOP)); | 743 UTF16ToWide(l10n_util::GetStringUTF16(IDS_ALWAYS_ON_TOP)); |
| 741 | 744 |
| 742 // Let's insert a menu to the window. | 745 // Let's insert a menu to the window. |
| 743 HMENU system_menu = ::GetSystemMenu(GetWidget()->GetNativeWindow(), FALSE); | 746 HMENU system_menu = ::GetSystemMenu(GetWidget()->GetNativeWindow(), FALSE); |
| 744 int index = ::GetMenuItemCount(system_menu) - 1; | 747 int index = ::GetMenuItemCount(system_menu) - 1; |
| 745 if (index < 0) { | 748 if (index < 0) { |
| 746 // Paranoia check. | 749 // Paranoia check. |
| 747 NOTREACHED(); | 750 NOTREACHED(); |
| 748 index = 0; | 751 index = 0; |
| 749 } | 752 } |
| 750 // First we add the separator. | 753 // First we add the separator. |
| 751 MENUITEMINFO menu_info; | 754 MENUITEMINFO menu_info; |
| 752 memset(&menu_info, 0, sizeof(MENUITEMINFO)); | 755 memset(&menu_info, 0, sizeof(MENUITEMINFO)); |
| 753 menu_info.cbSize = sizeof(MENUITEMINFO); | 756 menu_info.cbSize = sizeof(MENUITEMINFO); |
| 754 menu_info.fMask = MIIM_FTYPE; | 757 menu_info.fMask = MIIM_FTYPE; |
| 755 menu_info.fType = MFT_SEPARATOR; | 758 menu_info.fType = MFT_SEPARATOR; |
| 756 ::InsertMenuItem(system_menu, index, TRUE, &menu_info); | 759 ::InsertMenuItem(system_menu, index, TRUE, &menu_info); |
| 757 | 760 |
| 758 // Then the actual menu. | 761 // Then the actual menu. |
| 759 menu_info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING | MIIM_STATE; | 762 menu_info.fMask = MIIM_FTYPE | MIIM_ID | MIIM_STRING | MIIM_STATE; |
| 760 menu_info.fType = MFT_STRING; | 763 menu_info.fType = MFT_STRING; |
| 761 menu_info.fState = MFS_ENABLED; | 764 menu_info.fState = MFS_ENABLED; |
| 762 if (is_always_on_top_) | 765 if (is_always_on_top_) |
| 763 menu_info.fState |= MFS_CHECKED; | 766 menu_info.fState |= MFS_CHECKED; |
| 764 menu_info.wID = IDC_ALWAYS_ON_TOP; | 767 menu_info.wID = IDC_ALWAYS_ON_TOP; |
| 765 menu_info.dwTypeData = const_cast<wchar_t*>(always_on_top_menu_text_.c_str()); | 768 menu_info.dwTypeData = const_cast<wchar_t*>(always_on_top_menu_text_.c_str()); |
| 766 ::InsertMenuItem(system_menu, index, TRUE, &menu_info); | 769 ::InsertMenuItem(system_menu, index, TRUE, &menu_info); |
| 770 #endif | |
|
sky
2011/09/06 17:22:48
#else NOTIMPLEMENTED?
| |
| 767 } | 771 } |
| 768 | 772 |
| 769 bool TaskManagerView::GetSavedAlwaysOnTopState(bool* always_on_top) const { | 773 bool TaskManagerView::GetSavedAlwaysOnTopState(bool* always_on_top) const { |
| 770 if (!g_browser_process->local_state()) | 774 if (!g_browser_process->local_state()) |
| 771 return false; | 775 return false; |
| 772 | 776 |
| 773 const DictionaryValue* dictionary = | 777 const DictionaryValue* dictionary = |
| 774 g_browser_process->local_state()->GetDictionary( | 778 g_browser_process->local_state()->GetDictionary( |
| 775 WideToUTF8(GetWindowName()).c_str()); | 779 WideToUTF8(GetWindowName()).c_str()); |
| 776 return dictionary && | 780 return dictionary && |
| 777 dictionary->GetBoolean("always_on_top", always_on_top) && always_on_top; | 781 dictionary->GetBoolean("always_on_top", always_on_top) && always_on_top; |
| 778 } | 782 } |
| 779 | 783 |
| 780 } // namespace | 784 } // namespace |
| 781 | 785 |
| 782 namespace browser { | 786 namespace browser { |
| 783 | 787 |
| 784 // Declared in browser_dialogs.h so others don't need to depend on our header. | 788 // Declared in browser_dialogs.h so others don't need to depend on our header. |
| 785 void ShowTaskManager() { | 789 void ShowTaskManager() { |
| 786 TaskManagerView::Show(false); | 790 TaskManagerView::Show(false); |
| 787 } | 791 } |
| 788 | 792 |
| 789 void ShowBackgroundPages() { | 793 void ShowBackgroundPages() { |
| 790 TaskManagerView::Show(true); | 794 TaskManagerView::Show(true); |
| 791 } | 795 } |
| 792 | 796 |
| 793 } // namespace browser | 797 } // namespace browser |
| OLD | NEW |