Index: chrome/browser/ui/panels/panel_browser_frame_view.cc |
=================================================================== |
--- chrome/browser/ui/panels/panel_browser_frame_view.cc (revision 84709) |
+++ chrome/browser/ui/panels/panel_browser_frame_view.cc (working copy) |
@@ -7,6 +7,7 @@ |
#include "chrome/browser/themes/theme_service.h" |
#include "chrome/browser/ui/panels/panel.h" |
#include "chrome/browser/ui/panels/panel_browser_view.h" |
+#include "chrome/browser/ui/panels/panel_manager.h" |
#include "content/browser/tab_contents/tab_contents.h" |
#include "grit/app_resources.h" |
#include "grit/generated_resources.h" |
@@ -19,6 +20,7 @@ |
#include "ui/gfx/canvas_skia.h" |
#include "views/controls/button/image_button.h" |
#include "views/controls/button/menu_button.h" |
+#include "views/controls/menu/menu_2.h" |
jennb
2011/05/10 22:38:44
alpha ordering wrong
jianli
2011/05/10 23:46:58
I think ".../menu/..." should be after ".../button
|
#include "views/controls/label.h" |
#include "views/painter.h" |
#include "views/window/window.h" |
@@ -137,7 +139,9 @@ |
options_button_(NULL), |
close_button_(NULL), |
title_icon_(NULL), |
- title_label_(NULL) { |
+ title_label_(NULL), |
+ option_menu_manipulate_all_enabled_(false), |
+ option_menu_restore_all_enabled_(false) { |
EnsureResourcesInitialized(); |
options_button_ = new views::MenuButton(NULL, std::wstring(), this, false); |
@@ -342,9 +346,46 @@ |
} |
void PanelBrowserFrameView::RunMenu(View* source, const gfx::Point& pt) { |
- NOTIMPLEMENTED(); |
+ CreateOptionsMenu(); |
+ options_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT); |
} |
+bool PanelBrowserFrameView::IsCommandIdChecked(int command_id) const { |
+ // Nothing in the menu is checked. |
+ return false; |
+} |
+ |
+bool PanelBrowserFrameView::IsCommandIdEnabled(int command_id) const { |
+ // All the menu options are always enabled. |
+ return true; |
+} |
+ |
+bool PanelBrowserFrameView::GetAcceleratorForCommandId( |
+ int command_id, ui::Accelerator* accelerator) { |
+ // Currently no accelerators. |
jennb
2011/05/10 22:38:44
Need TODO to add accelerators? or NOTIMPLEMENTED()
jianli
2011/05/10 23:46:58
I removed the comment since it is misleading. We d
|
+ return false; |
+} |
+ |
+void PanelBrowserFrameView::ExecuteCommand(int command_id) { |
+ switch (command_id) { |
+ case kMinimizeAllCommand: |
+ browser_view_->panel()->manager()->MinimizeAll(); |
+ break; |
+ case kRestoreAllCommand: |
+ browser_view_->panel()->manager()->RestoreAll(); |
+ break; |
+ case kCloseAllCommand: |
+ browser_view_->panel()->manager()->RemoveAllActive(); |
+ break; |
+ case kAboutCommand: |
+ NOTIMPLEMENTED(); |
+ break; |
+ default: |
+ NOTREACHED(); |
+ break; |
+ } |
+} |
+ |
bool PanelBrowserFrameView::ShouldTabIconViewAnimate() const { |
// This function is queried during the creation of the window as the |
// TabIconView we host is initialized, so we need to NULL check the selected |
@@ -482,3 +523,62 @@ |
void PanelBrowserFrameView::OnActivationChanged(bool active) { |
SchedulePaint(); |
} |
+ |
+void PanelBrowserFrameView::CreateOptionsMenu() { |
+ if (!options_menu_contents_.get()) |
+ options_menu_contents_.reset(new ui::SimpleMenuModel(this)); |
+ CreateOptionsMenuItems(); |
+ if (!options_menu_.get()) |
+ options_menu_.reset(new views::Menu2(options_menu_contents_.get())); |
+} |
+ |
+void PanelBrowserFrameView::CreateOptionsMenuItems() { |
+ // Determines if we need to rebuild the menu items. The menu items might |
+ // be different if any of the following have been changed since the last |
+ // time: |
+ // 1) Multiple panel vs. single panel. |
+ // 2) All panels minimized or not. |
+ bool previous_option_menu_manipulate_all_enabled = |
+ option_menu_manipulate_all_enabled_; |
+ bool previous_option_menu_restore_all_enabled_ = |
+ option_menu_restore_all_enabled_; |
+ option_menu_manipulate_all_enabled_ = |
jennb
2011/05/10 22:38:44
Oh, I misunderstood that this is menu-state, not p
jianli
2011/05/10 23:46:58
Changed to check the state by querying the menu.
|
+ browser_view_->panel()->manager()->active_count() > 1; |
+ option_menu_restore_all_enabled_ = |
+ browser_view_->panel()->manager()->AreAllMinimized(); |
+ |
+ bool rebuild_menu_items = false; |
+ if (options_menu_contents_->GetItemCount() > 0) { |
+ if (previous_option_menu_manipulate_all_enabled == |
+ option_menu_manipulate_all_enabled_ && |
+ previous_option_menu_restore_all_enabled_ == |
+ option_menu_restore_all_enabled_) { |
+ return; |
+ } |
+ |
+ rebuild_menu_items = true; |
+ options_menu_contents_->Clear(); |
+ } |
+ |
+ const string16 minimize_all_text = |
jennb
2011/05/10 22:38:44
Move the *_all* strings inside where they are actu
jianli
2011/05/10 23:46:58
Done.
|
+ l10n_util::GetStringUTF16(IDS_PANEL_OPTIONS_MENU_MINIMIZE_ALL); |
+ const string16 restore_all_text = |
+ l10n_util::GetStringUTF16(IDS_PANEL_OPTIONS_MENU_RESTORE_ALL); |
+ const string16 close_all_text = |
+ l10n_util::GetStringUTF16(IDS_PANEL_OPTIONS_MENU_CLOSE_ALL); |
+ const string16 about_text = |
jennb
2011/05/10 22:38:44
Move down to where about menu item is added.
jianli
2011/05/10 23:46:58
Done.
|
+ l10n_util::GetStringUTF16(IDS_PANEL_OPTIONS_MENU_ABOUT); |
+ |
+ if (option_menu_manipulate_all_enabled_) { |
+ if (option_menu_restore_all_enabled_) |
+ options_menu_contents_->AddItem(kRestoreAllCommand, restore_all_text); |
+ else |
+ options_menu_contents_->AddItem(kMinimizeAllCommand, minimize_all_text); |
+ options_menu_contents_->AddItem(kCloseAllCommand, close_all_text); |
+ options_menu_contents_->AddSeparator(); |
+ } |
+ options_menu_contents_->AddItem(kAboutCommand, about_text); |
+ |
+ if (rebuild_menu_items) |
jennb
2011/05/10 22:38:44
Seems like if you got this far, rebuild_menu_items
jianli
2011/05/10 23:46:58
This function could be called first time when ther
|
+ options_menu_->Rebuild(); |
+} |