| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/mac/bundle_locations.h" | 9 #include "base/mac/bundle_locations.h" |
| 10 #include "base/mac/sdk_forward_declarations.h" | 10 #include "base/mac/sdk_forward_declarations.h" |
| 11 #include "base/strings/sys_string_conversions.h" | 11 #include "base/strings/sys_string_conversions.h" |
| 12 #import "chrome/browser/bookmarks/bookmark_model_factory.h" | 12 #import "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 13 #import "chrome/browser/bookmarks/managed_bookmark_service_factory.h" | 13 #import "chrome/browser/bookmarks/managed_bookmark_service_factory.h" |
| 14 #import "chrome/browser/profiles/profile.h" | 14 #import "chrome/browser/profiles/profile.h" |
| 15 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_constants.h" | 15 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_constants.h" |
| 16 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" | 16 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" |
| 17 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_button_cell.h" | 17 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_button_cell.h" |
| 18 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_hover_state.h" | 18 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_hover_state.h" |
| 19 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_view.h" | 19 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_view.h" |
| 20 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_window.h" | 20 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_window.h" |
| 21 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_folder_target.h" | 21 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_folder_target.h" |
| 22 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_menu_cocoa_controller.h" | 22 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_menu_cocoa_controller.h" |
| 23 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 23 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 24 #import "chrome/browser/ui/cocoa/l10n_util.h" |
| 24 #include "components/bookmarks/browser/bookmark_model.h" | 25 #include "components/bookmarks/browser/bookmark_model.h" |
| 25 #include "components/bookmarks/browser/bookmark_node_data.h" | 26 #include "components/bookmarks/browser/bookmark_node_data.h" |
| 26 #import "components/bookmarks/managed/managed_bookmark_service.h" | 27 #import "components/bookmarks/managed/managed_bookmark_service.h" |
| 27 #include "ui/base/clipboard/clipboard_util_mac.h" | 28 #include "ui/base/clipboard/clipboard_util_mac.h" |
| 28 #include "ui/base/cocoa/cocoa_base_utils.h" | 29 #include "ui/base/cocoa/cocoa_base_utils.h" |
| 29 #include "ui/base/material_design/material_design_controller.h" | 30 #include "ui/base/material_design/material_design_controller.h" |
| 30 #include "ui/base/resource/resource_bundle.h" | 31 #include "ui/base/resource/resource_bundle.h" |
| 31 #include "ui/base/theme_provider.h" | 32 #include "ui/base/theme_provider.h" |
| 32 #include "ui/resources/grit/ui_resources.h" | 33 #include "ui/resources/grit/ui_resources.h" |
| 33 | 34 |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 parentButton_.reset([button retain]); | 270 parentButton_.reset([button retain]); |
| 270 selectedIndex_ = -1; | 271 selectedIndex_ = -1; |
| 271 | 272 |
| 272 profile_ = profile; | 273 profile_ = profile; |
| 273 | 274 |
| 274 // We want the button to remain bordered as part of the menu path. | 275 // We want the button to remain bordered as part of the menu path. |
| 275 [button forceButtonBorderToStayOnAlways:YES]; | 276 [button forceButtonBorderToStayOnAlways:YES]; |
| 276 | 277 |
| 277 parentController_.reset([parentController retain]); | 278 parentController_.reset([parentController retain]); |
| 278 if (!parentController_) | 279 if (!parentController_) |
| 279 [self setSubFolderGrowthToRight:YES]; | 280 [self setSubFolderGrowthToRight:!cocoa_l10n_util:: |
| 281 ShouldDoExperimentalRTLLayout()]; |
| 280 else | 282 else |
| 281 [self setSubFolderGrowthToRight:[parentController | 283 [self setSubFolderGrowthToRight:[parentController |
| 282 subFolderGrowthToRight]]; | 284 subFolderGrowthToRight]]; |
| 283 barController_ = barController; // WEAK | 285 barController_ = barController; // WEAK |
| 284 buttons_.reset([[NSMutableArray alloc] init]); | 286 buttons_.reset([[NSMutableArray alloc] init]); |
| 285 folderTarget_.reset( | 287 folderTarget_.reset( |
| 286 [[BookmarkFolderTarget alloc] initWithController:self profile:profile]); | 288 [[BookmarkFolderTarget alloc] initWithController:self profile:profile]); |
| 287 [self configureWindow]; | 289 [self configureWindow]; |
| 288 hoverState_.reset([[BookmarkBarFolderHoverState alloc] init]); | 290 hoverState_.reset([[BookmarkBarFolderHoverState alloc] init]); |
| 289 } | 291 } |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 // Compute and return the top left point of our window (screen | 524 // Compute and return the top left point of our window (screen |
| 523 // coordinates). The top left is positioned in a manner similar to | 525 // coordinates). The top left is positioned in a manner similar to |
| 524 // cascading menus. Windows may grow to either the right or left of | 526 // cascading menus. Windows may grow to either the right or left of |
| 525 // their parent (if a sub-folder) so we need to know |windowWidth|. | 527 // their parent (if a sub-folder) so we need to know |windowWidth|. |
| 526 - (NSPoint)windowTopLeftForWidth:(int)windowWidth height:(int)windowHeight { | 528 - (NSPoint)windowTopLeftForWidth:(int)windowWidth height:(int)windowHeight { |
| 527 CGFloat kMinSqueezedMenuHeight = bookmarks::kBookmarkFolderButtonHeight * 2.0; | 529 CGFloat kMinSqueezedMenuHeight = bookmarks::kBookmarkFolderButtonHeight * 2.0; |
| 528 NSPoint newWindowTopLeft; | 530 NSPoint newWindowTopLeft; |
| 529 if (![parentController_ isKindOfClass:[self class]]) { | 531 if (![parentController_ isKindOfClass:[self class]]) { |
| 530 // If we're not popping up from one of ourselves, we must be | 532 // If we're not popping up from one of ourselves, we must be |
| 531 // popping up from the bookmark bar itself. In this case, start | 533 // popping up from the bookmark bar itself. In this case, start |
| 532 // BELOW the parent button. Our left is the button left; our top | 534 // BELOW the parent button. Our leading edge is the button leading |
| 533 // is bottom of button's parent view. | 535 // edge; our top is bottom of button's parent view. |
| 534 NSPoint buttonBottomLeftInScreen = ui::ConvertPointFromWindowToScreen( | 536 BOOL isRTL = cocoa_l10n_util::ShouldDoExperimentalRTLLayout(); |
| 537 NSPoint buttonAnchorPoint = |
| 538 isRTL ? NSMakePoint(NSWidth([parentButton_ frame]), 0) : NSZeroPoint; |
| 539 NSPoint buttonAnchorPointInScreen = ui::ConvertPointFromWindowToScreen( |
| 535 [parentButton_ window], | 540 [parentButton_ window], |
| 536 [parentButton_ convertPoint:NSZeroPoint toView:nil]); | 541 [parentButton_ convertPoint:buttonAnchorPoint toView:nil]); |
| 537 NSPoint bookmarkBarBottomLeftInScreen = ui::ConvertPointFromWindowToScreen( | 542 NSPoint bookmarkBarAnchorPoint = |
| 543 isRTL ? NSMakePoint(NSWidth([[parentButton_ superview] frame]), 0) |
| 544 : NSZeroPoint; |
| 545 NSPoint bookmarkBarAnchorPointInScreen = ui::ConvertPointFromWindowToScreen( |
| 538 [parentButton_ window], | 546 [parentButton_ window], |
| 539 [[parentButton_ superview] convertPoint:NSZeroPoint toView:nil]); | 547 [[parentButton_ superview] convertPoint:bookmarkBarAnchorPoint |
| 548 toView:nil]); |
| 540 newWindowTopLeft = NSMakePoint( | 549 newWindowTopLeft = NSMakePoint( |
| 541 buttonBottomLeftInScreen.x, | 550 isRTL ? buttonAnchorPointInScreen.x - windowWidth |
| 542 bookmarkBarBottomLeftInScreen.y + bookmarks::kBookmarkBarMenuOffset); | 551 : buttonAnchorPointInScreen.x, |
| 552 bookmarkBarAnchorPointInScreen.y + bookmarks::kBookmarkBarMenuOffset); |
| 543 // Make sure the window is on-screen; if not, push left or right. It is | 553 // Make sure the window is on-screen; if not, push left or right. It is |
| 544 // intentional that top level folders "push left" or "push right" slightly | 554 // intentional that top level folders "push left" or "push right" slightly |
| 545 // different than subfolders. | 555 // different than subfolders. |
| 546 NSRect screenVisibleFrame = [[self menuScreen] visibleFrame]; | 556 NSRect screenVisibleFrame = [[self menuScreen] visibleFrame]; |
| 547 // Test if window goes off-screen on the right side. | 557 // Test if window goes off-screen on the right side. |
| 548 CGFloat spillOff = | 558 CGFloat spillOff = |
| 549 newWindowTopLeft.x + windowWidth - NSMaxX(screenVisibleFrame); | 559 newWindowTopLeft.x + windowWidth - NSMaxX(screenVisibleFrame); |
| 550 if (spillOff > 0.0) { | 560 if (spillOff > 0.0) { |
| 551 newWindowTopLeft.x = std::max(newWindowTopLeft.x - spillOff, | 561 newWindowTopLeft.x = std::max(newWindowTopLeft.x - spillOff, |
| 552 NSMinX(screenVisibleFrame)); | 562 NSMinX(screenVisibleFrame)); |
| (...skipping 918 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1471 // Closing the top level implicitly closes all children. | 1481 // Closing the top level implicitly closes all children. |
| 1472 [barController_ closeAllBookmarkFolders]; | 1482 [barController_ closeAllBookmarkFolders]; |
| 1473 } | 1483 } |
| 1474 | 1484 |
| 1475 // Close our bookmark folder (a sub-controller) if we have one. | 1485 // Close our bookmark folder (a sub-controller) if we have one. |
| 1476 - (void)closeBookmarkFolder:(id)sender { | 1486 - (void)closeBookmarkFolder:(id)sender { |
| 1477 if (folderController_) { | 1487 if (folderController_) { |
| 1478 // Make this menu key, so key status doesn't go back to the browser | 1488 // Make this menu key, so key status doesn't go back to the browser |
| 1479 // window when the submenu closes. | 1489 // window when the submenu closes. |
| 1480 [[self window] makeKeyWindow]; | 1490 [[self window] makeKeyWindow]; |
| 1481 [self setSubFolderGrowthToRight:YES]; | 1491 [self setSubFolderGrowthToRight:!cocoa_l10n_util:: |
| 1492 ShouldDoExperimentalRTLLayout()]; |
| 1482 [[folderController_ window] close]; | 1493 [[folderController_ window] close]; |
| 1483 folderController_ = nil; | 1494 folderController_ = nil; |
| 1484 } | 1495 } |
| 1485 } | 1496 } |
| 1486 | 1497 |
| 1487 - (BookmarkModel*)bookmarkModel { | 1498 - (BookmarkModel*)bookmarkModel { |
| 1488 return [barController_ bookmarkModel]; | 1499 return [barController_ bookmarkModel]; |
| 1489 } | 1500 } |
| 1490 | 1501 |
| 1491 - (BOOL)draggingAllowed:(id<NSDraggingInfo>)info { | 1502 - (BOOL)draggingAllowed:(id<NSDraggingInfo>)info { |
| (...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2102 | 2113 |
| 2103 - (void)setIgnoreAnimations:(BOOL)ignore { | 2114 - (void)setIgnoreAnimations:(BOOL)ignore { |
| 2104 ignoreAnimations_ = ignore; | 2115 ignoreAnimations_ = ignore; |
| 2105 } | 2116 } |
| 2106 | 2117 |
| 2107 - (BookmarkButton*)buttonThatMouseIsIn { | 2118 - (BookmarkButton*)buttonThatMouseIsIn { |
| 2108 return buttonThatMouseIsIn_; | 2119 return buttonThatMouseIsIn_; |
| 2109 } | 2120 } |
| 2110 | 2121 |
| 2111 @end // BookmarkBarFolderController | 2122 @end // BookmarkBarFolderController |
| OLD | NEW |