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

Side by Side Diff: chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc

Issue 573893003: Avoid unnecessary visibility changes to BookmarkBarView (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: feedback Created 6 years, 3 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/bookmarks/bookmark_bar_view.h" 5 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 20 matching lines...) Expand all
31 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" 31 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
32 #include "chrome/browser/ui/bookmarks/bookmark_utils.h" 32 #include "chrome/browser/ui/bookmarks/bookmark_utils.h"
33 #include "chrome/browser/ui/browser.h" 33 #include "chrome/browser/ui/browser.h"
34 #include "chrome/browser/ui/chrome_pages.h" 34 #include "chrome/browser/ui/chrome_pages.h"
35 #include "chrome/browser/ui/elide_url.h" 35 #include "chrome/browser/ui/elide_url.h"
36 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" 36 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h"
37 #include "chrome/browser/ui/omnibox/omnibox_view.h" 37 #include "chrome/browser/ui/omnibox/omnibox_view.h"
38 #include "chrome/browser/ui/tabs/tab_strip_model.h" 38 #include "chrome/browser/ui/tabs/tab_strip_model.h"
39 #include "chrome/browser/ui/view_ids.h" 39 #include "chrome/browser/ui/view_ids.h"
40 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_instructions_view.h" 40 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_instructions_view.h"
41 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view_observer.h"
41 #include "chrome/browser/ui/views/bookmarks/bookmark_context_menu.h" 42 #include "chrome/browser/ui/views/bookmarks/bookmark_context_menu.h"
42 #include "chrome/browser/ui/views/bookmarks/bookmark_drag_drop_views.h" 43 #include "chrome/browser/ui/views/bookmarks/bookmark_drag_drop_views.h"
43 #include "chrome/browser/ui/views/bookmarks/bookmark_menu_controller_views.h" 44 #include "chrome/browser/ui/views/bookmarks/bookmark_menu_controller_views.h"
44 #include "chrome/browser/ui/views/event_utils.h" 45 #include "chrome/browser/ui/views/event_utils.h"
45 #include "chrome/browser/ui/views/frame/browser_view.h" 46 #include "chrome/browser/ui/views/frame/browser_view.h"
46 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" 47 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
47 #include "chrome/browser/ui/webui/ntp/core_app_launcher_handler.h" 48 #include "chrome/browser/ui/webui/ntp/core_app_launcher_handler.h"
48 #include "chrome/common/chrome_switches.h" 49 #include "chrome/common/chrome_switches.h"
49 #include "chrome/common/extensions/extension_constants.h" 50 #include "chrome/common/extensions/extension_constants.h"
50 #include "chrome/common/pref_names.h" 51 #include "chrome/common/pref_names.h"
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 } 467 }
467 468
468 BookmarkBarView::BookmarkBarView(Browser* browser, BrowserView* browser_view) 469 BookmarkBarView::BookmarkBarView(Browser* browser, BrowserView* browser_view)
469 : page_navigator_(NULL), 470 : page_navigator_(NULL),
470 client_(NULL), 471 client_(NULL),
471 bookmark_menu_(NULL), 472 bookmark_menu_(NULL),
472 bookmark_drop_menu_(NULL), 473 bookmark_drop_menu_(NULL),
473 other_bookmarked_button_(NULL), 474 other_bookmarked_button_(NULL),
474 managed_bookmarks_button_(NULL), 475 managed_bookmarks_button_(NULL),
475 apps_page_shortcut_(NULL), 476 apps_page_shortcut_(NULL),
476 show_folder_method_factory_(this),
477 overflow_button_(NULL), 477 overflow_button_(NULL),
478 instructions_(NULL), 478 instructions_(NULL),
479 bookmarks_separator_view_(NULL), 479 bookmarks_separator_view_(NULL),
480 browser_(browser), 480 browser_(browser),
481 browser_view_(browser_view), 481 browser_view_(browser_view),
482 infobar_visible_(false), 482 infobar_visible_(false),
483 throbbing_view_(NULL), 483 throbbing_view_(NULL),
484 bookmark_bar_state_(BookmarkBar::SHOW), 484 bookmark_bar_state_(BookmarkBar::SHOW),
485 animating_detached_(false) { 485 animating_detached_(false),
486 show_folder_method_factory_(this) {
486 set_id(VIEW_ID_BOOKMARK_BAR); 487 set_id(VIEW_ID_BOOKMARK_BAR);
487 Init(); 488 Init();
488 489
489 size_animation_->Reset(1); 490 size_animation_->Reset(1);
490 } 491 }
491 492
492 BookmarkBarView::~BookmarkBarView() { 493 BookmarkBarView::~BookmarkBarView() {
493 if (model_) 494 if (model_)
494 model_->RemoveObserver(this); 495 model_->RemoveObserver(this);
495 496
496 // It's possible for the menu to outlive us, reset the observer to make sure 497 // It's possible for the menu to outlive us, reset the observer to make sure
497 // it doesn't have a reference to us. 498 // it doesn't have a reference to us.
498 if (bookmark_menu_) { 499 if (bookmark_menu_) {
499 bookmark_menu_->set_observer(NULL); 500 bookmark_menu_->set_observer(NULL);
500 bookmark_menu_->SetPageNavigator(NULL); 501 bookmark_menu_->SetPageNavigator(NULL);
501 bookmark_menu_->clear_bookmark_bar(); 502 bookmark_menu_->clear_bookmark_bar();
502 } 503 }
503 if (context_menu_.get()) 504 if (context_menu_.get())
504 context_menu_->SetPageNavigator(NULL); 505 context_menu_->SetPageNavigator(NULL);
505 506
506 StopShowFolderDropMenuTimer(); 507 StopShowFolderDropMenuTimer();
507 } 508 }
508 509
509 // static 510 // static
510 void BookmarkBarView::DisableAnimationsForTesting(bool disabled) { 511 void BookmarkBarView::DisableAnimationsForTesting(bool disabled) {
511 animations_enabled = !disabled; 512 animations_enabled = !disabled;
512 } 513 }
513 514
515 void BookmarkBarView::AddObserver(BookmarkBarViewObserver* observer) {
516 observers_.AddObserver(observer);
517 }
518
519 void BookmarkBarView::RemoveObserver(BookmarkBarViewObserver* observer) {
520 observers_.RemoveObserver(observer);
521 }
522
514 void BookmarkBarView::SetPageNavigator(PageNavigator* navigator) { 523 void BookmarkBarView::SetPageNavigator(PageNavigator* navigator) {
515 page_navigator_ = navigator; 524 page_navigator_ = navigator;
516 if (bookmark_menu_) 525 if (bookmark_menu_)
517 bookmark_menu_->SetPageNavigator(navigator); 526 bookmark_menu_->SetPageNavigator(navigator);
518 if (context_menu_.get()) 527 if (context_menu_.get())
519 context_menu_->SetPageNavigator(navigator); 528 context_menu_->SetPageNavigator(navigator);
520 } 529 }
521 530
522 void BookmarkBarView::SetBookmarkBarState( 531 void BookmarkBarView::SetBookmarkBarState(
523 BookmarkBar::State state, 532 BookmarkBar::State state,
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
970 } 979 }
971 980
972 void BookmarkBarView::OnThemeChanged() { 981 void BookmarkBarView::OnThemeChanged() {
973 UpdateColors(); 982 UpdateColors();
974 } 983 }
975 984
976 const char* BookmarkBarView::GetClassName() const { 985 const char* BookmarkBarView::GetClassName() const {
977 return kViewClassName; 986 return kViewClassName;
978 } 987 }
979 988
989 void BookmarkBarView::SetVisible(bool v) {
990 if (v == visible())
991 return;
992
993 View::SetVisible(v);
994 FOR_EACH_OBSERVER(BookmarkBarViewObserver, observers_,
995 OnBookmarkBarVisibilityChanged());
996 }
997
980 void BookmarkBarView::GetAccessibleState(ui::AXViewState* state) { 998 void BookmarkBarView::GetAccessibleState(ui::AXViewState* state) {
981 state->role = ui::AX_ROLE_TOOLBAR; 999 state->role = ui::AX_ROLE_TOOLBAR;
982 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_BOOKMARKS); 1000 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_BOOKMARKS);
983 } 1001 }
984 1002
985 void BookmarkBarView::AnimationProgressed(const gfx::Animation* animation) { 1003 void BookmarkBarView::AnimationProgressed(const gfx::Animation* animation) {
986 // |browser_view_| can be NULL during tests. 1004 // |browser_view_| can be NULL during tests.
987 if (browser_view_) 1005 if (browser_view_)
988 browser_view_->ToolbarSizeChanged(true); 1006 browser_view_->ToolbarSizeChanged(true);
989 } 1007 }
(...skipping 966 matching lines...) Expand 10 before | Expand all | Expand 10 after
1956 DCHECK(apps_page_shortcut_); 1974 DCHECK(apps_page_shortcut_);
1957 // Only perform layout if required. 1975 // Only perform layout if required.
1958 bool visible = chrome::ShouldShowAppsShortcutInBookmarkBar( 1976 bool visible = chrome::ShouldShowAppsShortcutInBookmarkBar(
1959 browser_->profile(), browser_->host_desktop_type()); 1977 browser_->profile(), browser_->host_desktop_type());
1960 if (apps_page_shortcut_->visible() == visible) 1978 if (apps_page_shortcut_->visible() == visible)
1961 return; 1979 return;
1962 apps_page_shortcut_->SetVisible(visible); 1980 apps_page_shortcut_->SetVisible(visible);
1963 UpdateBookmarksSeparatorVisibility(); 1981 UpdateBookmarksSeparatorVisibility();
1964 Layout(); 1982 Layout();
1965 } 1983 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/bookmarks/bookmark_bar_view.h ('k') | chrome/browser/ui/views/bookmarks/bookmark_bar_view_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698