Chromium Code Reviews| 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_action_manager.h" | 9 #include "chrome/browser/extensions/extension_action_manager.h" |
| 10 #include "chrome/browser/extensions/extension_util.h" | 10 #include "chrome/browser/extensions/extension_util.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 45 #include "ui/views/painter.h" | 45 #include "ui/views/painter.h" |
| 46 #include "ui/views/widget/widget.h" | 46 #include "ui/views/widget/widget.h" |
| 47 | 47 |
| 48 using extensions::Extension; | 48 using extensions::Extension; |
| 49 | 49 |
| 50 namespace { | 50 namespace { |
| 51 | 51 |
| 52 // Horizontal spacing before the chevron (if visible). | 52 // Horizontal spacing before the chevron (if visible). |
| 53 const int kChevronSpacing = ToolbarView::kStandardSpacing - 2; | 53 const int kChevronSpacing = ToolbarView::kStandardSpacing - 2; |
| 54 | 54 |
| 55 // A version of MenuButton with almost empty insets to fit properly on the | |
| 56 // toolbar. | |
| 57 class ChevronMenuButton : public views::MenuButton { | |
| 58 public: | |
| 59 ChevronMenuButton(views::ButtonListener* listener, | |
| 60 const base::string16& text, | |
| 61 views::MenuButtonListener* menu_button_listener, | |
| 62 bool show_menu_marker) | |
| 63 : views::MenuButton(listener, | |
| 64 text, | |
| 65 menu_button_listener, | |
| 66 show_menu_marker) { | |
| 67 } | |
| 68 | |
| 69 virtual ~ChevronMenuButton() {} | |
| 70 | |
| 71 virtual scoped_ptr<views::LabelButtonBorder> CreateDefaultBorder() const | |
| 72 OVERRIDE { | |
| 73 // The chevron resource was designed to not have any insets. | |
| 74 scoped_ptr<views::LabelButtonBorder> border = | |
| 75 views::MenuButton::CreateDefaultBorder(); | |
| 76 border->set_insets(gfx::Insets()); | |
| 77 return border.Pass(); | |
| 78 } | |
| 79 | |
| 80 private: | |
| 81 DISALLOW_COPY_AND_ASSIGN(ChevronMenuButton); | |
| 82 }; | |
| 83 | |
| 84 } // namespace | 55 } // namespace |
| 85 | 56 |
| 86 //////////////////////////////////////////////////////////////////////////////// | 57 //////////////////////////////////////////////////////////////////////////////// |
| 87 // BrowserActionsContainer::DropPosition | 58 // BrowserActionsContainer::DropPosition |
| 88 | 59 |
| 89 struct BrowserActionsContainer::DropPosition { | 60 struct BrowserActionsContainer::DropPosition { |
| 90 DropPosition(size_t row, size_t icon_in_row); | 61 DropPosition(size_t row, size_t icon_in_row); |
| 91 | 62 |
| 92 // The (0-indexed) row into which the action will be dropped. | 63 // The (0-indexed) row into which the action will be dropped. |
| 93 size_t row; | 64 size_t row; |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 119 BrowserActionsContainer* main_container) | 90 BrowserActionsContainer* main_container) |
| 120 : initialized_(false), | 91 : initialized_(false), |
| 121 profile_(browser->profile()), | 92 profile_(browser->profile()), |
| 122 browser_(browser), | 93 browser_(browser), |
| 123 owner_view_(owner_view), | 94 owner_view_(owner_view), |
| 124 main_container_(main_container), | 95 main_container_(main_container), |
| 125 popup_owner_(NULL), | 96 popup_owner_(NULL), |
| 126 model_(NULL), | 97 model_(NULL), |
| 127 container_width_(0), | 98 container_width_(0), |
| 128 resize_area_(NULL), | 99 resize_area_(NULL), |
| 129 chevron_(NULL), | |
| 130 overflow_menu_(NULL), | |
| 131 suppress_chevron_(false), | 100 suppress_chevron_(false), |
| 132 resize_amount_(0), | 101 resize_amount_(0), |
| 133 animation_target_size_(0), | 102 animation_target_size_(0) { |
| 134 show_menu_task_factory_(this) { | |
| 135 set_id(VIEW_ID_BROWSER_ACTION_TOOLBAR); | 103 set_id(VIEW_ID_BROWSER_ACTION_TOOLBAR); |
| 136 | 104 |
| 137 model_ = extensions::ExtensionToolbarModel::Get(browser->profile()); | 105 model_ = extensions::ExtensionToolbarModel::Get(browser->profile()); |
| 138 if (model_) | 106 if (model_) |
| 139 model_->AddObserver(this); | 107 model_->AddObserver(this); |
| 140 | 108 |
| 141 bool overflow_experiment = | 109 bool overflow_experiment = |
| 142 extensions::FeatureSwitch::extension_action_redesign()->IsEnabled(); | 110 extensions::FeatureSwitch::extension_action_redesign()->IsEnabled(); |
| 143 DCHECK(!in_overflow_mode() || overflow_experiment); | 111 DCHECK(!in_overflow_mode() || overflow_experiment); |
| 144 | 112 |
| 145 if (!in_overflow_mode()) { | 113 if (!in_overflow_mode()) { |
| 146 extension_keybinding_registry_.reset(new ExtensionKeybindingRegistryViews( | 114 extension_keybinding_registry_.reset(new ExtensionKeybindingRegistryViews( |
| 147 browser->profile(), | 115 browser->profile(), |
| 148 owner_view->GetFocusManager(), | 116 owner_view->GetFocusManager(), |
| 149 extensions::ExtensionKeybindingRegistry::ALL_EXTENSIONS, | 117 extensions::ExtensionKeybindingRegistry::ALL_EXTENSIONS, |
| 150 this)); | 118 this)); |
| 151 | 119 |
| 152 resize_animation_.reset(new gfx::SlideAnimation(this)); | 120 resize_animation_.reset(new gfx::SlideAnimation(this)); |
| 153 resize_area_ = new views::ResizeArea(this); | 121 resize_area_ = new views::ResizeArea(this); |
| 154 AddChildView(resize_area_); | 122 AddChildView(resize_area_); |
| 155 | 123 |
| 156 // 'Main' mode doesn't need a chevron overflow when overflow is shown inside | 124 // 'Main' mode doesn't need a chevron overflow when overflow is shown inside |
| 157 // the Chrome menu. | 125 // the Chrome menu. |
| 158 if (!overflow_experiment) { | 126 if (!overflow_experiment) { |
| 159 chevron_ = new ChevronMenuButton(NULL, base::string16(), this, false); | 127 // Since the ChevronMenuButton holds a raw pointer to us, we need to |
| 128 // ensure it doesn't outlive us. Having it owned by the view hierarchy as | |
| 129 // a child will suffice. | |
| 130 chevron_.reset(new ChevronMenuButton(this)); | |
|
Peter Kasting
2014/09/25 20:42:41
This needs to not be a scoped_ptr now, since other
Devlin
2014/09/25 20:47:12
Done.
| |
| 160 chevron_->EnableCanvasFlippingForRTLUI(true); | 131 chevron_->EnableCanvasFlippingForRTLUI(true); |
| 161 chevron_->SetAccessibleName( | 132 chevron_->SetAccessibleName( |
| 162 l10n_util::GetStringUTF16(IDS_ACCNAME_EXTENSIONS_CHEVRON)); | 133 l10n_util::GetStringUTF16(IDS_ACCNAME_EXTENSIONS_CHEVRON)); |
| 163 chevron_->SetVisible(false); | 134 chevron_->SetVisible(false); |
| 164 AddChildView(chevron_); | 135 AddChildView(chevron_.get()); |
| 165 } | 136 } |
| 166 } | 137 } |
| 167 } | 138 } |
| 168 | 139 |
| 169 BrowserActionsContainer::~BrowserActionsContainer() { | 140 BrowserActionsContainer::~BrowserActionsContainer() { |
| 170 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, | 141 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, |
| 171 observers_, | 142 observers_, |
| 172 OnBrowserActionsContainerDestroyed()); | 143 OnBrowserActionsContainerDestroyed()); |
| 173 | 144 |
| 174 if (overflow_menu_) | |
| 175 overflow_menu_->set_observer(NULL); | |
| 176 if (model_) | 145 if (model_) |
| 177 model_->RemoveObserver(this); | 146 model_->RemoveObserver(this); |
| 178 StopShowFolderDropMenuTimer(); | |
| 179 HideActivePopup(); | 147 HideActivePopup(); |
| 180 DeleteBrowserActionViews(); | 148 DeleteBrowserActionViews(); |
| 181 } | 149 } |
| 182 | 150 |
| 183 void BrowserActionsContainer::Init() { | 151 void BrowserActionsContainer::Init() { |
| 184 LoadImages(); | 152 LoadImages(); |
| 185 | 153 |
| 186 // We wait to set the container width until now so that the chevron images | 154 // We wait to set the container width until now so that the chevron images |
| 187 // will be loaded. The width calculation needs to know the chevron size. | 155 // will be loaded. The width calculation needs to know the chevron size. |
| 188 if (model_ && model_->extensions_initialized()) { | 156 if (model_ && model_->extensions_initialized()) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 226 action_manager->GetExtensionAction(**i), | 194 action_manager->GetExtensionAction(**i), |
| 227 browser_, | 195 browser_, |
| 228 this); | 196 this); |
| 229 browser_action_views_.push_back(view); | 197 browser_action_views_.push_back(view); |
| 230 AddChildView(view); | 198 AddChildView(view); |
| 231 } | 199 } |
| 232 } | 200 } |
| 233 | 201 |
| 234 void BrowserActionsContainer::DeleteBrowserActionViews() { | 202 void BrowserActionsContainer::DeleteBrowserActionViews() { |
| 235 HideActivePopup(); | 203 HideActivePopup(); |
| 236 if (overflow_menu_) | |
| 237 overflow_menu_->NotifyBrowserActionViewsDeleting(); | |
| 238 STLDeleteElements(&browser_action_views_); | 204 STLDeleteElements(&browser_action_views_); |
| 239 } | 205 } |
| 240 | 206 |
| 241 size_t BrowserActionsContainer::VisibleBrowserActions() const { | 207 size_t BrowserActionsContainer::VisibleBrowserActions() const { |
| 242 size_t visible_actions = 0; | 208 size_t visible_actions = 0; |
| 243 for (size_t i = 0; i < browser_action_views_.size(); ++i) { | 209 for (size_t i = 0; i < browser_action_views_.size(); ++i) { |
| 244 if (browser_action_views_[i]->visible()) | 210 if (browser_action_views_[i]->visible()) |
| 245 ++visible_actions; | 211 ++visible_actions; |
| 246 } | 212 } |
| 247 return visible_actions; | 213 return visible_actions; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 288 ToolbarVisibleCountChanged(); | 254 ToolbarVisibleCountChanged(); |
| 289 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, | 255 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, |
| 290 observers_, | 256 observers_, |
| 291 OnBrowserActionDragDone()); | 257 OnBrowserActionDragDone()); |
| 292 } | 258 } |
| 293 | 259 |
| 294 views::MenuButton* BrowserActionsContainer::GetOverflowReferenceView() { | 260 views::MenuButton* BrowserActionsContainer::GetOverflowReferenceView() { |
| 295 // With traditional overflow, the reference is the chevron. With the | 261 // With traditional overflow, the reference is the chevron. With the |
| 296 // redesign, we use the wrench menu instead. | 262 // redesign, we use the wrench menu instead. |
| 297 return chevron_ ? | 263 return chevron_ ? |
| 298 chevron_ : | 264 chevron_.get() : |
| 299 BrowserView::GetBrowserViewForBrowser(browser_)->toolbar()->app_menu(); | 265 BrowserView::GetBrowserViewForBrowser(browser_)->toolbar()->app_menu(); |
| 300 } | 266 } |
| 301 | 267 |
| 302 void BrowserActionsContainer::SetPopupOwner(BrowserActionView* popup_owner) { | 268 void BrowserActionsContainer::SetPopupOwner(BrowserActionView* popup_owner) { |
| 303 // We should never be setting a popup owner when one already exists, and | 269 // We should never be setting a popup owner when one already exists, and |
| 304 // never unsetting one when one wasn't set. | 270 // never unsetting one when one wasn't set. |
| 305 DCHECK((!popup_owner_ && popup_owner) || | 271 DCHECK((!popup_owner_ && popup_owner) || |
| 306 (popup_owner_ && !popup_owner)); | 272 (popup_owner_ && !popup_owner)); |
| 307 popup_owner_ = popup_owner; | 273 popup_owner_ = popup_owner; |
| 308 } | 274 } |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 375 SetVisible(false); | 341 SetVisible(false); |
| 376 return; | 342 return; |
| 377 } | 343 } |
| 378 | 344 |
| 379 SetVisible(true); | 345 SetVisible(true); |
| 380 if (resize_area_) | 346 if (resize_area_) |
| 381 resize_area_->SetBounds(0, 0, kItemSpacing, height()); | 347 resize_area_->SetBounds(0, 0, kItemSpacing, height()); |
| 382 | 348 |
| 383 // If the icons don't all fit, show the chevron (unless suppressed). | 349 // If the icons don't all fit, show the chevron (unless suppressed). |
| 384 int max_x = GetPreferredSize().width(); | 350 int max_x = GetPreferredSize().width(); |
| 385 if ((IconCountToWidth(-1, false) > max_x) && !suppress_chevron_ && chevron_) { | 351 if (IconCountToWidth(-1, false) > max_x && !suppress_chevron_ && chevron_) { |
| 386 chevron_->SetVisible(true); | 352 chevron_->SetVisible(true); |
| 387 gfx::Size chevron_size(chevron_->GetPreferredSize()); | 353 gfx::Size chevron_size(chevron_->GetPreferredSize()); |
| 388 max_x -= | 354 max_x -= |
| 389 ToolbarView::kStandardSpacing + chevron_size.width() + kChevronSpacing; | 355 ToolbarView::kStandardSpacing + chevron_size.width() + kChevronSpacing; |
| 390 chevron_->SetBounds( | 356 chevron_->SetBounds( |
| 391 width() - ToolbarView::kStandardSpacing - chevron_size.width(), | 357 width() - ToolbarView::kStandardSpacing - chevron_size.width(), |
| 392 0, | 358 0, |
| 393 chevron_size.width(), | 359 chevron_size.width(), |
| 394 chevron_size.height()); | 360 chevron_size.height()); |
| 395 } else if (chevron_) { | 361 } else if (chevron_) { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 440 bool BrowserActionsContainer::AreDropTypesRequired() { | 406 bool BrowserActionsContainer::AreDropTypesRequired() { |
| 441 return BrowserActionDragData::AreDropTypesRequired(); | 407 return BrowserActionDragData::AreDropTypesRequired(); |
| 442 } | 408 } |
| 443 | 409 |
| 444 bool BrowserActionsContainer::CanDrop(const OSExchangeData& data) { | 410 bool BrowserActionsContainer::CanDrop(const OSExchangeData& data) { |
| 445 return BrowserActionDragData::CanDrop(data, profile_); | 411 return BrowserActionDragData::CanDrop(data, profile_); |
| 446 } | 412 } |
| 447 | 413 |
| 448 int BrowserActionsContainer::OnDragUpdated( | 414 int BrowserActionsContainer::OnDragUpdated( |
| 449 const ui::DropTargetEvent& event) { | 415 const ui::DropTargetEvent& event) { |
| 450 // First check if we are above the chevron (overflow) menu. | |
| 451 if (chevron_ && GetEventHandlerForPoint(event.location()) == chevron_) { | |
| 452 if (!show_menu_task_factory_.HasWeakPtrs() && !overflow_menu_) | |
| 453 StartShowFolderDropMenuTimer(); | |
| 454 return ui::DragDropTypes::DRAG_MOVE; | |
| 455 } | |
| 456 StopShowFolderDropMenuTimer(); | |
| 457 | |
| 458 size_t row_index = 0; | 416 size_t row_index = 0; |
| 459 size_t before_icon_in_row = 0; | 417 size_t before_icon_in_row = 0; |
| 460 // If there are no visible browser actions (such as when dragging an icon to | 418 // If there are no visible browser actions (such as when dragging an icon to |
| 461 // an empty overflow/main container), then 0, 0 for row, column is correct. | 419 // an empty overflow/main container), then 0, 0 for row, column is correct. |
| 462 if (VisibleBrowserActions() != 0) { | 420 if (VisibleBrowserActions() != 0) { |
| 463 // Figure out where to display the indicator. This is a complex calculation: | 421 // Figure out where to display the indicator. This is a complex calculation: |
| 464 | 422 |
| 465 // First, we subtract out the padding to the left of the icon area, which is | 423 // First, we subtract out the padding to the left of the icon area, which is |
| 466 // ToolbarView::kStandardSpacing. If we're right-to-left, we also mirror the | 424 // ToolbarView::kStandardSpacing. If we're right-to-left, we also mirror the |
| 467 // event.x() so that our calculations are consistent with left-to-right. | 425 // event.x() so that our calculations are consistent with left-to-right. |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 527 !(drop_position_->row == row_index && | 485 !(drop_position_->row == row_index && |
| 528 drop_position_->icon_in_row == before_icon_in_row)) { | 486 drop_position_->icon_in_row == before_icon_in_row)) { |
| 529 drop_position_.reset(new DropPosition(row_index, before_icon_in_row)); | 487 drop_position_.reset(new DropPosition(row_index, before_icon_in_row)); |
| 530 SchedulePaint(); | 488 SchedulePaint(); |
| 531 } | 489 } |
| 532 | 490 |
| 533 return ui::DragDropTypes::DRAG_MOVE; | 491 return ui::DragDropTypes::DRAG_MOVE; |
| 534 } | 492 } |
| 535 | 493 |
| 536 void BrowserActionsContainer::OnDragExited() { | 494 void BrowserActionsContainer::OnDragExited() { |
| 537 StopShowFolderDropMenuTimer(); | |
| 538 drop_position_.reset(); | 495 drop_position_.reset(); |
| 539 SchedulePaint(); | 496 SchedulePaint(); |
| 540 } | 497 } |
| 541 | 498 |
| 542 int BrowserActionsContainer::OnPerformDrop( | 499 int BrowserActionsContainer::OnPerformDrop( |
| 543 const ui::DropTargetEvent& event) { | 500 const ui::DropTargetEvent& event) { |
| 544 BrowserActionDragData data; | 501 BrowserActionDragData data; |
| 545 if (!data.Read(event.data())) | 502 if (!data.Read(event.data())) |
| 546 return ui::DragDropTypes::DRAG_NONE; | 503 return ui::DragDropTypes::DRAG_NONE; |
| 547 | 504 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 589 OnDragExited(); // Perform clean up after dragging. | 546 OnDragExited(); // Perform clean up after dragging. |
| 590 return ui::DragDropTypes::DRAG_MOVE; | 547 return ui::DragDropTypes::DRAG_MOVE; |
| 591 } | 548 } |
| 592 | 549 |
| 593 void BrowserActionsContainer::GetAccessibleState( | 550 void BrowserActionsContainer::GetAccessibleState( |
| 594 ui::AXViewState* state) { | 551 ui::AXViewState* state) { |
| 595 state->role = ui::AX_ROLE_GROUP; | 552 state->role = ui::AX_ROLE_GROUP; |
| 596 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_EXTENSIONS); | 553 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_EXTENSIONS); |
| 597 } | 554 } |
| 598 | 555 |
| 599 void BrowserActionsContainer::OnMenuButtonClicked(views::View* source, | |
| 600 const gfx::Point& point) { | |
| 601 if (source == chevron_) { | |
| 602 overflow_menu_ = | |
| 603 new BrowserActionOverflowMenuController(this, | |
| 604 browser_, | |
| 605 chevron_, | |
| 606 browser_action_views_, | |
| 607 VisibleBrowserActions(), | |
| 608 false); | |
| 609 overflow_menu_->set_observer(this); | |
| 610 overflow_menu_->RunMenu(GetWidget()); | |
| 611 } | |
| 612 } | |
| 613 | |
| 614 void BrowserActionsContainer::WriteDragDataForView(View* sender, | 556 void BrowserActionsContainer::WriteDragDataForView(View* sender, |
| 615 const gfx::Point& press_pt, | 557 const gfx::Point& press_pt, |
| 616 OSExchangeData* data) { | 558 OSExchangeData* data) { |
| 617 DCHECK(data); | 559 DCHECK(data); |
| 618 | 560 |
| 619 for (size_t i = 0; i < browser_action_views_.size(); ++i) { | 561 for (size_t i = 0; i < browser_action_views_.size(); ++i) { |
| 620 BrowserActionView* view = browser_action_views_[i]; | 562 BrowserActionView* view = browser_action_views_[i]; |
| 621 if (view == sender) { | 563 if (view == sender) { |
| 622 // Set the dragging image for the icon. | 564 // Set the dragging image for the icon. |
| 623 gfx::ImageSkia badge(view->GetIconWithBadge()); | 565 gfx::ImageSkia badge(view->GetIconWithBadge()); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 685 resize_amount_ = 0; | 627 resize_amount_ = 0; |
| 686 suppress_chevron_ = false; | 628 suppress_chevron_ = false; |
| 687 SetChevronVisibility(); | 629 SetChevronVisibility(); |
| 688 OnBrowserActionVisibilityChanged(); | 630 OnBrowserActionVisibilityChanged(); |
| 689 | 631 |
| 690 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, | 632 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, |
| 691 observers_, | 633 observers_, |
| 692 OnBrowserActionsContainerAnimationEnded()); | 634 OnBrowserActionsContainerAnimationEnded()); |
| 693 } | 635 } |
| 694 | 636 |
| 695 void BrowserActionsContainer::NotifyMenuDeleted( | |
| 696 BrowserActionOverflowMenuController* controller) { | |
| 697 DCHECK_EQ(overflow_menu_, controller); | |
| 698 overflow_menu_ = NULL; | |
| 699 } | |
| 700 | |
| 701 content::WebContents* BrowserActionsContainer::GetCurrentWebContents() { | 637 content::WebContents* BrowserActionsContainer::GetCurrentWebContents() { |
| 702 return browser_->tab_strip_model()->GetActiveWebContents(); | 638 return browser_->tab_strip_model()->GetActiveWebContents(); |
| 703 } | 639 } |
| 704 | 640 |
| 705 extensions::ActiveTabPermissionGranter* | 641 extensions::ActiveTabPermissionGranter* |
| 706 BrowserActionsContainer::GetActiveTabPermissionGranter() { | 642 BrowserActionsContainer::GetActiveTabPermissionGranter() { |
| 707 content::WebContents* web_contents = | 643 content::WebContents* web_contents = |
| 708 browser_->tab_strip_model()->GetActiveWebContents(); | 644 browser_->tab_strip_model()->GetActiveWebContents(); |
| 709 if (!web_contents) | 645 if (!web_contents) |
| 710 return NULL; | 646 return NULL; |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 812 | 748 |
| 813 void BrowserActionsContainer::ToolbarExtensionAdded(const Extension* extension, | 749 void BrowserActionsContainer::ToolbarExtensionAdded(const Extension* extension, |
| 814 int index) { | 750 int index) { |
| 815 #if defined(DEBUG) | 751 #if defined(DEBUG) |
| 816 for (size_t i = 0; i < browser_action_views_.size(); ++i) { | 752 for (size_t i = 0; i < browser_action_views_.size(); ++i) { |
| 817 DCHECK(browser_action_views_[i]->extension() != extension) << | 753 DCHECK(browser_action_views_[i]->extension() != extension) << |
| 818 "Asked to add a browser action view for an extension that already " | 754 "Asked to add a browser action view for an extension that already " |
| 819 "exists."; | 755 "exists."; |
| 820 } | 756 } |
| 821 #endif | 757 #endif |
| 822 CloseOverflowMenu(); | 758 if (chevron_) |
| 759 chevron_->CloseMenu(); | |
| 823 | 760 |
| 824 if (!ShouldDisplayBrowserAction(extension)) | 761 if (!ShouldDisplayBrowserAction(extension)) |
| 825 return; | 762 return; |
| 826 | 763 |
| 827 // Add the new browser action to the vector and the view hierarchy. | 764 // Add the new browser action to the vector and the view hierarchy. |
| 828 if (profile_->IsOffTheRecord()) | 765 if (profile_->IsOffTheRecord()) |
| 829 index = model_->OriginalIndexToIncognito(index); | 766 index = model_->OriginalIndexToIncognito(index); |
| 830 BrowserActionView* view = | 767 BrowserActionView* view = |
| 831 new BrowserActionView(extension, | 768 new BrowserActionView(extension, |
| 832 extensions::ExtensionActionManager::Get(profile_)-> | 769 extensions::ExtensionActionManager::Get(profile_)-> |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 859 } | 796 } |
| 860 } | 797 } |
| 861 | 798 |
| 862 // Otherwise, we don't have to resize, so just redraw the (possibly modified) | 799 // Otherwise, we don't have to resize, so just redraw the (possibly modified) |
| 863 // visible icon set. | 800 // visible icon set. |
| 864 OnBrowserActionVisibilityChanged(); | 801 OnBrowserActionVisibilityChanged(); |
| 865 } | 802 } |
| 866 | 803 |
| 867 void BrowserActionsContainer::ToolbarExtensionRemoved( | 804 void BrowserActionsContainer::ToolbarExtensionRemoved( |
| 868 const Extension* extension) { | 805 const Extension* extension) { |
| 869 CloseOverflowMenu(); | 806 if (chevron_) |
| 807 chevron_->CloseMenu(); | |
| 870 | 808 |
| 871 size_t visible_actions = VisibleBrowserActionsAfterAnimation(); | 809 size_t visible_actions = VisibleBrowserActionsAfterAnimation(); |
| 872 for (BrowserActionViews::iterator i(browser_action_views_.begin()); | 810 for (BrowserActionViews::iterator i(browser_action_views_.begin()); |
| 873 i != browser_action_views_.end(); ++i) { | 811 i != browser_action_views_.end(); ++i) { |
| 874 if ((*i)->extension() == extension) { | 812 if ((*i)->extension() == extension) { |
| 875 delete *i; | 813 delete *i; |
| 876 browser_action_views_.erase(i); | 814 browser_action_views_.erase(i); |
| 877 | 815 |
| 878 // If the extension is being upgraded we don't want the bar to shrink | 816 // If the extension is being upgraded we don't want the bar to shrink |
| 879 // because the icon is just going to get re-added to the same location. | 817 // because the icon is just going to get re-added to the same location. |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1001 chevron_ && visible_actions < browser_action_views_.size()); | 939 chevron_ && visible_actions < browser_action_views_.size()); |
| 1002 } | 940 } |
| 1003 | 941 |
| 1004 void BrowserActionsContainer::SetChevronVisibility() { | 942 void BrowserActionsContainer::SetChevronVisibility() { |
| 1005 if (chevron_) { | 943 if (chevron_) { |
| 1006 chevron_->SetVisible( | 944 chevron_->SetVisible( |
| 1007 VisibleBrowserActionsAfterAnimation() < browser_action_views_.size()); | 945 VisibleBrowserActionsAfterAnimation() < browser_action_views_.size()); |
| 1008 } | 946 } |
| 1009 } | 947 } |
| 1010 | 948 |
| 1011 void BrowserActionsContainer::CloseOverflowMenu() { | |
| 1012 if (overflow_menu_) | |
| 1013 overflow_menu_->CancelMenu(); | |
| 1014 } | |
| 1015 | |
| 1016 void BrowserActionsContainer::StopShowFolderDropMenuTimer() { | |
| 1017 show_menu_task_factory_.InvalidateWeakPtrs(); | |
| 1018 } | |
| 1019 | |
| 1020 void BrowserActionsContainer::StartShowFolderDropMenuTimer() { | |
| 1021 base::MessageLoop::current()->PostDelayedTask( | |
| 1022 FROM_HERE, | |
| 1023 base::Bind(&BrowserActionsContainer::ShowDropFolder, | |
| 1024 show_menu_task_factory_.GetWeakPtr()), | |
| 1025 base::TimeDelta::FromMilliseconds(views::GetMenuShowDelay())); | |
| 1026 } | |
| 1027 | |
| 1028 void BrowserActionsContainer::ShowDropFolder() { | |
| 1029 DCHECK(!overflow_menu_); | |
| 1030 overflow_menu_ = | |
| 1031 new BrowserActionOverflowMenuController(this, | |
| 1032 browser_, | |
| 1033 chevron_, | |
| 1034 browser_action_views_, | |
| 1035 VisibleBrowserActions(), | |
| 1036 true); | |
| 1037 overflow_menu_->set_observer(this); | |
| 1038 overflow_menu_->RunMenu(GetWidget()); | |
| 1039 } | |
| 1040 | |
| 1041 int BrowserActionsContainer::IconCountToWidth(int icons, | 949 int BrowserActionsContainer::IconCountToWidth(int icons, |
| 1042 bool display_chevron) const { | 950 bool display_chevron) const { |
| 1043 if (icons < 0) | 951 if (icons < 0) |
| 1044 icons = browser_action_views_.size(); | 952 icons = browser_action_views_.size(); |
| 1045 if ((icons == 0) && !display_chevron) | 953 if ((icons == 0) && !display_chevron) |
| 1046 return ToolbarView::kStandardSpacing; | 954 return ToolbarView::kStandardSpacing; |
| 1047 int icons_size = | 955 int icons_size = |
| 1048 (icons == 0) ? 0 : ((icons * IconWidth(true)) - kItemSpacing); | 956 (icons == 0) ? 0 : ((icons * IconWidth(true)) - kItemSpacing); |
| 1049 int chevron_size = chevron_ && display_chevron ? | 957 int chevron_size = chevron_ && display_chevron ? |
| 1050 (kChevronSpacing + chevron_->GetPreferredSize().width()) : 0; | 958 (kChevronSpacing + chevron_->GetPreferredSize().width()) : 0; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1136 if (initialized_ && profile_->IsOffTheRecord()) { | 1044 if (initialized_ && profile_->IsOffTheRecord()) { |
| 1137 main_displayed = in_overflow_mode() ? | 1045 main_displayed = in_overflow_mode() ? |
| 1138 main_container_->VisibleBrowserActionsAfterAnimation() : | 1046 main_container_->VisibleBrowserActionsAfterAnimation() : |
| 1139 VisibleBrowserActionsAfterAnimation(); | 1047 VisibleBrowserActionsAfterAnimation(); |
| 1140 } | 1048 } |
| 1141 | 1049 |
| 1142 // The overflow displays any (displayable) icons not shown by the main bar. | 1050 // The overflow displays any (displayable) icons not shown by the main bar. |
| 1143 return in_overflow_mode() ? | 1051 return in_overflow_mode() ? |
| 1144 displayable_icon_count - main_displayed : main_displayed; | 1052 displayable_icon_count - main_displayed : main_displayed; |
| 1145 } | 1053 } |
| OLD | NEW |