Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" | 5 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" |
| 6 | 6 |
| 7 #include <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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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, or 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). |
|
Finnur
2016/03/11 15:10:11
This comment needs updating. Could actually do wit
Devlin
2016/03/11 17:32:10
Done.
| |
| 288 return GetEndIndexInBounds() != toolbar_actions_.size() || | 289 return GetEndIndexInBounds() != toolbar_actions_.size() || |
| 289 (is_drag_in_progress_ && !platform_settings_.chevron_enabled); | 290 (is_drag_in_progress_ && !platform_settings_.chevron_enabled) || |
| 291 (popped_out_action_ && !is_popped_out_sticky_); | |
| 290 } | 292 } |
| 291 | 293 |
| 292 gfx::Rect ToolbarActionsBar::GetFrameForIndex( | 294 gfx::Rect ToolbarActionsBar::GetFrameForIndex( |
| 293 size_t index) const { | 295 size_t index) const { |
| 294 size_t start_index = GetStartIndexInBounds(); | 296 size_t start_index = GetStartIndexInBounds(); |
| 295 | 297 |
| 296 // If the index is for an action that is before range we show (i.e., is for | 298 // 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 | 299 // a button that's on the main bar, and this is the overflow), send back an |
| 298 // empty rect. | 300 // empty rect. |
| 299 if (index < start_index) | 301 if (index < start_index) |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 500 if (in_overflow_mode()) | 502 if (in_overflow_mode()) |
| 501 return main_bar_->IsActionVisibleOnMainBar(action); | 503 return main_bar_->IsActionVisibleOnMainBar(action); |
| 502 | 504 |
| 503 size_t index = std::find(toolbar_actions_.begin(), | 505 size_t index = std::find(toolbar_actions_.begin(), |
| 504 toolbar_actions_.end(), | 506 toolbar_actions_.end(), |
| 505 action) - toolbar_actions_.begin(); | 507 action) - toolbar_actions_.begin(); |
| 506 return index < GetIconCount() || action == popped_out_action_; | 508 return index < GetIconCount() || action == popped_out_action_; |
| 507 } | 509 } |
| 508 | 510 |
| 509 void ToolbarActionsBar::PopOutAction(ToolbarActionViewController* controller, | 511 void ToolbarActionsBar::PopOutAction(ToolbarActionViewController* controller, |
| 512 bool is_sticky, | |
| 510 const base::Closure& closure) { | 513 const base::Closure& closure) { |
| 511 DCHECK(!in_overflow_mode()) << "Only the main bar can pop out actions."; | 514 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!"; | 515 DCHECK(!popped_out_action_) << "Only one action can be popped out at a time!"; |
| 513 bool needs_redraw = !IsActionVisibleOnMainBar(controller); | 516 bool needs_redraw = !IsActionVisibleOnMainBar(controller); |
| 514 popped_out_action_ = controller; | 517 popped_out_action_ = controller; |
| 518 is_popped_out_sticky_ = is_sticky; | |
| 515 if (needs_redraw) { | 519 if (needs_redraw) { |
| 516 // We suppress animation for this draw, because we need the action to get | 520 // 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. | 521 // into position immediately, since it's about to show its popup. |
| 518 base::AutoReset<bool> layout_resetter(&suppress_animation_, false); | 522 base::AutoReset<bool> layout_resetter(&suppress_animation_, false); |
| 519 delegate_->Redraw(true); | 523 delegate_->Redraw(true); |
| 520 } | 524 } |
| 521 | 525 |
| 522 ResizeDelegate(gfx::Tween::LINEAR, false); | 526 ResizeDelegate(gfx::Tween::LINEAR, false); |
| 523 if (!delegate_->IsAnimating()) { | 527 if (!delegate_->IsAnimating()) { |
| 524 // Don't call the closure re-entrantly. | 528 // Don't call the closure re-entrantly. |
| 525 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, closure); | 529 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, closure); |
| 526 } else { | 530 } else { |
| 527 popped_out_closure_ = closure; | 531 popped_out_closure_ = closure; |
| 528 } | 532 } |
| 529 } | 533 } |
| 530 | 534 |
| 531 void ToolbarActionsBar::UndoPopOut() { | 535 void ToolbarActionsBar::UndoPopOut() { |
| 532 DCHECK(!in_overflow_mode()) << "Only the main bar can pop out actions."; | 536 DCHECK(!in_overflow_mode()) << "Only the main bar can pop out actions."; |
| 533 DCHECK(popped_out_action_); | 537 DCHECK(popped_out_action_); |
| 534 ToolbarActionViewController* controller = popped_out_action_; | 538 ToolbarActionViewController* controller = popped_out_action_; |
| 535 popped_out_action_ = nullptr; | 539 popped_out_action_ = nullptr; |
| 540 is_popped_out_sticky_ = false; | |
| 536 popped_out_closure_.Reset(); | 541 popped_out_closure_.Reset(); |
| 537 if (!IsActionVisibleOnMainBar(controller)) | 542 if (!IsActionVisibleOnMainBar(controller)) |
| 538 delegate_->Redraw(true); | 543 delegate_->Redraw(true); |
| 539 ResizeDelegate(gfx::Tween::LINEAR, false); | 544 ResizeDelegate(gfx::Tween::LINEAR, false); |
| 540 } | 545 } |
| 541 | 546 |
| 542 void ToolbarActionsBar::SetPopupOwner( | 547 void ToolbarActionsBar::SetPopupOwner( |
| 543 ToolbarActionViewController* popup_owner) { | 548 ToolbarActionViewController* popup_owner) { |
| 544 // We should never be setting a popup owner when one already exists, and | 549 // We should never be setting a popup owner when one already exists, and |
| 545 // never unsetting one when one wasn't set. | 550 // 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_) { | 781 for (ToolbarActionViewController* action : toolbar_actions_) { |
| 777 if (action->GetId() == action_id) | 782 if (action->GetId() == action_id) |
| 778 return action; | 783 return action; |
| 779 } | 784 } |
| 780 return nullptr; | 785 return nullptr; |
| 781 } | 786 } |
| 782 | 787 |
| 783 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { | 788 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { |
| 784 return browser_->tab_strip_model()->GetActiveWebContents(); | 789 return browser_->tab_strip_model()->GetActiveWebContents(); |
| 785 } | 790 } |
| OLD | NEW |