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