| 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 "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "chrome/browser/extensions/extension_action_manager.h" | 8 #include "chrome/browser/extensions/extension_action_manager.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 ToolbarActionsBar::ToolbarActionsBar(ToolbarActionsBarDelegate* delegate, | 72 ToolbarActionsBar::ToolbarActionsBar(ToolbarActionsBarDelegate* delegate, |
| 73 Browser* browser, | 73 Browser* browser, |
| 74 bool in_overflow_mode) | 74 bool in_overflow_mode) |
| 75 : delegate_(delegate), | 75 : delegate_(delegate), |
| 76 browser_(browser), | 76 browser_(browser), |
| 77 model_(extensions::ExtensionToolbarModel::Get(browser_->profile())), | 77 model_(extensions::ExtensionToolbarModel::Get(browser_->profile())), |
| 78 in_overflow_mode_(in_overflow_mode), | 78 in_overflow_mode_(in_overflow_mode), |
| 79 platform_settings_(in_overflow_mode), | 79 platform_settings_(in_overflow_mode), |
| 80 model_observer_(this), | 80 model_observer_(this), |
| 81 suppress_layout_(false), | 81 suppress_layout_(false), |
| 82 suppress_animation_(!model_ || !model_->extensions_initialized()) { | 82 suppress_animation_(true) { |
| 83 if (model_) // |model_| can be null in unittests. | 83 if (model_) // |model_| can be null in unittests. |
| 84 model_observer_.Add(model_); | 84 model_observer_.Add(model_); |
| 85 } | 85 } |
| 86 | 86 |
| 87 ToolbarActionsBar::~ToolbarActionsBar() { | 87 ToolbarActionsBar::~ToolbarActionsBar() { |
| 88 // We don't just call DeleteActions() here because it makes assumptions about | 88 // We don't just call DeleteActions() here because it makes assumptions about |
| 89 // the order of deletion between the views and the ToolbarActionsBar. | 89 // the order of deletion between the views and the ToolbarActionsBar. |
| 90 DCHECK(toolbar_actions_.empty()) << | 90 DCHECK(toolbar_actions_.empty()) << |
| 91 "Must call DeleteActions() before destruction."; | 91 "Must call DeleteActions() before destruction."; |
| 92 } | 92 } |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 extensions::FeatureSwitch::extension_action_redesign()->IsEnabled()); | 234 extensions::FeatureSwitch::extension_action_redesign()->IsEnabled()); |
| 235 toolbar_actions_.insert(toolbar_actions_.end(), | 235 toolbar_actions_.insert(toolbar_actions_.end(), |
| 236 component_actions.begin(), | 236 component_actions.begin(), |
| 237 component_actions.end()); | 237 component_actions.end()); |
| 238 component_actions.weak_clear(); | 238 component_actions.weak_clear(); |
| 239 } | 239 } |
| 240 | 240 |
| 241 for (size_t i = 0; i < toolbar_actions_.size(); ++i) | 241 for (size_t i = 0; i < toolbar_actions_.size(); ++i) |
| 242 delegate_->AddViewForAction(toolbar_actions_[i], i); | 242 delegate_->AddViewForAction(toolbar_actions_[i], i); |
| 243 } | 243 } |
| 244 |
| 245 if (!toolbar_actions_.empty()) { |
| 246 delegate_->Redraw(false); |
| 247 ResizeDelegate(gfx::Tween::EASE_OUT, false); |
| 248 } |
| 249 |
| 250 // Once the actions are created, we should animate the changes. |
| 251 suppress_animation_ = false; |
| 244 } | 252 } |
| 245 | 253 |
| 246 void ToolbarActionsBar::DeleteActions() { | 254 void ToolbarActionsBar::DeleteActions() { |
| 247 delegate_->RemoveAllViews(); | 255 delegate_->RemoveAllViews(); |
| 248 toolbar_actions_.clear(); | 256 toolbar_actions_.clear(); |
| 249 } | 257 } |
| 250 | 258 |
| 251 void ToolbarActionsBar::Update() { | 259 void ToolbarActionsBar::Update() { |
| 252 if (toolbar_actions_.empty()) | 260 if (toolbar_actions_.empty()) |
| 253 return; // Nothing to do. | 261 return; // Nothing to do. |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 DeleteActions(); | 435 DeleteActions(); |
| 428 CreateActions(); | 436 CreateActions(); |
| 429 // Resize the delegate. We suppress the chevron so that we don't risk showing | 437 // Resize the delegate. We suppress the chevron so that we don't risk showing |
| 430 // it only for the duration of the animation. | 438 // it only for the duration of the animation. |
| 431 ResizeDelegate(gfx::Tween::LINEAR, true); | 439 ResizeDelegate(gfx::Tween::LINEAR, true); |
| 432 } | 440 } |
| 433 | 441 |
| 434 void ToolbarActionsBar::OnToolbarModelInitialized() { | 442 void ToolbarActionsBar::OnToolbarModelInitialized() { |
| 435 // We shouldn't have any actions before the model is initialized. | 443 // We shouldn't have any actions before the model is initialized. |
| 436 DCHECK(toolbar_actions_.empty()); | 444 DCHECK(toolbar_actions_.empty()); |
| 437 suppress_animation_ = false; | |
| 438 CreateActions(); | 445 CreateActions(); |
| 439 if (!toolbar_actions_.empty()) { | |
| 440 delegate_->Redraw(false); | |
| 441 ResizeDelegate(gfx::Tween::EASE_OUT, false); | |
| 442 } | |
| 443 } | 446 } |
| 444 | 447 |
| 445 void ToolbarActionsBar::OnToolbarReorderNecessary( | 448 void ToolbarActionsBar::OnToolbarReorderNecessary( |
| 446 content::WebContents* web_contents) { | 449 content::WebContents* web_contents) { |
| 447 if (GetCurrentWebContents() == web_contents) | 450 if (GetCurrentWebContents() == web_contents) |
| 448 ReorderActions(); | 451 ReorderActions(); |
| 449 } | 452 } |
| 450 | 453 |
| 451 Browser* ToolbarActionsBar::GetBrowser() { | 454 Browser* ToolbarActionsBar::GetBrowser() { |
| 452 return browser_; | 455 return browser_; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 for (ToolbarActionViewController* action : toolbar_actions_) { | 497 for (ToolbarActionViewController* action : toolbar_actions_) { |
| 495 if (action->GetId() == id) | 498 if (action->GetId() == id) |
| 496 return action; | 499 return action; |
| 497 } | 500 } |
| 498 return nullptr; | 501 return nullptr; |
| 499 } | 502 } |
| 500 | 503 |
| 501 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { | 504 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { |
| 502 return browser_->tab_strip_model()->GetActiveWebContents(); | 505 return browser_->tab_strip_model()->GetActiveWebContents(); |
| 503 } | 506 } |
| OLD | NEW |