OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/views/toolbar_view.h" | 5 #include "chrome/browser/views/toolbar_view.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
11 #include "chrome/app/chrome_dll_resource.h" | 11 #include "chrome/app/chrome_dll_resource.h" |
12 #include "chrome/app/theme/theme_resources.h" | 12 #include "chrome/app/theme/theme_resources.h" |
13 #include "chrome/browser/bookmarks/bookmark_drag_data.h" | 13 #include "chrome/browser/bookmarks/bookmark_drag_data.h" |
14 #include "chrome/browser/bookmarks/bookmark_model.h" | 14 #include "chrome/browser/bookmarks/bookmark_model.h" |
15 #include "chrome/browser/browser.h" | 15 #include "chrome/browser/browser.h" |
16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
17 #include "chrome/browser/character_encoding.h" | 17 #include "chrome/browser/character_encoding.h" |
18 #include "chrome/browser/drag_utils.h" | 18 #include "chrome/browser/drag_utils.h" |
19 #include "chrome/browser/navigation_controller.h" | 19 #include "chrome/browser/navigation_controller.h" |
20 #include "chrome/browser/navigation_entry.h" | 20 #include "chrome/browser/navigation_entry.h" |
21 #include "chrome/browser/profile.h" | 21 #include "chrome/browser/profile.h" |
| 22 #include "chrome/browser/user_data_manager.h" |
22 #include "chrome/browser/user_metrics.h" | 23 #include "chrome/browser/user_metrics.h" |
23 #include "chrome/browser/views/dom_view.h" | 24 #include "chrome/browser/views/dom_view.h" |
24 #include "chrome/browser/views/go_button.h" | 25 #include "chrome/browser/views/go_button.h" |
25 #include "chrome/browser/views/location_bar_view.h" | 26 #include "chrome/browser/views/location_bar_view.h" |
26 #include "chrome/browser/views/theme_helpers.h" | 27 #include "chrome/browser/views/theme_helpers.h" |
27 #include "chrome/browser/views/toolbar_star_toggle.h" | 28 #include "chrome/browser/views/toolbar_star_toggle.h" |
28 #include "chrome/browser/view_ids.h" | 29 #include "chrome/browser/view_ids.h" |
29 #include "chrome/common/chrome_constants.h" | 30 #include "chrome/common/chrome_constants.h" |
30 #include "chrome/common/drag_drop_types.h" | 31 #include "chrome/common/drag_drop_types.h" |
31 #include "chrome/common/l10n_util.h" | 32 #include "chrome/common/l10n_util.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 back_(NULL), | 68 back_(NULL), |
68 forward_(NULL), | 69 forward_(NULL), |
69 reload_(NULL), | 70 reload_(NULL), |
70 home_(NULL), | 71 home_(NULL), |
71 star_(NULL), | 72 star_(NULL), |
72 location_bar_(NULL), | 73 location_bar_(NULL), |
73 go_(NULL), | 74 go_(NULL), |
74 profile_(NULL), | 75 profile_(NULL), |
75 acc_focused_view_(NULL), | 76 acc_focused_view_(NULL), |
76 browser_(browser), | 77 browser_(browser), |
77 tab_(NULL) { | 78 tab_(NULL), |
| 79 profiles_helper_(new GetProfilesHelper(this)), |
| 80 profiles_menu_(NULL) { |
78 back_menu_model_.reset(new BackForwardMenuModel( | 81 back_menu_model_.reset(new BackForwardMenuModel( |
79 browser, BackForwardMenuModel::BACKWARD_MENU_DELEGATE)); | 82 browser, BackForwardMenuModel::BACKWARD_MENU_DELEGATE)); |
80 forward_menu_model_.reset(new BackForwardMenuModel( | 83 forward_menu_model_.reset(new BackForwardMenuModel( |
81 browser, BackForwardMenuModel::FORWARD_MENU_DELEGATE)); | 84 browser, BackForwardMenuModel::FORWARD_MENU_DELEGATE)); |
82 | 85 |
83 if (browser->type() == Browser::TYPE_NORMAL) | 86 if (browser->type() == Browser::TYPE_NORMAL) |
84 display_mode_ = DISPLAYMODE_NORMAL; | 87 display_mode_ = DISPLAYMODE_NORMAL; |
85 else | 88 else |
86 display_mode_ = DISPLAYMODE_LOCATION; | 89 display_mode_ = DISPLAYMODE_LOCATION; |
87 } | 90 } |
88 | 91 |
89 BrowserToolbarView::~BrowserToolbarView() { | 92 BrowserToolbarView::~BrowserToolbarView() { |
| 93 profiles_helper_->OnDelegateDeleted(); |
90 } | 94 } |
91 | 95 |
92 void BrowserToolbarView::Init(Profile* profile) { | 96 void BrowserToolbarView::Init(Profile* profile) { |
93 // Create all the individual Views in the Toolbar. | 97 // Create all the individual Views in the Toolbar. |
94 CreateLeftSideControls(); | 98 CreateLeftSideControls(); |
95 CreateCenterStack(profile); | 99 CreateCenterStack(profile); |
96 CreateRightSideControls(profile); | 100 CreateRightSideControls(profile); |
97 | 101 |
98 show_home_button_.Init(prefs::kShowHomeButton, profile->GetPrefs(), this); | 102 show_home_button_.Init(prefs::kShowHomeButton, profile->GetPrefs(), this); |
99 | 103 |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 Menu::AnchorPoint anchor = Menu::TOPRIGHT; | 535 Menu::AnchorPoint anchor = Menu::TOPRIGHT; |
532 if (UILayoutIsRightToLeft()) | 536 if (UILayoutIsRightToLeft()) |
533 anchor = Menu::TOPLEFT; | 537 anchor = Menu::TOPLEFT; |
534 | 538 |
535 Menu menu(this, anchor, hwnd); | 539 Menu menu(this, anchor, hwnd); |
536 menu.AppendMenuItemWithLabel(IDC_NEWTAB, l10n_util::GetString(IDS_NEWTAB)); | 540 menu.AppendMenuItemWithLabel(IDC_NEWTAB, l10n_util::GetString(IDS_NEWTAB)); |
537 menu.AppendMenuItemWithLabel(IDC_NEWWINDOW, | 541 menu.AppendMenuItemWithLabel(IDC_NEWWINDOW, |
538 l10n_util::GetString(IDS_NEWWINDOW)); | 542 l10n_util::GetString(IDS_NEWWINDOW)); |
539 menu.AppendMenuItemWithLabel(IDC_GOOFFTHERECORD, | 543 menu.AppendMenuItemWithLabel(IDC_GOOFFTHERECORD, |
540 l10n_util::GetString(IDS_GOOFFTHERECORD)); | 544 l10n_util::GetString(IDS_GOOFFTHERECORD)); |
| 545 |
| 546 // Enumerate profiles asynchronously and then create the parent menu item |
| 547 // "Open new window in profile...". We will create the child menu items for |
| 548 // this once the asynchronous call is done. See OnGetProfilesDone. |
| 549 profiles_helper_->GetProfiles(NULL); |
| 550 Menu* profiles_menu = menu.AppendSubMenu( |
| 551 IDC_NEWPROFILEWINDOW, |
| 552 l10n_util::GetString(IDS_NEWPROFILEWINDOW)); |
| 553 profiles_menu_ = profiles_menu; |
| 554 |
541 menu.AppendSeparator(); | 555 menu.AppendSeparator(); |
542 menu.AppendMenuItemWithLabel(IDC_SHOW_BOOKMARKS_BAR, | 556 menu.AppendMenuItemWithLabel(IDC_SHOW_BOOKMARKS_BAR, |
543 l10n_util::GetString(IDS_SHOW_BOOKMARK_BAR)); | 557 l10n_util::GetString(IDS_SHOW_BOOKMARK_BAR)); |
544 menu.AppendSeparator(); | 558 menu.AppendSeparator(); |
545 menu.AppendMenuItemWithLabel(IDC_SHOW_HISTORY, | 559 menu.AppendMenuItemWithLabel(IDC_SHOW_HISTORY, |
546 l10n_util::GetString(IDS_SHOW_HISTORY)); | 560 l10n_util::GetString(IDS_SHOW_HISTORY)); |
547 menu.AppendMenuItemWithLabel(IDC_SHOW_BOOKMARK_MANAGER, | 561 menu.AppendMenuItemWithLabel(IDC_SHOW_BOOKMARK_MANAGER, |
548 l10n_util::GetString(IDS_BOOKMARK_MANAGER)); | 562 l10n_util::GetString(IDS_BOOKMARK_MANAGER)); |
549 menu.AppendMenuItemWithLabel(IDC_SHOW_DOWNLOADS, | 563 menu.AppendMenuItemWithLabel(IDC_SHOW_DOWNLOADS, |
550 l10n_util::GetString(IDS_SHOW_DOWNLOADS)); | 564 l10n_util::GetString(IDS_SHOW_DOWNLOADS)); |
551 menu.AppendSeparator(); | 565 menu.AppendSeparator(); |
552 menu.AppendMenuItemWithLabel(IDC_CLEAR_BROWSING_DATA, | 566 menu.AppendMenuItemWithLabel(IDC_CLEAR_BROWSING_DATA, |
553 l10n_util::GetString(IDS_CLEAR_BROWSING_DATA)); | 567 l10n_util::GetString(IDS_CLEAR_BROWSING_DATA)); |
554 menu.AppendMenuItemWithLabel(IDC_IMPORT_SETTINGS, | 568 menu.AppendMenuItemWithLabel(IDC_IMPORT_SETTINGS, |
555 l10n_util::GetString(IDS_IMPORT_SETTINGS)); | 569 l10n_util::GetString(IDS_IMPORT_SETTINGS)); |
556 menu.AppendSeparator(); | 570 menu.AppendSeparator(); |
557 menu.AppendMenuItemWithLabel(IDC_OPTIONS, | 571 menu.AppendMenuItemWithLabel(IDC_OPTIONS, |
558 l10n_util::GetStringF(IDS_OPTIONS, | 572 l10n_util::GetStringF(IDS_OPTIONS, |
559 l10n_util::GetString(IDS_PRODUCT_NAME))); | 573 l10n_util::GetString(IDS_PRODUCT_NAME))); |
560 menu.AppendMenuItemWithLabel(IDC_ABOUT, | 574 menu.AppendMenuItemWithLabel(IDC_ABOUT, |
561 l10n_util::GetStringF(IDS_ABOUT, | 575 l10n_util::GetStringF(IDS_ABOUT, |
562 l10n_util::GetString(IDS_PRODUCT_NAME))); | 576 l10n_util::GetString(IDS_PRODUCT_NAME))); |
563 menu.AppendMenuItemWithLabel(IDC_HELPMENU, l10n_util::GetString(IDS_HELP)); | 577 menu.AppendMenuItemWithLabel(IDC_HELPMENU, l10n_util::GetString(IDS_HELP)); |
564 menu.AppendSeparator(); | 578 menu.AppendSeparator(); |
565 menu.AppendMenuItemWithLabel(IDC_EXIT, l10n_util::GetString(IDS_EXIT)); | 579 menu.AppendMenuItemWithLabel(IDC_EXIT, l10n_util::GetString(IDS_EXIT)); |
566 | 580 |
567 menu.RunMenuAt(pt.x, pt.y); | 581 menu.RunMenuAt(pt.x, pt.y); |
| 582 |
| 583 // Menu is going away, so set the profiles menu pointer to NULL. |
| 584 profiles_menu_ = NULL; |
568 } | 585 } |
569 | 586 |
570 bool BrowserToolbarView::IsItemChecked(int id) const { | 587 bool BrowserToolbarView::IsItemChecked(int id) const { |
571 if (!profile_) | 588 if (!profile_) |
572 return false; | 589 return false; |
573 if (id == IDC_SHOW_BOOKMARKS_BAR) | 590 if (id == IDC_SHOW_BOOKMARKS_BAR) |
574 return profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar); | 591 return profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar); |
575 else | 592 else |
576 return EncodingMenuControllerDelegate::IsItemChecked(id); | 593 return EncodingMenuControllerDelegate::IsItemChecked(id); |
577 } | 594 } |
578 | 595 |
579 void BrowserToolbarView::RunMenu(views::View* source, const CPoint& pt, | 596 void BrowserToolbarView::RunMenu(views::View* source, const CPoint& pt, |
580 HWND hwnd) { | 597 HWND hwnd) { |
581 switch (source->GetID()) { | 598 switch (source->GetID()) { |
582 case VIEW_ID_PAGE_MENU: | 599 case VIEW_ID_PAGE_MENU: |
583 RunPageMenu(pt, hwnd); | 600 RunPageMenu(pt, hwnd); |
584 break; | 601 break; |
585 case VIEW_ID_APP_MENU: | 602 case VIEW_ID_APP_MENU: |
586 RunAppMenu(pt, hwnd); | 603 RunAppMenu(pt, hwnd); |
587 break; | 604 break; |
588 default: | 605 default: |
589 NOTREACHED() << "Invalid source menu."; | 606 NOTREACHED() << "Invalid source menu."; |
590 } | 607 } |
591 } | 608 } |
592 | 609 |
| 610 void BrowserToolbarView::OnGetProfilesDone( |
| 611 const std::vector<std::wstring>& profiles) { |
| 612 // Nothing to do if the menu has gone away. |
| 613 if (!profiles_menu_) |
| 614 return; |
| 615 |
| 616 // Store the latest list of profiles in the browser. |
| 617 browser_->set_user_data_dir_profiles(profiles); |
| 618 |
| 619 // Number of sub menu items that we can show directly. |
| 620 const int sub_items_count = IDC_NEWPROFILEWINDOW_MAX_ID - |
| 621 IDC_NEWPROFILEWINDOW_MIN_ID + 1; |
| 622 std::vector<std::wstring>::const_iterator iter = profiles.begin(); |
| 623 // Add direct sub menu items for profiles. |
| 624 for (int i = IDC_NEWPROFILEWINDOW_MIN_ID; |
| 625 i <= IDC_NEWPROFILEWINDOW_MAX_ID && iter != profiles.end(); |
| 626 ++i, ++iter) { |
| 627 profiles_menu_->AppendMenuItemWithLabel(i, *iter); |
| 628 } |
| 629 // If there are more profiles then show "Other" link. |
| 630 if (iter != profiles.end()) { |
| 631 profiles_menu_->AppendSeparator(); |
| 632 profiles_menu_->AppendMenuItemWithLabel( |
| 633 IDC_SELECT_PROFILE, |
| 634 l10n_util::GetString(IDS_NEWPROFILEWINDOW_OTHERPROFILE)); |
| 635 } |
| 636 // Always show a link to select a new profile. |
| 637 profiles_menu_->AppendSeparator(); |
| 638 profiles_menu_->AppendMenuItemWithLabel( |
| 639 IDC_NEW_PROFILE, |
| 640 l10n_util::GetString(IDS_SELECT_PROFILE_DIALOG_NEW_PROFILE_ENTRY)); |
| 641 } |
| 642 |
593 bool BrowserToolbarView::GetAccessibleRole(VARIANT* role) { | 643 bool BrowserToolbarView::GetAccessibleRole(VARIANT* role) { |
594 DCHECK(role); | 644 DCHECK(role); |
595 | 645 |
596 role->vt = VT_I4; | 646 role->vt = VT_I4; |
597 role->lVal = ROLE_SYSTEM_TOOLBAR; | 647 role->lVal = ROLE_SYSTEM_TOOLBAR; |
598 return true; | 648 return true; |
599 } | 649 } |
600 | 650 |
601 bool BrowserToolbarView::GetAccessibleName(std::wstring* name) { | 651 bool BrowserToolbarView::GetAccessibleName(std::wstring* name) { |
602 if (!accessible_name_.empty()) { | 652 if (!accessible_name_.empty()) { |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
691 const NotificationDetails& details) { | 741 const NotificationDetails& details) { |
692 if (type == NOTIFY_PREF_CHANGED) { | 742 if (type == NOTIFY_PREF_CHANGED) { |
693 std::wstring* pref_name = Details<std::wstring>(details).ptr(); | 743 std::wstring* pref_name = Details<std::wstring>(details).ptr(); |
694 if (*pref_name == prefs::kShowHomeButton) { | 744 if (*pref_name == prefs::kShowHomeButton) { |
695 Layout(); | 745 Layout(); |
696 SchedulePaint(); | 746 SchedulePaint(); |
697 } | 747 } |
698 } | 748 } |
699 } | 749 } |
700 | 750 |
| 751 void BrowserToolbarView::ExecuteCommand(int id) { |
| 752 // If the command id is for one of the sub-menu-items of the new profile |
| 753 // window menu then we need to get the name of the profile from the menu |
| 754 // item id and then pass on that to the browser to take action. |
| 755 if (id >= IDC_NEWPROFILEWINDOW_MIN_ID && id <= IDC_NEWPROFILEWINDOW_MAX_ID) { |
| 756 browser_->NewProfileWindowByIndex(id - IDC_NEWPROFILEWINDOW_MIN_ID); |
| 757 return; |
| 758 } |
| 759 |
| 760 // For all other menu items, use the method in the base class. |
| 761 EncodingMenuControllerDelegate::ExecuteCommand(id); |
| 762 } |
| 763 |
701 bool BrowserToolbarView::GetAcceleratorInfo(int id, | 764 bool BrowserToolbarView::GetAcceleratorInfo(int id, |
702 views::Accelerator* accel) { | 765 views::Accelerator* accel) { |
703 // The standard Ctrl-X, Ctrl-V and Ctrl-C are not defined as accelerators | 766 // The standard Ctrl-X, Ctrl-V and Ctrl-C are not defined as accelerators |
704 // anywhere so we need to check for them explicitly here. | 767 // anywhere so we need to check for them explicitly here. |
705 // TODO(cpu) Bug 1109102. Query WebKit land for the actual bindings. | 768 // TODO(cpu) Bug 1109102. Query WebKit land for the actual bindings. |
706 switch (id) { | 769 switch (id) { |
707 case IDC_CUT: | 770 case IDC_CUT: |
708 *accel = views::Accelerator(L'X', false, true, false); | 771 *accel = views::Accelerator(L'X', false, true, false); |
709 return true; | 772 return true; |
710 case IDC_COPY: | 773 case IDC_COPY: |
711 *accel = views::Accelerator(L'C', false, true, false); | 774 *accel = views::Accelerator(L'C', false, true, false); |
712 return true; | 775 return true; |
713 case IDC_PASTE: | 776 case IDC_PASTE: |
714 *accel = views::Accelerator(L'V', false, true, false); | 777 *accel = views::Accelerator(L'V', false, true, false); |
715 return true; | 778 return true; |
716 } | 779 } |
717 // Else, we retrieve the accelerator information from the frame. | 780 // Else, we retrieve the accelerator information from the frame. |
718 return GetWidget()->GetAccelerator(id, accel); | 781 return GetWidget()->GetAccelerator(id, accel); |
719 } | 782 } |
720 | 783 |
OLD | NEW |