OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_UI_COCOA_BOOKMARKS_BOOKMARK_BAR_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_UI_COCOA_BOOKMARKS_BOOKMARK_BAR_CONTROLLER_H_ |
6 #define CHROME_BROWSER_UI_COCOA_BOOKMARKS_BOOKMARK_BAR_CONTROLLER_H_ | 6 #define CHROME_BROWSER_UI_COCOA_BOOKMARKS_BOOKMARK_BAR_CONTROLLER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #import <Cocoa/Cocoa.h> | 9 #import <Cocoa/Cocoa.h> |
10 #include <map> | 10 #include <map> |
11 | 11 |
12 #include "base/memory/scoped_nsobject.h" | 12 #include "base/memory/scoped_nsobject.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_bridge.h" | 14 #include "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_bridge.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_state.h" | 16 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_state.h" |
17 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_toolbar_view.h" | 17 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_toolbar_view.h" |
18 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h" | 18 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h" |
19 #include "chrome/browser/ui/cocoa/tabs/tab_strip_model_observer_bridge.h" | 19 #include "chrome/browser/ui/cocoa/tabs/tab_strip_model_observer_bridge.h" |
| 20 #import "content/common/chrome_application_mac.h" |
20 #include "webkit/glue/window_open_disposition.h" | 21 #include "webkit/glue/window_open_disposition.h" |
21 | 22 |
22 @class BookmarkBarController; | 23 @class BookmarkBarController; |
23 @class BookmarkBarFolderController; | 24 @class BookmarkBarFolderController; |
24 @class BookmarkBarView; | 25 @class BookmarkBarView; |
25 @class BookmarkButton; | 26 @class BookmarkButton; |
26 @class BookmarkButtonCell; | 27 @class BookmarkButtonCell; |
27 @class BookmarkFolderTarget; | 28 @class BookmarkFolderTarget; |
28 class BookmarkModel; | 29 class BookmarkModel; |
29 @class BookmarkMenu; | 30 @class BookmarkMenu; |
30 class BookmarkNode; | 31 class BookmarkNode; |
31 class Browser; | 32 class Browser; |
32 class GURL; | 33 class GURL; |
33 | 34 |
34 namespace bookmarks { | 35 namespace bookmarks { |
35 | 36 |
36 // Magic numbers from Cole | 37 // Magic numbers from Cole |
37 // TODO(jrg): create an objc-friendly version of bookmark_bar_constants.h? | 38 // TODO(jrg): create an objc-friendly version of bookmark_bar_constants.h? |
38 | 39 |
39 // Used as a maximum width for buttons on the bar. | 40 // Used as a maximum width for buttons on the bar. |
40 const CGFloat kDefaultBookmarkWidth = 150.0; | 41 const CGFloat kDefaultBookmarkWidth = 150.0; |
41 | 42 |
42 // Horizontal frame inset for buttons in the bookmark bar. | 43 // Horizontal frame inset for buttons in the bookmark bar. |
43 const CGFloat kBookmarkHorizontalPadding = 1.0; | 44 const CGFloat kBookmarkHorizontalPadding = 1.0; |
44 | 45 |
45 // Vertical frame inset for buttons in the bookmark bar. | 46 // Vertical frame inset for buttons in the bookmark bar. |
46 const CGFloat kBookmarkVerticalPadding = 2.0; | 47 const CGFloat kBookmarkVerticalPadding = 2.0; |
47 | 48 |
| 49 // Used as a min/max width for buttons on menus (not on the bar). |
| 50 const CGFloat kBookmarkMenuButtonMinimumWidth = 100.0; |
| 51 const CGFloat kBookmarkMenuButtonMaximumWidth = 485.0; |
| 52 |
| 53 // The minimum separation between a folder menu and the edge of the screen. |
| 54 // If the menu gets closer to the edge of the screen (either right or left) |
| 55 // then it is pops up in the opposite direction. |
| 56 // (See -[BookmarkBarFolderController childFolderWindowLeftForWidth:]). |
| 57 const CGFloat kBookmarkHorizontalScreenPadding = 8.0; |
| 58 |
| 59 // Our NSScrollView is supposed to be just barely big enough to fit its |
| 60 // contentView. It is actually a hair too small. |
| 61 // This turns on horizontal scrolling which, although slight, is awkward. |
| 62 // Make sure our window (and NSScrollView) are wider than its documentView |
| 63 // by at least this much. |
| 64 const CGFloat kScrollViewContentWidthMargin = 2; |
| 65 |
| 66 // Make subfolder menus overlap their parent menu a bit to give a better |
| 67 // perception of a menuing system. |
| 68 const CGFloat kBookmarkMenuOverlap = 2.0; |
| 69 |
| 70 // When constraining a scrolling bookmark bar folder window to the |
| 71 // screen, shrink the "constrain" by this much vertically. Currently |
| 72 // this is 0.0 to avoid a problem with tracking areas leaving the |
| 73 // window, but should probably be 8.0 or something. |
| 74 const CGFloat kScrollWindowVerticalMargin = 6.0; |
| 75 |
48 // How far to offset a folder menu from the top of the bookmark bar. This | 76 // How far to offset a folder menu from the top of the bookmark bar. This |
49 // is set just above the bar so that it become distinctive when drawn. | 77 // is set just above the bar so that it become distinctive when drawn. |
50 const CGFloat kBookmarkBarMenuOffset = 2.0; | 78 const CGFloat kBookmarkBarMenuOffset = 2.0; |
51 | 79 |
| 80 // How far to offset a folder menu's left edge horizontally in relation to |
| 81 // the left edge of the button from which it springs. Because of drawing |
| 82 // differences, simply aligning the |frame| of each does not render the |
| 83 // pproper result, so we have to offset. |
| 84 const CGFloat kBookmarkBarButtonOffset = 2.0; |
| 85 |
| 86 // Delay before opening a subfolder (and closing the previous one) |
| 87 // when hovering over a folder button. |
| 88 const NSTimeInterval kHoverOpenDelay = 0.3; |
| 89 |
| 90 // Delay on hover before a submenu opens when dragging. |
| 91 // Experimentally a drag hover open delay needs to be bigger than a |
| 92 // normal (non-drag) menu hover open such as used in the bookmark folder. |
| 93 // TODO(jrg): confirm feel of this constant with ui-team. |
| 94 // http://crbug.com/36276 |
| 95 const NSTimeInterval kDragHoverOpenDelay = 0.7; |
| 96 |
| 97 // Notes on use of kDragHoverCloseDelay in |
| 98 // -[BookmarkBarFolderController draggingEntered:]. |
| 99 // |
| 100 // We have an implicit delay on stop-hover-open before a submenu |
| 101 // closes. This cannot be zero since it's nice to move the mouse in a |
| 102 // direct line from "current position" to "position of item in |
| 103 // submenu". However, by doing so, it's possible to overlap a |
| 104 // different button on the current menu. Example: |
| 105 // |
| 106 // Folder1 |
| 107 // Folder2 ---> Sub1 |
| 108 // Folder3 Sub2 |
| 109 // Sub3 |
| 110 // |
| 111 // If you hover over the F in Folder2 to open the sub, and then want to |
| 112 // select Sub3, a direct line movement of the mouse may cross over |
| 113 // Folder3. Without this delay, that'll cause Sub to be closed before |
| 114 // you get there, since a "hover over" of Folder3 gets activated. |
| 115 // It's subtle but without the delay it feels broken. |
| 116 // |
| 117 // This is only really a problem with vertical menu --> vertical menu |
| 118 // movement; the bookmark bar (horizontal menu, sort of) seems fine, |
| 119 // perhaps because mouse move direction is purely vertical so there is |
| 120 // no opportunity for overlap. |
| 121 const NSTimeInterval kDragHoverCloseDelay = 0.4; |
| 122 |
52 } // namespace bookmarks | 123 } // namespace bookmarks |
53 | 124 |
54 // The interface for the bookmark bar controller's delegate. Currently, the | 125 // The interface for the bookmark bar controller's delegate. Currently, the |
55 // delegate is the BWC and is responsible for ensuring that the toolbar is | 126 // delegate is the BWC and is responsible for ensuring that the toolbar is |
56 // displayed correctly (as specified by |-getDesiredToolbarHeightCompression| | 127 // displayed correctly (as specified by |-getDesiredToolbarHeightCompression| |
57 // and |-toolbarDividerOpacity|) at the beginning and at the end of an animation | 128 // and |-toolbarDividerOpacity|) at the beginning and at the end of an animation |
58 // (or after a state change). | 129 // (or after a state change). |
59 @protocol BookmarkBarControllerDelegate | 130 @protocol BookmarkBarControllerDelegate |
60 | 131 |
61 // Sent when the state has changed (after any animation), but before the final | 132 // Sent when the state has changed (after any animation), but before the final |
62 // display update. | 133 // display update. |
63 - (void)bookmarkBar:(BookmarkBarController*)controller | 134 - (void)bookmarkBar:(BookmarkBarController*)controller |
64 didChangeFromState:(bookmarks::VisualState)oldState | 135 didChangeFromState:(bookmarks::VisualState)oldState |
65 toState:(bookmarks::VisualState)newState; | 136 toState:(bookmarks::VisualState)newState; |
66 | 137 |
67 // Sent before the animation begins. | 138 // Sent before the animation begins. |
68 - (void)bookmarkBar:(BookmarkBarController*)controller | 139 - (void)bookmarkBar:(BookmarkBarController*)controller |
69 willAnimateFromState:(bookmarks::VisualState)oldState | 140 willAnimateFromState:(bookmarks::VisualState)oldState |
70 toState:(bookmarks::VisualState)newState; | 141 toState:(bookmarks::VisualState)newState; |
71 | 142 |
72 @end | 143 @end |
73 | 144 |
74 // A controller for the bookmark bar in the browser window. Handles showing | 145 // A controller for the bookmark bar in the browser window. Handles showing |
75 // and hiding based on the preference in the given profile. | 146 // and hiding based on the preference in the given profile. |
76 @interface BookmarkBarController : | 147 @interface BookmarkBarController : |
77 NSViewController<BookmarkBarState, | 148 NSViewController<BookmarkBarState, |
78 BookmarkBarToolbarViewController, | 149 BookmarkBarToolbarViewController, |
79 BookmarkButtonDelegate, | 150 BookmarkButtonDelegate, |
80 BookmarkButtonControllerProtocol, | 151 BookmarkButtonControllerProtocol, |
| 152 CrApplicationEventHookProtocol, |
81 NSUserInterfaceValidations> { | 153 NSUserInterfaceValidations> { |
82 @private | 154 @private |
83 // The visual state of the bookmark bar. If an animation is running, this is | 155 // The visual state of the bookmark bar. If an animation is running, this is |
84 // set to the "destination" and |lastVisualState_| is set to the "original" | 156 // set to the "destination" and |lastVisualState_| is set to the "original" |
85 // state. This is set to |kInvalidState| on initialization (when the | 157 // state. This is set to |kInvalidState| on initialization (when the |
86 // appropriate state is not yet known). | 158 // appropriate state is not yet known). |
87 bookmarks::VisualState visualState_; | 159 bookmarks::VisualState visualState_; |
88 | 160 |
89 // The "original" state of the bookmark bar if an animation is running, | 161 // The "original" state of the bookmark bar if an animation is running, |
90 // otherwise it should be |kInvalidState|. | 162 // otherwise it should be |kInvalidState|. |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 | 398 |
327 // The following are for testing purposes only and are not used internally. | 399 // The following are for testing purposes only and are not used internally. |
328 - (NSMenu *)menuForFolderNode:(const BookmarkNode*)node; | 400 - (NSMenu *)menuForFolderNode:(const BookmarkNode*)node; |
329 - (NSMenu*)buttonContextMenu; | 401 - (NSMenu*)buttonContextMenu; |
330 - (void)setButtonContextMenu:(id)menu; | 402 - (void)setButtonContextMenu:(id)menu; |
331 // Set to YES in order to prevent animations. | 403 // Set to YES in order to prevent animations. |
332 - (void)setIgnoreAnimations:(BOOL)ignore; | 404 - (void)setIgnoreAnimations:(BOOL)ignore; |
333 @end | 405 @end |
334 | 406 |
335 #endif // CHROME_BROWSER_UI_COCOA_BOOKMARKS_BOOKMARK_BAR_CONTROLLER_H_ | 407 #endif // CHROME_BROWSER_UI_COCOA_BOOKMARKS_BOOKMARK_BAR_CONTROLLER_H_ |
OLD | NEW |