| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/browser_actions_container.h" | 5 #include "chrome/browser/ui/views/browser_actions_container.h" |
| 6 | 6 |
| 7 #include "base/bind.h" |
| 7 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 8 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 9 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/extensions/extension_browser_event_router.h" | 11 #include "chrome/browser/extensions/extension_browser_event_router.h" |
| 11 #include "chrome/browser/extensions/extension_host.h" | 12 #include "chrome/browser/extensions/extension_host.h" |
| 12 #include "chrome/browser/extensions/extension_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
| 13 #include "chrome/browser/extensions/extension_tabs_module.h" | 14 #include "chrome/browser/extensions/extension_tabs_module.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/sessions/restore_tab_helper.h" | 16 #include "chrome/browser/sessions/restore_tab_helper.h" |
| 16 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
| (...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 } | 596 } |
| 596 | 597 |
| 597 void BrowserActionsContainer::OnDragEntered( | 598 void BrowserActionsContainer::OnDragEntered( |
| 598 const views::DropTargetEvent& event) { | 599 const views::DropTargetEvent& event) { |
| 599 } | 600 } |
| 600 | 601 |
| 601 int BrowserActionsContainer::OnDragUpdated( | 602 int BrowserActionsContainer::OnDragUpdated( |
| 602 const views::DropTargetEvent& event) { | 603 const views::DropTargetEvent& event) { |
| 603 // First check if we are above the chevron (overflow) menu. | 604 // First check if we are above the chevron (overflow) menu. |
| 604 if (GetEventHandlerForPoint(event.location()) == chevron_) { | 605 if (GetEventHandlerForPoint(event.location()) == chevron_) { |
| 605 if (show_menu_task_factory_.empty() && !overflow_menu_) | 606 if (!show_menu_task_factory_.HasWeakPtrs() && !overflow_menu_) |
| 606 StartShowFolderDropMenuTimer(); | 607 StartShowFolderDropMenuTimer(); |
| 607 return ui::DragDropTypes::DRAG_MOVE; | 608 return ui::DragDropTypes::DRAG_MOVE; |
| 608 } | 609 } |
| 609 StopShowFolderDropMenuTimer(); | 610 StopShowFolderDropMenuTimer(); |
| 610 | 611 |
| 611 // Figure out where to display the indicator. This is a complex calculation: | 612 // Figure out where to display the indicator. This is a complex calculation: |
| 612 | 613 |
| 613 // First, we figure out how much space is to the left of the icon area, so we | 614 // First, we figure out how much space is to the left of the icon area, so we |
| 614 // can calculate the true offset into the icon area. | 615 // can calculate the true offset into the icon area. |
| 615 int width_before_icons = ToolbarView::kStandardSpacing + | 616 int width_before_icons = ToolbarView::kStandardSpacing + |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1004 chevron_->SetVisible(static_cast<size_t>(visible_actions) < model_->size()); | 1005 chevron_->SetVisible(static_cast<size_t>(visible_actions) < model_->size()); |
| 1005 container_width_ = IconCountToWidth(visible_actions, chevron_->IsVisible()); | 1006 container_width_ = IconCountToWidth(visible_actions, chevron_->IsVisible()); |
| 1006 } | 1007 } |
| 1007 | 1008 |
| 1008 void BrowserActionsContainer::CloseOverflowMenu() { | 1009 void BrowserActionsContainer::CloseOverflowMenu() { |
| 1009 if (overflow_menu_) | 1010 if (overflow_menu_) |
| 1010 overflow_menu_->CancelMenu(); | 1011 overflow_menu_->CancelMenu(); |
| 1011 } | 1012 } |
| 1012 | 1013 |
| 1013 void BrowserActionsContainer::StopShowFolderDropMenuTimer() { | 1014 void BrowserActionsContainer::StopShowFolderDropMenuTimer() { |
| 1014 show_menu_task_factory_.RevokeAll(); | 1015 show_menu_task_factory_.InvalidateWeakPtrs(); |
| 1015 } | 1016 } |
| 1016 | 1017 |
| 1017 void BrowserActionsContainer::StartShowFolderDropMenuTimer() { | 1018 void BrowserActionsContainer::StartShowFolderDropMenuTimer() { |
| 1018 int delay = views::GetMenuShowDelay(); | 1019 int delay = views::GetMenuShowDelay(); |
| 1019 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 1020 MessageLoop::current()->PostDelayedTask( |
| 1020 show_menu_task_factory_.NewRunnableMethod( | 1021 FROM_HERE, |
| 1021 &BrowserActionsContainer::ShowDropFolder), | 1022 base::Bind(&BrowserActionsContainer::ShowDropFolder, |
| 1023 show_menu_task_factory_.GetWeakPtr()), |
| 1022 delay); | 1024 delay); |
| 1023 } | 1025 } |
| 1024 | 1026 |
| 1025 void BrowserActionsContainer::ShowDropFolder() { | 1027 void BrowserActionsContainer::ShowDropFolder() { |
| 1026 DCHECK(!overflow_menu_); | 1028 DCHECK(!overflow_menu_); |
| 1027 SetDropIndicator(-1); | 1029 SetDropIndicator(-1); |
| 1028 overflow_menu_ = new BrowserActionOverflowMenuController( | 1030 overflow_menu_ = new BrowserActionOverflowMenuController( |
| 1029 this, chevron_, browser_action_views_, VisibleBrowserActions()); | 1031 this, chevron_, browser_action_views_, VisibleBrowserActions()); |
| 1030 overflow_menu_->set_observer(this); | 1032 overflow_menu_->set_observer(this); |
| 1031 overflow_menu_->RunMenu(GetWidget(), true); | 1033 overflow_menu_->RunMenu(GetWidget(), true); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1100 } | 1102 } |
| 1101 } | 1103 } |
| 1102 | 1104 |
| 1103 bool BrowserActionsContainer::ShouldDisplayBrowserAction( | 1105 bool BrowserActionsContainer::ShouldDisplayBrowserAction( |
| 1104 const Extension* extension) { | 1106 const Extension* extension) { |
| 1105 // Only display incognito-enabled extensions while in incognito mode. | 1107 // Only display incognito-enabled extensions while in incognito mode. |
| 1106 return | 1108 return |
| 1107 (!profile_->IsOffTheRecord() || | 1109 (!profile_->IsOffTheRecord() || |
| 1108 profile_->GetExtensionService()->IsIncognitoEnabled(extension->id())); | 1110 profile_->GetExtensionService()->IsIncognitoEnabled(extension->id())); |
| 1109 } | 1111 } |
| OLD | NEW |