| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/toolbar/toolbar_actions_bar.h" | 5 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 // |equal| is used to compare the elements of |to_sort| and |reference|. | 51 // |equal| is used to compare the elements of |to_sort| and |reference|. |
| 52 // This allows us to sort a vector to match another vector of two different | 52 // This allows us to sort a vector to match another vector of two different |
| 53 // types without needing to construct a more cumbersome comparator class. | 53 // types without needing to construct a more cumbersome comparator class. |
| 54 // |FunctionType| should equate to (something similar to) | 54 // |FunctionType| should equate to (something similar to) |
| 55 // bool Equal(const Type1&, const Type2&), but we can't enforce this | 55 // bool Equal(const Type1&, const Type2&), but we can't enforce this |
| 56 // because of MSVC compilation limitations. | 56 // because of MSVC compilation limitations. |
| 57 template<typename Type1, typename Type2, typename FunctionType> | 57 template<typename Type1, typename Type2, typename FunctionType> |
| 58 void SortContainer(std::vector<Type1>* to_sort, | 58 void SortContainer(std::vector<Type1>* to_sort, |
| 59 const std::vector<Type2>& reference, | 59 const std::vector<Type2>& reference, |
| 60 FunctionType equal) { | 60 FunctionType equal) { |
| 61 CHECK_GE(to_sort->size(), reference.size()) << | 61 // |to_sort| must contain all elements in |reference|. |
| 62 "|to_sort| must contain all elements in |reference|."; | 62 CHECK_GE(to_sort->size(), reference.size()); |
| 63 if (reference.empty()) | 63 if (reference.empty()) |
| 64 return; | 64 return; |
| 65 // Run through the each element and compare it to the reference. If something | 65 // Run through the each element and compare it to the reference. If something |
| 66 // is out of place, find the correct spot for it. | 66 // is out of place, find the correct spot for it. |
| 67 for (size_t i = 0; i < reference.size() - 1; ++i) { | 67 for (size_t i = 0; i < reference.size() - 1; ++i) { |
| 68 if (!equal(to_sort->at(i), reference[i])) { | 68 if (!equal(to_sort->at(i), reference[i])) { |
| 69 // Find the correct index (it's guaranteed to be after our current | 69 // Find the correct index (it's guaranteed to be after our current |
| 70 // index, since everything up to this point is correct), and swap. | 70 // index, since everything up to this point is correct), and swap. |
| 71 size_t j = i + 1; | 71 size_t j = i + 1; |
| 72 while (!equal(to_sort->at(j), reference[i])) { | 72 while (!equal(to_sort->at(j), reference[i])) { |
| (...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 // static | 607 // static |
| 608 void ToolbarActionsBar::set_extension_bubble_appearance_wait_time_for_testing( | 608 void ToolbarActionsBar::set_extension_bubble_appearance_wait_time_for_testing( |
| 609 int time_in_seconds) { | 609 int time_in_seconds) { |
| 610 g_extension_bubble_appearance_wait_time_in_seconds = time_in_seconds; | 610 g_extension_bubble_appearance_wait_time_in_seconds = time_in_seconds; |
| 611 } | 611 } |
| 612 | 612 |
| 613 void ToolbarActionsBar::OnToolbarActionAdded( | 613 void ToolbarActionsBar::OnToolbarActionAdded( |
| 614 const ToolbarActionsModel::ToolbarItem& item, | 614 const ToolbarActionsModel::ToolbarItem& item, |
| 615 int index) { | 615 int index) { |
| 616 CHECK(model_->actions_initialized()); | 616 CHECK(model_->actions_initialized()); |
| 617 CHECK(GetActionForId(item.id) == nullptr) | 617 // Asked to add a toolbar action view for an action that already exists |
| 618 << "Asked to add a toolbar action view for an action that already " | 618 CHECK(GetActionForId(item.id) == nullptr); |
| 619 "exists"; | |
| 620 | 619 |
| 621 toolbar_actions_.insert(toolbar_actions_.begin() + index, | 620 toolbar_actions_.insert(toolbar_actions_.begin() + index, |
| 622 model_->CreateActionForItem(browser_, this, item)); | 621 model_->CreateActionForItem(browser_, this, item)); |
| 623 delegate_->AddViewForAction(toolbar_actions_[index], index); | 622 delegate_->AddViewForAction(toolbar_actions_[index], index); |
| 624 | 623 |
| 625 // We may need to resize (e.g. to show the new icon, or the chevron). We don't | 624 // We may need to resize (e.g. to show the new icon, or the chevron). We don't |
| 626 // need to check if an extension is upgrading here, because ResizeDelegate() | 625 // need to check if an extension is upgrading here, because ResizeDelegate() |
| 627 // checks to see if the container is already the proper size, and because | 626 // checks to see if the container is already the proper size, and because |
| 628 // if the action is newly incognito enabled, even though it's a reload, it's | 627 // if the action is newly incognito enabled, even though it's a reload, it's |
| 629 // a new extension to this toolbar. | 628 // a new extension to this toolbar. |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 802 for (ToolbarActionViewController* action : toolbar_actions_) { | 801 for (ToolbarActionViewController* action : toolbar_actions_) { |
| 803 if (action->GetId() == action_id) | 802 if (action->GetId() == action_id) |
| 804 return action; | 803 return action; |
| 805 } | 804 } |
| 806 return nullptr; | 805 return nullptr; |
| 807 } | 806 } |
| 808 | 807 |
| 809 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { | 808 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { |
| 810 return browser_->tab_strip_model()->GetActiveWebContents(); | 809 return browser_->tab_strip_model()->GetActiveWebContents(); |
| 811 } | 810 } |
| OLD | NEW |