Index: chrome/browser/ui/views/toolbar/extension_toolbar_menu_view.cc |
diff --git a/chrome/browser/ui/views/toolbar/extension_toolbar_menu_view.cc b/chrome/browser/ui/views/toolbar/extension_toolbar_menu_view.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a82e146f9789ddfdf4cdb12ed8a8448da97f7781 |
--- /dev/null |
+++ b/chrome/browser/ui/views/toolbar/extension_toolbar_menu_view.cc |
@@ -0,0 +1,55 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/ui/views/toolbar/extension_toolbar_menu_view.h" |
+ |
+#include "chrome/browser/ui/views/frame/browser_view.h" |
+#include "chrome/browser/ui/views/toolbar/browser_actions_container.h" |
+#include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
+ |
+namespace { |
+ |
+// Padding to the left of the menu to make sure the icons are in line with the |
+// rest of the menu. |
+const int kLeftEdgePadding = 33; |
+ |
+// Vertical padding to make sure the icons are centered vertically within the |
+// menu. |
+const int kVerticalPadding = 8; |
+ |
+} // namespace |
+ |
+ExtensionToolbarMenuView::ExtensionToolbarMenuView(Browser* browser) |
+ : browser_(browser) { |
+ BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); |
+ container_ = new BrowserActionsContainer( |
+ browser_, |
+ NULL, // No owner view, means no extra keybindings are registered. |
+ browser_view->GetToolbarView()->browser_actions()); |
+ container_->Init(); |
+ AddChildView(container_); |
+} |
+ |
+ExtensionToolbarMenuView::~ExtensionToolbarMenuView() { |
+} |
+ |
+gfx::Size ExtensionToolbarMenuView::GetPreferredSize() const { |
+ gfx::Size sz = container_->GetPreferredSize(); |
+ if (sz.height() == 0) |
+ return sz; |
+ // If we go above 6 icons, make sure the seventh is in line with the right |
+ // edge of the Paste button further down the menu. |
+ if (sz.width() > 200) |
+ sz.set_width(std::max(sz.width(), 280)); |
+ |
+ sz.Enlarge(0, kVerticalPadding); |
+ return sz; |
+} |
+ |
+void ExtensionToolbarMenuView::Layout() { |
+ // All buttons are given the same width. |
+ gfx::Size sz = container_->GetPreferredSize(); |
+ container_->SetBounds( |
+ kLeftEdgePadding, 0, sz.width(), sz.height() + (kVerticalPadding / 2)); |
+} |