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

Side by Side Diff: chrome/browser/ui/views/location_bar/location_bar_view.cc

Issue 789763004: Fix disappearing page actions bug. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Significant clean up. Created 6 years 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/location_bar/location_bar_view.h" 5 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 9
10 #include "base/i18n/rtl.h" 10 #include "base/i18n/rtl.h"
(...skipping 1063 matching lines...) Expand 10 before | Expand all | Expand 10 after
1074 if (web_contents) { 1074 if (web_contents) {
1075 extensions::TabHelper* extensions_tab_helper = 1075 extensions::TabHelper* extensions_tab_helper =
1076 extensions::TabHelper::FromWebContents(web_contents); 1076 extensions::TabHelper::FromWebContents(web_contents);
1077 extensions::LocationBarController* controller = 1077 extensions::LocationBarController* controller =
1078 extensions_tab_helper->location_bar_controller(); 1078 extensions_tab_helper->location_bar_controller();
1079 new_page_actions = controller->GetCurrentActions(); 1079 new_page_actions = controller->GetCurrentActions();
1080 } 1080 }
1081 1081
1082 // On startup we sometimes haven't loaded any extensions. This makes sure 1082 // On startup we sometimes haven't loaded any extensions. This makes sure
1083 // we catch up when the extensions (and any page actions) load. 1083 // we catch up when the extensions (and any page actions) load.
1084 if (page_actions_ != new_page_actions) { 1084 if (PageActionsDiffer(new_page_actions)) {
1085 changed = true; 1085 changed = true;
1086 1086
1087 page_actions_.swap(new_page_actions); 1087 DeletePageActionViews();
1088 DeletePageActionViews(); // Delete the old views (if any).
1089 1088
1090 // Create the page action views. 1089 // Create the page action views.
1091 for (PageActions::const_iterator i = page_actions_.begin(); 1090 for (PageActions::const_iterator i = new_page_actions.begin();
1092 i != page_actions_.end(); ++i) { 1091 i != new_page_actions.end(); ++i) {
1093 PageActionWithBadgeView* page_action_view = new PageActionWithBadgeView( 1092 PageActionWithBadgeView* page_action_view = new PageActionWithBadgeView(
1094 delegate_->CreatePageActionImageView(this, *i)); 1093 delegate_->CreatePageActionImageView(this, *i));
1095 page_action_view->SetVisible(false); 1094 page_action_view->SetVisible(false);
1096 page_action_views_.push_back(page_action_view); 1095 page_action_views_.push_back(page_action_view);
1097 } 1096 }
1098 1097
1099 // Move rightmost extensions to the start. 1098 // Move rightmost extensions to the start.
1100 std::stable_partition( 1099 std::stable_partition(
1101 page_action_views_.begin(), 1100 page_action_views_.begin(),
1102 page_action_views_.end(), 1101 page_action_views_.end(),
(...skipping 18 matching lines...) Expand all
1121 i != page_action_views_.end(); ++i) { 1120 i != page_action_views_.end(); ++i) {
1122 bool old_visibility = (*i)->visible(); 1121 bool old_visibility = (*i)->visible();
1123 (*i)->UpdateVisibility( 1122 (*i)->UpdateVisibility(
1124 GetToolbarModel()->input_in_progress() ? NULL : web_contents); 1123 GetToolbarModel()->input_in_progress() ? NULL : web_contents);
1125 changed |= old_visibility != (*i)->visible(); 1124 changed |= old_visibility != (*i)->visible();
1126 } 1125 }
1127 } 1126 }
1128 return changed; 1127 return changed;
1129 } 1128 }
1130 1129
1130 bool LocationBarView::PageActionsDiffer(
1131 const std::vector<ExtensionAction*>& page_actions) {
1132 if (page_action_views_.size() != page_actions.size())
1133 return true;
1134
1135 for (size_t index = 0; index < page_actions.size(); ++index) {
1136 PageActionWithBadgeView* view = page_action_views_[index];
1137 if (view->image_view()->extension_action() != page_actions[index])
1138 return true;
1139 }
1140
1141 return false;
1142 }
1143
1131 bool LocationBarView::RefreshZoomView() { 1144 bool LocationBarView::RefreshZoomView() {
1132 DCHECK(zoom_view_); 1145 DCHECK(zoom_view_);
1133 WebContents* web_contents = GetWebContents(); 1146 WebContents* web_contents = GetWebContents();
1134 if (!web_contents) 1147 if (!web_contents)
1135 return false; 1148 return false;
1136 const bool was_visible = zoom_view_->visible(); 1149 const bool was_visible = zoom_view_->visible();
1137 zoom_view_->Update(ui_zoom::ZoomController::FromWebContents(web_contents)); 1150 zoom_view_->Update(ui_zoom::ZoomController::FromWebContents(web_contents));
1138 if (!zoom_view_->visible()) 1151 if (!zoom_view_->visible())
1139 ZoomBubbleView::CloseBubble(); 1152 ZoomBubbleView::CloseBubble();
1140 return was_visible != zoom_view_->visible(); 1153 return was_visible != zoom_view_->visible();
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1286 } 1299 }
1287 1300
1288 void LocationBarView::UpdatePageActions() { 1301 void LocationBarView::UpdatePageActions() {
1289 if (RefreshPageActionViews()) { // Changed. 1302 if (RefreshPageActionViews()) { // Changed.
1290 Layout(); 1303 Layout();
1291 SchedulePaint(); 1304 SchedulePaint();
1292 } 1305 }
1293 } 1306 }
1294 1307
1295 void LocationBarView::InvalidatePageActions() { 1308 void LocationBarView::InvalidatePageActions() {
1296 DeletePageActionViews(); 1309 RefreshPageActionViews();
Peter Kasting 2014/12/23 00:20:05 Why not just inline the contents of this method he
erikchen 2014/12/23 00:55:03 1. I renamed InvalidatePageActions->RefreshPageAct
1297 } 1310 }
1298 1311
1299 void LocationBarView::UpdateBookmarkStarVisibility() { 1312 void LocationBarView::UpdateBookmarkStarVisibility() {
1300 if (star_view_) { 1313 if (star_view_) {
1301 star_view_->SetVisible( 1314 star_view_->SetVisible(
1302 browser_defaults::bookmarks_enabled && !is_popup_mode_ && 1315 browser_defaults::bookmarks_enabled && !is_popup_mode_ &&
1303 !GetToolbarModel()->input_in_progress() && 1316 !GetToolbarModel()->input_in_progress() &&
1304 edit_bookmarks_enabled_.GetValue() && 1317 edit_bookmarks_enabled_.GetValue() &&
1305 !IsBookmarkStarHiddenByExtension()); 1318 !IsBookmarkStarHiddenByExtension());
1306 } 1319 }
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
1665 1678
1666 void LocationBarView::ModelChanged(const SearchModel::State& old_state, 1679 void LocationBarView::ModelChanged(const SearchModel::State& old_state,
1667 const SearchModel::State& new_state) { 1680 const SearchModel::State& new_state) {
1668 const bool visible = !GetToolbarModel()->input_in_progress() && 1681 const bool visible = !GetToolbarModel()->input_in_progress() &&
1669 new_state.voice_search_supported; 1682 new_state.voice_search_supported;
1670 if (mic_search_view_->visible() != visible) { 1683 if (mic_search_view_->visible() != visible) {
1671 mic_search_view_->SetVisible(visible); 1684 mic_search_view_->SetVisible(visible);
1672 Layout(); 1685 Layout();
1673 } 1686 }
1674 } 1687 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698