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/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
| 11 #include "chrome/browser/extensions/extension_util.h" | 11 #include "chrome/browser/extensions/extension_util.h" |
| 12 #include "chrome/browser/extensions/extension_view_host.h" | 12 #include "chrome/browser/extensions/extension_view_host.h" |
| 13 #include "chrome/browser/extensions/tab_helper.h" | 13 #include "chrome/browser/extensions/tab_helper.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/sessions/session_tab_helper.h" | 15 #include "chrome/browser/sessions/session_tab_helper.h" |
| 16 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
| 17 #include "chrome/browser/ui/browser_window.h" | 17 #include "chrome/browser/ui/browser_window.h" |
| 18 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 18 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 19 #include "chrome/browser/ui/view_ids.h" | 19 #include "chrome/browser/ui/view_ids.h" |
| 20 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h" | 20 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h" |
| 21 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views .h" | 21 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views .h" |
| 22 #include "chrome/browser/ui/views/extensions/extension_popup.h" | 22 #include "chrome/browser/ui/views/extensions/extension_popup.h" |
| 23 #include "chrome/browser/ui/views/toolbar/browser_action_view.h" | 23 #include "chrome/browser/ui/views/toolbar/browser_action_view.h" |
| 24 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | 24 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
| 25 #include "chrome/common/extensions/command.h" | 25 #include "chrome/common/extensions/command.h" |
| 26 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
| 27 #include "extensions/browser/extension_system.h" | 27 #include "extensions/browser/extension_system.h" |
| 28 #include "extensions/browser/pref_names.h" | 28 #include "extensions/browser/pref_names.h" |
| 29 #include "extensions/browser/runtime_data.h" | 29 #include "extensions/browser/runtime_data.h" |
| 30 #include "extensions/common/feature_switch.h" | |
| 30 #include "grit/generated_resources.h" | 31 #include "grit/generated_resources.h" |
| 31 #include "grit/theme_resources.h" | 32 #include "grit/theme_resources.h" |
| 32 #include "grit/ui_resources.h" | 33 #include "grit/ui_resources.h" |
| 33 #include "third_party/skia/include/core/SkColor.h" | 34 #include "third_party/skia/include/core/SkColor.h" |
| 34 #include "ui/accessibility/ax_view_state.h" | 35 #include "ui/accessibility/ax_view_state.h" |
| 35 #include "ui/base/dragdrop/drag_utils.h" | 36 #include "ui/base/dragdrop/drag_utils.h" |
| 36 #include "ui/base/l10n/l10n_util.h" | 37 #include "ui/base/l10n/l10n_util.h" |
| 37 #include "ui/base/nine_image_painter_factory.h" | 38 #include "ui/base/nine_image_painter_factory.h" |
| 38 #include "ui/base/resource/resource_bundle.h" | 39 #include "ui/base/resource/resource_bundle.h" |
| 39 #include "ui/base/theme_provider.h" | 40 #include "ui/base/theme_provider.h" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 50 | 51 |
| 51 namespace { | 52 namespace { |
| 52 | 53 |
| 53 // Horizontal spacing between most items in the container, as well as after the | 54 // Horizontal spacing between most items in the container, as well as after the |
| 54 // last item or chevron (if visible). | 55 // last item or chevron (if visible). |
| 55 const int kItemSpacing = ToolbarView::kStandardSpacing; | 56 const int kItemSpacing = ToolbarView::kStandardSpacing; |
| 56 | 57 |
| 57 // Horizontal spacing before the chevron (if visible). | 58 // Horizontal spacing before the chevron (if visible). |
| 58 const int kChevronSpacing = kItemSpacing - 2; | 59 const int kChevronSpacing = kItemSpacing - 2; |
| 59 | 60 |
| 61 // Padding to make sure the badge appears in the right location vertically when | |
| 62 // in slave mode (inside the app menu, aka. hamburger menu). | |
| 63 const int kPaddingForBadge = 9; | |
| 64 | |
| 65 // The maximum number of icons to show per row when in slave mode (showing icons | |
| 66 // in the application menu). | |
| 67 const int kIconsPerMenuRow = 7; | |
| 68 | |
| 60 // A version of MenuButton with almost empty insets to fit properly on the | 69 // A version of MenuButton with almost empty insets to fit properly on the |
| 61 // toolbar. | 70 // toolbar. |
| 62 class ChevronMenuButton : public views::MenuButton { | 71 class ChevronMenuButton : public views::MenuButton { |
| 63 public: | 72 public: |
| 64 ChevronMenuButton(views::ButtonListener* listener, | 73 ChevronMenuButton(views::ButtonListener* listener, |
| 65 const base::string16& text, | 74 const base::string16& text, |
| 66 views::MenuButtonListener* menu_button_listener, | 75 views::MenuButtonListener* menu_button_listener, |
| 67 bool show_menu_marker) | 76 bool show_menu_marker) |
| 68 : views::MenuButton(listener, | 77 : views::MenuButton(listener, |
| 69 text, | 78 text, |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 87 }; | 96 }; |
| 88 | 97 |
| 89 } // namespace | 98 } // namespace |
| 90 | 99 |
| 91 // static | 100 // static |
| 92 bool BrowserActionsContainer::disable_animations_during_testing_ = false; | 101 bool BrowserActionsContainer::disable_animations_during_testing_ = false; |
| 93 | 102 |
| 94 //////////////////////////////////////////////////////////////////////////////// | 103 //////////////////////////////////////////////////////////////////////////////// |
| 95 // BrowserActionsContainer | 104 // BrowserActionsContainer |
| 96 | 105 |
| 97 BrowserActionsContainer::BrowserActionsContainer(Browser* browser, | 106 BrowserActionsContainer::BrowserActionsContainer( |
| 98 View* owner_view) | 107 Browser* browser, View* owner_view, BrowserActionsContainer* master) |
| 99 : profile_(browser->profile()), | 108 : profile_(browser->profile()), |
| 100 browser_(browser), | 109 browser_(browser), |
| 101 owner_view_(owner_view), | 110 owner_view_(owner_view), |
| 111 master_(master), | |
| 102 popup_(NULL), | 112 popup_(NULL), |
| 103 popup_button_(NULL), | 113 popup_button_(NULL), |
| 104 model_(NULL), | 114 model_(NULL), |
| 105 container_width_(0), | 115 container_width_(0), |
| 116 resize_area_(NULL), | |
| 106 chevron_(NULL), | 117 chevron_(NULL), |
| 107 overflow_menu_(NULL), | 118 overflow_menu_(NULL), |
| 108 suppress_chevron_(false), | 119 suppress_chevron_(false), |
| 109 resize_amount_(0), | 120 resize_amount_(0), |
| 110 animation_target_size_(0), | 121 animation_target_size_(0), |
| 111 drop_indicator_position_(-1), | 122 drop_indicator_position_(-1), |
| 112 task_factory_(this), | 123 task_factory_(this), |
| 113 show_menu_task_factory_(this) { | 124 show_menu_task_factory_(this) { |
| 114 set_id(VIEW_ID_BROWSER_ACTION_TOOLBAR); | 125 set_id(VIEW_ID_BROWSER_ACTION_TOOLBAR); |
| 115 | 126 |
| 116 model_ = extensions::ExtensionToolbarModel::Get(browser->profile()); | 127 model_ = extensions::ExtensionToolbarModel::Get(browser->profile()); |
| 117 if (model_) | 128 if (model_) |
| 118 model_->AddObserver(this); | 129 model_->AddObserver(this); |
| 119 | 130 |
|
Devlin
2014/06/23 17:55:29
For a sanity check, can we do something like:
DCHE
| |
| 120 extension_keybinding_registry_.reset(new ExtensionKeybindingRegistryViews( | 131 if (!is_slave()) { |
| 121 browser->profile(), | 132 extension_keybinding_registry_.reset(new ExtensionKeybindingRegistryViews( |
| 122 owner_view->GetFocusManager(), | 133 browser->profile(), |
| 123 extensions::ExtensionKeybindingRegistry::ALL_EXTENSIONS, | 134 owner_view->GetFocusManager(), |
| 124 this)); | 135 extensions::ExtensionKeybindingRegistry::ALL_EXTENSIONS, |
| 136 this)); | |
| 125 | 137 |
| 126 resize_animation_.reset(new gfx::SlideAnimation(this)); | 138 resize_animation_.reset(new gfx::SlideAnimation(this)); |
| 127 resize_area_ = new views::ResizeArea(this); | 139 resize_area_ = new views::ResizeArea(this); |
| 128 AddChildView(resize_area_); | 140 AddChildView(resize_area_); |
| 129 | 141 |
| 130 chevron_ = new ChevronMenuButton(NULL, base::string16(), this, false); | 142 // Master mode doesn't need a chevron overflow when overflow is shown inside |
| 131 chevron_->EnableCanvasFlippingForRTLUI(true); | 143 // the hamburger menu. |
| 132 chevron_->SetAccessibleName( | 144 if (!extensions::FeatureSwitch::extension_action_redesign()->IsEnabled()) { |
| 133 l10n_util::GetStringUTF16(IDS_ACCNAME_EXTENSIONS_CHEVRON)); | 145 chevron_ = new ChevronMenuButton(NULL, base::string16(), this, false); |
| 134 chevron_->SetVisible(false); | 146 chevron_->SetBorder(views::Border::NullBorder()); |
| 135 AddChildView(chevron_); | 147 chevron_->EnableCanvasFlippingForRTLUI(true); |
| 148 chevron_->SetAccessibleName( | |
| 149 l10n_util::GetStringUTF16(IDS_ACCNAME_EXTENSIONS_CHEVRON)); | |
| 150 chevron_->SetVisible(false); | |
| 151 AddChildView(chevron_); | |
| 152 } | |
| 153 } | |
| 136 } | 154 } |
| 137 | 155 |
| 138 BrowserActionsContainer::~BrowserActionsContainer() { | 156 BrowserActionsContainer::~BrowserActionsContainer() { |
| 139 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, | 157 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, |
| 140 observers_, | 158 observers_, |
| 141 OnBrowserActionsContainerDestroyed()); | 159 OnBrowserActionsContainerDestroyed()); |
| 142 | 160 |
| 143 if (overflow_menu_) | 161 if (overflow_menu_) |
| 144 overflow_menu_->set_observer(NULL); | 162 overflow_menu_->set_observer(NULL); |
| 145 if (model_) | 163 if (model_) |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 226 void BrowserActionsContainer::ExecuteExtensionCommand( | 244 void BrowserActionsContainer::ExecuteExtensionCommand( |
| 227 const extensions::Extension* extension, | 245 const extensions::Extension* extension, |
| 228 const extensions::Command& command) { | 246 const extensions::Command& command) { |
| 229 // Global commands are handled by the ExtensionCommandsGlobalRegistry | 247 // Global commands are handled by the ExtensionCommandsGlobalRegistry |
| 230 // instance. | 248 // instance. |
| 231 DCHECK(!command.global()); | 249 DCHECK(!command.global()); |
| 232 extension_keybinding_registry_->ExecuteCommand(extension->id(), | 250 extension_keybinding_registry_->ExecuteCommand(extension->id(), |
| 233 command.accelerator()); | 251 command.accelerator()); |
| 234 } | 252 } |
| 235 | 253 |
| 254 bool BrowserActionsContainer::ShownInsideMenu() const { | |
| 255 return is_slave(); | |
| 256 } | |
| 257 | |
| 236 void BrowserActionsContainer::AddObserver( | 258 void BrowserActionsContainer::AddObserver( |
| 237 BrowserActionsContainerObserver* observer) { | 259 BrowserActionsContainerObserver* observer) { |
| 238 observers_.AddObserver(observer); | 260 observers_.AddObserver(observer); |
| 239 } | 261 } |
| 240 | 262 |
| 241 void BrowserActionsContainer::RemoveObserver( | 263 void BrowserActionsContainer::RemoveObserver( |
| 242 BrowserActionsContainerObserver* observer) { | 264 BrowserActionsContainerObserver* observer) { |
| 243 observers_.RemoveObserver(observer); | 265 observers_.RemoveObserver(observer); |
| 244 } | 266 } |
| 245 | 267 |
| 246 gfx::Size BrowserActionsContainer::GetPreferredSize() const { | 268 gfx::Size BrowserActionsContainer::GetPreferredSize() const { |
| 247 // We calculate the size of the view by taking the current width and | 269 size_t our_icon_count = browser_action_views_.size() - |
| 248 // subtracting resize_amount_ (the latter represents how far the user is | 270 (is_slave() ? master_->VisibleBrowserActions() : 0); |
|
Devlin
2014/06/23 17:55:28
I'm a little nervous about how master and slave ea
Finnur
2014/06/25 16:18:11
Yeah, I know. But I think there are complexities e
| |
| 249 // resizing the view or, if animating the snapping, how far to animate it). | 271 |
| 250 // But we also clamp it to a minimum size and the maximum size, so that the | 272 // If there are no actions to show, or master is already showing them all, |
| 251 // container can never shrink too far or take up more space than it needs. In | 273 // then no further work is required. |
| 252 // other words: MinimumNonemptyWidth() < width() - resize < ClampTo(MAX). | 274 if (browser_action_views_.empty() || our_icon_count == 0) |
| 253 int preferred_width = std::min( | 275 return gfx::Size(); |
| 254 std::max(MinimumNonemptyWidth(), container_width_ - resize_amount_), | 276 |
| 255 IconCountToWidth(-1, false)); | 277 if (is_slave()) { |
| 256 // Height will be ignored by the ToolbarView. | 278 return gfx::Size( |
| 257 return gfx::Size(preferred_width, 0); | 279 IconCountToWidth(kIconsPerMenuRow, false), |
| 280 (std::max(((our_icon_count - 1) / kIconsPerMenuRow), 0U) + 1) * | |
|
Devlin
2014/06/23 17:55:29
I think you'll get a compile error here on pickier
Finnur
2014/06/25 16:18:11
Good point.
Devlin
2014/06/26 00:04:07
I don't see a change for this...?
Finnur
2014/06/26 12:00:44
Somehow forgot to upload it. Should be done now.
| |
| 281 IconHeight()); | |
| 282 } else { | |
|
Devlin
2014/06/23 17:55:28
nit: no need for the else after a return.
| |
| 283 // We calculate the size of the view by taking the current width and | |
| 284 // subtracting resize_amount_ (the latter represents how far the user is | |
| 285 // resizing the view or, if animating the snapping, how far to animate it). | |
| 286 // But we also clamp it to a minimum size and the maximum size, so that the | |
| 287 // container can never shrink too far or take up more space than it needs. | |
| 288 // In other words: MinimumNonemptyWidth() < width() - resize < ClampTo(MAX). | |
| 289 int preferred_width = std::min( | |
| 290 std::max(MinimumNonemptyWidth(), container_width_ - resize_amount_), | |
| 291 IconCountToWidth(-1, false)); | |
| 292 return gfx::Size(preferred_width, IconHeight()); | |
| 293 } | |
| 258 } | 294 } |
| 259 | 295 |
| 260 gfx::Size BrowserActionsContainer::GetMinimumSize() const { | 296 gfx::Size BrowserActionsContainer::GetMinimumSize() const { |
| 261 int min_width = std::min(MinimumNonemptyWidth(), IconCountToWidth(-1, false)); | 297 int min_width = std::min(MinimumNonemptyWidth(), IconCountToWidth(-1, false)); |
| 262 // Height will be ignored by the ToolbarView. | 298 return gfx::Size(min_width, IconHeight()); |
| 263 return gfx::Size(min_width, 0); | |
| 264 } | 299 } |
| 265 | 300 |
| 266 void BrowserActionsContainer::Layout() { | 301 void BrowserActionsContainer::Layout() { |
| 267 if (browser_action_views_.empty()) { | 302 if (browser_action_views_.empty()) { |
| 268 SetVisible(false); | 303 SetVisible(false); |
| 269 return; | 304 return; |
| 270 } | 305 } |
| 271 | 306 |
| 272 SetVisible(true); | 307 SetVisible(true); |
| 273 resize_area_->SetBounds(0, 0, kItemSpacing, height()); | 308 if (resize_area_) |
| 309 resize_area_->SetBounds(0, 0, kItemSpacing, height()); | |
| 274 | 310 |
| 275 // If the icons don't all fit, show the chevron (unless suppressed). | 311 // If the icons don't all fit, show the chevron (unless suppressed). |
| 276 int max_x = GetPreferredSize().width(); | 312 int max_x = GetPreferredSize().width(); |
| 277 if ((IconCountToWidth(-1, false) > max_x) && !suppress_chevron_) { | 313 if ((IconCountToWidth(-1, false) > max_x) && !suppress_chevron_ && chevron_) { |
| 278 chevron_->SetVisible(true); | 314 chevron_->SetVisible(true); |
| 279 gfx::Size chevron_size(chevron_->GetPreferredSize()); | 315 gfx::Size chevron_size(chevron_->GetPreferredSize()); |
| 280 max_x -= | 316 max_x -= |
| 281 ToolbarView::kStandardSpacing + chevron_size.width() + kChevronSpacing; | 317 ToolbarView::kStandardSpacing + chevron_size.width() + kChevronSpacing; |
| 282 chevron_->SetBounds( | 318 chevron_->SetBounds( |
| 283 width() - ToolbarView::kStandardSpacing - chevron_size.width(), | 319 width() - ToolbarView::kStandardSpacing - chevron_size.width(), |
| 284 0, | 320 0, |
| 285 chevron_size.width(), | 321 chevron_size.width(), |
| 286 chevron_size.height()); | 322 chevron_size.height()); |
| 287 } else { | 323 } else { |
| 288 chevron_->SetVisible(false); | 324 if (chevron_) |
|
Devlin
2014/06/23 17:55:29
nit: else if (chevron_) {
| |
| 325 chevron_->SetVisible(false); | |
| 289 } | 326 } |
| 290 | 327 |
| 291 // Now draw the icons for the browser actions in the available space. | 328 // Now draw the icons for the browser actions in the available space. |
| 292 int icon_width = IconWidth(false); | 329 int icon_width = IconWidth(false); |
| 293 for (size_t i = 0; i < browser_action_views_.size(); ++i) { | 330 if (is_slave()) { |
| 294 BrowserActionView* view = browser_action_views_[i]; | 331 size_t our_icon_count = |
| 295 int x = ToolbarView::kStandardSpacing + (i * IconWidth(true)); | 332 browser_action_views_.size() - master_->VisibleBrowserActions(); |
| 296 if (x + icon_width <= max_x) { | 333 for (size_t i = 0; i < our_icon_count; ++i) { |
| 297 view->SetBounds(x, 0, icon_width, height()); | 334 BrowserActionView* view = |
| 335 browser_action_views_[i + master_->VisibleBrowserActions()]; | |
| 336 int x = ToolbarView::kStandardSpacing + i * IconWidth(true) - | |
| 337 ((i / kIconsPerMenuRow) * (IconWidth(true) * kIconsPerMenuRow)); | |
| 338 gfx::Rect rect_bounds( | |
| 339 x, | |
| 340 IconHeight() * | |
| 341 (std::max((static_cast<int>(i) / kIconsPerMenuRow), 0)), | |
| 342 icon_width, | |
| 343 IconHeight() + kPaddingForBadge); | |
| 344 view->SetBoundsRect(rect_bounds); | |
| 298 view->SetVisible(true); | 345 view->SetVisible(true); |
| 299 } else { | 346 } |
| 300 view->SetVisible(false); | 347 } else { |
| 348 for (size_t i = 0; i < browser_action_views_.size(); ++i) { | |
| 349 BrowserActionView* view = browser_action_views_[i]; | |
| 350 int x = ToolbarView::kStandardSpacing + (i * IconWidth(true)); | |
| 351 if (x + icon_width <= max_x) { | |
| 352 view->SetBounds(x, 0, icon_width, IconHeight()); | |
| 353 view->SetVisible(true); | |
| 354 } else { | |
| 355 view->SetVisible(false); | |
| 356 } | |
| 301 } | 357 } |
| 302 } | 358 } |
| 303 } | 359 } |
| 304 | 360 |
| 305 bool BrowserActionsContainer::GetDropFormats( | 361 bool BrowserActionsContainer::GetDropFormats( |
| 306 int* formats, | 362 int* formats, |
| 307 std::set<OSExchangeData::CustomFormat>* custom_formats) { | 363 std::set<OSExchangeData::CustomFormat>* custom_formats) { |
| 308 custom_formats->insert(BrowserActionDragData::GetBrowserActionCustomFormat()); | 364 custom_formats->insert(BrowserActionDragData::GetBrowserActionCustomFormat()); |
| 309 | 365 |
| 310 return true; | 366 return true; |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 549 return SessionTabHelper::FromWebContents(active_tab)->session_id().id(); | 605 return SessionTabHelper::FromWebContents(active_tab)->session_id().id(); |
| 550 } | 606 } |
| 551 | 607 |
| 552 void BrowserActionsContainer::OnBrowserActionExecuted( | 608 void BrowserActionsContainer::OnBrowserActionExecuted( |
| 553 BrowserActionButton* button) { | 609 BrowserActionButton* button) { |
| 554 ShowPopup(button, ExtensionPopup::SHOW, true); | 610 ShowPopup(button, ExtensionPopup::SHOW, true); |
| 555 } | 611 } |
| 556 | 612 |
| 557 void BrowserActionsContainer::OnBrowserActionVisibilityChanged() { | 613 void BrowserActionsContainer::OnBrowserActionVisibilityChanged() { |
| 558 SetVisible(!browser_action_views_.empty()); | 614 SetVisible(!browser_action_views_.empty()); |
| 559 owner_view_->Layout(); | 615 if (owner_view_) { |
| 560 owner_view_->SchedulePaint(); | 616 owner_view_->Layout(); |
| 617 owner_view_->SchedulePaint(); | |
| 618 } | |
| 561 } | 619 } |
| 562 | 620 |
| 563 extensions::ActiveTabPermissionGranter* | 621 extensions::ActiveTabPermissionGranter* |
| 564 BrowserActionsContainer::GetActiveTabPermissionGranter() { | 622 BrowserActionsContainer::GetActiveTabPermissionGranter() { |
| 565 content::WebContents* web_contents = | 623 content::WebContents* web_contents = |
| 566 browser_->tab_strip_model()->GetActiveWebContents(); | 624 browser_->tab_strip_model()->GetActiveWebContents(); |
| 567 if (!web_contents) | 625 if (!web_contents) |
| 568 return NULL; | 626 return NULL; |
| 569 return extensions::TabHelper::FromWebContents(web_contents)-> | 627 return extensions::TabHelper::FromWebContents(web_contents)-> |
| 570 active_tab_permission_granter(); | 628 active_tab_permission_granter(); |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 758 | 816 |
| 759 if (browser_action_views_.size() > visible_actions) { | 817 if (browser_action_views_.size() > visible_actions) { |
| 760 // If we have more icons than we can show, then we must not be changing | 818 // If we have more icons than we can show, then we must not be changing |
| 761 // the container size (since we either removed an icon from the main | 819 // the container size (since we either removed an icon from the main |
| 762 // area and one from the overflow list will have shifted in, or we | 820 // area and one from the overflow list will have shifted in, or we |
| 763 // removed an entry directly from the overflow list). | 821 // removed an entry directly from the overflow list). |
| 764 OnBrowserActionVisibilityChanged(); | 822 OnBrowserActionVisibilityChanged(); |
| 765 } else { | 823 } else { |
| 766 // Either we went from overflow to no-overflow, or we shrunk the no- | 824 // Either we went from overflow to no-overflow, or we shrunk the no- |
| 767 // overflow container by 1. Either way the size changed, so animate. | 825 // overflow container by 1. Either way the size changed, so animate. |
| 768 chevron_->SetVisible(false); | 826 if (chevron_) |
| 827 chevron_->SetVisible(false); | |
| 769 SaveDesiredSizeAndAnimate(gfx::Tween::EASE_OUT, | 828 SaveDesiredSizeAndAnimate(gfx::Tween::EASE_OUT, |
| 770 browser_action_views_.size()); | 829 browser_action_views_.size()); |
| 771 } | 830 } |
| 772 return; | 831 return; |
|
Devlin
2014/06/23 17:55:29
Obviously not this patch's code, but this return l
Finnur
2014/06/24 17:00:49
No, we want only one action to get deleted (it is
| |
| 773 } | 832 } |
| 774 } | 833 } |
| 775 } | 834 } |
| 776 | 835 |
| 777 void BrowserActionsContainer::BrowserActionMoved(const Extension* extension, | 836 void BrowserActionsContainer::BrowserActionMoved(const Extension* extension, |
| 778 int index) { | 837 int index) { |
| 779 if (!ShouldDisplayBrowserAction(extension)) | 838 if (!ShouldDisplayBrowserAction(extension)) |
| 780 return; | 839 return; |
| 781 | 840 |
| 782 if (profile_->IsOffTheRecord()) | 841 if (profile_->IsOffTheRecord()) |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 804 // we delete and recreate everything here, but that's how it's done in | 863 // we delete and recreate everything here, but that's how it's done in |
| 805 // BrowserActionMoved(), too. If we want to optimize it, we could move the | 864 // BrowserActionMoved(), too. If we want to optimize it, we could move the |
| 806 // existing icons, instead of deleting it all. | 865 // existing icons, instead of deleting it all. |
| 807 DeleteBrowserActionViews(); | 866 DeleteBrowserActionViews(); |
| 808 CreateBrowserActionViews(); | 867 CreateBrowserActionViews(); |
| 809 SaveDesiredSizeAndAnimate(gfx::Tween::LINEAR, browser_action_views_.size()); | 868 SaveDesiredSizeAndAnimate(gfx::Tween::LINEAR, browser_action_views_.size()); |
| 810 } | 869 } |
| 811 | 870 |
| 812 void BrowserActionsContainer::LoadImages() { | 871 void BrowserActionsContainer::LoadImages() { |
| 813 ui::ThemeProvider* tp = GetThemeProvider(); | 872 ui::ThemeProvider* tp = GetThemeProvider(); |
| 814 chevron_->SetImage(views::Button::STATE_NORMAL, | 873 if (tp && chevron_) { |
|
Devlin
2014/06/23 17:55:29
maybe instead:
if (!tp || !chevron)
return;
...
| |
| 815 *tp->GetImageSkiaNamed(IDR_BROWSER_ACTIONS_OVERFLOW)); | 874 chevron_->SetImage(views::Button::STATE_NORMAL, |
| 875 *tp->GetImageSkiaNamed(IDR_BROWSER_ACTIONS_OVERFLOW)); | |
| 816 | 876 |
| 817 const int kImages[] = IMAGE_GRID(IDR_DEVELOPER_MODE_HIGHLIGHT); | 877 const int kImages[] = IMAGE_GRID(IDR_DEVELOPER_MODE_HIGHLIGHT); |
| 818 highlight_painter_.reset(views::Painter::CreateImageGridPainter(kImages)); | 878 highlight_painter_.reset(views::Painter::CreateImageGridPainter(kImages)); |
| 879 } | |
| 819 } | 880 } |
| 820 | 881 |
| 821 void BrowserActionsContainer::SetContainerWidth() { | 882 void BrowserActionsContainer::SetContainerWidth() { |
| 822 int visible_actions = model_->GetVisibleIconCount(); | 883 // The slave only draws the overflow (what isn't visible in the other |
| 884 // container). | |
| 885 int visible_actions = is_slave() ? model_->toolbar_items().size() - | |
| 886 model_->GetVisibleIconCount() | |
| 887 : model_->GetVisibleIconCount(); | |
| 823 if (visible_actions < 0) // All icons should be visible. | 888 if (visible_actions < 0) // All icons should be visible. |
| 824 visible_actions = model_->toolbar_items().size(); | 889 visible_actions = model_->toolbar_items().size(); |
| 825 chevron_->SetVisible( | 890 if (chevron_) { |
| 826 static_cast<size_t>(visible_actions) < model_->toolbar_items().size()); | 891 chevron_->SetVisible( |
| 827 container_width_ = IconCountToWidth(visible_actions, chevron_->visible()); | 892 static_cast<size_t>(visible_actions) < model_->toolbar_items().size()); |
| 893 } | |
| 894 container_width_ = | |
| 895 IconCountToWidth(visible_actions, chevron_ ? chevron_->visible() : false); | |
| 828 } | 896 } |
| 829 | 897 |
| 830 void BrowserActionsContainer::CloseOverflowMenu() { | 898 void BrowserActionsContainer::CloseOverflowMenu() { |
| 831 if (overflow_menu_) | 899 if (overflow_menu_) |
| 832 overflow_menu_->CancelMenu(); | 900 overflow_menu_->CancelMenu(); |
| 833 } | 901 } |
| 834 | 902 |
| 835 void BrowserActionsContainer::StopShowFolderDropMenuTimer() { | 903 void BrowserActionsContainer::StopShowFolderDropMenuTimer() { |
| 836 show_menu_task_factory_.InvalidateWeakPtrs(); | 904 show_menu_task_factory_.InvalidateWeakPtrs(); |
| 837 } | 905 } |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 861 } | 929 } |
| 862 | 930 |
| 863 int BrowserActionsContainer::IconCountToWidth(int icons, | 931 int BrowserActionsContainer::IconCountToWidth(int icons, |
| 864 bool display_chevron) const { | 932 bool display_chevron) const { |
| 865 if (icons < 0) | 933 if (icons < 0) |
| 866 icons = browser_action_views_.size(); | 934 icons = browser_action_views_.size(); |
| 867 if ((icons == 0) && !display_chevron) | 935 if ((icons == 0) && !display_chevron) |
| 868 return ToolbarView::kStandardSpacing; | 936 return ToolbarView::kStandardSpacing; |
| 869 int icons_size = | 937 int icons_size = |
| 870 (icons == 0) ? 0 : ((icons * IconWidth(true)) - kItemSpacing); | 938 (icons == 0) ? 0 : ((icons * IconWidth(true)) - kItemSpacing); |
| 871 int chevron_size = display_chevron ? | 939 int chevron_size = chevron_ && display_chevron ? |
| 872 (kChevronSpacing + chevron_->GetPreferredSize().width()) : 0; | 940 (kChevronSpacing + chevron_->GetPreferredSize().width()) : 0; |
| 873 return ToolbarView::kStandardSpacing + icons_size + chevron_size + | 941 return ToolbarView::kStandardSpacing + icons_size + chevron_size + |
| 874 ToolbarView::kStandardSpacing; | 942 ToolbarView::kStandardSpacing; |
| 875 } | 943 } |
| 876 | 944 |
| 877 size_t BrowserActionsContainer::WidthToIconCount(int pixels) const { | 945 size_t BrowserActionsContainer::WidthToIconCount(int pixels) const { |
| 878 // Check for widths large enough to show the entire icon set. | 946 // Check for widths large enough to show the entire icon set. |
| 879 if (pixels >= IconCountToWidth(-1, false)) | 947 if (pixels >= IconCountToWidth(-1, false)) |
| 880 return browser_action_views_.size(); | 948 return browser_action_views_.size(); |
| 881 | 949 |
| 882 // We need to reserve space for the resize area, chevron, and the spacing on | 950 // We need to reserve space for the resize area, chevron, and the spacing on |
| 883 // either side of the chevron. | 951 // either side of the chevron. |
| 884 int available_space = pixels - ToolbarView::kStandardSpacing - | 952 int available_space = pixels - ToolbarView::kStandardSpacing - |
| 885 chevron_->GetPreferredSize().width() - kChevronSpacing - | 953 (chevron_ ? chevron_->GetPreferredSize().width() : 0) - |
| 886 ToolbarView::kStandardSpacing; | 954 kChevronSpacing - ToolbarView::kStandardSpacing; |
| 887 // Now we add an extra between-item padding value so the space can be divided | 955 // Now we add an extra between-item padding value so the space can be divided |
| 888 // evenly by (size of icon with padding). | 956 // evenly by (size of icon with padding). |
| 889 return static_cast<size_t>( | 957 return static_cast<size_t>( |
| 890 std::max(0, available_space + kItemSpacing) / IconWidth(true)); | 958 std::max(0, available_space + kItemSpacing) / IconWidth(true)); |
| 891 } | 959 } |
| 892 | 960 |
| 893 int BrowserActionsContainer::MinimumNonemptyWidth() const { | 961 int BrowserActionsContainer::MinimumNonemptyWidth() const { |
| 894 return ToolbarView::kStandardSpacing + kChevronSpacing + | 962 return ToolbarView::kStandardSpacing + |
| 895 chevron_->GetPreferredSize().width() + ToolbarView::kStandardSpacing; | 963 (chevron_ ? (kChevronSpacing + chevron_->GetPreferredSize().width() + |
| 964 ToolbarView::kStandardSpacing) | |
| 965 : 0); | |
| 896 } | 966 } |
| 897 | 967 |
| 898 void BrowserActionsContainer::SaveDesiredSizeAndAnimate( | 968 void BrowserActionsContainer::SaveDesiredSizeAndAnimate( |
| 899 gfx::Tween::Type tween_type, | 969 gfx::Tween::Type tween_type, |
| 900 size_t num_visible_icons) { | 970 size_t num_visible_icons) { |
| 901 // Save off the desired number of visible icons. We do this now instead of at | 971 // Save off the desired number of visible icons. We do this now instead of at |
| 902 // the end of the animation so that even if the browser is shut down while | 972 // the end of the animation so that even if the browser is shut down while |
| 903 // animating, the right value will be restored on next run. | 973 // animating, the right value will be restored on next run. |
| 904 // NOTE: Don't save the icon count in incognito because there may be fewer | 974 // NOTE: Don't save the icon count in incognito because there may be fewer |
| 905 // icons in that mode. The result is that the container in a normal window is | 975 // icons in that mode. The result is that the container in a normal window is |
| 906 // always at least as wide as in an incognito window. | 976 // always at least as wide as in an incognito window. |
| 907 if (!profile_->IsOffTheRecord()) | 977 if (!profile_->IsOffTheRecord()) |
| 908 model_->SetVisibleIconCount(num_visible_icons); | 978 model_->SetVisibleIconCount(num_visible_icons); |
| 909 int target_size = IconCountToWidth(num_visible_icons, | 979 int target_size = IconCountToWidth(num_visible_icons, |
| 910 num_visible_icons < browser_action_views_.size()); | 980 num_visible_icons < browser_action_views_.size()); |
| 911 if (!disable_animations_during_testing_) { | 981 if (resize_animation_ && !disable_animations_during_testing_) { |
| 912 // Animate! We have to set the animation_target_size_ after calling Reset(), | 982 // Animate! We have to set the animation_target_size_ after calling Reset(), |
| 913 // because that could end up calling AnimationEnded which clears the value. | 983 // because that could end up calling AnimationEnded which clears the value. |
| 914 resize_animation_->Reset(); | 984 resize_animation_->Reset(); |
| 915 resize_animation_->SetTweenType(tween_type); | 985 resize_animation_->SetTweenType(tween_type); |
| 916 animation_target_size_ = target_size; | 986 animation_target_size_ = target_size; |
| 917 resize_animation_->Show(); | 987 resize_animation_->Show(); |
| 918 } else { | 988 } else { |
| 919 animation_target_size_ = target_size; | 989 animation_target_size_ = target_size; |
| 920 AnimationEnded(resize_animation_.get()); | 990 AnimationEnded(resize_animation_.get()); |
| 921 } | 991 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 958 views::BubbleBorder::TOP_RIGHT, | 1028 views::BubbleBorder::TOP_RIGHT, |
| 959 show_action); | 1029 show_action); |
| 960 popup_->GetWidget()->AddObserver(this); | 1030 popup_->GetWidget()->AddObserver(this); |
| 961 popup_button_ = button; | 1031 popup_button_ = button; |
| 962 | 1032 |
| 963 // Only set button as pushed if it was triggered by a user click. | 1033 // Only set button as pushed if it was triggered by a user click. |
| 964 if (should_grant) | 1034 if (should_grant) |
| 965 popup_button_->SetButtonPushed(); | 1035 popup_button_->SetButtonPushed(); |
| 966 return true; | 1036 return true; |
| 967 } | 1037 } |
| OLD | NEW |