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 chevron_.reset(new ChevronMenuButton(this)); |
| 128 chevron_->set_owned_by_client(); | |
|
Peter Kasting
2014/09/25 01:06:43
Why do we want to own this ourselves instead of le
Devlin
2014/09/25 15:56:49
ChevronMenuButton takes (and uses) a raw pointer t
Peter Kasting
2014/09/25 19:06:18
Hmm. I see what you mean.
I think I probably pre
Devlin
2014/09/25 20:04:09
Done.
| |
| 160 chevron_->EnableCanvasFlippingForRTLUI(true); | 129 chevron_->EnableCanvasFlippingForRTLUI(true); |
| 161 chevron_->SetAccessibleName( | 130 chevron_->SetAccessibleName( |
| 162 l10n_util::GetStringUTF16(IDS_ACCNAME_EXTENSIONS_CHEVRON)); | 131 l10n_util::GetStringUTF16(IDS_ACCNAME_EXTENSIONS_CHEVRON)); |
| 163 chevron_->SetVisible(false); | 132 chevron_->SetVisible(false); |
| 164 AddChildView(chevron_); | 133 AddChildView(chevron_.get()); |
| 165 } | 134 } |
| 166 } | 135 } |
| 167 } | 136 } |
| 168 | 137 |
| 169 BrowserActionsContainer::~BrowserActionsContainer() { | 138 BrowserActionsContainer::~BrowserActionsContainer() { |
| 170 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, | 139 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, |
| 171 observers_, | 140 observers_, |
| 172 OnBrowserActionsContainerDestroyed()); | 141 OnBrowserActionsContainerDestroyed()); |
| 173 | 142 |
| 174 if (overflow_menu_) | |
| 175 overflow_menu_->set_observer(NULL); | |
| 176 if (model_) | 143 if (model_) |
| 177 model_->RemoveObserver(this); | 144 model_->RemoveObserver(this); |
| 178 StopShowFolderDropMenuTimer(); | |
| 179 HideActivePopup(); | 145 HideActivePopup(); |
| 180 DeleteBrowserActionViews(); | 146 DeleteBrowserActionViews(); |
| 181 } | 147 } |
| 182 | 148 |
| 183 void BrowserActionsContainer::Init() { | 149 void BrowserActionsContainer::Init() { |
| 184 LoadImages(); | 150 LoadImages(); |
| 185 | 151 |
| 186 // We wait to set the container width until now so that the chevron images | 152 // 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. | 153 // will be loaded. The width calculation needs to know the chevron size. |
| 188 if (model_ && model_->extensions_initialized()) { | 154 if (model_ && model_->extensions_initialized()) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 226 action_manager->GetExtensionAction(**i), | 192 action_manager->GetExtensionAction(**i), |
| 227 browser_, | 193 browser_, |
| 228 this); | 194 this); |
| 229 browser_action_views_.push_back(view); | 195 browser_action_views_.push_back(view); |
| 230 AddChildView(view); | 196 AddChildView(view); |
| 231 } | 197 } |
| 232 } | 198 } |
| 233 | 199 |
| 234 void BrowserActionsContainer::DeleteBrowserActionViews() { | 200 void BrowserActionsContainer::DeleteBrowserActionViews() { |
| 235 HideActivePopup(); | 201 HideActivePopup(); |
| 236 if (overflow_menu_) | |
| 237 overflow_menu_->NotifyBrowserActionViewsDeleting(); | |
| 238 STLDeleteElements(&browser_action_views_); | 202 STLDeleteElements(&browser_action_views_); |
| 239 } | 203 } |
| 240 | 204 |
| 241 size_t BrowserActionsContainer::VisibleBrowserActions() const { | 205 size_t BrowserActionsContainer::VisibleBrowserActions() const { |
| 242 size_t visible_actions = 0; | 206 size_t visible_actions = 0; |
| 243 for (size_t i = 0; i < browser_action_views_.size(); ++i) { | 207 for (size_t i = 0; i < browser_action_views_.size(); ++i) { |
| 244 if (browser_action_views_[i]->visible()) | 208 if (browser_action_views_[i]->visible()) |
| 245 ++visible_actions; | 209 ++visible_actions; |
| 246 } | 210 } |
| 247 return visible_actions; | 211 return visible_actions; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 287 void BrowserActionsContainer::OnBrowserActionViewDragDone() { | 251 void BrowserActionsContainer::OnBrowserActionViewDragDone() { |
| 288 ToolbarVisibleCountChanged(); | 252 ToolbarVisibleCountChanged(); |
| 289 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, | 253 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, |
| 290 observers_, | 254 observers_, |
| 291 OnBrowserActionDragDone()); | 255 OnBrowserActionDragDone()); |
| 292 } | 256 } |
| 293 | 257 |
| 294 views::MenuButton* BrowserActionsContainer::GetOverflowReferenceView() { | 258 views::MenuButton* BrowserActionsContainer::GetOverflowReferenceView() { |
| 295 // With traditional overflow, the reference is the chevron. With the | 259 // With traditional overflow, the reference is the chevron. With the |
| 296 // redesign, we use the wrench menu instead. | 260 // redesign, we use the wrench menu instead. |
| 297 return chevron_ ? | 261 return chevron_.get() ? |
|
Peter Kasting
2014/09/25 01:06:43
Nit: Don't use get() when using a scoped_ptr<> as
Devlin
2014/09/25 15:56:49
For some reason, I thought we were getting rid of
Peter Kasting
2014/09/25 19:06:18
We're getting rid of implicit conversion of scoped
| |
| 298 chevron_ : | 262 chevron_.get() : |
| 299 BrowserView::GetBrowserViewForBrowser(browser_)->toolbar()->app_menu(); | 263 BrowserView::GetBrowserViewForBrowser(browser_)->toolbar()->app_menu(); |
| 300 } | 264 } |
| 301 | 265 |
| 302 void BrowserActionsContainer::SetPopupOwner(BrowserActionView* popup_owner) { | 266 void BrowserActionsContainer::SetPopupOwner(BrowserActionView* popup_owner) { |
| 303 // We should never be setting a popup owner when one already exists, and | 267 // We should never be setting a popup owner when one already exists, and |
| 304 // never unsetting one when one wasn't set. | 268 // never unsetting one when one wasn't set. |
| 305 DCHECK((!popup_owner_ && popup_owner) || | 269 DCHECK((!popup_owner_ && popup_owner) || |
| 306 (popup_owner_ && !popup_owner)); | 270 (popup_owner_ && !popup_owner)); |
| 307 popup_owner_ = popup_owner; | 271 popup_owner_ = popup_owner; |
| 308 } | 272 } |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 375 SetVisible(false); | 339 SetVisible(false); |
| 376 return; | 340 return; |
| 377 } | 341 } |
| 378 | 342 |
| 379 SetVisible(true); | 343 SetVisible(true); |
| 380 if (resize_area_) | 344 if (resize_area_) |
| 381 resize_area_->SetBounds(0, 0, kItemSpacing, height()); | 345 resize_area_->SetBounds(0, 0, kItemSpacing, height()); |
| 382 | 346 |
| 383 // If the icons don't all fit, show the chevron (unless suppressed). | 347 // If the icons don't all fit, show the chevron (unless suppressed). |
| 384 int max_x = GetPreferredSize().width(); | 348 int max_x = GetPreferredSize().width(); |
| 385 if ((IconCountToWidth(-1, false) > max_x) && !suppress_chevron_ && chevron_) { | 349 if (IconCountToWidth(-1, false) > max_x && |
| 350 !suppress_chevron_ && | |
| 351 chevron_.get()) { | |
| 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_.get()) { |
| 396 chevron_->SetVisible(false); | 362 chevron_->SetVisible(false); |
| 397 } | 363 } |
| 398 | 364 |
| 399 // Now draw the icons for the browser actions in the available space. | 365 // Now draw the icons for the browser actions in the available space. |
| 400 int icon_width = IconWidth(false); | 366 int icon_width = IconWidth(false); |
| 401 if (in_overflow_mode()) { | 367 if (in_overflow_mode()) { |
| 402 for (size_t i = 0; | 368 for (size_t i = 0; |
| 403 i < main_container_->VisibleBrowserActionsAfterAnimation(); ++i) { | 369 i < main_container_->VisibleBrowserActionsAfterAnimation(); ++i) { |
| 404 // Ensure that any browser actions shown in the main view are hidden in | 370 // Ensure that any browser actions shown in the main view are hidden in |
| 405 // the overflow view. | 371 // the overflow view. |
| (...skipping 34 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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, | 556 void BrowserActionsContainer::OnMenuButtonClicked(views::View* source, |
| 600 const gfx::Point& point) { | 557 const gfx::Point& point) { |
| 601 if (source == chevron_) { | 558 DCHECK(false); |
|
Peter Kasting
2014/09/25 01:06:43
Why are we even overriding this method, then?
Devlin
2014/09/25 15:56:49
Whoops! Missed that one in the cleanup (had it as
| |
| 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 } | 559 } |
| 613 | 560 |
| 614 void BrowserActionsContainer::WriteDragDataForView(View* sender, | 561 void BrowserActionsContainer::WriteDragDataForView(View* sender, |
| 615 const gfx::Point& press_pt, | 562 const gfx::Point& press_pt, |
| 616 OSExchangeData* data) { | 563 OSExchangeData* data) { |
| 617 DCHECK(data); | 564 DCHECK(data); |
| 618 | 565 |
| 619 for (size_t i = 0; i < browser_action_views_.size(); ++i) { | 566 for (size_t i = 0; i < browser_action_views_.size(); ++i) { |
| 620 BrowserActionView* view = browser_action_views_[i]; | 567 BrowserActionView* view = browser_action_views_[i]; |
| 621 if (view == sender) { | 568 if (view == sender) { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 685 resize_amount_ = 0; | 632 resize_amount_ = 0; |
| 686 suppress_chevron_ = false; | 633 suppress_chevron_ = false; |
| 687 SetChevronVisibility(); | 634 SetChevronVisibility(); |
| 688 OnBrowserActionVisibilityChanged(); | 635 OnBrowserActionVisibilityChanged(); |
| 689 | 636 |
| 690 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, | 637 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, |
| 691 observers_, | 638 observers_, |
| 692 OnBrowserActionsContainerAnimationEnded()); | 639 OnBrowserActionsContainerAnimationEnded()); |
| 693 } | 640 } |
| 694 | 641 |
| 695 void BrowserActionsContainer::NotifyMenuDeleted( | |
| 696 BrowserActionOverflowMenuController* controller) { | |
| 697 DCHECK_EQ(overflow_menu_, controller); | |
| 698 overflow_menu_ = NULL; | |
| 699 } | |
| 700 | |
| 701 content::WebContents* BrowserActionsContainer::GetCurrentWebContents() { | 642 content::WebContents* BrowserActionsContainer::GetCurrentWebContents() { |
| 702 return browser_->tab_strip_model()->GetActiveWebContents(); | 643 return browser_->tab_strip_model()->GetActiveWebContents(); |
| 703 } | 644 } |
| 704 | 645 |
| 705 extensions::ActiveTabPermissionGranter* | 646 extensions::ActiveTabPermissionGranter* |
| 706 BrowserActionsContainer::GetActiveTabPermissionGranter() { | 647 BrowserActionsContainer::GetActiveTabPermissionGranter() { |
| 707 content::WebContents* web_contents = | 648 content::WebContents* web_contents = |
| 708 browser_->tab_strip_model()->GetActiveWebContents(); | 649 browser_->tab_strip_model()->GetActiveWebContents(); |
| 709 if (!web_contents) | 650 if (!web_contents) |
| 710 return NULL; | 651 return NULL; |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 812 | 753 |
| 813 void BrowserActionsContainer::ToolbarExtensionAdded(const Extension* extension, | 754 void BrowserActionsContainer::ToolbarExtensionAdded(const Extension* extension, |
| 814 int index) { | 755 int index) { |
| 815 #if defined(DEBUG) | 756 #if defined(DEBUG) |
| 816 for (size_t i = 0; i < browser_action_views_.size(); ++i) { | 757 for (size_t i = 0; i < browser_action_views_.size(); ++i) { |
| 817 DCHECK(browser_action_views_[i]->extension() != extension) << | 758 DCHECK(browser_action_views_[i]->extension() != extension) << |
| 818 "Asked to add a browser action view for an extension that already " | 759 "Asked to add a browser action view for an extension that already " |
| 819 "exists."; | 760 "exists."; |
| 820 } | 761 } |
| 821 #endif | 762 #endif |
| 822 CloseOverflowMenu(); | 763 if (chevron_.get()) |
| 764 chevron_->CloseMenu(); | |
| 823 | 765 |
| 824 if (!ShouldDisplayBrowserAction(extension)) | 766 if (!ShouldDisplayBrowserAction(extension)) |
| 825 return; | 767 return; |
| 826 | 768 |
| 827 // Add the new browser action to the vector and the view hierarchy. | 769 // Add the new browser action to the vector and the view hierarchy. |
| 828 if (profile_->IsOffTheRecord()) | 770 if (profile_->IsOffTheRecord()) |
| 829 index = model_->OriginalIndexToIncognito(index); | 771 index = model_->OriginalIndexToIncognito(index); |
| 830 BrowserActionView* view = | 772 BrowserActionView* view = |
| 831 new BrowserActionView(extension, | 773 new BrowserActionView(extension, |
| 832 extensions::ExtensionActionManager::Get(profile_)-> | 774 extensions::ExtensionActionManager::Get(profile_)-> |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 845 IsBeingUpgraded(extension)) { | 787 IsBeingUpgraded(extension)) { |
| 846 // We need to resize if either: | 788 // We need to resize if either: |
| 847 // - The container is set to display all icons (visible count = -1), or | 789 // - The container is set to display all icons (visible count = -1), or |
| 848 // - The container will need to expand to include the chevron. This can | 790 // - The container will need to expand to include the chevron. This can |
| 849 // happen when the container is set to display <n> icons, where <n> is | 791 // happen when the container is set to display <n> icons, where <n> is |
| 850 // the number of icons before the new icon. With the new icon, the chevron | 792 // the number of icons before the new icon. With the new icon, the chevron |
| 851 // will need to be displayed. | 793 // will need to be displayed. |
| 852 int model_icon_count = model_->GetVisibleIconCount(); | 794 int model_icon_count = model_->GetVisibleIconCount(); |
| 853 if (model_icon_count == -1 || | 795 if (model_icon_count == -1 || |
| 854 (static_cast<size_t>(model_icon_count) < browser_action_views_.size() && | 796 (static_cast<size_t>(model_icon_count) < browser_action_views_.size() && |
| 855 (chevron_ && !chevron_->visible()))) { | 797 (chevron_.get() && !chevron_->visible()))) { |
| 856 suppress_chevron_ = true; | 798 suppress_chevron_ = true; |
| 857 Animate(gfx::Tween::LINEAR, GetIconCount()); | 799 Animate(gfx::Tween::LINEAR, GetIconCount()); |
| 858 return; | 800 return; |
| 859 } | 801 } |
| 860 } | 802 } |
| 861 | 803 |
| 862 // Otherwise, we don't have to resize, so just redraw the (possibly modified) | 804 // Otherwise, we don't have to resize, so just redraw the (possibly modified) |
| 863 // visible icon set. | 805 // visible icon set. |
| 864 OnBrowserActionVisibilityChanged(); | 806 OnBrowserActionVisibilityChanged(); |
| 865 } | 807 } |
| 866 | 808 |
| 867 void BrowserActionsContainer::ToolbarExtensionRemoved( | 809 void BrowserActionsContainer::ToolbarExtensionRemoved( |
| 868 const Extension* extension) { | 810 const Extension* extension) { |
| 869 CloseOverflowMenu(); | 811 if (chevron_.get()) |
| 812 chevron_->CloseMenu(); | |
| 870 | 813 |
| 871 size_t visible_actions = VisibleBrowserActionsAfterAnimation(); | 814 size_t visible_actions = VisibleBrowserActionsAfterAnimation(); |
| 872 for (BrowserActionViews::iterator i(browser_action_views_.begin()); | 815 for (BrowserActionViews::iterator i(browser_action_views_.begin()); |
| 873 i != browser_action_views_.end(); ++i) { | 816 i != browser_action_views_.end(); ++i) { |
| 874 if ((*i)->extension() == extension) { | 817 if ((*i)->extension() == extension) { |
| 875 delete *i; | 818 delete *i; |
| 876 browser_action_views_.erase(i); | 819 browser_action_views_.erase(i); |
| 877 | 820 |
| 878 // If the extension is being upgraded we don't want the bar to shrink | 821 // 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. | 822 // because the icon is just going to get re-added to the same location. |
| 880 if (extensions::ExtensionSystem::Get(profile_)->runtime_data()-> | 823 if (extensions::ExtensionSystem::Get(profile_)->runtime_data()-> |
| 881 IsBeingUpgraded(extension)) | 824 IsBeingUpgraded(extension)) |
| 882 return; | 825 return; |
| 883 | 826 |
| 884 if (browser_action_views_.size() > visible_actions) { | 827 if (browser_action_views_.size() > visible_actions) { |
| 885 // If we have more icons than we can show, then we must not be changing | 828 // If we have more icons than we can show, then we must not be changing |
| 886 // the container size (since we either removed an icon from the main | 829 // the container size (since we either removed an icon from the main |
| 887 // area and one from the overflow list will have shifted in, or we | 830 // area and one from the overflow list will have shifted in, or we |
| 888 // removed an entry directly from the overflow list). | 831 // removed an entry directly from the overflow list). |
| 889 OnBrowserActionVisibilityChanged(); | 832 OnBrowserActionVisibilityChanged(); |
| 890 } else { | 833 } else { |
| 891 // Either we went from overflow to no-overflow, or we shrunk the no- | 834 // Either we went from overflow to no-overflow, or we shrunk the no- |
| 892 // overflow container by 1. Either way the size changed, so animate. | 835 // overflow container by 1. Either way the size changed, so animate. |
| 893 if (chevron_) | 836 if (chevron_.get()) |
| 894 chevron_->SetVisible(false); | 837 chevron_->SetVisible(false); |
| 895 Animate(gfx::Tween::EASE_OUT, browser_action_views_.size()); | 838 Animate(gfx::Tween::EASE_OUT, browser_action_views_.size()); |
| 896 } | 839 } |
| 897 return; // We have found the action to remove, bail out. | 840 return; // We have found the action to remove, bail out. |
| 898 } | 841 } |
| 899 } | 842 } |
| 900 } | 843 } |
| 901 | 844 |
| 902 void BrowserActionsContainer::ToolbarExtensionMoved(const Extension* extension, | 845 void BrowserActionsContainer::ToolbarExtensionMoved(const Extension* extension, |
| 903 int index) { | 846 int index) { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 964 CreateBrowserActionViews(); | 907 CreateBrowserActionViews(); |
| 965 Animate(gfx::Tween::LINEAR, GetIconCount()); | 908 Animate(gfx::Tween::LINEAR, GetIconCount()); |
| 966 } | 909 } |
| 967 | 910 |
| 968 Browser* BrowserActionsContainer::GetBrowser() { | 911 Browser* BrowserActionsContainer::GetBrowser() { |
| 969 return browser_; | 912 return browser_; |
| 970 } | 913 } |
| 971 | 914 |
| 972 void BrowserActionsContainer::LoadImages() { | 915 void BrowserActionsContainer::LoadImages() { |
| 973 ui::ThemeProvider* tp = GetThemeProvider(); | 916 ui::ThemeProvider* tp = GetThemeProvider(); |
| 974 if (!tp || !chevron_) | 917 if (!tp || !chevron_.get()) |
| 975 return; | 918 return; |
| 976 | 919 |
| 977 chevron_->SetImage(views::Button::STATE_NORMAL, | 920 chevron_->SetImage(views::Button::STATE_NORMAL, |
| 978 *tp->GetImageSkiaNamed(IDR_BROWSER_ACTIONS_OVERFLOW)); | 921 *tp->GetImageSkiaNamed(IDR_BROWSER_ACTIONS_OVERFLOW)); |
| 979 | 922 |
| 980 const int kImages[] = IMAGE_GRID(IDR_DEVELOPER_MODE_HIGHLIGHT); | 923 const int kImages[] = IMAGE_GRID(IDR_DEVELOPER_MODE_HIGHLIGHT); |
| 981 highlight_painter_.reset(views::Painter::CreateImageGridPainter(kImages)); | 924 highlight_painter_.reset(views::Painter::CreateImageGridPainter(kImages)); |
| 982 } | 925 } |
| 983 | 926 |
| 984 void BrowserActionsContainer::OnBrowserActionVisibilityChanged() { | 927 void BrowserActionsContainer::OnBrowserActionVisibilityChanged() { |
| 985 SetVisible(!browser_action_views_.empty()); | 928 SetVisible(!browser_action_views_.empty()); |
| 986 if (owner_view_) { | 929 if (owner_view_) { |
| 987 owner_view_->Layout(); | 930 owner_view_->Layout(); |
| 988 owner_view_->SchedulePaint(); | 931 owner_view_->SchedulePaint(); |
| 989 } else { | 932 } else { |
| 990 // In overflow mode, we don't have an owner view, but we still have to | 933 // In overflow mode, we don't have an owner view, but we still have to |
| 991 // update ourselves. | 934 // update ourselves. |
| 992 Layout(); | 935 Layout(); |
| 993 SchedulePaint(); | 936 SchedulePaint(); |
| 994 } | 937 } |
| 995 } | 938 } |
| 996 | 939 |
| 997 int BrowserActionsContainer::GetPreferredWidth() { | 940 int BrowserActionsContainer::GetPreferredWidth() { |
| 998 size_t visible_actions = GetIconCount(); | 941 size_t visible_actions = GetIconCount(); |
| 999 return IconCountToWidth( | 942 return IconCountToWidth( |
| 1000 visible_actions, | 943 visible_actions, |
| 1001 chevron_ && visible_actions < browser_action_views_.size()); | 944 chevron_.get() && visible_actions < browser_action_views_.size()); |
| 1002 } | 945 } |
| 1003 | 946 |
| 1004 void BrowserActionsContainer::SetChevronVisibility() { | 947 void BrowserActionsContainer::SetChevronVisibility() { |
| 1005 if (chevron_) { | 948 if (chevron_.get()) { |
| 1006 chevron_->SetVisible( | 949 chevron_->SetVisible( |
| 1007 VisibleBrowserActionsAfterAnimation() < browser_action_views_.size()); | 950 VisibleBrowserActionsAfterAnimation() < browser_action_views_.size()); |
| 1008 } | 951 } |
| 1009 } | 952 } |
| 1010 | 953 |
| 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, | 954 int BrowserActionsContainer::IconCountToWidth(int icons, |
| 1042 bool display_chevron) const { | 955 bool display_chevron) const { |
| 1043 if (icons < 0) | 956 if (icons < 0) |
| 1044 icons = browser_action_views_.size(); | 957 icons = browser_action_views_.size(); |
| 1045 if ((icons == 0) && !display_chevron) | 958 if ((icons == 0) && !display_chevron) |
| 1046 return ToolbarView::kStandardSpacing; | 959 return ToolbarView::kStandardSpacing; |
| 1047 int icons_size = | 960 int icons_size = |
| 1048 (icons == 0) ? 0 : ((icons * IconWidth(true)) - kItemSpacing); | 961 (icons == 0) ? 0 : ((icons * IconWidth(true)) - kItemSpacing); |
| 1049 int chevron_size = chevron_ && display_chevron ? | 962 int chevron_size = chevron_.get() && display_chevron ? |
| 1050 (kChevronSpacing + chevron_->GetPreferredSize().width()) : 0; | 963 (kChevronSpacing + chevron_->GetPreferredSize().width()) : 0; |
| 1051 // In overflow mode, our padding is to use item spacing on either end (just so | 964 // In overflow mode, our padding is to use item spacing on either end (just so |
| 1052 // we can see the drop indicator). Otherwise we use the standard toolbar | 965 // we can see the drop indicator). Otherwise we use the standard toolbar |
| 1053 // spacing. | 966 // spacing. |
| 1054 // Note: These are actually the same thing, but, on the offchance one | 967 // Note: These are actually the same thing, but, on the offchance one |
| 1055 // changes, let's get it right. | 968 // changes, let's get it right. |
| 1056 int padding = | 969 int padding = |
| 1057 2 * (in_overflow_mode() ? kItemSpacing : ToolbarView::kStandardSpacing); | 970 2 * (in_overflow_mode() ? kItemSpacing : ToolbarView::kStandardSpacing); |
| 1058 return icons_size + chevron_size + padding; | 971 return icons_size + chevron_size + padding; |
| 1059 } | 972 } |
| 1060 | 973 |
| 1061 size_t BrowserActionsContainer::WidthToIconCount(int pixels) const { | 974 size_t BrowserActionsContainer::WidthToIconCount(int pixels) const { |
| 1062 // Check for widths large enough to show the entire icon set. | 975 // Check for widths large enough to show the entire icon set. |
| 1063 if (pixels >= IconCountToWidth(-1, false)) | 976 if (pixels >= IconCountToWidth(-1, false)) |
| 1064 return browser_action_views_.size(); | 977 return browser_action_views_.size(); |
| 1065 | 978 |
| 1066 // We reserve space for the padding on either side of the toolbar... | 979 // We reserve space for the padding on either side of the toolbar... |
| 1067 int available_space = pixels - (ToolbarView::kStandardSpacing * 2); | 980 int available_space = pixels - (ToolbarView::kStandardSpacing * 2); |
| 1068 // ... and, if the chevron is enabled, the chevron. | 981 // ... and, if the chevron is enabled, the chevron. |
| 1069 if (chevron_) | 982 if (chevron_.get()) |
| 1070 available_space -= (chevron_->GetPreferredSize().width() + kChevronSpacing); | 983 available_space -= (chevron_->GetPreferredSize().width() + kChevronSpacing); |
| 1071 | 984 |
| 1072 // Now we add an extra between-item padding value so the space can be divided | 985 // Now we add an extra between-item padding value so the space can be divided |
| 1073 // evenly by (size of icon with padding). | 986 // evenly by (size of icon with padding). |
| 1074 return static_cast<size_t>( | 987 return static_cast<size_t>( |
| 1075 std::max(0, available_space + kItemSpacing) / IconWidth(true)); | 988 std::max(0, available_space + kItemSpacing) / IconWidth(true)); |
| 1076 } | 989 } |
| 1077 | 990 |
| 1078 int BrowserActionsContainer::MinimumNonemptyWidth() const { | 991 int BrowserActionsContainer::MinimumNonemptyWidth() const { |
| 1079 if (!chevron_) | 992 if (!chevron_.get()) |
| 1080 return ToolbarView::kStandardSpacing; | 993 return ToolbarView::kStandardSpacing; |
| 1081 return (ToolbarView::kStandardSpacing * 2) + kChevronSpacing + | 994 return (ToolbarView::kStandardSpacing * 2) + kChevronSpacing + |
| 1082 chevron_->GetPreferredSize().width(); | 995 chevron_->GetPreferredSize().width(); |
| 1083 } | 996 } |
| 1084 | 997 |
| 1085 void BrowserActionsContainer::Animate(gfx::Tween::Type tween_type, | 998 void BrowserActionsContainer::Animate(gfx::Tween::Type tween_type, |
| 1086 size_t num_visible_icons) { | 999 size_t num_visible_icons) { |
| 1087 int target_size = IconCountToWidth(num_visible_icons, | 1000 int target_size = IconCountToWidth(num_visible_icons, |
| 1088 num_visible_icons < browser_action_views_.size()); | 1001 num_visible_icons < browser_action_views_.size()); |
| 1089 if (resize_animation_ && !disable_animations_during_testing_) { | 1002 if (resize_animation_ && !disable_animations_during_testing_) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1136 if (initialized_ && profile_->IsOffTheRecord()) { | 1049 if (initialized_ && profile_->IsOffTheRecord()) { |
| 1137 main_displayed = in_overflow_mode() ? | 1050 main_displayed = in_overflow_mode() ? |
| 1138 main_container_->VisibleBrowserActionsAfterAnimation() : | 1051 main_container_->VisibleBrowserActionsAfterAnimation() : |
| 1139 VisibleBrowserActionsAfterAnimation(); | 1052 VisibleBrowserActionsAfterAnimation(); |
| 1140 } | 1053 } |
| 1141 | 1054 |
| 1142 // The overflow displays any (displayable) icons not shown by the main bar. | 1055 // The overflow displays any (displayable) icons not shown by the main bar. |
| 1143 return in_overflow_mode() ? | 1056 return in_overflow_mode() ? |
| 1144 displayable_icon_count - main_displayed : main_displayed; | 1057 displayable_icon_count - main_displayed : main_displayed; |
| 1145 } | 1058 } |
| OLD | NEW |