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/11 18:06:10
I meant this goes below the next line.
jianli
2011/05/11 18:31:31
Done.
| |
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 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
335 BrowserNonClientFrameView::OnMouseReleased(event); | 337 BrowserNonClientFrameView::OnMouseReleased(event); |
336 } | 338 } |
337 | 339 |
338 void PanelBrowserFrameView::ButtonPressed(views::Button* sender, | 340 void PanelBrowserFrameView::ButtonPressed(views::Button* sender, |
339 const views::Event& event) { | 341 const views::Event& event) { |
340 if (sender == close_button_) | 342 if (sender == close_button_) |
341 frame_->GetWindow()->CloseWindow(); | 343 frame_->GetWindow()->CloseWindow(); |
342 } | 344 } |
343 | 345 |
344 void PanelBrowserFrameView::RunMenu(View* source, const gfx::Point& pt) { | 346 void PanelBrowserFrameView::RunMenu(View* source, const gfx::Point& pt) { |
345 NOTIMPLEMENTED(); | 347 CreateOptionsMenu(); |
348 options_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT); | |
349 } | |
350 | |
351 bool PanelBrowserFrameView::IsCommandIdChecked(int command_id) const { | |
352 // Nothing in the menu is checked. | |
353 return false; | |
354 } | |
355 | |
356 bool PanelBrowserFrameView::IsCommandIdEnabled(int command_id) const { | |
357 // All the menu options are always enabled. | |
358 return true; | |
359 } | |
360 | |
361 bool PanelBrowserFrameView::GetAcceleratorForCommandId( | |
362 int command_id, ui::Accelerator* accelerator) { | |
363 return false; | |
364 } | |
365 | |
366 void PanelBrowserFrameView::ExecuteCommand(int command_id) { | |
367 switch (command_id) { | |
368 case COMMAND_MINIMIZE_ALL: | |
369 browser_view_->panel()->manager()->MinimizeAll(); | |
370 break; | |
371 case COMMAND_RESTORE_ALL: | |
372 browser_view_->panel()->manager()->RestoreAll(); | |
373 break; | |
374 case COMMAND_CLOSE_ALL: | |
375 browser_view_->panel()->manager()->RemoveAllActive(); | |
376 break; | |
377 case COMMAND_ABOUT: | |
378 NOTIMPLEMENTED(); | |
379 break; | |
380 default: | |
381 NOTREACHED(); | |
382 break; | |
383 } | |
346 } | 384 } |
347 | 385 |
348 bool PanelBrowserFrameView::ShouldTabIconViewAnimate() const { | 386 bool PanelBrowserFrameView::ShouldTabIconViewAnimate() const { |
349 // This function is queried during the creation of the window as the | 387 // 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 | 388 // 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. | 389 // TabContents because in this condition there is not yet a selected tab. |
352 TabContents* current_tab = browser_view_->GetSelectedTabContents(); | 390 TabContents* current_tab = browser_view_->GetSelectedTabContents(); |
353 return current_tab ? current_tab->is_loading() : false; | 391 return current_tab ? current_tab->is_loading() : false; |
354 } | 392 } |
355 | 393 |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
475 } | 513 } |
476 | 514 |
477 void PanelBrowserFrameView::UpdateTitleBar() { | 515 void PanelBrowserFrameView::UpdateTitleBar() { |
478 title_label_->SetText( | 516 title_label_->SetText( |
479 frame_->GetWindow()->window_delegate()->GetWindowTitle()); | 517 frame_->GetWindow()->window_delegate()->GetWindowTitle()); |
480 } | 518 } |
481 | 519 |
482 void PanelBrowserFrameView::OnActivationChanged(bool active) { | 520 void PanelBrowserFrameView::OnActivationChanged(bool active) { |
483 SchedulePaint(); | 521 SchedulePaint(); |
484 } | 522 } |
523 | |
524 void PanelBrowserFrameView::CreateOptionsMenu() { | |
525 if (!options_menu_contents_.get()) | |
526 options_menu_contents_.reset(new ui::SimpleMenuModel(this)); | |
527 CreateOptionsMenuItems(); | |
528 if (!options_menu_.get()) | |
529 options_menu_.reset(new views::Menu2(options_menu_contents_.get())); | |
530 } | |
531 | |
532 void PanelBrowserFrameView::CreateOptionsMenuItems() { | |
533 // Determines if we need to rebuild the menu items. The menu items might | |
534 // be different if any of the following have been changed since the last | |
535 // time: | |
536 // 1) Multiple panel vs. single panel. | |
537 // 2) All panels minimized or not. | |
538 bool should_manipulate_all = | |
539 browser_view_->panel()->manager()->active_count() > 1; | |
540 bool should_restore_all = | |
541 browser_view_->panel()->manager()->AreAllMinimized(); | |
542 | |
543 bool rebuild_menu_items = false; | |
544 if (options_menu_contents_->GetItemCount() > 0) { | |
545 bool manipulate_all = options_menu_contents_->GetItemCount() > 1; | |
546 bool restore_all = | |
547 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
| |
548 | |
549 if (manipulate_all == should_manipulate_all && | |
550 restore_all == should_restore_all) { | |
551 return; | |
552 } | |
553 | |
554 rebuild_menu_items = true; | |
555 options_menu_contents_->Clear(); | |
556 } | |
557 | |
558 if (should_manipulate_all) { | |
559 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.
| |
560 should_restore_all ? COMMAND_RESTORE_ALL : COMMAND_MINIMIZE_ALL, | |
561 l10n_util::GetStringUTF16( | |
562 should_restore_all ? IDS_PANEL_OPTIONS_MENU_RESTORE_ALL : | |
563 IDS_PANEL_OPTIONS_MENU_MINIMIZE_ALL)); | |
564 options_menu_contents_->AddItem( | |
565 COMMAND_CLOSE_ALL, | |
566 l10n_util::GetStringUTF16(IDS_PANEL_OPTIONS_MENU_CLOSE_ALL)); | |
567 options_menu_contents_->AddSeparator(); | |
568 } | |
569 | |
570 options_menu_contents_->AddItem( | |
571 COMMAND_ABOUT, l10n_util::GetStringUTF16(IDS_PANEL_OPTIONS_MENU_ABOUT)); | |
572 | |
573 // Do not call Rebuild() if we're building the menu for the first time. | |
574 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
| |
575 options_menu_->Rebuild(); | |
576 } | |
OLD | NEW |