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