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 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller.h" | 5 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller.h" |
6 | 6 |
7 #include "base/mac/bundle_locations.h" | 7 #include "base/mac/bundle_locations.h" |
8 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
9 #import "chrome/browser/bookmarks/bookmark_model_factory.h" | 9 #import "chrome/browser/bookmarks/bookmark_model_factory.h" |
10 #import "chrome/browser/bookmarks/chrome_bookmark_client.h" | |
11 #import "chrome/browser/bookmarks/chrome_bookmark_client_factory.h" | |
12 #import "chrome/browser/profiles/profile.h" | 10 #import "chrome/browser/profiles/profile.h" |
13 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_constants.h" | 11 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_constants.h" |
14 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" | 12 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" |
15 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_button_cell.h" | 13 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_button_cell.h" |
16 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_hover_state.h" | 14 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_hover_state.h" |
17 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_view.h" | 15 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_view.h" |
18 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_window.h" | 16 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_window.h" |
19 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_folder_target.h" | 17 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_folder_target.h" |
20 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_menu_cocoa_controller.h" | 18 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_menu_cocoa_controller.h" |
21 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 19 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
(...skipping 1243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1265 // Drop it at the end. | 1263 // Drop it at the end. |
1266 destIndex = [button bookmarkNode]->child_count(); | 1264 destIndex = [button bookmarkNode]->child_count(); |
1267 } else { | 1265 } else { |
1268 // Else we're dropping somewhere in the folder, so find the right spot. | 1266 // Else we're dropping somewhere in the folder, so find the right spot. |
1269 destParent = [parentButton_ bookmarkNode]; | 1267 destParent = [parentButton_ bookmarkNode]; |
1270 destIndex = [self indexForDragToPoint:point]; | 1268 destIndex = [self indexForDragToPoint:point]; |
1271 // Be careful if the number of buttons != number of nodes. | 1269 // Be careful if the number of buttons != number of nodes. |
1272 destIndex += [[parentButton_ cell] startingChildIndex]; | 1270 destIndex += [[parentButton_ cell] startingChildIndex]; |
1273 } | 1271 } |
1274 | 1272 |
1275 ChromeBookmarkClient* client = | 1273 BookmarkModel* bookmarkModel = [self bookmarkModel]; |
1276 ChromeBookmarkClientFactory::GetForProfile(profile_); | 1274 if (!bookmarkModel->CanBeEditedByUser(destParent)) |
1277 if (!client->CanBeEditedByUser(destParent)) | |
1278 return NO; | 1275 return NO; |
1279 if (!client->CanBeEditedByUser(sourceNode)) | 1276 if (!bookmarkModel->CanBeEditedByUser(sourceNode)) |
1280 copy = YES; | 1277 copy = YES; |
1281 | 1278 |
1282 // Prevent cycles. | 1279 // Prevent cycles. |
1283 BOOL wasCopiedOrMoved = NO; | 1280 BOOL wasCopiedOrMoved = NO; |
1284 if (!destParent->HasAncestor(sourceNode)) { | 1281 if (!destParent->HasAncestor(sourceNode)) { |
1285 if (copy) | 1282 if (copy) |
1286 [self bookmarkModel]->Copy(sourceNode, destParent, destIndex); | 1283 [self bookmarkModel]->Copy(sourceNode, destParent, destIndex); |
1287 else | 1284 else |
1288 [self bookmarkModel]->Move(sourceNode, destParent, destIndex); | 1285 [self bookmarkModel]->Move(sourceNode, destParent, destIndex); |
1289 wasCopiedOrMoved = YES; | 1286 wasCopiedOrMoved = YES; |
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1835 // Drop it at the end. | 1832 // Drop it at the end. |
1836 destIndex = [button bookmarkNode]->child_count(); | 1833 destIndex = [button bookmarkNode]->child_count(); |
1837 } else { | 1834 } else { |
1838 // Else we're dropping somewhere in the folder, so find the right spot. | 1835 // Else we're dropping somewhere in the folder, so find the right spot. |
1839 destParent = [parentButton_ bookmarkNode]; | 1836 destParent = [parentButton_ bookmarkNode]; |
1840 destIndex = [self indexForDragToPoint:point]; | 1837 destIndex = [self indexForDragToPoint:point]; |
1841 // Be careful if the number of buttons != number of nodes. | 1838 // Be careful if the number of buttons != number of nodes. |
1842 destIndex += [[parentButton_ cell] startingChildIndex]; | 1839 destIndex += [[parentButton_ cell] startingChildIndex]; |
1843 } | 1840 } |
1844 | 1841 |
1845 ChromeBookmarkClient* client = | 1842 BookmarkModel* bookmarkModel = [self bookmarkModel]; |
1846 ChromeBookmarkClientFactory::GetForProfile(profile_); | 1843 if (!bookmarkModel->CanBeEditedByUser(destParent)) |
1847 if (!client->CanBeEditedByUser(destParent)) | |
1848 return NO; | 1844 return NO; |
1849 | 1845 |
1850 // Create and add the new bookmark nodes. | 1846 // Create and add the new bookmark nodes. |
1851 size_t urlCount = [urls count]; | 1847 size_t urlCount = [urls count]; |
1852 for (size_t i = 0; i < urlCount; ++i) { | 1848 for (size_t i = 0; i < urlCount; ++i) { |
1853 GURL gurl; | 1849 GURL gurl; |
1854 const char* string = [[urls objectAtIndex:i] UTF8String]; | 1850 const char* string = [[urls objectAtIndex:i] UTF8String]; |
1855 if (string) | 1851 if (string) |
1856 gurl = GURL(string); | 1852 gurl = GURL(string); |
1857 // We only expect to receive valid URLs. | 1853 // We only expect to receive valid URLs. |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2019 | 2015 |
2020 - (void)setIgnoreAnimations:(BOOL)ignore { | 2016 - (void)setIgnoreAnimations:(BOOL)ignore { |
2021 ignoreAnimations_ = ignore; | 2017 ignoreAnimations_ = ignore; |
2022 } | 2018 } |
2023 | 2019 |
2024 - (BookmarkButton*)buttonThatMouseIsIn { | 2020 - (BookmarkButton*)buttonThatMouseIsIn { |
2025 return buttonThatMouseIsIn_; | 2021 return buttonThatMouseIsIn_; |
2026 } | 2022 } |
2027 | 2023 |
2028 @end // BookmarkBarFolderController | 2024 @end // BookmarkBarFolderController |
OLD | NEW |