| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 model_(ToolbarActionsModel::Get(browser_->profile())), | 117 model_(ToolbarActionsModel::Get(browser_->profile())), |
| 118 main_bar_(main_bar), | 118 main_bar_(main_bar), |
| 119 platform_settings_(), | 119 platform_settings_(), |
| 120 popup_owner_(nullptr), | 120 popup_owner_(nullptr), |
| 121 model_observer_(this), | 121 model_observer_(this), |
| 122 suppress_layout_(false), | 122 suppress_layout_(false), |
| 123 suppress_animation_(true), | 123 suppress_animation_(true), |
| 124 checked_extension_bubble_(false), | 124 checked_extension_bubble_(false), |
| 125 is_drag_in_progress_(false), | 125 is_drag_in_progress_(false), |
| 126 popped_out_action_(nullptr), | 126 popped_out_action_(nullptr), |
| 127 is_popped_out_sticky_(false), |
| 127 weak_ptr_factory_(this) { | 128 weak_ptr_factory_(this) { |
| 128 if (model_) // |model_| can be null in unittests. | 129 if (model_) // |model_| can be null in unittests. |
| 129 model_observer_.Add(model_); | 130 model_observer_.Add(model_); |
| 130 } | 131 } |
| 131 | 132 |
| 132 ToolbarActionsBar::~ToolbarActionsBar() { | 133 ToolbarActionsBar::~ToolbarActionsBar() { |
| 133 // We don't just call DeleteActions() here because it makes assumptions about | 134 // We don't just call DeleteActions() here because it makes assumptions about |
| 134 // the order of deletion between the views and the ToolbarActionsBar. | 135 // the order of deletion between the views and the ToolbarActionsBar. |
| 135 DCHECK(toolbar_actions_.empty()) << | 136 DCHECK(toolbar_actions_.empty()) << |
| 136 "Must call DeleteActions() before destruction."; | 137 "Must call DeleteActions() before destruction."; |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 // animations are small and fast enough that this doesn't cause problems). | 277 // animations are small and fast enough that this doesn't cause problems). |
| 277 return in_overflow_mode() | 278 return in_overflow_mode() |
| 278 ? toolbar_actions_.size() | 279 ? toolbar_actions_.size() |
| 279 : WidthToIconCount(delegate_->GetWidth( | 280 : WidthToIconCount(delegate_->GetWidth( |
| 280 ToolbarActionsBarDelegate::GET_WIDTH_AFTER_ANIMATION)); | 281 ToolbarActionsBarDelegate::GET_WIDTH_AFTER_ANIMATION)); |
| 281 } | 282 } |
| 282 | 283 |
| 283 bool ToolbarActionsBar::NeedsOverflow() const { | 284 bool ToolbarActionsBar::NeedsOverflow() const { |
| 284 DCHECK(!in_overflow_mode()); | 285 DCHECK(!in_overflow_mode()); |
| 285 // We need an overflow view if either the end index is less than the number of | 286 // We need an overflow view if either the end index is less than the number of |
| 286 // icons, or if a drag is in progress with the redesign turned on (since the | 287 // icons, if a drag is in progress with the redesign turned on (since the |
| 287 // user can drag an icon into the app menu). | 288 // user can drag an icon into the app menu), or if there is a non-sticky |
| 289 // popped out action (because the action will pop back into overflow when the |
| 290 // menu opens). |
| 288 return GetEndIndexInBounds() != toolbar_actions_.size() || | 291 return GetEndIndexInBounds() != toolbar_actions_.size() || |
| 289 (is_drag_in_progress_ && !platform_settings_.chevron_enabled); | 292 (is_drag_in_progress_ && !platform_settings_.chevron_enabled) || |
| 293 (popped_out_action_ && !is_popped_out_sticky_); |
| 290 } | 294 } |
| 291 | 295 |
| 292 gfx::Rect ToolbarActionsBar::GetFrameForIndex( | 296 gfx::Rect ToolbarActionsBar::GetFrameForIndex( |
| 293 size_t index) const { | 297 size_t index) const { |
| 294 size_t start_index = GetStartIndexInBounds(); | 298 size_t start_index = GetStartIndexInBounds(); |
| 295 | 299 |
| 296 // If the index is for an action that is before range we show (i.e., is for | 300 // If the index is for an action that is before range we show (i.e., is for |
| 297 // a button that's on the main bar, and this is the overflow), send back an | 301 // a button that's on the main bar, and this is the overflow), send back an |
| 298 // empty rect. | 302 // empty rect. |
| 299 if (index < start_index) | 303 if (index < start_index) |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 if (in_overflow_mode()) | 504 if (in_overflow_mode()) |
| 501 return main_bar_->IsActionVisibleOnMainBar(action); | 505 return main_bar_->IsActionVisibleOnMainBar(action); |
| 502 | 506 |
| 503 size_t index = std::find(toolbar_actions_.begin(), | 507 size_t index = std::find(toolbar_actions_.begin(), |
| 504 toolbar_actions_.end(), | 508 toolbar_actions_.end(), |
| 505 action) - toolbar_actions_.begin(); | 509 action) - toolbar_actions_.begin(); |
| 506 return index < GetIconCount() || action == popped_out_action_; | 510 return index < GetIconCount() || action == popped_out_action_; |
| 507 } | 511 } |
| 508 | 512 |
| 509 void ToolbarActionsBar::PopOutAction(ToolbarActionViewController* controller, | 513 void ToolbarActionsBar::PopOutAction(ToolbarActionViewController* controller, |
| 514 bool is_sticky, |
| 510 const base::Closure& closure) { | 515 const base::Closure& closure) { |
| 511 DCHECK(!in_overflow_mode()) << "Only the main bar can pop out actions."; | 516 DCHECK(!in_overflow_mode()) << "Only the main bar can pop out actions."; |
| 512 DCHECK(!popped_out_action_) << "Only one action can be popped out at a time!"; | 517 DCHECK(!popped_out_action_) << "Only one action can be popped out at a time!"; |
| 513 bool needs_redraw = !IsActionVisibleOnMainBar(controller); | 518 bool needs_redraw = !IsActionVisibleOnMainBar(controller); |
| 514 popped_out_action_ = controller; | 519 popped_out_action_ = controller; |
| 520 is_popped_out_sticky_ = is_sticky; |
| 515 if (needs_redraw) { | 521 if (needs_redraw) { |
| 516 // We suppress animation for this draw, because we need the action to get | 522 // We suppress animation for this draw, because we need the action to get |
| 517 // into position immediately, since it's about to show its popup. | 523 // into position immediately, since it's about to show its popup. |
| 518 base::AutoReset<bool> layout_resetter(&suppress_animation_, false); | 524 base::AutoReset<bool> layout_resetter(&suppress_animation_, false); |
| 519 delegate_->Redraw(true); | 525 delegate_->Redraw(true); |
| 520 } | 526 } |
| 521 | 527 |
| 522 ResizeDelegate(gfx::Tween::LINEAR, false); | 528 ResizeDelegate(gfx::Tween::LINEAR, false); |
| 523 if (!delegate_->IsAnimating()) { | 529 if (!delegate_->IsAnimating()) { |
| 524 // Don't call the closure re-entrantly. | 530 // Don't call the closure re-entrantly. |
| 525 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, closure); | 531 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, closure); |
| 526 } else { | 532 } else { |
| 527 popped_out_closure_ = closure; | 533 popped_out_closure_ = closure; |
| 528 } | 534 } |
| 529 } | 535 } |
| 530 | 536 |
| 531 void ToolbarActionsBar::UndoPopOut() { | 537 void ToolbarActionsBar::UndoPopOut() { |
| 532 DCHECK(!in_overflow_mode()) << "Only the main bar can pop out actions."; | 538 DCHECK(!in_overflow_mode()) << "Only the main bar can pop out actions."; |
| 533 DCHECK(popped_out_action_); | 539 DCHECK(popped_out_action_); |
| 534 ToolbarActionViewController* controller = popped_out_action_; | 540 ToolbarActionViewController* controller = popped_out_action_; |
| 535 popped_out_action_ = nullptr; | 541 popped_out_action_ = nullptr; |
| 542 is_popped_out_sticky_ = false; |
| 536 popped_out_closure_.Reset(); | 543 popped_out_closure_.Reset(); |
| 537 if (!IsActionVisibleOnMainBar(controller)) | 544 if (!IsActionVisibleOnMainBar(controller)) |
| 538 delegate_->Redraw(true); | 545 delegate_->Redraw(true); |
| 539 ResizeDelegate(gfx::Tween::LINEAR, false); | 546 ResizeDelegate(gfx::Tween::LINEAR, false); |
| 540 } | 547 } |
| 541 | 548 |
| 542 void ToolbarActionsBar::SetPopupOwner( | 549 void ToolbarActionsBar::SetPopupOwner( |
| 543 ToolbarActionViewController* popup_owner) { | 550 ToolbarActionViewController* popup_owner) { |
| 544 // We should never be setting a popup owner when one already exists, and | 551 // We should never be setting a popup owner when one already exists, and |
| 545 // never unsetting one when one wasn't set. | 552 // never unsetting one when one wasn't set. |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 776 for (ToolbarActionViewController* action : toolbar_actions_) { | 783 for (ToolbarActionViewController* action : toolbar_actions_) { |
| 777 if (action->GetId() == action_id) | 784 if (action->GetId() == action_id) |
| 778 return action; | 785 return action; |
| 779 } | 786 } |
| 780 return nullptr; | 787 return nullptr; |
| 781 } | 788 } |
| 782 | 789 |
| 783 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { | 790 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { |
| 784 return browser_->tab_strip_model()->GetActiveWebContents(); | 791 return browser_->tab_strip_model()->GetActiveWebContents(); |
| 785 } | 792 } |
| OLD | NEW |