| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/views/toolbar/browser_actions_container.h" | 5 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "chrome/browser/extensions/extension_message_bubble_controller.h" | 9 #include "chrome/browser/extensions/extension_message_bubble_controller.h" |
| 10 #include "chrome/browser/extensions/tab_helper.h" | 10 #include "chrome/browser/extensions/tab_helper.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/extensions/extension_toolbar_icon_surfacing_bubble_d
elegate.h" | 13 #include "chrome/browser/ui/extensions/extension_toolbar_icon_surfacing_bubble_d
elegate.h" |
| 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 15 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" | 15 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" |
| 16 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" | 16 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" |
| 17 #include "chrome/browser/ui/toolbar/toolbar_actions_model.h" | 17 #include "chrome/browser/ui/toolbar/toolbar_actions_model.h" |
| 18 #include "chrome/browser/ui/view_ids.h" | 18 #include "chrome/browser/ui/view_ids.h" |
| 19 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h" | 19 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h" |
| 20 #include "chrome/browser/ui/views/extensions/extension_message_bubble_view.h" | 20 #include "chrome/browser/ui/views/extensions/extension_message_bubble_view.h" |
| 21 #include "chrome/browser/ui/views/extensions/extension_toolbar_icon_surfacing_bu
bble_views.h" | 21 #include "chrome/browser/ui/views/extensions/extension_toolbar_icon_surfacing_bu
bble_views.h" |
| 22 #include "chrome/browser/ui/views/frame/browser_view.h" | 22 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 23 #include "chrome/browser/ui/views/toolbar/app_menu_button.h" | 23 #include "chrome/browser/ui/views/toolbar/app_menu_button.h" |
| 24 #include "chrome/browser/ui/views/toolbar/browser_actions_container_observer.h" | |
| 25 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | 24 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
| 26 #include "chrome/common/extensions/command.h" | 25 #include "chrome/common/extensions/command.h" |
| 27 #include "chrome/grit/generated_resources.h" | 26 #include "chrome/grit/generated_resources.h" |
| 28 #include "extensions/common/feature_switch.h" | 27 #include "extensions/common/feature_switch.h" |
| 29 #include "grit/theme_resources.h" | 28 #include "grit/theme_resources.h" |
| 30 #include "third_party/skia/include/core/SkColor.h" | 29 #include "third_party/skia/include/core/SkColor.h" |
| 31 #include "ui/accessibility/ax_view_state.h" | 30 #include "ui/accessibility/ax_view_state.h" |
| 32 #include "ui/base/dragdrop/drag_utils.h" | 31 #include "ui/base/dragdrop/drag_utils.h" |
| 33 #include "ui/base/l10n/l10n_util.h" | 32 #include "ui/base/l10n/l10n_util.h" |
| 34 #include "ui/base/nine_image_painter_factory.h" | 33 #include "ui/base/nine_image_painter_factory.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 } | 120 } |
| 122 } | 121 } |
| 123 | 122 |
| 124 BrowserActionsContainer::~BrowserActionsContainer() { | 123 BrowserActionsContainer::~BrowserActionsContainer() { |
| 125 if (active_bubble_) | 124 if (active_bubble_) |
| 126 active_bubble_->GetWidget()->Close(); | 125 active_bubble_->GetWidget()->Close(); |
| 127 // We should synchronously receive the OnWidgetClosing() event, so we should | 126 // We should synchronously receive the OnWidgetClosing() event, so we should |
| 128 // always have cleared the active bubble by now. | 127 // always have cleared the active bubble by now. |
| 129 DCHECK(!active_bubble_); | 128 DCHECK(!active_bubble_); |
| 130 | 129 |
| 131 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, observers_, | |
| 132 OnBrowserActionsContainerDestroyed(this)); | |
| 133 | |
| 134 toolbar_actions_bar_->DeleteActions(); | 130 toolbar_actions_bar_->DeleteActions(); |
| 135 // All views should be removed as part of ToolbarActionsBar::DeleteActions(). | 131 // All views should be removed as part of ToolbarActionsBar::DeleteActions(). |
| 136 DCHECK(toolbar_action_views_.empty()); | 132 DCHECK(toolbar_action_views_.empty()); |
| 137 } | 133 } |
| 138 | 134 |
| 139 void BrowserActionsContainer::Init() { | 135 void BrowserActionsContainer::Init() { |
| 140 LoadImages(); | 136 LoadImages(); |
| 141 } | 137 } |
| 142 | 138 |
| 143 std::string BrowserActionsContainer::GetIdAt(size_t index) const { | 139 std::string BrowserActionsContainer::GetIdAt(size_t index) const { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 extension_keybinding_registry_->ExecuteCommand(extension->id(), | 178 extension_keybinding_registry_->ExecuteCommand(extension->id(), |
| 183 command.accelerator()); | 179 command.accelerator()); |
| 184 } | 180 } |
| 185 | 181 |
| 186 bool BrowserActionsContainer::ShownInsideMenu() const { | 182 bool BrowserActionsContainer::ShownInsideMenu() const { |
| 187 return in_overflow_mode(); | 183 return in_overflow_mode(); |
| 188 } | 184 } |
| 189 | 185 |
| 190 void BrowserActionsContainer::OnToolbarActionViewDragDone() { | 186 void BrowserActionsContainer::OnToolbarActionViewDragDone() { |
| 191 toolbar_actions_bar_->OnDragEnded(); | 187 toolbar_actions_bar_->OnDragEnded(); |
| 192 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, | |
| 193 observers_, | |
| 194 OnBrowserActionDragDone()); | |
| 195 } | 188 } |
| 196 | 189 |
| 197 views::MenuButton* BrowserActionsContainer::GetOverflowReferenceView() { | 190 views::MenuButton* BrowserActionsContainer::GetOverflowReferenceView() { |
| 198 // With traditional overflow, the reference is the chevron. With the redesign, | 191 // With traditional overflow, the reference is the chevron. With the redesign, |
| 199 // we use the app menu instead. | 192 // we use the app menu instead. |
| 200 return chevron_ ? static_cast<views::MenuButton*>(chevron_) | 193 return chevron_ ? static_cast<views::MenuButton*>(chevron_) |
| 201 : static_cast<views::MenuButton*>( | 194 : static_cast<views::MenuButton*>( |
| 202 GetToolbarView(browser_)->app_menu_button()); | 195 GetToolbarView(browser_)->app_menu_button()); |
| 203 } | 196 } |
| 204 | 197 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 // Find where the correct view is (it's guaranteed to be after our | 258 // Find where the correct view is (it's guaranteed to be after our |
| 266 // current index, since everything up to this point is correct). | 259 // current index, since everything up to this point is correct). |
| 267 int j = i + 1; | 260 int j = i + 1; |
| 268 while (actions[i] != toolbar_action_views_[j]->view_controller()) | 261 while (actions[i] != toolbar_action_views_[j]->view_controller()) |
| 269 ++j; | 262 ++j; |
| 270 std::swap(toolbar_action_views_[i], toolbar_action_views_[j]); | 263 std::swap(toolbar_action_views_[i], toolbar_action_views_[j]); |
| 271 } | 264 } |
| 272 } | 265 } |
| 273 } | 266 } |
| 274 | 267 |
| 275 if (width() != GetPreferredSize().width() && parent()) { | 268 Layout(); |
| 276 parent()->Layout(); | |
| 277 parent()->SchedulePaint(); | |
| 278 } else { | |
| 279 Layout(); | |
| 280 SchedulePaint(); | |
| 281 } | |
| 282 } | 269 } |
| 283 | 270 |
| 284 void BrowserActionsContainer::ResizeAndAnimate( | 271 void BrowserActionsContainer::ResizeAndAnimate( |
| 285 gfx::Tween::Type tween_type, | 272 gfx::Tween::Type tween_type, |
| 286 int target_width, | 273 int target_width, |
| 287 bool suppress_chevron) { | 274 bool suppress_chevron) { |
| 288 if (resize_animation_ && !toolbar_actions_bar_->suppress_animation()) { | 275 if (resize_animation_ && !toolbar_actions_bar_->suppress_animation()) { |
| 289 if (!in_overflow_mode()) { | 276 if (!in_overflow_mode()) { |
| 290 // Make sure we don't try to animate to wider than the allowed width. | 277 // Make sure we don't try to animate to wider than the allowed width. |
| 291 int max_width = GetToolbarView(browser_)->GetMaxBrowserActionsWidth(); | 278 int max_width = GetToolbarView(browser_)->GetMaxBrowserActionsWidth(); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 // If we can't even show the minimum width, just throw in the towel (and | 356 // If we can't even show the minimum width, just throw in the towel (and |
| 370 // show nothing). | 357 // show nothing). |
| 371 if (max_width < toolbar_actions_bar_->GetMinimumWidth()) | 358 if (max_width < toolbar_actions_bar_->GetMinimumWidth()) |
| 372 return 0; | 359 return 0; |
| 373 preferred_width = toolbar_actions_bar_->IconCountToWidth( | 360 preferred_width = toolbar_actions_bar_->IconCountToWidth( |
| 374 toolbar_actions_bar_->WidthToIconCount(max_width)); | 361 toolbar_actions_bar_->WidthToIconCount(max_width)); |
| 375 } | 362 } |
| 376 return preferred_width; | 363 return preferred_width; |
| 377 } | 364 } |
| 378 | 365 |
| 379 void BrowserActionsContainer::AddObserver( | |
| 380 BrowserActionsContainerObserver* observer) { | |
| 381 observers_.AddObserver(observer); | |
| 382 } | |
| 383 | |
| 384 void BrowserActionsContainer::RemoveObserver( | |
| 385 BrowserActionsContainerObserver* observer) { | |
| 386 observers_.RemoveObserver(observer); | |
| 387 } | |
| 388 | |
| 389 gfx::Size BrowserActionsContainer::GetPreferredSize() const { | 366 gfx::Size BrowserActionsContainer::GetPreferredSize() const { |
| 390 if (in_overflow_mode()) | 367 if (in_overflow_mode()) |
| 391 return toolbar_actions_bar_->GetPreferredSize(); | 368 return toolbar_actions_bar_->GetPreferredSize(); |
| 392 | 369 |
| 393 // If there are no actions to show, then don't show the container at all. | 370 // If there are no actions to show, then don't show the container at all. |
| 394 if (toolbar_action_views_.empty()) | 371 if (toolbar_action_views_.empty()) |
| 395 return gfx::Size(); | 372 return gfx::Size(); |
| 396 | 373 |
| 397 // When resizing, preferred width is the starting width - resize amount. | 374 // When resizing, preferred width is the starting width - resize amount. |
| 398 // Otherwise, use the normal preferred width. | 375 // Otherwise, use the normal preferred width. |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 if (toolbar_actions_bar_->is_highlighting() || animating()) | 624 if (toolbar_actions_bar_->is_highlighting() || animating()) |
| 648 return; | 625 return; |
| 649 | 626 |
| 650 // If this is the start of the resize gesture, initialize the starting | 627 // If this is the start of the resize gesture, initialize the starting |
| 651 // width. | 628 // width. |
| 652 if (resize_starting_width_ == -1) | 629 if (resize_starting_width_ == -1) |
| 653 resize_starting_width_ = width(); | 630 resize_starting_width_ = width(); |
| 654 | 631 |
| 655 if (!done_resizing) { | 632 if (!done_resizing) { |
| 656 resize_amount_ = resize_amount; | 633 resize_amount_ = resize_amount; |
| 657 Redraw(false); | 634 parent()->Layout(); |
| 658 return; | 635 return; |
| 659 } | 636 } |
| 660 | 637 |
| 661 // Up until now we've only been modifying the resize_amount, but now it is | 638 // Up until now we've only been modifying the resize_amount, but now it is |
| 662 // time to set the container size to the size we have resized to, and then | 639 // time to set the container size to the size we have resized to, and then |
| 663 // animate to the nearest icon count size if necessary (which may be 0). | 640 // animate to the nearest icon count size if necessary (which may be 0). |
| 664 int ending_width = | 641 int ending_width = |
| 665 std::min(std::max(toolbar_actions_bar_->GetMinimumWidth(), | 642 std::min(std::max(toolbar_actions_bar_->GetMinimumWidth(), |
| 666 resize_starting_width_ - resize_amount), | 643 resize_starting_width_ - resize_amount), |
| 667 toolbar_actions_bar_->GetMaximumWidth()); | 644 toolbar_actions_bar_->GetMaximumWidth()); |
| 668 resize_starting_width_ = -1; | 645 resize_starting_width_ = -1; |
| 669 toolbar_actions_bar_->OnResizeComplete(ending_width); | 646 toolbar_actions_bar_->OnResizeComplete(ending_width); |
| 670 } | 647 } |
| 671 | 648 |
| 672 void BrowserActionsContainer::AnimationProgressed( | 649 void BrowserActionsContainer::AnimationProgressed( |
| 673 const gfx::Animation* animation) { | 650 const gfx::Animation* animation) { |
| 674 DCHECK_EQ(resize_animation_.get(), animation); | 651 DCHECK_EQ(resize_animation_.get(), animation); |
| 675 resize_amount_ = static_cast<int>(resize_animation_->GetCurrentValue() * | 652 resize_amount_ = static_cast<int>(resize_animation_->GetCurrentValue() * |
| 676 (resize_starting_width_ - animation_target_size_)); | 653 (resize_starting_width_ - animation_target_size_)); |
| 677 Redraw(false); | 654 parent()->Layout(); |
| 678 } | 655 } |
| 679 | 656 |
| 680 void BrowserActionsContainer::AnimationCanceled( | 657 void BrowserActionsContainer::AnimationCanceled( |
| 681 const gfx::Animation* animation) { | 658 const gfx::Animation* animation) { |
| 682 AnimationEnded(animation); | 659 AnimationEnded(animation); |
| 683 } | 660 } |
| 684 | 661 |
| 685 void BrowserActionsContainer::AnimationEnded(const gfx::Animation* animation) { | 662 void BrowserActionsContainer::AnimationEnded(const gfx::Animation* animation) { |
| 686 animation_target_size_ = 0; | 663 animation_target_size_ = 0; |
| 687 resize_amount_ = 0; | 664 resize_amount_ = 0; |
| 688 resize_starting_width_ = -1; | 665 resize_starting_width_ = -1; |
| 689 suppress_chevron_ = false; | 666 suppress_chevron_ = false; |
| 690 Redraw(false); | 667 parent()->Layout(); |
| 691 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, | |
| 692 observers_, | |
| 693 OnBrowserActionsContainerAnimationEnded()); | |
| 694 | 668 |
| 695 toolbar_actions_bar_->OnAnimationEnded(); | 669 toolbar_actions_bar_->OnAnimationEnded(); |
| 696 } | 670 } |
| 697 | 671 |
| 698 content::WebContents* BrowserActionsContainer::GetCurrentWebContents() { | 672 content::WebContents* BrowserActionsContainer::GetCurrentWebContents() { |
| 699 return browser_->tab_strip_model()->GetActiveWebContents(); | 673 return browser_->tab_strip_model()->GetActiveWebContents(); |
| 700 } | 674 } |
| 701 | 675 |
| 702 extensions::ActiveTabPermissionGranter* | 676 extensions::ActiveTabPermissionGranter* |
| 703 BrowserActionsContainer::GetActiveTabPermissionGranter() { | 677 BrowserActionsContainer::GetActiveTabPermissionGranter() { |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 807 warning_highlight_painter_.reset( | 781 warning_highlight_painter_.reset( |
| 808 views::Painter::CreateImageGridPainter(kWarningImages)); | 782 views::Painter::CreateImageGridPainter(kWarningImages)); |
| 809 } | 783 } |
| 810 | 784 |
| 811 void BrowserActionsContainer::ClearActiveBubble(views::Widget* widget) { | 785 void BrowserActionsContainer::ClearActiveBubble(views::Widget* widget) { |
| 812 DCHECK(active_bubble_); | 786 DCHECK(active_bubble_); |
| 813 DCHECK_EQ(active_bubble_->GetWidget(), widget); | 787 DCHECK_EQ(active_bubble_->GetWidget(), widget); |
| 814 widget->RemoveObserver(this); | 788 widget->RemoveObserver(this); |
| 815 active_bubble_ = nullptr; | 789 active_bubble_ = nullptr; |
| 816 } | 790 } |
| OLD | NEW |