Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/browser_actions_container.h" | 5 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "chrome/browser/extensions/tab_helper.h" | 9 #include "chrome/browser/extensions/tab_helper.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 119 // All views should be removed as part of ToolbarActionsBar::DeleteActions(). | 119 // All views should be removed as part of ToolbarActionsBar::DeleteActions(). |
| 120 DCHECK(toolbar_action_views_.empty()); | 120 DCHECK(toolbar_action_views_.empty()); |
| 121 } | 121 } |
| 122 | 122 |
| 123 void BrowserActionsContainer::Init() { | 123 void BrowserActionsContainer::Init() { |
| 124 LoadImages(); | 124 LoadImages(); |
| 125 | 125 |
| 126 // We wait to set the container width until now so that the chevron images | 126 // We wait to set the container width until now so that the chevron images |
| 127 // will be loaded. The width calculation needs to know the chevron size. | 127 // will be loaded. The width calculation needs to know the chevron size. |
| 128 container_width_ = toolbar_actions_bar_->GetPreferredSize().width(); | 128 container_width_ = toolbar_actions_bar_->GetPreferredSize().width(); |
| 129 | |
| 130 initialized_ = true; | |
| 131 } | 129 } |
| 132 | 130 |
| 133 const std::string& BrowserActionsContainer::GetIdAt(size_t index) { | 131 const std::string& BrowserActionsContainer::GetIdAt(size_t index) { |
| 134 return toolbar_action_views_[index]->view_controller()->GetId(); | 132 return toolbar_action_views_[index]->view_controller()->GetId(); |
| 135 } | 133 } |
| 136 | 134 |
| 137 ToolbarActionView* BrowserActionsContainer::GetViewForId( | 135 ToolbarActionView* BrowserActionsContainer::GetViewForId( |
| 138 const std::string& id) { | 136 const std::string& id) { |
| 139 for (ToolbarActionView* view : toolbar_action_views_) { | 137 for (ToolbarActionView* view : toolbar_action_views_) { |
| 140 if (view->view_controller()->GetId() == id) | 138 if (view->view_controller()->GetId() == id) |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 214 // this container. | 212 // this container. |
| 215 ToolbarActionViews::const_iterator iter = | 213 ToolbarActionViews::const_iterator iter = |
| 216 std::find(toolbar_action_views_.begin(), | 214 std::find(toolbar_action_views_.begin(), |
| 217 toolbar_action_views_.end(), | 215 toolbar_action_views_.end(), |
| 218 view); | 216 view); |
| 219 DCHECK(iter != toolbar_action_views_.end()); | 217 DCHECK(iter != toolbar_action_views_.end()); |
| 220 size_t index = iter - toolbar_action_views_.begin(); | 218 size_t index = iter - toolbar_action_views_.begin(); |
| 221 return main_container_->toolbar_action_views_[index]; | 219 return main_container_->toolbar_action_views_[index]; |
| 222 } | 220 } |
| 223 | 221 |
| 222 bool BrowserActionsContainer::IsReady() const { | |
| 223 return initialized_; | |
|
Peter Kasting
2014/11/14 21:31:58
So what happens if we allow additions at any time?
Devlin
2014/11/14 22:00:38
Hmm. I think I misread the comment on line 734, a
| |
| 224 } | |
| 225 | |
| 224 void BrowserActionsContainer::AddViewForAction( | 226 void BrowserActionsContainer::AddViewForAction( |
| 225 ToolbarActionViewController* view_controller, | 227 ToolbarActionViewController* view_controller, |
| 226 size_t index) { | 228 size_t index) { |
| 227 if (chevron_) | 229 if (chevron_) |
| 228 chevron_->CloseMenu(); | 230 chevron_->CloseMenu(); |
| 229 | 231 |
| 230 view_controller->GetActionName(); | 232 view_controller->GetActionName(); |
| 231 ToolbarActionView* view = | 233 ToolbarActionView* view = |
| 232 new ToolbarActionView(view_controller, browser_, this); | 234 new ToolbarActionView(view_controller, browser_, this); |
| 233 toolbar_action_views_.insert(toolbar_action_views_.begin() + index, view); | 235 toolbar_action_views_.insert(toolbar_action_views_.begin() + index, view); |
| (...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 720 | 722 |
| 721 if (details.is_add && details.child == this) { | 723 if (details.is_add && details.child == this) { |
| 722 if (!in_overflow_mode()) { // We only need one keybinding registry. | 724 if (!in_overflow_mode()) { // We only need one keybinding registry. |
| 723 extension_keybinding_registry_.reset(new ExtensionKeybindingRegistryViews( | 725 extension_keybinding_registry_.reset(new ExtensionKeybindingRegistryViews( |
| 724 browser_->profile(), | 726 browser_->profile(), |
| 725 parent()->GetFocusManager(), | 727 parent()->GetFocusManager(), |
| 726 extensions::ExtensionKeybindingRegistry::ALL_EXTENSIONS, | 728 extensions::ExtensionKeybindingRegistry::ALL_EXTENSIONS, |
| 727 this)); | 729 this)); |
| 728 } | 730 } |
| 729 | 731 |
| 732 initialized_ = true; | |
|
Peter Kasting
2014/11/14 21:31:58
This seems suspicious. Why do we have to set this
Devlin
2014/11/14 22:00:37
We still need Init(), but we actually don't need i
| |
| 733 | |
| 730 // Initial toolbar button creation and placement in the widget hierarchy. | 734 // Initial toolbar button creation and placement in the widget hierarchy. |
| 731 // We do this here instead of in the constructor because adding views | 735 // We do this here instead of in the constructor because adding views |
| 732 // calls Layout on the Toolbar, which needs this object to be constructed | 736 // calls Layout on the Toolbar, which needs this object to be constructed |
| 733 // before its Layout function is called. | 737 // before its Layout function is called. |
| 734 toolbar_actions_bar_->CreateActions(); | 738 toolbar_actions_bar_->CreateActions(); |
| 735 } | 739 } |
| 736 } | 740 } |
| 737 | 741 |
| 738 void BrowserActionsContainer::LoadImages() { | 742 void BrowserActionsContainer::LoadImages() { |
| 739 if (in_overflow_mode()) | 743 if (in_overflow_mode()) |
| 740 return; // Overflow mode has neither a chevron nor highlighting. | 744 return; // Overflow mode has neither a chevron nor highlighting. |
| 741 | 745 |
| 742 ui::ThemeProvider* tp = GetThemeProvider(); | 746 ui::ThemeProvider* tp = GetThemeProvider(); |
| 743 if (tp && chevron_) { | 747 if (tp && chevron_) { |
| 744 chevron_->SetImage(views::Button::STATE_NORMAL, | 748 chevron_->SetImage(views::Button::STATE_NORMAL, |
| 745 *tp->GetImageSkiaNamed(IDR_BROWSER_ACTIONS_OVERFLOW)); | 749 *tp->GetImageSkiaNamed(IDR_BROWSER_ACTIONS_OVERFLOW)); |
| 746 } | 750 } |
| 747 | 751 |
| 748 const int kImages[] = IMAGE_GRID(IDR_DEVELOPER_MODE_HIGHLIGHT); | 752 const int kImages[] = IMAGE_GRID(IDR_DEVELOPER_MODE_HIGHLIGHT); |
| 749 highlight_painter_.reset(views::Painter::CreateImageGridPainter(kImages)); | 753 highlight_painter_.reset(views::Painter::CreateImageGridPainter(kImages)); |
| 750 } | 754 } |
| OLD | NEW |