| 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 "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/profiler/scoped_tracker.h" | 9 #include "base/profiler/scoped_tracker.h" |
| 10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| 11 #include "base/thread_task_runner_handle.h" | 11 #include "base/thread_task_runner_handle.h" |
| 12 #include "chrome/browser/extensions/extension_action_manager.h" | 12 #include "chrome/browser/extensions/extension_action_manager.h" |
| 13 #include "chrome/browser/extensions/extension_message_bubble_controller.h" | 13 #include "chrome/browser/extensions/extension_message_bubble_controller.h" |
| 14 #include "chrome/browser/extensions/extension_util.h" | 14 #include "chrome/browser/extensions/extension_util.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/sessions/session_tab_helper.h" | 16 #include "chrome/browser/sessions/session_tab_helper.h" |
| 17 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
| 18 #include "chrome/browser/ui/browser_window.h" | 18 #include "chrome/browser/ui/browser_window.h" |
| 19 #include "chrome/browser/ui/extensions/extension_action_view_controller.h" | 19 #include "chrome/browser/ui/extensions/extension_action_view_controller.h" |
| 20 #include "chrome/browser/ui/extensions/extension_message_bubble_factory.h" | 20 #include "chrome/browser/ui/extensions/extension_message_bubble_factory.h" |
| 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 22 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h" | 22 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h" |
| 23 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" | 23 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" |
| 24 #include "chrome/browser/ui/toolbar/toolbar_actions_bar_delegate.h" | 24 #include "chrome/browser/ui/toolbar/toolbar_actions_bar_delegate.h" |
| 25 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
| 26 #include "components/crx_file/id_util.h" | 26 #include "components/crx_file/id_util.h" |
| 27 #include "components/pref_registry/pref_registry_syncable.h" | 27 #include "components/pref_registry/pref_registry_syncable.h" |
| 28 #include "extensions/browser/extension_registry.h" |
| 28 #include "extensions/browser/extension_system.h" | 29 #include "extensions/browser/extension_system.h" |
| 29 #include "extensions/browser/runtime_data.h" | 30 #include "extensions/browser/runtime_data.h" |
| 30 #include "extensions/common/extension.h" | 31 #include "extensions/common/extension.h" |
| 31 #include "extensions/common/feature_switch.h" | 32 #include "extensions/common/feature_switch.h" |
| 32 #include "grit/theme_resources.h" | 33 #include "grit/theme_resources.h" |
| 33 #include "ui/base/resource/resource_bundle.h" | 34 #include "ui/base/resource/resource_bundle.h" |
| 34 #include "ui/gfx/image/image_skia.h" | 35 #include "ui/gfx/image/image_skia.h" |
| 35 | 36 |
| 36 namespace { | 37 namespace { |
| 37 | 38 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 icons_per_overflow_menu_row(1), | 113 icons_per_overflow_menu_row(1), |
| 113 chevron_enabled(!extensions::FeatureSwitch::extension_action_redesign()-> | 114 chevron_enabled(!extensions::FeatureSwitch::extension_action_redesign()-> |
| 114 IsEnabled()) { | 115 IsEnabled()) { |
| 115 } | 116 } |
| 116 | 117 |
| 117 ToolbarActionsBar::ToolbarActionsBar(ToolbarActionsBarDelegate* delegate, | 118 ToolbarActionsBar::ToolbarActionsBar(ToolbarActionsBarDelegate* delegate, |
| 118 Browser* browser, | 119 Browser* browser, |
| 119 ToolbarActionsBar* main_bar) | 120 ToolbarActionsBar* main_bar) |
| 120 : delegate_(delegate), | 121 : delegate_(delegate), |
| 121 browser_(browser), | 122 browser_(browser), |
| 122 model_(extensions::ExtensionToolbarModel::Get(browser_->profile())), | 123 model_(ToolbarActionsModel::Get(browser_->profile())), |
| 123 main_bar_(main_bar), | 124 main_bar_(main_bar), |
| 124 platform_settings_(main_bar != nullptr), | 125 platform_settings_(main_bar != nullptr), |
| 125 popup_owner_(nullptr), | 126 popup_owner_(nullptr), |
| 126 model_observer_(this), | 127 model_observer_(this), |
| 127 suppress_layout_(false), | 128 suppress_layout_(false), |
| 128 suppress_animation_(true), | 129 suppress_animation_(true), |
| 129 overflowed_action_wants_to_run_(false), | 130 overflowed_action_wants_to_run_(false), |
| 130 checked_extension_bubble_(false), | 131 checked_extension_bubble_(false), |
| 131 popped_out_action_(nullptr), | 132 popped_out_action_(nullptr), |
| 132 weak_ptr_factory_(this) { | 133 weak_ptr_factory_(this) { |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 // want to "slide" the action back in. | 252 // want to "slide" the action back in. |
| 252 size_t visible_icons = in_overflow_mode() ? | 253 size_t visible_icons = in_overflow_mode() ? |
| 253 toolbar_actions_.size() - model_->visible_icon_count() : | 254 toolbar_actions_.size() - model_->visible_icon_count() : |
| 254 model_->visible_icon_count() + pop_out_modifier; | 255 model_->visible_icon_count() + pop_out_modifier; |
| 255 | 256 |
| 256 #if DCHECK_IS_ON() | 257 #if DCHECK_IS_ON() |
| 257 // Good time for some sanity checks: We should never try to display more | 258 // Good time for some sanity checks: We should never try to display more |
| 258 // icons than we have, and we should always have a view per item in the model. | 259 // icons than we have, and we should always have a view per item in the model. |
| 259 // (The only exception is if this is in initialization.) | 260 // (The only exception is if this is in initialization.) |
| 260 if (!toolbar_actions_.empty() && !suppress_layout_ && | 261 if (!toolbar_actions_.empty() && !suppress_layout_ && |
| 261 model_->extensions_initialized()) { | 262 model_->actions_initialized()) { |
| 262 size_t num_extension_actions = 0u; | 263 size_t num_extension_actions = 0u; |
| 263 for (ToolbarActionViewController* action : toolbar_actions_) { | 264 for (ToolbarActionViewController* action : toolbar_actions_) { |
| 264 // No component action should ever have a valid extension id, so we can | 265 // No component action should ever have a valid extension id, so we can |
| 265 // use this to check the extension amount. | 266 // use this to check the extension amount. |
| 266 if (crx_file::id_util::IdIsValid(action->GetId())) | 267 if (crx_file::id_util::IdIsValid(action->GetId())) |
| 267 ++num_extension_actions; | 268 ++num_extension_actions; |
| 268 } | 269 } |
| 269 | 270 |
| 270 int num_component_actions = | 271 int num_component_actions = |
| 271 ComponentToolbarActionsFactory::GetInstance()-> | 272 ComponentToolbarActionsFactory::GetInstance()-> |
| 272 GetNumComponentActions(browser_); | 273 GetNumComponentActions(browser_); |
| 273 size_t num_total_actions = num_extension_actions + num_component_actions; | 274 size_t num_total_actions = num_extension_actions + num_component_actions; |
| 274 | 275 |
| 275 DCHECK_LE(visible_icons, num_total_actions); | 276 DCHECK_LE(visible_icons, num_total_actions); |
| 276 DCHECK_EQ(model_->toolbar_items().size(), num_extension_actions); | 277 DCHECK_EQ(model_->toolbar_items().size(), num_total_actions); |
| 277 } | 278 } |
| 278 #endif | 279 #endif |
| 279 | 280 |
| 280 return visible_icons; | 281 return visible_icons; |
| 281 } | 282 } |
| 282 | 283 |
| 283 std::vector<ToolbarActionViewController*> | 284 std::vector<ToolbarActionViewController*> |
| 284 ToolbarActionsBar::GetActions() const { | 285 ToolbarActionsBar::GetActions() const { |
| 285 std::vector<ToolbarActionViewController*> actions = toolbar_actions_.get(); | 286 std::vector<ToolbarActionViewController*> actions = toolbar_actions_.get(); |
| 286 | 287 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 300 } | 301 } |
| 301 } | 302 } |
| 302 | 303 |
| 303 return actions; | 304 return actions; |
| 304 } | 305 } |
| 305 | 306 |
| 306 void ToolbarActionsBar::CreateActions() { | 307 void ToolbarActionsBar::CreateActions() { |
| 307 DCHECK(toolbar_actions_.empty()); | 308 DCHECK(toolbar_actions_.empty()); |
| 308 // We wait for the extension system to be initialized before we add any | 309 // We wait for the extension system to be initialized before we add any |
| 309 // actions, as they rely on the extension system to function. | 310 // actions, as they rely on the extension system to function. |
| 310 if (!model_ || !model_->extensions_initialized()) | 311 if (!model_ || !model_->actions_initialized()) |
| 311 return; | 312 return; |
| 312 | 313 |
| 313 { | 314 { |
| 314 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/463337 | 315 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/463337 |
| 315 // is fixed. | 316 // is fixed. |
| 316 tracked_objects::ScopedTracker tracking_profile1( | 317 tracked_objects::ScopedTracker tracking_profile1( |
| 317 FROM_HERE_WITH_EXPLICIT_FUNCTION("ToolbarActionsBar::CreateActions1")); | 318 FROM_HERE_WITH_EXPLICIT_FUNCTION("ToolbarActionsBar::CreateActions1")); |
| 318 // We don't redraw the view while creating actions. | 319 // We don't redraw the view while creating actions. |
| 319 base::AutoReset<bool> layout_resetter(&suppress_layout_, true); | 320 base::AutoReset<bool> layout_resetter(&suppress_layout_, true); |
| 320 | 321 |
| 321 // Extension actions come first. | 322 // Get the toolbar actions. |
| 322 extensions::ExtensionActionManager* action_manager = | 323 toolbar_actions_ = model_->GetActions(browser_, this); |
| 323 extensions::ExtensionActionManager::Get(browser_->profile()); | |
| 324 const extensions::ExtensionList& toolbar_items = model_->toolbar_items(); | |
| 325 for (const scoped_refptr<const extensions::Extension>& extension : | |
| 326 toolbar_items) { | |
| 327 toolbar_actions_.push_back(new ExtensionActionViewController( | |
| 328 extension.get(), | |
| 329 browser_, | |
| 330 action_manager->GetExtensionAction(*extension), | |
| 331 this)); | |
| 332 } | |
| 333 | 324 |
| 334 // Component actions come second, and are suppressed if the extension | |
| 335 // actions are being highlighted. | |
| 336 if (!model_->is_highlighting()) { | 325 if (!model_->is_highlighting()) { |
| 337 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/463337 | 326 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/463337 |
| 338 // is fixed. | 327 // is fixed. |
| 339 tracked_objects::ScopedTracker tracking_profile2( | 328 tracked_objects::ScopedTracker tracking_profile2( |
| 340 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 329 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 341 "ToolbarActionsBar::CreateActions2")); | 330 "ToolbarActionsBar::CreateActions2")); |
| 342 | |
| 343 ScopedVector<ToolbarActionViewController> component_actions = | |
| 344 ComponentToolbarActionsFactory::GetInstance()-> | |
| 345 GetComponentToolbarActions(browser_); | |
| 346 DCHECK(component_actions.empty() || | |
| 347 extensions::FeatureSwitch::extension_action_redesign()->IsEnabled()); | |
| 348 toolbar_actions_.insert(toolbar_actions_.end(), | |
| 349 component_actions.begin(), | |
| 350 component_actions.end()); | |
| 351 component_actions.weak_clear(); | |
| 352 } | 331 } |
| 353 | 332 |
| 354 if (!toolbar_actions_.empty()) { | 333 if (!toolbar_actions_.empty()) { |
| 355 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/463337 | 334 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/463337 |
| 356 // is fixed. | 335 // is fixed. |
| 357 tracked_objects::ScopedTracker tracking_profile3( | 336 tracked_objects::ScopedTracker tracking_profile3( |
| 358 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 337 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 359 "ToolbarActionsBar::CreateActions3")); | 338 "ToolbarActionsBar::CreateActions3")); |
| 360 ReorderActions(); | 339 ReorderActions(); |
| 361 } | 340 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 if (in_overflow_mode()) { | 410 if (in_overflow_mode()) { |
| 432 main_bar_->OnDragDrop(dragged_index, dropped_index, drag_type); | 411 main_bar_->OnDragDrop(dragged_index, dropped_index, drag_type); |
| 433 return; | 412 return; |
| 434 } | 413 } |
| 435 | 414 |
| 436 int delta = 0; | 415 int delta = 0; |
| 437 if (drag_type == DRAG_TO_OVERFLOW) | 416 if (drag_type == DRAG_TO_OVERFLOW) |
| 438 delta = -1; | 417 delta = -1; |
| 439 else if (drag_type == DRAG_TO_MAIN) | 418 else if (drag_type == DRAG_TO_MAIN) |
| 440 delta = 1; | 419 delta = 1; |
| 441 model_->MoveExtensionIcon(toolbar_actions_[dragged_index]->GetId(), | 420 model_->MoveActionIcon(toolbar_actions_[dragged_index]->GetId(), |
| 442 dropped_index); | 421 dropped_index); |
| 443 if (delta) | 422 if (delta) |
| 444 model_->SetVisibleIconCount(model_->visible_icon_count() + delta); | 423 model_->SetVisibleIconCount(model_->visible_icon_count() + delta); |
| 445 } | 424 } |
| 446 | 425 |
| 447 void ToolbarActionsBar::OnAnimationEnded() { | 426 void ToolbarActionsBar::OnAnimationEnded() { |
| 448 // Check if we were waiting for animation to complete to either show a | 427 // Check if we were waiting for animation to complete to either show a |
| 449 // message bubble, or to show a popup. | 428 // message bubble, or to show a popup. |
| 450 if (pending_extension_bubble_controller_) { | 429 if (pending_extension_bubble_controller_) { |
| 451 MaybeShowExtensionBubble(pending_extension_bubble_controller_.Pass()); | 430 MaybeShowExtensionBubble(pending_extension_bubble_controller_.Pass()); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 } | 495 } |
| 517 | 496 |
| 518 void ToolbarActionsBar::MaybeShowExtensionBubble( | 497 void ToolbarActionsBar::MaybeShowExtensionBubble( |
| 519 scoped_ptr<extensions::ExtensionMessageBubbleController> controller) { | 498 scoped_ptr<extensions::ExtensionMessageBubbleController> controller) { |
| 520 controller->HighlightExtensionsIfNecessary(); // Safe to call multiple times. | 499 controller->HighlightExtensionsIfNecessary(); // Safe to call multiple times. |
| 521 if (delegate_->IsAnimating()) { | 500 if (delegate_->IsAnimating()) { |
| 522 // If the toolbar is animating, we can't effectively anchor the bubble, | 501 // If the toolbar is animating, we can't effectively anchor the bubble, |
| 523 // so wait until animation stops. | 502 // so wait until animation stops. |
| 524 pending_extension_bubble_controller_ = controller.Pass(); | 503 pending_extension_bubble_controller_ = controller.Pass(); |
| 525 } else { | 504 } else { |
| 526 const extensions::ExtensionIdList& affected_extensions = | 505 const ActionIdList& affected_extensions = controller->GetExtensionIdList(); |
| 527 controller->GetExtensionIdList(); | |
| 528 ToolbarActionViewController* anchor_action = nullptr; | 506 ToolbarActionViewController* anchor_action = nullptr; |
| 529 for (const std::string& id : affected_extensions) { | 507 for (const std::string& id : affected_extensions) { |
| 530 anchor_action = GetActionForId(id); | 508 anchor_action = GetActionForId(id); |
| 531 if (anchor_action) | 509 if (anchor_action) |
| 532 break; | 510 break; |
| 533 } | 511 } |
| 534 delegate_->ShowExtensionMessageBubble(controller.Pass(), anchor_action); | 512 delegate_->ShowExtensionMessageBubble(controller.Pass(), anchor_action); |
| 535 } | 513 } |
| 536 } | 514 } |
| 537 | 515 |
| 538 void ToolbarActionsBar::OnToolbarExtensionAdded( | 516 void ToolbarActionsBar::OnToolbarActionAdded(const std::string& action_id, |
| 539 const extensions::Extension* extension, | 517 int index) { |
| 540 int index) { | 518 DCHECK(GetActionForId(action_id) == nullptr) << |
| 541 DCHECK(GetActionForId(extension->id()) == nullptr) << | |
| 542 "Asked to add a toolbar action view for an extension that already exists"; | 519 "Asked to add a toolbar action view for an extension that already exists"; |
| 543 | 520 |
| 521 // Check that |action_id| is not a component action since |
| 522 // OnToolbarActionAdded is only called after the toolbar model has been |
| 523 // initialized. |
| 524 if (model_->IsKnownActionWithType(action_id, |
| 525 ToolbarActionsModel::ACTION_COMPONENT)) |
| 526 return; |
| 527 |
| 528 const extensions::Extension* extension = |
| 529 extensions::ExtensionRegistry::Get(browser_->profile())-> |
| 530 enabled_extensions().GetByID(action_id); |
| 531 |
| 544 toolbar_actions_.insert( | 532 toolbar_actions_.insert( |
| 545 toolbar_actions_.begin() + index, | 533 toolbar_actions_.begin() + index, |
| 546 new ExtensionActionViewController( | 534 new ExtensionActionViewController( |
| 547 extension, | 535 extension, |
| 548 browser_, | 536 browser_, |
| 549 extensions::ExtensionActionManager::Get(browser_->profile())-> | 537 extensions::ExtensionActionManager::Get(browser_->profile())-> |
| 550 GetExtensionAction(*extension), | 538 GetExtensionAction(*extension), |
| 551 this)); | 539 this)); |
| 552 | 540 |
| 553 delegate_->AddViewForAction(toolbar_actions_[index], index); | 541 delegate_->AddViewForAction(toolbar_actions_[index], index); |
| 554 | 542 |
| 555 // If we are still initializing the container, don't bother animating. | 543 // If we are still initializing the container, don't bother animating. |
| 556 if (!model_->extensions_initialized()) | 544 if (!model_->actions_initialized()) |
| 557 return; | 545 return; |
| 558 | 546 |
| 559 // We may need to resize (e.g. to show the new icon, or the chevron). We don't | 547 // We may need to resize (e.g. to show the new icon, or the chevron). We don't |
| 560 // need to check if the extension is upgrading here, because ResizeDelegate() | 548 // need to check if the extension is upgrading here, because ResizeDelegate() |
| 561 // checks to see if the container is already the proper size, and because | 549 // checks to see if the container is already the proper size, and because |
| 562 // if the action is newly incognito enabled, even though it's a reload, it's | 550 // if the action is newly incognito enabled, even though it's a reload, it's |
| 563 // a new extension to this toolbar. | 551 // a new extension to this toolbar. |
| 564 // We suppress the chevron during animation because, if we're expanding to | 552 // We suppress the chevron during animation because, if we're expanding to |
| 565 // show a new icon, we don't want to have the chevron visible only for the | 553 // show a new icon, we don't want to have the chevron visible only for the |
| 566 // duration of the animation. | 554 // duration of the animation. |
| 567 ResizeDelegate(gfx::Tween::LINEAR, true); | 555 ResizeDelegate(gfx::Tween::LINEAR, true); |
| 568 } | 556 } |
| 569 | 557 |
| 570 void ToolbarActionsBar::OnToolbarExtensionRemoved( | 558 void ToolbarActionsBar::OnToolbarActionRemoved(const std::string& action_id) { |
| 571 const extensions::Extension* extension) { | |
| 572 ToolbarActions::iterator iter = toolbar_actions_.begin(); | 559 ToolbarActions::iterator iter = toolbar_actions_.begin(); |
| 573 while (iter != toolbar_actions_.end() && (*iter)->GetId() != extension->id()) | 560 while (iter != toolbar_actions_.end() && (*iter)->GetId() != action_id) |
| 574 ++iter; | 561 ++iter; |
| 575 | 562 |
| 576 if (iter == toolbar_actions_.end()) | 563 if (iter == toolbar_actions_.end()) |
| 577 return; | 564 return; |
| 578 | 565 |
| 566 // Component actions cannot be removed. |
| 567 if (model_->IsKnownActionWithType(action_id, |
| 568 ToolbarActionsModel::ACTION_COMPONENT)) |
| 569 return; |
| 570 |
| 579 // The action should outlive the UI element (which is owned by the delegate), | 571 // The action should outlive the UI element (which is owned by the delegate), |
| 580 // so we can't delete it just yet. But we should remove it from the list of | 572 // so we can't delete it just yet. But we should remove it from the list of |
| 581 // actions so that any width calculations are correct. | 573 // actions so that any width calculations are correct. |
| 582 scoped_ptr<ToolbarActionViewController> removed_action(*iter); | 574 scoped_ptr<ToolbarActionViewController> removed_action(*iter); |
| 583 toolbar_actions_.weak_erase(iter); | 575 toolbar_actions_.weak_erase(iter); |
| 584 delegate_->RemoveViewForAction(removed_action.get()); | 576 delegate_->RemoveViewForAction(removed_action.get()); |
| 585 removed_action.reset(); | 577 removed_action.reset(); |
| 586 | 578 |
| 587 // If the extension is being upgraded we don't want the bar to shrink | 579 // If the extension is being upgraded we don't want the bar to shrink |
| 588 // because the icon is just going to get re-added to the same location. | 580 // because the icon is just going to get re-added to the same location. |
| 589 // There is an exception if this is an off-the-record profile, and the | 581 // There is an exception if this is an off-the-record profile, and the |
| 590 // extension is no longer incognito-enabled. | 582 // extension is no longer incognito-enabled. |
| 591 if (!extensions::ExtensionSystem::Get(browser_->profile())->runtime_data()-> | 583 if (!extensions::ExtensionSystem::Get(browser_->profile())->runtime_data()-> |
| 592 IsBeingUpgraded(extension->id()) || | 584 IsBeingUpgraded(action_id) || |
| 593 (browser_->profile()->IsOffTheRecord() && | 585 (browser_->profile()->IsOffTheRecord() && |
| 594 !extensions::util::IsIncognitoEnabled(extension->id(), | 586 !extensions::util::IsIncognitoEnabled(action_id, |
| 595 browser_->profile()))) { | 587 browser_->profile()))) { |
| 596 if (toolbar_actions_.size() > model_->visible_icon_count()) { | 588 if (toolbar_actions_.size() > model_->visible_icon_count()) { |
| 597 // If we have more icons than we can show, then we must not be changing | 589 // If we have more icons than we can show, then we must not be changing |
| 598 // the container size (since we either removed an icon from the main | 590 // the container size (since we either removed an icon from the main |
| 599 // area and one from the overflow list will have shifted in, or we | 591 // area and one from the overflow list will have shifted in, or we |
| 600 // removed an entry directly from the overflow list). | 592 // removed an entry directly from the overflow list). |
| 601 delegate_->Redraw(false); | 593 delegate_->Redraw(false); |
| 602 } else { | 594 } else { |
| 603 delegate_->SetChevronVisibility(false); | 595 delegate_->SetChevronVisibility(false); |
| 604 // Either we went from overflow to no-overflow, or we shrunk the no- | 596 // Either we went from overflow to no-overflow, or we shrunk the no- |
| 605 // overflow container by 1. Either way the size changed, so animate. | 597 // overflow container by 1. Either way the size changed, so animate. |
| 606 ResizeDelegate(gfx::Tween::EASE_OUT, false); | 598 ResizeDelegate(gfx::Tween::EASE_OUT, false); |
| 607 } | 599 } |
| 608 } | 600 } |
| 609 | 601 |
| 610 SetOverflowedActionWantsToRun(); | 602 SetOverflowedActionWantsToRun(); |
| 611 } | 603 } |
| 612 | 604 |
| 613 void ToolbarActionsBar::OnToolbarExtensionMoved( | 605 void ToolbarActionsBar::OnToolbarActionMoved(const std::string& action_id, |
| 614 const extensions::Extension* extension, | 606 int index) { |
| 615 int index) { | |
| 616 DCHECK(index >= 0 && index < static_cast<int>(toolbar_actions_.size())); | 607 DCHECK(index >= 0 && index < static_cast<int>(toolbar_actions_.size())); |
| 617 // Unfortunately, |index| doesn't really mean a lot to us, because this | 608 // Unfortunately, |index| doesn't really mean a lot to us, because this |
| 618 // window's toolbar could be different (if actions are popped out). Just | 609 // window's toolbar could be different (if actions are popped out). Just |
| 619 // do a full reorder. | 610 // do a full reorder. |
| 620 ReorderActions(); | 611 ReorderActions(); |
| 621 } | 612 } |
| 622 | 613 |
| 623 void ToolbarActionsBar::OnToolbarExtensionUpdated( | 614 void ToolbarActionsBar::OnToolbarActionUpdated(const std::string& action_id) { |
| 624 const extensions::Extension* extension) { | 615 ToolbarActionViewController* action = GetActionForId(action_id); |
| 625 ToolbarActionViewController* action = GetActionForId(extension->id()); | |
| 626 // There might not be a view in cases where we are highlighting or if we | 616 // There might not be a view in cases where we are highlighting or if we |
| 627 // haven't fully initialized the actions. | 617 // haven't fully initialized the actions. |
| 628 if (action) { | 618 if (action) { |
| 629 action->UpdateState(); | 619 action->UpdateState(); |
| 630 SetOverflowedActionWantsToRun(); | 620 SetOverflowedActionWantsToRun(); |
| 631 } | 621 } |
| 632 } | 622 } |
| 633 | 623 |
| 634 bool ToolbarActionsBar::ShowExtensionActionPopup( | 624 bool ToolbarActionsBar::ShowToolbarActionPopup(const std::string& action_id, |
| 635 const extensions::Extension* extension, | 625 bool grant_active_tab) { |
| 636 bool grant_active_tab) { | |
| 637 // Don't override another popup, and only show in the active window. | 626 // Don't override another popup, and only show in the active window. |
| 638 if (popup_owner() || !browser_->window()->IsActive()) | 627 if (popup_owner() || !browser_->window()->IsActive()) |
| 639 return false; | 628 return false; |
| 640 | 629 |
| 641 ToolbarActionViewController* action = GetActionForId(extension->id()); | 630 ToolbarActionViewController* action = GetActionForId(action_id); |
| 642 return action && action->ExecuteAction(grant_active_tab); | 631 return action && action->ExecuteAction(grant_active_tab); |
| 643 } | 632 } |
| 644 | 633 |
| 645 void ToolbarActionsBar::OnToolbarVisibleCountChanged() { | 634 void ToolbarActionsBar::OnToolbarVisibleCountChanged() { |
| 646 ResizeDelegate(gfx::Tween::EASE_OUT, false); | 635 ResizeDelegate(gfx::Tween::EASE_OUT, false); |
| 647 SetOverflowedActionWantsToRun(); | 636 SetOverflowedActionWantsToRun(); |
| 648 } | 637 } |
| 649 | 638 |
| 650 void ToolbarActionsBar::ResizeDelegate(gfx::Tween::Type tween_type, | 639 void ToolbarActionsBar::ResizeDelegate(gfx::Tween::Type tween_type, |
| 651 bool suppress_chevron) { | 640 bool suppress_chevron) { |
| 652 int desired_width = GetPreferredSize().width(); | 641 int desired_width = GetPreferredSize().width(); |
| 653 if (desired_width != delegate_->GetWidth()) { | 642 if (desired_width != delegate_->GetWidth()) { |
| 654 delegate_->ResizeAndAnimate(tween_type, desired_width, suppress_chevron); | 643 delegate_->ResizeAndAnimate(tween_type, desired_width, suppress_chevron); |
| 655 } else if (delegate_->IsAnimating()) { | 644 } else if (delegate_->IsAnimating()) { |
| 656 // It's possible that we're right where we're supposed to be in terms of | 645 // It's possible that we're right where we're supposed to be in terms of |
| 657 // width, but that we're also currently resizing. If this is the case, end | 646 // width, but that we're also currently resizing. If this is the case, end |
| 658 // the current animation with the current width. | 647 // the current animation with the current width. |
| 659 delegate_->StopAnimating(); | 648 delegate_->StopAnimating(); |
| 660 } else { | 649 } else { |
| 661 // We may already be at the right size (this can happen frequently with | 650 // We may already be at the right size (this can happen frequently with |
| 662 // overflow, where we have a fixed width, and in tests, where we skip | 651 // overflow, where we have a fixed width, and in tests, where we skip |
| 663 // animations). If this is the case, we still need to Redraw(), because the | 652 // animations). If this is the case, we still need to Redraw(), because the |
| 664 // icons within the toolbar may have changed (e.g. if we removed one | 653 // icons within the toolbar may have changed (e.g. if we removed one |
| 665 // action and added a different one in quick succession). | 654 // action and added a different one in quick succession). |
| 666 delegate_->Redraw(false); | 655 delegate_->Redraw(false); |
| 667 } | 656 } |
| 668 } | 657 } |
| 669 | 658 |
| 670 void ToolbarActionsBar::OnToolbarHighlightModeChanged(bool is_highlighting) { | 659 void ToolbarActionsBar::OnToolbarHighlightModeChanged(bool is_highlighting) { |
| 671 if (!model_->extensions_initialized()) | 660 if (!model_->actions_initialized()) |
| 672 return; | 661 return; |
| 673 // It's a bit of a pain that we delete and recreate everything here, but given | 662 // It's a bit of a pain that we delete and recreate everything here, but given |
| 674 // everything else going on (the lack of highlight, [n] more extensions | 663 // everything else going on (the lack of highlight, [n] more extensions |
| 675 // appearing, etc), it's not worth the extra complexity to create and insert | 664 // appearing, etc), it's not worth the extra complexity to create and insert |
| 676 // only the new actions. | 665 // only the new actions. |
| 677 DeleteActions(); | 666 DeleteActions(); |
| 678 CreateActions(); | 667 CreateActions(); |
| 679 // Resize the delegate. We suppress the chevron so that we don't risk showing | 668 // Resize the delegate. We suppress the chevron so that we don't risk showing |
| 680 // it only for the duration of the animation. | 669 // it only for the duration of the animation. |
| 681 ResizeDelegate(gfx::Tween::LINEAR, true); | 670 ResizeDelegate(gfx::Tween::LINEAR, true); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 697 Browser* ToolbarActionsBar::GetBrowser() { | 686 Browser* ToolbarActionsBar::GetBrowser() { |
| 698 return browser_; | 687 return browser_; |
| 699 } | 688 } |
| 700 | 689 |
| 701 void ToolbarActionsBar::ReorderActions() { | 690 void ToolbarActionsBar::ReorderActions() { |
| 702 if (toolbar_actions_.empty()) | 691 if (toolbar_actions_.empty()) |
| 703 return; | 692 return; |
| 704 | 693 |
| 705 // First, reset the order to that of the model. | 694 // First, reset the order to that of the model. |
| 706 auto compare = [](ToolbarActionViewController* const& action, | 695 auto compare = [](ToolbarActionViewController* const& action, |
| 707 const scoped_refptr<const extensions::Extension>& ext) { | 696 const std::string ext) { |
| 708 return action->GetId() == ext->id(); | 697 return action->GetId() == ext; |
| 709 }; | 698 }; |
| 710 SortContainer(&toolbar_actions_.get(), model_->toolbar_items(), compare); | 699 SortContainer(&toolbar_actions_.get(), model_->toolbar_items(), compare); |
| 711 | 700 |
| 712 // Our visible browser actions may have changed - re-Layout() and check the | 701 // Our visible browser actions may have changed - re-Layout() and check the |
| 713 // size (if we aren't suppressing the layout). | 702 // size (if we aren't suppressing the layout). |
| 714 if (!suppress_layout_) { | 703 if (!suppress_layout_) { |
| 715 ResizeDelegate(gfx::Tween::EASE_OUT, false); | 704 ResizeDelegate(gfx::Tween::EASE_OUT, false); |
| 716 delegate_->Redraw(true); | 705 delegate_->Redraw(true); |
| 717 } | 706 } |
| 718 | 707 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 733 | 722 |
| 734 if (overflowed_action_wants_to_run_ != overflowed_action_wants_to_run) { | 723 if (overflowed_action_wants_to_run_ != overflowed_action_wants_to_run) { |
| 735 overflowed_action_wants_to_run_ = overflowed_action_wants_to_run; | 724 overflowed_action_wants_to_run_ = overflowed_action_wants_to_run; |
| 736 if (send_overflowed_action_changes_) | 725 if (send_overflowed_action_changes_) |
| 737 delegate_->OnOverflowedActionWantsToRunChanged( | 726 delegate_->OnOverflowedActionWantsToRunChanged( |
| 738 overflowed_action_wants_to_run_); | 727 overflowed_action_wants_to_run_); |
| 739 } | 728 } |
| 740 } | 729 } |
| 741 | 730 |
| 742 ToolbarActionViewController* ToolbarActionsBar::GetActionForId( | 731 ToolbarActionViewController* ToolbarActionsBar::GetActionForId( |
| 743 const std::string& id) { | 732 const std::string& action_id) { |
| 744 for (ToolbarActionViewController* action : toolbar_actions_) { | 733 for (ToolbarActionViewController* action : toolbar_actions_) { |
| 745 if (action->GetId() == id) | 734 if (action->GetId() == action_id) |
| 746 return action; | 735 return action; |
| 747 } | 736 } |
| 748 return nullptr; | 737 return nullptr; |
| 749 } | 738 } |
| 750 | 739 |
| 751 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { | 740 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { |
| 752 return browser_->tab_strip_model()->GetActiveWebContents(); | 741 return browser_->tab_strip_model()->GetActiveWebContents(); |
| 753 } | 742 } |
| OLD | NEW |