| 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 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 // want to "slide" the action back in. | 245 // want to "slide" the action back in. |
| 246 size_t visible_icons = in_overflow_mode() ? | 246 size_t visible_icons = in_overflow_mode() ? |
| 247 toolbar_actions_.size() - model_->visible_icon_count() : | 247 toolbar_actions_.size() - model_->visible_icon_count() : |
| 248 model_->visible_icon_count() + pop_out_modifier; | 248 model_->visible_icon_count() + pop_out_modifier; |
| 249 | 249 |
| 250 #if DCHECK_IS_ON() | 250 #if DCHECK_IS_ON() |
| 251 // Good time for some sanity checks: We should never try to display more | 251 // Good time for some sanity checks: We should never try to display more |
| 252 // icons than we have, and we should always have a view per item in the model. | 252 // icons than we have, and we should always have a view per item in the model. |
| 253 // (The only exception is if this is in initialization.) | 253 // (The only exception is if this is in initialization.) |
| 254 if (!toolbar_actions_.empty() && !suppress_layout_ && | 254 if (!toolbar_actions_.empty() && !suppress_layout_ && |
| 255 model_->actions_initialized()) { | 255 model_->ActionsInitialized()) { |
| 256 DCHECK_LE(visible_icons, toolbar_actions_.size()); | 256 DCHECK_LE(visible_icons, toolbar_actions_.size()); |
| 257 DCHECK_EQ(model_->toolbar_items().size(), toolbar_actions_.size()); | 257 DCHECK_EQ(model_->toolbar_items().size(), toolbar_actions_.size()); |
| 258 } | 258 } |
| 259 #endif | 259 #endif |
| 260 | 260 |
| 261 return visible_icons; | 261 return visible_icons; |
| 262 } | 262 } |
| 263 | 263 |
| 264 size_t ToolbarActionsBar::GetStartIndexInBounds() const { | 264 size_t ToolbarActionsBar::GetStartIndexInBounds() const { |
| 265 return in_overflow_mode() ? main_bar_->GetEndIndexInBounds() : 0; | 265 return in_overflow_mode() ? main_bar_->GetEndIndexInBounds() : 0; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 actions.rend() - visible + 1); | 331 actions.rend() - visible + 1); |
| 332 } | 332 } |
| 333 } | 333 } |
| 334 | 334 |
| 335 return actions; | 335 return actions; |
| 336 } | 336 } |
| 337 | 337 |
| 338 void ToolbarActionsBar::CreateActions() { | 338 void ToolbarActionsBar::CreateActions() { |
| 339 CHECK(toolbar_actions_.empty()); | 339 CHECK(toolbar_actions_.empty()); |
| 340 // If the model isn't initialized, wait for it. | 340 // If the model isn't initialized, wait for it. |
| 341 if (!model_ || !model_->actions_initialized()) | 341 if (!model_ || !model_->ActionsInitialized()) |
| 342 return; | 342 return; |
| 343 | 343 |
| 344 { | 344 { |
| 345 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/463337 | 345 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/463337 |
| 346 // is fixed. | 346 // is fixed. |
| 347 tracked_objects::ScopedTracker tracking_profile1( | 347 tracked_objects::ScopedTracker tracking_profile1( |
| 348 FROM_HERE_WITH_EXPLICIT_FUNCTION("ToolbarActionsBar::CreateActions1")); | 348 FROM_HERE_WITH_EXPLICIT_FUNCTION("ToolbarActionsBar::CreateActions1")); |
| 349 // We don't redraw the view while creating actions. | 349 // We don't redraw the view while creating actions. |
| 350 base::AutoReset<bool> layout_resetter(&suppress_layout_, true); | 350 base::AutoReset<bool> layout_resetter(&suppress_layout_, true); |
| 351 | 351 |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 626 | 626 |
| 627 // static | 627 // static |
| 628 void ToolbarActionsBar::set_extension_bubble_appearance_wait_time_for_testing( | 628 void ToolbarActionsBar::set_extension_bubble_appearance_wait_time_for_testing( |
| 629 int time_in_seconds) { | 629 int time_in_seconds) { |
| 630 g_extension_bubble_appearance_wait_time_in_seconds = time_in_seconds; | 630 g_extension_bubble_appearance_wait_time_in_seconds = time_in_seconds; |
| 631 } | 631 } |
| 632 | 632 |
| 633 void ToolbarActionsBar::OnToolbarActionAdded( | 633 void ToolbarActionsBar::OnToolbarActionAdded( |
| 634 const ToolbarActionsModel::ToolbarItem& item, | 634 const ToolbarActionsModel::ToolbarItem& item, |
| 635 int index) { | 635 int index) { |
| 636 CHECK(model_->actions_initialized()); | 636 CHECK(model_->ActionsInitialized()); |
| 637 CHECK(GetActionForId(item.id) == nullptr) | 637 CHECK(GetActionForId(item.id) == nullptr) |
| 638 << "Asked to add a toolbar action view for an action that already " | 638 << "Asked to add a toolbar action view for an action that already " |
| 639 "exists"; | 639 "exists"; |
| 640 | 640 |
| 641 toolbar_actions_.insert(toolbar_actions_.begin() + index, | 641 toolbar_actions_.insert(toolbar_actions_.begin() + index, |
| 642 model_->CreateActionForItem(browser_, this, item)); | 642 model_->CreateActionForItem(browser_, this, item)); |
| 643 delegate_->AddViewForAction(toolbar_actions_[index], index); | 643 delegate_->AddViewForAction(toolbar_actions_[index], index); |
| 644 | 644 |
| 645 // We may need to resize (e.g. to show the new icon, or the chevron). We don't | 645 // We may need to resize (e.g. to show the new icon, or the chevron). We don't |
| 646 // need to check if an extension is upgrading here, because ResizeDelegate() | 646 // need to check if an extension is upgrading here, because ResizeDelegate() |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 // icons within the toolbar may have changed (e.g. if we removed one | 733 // icons within the toolbar may have changed (e.g. if we removed one |
| 734 // action and added a different one in quick succession). | 734 // action and added a different one in quick succession). |
| 735 delegate_->Redraw(false); | 735 delegate_->Redraw(false); |
| 736 } | 736 } |
| 737 | 737 |
| 738 for (ToolbarActionsBarObserver& observer : observers_) | 738 for (ToolbarActionsBarObserver& observer : observers_) |
| 739 observer.OnToolbarActionsBarDidStartResize(); | 739 observer.OnToolbarActionsBarDidStartResize(); |
| 740 } | 740 } |
| 741 | 741 |
| 742 void ToolbarActionsBar::OnToolbarHighlightModeChanged(bool is_highlighting) { | 742 void ToolbarActionsBar::OnToolbarHighlightModeChanged(bool is_highlighting) { |
| 743 if (!model_->actions_initialized()) | 743 if (!model_->ActionsInitialized()) |
| 744 return; | 744 return; |
| 745 | 745 |
| 746 { | 746 { |
| 747 base::AutoReset<bool> layout_resetter(&suppress_layout_, true); | 747 base::AutoReset<bool> layout_resetter(&suppress_layout_, true); |
| 748 base::AutoReset<bool> animation_resetter(&suppress_animation_, true); | 748 base::AutoReset<bool> animation_resetter(&suppress_animation_, true); |
| 749 std::set<std::string> seen; | 749 std::set<std::string> seen; |
| 750 for (const ToolbarActionsModel::ToolbarItem item : | 750 for (const ToolbarActionsModel::ToolbarItem item : |
| 751 model_->toolbar_items()) { | 751 model_->toolbar_items()) { |
| 752 auto current_pos = | 752 auto current_pos = |
| 753 std::find_if(toolbar_actions_.begin(), toolbar_actions_.end(), | 753 std::find_if(toolbar_actions_.begin(), toolbar_actions_.end(), |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 822 for (ToolbarActionViewController* action : toolbar_actions_) { | 822 for (ToolbarActionViewController* action : toolbar_actions_) { |
| 823 if (action->GetId() == action_id) | 823 if (action->GetId() == action_id) |
| 824 return action; | 824 return action; |
| 825 } | 825 } |
| 826 return nullptr; | 826 return nullptr; |
| 827 } | 827 } |
| 828 | 828 |
| 829 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { | 829 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { |
| 830 return browser_->tab_strip_model()->GetActiveWebContents(); | 830 return browser_->tab_strip_model()->GetActiveWebContents(); |
| 831 } | 831 } |
| OLD | NEW |