Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Side by Side Diff: chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller.mm

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

Powered by Google App Engine
This is Rietveld 408576698