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/views/wrench_menu.h" | 5 #include "chrome/browser/ui/views/wrench_menu.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "chrome/app/chrome_command_ids.h" | 11 #include "chrome/app/chrome_command_ids.h" |
12 #include "chrome/browser/bookmarks/bookmark_model.h" | 12 #include "chrome/browser/bookmarks/bookmark_model.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
15 #include "chrome/browser/ui/browser_window.h" | 15 #include "chrome/browser/ui/browser_window.h" |
16 #include "chrome/browser/ui/views/bookmarks/bookmark_menu_delegate.h" | 16 #include "chrome/browser/ui/views/bookmarks/bookmark_menu_delegate.h" |
| 17 #include "chrome/common/chrome_notification_types.h" |
17 #include "content/browser/tab_contents/tab_contents.h" | 18 #include "content/browser/tab_contents/tab_contents.h" |
18 #include "content/browser/user_metrics.h" | 19 #include "content/browser/user_metrics.h" |
19 #include "content/common/content_notification_types.h" | 20 #include "content/common/content_notification_types.h" |
20 #include "content/common/notification_observer.h" | 21 #include "content/common/notification_observer.h" |
21 #include "content/common/notification_registrar.h" | 22 #include "content/common/notification_registrar.h" |
22 #include "content/common/notification_source.h" | 23 #include "content/common/notification_source.h" |
23 #include "grit/chromium_strings.h" | 24 #include "grit/chromium_strings.h" |
24 #include "grit/generated_resources.h" | 25 #include "grit/generated_resources.h" |
25 #include "grit/theme_resources.h" | 26 #include "grit/theme_resources.h" |
26 #include "third_party/skia/include/core/SkPaint.h" | 27 #include "third_party/skia/include/core/SkPaint.h" |
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 | 562 |
562 // WrenchMenu ------------------------------------------------------------------ | 563 // WrenchMenu ------------------------------------------------------------------ |
563 | 564 |
564 WrenchMenu::WrenchMenu(Browser* browser) | 565 WrenchMenu::WrenchMenu(Browser* browser) |
565 : root_(NULL), | 566 : root_(NULL), |
566 browser_(browser), | 567 browser_(browser), |
567 selected_menu_model_(NULL), | 568 selected_menu_model_(NULL), |
568 selected_index_(0), | 569 selected_index_(0), |
569 bookmark_menu_(NULL), | 570 bookmark_menu_(NULL), |
570 first_bookmark_command_id_(0) { | 571 first_bookmark_command_id_(0) { |
| 572 registrar_.Add(this, chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED, |
| 573 Source<Profile>(browser_->profile())); |
571 } | 574 } |
572 | 575 |
573 WrenchMenu::~WrenchMenu() { | 576 WrenchMenu::~WrenchMenu() { |
574 if (bookmark_menu_delegate_.get()) { | 577 if (bookmark_menu_delegate_.get()) { |
575 BookmarkModel* model = browser_->profile()->GetBookmarkModel(); | 578 BookmarkModel* model = browser_->profile()->GetBookmarkModel(); |
576 if (model) | 579 if (model) |
577 model->RemoveObserver(this); | 580 model->RemoveObserver(this); |
578 } | 581 } |
579 } | 582 } |
580 | 583 |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
762 if (menu == bookmark_menu_) | 765 if (menu == bookmark_menu_) |
763 CreateBookmarkMenu(); | 766 CreateBookmarkMenu(); |
764 } | 767 } |
765 | 768 |
766 void WrenchMenu::BookmarkModelChanged() { | 769 void WrenchMenu::BookmarkModelChanged() { |
767 DCHECK(bookmark_menu_delegate_.get()); | 770 DCHECK(bookmark_menu_delegate_.get()); |
768 if (!bookmark_menu_delegate_->is_mutating_model()) | 771 if (!bookmark_menu_delegate_->is_mutating_model()) |
769 root_->Cancel(); | 772 root_->Cancel(); |
770 } | 773 } |
771 | 774 |
| 775 |
| 776 void WrenchMenu::Observe(int type, |
| 777 const NotificationSource& source, |
| 778 const NotificationDetails& details) { |
| 779 switch (type) { |
| 780 case chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED: |
| 781 // A change in the global errors list can add or remove items from the |
| 782 // menu. Close the menu to avoid have a stale menu on-screen. |
| 783 root_->Cancel(); |
| 784 break; |
| 785 default: |
| 786 NOTREACHED(); |
| 787 } |
| 788 } |
| 789 |
772 void WrenchMenu::PopulateMenu(MenuItemView* parent, | 790 void WrenchMenu::PopulateMenu(MenuItemView* parent, |
773 MenuModel* model, | 791 MenuModel* model, |
774 int* next_id) { | 792 int* next_id) { |
775 int index_offset = model->GetFirstItemIndex(NULL); | 793 int index_offset = model->GetFirstItemIndex(NULL); |
776 for (int i = 0, max = model->GetItemCount(); i < max; ++i) { | 794 for (int i = 0, max = model->GetItemCount(); i < max; ++i) { |
777 int index = i + index_offset; | 795 int index = i + index_offset; |
778 | 796 |
779 MenuItemView* item = | 797 MenuItemView* item = |
780 AppendMenuItem(parent, model, index, model->GetTypeAt(index), next_id); | 798 AppendMenuItem(parent, model, index, model->GetTypeAt(index), next_id); |
781 | 799 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
860 browser_->window()->GetNativeHandle()); | 878 browser_->window()->GetNativeHandle()); |
861 bookmark_menu_delegate_.reset( | 879 bookmark_menu_delegate_.reset( |
862 new BookmarkMenuDelegate(browser_->profile(), | 880 new BookmarkMenuDelegate(browser_->profile(), |
863 NULL, | 881 NULL, |
864 parent, | 882 parent, |
865 first_bookmark_command_id_)); | 883 first_bookmark_command_id_)); |
866 bookmark_menu_delegate_->Init( | 884 bookmark_menu_delegate_->Init( |
867 this, bookmark_menu_, model->bookmark_bar_node(), 0, | 885 this, bookmark_menu_, model->bookmark_bar_node(), 0, |
868 BookmarkMenuDelegate::SHOW_OTHER_FOLDER); | 886 BookmarkMenuDelegate::SHOW_OTHER_FOLDER); |
869 } | 887 } |
OLD | NEW |