Chromium Code Reviews| Index: chrome/browser/ui/panels/panel_browser_frame_view.cc |
| =================================================================== |
| --- chrome/browser/ui/panels/panel_browser_frame_view.cc (revision 84897) |
| +++ 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/11 18:06:10
I meant this goes below the next line.
jianli
2011/05/11 18:31:31
Done.
|
| #include "views/controls/label.h" |
| #include "views/painter.h" |
| #include "views/window/window.h" |
| @@ -342,9 +344,45 @@ |
| } |
| 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) { |
| + return false; |
| +} |
| + |
| +void PanelBrowserFrameView::ExecuteCommand(int command_id) { |
| + switch (command_id) { |
| + case COMMAND_MINIMIZE_ALL: |
| + browser_view_->panel()->manager()->MinimizeAll(); |
| + break; |
| + case COMMAND_RESTORE_ALL: |
| + browser_view_->panel()->manager()->RestoreAll(); |
| + break; |
| + case COMMAND_CLOSE_ALL: |
| + browser_view_->panel()->manager()->RemoveAllActive(); |
| + break; |
| + case COMMAND_ABOUT: |
| + 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 +520,57 @@ |
| 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 should_manipulate_all = |
| + browser_view_->panel()->manager()->active_count() > 1; |
| + bool should_restore_all = |
| + browser_view_->panel()->manager()->AreAllMinimized(); |
| + |
| + bool rebuild_menu_items = false; |
| + if (options_menu_contents_->GetItemCount() > 0) { |
| + bool manipulate_all = options_menu_contents_->GetItemCount() > 1; |
| + bool restore_all = |
| + options_menu_contents_->GetCommandIdAt(0) == COMMAND_RESTORE_ALL; |
|
jennb
2011/05/11 18:06:10
I wish there was a way to check HasCommandId(COMMA
|
| + |
| + if (manipulate_all == should_manipulate_all && |
| + restore_all == should_restore_all) { |
| + return; |
| + } |
| + |
| + rebuild_menu_items = true; |
| + options_menu_contents_->Clear(); |
| + } |
| + |
| + if (should_manipulate_all) { |
| + options_menu_contents_->AddItem( |
|
jennb
2011/05/11 18:06:10
It would be easier to read if you did:
if (should_
jianli
2011/05/11 18:31:31
Done.
|
| + should_restore_all ? COMMAND_RESTORE_ALL : COMMAND_MINIMIZE_ALL, |
| + l10n_util::GetStringUTF16( |
| + should_restore_all ? IDS_PANEL_OPTIONS_MENU_RESTORE_ALL : |
| + IDS_PANEL_OPTIONS_MENU_MINIMIZE_ALL)); |
| + options_menu_contents_->AddItem( |
| + COMMAND_CLOSE_ALL, |
| + l10n_util::GetStringUTF16(IDS_PANEL_OPTIONS_MENU_CLOSE_ALL)); |
| + options_menu_contents_->AddSeparator(); |
| + } |
| + |
| + options_menu_contents_->AddItem( |
| + COMMAND_ABOUT, l10n_util::GetStringUTF16(IDS_PANEL_OPTIONS_MENU_ABOUT)); |
| + |
| + // Do not call Rebuild() if we're building the menu for the first time. |
| + if (rebuild_menu_items) |
|
jennb
2011/05/11 18:06:10
Feels like this method should return true if optio
jianli
2011/05/11 18:31:31
Done. I also renamed CreateOptionsMenu to CreateOr
|
| + options_menu_->Rebuild(); |
| +} |