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/views/toolbar/extension_toolbar_menu_view.h" | 5 #include "chrome/browser/ui/views/toolbar/extension_toolbar_menu_view.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 // This can be changed for tests. | 23 // This can be changed for tests. |
| 24 int g_close_menu_delay = 300; | 24 int g_close_menu_delay = 300; |
| 25 } | 25 } |
| 26 | 26 |
| 27 ExtensionToolbarMenuView::ExtensionToolbarMenuView(Browser* browser, | 27 ExtensionToolbarMenuView::ExtensionToolbarMenuView(Browser* browser, |
| 28 WrenchMenu* app_menu) | 28 WrenchMenu* app_menu) |
| 29 : browser_(browser), | 29 : browser_(browser), |
| 30 app_menu_(app_menu), | 30 app_menu_(app_menu), |
| 31 container_(nullptr), | 31 container_(nullptr), |
| 32 max_height_(0), | 32 max_height_(0), |
| 33 browser_actions_container_observer_(this), | 33 toolbar_actions_bar_observer_(this), |
| 34 weak_factory_(this) { | 34 weak_factory_(this) { |
| 35 BrowserActionsContainer* main = | 35 BrowserActionsContainer* main = |
| 36 BrowserView::GetBrowserViewForBrowser(browser_) | 36 BrowserView::GetBrowserViewForBrowser(browser_) |
| 37 ->toolbar()->browser_actions(); | 37 ->toolbar()->browser_actions(); |
| 38 container_ = new BrowserActionsContainer(browser_, main); | 38 container_ = new BrowserActionsContainer(browser_, main); |
| 39 container_->Init(); | 39 container_->Init(); |
| 40 SetContents(container_); | 40 SetContents(container_); |
| 41 // We Layout() the container here so that we know the number of actions | 41 // We Layout() the container here so that we know the number of actions |
| 42 // that will be visible in ShouldShow(). | 42 // that will be visible in ShouldShow(). |
| 43 container_->Layout(); | 43 container_->Layout(); |
| 44 | 44 |
| 45 // Listen for the drop to finish so we can close the app menu, if necessary. | 45 // Listen for the drop to finish so we can close the app menu, if necessary. |
| 46 browser_actions_container_observer_.Add(container_); | 46 toolbar_actions_bar_observer_.Add(main->toolbar_actions_bar()); |
| 47 browser_actions_container_observer_.Add(main); | |
| 48 | 47 |
| 49 // In *very* extreme cases, it's possible that there are so many overflowed | 48 // In *very* extreme cases, it's possible that there are so many overflowed |
| 50 // actions, we won't be able to show them all. Cap the height so that the | 49 // actions, we won't be able to show them all. Cap the height so that the |
| 51 // overflow won't be excessively tall (at 8 icons per row, this allows for | 50 // overflow won't be excessively tall (at 8 icons per row, this allows for |
| 52 // 104 total extensions). | 51 // 104 total extensions). |
| 53 const int kMaxOverflowRows = 13; | 52 const int kMaxOverflowRows = 13; |
| 54 max_height_ = ToolbarActionsBar::IconHeight() * kMaxOverflowRows; | 53 max_height_ = ToolbarActionsBar::IconHeight() * kMaxOverflowRows; |
| 55 ClipHeightTo(0, max_height_); | 54 ClipHeightTo(0, max_height_); |
| 56 } | 55 } |
| 57 | 56 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 87 void ExtensionToolbarMenuView::Layout() { | 86 void ExtensionToolbarMenuView::Layout() { |
| 88 SetPosition(gfx::Point(start_padding(), 0)); | 87 SetPosition(gfx::Point(start_padding(), 0)); |
| 89 SizeToPreferredSize(); | 88 SizeToPreferredSize(); |
| 90 views::ScrollView::Layout(); | 89 views::ScrollView::Layout(); |
| 91 } | 90 } |
| 92 | 91 |
| 93 void ExtensionToolbarMenuView::set_close_menu_delay_for_testing(int delay) { | 92 void ExtensionToolbarMenuView::set_close_menu_delay_for_testing(int delay) { |
| 94 g_close_menu_delay = delay; | 93 g_close_menu_delay = delay; |
| 95 } | 94 } |
| 96 | 95 |
| 97 void ExtensionToolbarMenuView::OnBrowserActionsContainerDestroyed( | 96 void ExtensionToolbarMenuView::OnToolbarActionsBarDestroyed() { |
| 98 BrowserActionsContainer* browser_actions_container) { | 97 toolbar_actions_bar_observer_.RemoveAll(); |
| 99 browser_actions_container_observer_.Remove(browser_actions_container); | |
| 100 } | 98 } |
| 101 | 99 |
| 102 void ExtensionToolbarMenuView::OnBrowserActionDragDone() { | 100 void ExtensionToolbarMenuView::OnToolbarActionDragDone() { |
| 103 // In the case of a drag-and-drop, the bounds of the container may have | 101 // In the case of a drag-and-drop, the bounds of the container may have |
| 104 // changed (in the case of removing an icon that was the last in a row). We | 102 // changed (in the case of removing an icon that was the last in a row). |
| 105 // need to re-layout the menu in order to shrink down the view (calling | 103 Redraw(); |
| 106 // Layout() on this is insufficient because other items may need to shift | |
| 107 // upwards). | |
| 108 parent()->parent()->Layout(); | |
| 109 | 104 |
| 110 // We need to close the app menu if it was just opened for the drag and drop, | 105 // We need to close the app menu if it was just opened for the drag and drop, |
| 111 // or if there are no more extensions in the overflow menu after a drag and | 106 // or if there are no more extensions in the overflow menu after a drag and |
| 112 // drop. | 107 // drop. |
| 113 if (app_menu_->for_drop() || | 108 if (app_menu_->for_drop() || |
| 114 container_->toolbar_actions_bar()->GetIconCount() == 0) { | 109 container_->toolbar_actions_bar()->GetIconCount() == 0) { |
| 115 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 110 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 116 FROM_HERE, base::Bind(&ExtensionToolbarMenuView::CloseAppMenu, | 111 FROM_HERE, base::Bind(&ExtensionToolbarMenuView::CloseAppMenu, |
| 117 weak_factory_.GetWeakPtr()), | 112 weak_factory_.GetWeakPtr()), |
| 118 base::TimeDelta::FromMilliseconds(g_close_menu_delay)); | 113 base::TimeDelta::FromMilliseconds(g_close_menu_delay)); |
| 119 } | 114 } |
| 120 } | 115 } |
| 121 | 116 |
| 117 void ExtensionToolbarMenuView::OnToolbarActionsBarDidStartResize() { | |
| 118 Redraw(); | |
| 119 } | |
| 120 | |
| 122 void ExtensionToolbarMenuView::CloseAppMenu() { | 121 void ExtensionToolbarMenuView::CloseAppMenu() { |
| 123 app_menu_->CloseMenu(); | 122 app_menu_->CloseMenu(); |
| 124 } | 123 } |
| 125 | 124 |
| 125 void ExtensionToolbarMenuView::Redraw() { | |
| 126 // In a case where the size of the container may have changed (e.g., by a row | |
| 127 // being added or removed), We need to re-layout the menu in order to resize | |
|
Avi (use Gerrit)
2015/10/22 21:32:02
lower-case "we"
Devlin
2015/10/22 22:18:05
Whoops, done.
| |
| 128 // the view (calling Layout() on this is insufficient because other items may | |
| 129 // need to shift up or down). | |
| 130 parent()->parent()->Layout(); | |
| 131 // The Menus layout code doesn't recursively call layout on its children like | |
| 132 // the default View code. Explicitly layout this view. | |
| 133 Layout(); | |
| 134 } | |
| 135 | |
| 126 int ExtensionToolbarMenuView::start_padding() const { | 136 int ExtensionToolbarMenuView::start_padding() const { |
| 127 // We pad enough on the left so that the first icon starts at the same point | 137 // We pad enough on the left so that the first icon starts at the same point |
| 128 // as the labels. We subtract kItemSpacing because there needs to be padding | 138 // as the labels. We subtract kItemSpacing because there needs to be padding |
| 129 // so we can see the drop indicator. | 139 // so we can see the drop indicator. |
| 130 return views::MenuItemView::label_start() - | 140 return views::MenuItemView::label_start() - |
| 131 container_->toolbar_actions_bar()->platform_settings().item_spacing; | 141 container_->toolbar_actions_bar()->platform_settings().item_spacing; |
| 132 } | 142 } |
| 133 | 143 |
| OLD | NEW |