| 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 984 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 995 return; | 995 return; |
| 996 | 996 |
| 997 // Remember the previous visibility of the page actions so that we can | 997 // Remember the previous visibility of the page actions so that we can |
| 998 // notify when this changes. | 998 // notify when this changes. |
| 999 std::map<ExtensionAction*, bool> old_visibility; | 999 std::map<ExtensionAction*, bool> old_visibility; |
| 1000 for (PageActionViews::const_iterator i(page_action_views_.begin()); | 1000 for (PageActionViews::const_iterator i(page_action_views_.begin()); |
| 1001 i != page_action_views_.end(); ++i) { | 1001 i != page_action_views_.end(); ++i) { |
| 1002 old_visibility[(*i)->image_view()->page_action()] = (*i)->visible(); | 1002 old_visibility[(*i)->image_view()->page_action()] = (*i)->visible(); |
| 1003 } | 1003 } |
| 1004 | 1004 |
| 1005 std::vector<ExtensionAction*> page_actions; | 1005 std::vector<ExtensionAction*> new_page_actions; |
| 1006 | 1006 |
| 1007 TabContents* tab_contents = GetTabContents(); | 1007 TabContents* tab_contents = GetTabContents(); |
| 1008 if (tab_contents) { | 1008 if (tab_contents) { |
| 1009 extensions::LocationBarController* controller = | 1009 extensions::LocationBarController* controller = |
| 1010 tab_contents->extension_tab_helper()->location_bar_controller(); | 1010 tab_contents->extension_tab_helper()->location_bar_controller(); |
| 1011 page_actions.swap(*controller->GetCurrentActions()); | 1011 new_page_actions.swap(*controller->GetCurrentActions()); |
| 1012 } | 1012 } |
| 1013 | 1013 |
| 1014 // On startup we sometimes haven't loaded any extensions. This makes sure | 1014 // On startup we sometimes haven't loaded any extensions. This makes sure |
| 1015 // we catch up when the extensions (and any page actions) load. | 1015 // we catch up when the extensions (and any page actions) load. |
| 1016 if (page_actions.size() != page_action_views_.size()) { | 1016 if (page_actions_ != new_page_actions) { |
| 1017 page_actions_.swap(new_page_actions); |
| 1017 DeletePageActionViews(); // Delete the old views (if any). | 1018 DeletePageActionViews(); // Delete the old views (if any). |
| 1018 | 1019 |
| 1019 page_action_views_.resize(page_actions.size()); | 1020 page_action_views_.resize(page_actions_.size()); |
| 1020 View* right_anchor = chrome_to_mobile_view_; | 1021 View* right_anchor = chrome_to_mobile_view_; |
| 1021 if (!right_anchor) | 1022 if (!right_anchor) |
| 1022 right_anchor = star_view_; | 1023 right_anchor = star_view_; |
| 1023 if (!right_anchor) | 1024 if (!right_anchor) |
| 1024 right_anchor = action_box_button_view_; | 1025 right_anchor = action_box_button_view_; |
| 1025 DCHECK(right_anchor); | 1026 DCHECK(right_anchor); |
| 1026 | 1027 |
| 1027 // Add the page actions in reverse order, so that the child views are | 1028 // Add the page actions in reverse order, so that the child views are |
| 1028 // inserted in left-to-right order for accessibility. | 1029 // inserted in left-to-right order for accessibility. |
| 1029 for (int i = page_actions.size() - 1; i >= 0; --i) { | 1030 for (int i = page_actions_.size() - 1; i >= 0; --i) { |
| 1030 page_action_views_[i] = new PageActionWithBadgeView( | 1031 page_action_views_[i] = new PageActionWithBadgeView( |
| 1031 delegate_->CreatePageActionImageView(this, page_actions[i])); | 1032 delegate_->CreatePageActionImageView(this, page_actions_[i])); |
| 1032 page_action_views_[i]->SetVisible(false); | 1033 page_action_views_[i]->SetVisible(false); |
| 1033 AddChildViewAt(page_action_views_[i], GetIndexOf(right_anchor)); | 1034 AddChildViewAt(page_action_views_[i], GetIndexOf(right_anchor)); |
| 1034 } | 1035 } |
| 1035 } | 1036 } |
| 1036 | 1037 |
| 1037 WebContents* contents = GetWebContentsFromDelegate(delegate_); | 1038 WebContents* contents = GetWebContentsFromDelegate(delegate_); |
| 1038 if (!page_action_views_.empty() && contents) { | 1039 if (!page_action_views_.empty() && contents) { |
| 1039 Browser* browser = | 1040 Browser* browser = |
| 1040 browser::FindBrowserForController(&contents->GetController(), NULL); | 1041 browser::FindBrowserForController(&contents->GetController(), NULL); |
| 1041 GURL url = browser->GetActiveWebContents()->GetURL(); | 1042 GURL url = browser->GetActiveWebContents()->GetURL(); |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1342 bool LocationBarView::HasValidSuggestText() const { | 1343 bool LocationBarView::HasValidSuggestText() const { |
| 1343 return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() && | 1344 return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() && |
| 1344 !suggested_text_view_->text().empty(); | 1345 !suggested_text_view_->text().empty(); |
| 1345 } | 1346 } |
| 1346 | 1347 |
| 1347 #if !defined(USE_AURA) | 1348 #if !defined(USE_AURA) |
| 1348 OmniboxViewWin* LocationBarView::GetOmniboxViewWin() { | 1349 OmniboxViewWin* LocationBarView::GetOmniboxViewWin() { |
| 1349 return static_cast<OmniboxViewWin*>(location_entry_.get()); | 1350 return static_cast<OmniboxViewWin*>(location_entry_.get()); |
| 1350 } | 1351 } |
| 1351 #endif | 1352 #endif |
| OLD | NEW |