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/ui/panels/panel_browser_frame_view.h" | 5 #include "chrome/browser/ui/panels/panel_browser_frame_view.h" |
6 | 6 |
7 #include "chrome/browser/themes/theme_service.h" | 7 #include "chrome/browser/themes/theme_service.h" |
8 #include "chrome/browser/ui/panels/panel.h" | 8 #include "chrome/browser/ui/panels/panel.h" |
9 #include "chrome/browser/ui/panels/panel_browser_view.h" | 9 #include "chrome/browser/ui/panels/panel_browser_view.h" |
10 #include "chrome/browser/ui/panels/panel_manager.h" | |
10 #include "content/browser/tab_contents/tab_contents.h" | 11 #include "content/browser/tab_contents/tab_contents.h" |
11 #include "grit/app_resources.h" | 12 #include "grit/app_resources.h" |
12 #include "grit/generated_resources.h" | 13 #include "grit/generated_resources.h" |
13 #include "grit/theme_resources.h" | 14 #include "grit/theme_resources.h" |
14 #include "grit/theme_resources_standard.h" | 15 #include "grit/theme_resources_standard.h" |
15 #include "third_party/skia/include/effects/SkGradientShader.h" | 16 #include "third_party/skia/include/effects/SkGradientShader.h" |
16 #include "ui/base/accessibility/accessible_view_state.h" | 17 #include "ui/base/accessibility/accessible_view_state.h" |
17 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
18 #include "ui/base/resource/resource_bundle.h" | 19 #include "ui/base/resource/resource_bundle.h" |
19 #include "ui/gfx/canvas_skia.h" | 20 #include "ui/gfx/canvas_skia.h" |
20 #include "views/controls/button/image_button.h" | 21 #include "views/controls/button/image_button.h" |
21 #include "views/controls/button/menu_button.h" | 22 #include "views/controls/button/menu_button.h" |
23 #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
| |
22 #include "views/controls/label.h" | 24 #include "views/controls/label.h" |
23 #include "views/painter.h" | 25 #include "views/painter.h" |
24 #include "views/window/window.h" | 26 #include "views/window/window.h" |
25 #include "views/window/window_shape.h" | 27 #include "views/window/window_shape.h" |
26 | 28 |
27 #if defined(OS_LINUX) | 29 #if defined(OS_LINUX) |
28 #include "views/window/hit_test.h" | 30 #include "views/window/hit_test.h" |
29 #endif | 31 #endif |
30 | 32 |
31 namespace { | 33 namespace { |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
130 | 132 |
131 PanelBrowserFrameView::PanelBrowserFrameView(BrowserFrame* frame, | 133 PanelBrowserFrameView::PanelBrowserFrameView(BrowserFrame* frame, |
132 PanelBrowserView* browser_view) | 134 PanelBrowserView* browser_view) |
133 : BrowserNonClientFrameView(), | 135 : BrowserNonClientFrameView(), |
134 frame_(frame), | 136 frame_(frame), |
135 browser_view_(browser_view), | 137 browser_view_(browser_view), |
136 paint_state_(NOT_PAINTED), | 138 paint_state_(NOT_PAINTED), |
137 options_button_(NULL), | 139 options_button_(NULL), |
138 close_button_(NULL), | 140 close_button_(NULL), |
139 title_icon_(NULL), | 141 title_icon_(NULL), |
140 title_label_(NULL) { | 142 title_label_(NULL), |
143 option_menu_manipulate_all_enabled_(false), | |
144 option_menu_restore_all_enabled_(false) { | |
141 EnsureResourcesInitialized(); | 145 EnsureResourcesInitialized(); |
142 | 146 |
143 options_button_ = new views::MenuButton(NULL, std::wstring(), this, false); | 147 options_button_ = new views::MenuButton(NULL, std::wstring(), this, false); |
144 options_button_->SetIcon(*(options_button_resources.normal_image)); | 148 options_button_->SetIcon(*(options_button_resources.normal_image)); |
145 options_button_->SetHoverIcon(*(options_button_resources.hover_image)); | 149 options_button_->SetHoverIcon(*(options_button_resources.hover_image)); |
146 options_button_->SetPushedIcon(*(options_button_resources.pushed_image)); | 150 options_button_->SetPushedIcon(*(options_button_resources.pushed_image)); |
147 options_button_->set_alignment(views::TextButton::ALIGN_CENTER); | 151 options_button_->set_alignment(views::TextButton::ALIGN_CENTER); |
148 options_button_->set_border(NULL); | 152 options_button_->set_border(NULL); |
149 // TODO(jianli): Hide options button by default and show it when mouse is over | 153 // TODO(jianli): Hide options button by default and show it when mouse is over |
150 // panel. | 154 // panel. |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
335 BrowserNonClientFrameView::OnMouseReleased(event); | 339 BrowserNonClientFrameView::OnMouseReleased(event); |
336 } | 340 } |
337 | 341 |
338 void PanelBrowserFrameView::ButtonPressed(views::Button* sender, | 342 void PanelBrowserFrameView::ButtonPressed(views::Button* sender, |
339 const views::Event& event) { | 343 const views::Event& event) { |
340 if (sender == close_button_) | 344 if (sender == close_button_) |
341 frame_->GetWindow()->CloseWindow(); | 345 frame_->GetWindow()->CloseWindow(); |
342 } | 346 } |
343 | 347 |
344 void PanelBrowserFrameView::RunMenu(View* source, const gfx::Point& pt) { | 348 void PanelBrowserFrameView::RunMenu(View* source, const gfx::Point& pt) { |
345 NOTIMPLEMENTED(); | 349 CreateOptionsMenu(); |
350 options_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT); | |
351 } | |
352 | |
353 bool PanelBrowserFrameView::IsCommandIdChecked(int command_id) const { | |
354 // Nothing in the menu is checked. | |
355 return false; | |
356 } | |
357 | |
358 bool PanelBrowserFrameView::IsCommandIdEnabled(int command_id) const { | |
359 // All the menu options are always enabled. | |
360 return true; | |
361 } | |
362 | |
363 bool PanelBrowserFrameView::GetAcceleratorForCommandId( | |
364 int command_id, ui::Accelerator* accelerator) { | |
365 // 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
| |
366 return false; | |
367 } | |
368 | |
369 void PanelBrowserFrameView::ExecuteCommand(int command_id) { | |
370 switch (command_id) { | |
371 case kMinimizeAllCommand: | |
372 browser_view_->panel()->manager()->MinimizeAll(); | |
373 break; | |
374 case kRestoreAllCommand: | |
375 browser_view_->panel()->manager()->RestoreAll(); | |
376 break; | |
377 case kCloseAllCommand: | |
378 browser_view_->panel()->manager()->RemoveAllActive(); | |
379 break; | |
380 case kAboutCommand: | |
381 NOTIMPLEMENTED(); | |
382 break; | |
383 default: | |
384 NOTREACHED(); | |
385 break; | |
386 } | |
346 } | 387 } |
347 | 388 |
348 bool PanelBrowserFrameView::ShouldTabIconViewAnimate() const { | 389 bool PanelBrowserFrameView::ShouldTabIconViewAnimate() const { |
349 // This function is queried during the creation of the window as the | 390 // This function is queried during the creation of the window as the |
350 // TabIconView we host is initialized, so we need to NULL check the selected | 391 // TabIconView we host is initialized, so we need to NULL check the selected |
351 // TabContents because in this condition there is not yet a selected tab. | 392 // TabContents because in this condition there is not yet a selected tab. |
352 TabContents* current_tab = browser_view_->GetSelectedTabContents(); | 393 TabContents* current_tab = browser_view_->GetSelectedTabContents(); |
353 return current_tab ? current_tab->is_loading() : false; | 394 return current_tab ? current_tab->is_loading() : false; |
354 } | 395 } |
355 | 396 |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
475 } | 516 } |
476 | 517 |
477 void PanelBrowserFrameView::UpdateTitleBar() { | 518 void PanelBrowserFrameView::UpdateTitleBar() { |
478 title_label_->SetText( | 519 title_label_->SetText( |
479 frame_->GetWindow()->window_delegate()->GetWindowTitle()); | 520 frame_->GetWindow()->window_delegate()->GetWindowTitle()); |
480 } | 521 } |
481 | 522 |
482 void PanelBrowserFrameView::OnActivationChanged(bool active) { | 523 void PanelBrowserFrameView::OnActivationChanged(bool active) { |
483 SchedulePaint(); | 524 SchedulePaint(); |
484 } | 525 } |
526 | |
527 void PanelBrowserFrameView::CreateOptionsMenu() { | |
528 if (!options_menu_contents_.get()) | |
529 options_menu_contents_.reset(new ui::SimpleMenuModel(this)); | |
530 CreateOptionsMenuItems(); | |
531 if (!options_menu_.get()) | |
532 options_menu_.reset(new views::Menu2(options_menu_contents_.get())); | |
533 } | |
534 | |
535 void PanelBrowserFrameView::CreateOptionsMenuItems() { | |
536 // Determines if we need to rebuild the menu items. The menu items might | |
537 // be different if any of the following have been changed since the last | |
538 // time: | |
539 // 1) Multiple panel vs. single panel. | |
540 // 2) All panels minimized or not. | |
541 bool previous_option_menu_manipulate_all_enabled = | |
542 option_menu_manipulate_all_enabled_; | |
543 bool previous_option_menu_restore_all_enabled_ = | |
544 option_menu_restore_all_enabled_; | |
545 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.
| |
546 browser_view_->panel()->manager()->active_count() > 1; | |
547 option_menu_restore_all_enabled_ = | |
548 browser_view_->panel()->manager()->AreAllMinimized(); | |
549 | |
550 bool rebuild_menu_items = false; | |
551 if (options_menu_contents_->GetItemCount() > 0) { | |
552 if (previous_option_menu_manipulate_all_enabled == | |
553 option_menu_manipulate_all_enabled_ && | |
554 previous_option_menu_restore_all_enabled_ == | |
555 option_menu_restore_all_enabled_) { | |
556 return; | |
557 } | |
558 | |
559 rebuild_menu_items = true; | |
560 options_menu_contents_->Clear(); | |
561 } | |
562 | |
563 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.
| |
564 l10n_util::GetStringUTF16(IDS_PANEL_OPTIONS_MENU_MINIMIZE_ALL); | |
565 const string16 restore_all_text = | |
566 l10n_util::GetStringUTF16(IDS_PANEL_OPTIONS_MENU_RESTORE_ALL); | |
567 const string16 close_all_text = | |
568 l10n_util::GetStringUTF16(IDS_PANEL_OPTIONS_MENU_CLOSE_ALL); | |
569 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.
| |
570 l10n_util::GetStringUTF16(IDS_PANEL_OPTIONS_MENU_ABOUT); | |
571 | |
572 if (option_menu_manipulate_all_enabled_) { | |
573 if (option_menu_restore_all_enabled_) | |
574 options_menu_contents_->AddItem(kRestoreAllCommand, restore_all_text); | |
575 else | |
576 options_menu_contents_->AddItem(kMinimizeAllCommand, minimize_all_text); | |
577 options_menu_contents_->AddItem(kCloseAllCommand, close_all_text); | |
578 options_menu_contents_->AddSeparator(); | |
579 } | |
580 options_menu_contents_->AddItem(kAboutCommand, about_text); | |
581 | |
582 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
| |
583 options_menu_->Rebuild(); | |
584 } | |
OLD | NEW |