OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/extensions/browser_action_overflow_menu_contro
ller.h" | 5 #include "chrome/browser/ui/views/extensions/browser_action_overflow_menu_contro
ller.h" |
6 | 6 |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/extensions/extension_action.h" | 9 #include "chrome/browser/extensions/extension_action.h" |
10 #include "chrome/browser/extensions/extension_context_menu_model.h" | 10 #include "chrome/browser/extensions/extension_context_menu_model.h" |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 return ui::DragDropTypes::DRAG_NONE; | 220 return ui::DragDropTypes::DRAG_NONE; |
221 | 221 |
222 size_t drop_index = IndexForId(menu->GetCommand()); | 222 size_t drop_index = IndexForId(menu->GetCommand()); |
223 | 223 |
224 // When not dragging within the overflow menu (dragging an icon into the menu) | 224 // When not dragging within the overflow menu (dragging an icon into the menu) |
225 // subtract one to get the right index. | 225 // subtract one to get the right index. |
226 if (position == DROP_BEFORE && | 226 if (position == DROP_BEFORE && |
227 drop_data.index() < owner_->VisibleBrowserActions()) | 227 drop_data.index() < owner_->VisibleBrowserActions()) |
228 --drop_index; | 228 --drop_index; |
229 | 229 |
| 230 // Move the extension in the model. |
230 const extensions::Extension* extension = | 231 const extensions::Extension* extension = |
231 extensions::ExtensionRegistry::Get(browser_->profile())-> | 232 extensions::ExtensionRegistry::Get(browser_->profile())-> |
232 enabled_extensions().GetByID(drop_data.id()); | 233 enabled_extensions().GetByID(drop_data.id()); |
233 extensions::ExtensionToolbarModel::Get(browser_->profile())-> | 234 extensions::ExtensionToolbarModel* toolbar_model = |
234 MoveExtensionIcon(extension, drop_index); | 235 extensions::ExtensionToolbarModel::Get(browser_->profile()); |
| 236 if (browser_->profile()->IsOffTheRecord()) |
| 237 drop_index = toolbar_model->IncognitoIndexToOriginal(drop_index); |
| 238 toolbar_model->MoveExtensionIcon(extension, drop_index); |
| 239 |
| 240 // If the extension was moved to the overflow menu from the main bar, notify |
| 241 // the owner. |
| 242 if (drop_index >= owner_->VisibleBrowserActions()) |
| 243 owner_->NotifyActionMovedToOverflow(); |
235 | 244 |
236 if (for_drop_) | 245 if (for_drop_) |
237 delete this; | 246 delete this; |
238 return ui::DragDropTypes::DRAG_MOVE; | 247 return ui::DragDropTypes::DRAG_MOVE; |
239 } | 248 } |
240 | 249 |
241 bool BrowserActionOverflowMenuController::CanDrag(views::MenuItemView* menu) { | 250 bool BrowserActionOverflowMenuController::CanDrag(views::MenuItemView* menu) { |
242 return true; | 251 return true; |
243 } | 252 } |
244 | 253 |
245 void BrowserActionOverflowMenuController::WriteDragData( | 254 void BrowserActionOverflowMenuController::WriteDragData( |
246 views::MenuItemView* sender, OSExchangeData* data) { | 255 views::MenuItemView* sender, OSExchangeData* data) { |
247 size_t drag_index = IndexForId(sender->GetCommand()); | 256 size_t drag_index = IndexForId(sender->GetCommand()); |
248 const extensions::Extension* extension = views_[drag_index]->extension(); | 257 const extensions::Extension* extension = views_[drag_index]->extension(); |
249 BrowserActionDragData drag_data(extension->id(), drag_index); | 258 BrowserActionDragData drag_data(extension->id(), drag_index); |
250 drag_data.Write(owner_->profile(), data); | 259 drag_data.Write(owner_->profile(), data); |
251 } | 260 } |
252 | 261 |
253 int BrowserActionOverflowMenuController::GetDragOperations( | 262 int BrowserActionOverflowMenuController::GetDragOperations( |
254 views::MenuItemView* sender) { | 263 views::MenuItemView* sender) { |
255 return ui::DragDropTypes::DRAG_MOVE; | 264 return ui::DragDropTypes::DRAG_MOVE; |
256 } | 265 } |
257 | 266 |
258 size_t BrowserActionOverflowMenuController::IndexForId(int id) const { | 267 size_t BrowserActionOverflowMenuController::IndexForId(int id) const { |
259 // The index of the view being dragged (GetCommand gives a 1-based index into | 268 // The index of the view being dragged (GetCommand gives a 1-based index into |
260 // the overflow menu). | 269 // the overflow menu). |
261 DCHECK_GT(owner_->VisibleBrowserActions() + id, 0u); | 270 DCHECK_GT(owner_->VisibleBrowserActions() + id, 0u); |
262 return owner_->VisibleBrowserActions() + id - 1; | 271 return owner_->VisibleBrowserActions() + id - 1; |
263 } | 272 } |
OLD | NEW |