Chromium Code Reviews| 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/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
| 11 #import "chrome/browser/bookmarks/bookmark_model_factory.h" | 11 #import "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 12 #import "chrome/browser/bookmarks/managed_bookmark_service_factory.h" | 12 #import "chrome/browser/bookmarks/managed_bookmark_service_factory.h" |
| 13 #import "chrome/browser/profiles/profile.h" | 13 #import "chrome/browser/profiles/profile.h" |
| 14 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_constants.h" | 14 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_constants.h" |
| 15 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" | 15 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" |
| 16 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_button_cell.h" | 16 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_button_cell.h" |
| 17 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_hover_state.h" | 17 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_hover_state.h" |
| 18 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_view.h" | 18 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_view.h" |
| 19 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_window.h" | 19 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_window.h" |
| 20 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_folder_target.h" | 20 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_folder_target.h" |
| 21 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_menu_cocoa_controller.h" | 21 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_menu_cocoa_controller.h" |
| 22 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 22 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 23 #include "components/bookmarks/browser/bookmark_model.h" | 23 #include "components/bookmarks/browser/bookmark_model.h" |
| 24 #include "components/bookmarks/browser/bookmark_node_data.h" | 24 #include "components/bookmarks/browser/bookmark_node_data.h" |
| 25 #import "components/bookmarks/managed/managed_bookmark_service.h" | 25 #import "components/bookmarks/managed/managed_bookmark_service.h" |
| 26 #include "ui/base/cocoa/cocoa_base_utils.h" | |
| 26 #include "ui/base/theme_provider.h" | 27 #include "ui/base/theme_provider.h" |
| 27 | 28 |
| 28 using bookmarks::BookmarkModel; | 29 using bookmarks::BookmarkModel; |
| 29 using bookmarks::BookmarkNode; | 30 using bookmarks::BookmarkNode; |
| 30 using bookmarks::BookmarkNodeData; | 31 using bookmarks::BookmarkNodeData; |
| 31 using bookmarks::kBookmarkBarMenuCornerRadius; | 32 using bookmarks::kBookmarkBarMenuCornerRadius; |
| 32 | 33 |
| 33 namespace { | 34 namespace { |
| 34 | 35 |
| 35 // Frequency of the scrolling timer in seconds. | 36 // Frequency of the scrolling timer in seconds. |
| (...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 489 // cascading menus. Windows may grow to either the right or left of | 490 // cascading menus. Windows may grow to either the right or left of |
| 490 // their parent (if a sub-folder) so we need to know |windowWidth|. | 491 // their parent (if a sub-folder) so we need to know |windowWidth|. |
| 491 - (NSPoint)windowTopLeftForWidth:(int)windowWidth height:(int)windowHeight { | 492 - (NSPoint)windowTopLeftForWidth:(int)windowWidth height:(int)windowHeight { |
| 492 CGFloat kMinSqueezedMenuHeight = bookmarks::kBookmarkFolderButtonHeight * 2.0; | 493 CGFloat kMinSqueezedMenuHeight = bookmarks::kBookmarkFolderButtonHeight * 2.0; |
| 493 NSPoint newWindowTopLeft; | 494 NSPoint newWindowTopLeft; |
| 494 if (![parentController_ isKindOfClass:[self class]]) { | 495 if (![parentController_ isKindOfClass:[self class]]) { |
| 495 // If we're not popping up from one of ourselves, we must be | 496 // If we're not popping up from one of ourselves, we must be |
| 496 // popping up from the bookmark bar itself. In this case, start | 497 // popping up from the bookmark bar itself. In this case, start |
| 497 // BELOW the parent button. Our left is the button left; our top | 498 // BELOW the parent button. Our left is the button left; our top |
| 498 // is bottom of button's parent view. | 499 // is bottom of button's parent view. |
| 499 NSPoint buttonBottomLeftInScreen = | 500 NSPoint buttonBottomLeftInScreen = ui::ConvertPointFromWindowToScreen( |
| 500 [[parentButton_ window] | 501 [parentButton_ window], |
| 501 convertBaseToScreen:[parentButton_ | 502 [parentButton_ convertPoint:NSZeroPoint toView:nil]); |
| 502 convertPoint:NSZeroPoint toView:nil]]; | 503 NSPoint bookmarkBarBottomLeftInScreen = ui::ConvertPointFromWindowToScreen( |
| 503 NSPoint bookmarkBarBottomLeftInScreen = | 504 [parentButton_ window], |
| 504 [[parentButton_ window] | 505 [[parentButton_ superview] convertPoint:NSZeroPoint toView:nil]); |
| 505 convertBaseToScreen:[[parentButton_ superview] | |
| 506 convertPoint:NSZeroPoint toView:nil]]; | |
| 507 newWindowTopLeft = NSMakePoint( | 506 newWindowTopLeft = NSMakePoint( |
| 508 buttonBottomLeftInScreen.x + bookmarks::kBookmarkBarButtonOffset, | 507 buttonBottomLeftInScreen.x + bookmarks::kBookmarkBarButtonOffset, |
| 509 bookmarkBarBottomLeftInScreen.y + bookmarks::kBookmarkBarMenuOffset); | 508 bookmarkBarBottomLeftInScreen.y + bookmarks::kBookmarkBarMenuOffset); |
| 510 // Make sure the window is on-screen; if not, push left or right. It is | 509 // Make sure the window is on-screen; if not, push left or right. It is |
| 511 // intentional that top level folders "push left" or "push right" slightly | 510 // intentional that top level folders "push left" or "push right" slightly |
| 512 // different than subfolders. | 511 // different than subfolders. |
| 513 NSRect screenVisibleFrame = [[self menuScreen] visibleFrame]; | 512 NSRect screenVisibleFrame = [[self menuScreen] visibleFrame]; |
| 514 // Test if window goes off-screen on the right side. | 513 // Test if window goes off-screen on the right side. |
| 515 CGFloat spillOff = | 514 CGFloat spillOff = |
| 516 newWindowTopLeft.x + windowWidth - NSMaxX(screenVisibleFrame); | 515 newWindowTopLeft.x + windowWidth - NSMaxX(screenVisibleFrame); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 531 newWindowTopLeft.y = std::min( | 530 newWindowTopLeft.y = std::min( |
| 532 newWindowTopLeft.y + windowHeight + NSHeight([parentButton_ frame]), | 531 newWindowTopLeft.y + windowHeight + NSHeight([parentButton_ frame]), |
| 533 NSMaxY(screenVisibleFrame)); | 532 NSMaxY(screenVisibleFrame)); |
| 534 } | 533 } |
| 535 } else { | 534 } else { |
| 536 // Parent is a folder: expose as much as we can vertically; grow right/left. | 535 // Parent is a folder: expose as much as we can vertically; grow right/left. |
| 537 newWindowTopLeft.x = [self childFolderWindowLeftForWidth:windowWidth]; | 536 newWindowTopLeft.x = [self childFolderWindowLeftForWidth:windowWidth]; |
| 538 NSPoint topOfWindow = NSMakePoint(0, | 537 NSPoint topOfWindow = NSMakePoint(0, |
| 539 NSMaxY([parentButton_ frame]) - | 538 NSMaxY([parentButton_ frame]) - |
| 540 bookmarks::kBookmarkVerticalPadding); | 539 bookmarks::kBookmarkVerticalPadding); |
| 541 topOfWindow = [[parentButton_ window] | 540 topOfWindow = ui::ConvertPointFromWindowToScreen( |
| 542 convertBaseToScreen:[[parentButton_ superview] | 541 [parentButton_ window], |
| 543 convertPoint:topOfWindow toView:nil]]; | 542 [[parentButton_ superview] convertPoint:topOfWindow toView:nil]); |
|
Nico
2016/03/09 19:16:07
Here this does (maybe) the wrong thing since it dr
| |
| 544 newWindowTopLeft.y = topOfWindow.y + | 543 newWindowTopLeft.y = topOfWindow.y + |
| 545 2 * bookmarks::kBookmarkVerticalPadding; | 544 2 * bookmarks::kBookmarkVerticalPadding; |
| 546 } | 545 } |
| 547 return newWindowTopLeft; | 546 return newWindowTopLeft; |
| 548 } | 547 } |
| 549 | 548 |
| 550 // Set our window level to the right spot so we're above the menubar, dock, etc. | 549 // Set our window level to the right spot so we're above the menubar, dock, etc. |
| 551 // Factored out so we can override/noop in a unit test. | 550 // Factored out so we can override/noop in a unit test. |
| 552 - (void)configureWindowLevel { | 551 - (void)configureWindowLevel { |
| 553 [[self window] setLevel:NSPopUpMenuWindowLevel]; | 552 [[self window] setLevel:NSPopUpMenuWindowLevel]; |
| (...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1033 // Return the parent button's screen for use as the screen upon which all | 1032 // Return the parent button's screen for use as the screen upon which all |
| 1034 // display happens. This loop over all screens is not equivalent to | 1033 // display happens. This loop over all screens is not equivalent to |
| 1035 // |[[button window] screen]|. BookmarkButtons are commonly positioned near | 1034 // |[[button window] screen]|. BookmarkButtons are commonly positioned near |
| 1036 // the edge of their windows (both in the bookmark bar and in other bookmark | 1035 // the edge of their windows (both in the bookmark bar and in other bookmark |
| 1037 // menus), and |[[button window] screen]| would return the screen that the | 1036 // menus), and |[[button window] screen]| would return the screen that the |
| 1038 // majority of their window was on even if the parent button were clearly | 1037 // majority of their window was on even if the parent button were clearly |
| 1039 // contained within a different screen. | 1038 // contained within a different screen. |
| 1040 NSButton* button = parentButton_.get(); | 1039 NSButton* button = parentButton_.get(); |
| 1041 NSRect parentButtonGlobalFrame = | 1040 NSRect parentButtonGlobalFrame = |
| 1042 [button convertRect:[button bounds] toView:nil]; | 1041 [button convertRect:[button bounds] toView:nil]; |
| 1043 parentButtonGlobalFrame.origin = | 1042 parentButtonGlobalFrame.origin = ui::ConvertPointFromWindowToScreen( |
| 1044 [[button window] convertBaseToScreen:parentButtonGlobalFrame.origin]; | 1043 [button window], parentButtonGlobalFrame.origin); |
|
Avi (use Gerrit)
2016/03/09 17:30:20
parentButtonGlobalFrame = [[button window] convert
| |
| 1045 for (NSScreen* screen in [NSScreen screens]) { | 1044 for (NSScreen* screen in [NSScreen screens]) { |
| 1046 if (NSIntersectsRect([screen frame], parentButtonGlobalFrame)) | 1045 if (NSIntersectsRect([screen frame], parentButtonGlobalFrame)) |
| 1047 return screen; | 1046 return screen; |
| 1048 } | 1047 } |
| 1049 | 1048 |
| 1050 // The parent button is offscreen. The ideal thing to do would be to calculate | 1049 // The parent button is offscreen. The ideal thing to do would be to calculate |
| 1051 // the "closest" screen, the screen which has an edge parallel to, and the | 1050 // the "closest" screen, the screen which has an edge parallel to, and the |
| 1052 // least distance from, one of the edges of the button. However, popping a | 1051 // least distance from, one of the edges of the button. However, popping a |
| 1053 // subfolder from an offscreen button is an unrealistic edge case and so this | 1052 // subfolder from an offscreen button is an unrealistic edge case and so this |
| 1054 // ideal remains unrealized. Cheat instead; this code is wrong but a lot | 1053 // ideal remains unrealized. Cheat instead; this code is wrong but a lot |
| 1055 // simpler. | 1054 // simpler. |
| 1056 return [[button window] screen]; | 1055 return [[button window] screen]; |
| 1057 } | 1056 } |
| 1058 | 1057 |
| 1059 // Called as a result of our tracking area. Warning: on the main | 1058 // Called as a result of our tracking area. Warning: on the main |
| 1060 // screen (of a single-screened machine), the minimum mouse y value is | 1059 // screen (of a single-screened machine), the minimum mouse y value is |
| 1061 // 1, not 0. Also, we do not get events when the mouse is above the | 1060 // 1, not 0. Also, we do not get events when the mouse is above the |
| 1062 // menubar (to be fixed by setting the proper window level; see | 1061 // menubar (to be fixed by setting the proper window level; see |
| 1063 // initializer). | 1062 // initializer). |
| 1064 // Note [theEvent window] may not be our window, as we also get these messages | 1063 // Note [theEvent window] may not be our window, as we also get these messages |
| 1065 // forwarded from BookmarkButton's mouse tracking loop. | 1064 // forwarded from BookmarkButton's mouse tracking loop. |
| 1066 - (void)mouseMovedOrDragged:(NSEvent*)theEvent { | 1065 - (void)mouseMovedOrDragged:(NSEvent*)theEvent { |
| 1067 NSPoint eventScreenLocation = | 1066 NSPoint eventScreenLocation = ui::ConvertPointFromWindowToScreen( |
| 1068 [[theEvent window] convertBaseToScreen:[theEvent locationInWindow]]; | 1067 [theEvent window], [theEvent locationInWindow]); |
| 1069 | 1068 |
| 1070 // Base hot spot calculations on the positions of the scroll arrow views. | 1069 // Base hot spot calculations on the positions of the scroll arrow views. |
| 1071 NSRect testRect = [scrollDownArrowView_ frame]; | 1070 NSRect testRect = [scrollDownArrowView_ frame]; |
| 1072 NSPoint testPoint = [visibleView_ convertPoint:testRect.origin | 1071 NSPoint testPoint = [visibleView_ convertPoint:testRect.origin |
| 1073 toView:nil]; | 1072 toView:nil]; |
| 1074 testPoint = [[self window] convertBaseToScreen:testPoint]; | 1073 testPoint = ui::ConvertPointFromWindowToScreen([self window], testPoint); |
| 1075 CGFloat closeToTopOfScreen = testPoint.y; | 1074 CGFloat closeToTopOfScreen = testPoint.y; |
| 1076 | 1075 |
| 1077 testRect = [scrollUpArrowView_ frame]; | 1076 testRect = [scrollUpArrowView_ frame]; |
| 1078 testPoint = [visibleView_ convertPoint:testRect.origin toView:nil]; | 1077 testPoint = [visibleView_ convertPoint:testRect.origin toView:nil]; |
| 1079 testPoint = [[self window] convertBaseToScreen:testPoint]; | 1078 testPoint = ui::ConvertPointFromWindowToScreen([self window], testPoint); |
| 1080 CGFloat closeToBottomOfScreen = testPoint.y + testRect.size.height; | 1079 CGFloat closeToBottomOfScreen = testPoint.y + testRect.size.height; |
| 1081 if (eventScreenLocation.y <= closeToBottomOfScreen && | 1080 if (eventScreenLocation.y <= closeToBottomOfScreen && |
| 1082 ![scrollUpArrowView_ isHidden]) { | 1081 ![scrollUpArrowView_ isHidden]) { |
| 1083 [self beginScrollWindowUp]; | 1082 [self beginScrollWindowUp]; |
| 1084 } else if (eventScreenLocation.y > closeToTopOfScreen && | 1083 } else if (eventScreenLocation.y > closeToTopOfScreen && |
| 1085 ![scrollDownArrowView_ isHidden]) { | 1084 ![scrollDownArrowView_ isHidden]) { |
| 1086 [self beginScrollWindowDown]; | 1085 [self beginScrollWindowDown]; |
| 1087 } else { | 1086 } else { |
| 1088 [self endScroll]; | 1087 [self endScroll]; |
| 1089 } | 1088 } |
| (...skipping 955 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2045 | 2044 |
| 2046 - (void)setIgnoreAnimations:(BOOL)ignore { | 2045 - (void)setIgnoreAnimations:(BOOL)ignore { |
| 2047 ignoreAnimations_ = ignore; | 2046 ignoreAnimations_ = ignore; |
| 2048 } | 2047 } |
| 2049 | 2048 |
| 2050 - (BookmarkButton*)buttonThatMouseIsIn { | 2049 - (BookmarkButton*)buttonThatMouseIsIn { |
| 2051 return buttonThatMouseIsIn_; | 2050 return buttonThatMouseIsIn_; |
| 2052 } | 2051 } |
| 2053 | 2052 |
| 2054 @end // BookmarkBarFolderController | 2053 @end // BookmarkBarFolderController |
| OLD | NEW |