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 "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "chrome/browser/extensions/extension_action_manager.h" | 8 #include "chrome/browser/extensions/extension_action_manager.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/sessions/session_tab_helper.h" | 10 #include "chrome/browser/sessions/session_tab_helper.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 54 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
55 IDR_BROWSER_ACTION); | 55 IDR_BROWSER_ACTION); |
56 icon_height = skia->height(); | 56 icon_height = skia->height(); |
57 icon_width = skia->width(); | 57 icon_width = skia->width(); |
58 } | 58 } |
59 return type == WIDTH ? icon_width : icon_height; | 59 return type == WIDTH ? icon_width : icon_height; |
60 } | 60 } |
61 | 61 |
62 } // namespace | 62 } // namespace |
63 | 63 |
| 64 // static |
| 65 bool ToolbarActionsBar::disable_animations_during_testing_ = false; |
| 66 |
64 ToolbarActionsBar::PlatformSettings::PlatformSettings(bool in_overflow_mode) | 67 ToolbarActionsBar::PlatformSettings::PlatformSettings(bool in_overflow_mode) |
65 : left_padding(in_overflow_mode ? kOverflowLeftPadding : kLeftPadding), | 68 : left_padding(in_overflow_mode ? kOverflowLeftPadding : kLeftPadding), |
66 right_padding(in_overflow_mode ? kOverflowRightPadding : kRightPadding), | 69 right_padding(in_overflow_mode ? kOverflowRightPadding : kRightPadding), |
67 item_spacing(kItemSpacing), | 70 item_spacing(kItemSpacing), |
68 icons_per_overflow_menu_row(1), | 71 icons_per_overflow_menu_row(1), |
69 chevron_enabled(!extensions::FeatureSwitch::extension_action_redesign()-> | 72 chevron_enabled(!extensions::FeatureSwitch::extension_action_redesign()-> |
70 IsEnabled()) { | 73 IsEnabled()) { |
71 } | 74 } |
72 | 75 |
73 ToolbarActionsBar::ToolbarActionsBar(ToolbarActionsBarDelegate* delegate, | 76 ToolbarActionsBar::ToolbarActionsBar(ToolbarActionsBarDelegate* delegate, |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 extensions::FeatureSwitch::extension_action_redesign()->IsEnabled()); | 245 extensions::FeatureSwitch::extension_action_redesign()->IsEnabled()); |
243 toolbar_actions_.insert(toolbar_actions_.end(), | 246 toolbar_actions_.insert(toolbar_actions_.end(), |
244 component_actions.begin(), | 247 component_actions.begin(), |
245 component_actions.end()); | 248 component_actions.end()); |
246 component_actions.weak_clear(); | 249 component_actions.weak_clear(); |
247 } | 250 } |
248 | 251 |
249 if (!toolbar_actions_.empty()) | 252 if (!toolbar_actions_.empty()) |
250 ReorderActions(); | 253 ReorderActions(); |
251 | 254 |
| 255 |
252 for (size_t i = 0; i < toolbar_actions_.size(); ++i) | 256 for (size_t i = 0; i < toolbar_actions_.size(); ++i) |
253 delegate_->AddViewForAction(toolbar_actions_[i], i); | 257 delegate_->AddViewForAction(toolbar_actions_[i], i); |
254 } | 258 } |
255 | 259 |
256 // Once the actions are created, we should animate the changes. | 260 // Once the actions are created, we should animate the changes. |
257 suppress_animation_ = false; | 261 suppress_animation_ = false; |
258 } | 262 } |
259 | 263 |
260 void ToolbarActionsBar::DeleteActions() { | 264 void ToolbarActionsBar::DeleteActions() { |
261 delegate_->RemoveAllViews(); | 265 delegate_->RemoveAllViews(); |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 CreateActions(); | 522 CreateActions(); |
519 // Resize the delegate. We suppress the chevron so that we don't risk showing | 523 // Resize the delegate. We suppress the chevron so that we don't risk showing |
520 // it only for the duration of the animation. | 524 // it only for the duration of the animation. |
521 ResizeDelegate(gfx::Tween::LINEAR, true); | 525 ResizeDelegate(gfx::Tween::LINEAR, true); |
522 } | 526 } |
523 | 527 |
524 void ToolbarActionsBar::OnToolbarModelInitialized() { | 528 void ToolbarActionsBar::OnToolbarModelInitialized() { |
525 // We shouldn't have any actions before the model is initialized. | 529 // We shouldn't have any actions before the model is initialized. |
526 DCHECK(toolbar_actions_.empty()); | 530 DCHECK(toolbar_actions_.empty()); |
527 CreateActions(); | 531 CreateActions(); |
| 532 ResizeDelegate(gfx::Tween::EASE_OUT, false); |
528 } | 533 } |
529 | 534 |
530 Browser* ToolbarActionsBar::GetBrowser() { | 535 Browser* ToolbarActionsBar::GetBrowser() { |
531 return browser_; | 536 return browser_; |
532 } | 537 } |
533 | 538 |
534 void ToolbarActionsBar::TabInsertedAt(content::WebContents* web_contents, | 539 void ToolbarActionsBar::TabInsertedAt(content::WebContents* web_contents, |
535 int index, | 540 int index, |
536 bool foreground) { | 541 bool foreground) { |
537 if (foreground) | 542 if (foreground) |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
609 for (ToolbarActionViewController* action : toolbar_actions_) { | 614 for (ToolbarActionViewController* action : toolbar_actions_) { |
610 if (action->GetId() == id) | 615 if (action->GetId() == id) |
611 return action; | 616 return action; |
612 } | 617 } |
613 return nullptr; | 618 return nullptr; |
614 } | 619 } |
615 | 620 |
616 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { | 621 content::WebContents* ToolbarActionsBar::GetCurrentWebContents() { |
617 return browser_->tab_strip_model()->GetActiveWebContents(); | 622 return browser_->tab_strip_model()->GetActiveWebContents(); |
618 } | 623 } |
OLD | NEW |