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