Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 if (!page_action_views_.empty() && web_contents) { |
|
Mike Wittman
2014/12/23 01:21:55
nit: this check can be removed entirely and the co
erikchen
2014/12/23 01:29:36
Done.
| |
| 1120 for (PageActionViews::const_iterator i(page_action_views_.begin()); | 1119 for (PageActionViews::const_iterator i(page_action_views_.begin()); |
| 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 PageActions& 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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1279 } | 1292 } |
| 1280 | 1293 |
| 1281 void LocationBarView::UpdateManagePasswordsIconAndBubble() { | 1294 void LocationBarView::UpdateManagePasswordsIconAndBubble() { |
| 1282 if (RefreshManagePasswordsIconView()) { | 1295 if (RefreshManagePasswordsIconView()) { |
| 1283 Layout(); | 1296 Layout(); |
| 1284 SchedulePaint(); | 1297 SchedulePaint(); |
| 1285 } | 1298 } |
| 1286 } | 1299 } |
| 1287 | 1300 |
| 1288 void LocationBarView::UpdatePageActions() { | 1301 void LocationBarView::UpdatePageActions() { |
| 1302 RefreshPageActions(); | |
| 1303 } | |
| 1304 | |
| 1305 void LocationBarView::RefreshPageActions() { | |
| 1289 if (RefreshPageActionViews()) { // Changed. | 1306 if (RefreshPageActionViews()) { // Changed. |
| 1290 Layout(); | 1307 Layout(); |
| 1291 SchedulePaint(); | 1308 SchedulePaint(); |
| 1292 } | 1309 } |
| 1293 } | 1310 } |
| 1294 | 1311 |
| 1295 void LocationBarView::InvalidatePageActions() { | |
| 1296 DeletePageActionViews(); | |
| 1297 } | |
| 1298 | |
| 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 } |
| 1307 } | 1320 } |
| 1308 | 1321 |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 } |
| OLD | NEW |