Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(278)

Side by Side Diff: chrome/browser/ui/views/wrench_menu.cc

Issue 8201006: Views: Rebuild wrench menu if error is added or removed (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: '' Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/views/wrench_menu.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 root_->Cancel();
sky 2011/10/10 21:13:47 Add a comment as to why we need this.
sail 2011/10/10 21:18:24 Done.
782 break;
783 default:
784 NOTREACHED();
785 }
786 }
787
772 void WrenchMenu::PopulateMenu(MenuItemView* parent, 788 void WrenchMenu::PopulateMenu(MenuItemView* parent,
773 MenuModel* model, 789 MenuModel* model,
774 int* next_id) { 790 int* next_id) {
775 int index_offset = model->GetFirstItemIndex(NULL); 791 int index_offset = model->GetFirstItemIndex(NULL);
776 for (int i = 0, max = model->GetItemCount(); i < max; ++i) { 792 for (int i = 0, max = model->GetItemCount(); i < max; ++i) {
777 int index = i + index_offset; 793 int index = i + index_offset;
778 794
779 MenuItemView* item = 795 MenuItemView* item =
780 AppendMenuItem(parent, model, index, model->GetTypeAt(index), next_id); 796 AppendMenuItem(parent, model, index, model->GetTypeAt(index), next_id);
781 797
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
860 browser_->window()->GetNativeHandle()); 876 browser_->window()->GetNativeHandle());
861 bookmark_menu_delegate_.reset( 877 bookmark_menu_delegate_.reset(
862 new BookmarkMenuDelegate(browser_->profile(), 878 new BookmarkMenuDelegate(browser_->profile(),
863 NULL, 879 NULL,
864 parent, 880 parent,
865 first_bookmark_command_id_)); 881 first_bookmark_command_id_));
866 bookmark_menu_delegate_->Init( 882 bookmark_menu_delegate_->Init(
867 this, bookmark_menu_, model->bookmark_bar_node(), 0, 883 this, bookmark_menu_, model->bookmark_bar_node(), 0,
868 BookmarkMenuDelegate::SHOW_OTHER_FOLDER); 884 BookmarkMenuDelegate::SHOW_OTHER_FOLDER);
869 } 885 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/wrench_menu.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698