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

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: Comments from wittman. 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(),
1103 IsPageActionViewRightAligned( 1102 IsPageActionViewRightAligned(
1104 extensions::ExtensionRegistry::Get(profile()))); 1103 extensions::ExtensionRegistry::Get(profile())));
1105 1104
1106 View* right_anchor = open_pdf_in_reader_view_; 1105 View* right_anchor = open_pdf_in_reader_view_;
1107 if (!right_anchor) 1106 if (!right_anchor)
1108 right_anchor = star_view_; 1107 right_anchor = star_view_;
1109 DCHECK(right_anchor); 1108 DCHECK(right_anchor);
1110 1109
1111 // |page_action_views_| are ordered right-to-left. Add them as children in 1110 // |page_action_views_| are ordered right-to-left. Add them as children in
1112 // reverse order so the logical order and visual order match for 1111 // reverse order so the logical order and visual order match for
1113 // accessibility purposes. 1112 // accessibility purposes.
1114 for (PageActionViews::reverse_iterator i = page_action_views_.rbegin(); 1113 for (PageActionViews::reverse_iterator i = page_action_views_.rbegin();
1115 i != page_action_views_.rend(); ++i) 1114 i != page_action_views_.rend(); ++i)
1116 AddChildViewAt(*i, GetIndexOf(right_anchor)); 1115 AddChildViewAt(*i, GetIndexOf(right_anchor));
1117 } 1116 }
1118 1117
1119 if (!page_action_views_.empty() && web_contents) { 1118 for (PageActionViews::const_iterator i(page_action_views_.begin());
1120 for (PageActionViews::const_iterator i(page_action_views_.begin()); 1119 i != page_action_views_.end(); ++i) {
1121 i != page_action_views_.end(); ++i) { 1120 bool old_visibility = (*i)->visible();
1122 bool old_visibility = (*i)->visible(); 1121 (*i)->UpdateVisibility(
1123 (*i)->UpdateVisibility( 1122 GetToolbarModel()->input_in_progress() ? NULL : web_contents);
1124 GetToolbarModel()->input_in_progress() ? NULL : web_contents); 1123 changed |= old_visibility != (*i)->visible();
1125 changed |= old_visibility != (*i)->visible();
1126 }
1127 } 1124 }
1128 return changed; 1125 return changed;
1129 } 1126 }
1130 1127
1128 bool LocationBarView::PageActionsDiffer(
1129 const PageActions& page_actions) const {
1130 if (page_action_views_.size() != page_actions.size())
1131 return true;
1132
1133 for (size_t index = 0; index < page_actions.size(); ++index) {
1134 PageActionWithBadgeView* view = page_action_views_[index];
1135 if (view->image_view()->extension_action() != page_actions[index])
1136 return true;
1137 }
1138
1139 return false;
1140 }
1141
1131 bool LocationBarView::RefreshZoomView() { 1142 bool LocationBarView::RefreshZoomView() {
1132 DCHECK(zoom_view_); 1143 DCHECK(zoom_view_);
1133 WebContents* web_contents = GetWebContents(); 1144 WebContents* web_contents = GetWebContents();
1134 if (!web_contents) 1145 if (!web_contents)
1135 return false; 1146 return false;
1136 const bool was_visible = zoom_view_->visible(); 1147 const bool was_visible = zoom_view_->visible();
1137 zoom_view_->Update(ui_zoom::ZoomController::FromWebContents(web_contents)); 1148 zoom_view_->Update(ui_zoom::ZoomController::FromWebContents(web_contents));
1138 if (!zoom_view_->visible()) 1149 if (!zoom_view_->visible())
1139 ZoomBubbleView::CloseBubble(); 1150 ZoomBubbleView::CloseBubble();
1140 return was_visible != zoom_view_->visible(); 1151 return was_visible != zoom_view_->visible();
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
1285 } 1296 }
1286 } 1297 }
1287 1298
1288 void LocationBarView::UpdatePageActions() { 1299 void LocationBarView::UpdatePageActions() {
1289 if (RefreshPageActionViews()) { // Changed. 1300 if (RefreshPageActionViews()) { // Changed.
1290 Layout(); 1301 Layout();
1291 SchedulePaint(); 1302 SchedulePaint();
1292 } 1303 }
1293 } 1304 }
1294 1305
1295 void LocationBarView::InvalidatePageActions() {
1296 DeletePageActionViews();
1297 }
1298
1299 void LocationBarView::UpdateBookmarkStarVisibility() { 1306 void LocationBarView::UpdateBookmarkStarVisibility() {
1300 if (star_view_) { 1307 if (star_view_) {
1301 star_view_->SetVisible( 1308 star_view_->SetVisible(
1302 browser_defaults::bookmarks_enabled && !is_popup_mode_ && 1309 browser_defaults::bookmarks_enabled && !is_popup_mode_ &&
1303 !GetToolbarModel()->input_in_progress() && 1310 !GetToolbarModel()->input_in_progress() &&
1304 edit_bookmarks_enabled_.GetValue() && 1311 edit_bookmarks_enabled_.GetValue() &&
1305 !IsBookmarkStarHiddenByExtension()); 1312 !IsBookmarkStarHiddenByExtension());
1306 } 1313 }
1307 } 1314 }
1308 1315
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
1665 1672
1666 void LocationBarView::ModelChanged(const SearchModel::State& old_state, 1673 void LocationBarView::ModelChanged(const SearchModel::State& old_state,
1667 const SearchModel::State& new_state) { 1674 const SearchModel::State& new_state) {
1668 const bool visible = !GetToolbarModel()->input_in_progress() && 1675 const bool visible = !GetToolbarModel()->input_in_progress() &&
1669 new_state.voice_search_supported; 1676 new_state.voice_search_supported;
1670 if (mic_search_view_->visible() != visible) { 1677 if (mic_search_view_->visible() != visible) {
1671 mic_search_view_->SetVisible(visible); 1678 mic_search_view_->SetVisible(visible);
1672 Layout(); 1679 Layout();
1673 } 1680 }
1674 } 1681 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/location_bar/location_bar_view.h ('k') | chrome/test/base/test_browser_window.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698