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 weak_factory_(this) { | |
29 BrowserActionsContainer* main = | |
30 BrowserView::GetBrowserViewForBrowser(browser) | |
31 ->toolbar()->browser_actions(); | |
24 container_ = new BrowserActionsContainer( | 32 container_ = new BrowserActionsContainer( |
25 browser_, | 33 browser_, |
26 NULL, // No owner view, means no extra keybindings are registered. | 34 NULL, // No owner view, means no extra keybindings are registered. |
27 browser_view->GetToolbarView()->browser_actions()); | 35 main); |
28 container_->Init(); | 36 container_->Init(); |
29 AddChildView(container_); | 37 AddChildView(container_); |
38 | |
39 // If we were opened for a drop command, we have to wait for the drop to | |
40 // finish so we can close the wrench menu. | |
41 if (wrench_menu_->for_drop()) { | |
42 browser_actions_container_observer_.Add(container_); | |
43 browser_actions_container_observer_.Add(main); | |
44 } | |
30 } | 45 } |
31 | 46 |
32 ExtensionToolbarMenuView::~ExtensionToolbarMenuView() { | 47 ExtensionToolbarMenuView::~ExtensionToolbarMenuView() { |
33 } | 48 } |
34 | 49 |
35 gfx::Size ExtensionToolbarMenuView::GetPreferredSize() const { | 50 gfx::Size ExtensionToolbarMenuView::GetPreferredSize() const { |
36 gfx::Size sz = container_->GetPreferredSize(); | 51 gfx::Size sz = container_->GetPreferredSize(); |
37 if (sz.height() == 0) | 52 if (sz.height() == 0) |
38 return sz; | 53 return sz; |
39 | 54 |
40 sz.Enlarge(0, kVerticalPadding); | 55 sz.Enlarge(0, kVerticalPadding); |
41 return sz; | 56 return sz; |
42 } | 57 } |
43 | 58 |
44 void ExtensionToolbarMenuView::Layout() { | 59 void ExtensionToolbarMenuView::Layout() { |
45 // All buttons are given the same width. | 60 // All buttons are given the same width. |
46 gfx::Size sz = container_->GetPreferredSize(); | 61 gfx::Size sz = container_->GetPreferredSize(); |
47 int height = sz.height() + kVerticalPadding / 2; | 62 int height = sz.height() + kVerticalPadding / 2; |
48 SetBounds(views::MenuItemView::label_start(), 0, sz.width(), height); | 63 SetBounds(views::MenuItemView::label_start(), 0, sz.width(), height); |
49 container_->SetBounds(0, 0, sz.width(), height); | 64 container_->SetBounds(0, 0, sz.width(), height); |
50 } | 65 } |
66 | |
67 void ExtensionToolbarMenuView::OnBrowserActionDragDone() { | |
68 DCHECK(wrench_menu_->for_drop()); | |
69 // We have to post this in a message loop because it results in the menu being | |
70 // closed, which deletes this view. Since this is in an observer method, that | |
71 // could break the BrowserActionsContainer's observer list if done here. | |
sky
2014/07/18 19:36:53
observer list handles removal while notifying.
Devlin
2014/07/18 21:38:31
Oh, nifty. Coulda sworn it didn't... Done.
| |
72 base::MessageLoop::current()->PostTask( | |
73 FROM_HERE, | |
74 base::Bind(&ExtensionToolbarMenuView::CloseWrenchMenu, | |
75 weak_factory_.GetWeakPtr())); | |
76 } | |
77 | |
78 void ExtensionToolbarMenuView::CloseWrenchMenu() { | |
79 wrench_menu_->CloseMenu(); | |
80 } | |
OLD | NEW |