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/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 #include "chrome/browser/ui/views/frame/browser_view.h" | 10 #include "chrome/browser/ui/views/frame/browser_view.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 weak_factory_(this) { | 37 weak_factory_(this) { |
38 BrowserActionsContainer* main = | 38 BrowserActionsContainer* main = |
39 BrowserView::GetBrowserViewForBrowser(browser_) | 39 BrowserView::GetBrowserViewForBrowser(browser_) |
40 ->toolbar()->browser_actions(); | 40 ->toolbar()->browser_actions(); |
41 container_ = new BrowserActionsContainer( | 41 container_ = new BrowserActionsContainer( |
42 browser_, | 42 browser_, |
43 NULL, // No owner view, means no extra keybindings are registered. | 43 NULL, // No owner view, means no extra keybindings are registered. |
44 main); | 44 main); |
45 container_->Init(); | 45 container_->Init(); |
46 AddChildView(container_); | 46 AddChildView(container_); |
| 47 // We Layout() the container here so that we know the number of actions |
| 48 // that will be visible in ShouldShow(). |
| 49 container_->Layout(); |
47 | 50 |
48 // If we were opened for a drop command, we have to wait for the drop to | 51 // If we were opened for a drop command, we have to wait for the drop to |
49 // finish so we can close the wrench menu. | 52 // finish so we can close the wrench menu. |
50 if (wrench_menu_->for_drop()) { | 53 if (wrench_menu_->for_drop()) { |
51 browser_actions_container_observer_.Add(container_); | 54 browser_actions_container_observer_.Add(container_); |
52 browser_actions_container_observer_.Add(main); | 55 browser_actions_container_observer_.Add(main); |
53 } | 56 } |
54 } | 57 } |
55 | 58 |
56 ExtensionToolbarMenuView::~ExtensionToolbarMenuView() { | 59 ExtensionToolbarMenuView::~ExtensionToolbarMenuView() { |
57 } | 60 } |
58 | 61 |
| 62 bool ExtensionToolbarMenuView::ShouldShow() { |
| 63 return wrench_menu_->for_drop() || |
| 64 container_->VisibleBrowserActionsAfterAnimation(); |
| 65 } |
| 66 |
59 gfx::Size ExtensionToolbarMenuView::GetPreferredSize() const { | 67 gfx::Size ExtensionToolbarMenuView::GetPreferredSize() const { |
60 return container_->GetPreferredSize(); | 68 return container_->GetPreferredSize(); |
61 } | 69 } |
62 | 70 |
63 int ExtensionToolbarMenuView::GetHeightForWidth(int width) const { | 71 int ExtensionToolbarMenuView::GetHeightForWidth(int width) const { |
64 const views::MenuConfig& menu_config = | 72 const views::MenuConfig& menu_config = |
65 static_cast<const views::MenuItemView*>(parent())->GetMenuConfig(); | 73 static_cast<const views::MenuItemView*>(parent())->GetMenuConfig(); |
66 int end_padding = menu_config.arrow_to_edge_padding - | 74 int end_padding = menu_config.arrow_to_edge_padding - |
67 BrowserActionsContainer::kItemSpacing; | 75 BrowserActionsContainer::kItemSpacing; |
68 width -= start_padding() + end_padding; | 76 width -= start_padding() + end_padding; |
(...skipping 17 matching lines...) Expand all Loading... |
86 base::MessageLoop::current()->PostDelayedTask( | 94 base::MessageLoop::current()->PostDelayedTask( |
87 FROM_HERE, | 95 FROM_HERE, |
88 base::Bind(&ExtensionToolbarMenuView::CloseWrenchMenu, | 96 base::Bind(&ExtensionToolbarMenuView::CloseWrenchMenu, |
89 weak_factory_.GetWeakPtr()), | 97 weak_factory_.GetWeakPtr()), |
90 base::TimeDelta::FromMilliseconds(kCloseMenuDelay)); | 98 base::TimeDelta::FromMilliseconds(kCloseMenuDelay)); |
91 } | 99 } |
92 | 100 |
93 void ExtensionToolbarMenuView::CloseWrenchMenu() { | 101 void ExtensionToolbarMenuView::CloseWrenchMenu() { |
94 wrench_menu_->CloseMenu(); | 102 wrench_menu_->CloseMenu(); |
95 } | 103 } |
OLD | NEW |