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" |
11 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" | 11 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" |
12 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | 12 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
13 #include "chrome/browser/ui/views/toolbar/wrench_menu.h" | 13 #include "chrome/browser/ui/views/toolbar/wrench_menu.h" |
14 #include "ui/views/controls/menu/menu_item_view.h" | 14 #include "ui/views/controls/menu/menu_item_view.h" |
| 15 #include "ui/views/controls/menu/submenu_view.h" |
| 16 |
| 17 namespace { |
| 18 |
| 19 // Returns the padding before the BrowserActionsContainer in the menu. |
| 20 int start_padding() { |
| 21 // We pad enough on the left so that the first icon starts at the same point |
| 22 // as the labels. We need to subtract 1 because we want the pixel *before* |
| 23 // the label, and we subtract kItemSpacing because there needs to be padding |
| 24 // so we can see the drop indicator. |
| 25 return views::MenuItemView::label_start() - 1 - |
| 26 BrowserActionsContainer::kItemSpacing; |
| 27 } |
| 28 |
| 29 } // namespace |
15 | 30 |
16 ExtensionToolbarMenuView::ExtensionToolbarMenuView(Browser* browser, | 31 ExtensionToolbarMenuView::ExtensionToolbarMenuView(Browser* browser, |
17 WrenchMenu* wrench_menu) | 32 WrenchMenu* wrench_menu) |
18 : browser_(browser), | 33 : browser_(browser), |
19 wrench_menu_(wrench_menu), | 34 wrench_menu_(wrench_menu), |
20 container_(NULL), | 35 container_(NULL), |
21 browser_actions_container_observer_(this), | 36 browser_actions_container_observer_(this), |
22 weak_factory_(this) { | 37 weak_factory_(this) { |
23 BrowserActionsContainer* main = | 38 BrowserActionsContainer* main = |
24 BrowserView::GetBrowserViewForBrowser(browser_) | 39 BrowserView::GetBrowserViewForBrowser(browser_) |
(...skipping 13 matching lines...) Expand all Loading... |
38 } | 53 } |
39 } | 54 } |
40 | 55 |
41 ExtensionToolbarMenuView::~ExtensionToolbarMenuView() { | 56 ExtensionToolbarMenuView::~ExtensionToolbarMenuView() { |
42 } | 57 } |
43 | 58 |
44 gfx::Size ExtensionToolbarMenuView::GetPreferredSize() const { | 59 gfx::Size ExtensionToolbarMenuView::GetPreferredSize() const { |
45 return container_->GetPreferredSize(); | 60 return container_->GetPreferredSize(); |
46 } | 61 } |
47 | 62 |
| 63 int ExtensionToolbarMenuView::GetHeightForWidth(int width) const { |
| 64 const views::MenuConfig& menu_config = |
| 65 static_cast<const views::MenuItemView*>(parent())->GetMenuConfig(); |
| 66 int end_padding = menu_config.arrow_to_edge_padding - |
| 67 BrowserActionsContainer::kItemSpacing; |
| 68 width -= start_padding() + end_padding; |
| 69 |
| 70 int height = container_->GetHeightForWidth(width); |
| 71 return height; |
| 72 } |
| 73 |
48 void ExtensionToolbarMenuView::Layout() { | 74 void ExtensionToolbarMenuView::Layout() { |
49 // All buttons are given the same width. | |
50 gfx::Size sz = GetPreferredSize(); | 75 gfx::Size sz = GetPreferredSize(); |
51 SetBounds(views::MenuItemView::label_start(), 0, sz.width(), sz.height()); | 76 SetBounds(start_padding() + 1, 0, sz.width(), sz.height()); |
52 container_->SetBounds(0, 0, sz.width(), sz.height()); | 77 container_->SetBounds(0, 0, sz.width(), sz.height()); |
53 } | 78 } |
54 | 79 |
55 void ExtensionToolbarMenuView::OnBrowserActionDragDone() { | 80 void ExtensionToolbarMenuView::OnBrowserActionDragDone() { |
56 // The delay before we close the wrench menu if this was opened for a drop so | 81 // The delay before we close the wrench menu if this was opened for a drop so |
57 // that the user can see a browser action if one was moved. | 82 // that the user can see a browser action if one was moved. |
58 static const int kCloseMenuDelay = 300; | 83 static const int kCloseMenuDelay = 300; |
59 | 84 |
60 DCHECK(wrench_menu_->for_drop()); | 85 DCHECK(wrench_menu_->for_drop()); |
61 base::MessageLoop::current()->PostDelayedTask( | 86 base::MessageLoop::current()->PostDelayedTask( |
62 FROM_HERE, | 87 FROM_HERE, |
63 base::Bind(&ExtensionToolbarMenuView::CloseWrenchMenu, | 88 base::Bind(&ExtensionToolbarMenuView::CloseWrenchMenu, |
64 weak_factory_.GetWeakPtr()), | 89 weak_factory_.GetWeakPtr()), |
65 base::TimeDelta::FromMilliseconds(kCloseMenuDelay)); | 90 base::TimeDelta::FromMilliseconds(kCloseMenuDelay)); |
66 } | 91 } |
67 | 92 |
68 void ExtensionToolbarMenuView::CloseWrenchMenu() { | 93 void ExtensionToolbarMenuView::CloseWrenchMenu() { |
69 wrench_menu_->CloseMenu(); | 94 wrench_menu_->CloseMenu(); |
70 } | 95 } |
OLD | NEW |