Chromium Code Reviews| 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" |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 296 size_t rindex = actions.size() - index - 1; | 296 size_t rindex = actions.size() - index - 1; |
| 297 std::rotate(actions.rbegin() + rindex, | 297 std::rotate(actions.rbegin() + rindex, |
| 298 actions.rbegin() + rindex + 1, | 298 actions.rbegin() + rindex + 1, |
| 299 actions.rend() - visible + 1); | 299 actions.rend() - visible + 1); |
| 300 } | 300 } |
| 301 } | 301 } |
| 302 | 302 |
| 303 return actions; | 303 return actions; |
| 304 } | 304 } |
| 305 | 305 |
| 306 ToolbarActionsBar::HighlightType ToolbarActionsBar::GetHighlightType() const { | |
| 307 // TODO(devlin): This mapping is to avoid platform-specific ui implementations | |
| 308 // have a dependency on the ExtensionToolbarModel, but is a little odd. It | |
| 309 // would be better to just be able to return the set of images for the | |
| 310 // highlight here, but it's hard to do nicely since it's a nine-grid. | |
|
Peter Kasting
2015/07/23 00:00:12
Maybe this all becomes better if you return one im
Devlin
2015/07/23 02:43:30
It could be better with a single image, but see ot
Peter Kasting
2015/07/23 05:40:53
I guess I'd probably ask the same thing with the r
Devlin
2015/07/23 15:30:13
Benefit's not substantial enough. Removed the map
| |
| 311 HighlightType type = HIGHLIGHT_NONE; | |
| 312 if (model_ && model_->extensions_initialized()) { | |
| 313 switch (model_->highlight_type()) { | |
| 314 case extensions::ExtensionToolbarModel::HIGHLIGHT_NONE: | |
| 315 break; // Already HIGHLIGHT_TYPE_NONE | |
| 316 case extensions::ExtensionToolbarModel::HIGHLIGHT_INFO: | |
| 317 type = HIGHLIGHT_INFO; | |
| 318 break; | |
| 319 case extensions::ExtensionToolbarModel::HIGHLIGHT_WARNING: | |
| 320 type = HIGHLIGHT_WARNING; | |
| 321 break; | |
| 322 } | |
| 323 } | |
| 324 return type; | |
| 325 } | |
| 326 | |
| 306 void ToolbarActionsBar::CreateActions() { | 327 void ToolbarActionsBar::CreateActions() { |
| 307 DCHECK(toolbar_actions_.empty()); | 328 DCHECK(toolbar_actions_.empty()); |
| 308 // We wait for the extension system to be initialized before we add any | 329 // We wait for the extension system to be initialized before we add any |
| 309 // actions, as they rely on the extension system to function. | 330 // actions, as they rely on the extension system to function. |
| 310 if (!model_ || !model_->extensions_initialized()) | 331 if (!model_ || !model_->extensions_initialized()) |
| 311 return; | 332 return; |
| 312 | 333 |
| 313 { | 334 { |
| 314 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/463337 | 335 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/463337 |
| 315 // is fixed. | 336 // is fixed. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 365 | 386 |
| 366 for (size_t i = 0; i < toolbar_actions_.size(); ++i) | 387 for (size_t i = 0; i < toolbar_actions_.size(); ++i) |
| 367 delegate_->AddViewForAction(toolbar_actions_[i], i); | 388 delegate_->AddViewForAction(toolbar_actions_[i], i); |
| 368 } | 389 } |
| 369 | 390 |
| 370 // Once the actions are created, we should animate the changes. | 391 // Once the actions are created, we should animate the changes. |
| 371 suppress_animation_ = false; | 392 suppress_animation_ = false; |
| 372 | 393 |
| 373 // CreateActions() can be called multiple times, so we need to make sure we | 394 // CreateActions() can be called multiple times, so we need to make sure we |
| 374 // haven't already shown the bubble. | 395 // haven't already shown the bubble. |
| 375 if (!checked_extension_bubble_) { | 396 if (!checked_extension_bubble_ && !is_highlighting()) { |
|
Peter Kasting
2015/07/23 00:00:12
I'm not totally clear on why this was added...
Devlin
2015/07/23 02:43:30
Extension bubbles can cause a subsection of extens
Peter Kasting
2015/07/23 05:40:53
Ahhhh. Once again, might be worth a descriptive c
Devlin
2015/07/23 15:30:13
Done.
| |
| 376 checked_extension_bubble_ = true; | 397 checked_extension_bubble_ = true; |
| 377 // CreateActions() can be called as part of the browser window set up, which | 398 // CreateActions() can be called as part of the browser window set up, which |
| 378 // we need to let finish before showing the actions. | 399 // we need to let finish before showing the actions. |
| 379 scoped_ptr<extensions::ExtensionMessageBubbleController> controller = | 400 scoped_ptr<extensions::ExtensionMessageBubbleController> controller = |
| 380 ExtensionMessageBubbleFactory(browser_->profile()).GetController(); | 401 ExtensionMessageBubbleFactory(browser_->profile()).GetController(); |
| 381 if (controller) { | 402 if (controller) { |
| 382 base::ThreadTaskRunnerHandle::Get()->PostTask( | 403 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 383 FROM_HERE, base::Bind(&ToolbarActionsBar::MaybeShowExtensionBubble, | 404 FROM_HERE, base::Bind(&ToolbarActionsBar::MaybeShowExtensionBubble, |
| 384 weak_ptr_factory_.GetWeakPtr(), | 405 weak_ptr_factory_.GetWeakPtr(), |
| 385 base::Passed(controller.Pass()))); | 406 base::Passed(controller.Pass()))); |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 657 // We may already be at the right size (this can happen frequently with | 678 // We may already be at the right size (this can happen frequently with |
| 658 // overflow, where we have a fixed width, and in tests, where we skip | 679 // overflow, where we have a fixed width, and in tests, where we skip |
| 659 // animations). If this is the case, we still need to Redraw(), because the | 680 // animations). If this is the case, we still need to Redraw(), because the |
| 660 // icons within the toolbar may have changed (e.g. if we removed one | 681 // icons within the toolbar may have changed (e.g. if we removed one |
| 661 // action and added a different one in quick succession). | 682 // action and added a different one in quick succession). |
| 662 delegate_->Redraw(false); | 683 delegate_->Redraw(false); |
| 663 } | 684 } |
| 664 } | 685 } |
| 665 | 686 |
| 666 void ToolbarActionsBar::OnToolbarHighlightModeChanged(bool is_highlighting) { | 687 void ToolbarActionsBar::OnToolbarHighlightModeChanged(bool is_highlighting) { |
| 688 if (!model_->extensions_initialized()) | |
| 689 return; | |
| 667 // It's a bit of a pain that we delete and recreate everything here, but given | 690 // It's a bit of a pain that we delete and recreate everything here, but given |
| 668 // everything else going on (the lack of highlight, [n] more extensions | 691 // everything else going on (the lack of highlight, [n] more extensions |
| 669 // appearing, etc), it's not worth the extra complexity to create and insert | 692 // appearing, etc), it's not worth the extra complexity to create and insert |
| 670 // only the new actions. | 693 // only the new actions. |
| 671 DeleteActions(); | 694 DeleteActions(); |
| 672 CreateActions(); | 695 CreateActions(); |
| 673 // Resize the delegate. We suppress the chevron so that we don't risk showing | 696 // Resize the delegate. We suppress the chevron so that we don't risk showing |
| 674 // it only for the duration of the animation. | 697 // it only for the duration of the animation. |
| 675 ResizeDelegate(gfx::Tween::LINEAR, true); | 698 ResizeDelegate(gfx::Tween::LINEAR, true); |
| 676 } | 699 } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 738 for (ToolbarActionViewController* action : toolbar_actions_) { | 761 for (ToolbarActionViewController* action : toolbar_actions_) { |
| 739 if (action->GetId() == id) | 762 if (action->GetId() == id) |
| 740 return action; | 763 return action; |
| 741 } | 764 } |
| 742 return nullptr; | 765 return nullptr; |
| 743 } | 766 } |
| 744 | 767 |
| 745 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { | 768 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { |
| 746 return browser_->tab_strip_model()->GetActiveWebContents(); | 769 return browser_->tab_strip_model()->GetActiveWebContents(); |
| 747 } | 770 } |
| OLD | NEW |