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/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 1128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1139 i != page_action_views_.end(); ++i) | 1139 i != page_action_views_.end(); ++i) |
| 1140 RemoveChildView(*i); | 1140 RemoveChildView(*i); |
| 1141 STLDeleteElements(&page_action_views_); | 1141 STLDeleteElements(&page_action_views_); |
| 1142 } | 1142 } |
| 1143 | 1143 |
| 1144 bool LocationBarView::RefreshPageActionViews() { | 1144 bool LocationBarView::RefreshPageActionViews() { |
| 1145 if (is_popup_mode_) | 1145 if (is_popup_mode_) |
| 1146 return false; | 1146 return false; |
| 1147 | 1147 |
| 1148 bool changed = false; | 1148 bool changed = false; |
| 1149 | |
| 1150 // Remember the previous visibility of the page actions so that we can | |
| 1151 // notify when this changes. | |
| 1152 std::map<ExtensionAction*, bool> old_visibility; | |
| 1153 for (PageActionViews::const_iterator i(page_action_views_.begin()); | |
| 1154 i != page_action_views_.end(); ++i) { | |
| 1155 old_visibility[(*i)->image_view()->extension_action()] = (*i)->visible(); | |
| 1156 } | |
| 1157 | |
| 1158 PageActions new_page_actions; | 1149 PageActions new_page_actions; |
| 1159 | 1150 |
| 1160 WebContents* web_contents = GetWebContents(); | 1151 WebContents* web_contents = GetWebContents(); |
| 1161 if (web_contents) { | 1152 if (web_contents) { |
| 1162 extensions::TabHelper* extensions_tab_helper = | 1153 extensions::TabHelper* extensions_tab_helper = |
| 1163 extensions::TabHelper::FromWebContents(web_contents); | 1154 extensions::TabHelper::FromWebContents(web_contents); |
| 1164 extensions::LocationBarController* controller = | 1155 extensions::LocationBarController* controller = |
| 1165 extensions_tab_helper->location_bar_controller(); | 1156 extensions_tab_helper->location_bar_controller(); |
| 1166 new_page_actions = controller->GetCurrentActions(); | 1157 new_page_actions = controller->GetCurrentActions(); |
| 1167 } | 1158 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1199 // reverse order so the logical order and visual order match for | 1190 // reverse order so the logical order and visual order match for |
| 1200 // accessibility purposes. | 1191 // accessibility purposes. |
| 1201 for (PageActionViews::reverse_iterator i = page_action_views_.rbegin(); | 1192 for (PageActionViews::reverse_iterator i = page_action_views_.rbegin(); |
| 1202 i != page_action_views_.rend(); ++i) | 1193 i != page_action_views_.rend(); ++i) |
| 1203 AddChildViewAt(*i, GetIndexOf(right_anchor)); | 1194 AddChildViewAt(*i, GetIndexOf(right_anchor)); |
| 1204 } | 1195 } |
| 1205 | 1196 |
| 1206 if (!page_action_views_.empty() && web_contents) { | 1197 if (!page_action_views_.empty() && web_contents) { |
| 1207 for (PageActionViews::const_iterator i(page_action_views_.begin()); | 1198 for (PageActionViews::const_iterator i(page_action_views_.begin()); |
| 1208 i != page_action_views_.end(); ++i) { | 1199 i != page_action_views_.end(); ++i) { |
| 1200 bool old_visibility = (*i)->visible(); | |
| 1209 (*i)->UpdateVisibility( | 1201 (*i)->UpdateVisibility( |
| 1210 GetToolbarModel()->input_in_progress() ? NULL : web_contents); | 1202 GetToolbarModel()->input_in_progress() ? NULL : web_contents); |
| 1211 | 1203 changed = old_visibility != (*i)->visible() ? true : changed; |
|
sky
2014/08/20 15:45:30
Tricky, but isn't:
changed = old_visibility != (*i
Devlin
2014/08/20 15:54:49
Right; changed = old_visibility != (*i)->visible()
| |
| 1212 // Check if the visibility of the action changed and notify if it did. | |
| 1213 ExtensionAction* action = (*i)->image_view()->extension_action(); | |
| 1214 if (old_visibility.find(action) == old_visibility.end() || | |
| 1215 old_visibility[action] != (*i)->visible()) { | |
| 1216 changed = true; | |
| 1217 content::NotificationService::current()->Notify( | |
| 1218 extensions::NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, | |
| 1219 content::Source<ExtensionAction>(action), | |
| 1220 content::Details<WebContents>(web_contents)); | |
| 1221 } | |
| 1222 } | 1204 } |
| 1223 } | 1205 } |
| 1224 return changed; | 1206 return changed; |
| 1225 } | 1207 } |
| 1226 | 1208 |
| 1227 bool LocationBarView::RefreshZoomView() { | 1209 bool LocationBarView::RefreshZoomView() { |
| 1228 DCHECK(zoom_view_); | 1210 DCHECK(zoom_view_); |
| 1229 WebContents* web_contents = GetWebContents(); | 1211 WebContents* web_contents = GetWebContents(); |
| 1230 if (!web_contents) | 1212 if (!web_contents) |
| 1231 return false; | 1213 return false; |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1371 } | 1353 } |
| 1372 | 1354 |
| 1373 void LocationBarView::UpdateManagePasswordsIconAndBubble() { | 1355 void LocationBarView::UpdateManagePasswordsIconAndBubble() { |
| 1374 if (RefreshManagePasswordsIconView()) { | 1356 if (RefreshManagePasswordsIconView()) { |
| 1375 Layout(); | 1357 Layout(); |
| 1376 SchedulePaint(); | 1358 SchedulePaint(); |
| 1377 } | 1359 } |
| 1378 } | 1360 } |
| 1379 | 1361 |
| 1380 void LocationBarView::UpdatePageActions() { | 1362 void LocationBarView::UpdatePageActions() { |
| 1381 size_t count_before = page_action_views_.size(); | 1363 if (RefreshPageActionViews()) { // Changed. |
| 1382 bool changed = RefreshPageActionViews(); | |
| 1383 if (page_action_views_.size() != count_before) { | |
| 1384 content::NotificationService::current()->Notify( | |
| 1385 extensions::NOTIFICATION_EXTENSION_PAGE_ACTION_COUNT_CHANGED, | |
| 1386 content::Source<LocationBar>(this), | |
| 1387 content::NotificationService::NoDetails()); | |
| 1388 } | |
| 1389 | |
| 1390 if (changed) { | |
| 1391 Layout(); | 1364 Layout(); |
| 1392 SchedulePaint(); | 1365 SchedulePaint(); |
| 1393 } | 1366 } |
| 1394 } | 1367 } |
| 1395 | 1368 |
| 1396 void LocationBarView::InvalidatePageActions() { | 1369 void LocationBarView::InvalidatePageActions() { |
| 1397 size_t count_before = page_action_views_.size(); | |
| 1398 DeletePageActionViews(); | 1370 DeletePageActionViews(); |
| 1399 if (page_action_views_.size() != count_before) { | |
| 1400 content::NotificationService::current()->Notify( | |
| 1401 extensions::NOTIFICATION_EXTENSION_PAGE_ACTION_COUNT_CHANGED, | |
| 1402 content::Source<LocationBar>(this), | |
| 1403 content::NotificationService::NoDetails()); | |
| 1404 } | |
| 1405 } | 1371 } |
| 1406 | 1372 |
| 1407 void LocationBarView::UpdateOpenPDFInReaderPrompt() { | 1373 void LocationBarView::UpdateOpenPDFInReaderPrompt() { |
| 1408 open_pdf_in_reader_view_->Update( | 1374 open_pdf_in_reader_view_->Update( |
| 1409 GetToolbarModel()->input_in_progress() ? NULL : GetWebContents()); | 1375 GetToolbarModel()->input_in_progress() ? NULL : GetWebContents()); |
| 1410 Layout(); | 1376 Layout(); |
| 1411 SchedulePaint(); | 1377 SchedulePaint(); |
| 1412 } | 1378 } |
| 1413 | 1379 |
| 1414 void LocationBarView::UpdateGeneratedCreditCardView() { | 1380 void LocationBarView::UpdateGeneratedCreditCardView() { |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1762 | 1728 |
| 1763 void LocationBarView::ModelChanged(const SearchModel::State& old_state, | 1729 void LocationBarView::ModelChanged(const SearchModel::State& old_state, |
| 1764 const SearchModel::State& new_state) { | 1730 const SearchModel::State& new_state) { |
| 1765 const bool visible = !GetToolbarModel()->input_in_progress() && | 1731 const bool visible = !GetToolbarModel()->input_in_progress() && |
| 1766 new_state.voice_search_supported; | 1732 new_state.voice_search_supported; |
| 1767 if (mic_search_view_->visible() != visible) { | 1733 if (mic_search_view_->visible() != visible) { |
| 1768 mic_search_view_->SetVisible(visible); | 1734 mic_search_view_->SetVisible(visible); |
| 1769 Layout(); | 1735 Layout(); |
| 1770 } | 1736 } |
| 1771 } | 1737 } |
| OLD | NEW |