| 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 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_view_cocoa.h" | 5 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_view_cocoa.h" |
| 6 | 6 |
| 7 #include "base/metrics/user_metrics.h" | 7 #include "base/metrics/user_metrics.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #import "chrome/browser/themes/theme_properties.h" | 9 #import "chrome/browser/themes/theme_properties.h" |
| 10 #import "chrome/browser/themes/theme_service.h" | 10 #import "chrome/browser/themes/theme_service.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #import "third_party/mozilla/NSPasteboard+Utils.h" | 21 #import "third_party/mozilla/NSPasteboard+Utils.h" |
| 22 #include "ui/base/clipboard/clipboard_util_mac.h" | 22 #include "ui/base/clipboard/clipboard_util_mac.h" |
| 23 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" | 23 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" |
| 24 #import "ui/base/cocoa/nsview_additions.h" | 24 #import "ui/base/cocoa/nsview_additions.h" |
| 25 #include "ui/base/l10n/l10n_util_mac.h" | 25 #include "ui/base/l10n/l10n_util_mac.h" |
| 26 | 26 |
| 27 using base::UserMetricsAction; | 27 using base::UserMetricsAction; |
| 28 using bookmarks::BookmarkModel; | 28 using bookmarks::BookmarkModel; |
| 29 using bookmarks::BookmarkNode; | 29 using bookmarks::BookmarkNode; |
| 30 | 30 |
| 31 static const CGFloat kInitialElementYOrigin = 7; | 31 static const CGFloat kInitialContainerWidth = 596; |
| 32 static const CGFloat kInitialContainerHeight = 41; |
| 33 static const CGFloat kInitialElementYOrigin = 20; |
| 32 static const CGFloat kInitialElementHeight = 14; | 34 static const CGFloat kInitialElementHeight = 14; |
| 33 static const CGFloat kInitialTextFieldXOrigin = 5; | 35 static const CGFloat kInitialTextFieldXOrigin = 5; |
| 36 // static const CGFloat kInitialTextFieldWidth = 167; |
| 34 static const CGFloat kTextFieldTrailingPadding = 5; | 37 static const CGFloat kTextFieldTrailingPadding = 5; |
| 38 // static const CGFloat kInitialButtonWidth = 199; |
| 35 | 39 |
| 36 @interface BookmarkBarView (Private) | 40 @interface BookmarkBarView (Private) |
| 37 - (void)themeDidChangeNotification:(NSNotification*)aNotification; | 41 - (void)themeDidChangeNotification:(NSNotification*)aNotification; |
| 38 - (void)updateTheme:(const ui::ThemeProvider*)themeProvider; | 42 - (void)updateTheme:(const ui::ThemeProvider*)themeProvider; |
| 39 | 43 |
| 40 // NSView override. | 44 // NSView override. |
| 41 - (void)setFrameSize:(NSSize)size; | 45 - (void)setFrameSize:(NSSize)size; |
| 42 @end | 46 @end |
| 43 | 47 |
| 44 @implementation BookmarkBarView | 48 @implementation BookmarkBarView |
| (...skipping 24 matching lines...) Expand all Loading... |
| 69 } | 73 } |
| 70 | 74 |
| 71 - (instancetype)initWithController:(BookmarkBarController*)controller | 75 - (instancetype)initWithController:(BookmarkBarController*)controller |
| 72 frame:(NSRect)frame { | 76 frame:(NSRect)frame { |
| 73 DCHECK(controller) << "Controller shouldn't be nil"; | 77 DCHECK(controller) << "Controller shouldn't be nil"; |
| 74 if (self = [super initWithFrame:frame]) { | 78 if (self = [super initWithFrame:frame]) { |
| 75 controller_ = controller; | 79 controller_ = controller; |
| 76 | 80 |
| 77 NSFont* smallSystemFont = | 81 NSFont* smallSystemFont = |
| 78 [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]; | 82 [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]; |
| 83 noItemContainer_.reset( |
| 84 [[NSView alloc] initWithFrame:NSMakeRect(0, 0, kInitialContainerWidth, |
| 85 kInitialContainerHeight)]); |
| 86 [noItemContainer_ setAutoresizingMask:NSViewMaxXMargin]; |
| 87 [noItemContainer_ setAutoresizingMask:NSViewWidthSizable]; |
| 79 | 88 |
| 80 noItemTextField_.reset([[NSTextField alloc] | 89 noItemTextfield_.reset([[NSTextField alloc] |
| 81 initWithFrame:NSMakeRect(kInitialTextFieldXOrigin, | 90 initWithFrame:NSMakeRect(kInitialTextFieldXOrigin, |
| 82 kInitialElementYOrigin, CGFLOAT_MAX, | 91 kInitialElementYOrigin, CGFLOAT_MAX, |
| 83 kInitialElementHeight)]); | 92 kInitialElementHeight)]); |
| 84 [noItemTextField_ setFont:smallSystemFont]; | 93 [noItemTextfield_ setAutoresizingMask:NSViewWidthSizable]; |
| 85 [noItemTextField_ | 94 [noItemTextfield_ setFont:smallSystemFont]; |
| 95 [noItemTextfield_ |
| 86 setStringValue:l10n_util::GetNSString(IDS_BOOKMARKS_NO_ITEMS)]; | 96 setStringValue:l10n_util::GetNSString(IDS_BOOKMARKS_NO_ITEMS)]; |
| 87 [noItemTextField_ setEditable:NO]; | 97 [noItemTextfield_ setEditable:NO]; |
| 88 | 98 |
| 89 [noItemTextField_ setBordered:NO]; | 99 [noItemTextfield_ setBordered:NO]; |
| 90 [[noItemTextField_ cell] setLineBreakMode:NSLineBreakByTruncatingTail]; | 100 [[noItemTextfield_ cell] setLineBreakMode:NSLineBreakByTruncatingTail]; |
| 91 | 101 |
| 92 [noItemTextField_ setTextColor:[NSColor controlTextColor]]; | 102 [noItemTextfield_ setTextColor:[NSColor controlTextColor]]; |
| 93 [noItemTextField_ setBackgroundColor:[NSColor controlColor]]; | 103 [noItemTextfield_ setBackgroundColor:[NSColor controlColor]]; |
| 94 | 104 |
| 95 [noItemTextField_ setDrawsBackground:NO]; | 105 [noItemTextfield_ setDrawsBackground:NO]; |
| 96 [noItemTextField_ setTextColor:[NSColor controlTextColor]]; | 106 [noItemTextfield_ setTextColor:[NSColor controlTextColor]]; |
| 97 [noItemTextField_ setBackgroundColor:[NSColor controlColor]]; | 107 [noItemTextfield_ setBackgroundColor:[NSColor controlColor]]; |
| 98 [noItemTextField_ sizeToFit]; | 108 [noItemTextfield_ sizeToFit]; |
| 99 | 109 |
| 100 NSButton* importButton = [HyperlinkButtonCell | 110 NSButton* importButton = [HyperlinkButtonCell |
| 101 buttonWithString:l10n_util::GetNSString(IDS_BOOKMARK_BAR_IMPORT_LINK)]; | 111 buttonWithString:l10n_util::GetNSString(IDS_BOOKMARK_BAR_IMPORT_LINK)]; |
| 102 importBookmarksButton_.reset([importButton retain]); | 112 importBookmarksButton_.reset([importButton retain]); |
| 103 [importBookmarksButton_ | 113 [importBookmarksButton_ |
| 104 setFrame:NSMakeRect(NSMaxX([noItemTextField_ frame]) + | 114 setFrame:NSMakeRect(NSMaxX([noItemTextfield_ frame]) + |
| 105 kTextFieldTrailingPadding, | 115 kTextFieldTrailingPadding, |
| 106 kInitialElementYOrigin, CGFLOAT_MAX, | 116 kInitialElementYOrigin, CGFLOAT_MAX, |
| 107 kInitialElementHeight)]; | 117 kInitialElementHeight)]; |
| 118 [importBookmarksButton_ setAutoresizingMask:NSViewMaxXMargin]; |
| 108 [importBookmarksButton_ setFont:smallSystemFont]; | 119 [importBookmarksButton_ setFont:smallSystemFont]; |
| 109 [importBookmarksButton_ sizeToFit]; | 120 [importBookmarksButton_ sizeToFit]; |
| 121 [noItemContainer_ addSubview:importBookmarksButton_]; |
| 110 | 122 |
| 111 [self addSubview:noItemTextField_]; | 123 [noItemContainer_ addSubview:noItemTextfield_]; |
| 112 [self addSubview:importBookmarksButton_]; | 124 NSRect containerFrame = [noItemContainer_ frame]; |
| 125 containerFrame.size.width = std::max( |
| 126 NSWidth(containerFrame), NSMaxX([importBookmarksButton_ frame])); |
| 127 [noItemContainer_ setFrame:containerFrame]; |
| 128 |
| 129 [self addSubview:noItemContainer_]; |
| 113 [self registerForNotificationsAndDraggedTypes]; | 130 [self registerForNotificationsAndDraggedTypes]; |
| 114 } | 131 } |
| 115 return self; | 132 return self; |
| 116 } | 133 } |
| 117 | 134 |
| 118 - (void)registerForNotificationsAndDraggedTypes { | 135 - (void)registerForNotificationsAndDraggedTypes { |
| 119 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter]; | 136 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter]; |
| 120 [defaultCenter addObserver:self | 137 [defaultCenter addObserver:self |
| 121 selector:@selector(themeDidChangeNotification:) | 138 selector:@selector(themeDidChangeNotification:) |
| 122 name:kBrowserThemeDidChangeNotification | 139 name:kBrowserThemeDidChangeNotification |
| (...skipping 27 matching lines...) Expand all Loading... |
| 150 } | 167 } |
| 151 | 168 |
| 152 // Adapt appearance to the current theme. Called after theme changes and before | 169 // Adapt appearance to the current theme. Called after theme changes and before |
| 153 // this is shown for the first time. | 170 // this is shown for the first time. |
| 154 - (void)updateTheme:(const ui::ThemeProvider*)themeProvider { | 171 - (void)updateTheme:(const ui::ThemeProvider*)themeProvider { |
| 155 if (!themeProvider) | 172 if (!themeProvider) |
| 156 return; | 173 return; |
| 157 | 174 |
| 158 NSColor* color = | 175 NSColor* color = |
| 159 themeProvider->GetNSColor(ThemeProperties::COLOR_BOOKMARK_TEXT); | 176 themeProvider->GetNSColor(ThemeProperties::COLOR_BOOKMARK_TEXT); |
| 160 [noItemTextField_ setTextColor:color]; | 177 [noItemTextfield_ setTextColor:color]; |
| 161 } | 178 } |
| 162 | 179 |
| 163 // Mouse down events on the bookmark bar should not allow dragging the parent | 180 // Mouse down events on the bookmark bar should not allow dragging the parent |
| 164 // window around. | 181 // window around. |
| 165 - (BOOL)mouseDownCanMoveWindow { | 182 - (BOOL)mouseDownCanMoveWindow { |
| 166 return NO; | 183 return NO; |
| 167 } | 184 } |
| 168 | 185 |
| 169 - (NSTextField*)noItemTextField { | 186 - (NSTextField*)noItemTextfield { |
| 170 return noItemTextField_; | 187 return noItemTextfield_; |
| 188 } |
| 189 |
| 190 - (NSView*)noItemContainer { |
| 191 return noItemContainer_; |
| 171 } | 192 } |
| 172 | 193 |
| 173 - (NSButton*)importBookmarksButton { | 194 - (NSButton*)importBookmarksButton { |
| 174 return importBookmarksButton_; | 195 return importBookmarksButton_; |
| 175 } | 196 } |
| 176 | 197 |
| 177 // Internal method, needs to be called whenever a change has been made to | 198 // Internal method, needs to be called whenever a change has been made to |
| 178 // dropIndicatorShown_ or dropIndicatorPosition_ so it can get the controller | 199 // dropIndicatorShown_ or dropIndicatorPosition_ so it can get the controller |
| 179 // to reflect the change by moving buttons around. | 200 // to reflect the change by moving buttons around. |
| 180 - (void)dropIndicatorChanged { | 201 - (void)dropIndicatorChanged { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 // drop indicator if one was shown. | 250 // drop indicator if one was shown. |
| 230 if (dropIndicatorShown_) { | 251 if (dropIndicatorShown_) { |
| 231 dropIndicatorShown_ = NO; | 252 dropIndicatorShown_ = NO; |
| 232 [self dropIndicatorChanged]; | 253 [self dropIndicatorChanged]; |
| 233 } | 254 } |
| 234 } | 255 } |
| 235 | 256 |
| 236 - (void)draggingEnded:(id<NSDraggingInfo>)info { | 257 - (void)draggingEnded:(id<NSDraggingInfo>)info { |
| 237 [controller_ draggingEnded:info]; | 258 [controller_ draggingEnded:info]; |
| 238 | 259 |
| 260 [[BookmarkButton draggedButton] setHidden:NO]; |
| 239 if (dropIndicatorShown_) { | 261 if (dropIndicatorShown_) { |
| 240 dropIndicatorShown_ = NO; | 262 dropIndicatorShown_ = NO; |
| 241 [self dropIndicatorChanged]; | 263 [self dropIndicatorChanged]; |
| 242 } | 264 } |
| 243 [controller_ draggingEnded:info]; | 265 [controller_ draggingEnded:info]; |
| 244 } | 266 } |
| 245 | 267 |
| 246 - (BOOL)wantsPeriodicDraggingUpdates { | 268 - (BOOL)wantsPeriodicDraggingUpdates { |
| 247 return YES; | 269 return YES; |
| 248 } | 270 } |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 | 349 |
| 328 - (NSMenu*)menu { | 350 - (NSMenu*)menu { |
| 329 return [[controller_ menuController] menuForBookmarkBar]; | 351 return [[controller_ menuController] menuForBookmarkBar]; |
| 330 } | 352 } |
| 331 | 353 |
| 332 - (ViewID)viewID { | 354 - (ViewID)viewID { |
| 333 return VIEW_ID_BOOKMARK_BAR; | 355 return VIEW_ID_BOOKMARK_BAR; |
| 334 } | 356 } |
| 335 | 357 |
| 336 @end // @implementation BookmarkBarView | 358 @end // @implementation BookmarkBarView |
| OLD | NEW |