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 "chrome/browser/ui/views/frame/browser_view.h" | 7 #include "chrome/browser/ui/views/frame/browser_view.h" |
8 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" | 8 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" |
9 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | 9 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
| 10 #include "chrome/browser/ui/views/toolbar/wrench_menu.h" |
10 #include "ui/views/controls/menu/menu_item_view.h" | 11 #include "ui/views/controls/menu/menu_item_view.h" |
11 | 12 |
12 namespace { | 13 namespace { |
13 | 14 |
14 // Bottom padding to make sure we have enough room for the icons. | 15 // Bottom padding to make sure we have enough room for the icons. |
15 // TODO(devlin): Figure out why the bottom few pixels of the last row in the | 16 // TODO(devlin): Figure out why the bottom few pixels of the last row in the |
16 // overflow menu are cut off (so we can remove this). | 17 // overflow menu are cut off (so we can remove this). |
17 const int kVerticalPadding = 8; | 18 const int kVerticalPadding = 8; |
18 | 19 |
19 } // namespace | 20 } // namespace |
20 | 21 |
21 ExtensionToolbarMenuView::ExtensionToolbarMenuView(Browser* browser) | 22 ExtensionToolbarMenuView::ExtensionToolbarMenuView(Browser* browser, |
22 : browser_(browser) { | 23 WrenchMenu* wrench_menu) |
23 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); | 24 : browser_(browser), |
| 25 wrench_menu_(wrench_menu), |
| 26 container_(NULL), |
| 27 browser_actions_container_observer_(this) { |
| 28 BrowserActionsContainer* main = |
| 29 BrowserView::GetBrowserViewForBrowser(browser_) |
| 30 ->toolbar()->browser_actions(); |
24 container_ = new BrowserActionsContainer( | 31 container_ = new BrowserActionsContainer( |
25 browser_, | 32 browser_, |
26 NULL, // No owner view, means no extra keybindings are registered. | 33 NULL, // No owner view, means no extra keybindings are registered. |
27 browser_view->GetToolbarView()->browser_actions()); | 34 main); |
28 container_->Init(); | 35 container_->Init(); |
29 AddChildView(container_); | 36 AddChildView(container_); |
| 37 |
| 38 // If we were opened for a drop command, we have to wait for the drop to |
| 39 // finish so we can close the wrench menu. |
| 40 if (wrench_menu_->for_drop()) { |
| 41 browser_actions_container_observer_.Add(container_); |
| 42 browser_actions_container_observer_.Add(main); |
| 43 } |
30 } | 44 } |
31 | 45 |
32 ExtensionToolbarMenuView::~ExtensionToolbarMenuView() { | 46 ExtensionToolbarMenuView::~ExtensionToolbarMenuView() { |
33 } | 47 } |
34 | 48 |
35 gfx::Size ExtensionToolbarMenuView::GetPreferredSize() const { | 49 gfx::Size ExtensionToolbarMenuView::GetPreferredSize() const { |
36 gfx::Size sz = container_->GetPreferredSize(); | 50 gfx::Size sz = container_->GetPreferredSize(); |
37 if (sz.height() == 0) | 51 if (sz.height() == 0) |
38 return sz; | 52 return sz; |
39 | 53 |
40 sz.Enlarge(0, kVerticalPadding); | 54 sz.Enlarge(0, kVerticalPadding); |
41 return sz; | 55 return sz; |
42 } | 56 } |
43 | 57 |
44 void ExtensionToolbarMenuView::Layout() { | 58 void ExtensionToolbarMenuView::Layout() { |
45 // All buttons are given the same width. | 59 // All buttons are given the same width. |
46 gfx::Size sz = container_->GetPreferredSize(); | 60 gfx::Size sz = container_->GetPreferredSize(); |
47 int height = sz.height() + kVerticalPadding / 2; | 61 int height = sz.height() + kVerticalPadding / 2; |
48 SetBounds(views::MenuItemView::label_start(), 0, sz.width(), height); | 62 SetBounds(views::MenuItemView::label_start(), 0, sz.width(), height); |
49 container_->SetBounds(0, 0, sz.width(), height); | 63 container_->SetBounds(0, 0, sz.width(), height); |
50 } | 64 } |
| 65 |
| 66 void ExtensionToolbarMenuView::OnBrowserActionDragDone() { |
| 67 DCHECK(wrench_menu_->for_drop()); |
| 68 wrench_menu_->CloseMenu(); |
| 69 } |
OLD | NEW |