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

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

Issue 2751573002: [Mac] Refactor bookmark bar controller (Closed)
Patch Set: Factor layout tests to helper, address CL comments Created 3 years, 7 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) 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
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; 31 static const CGFloat kInitialElementYOrigin = 7;
32 static const CGFloat kInitialContainerHeight = 41;
33 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
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 [noItemContainer_ setAutoresizingMask:NSViewWidthSizable];
88 79
89 noItemTextfield_.reset([[NSTextField alloc] 80 noItemTextField_.reset([[NSTextField alloc]
90 initWithFrame:NSMakeRect(kInitialTextFieldXOrigin, 81 initWithFrame:NSMakeRect(kInitialTextFieldXOrigin,
91 kInitialElementYOrigin, CGFLOAT_MAX, 82 kInitialElementYOrigin, CGFLOAT_MAX,
92 kInitialElementHeight)]); 83 kInitialElementHeight)]);
93 [noItemTextfield_ setAutoresizingMask:NSViewWidthSizable]; 84 [noItemTextField_ setFont:smallSystemFont];
94 [noItemTextfield_ setFont:smallSystemFont]; 85 [noItemTextField_
95 [noItemTextfield_
96 setStringValue:l10n_util::GetNSString(IDS_BOOKMARKS_NO_ITEMS)]; 86 setStringValue:l10n_util::GetNSString(IDS_BOOKMARKS_NO_ITEMS)];
97 [noItemTextfield_ setEditable:NO]; 87 [noItemTextField_ setEditable:NO];
98 88
99 [noItemTextfield_ setBordered:NO]; 89 [noItemTextField_ setBordered:NO];
100 [[noItemTextfield_ cell] setLineBreakMode:NSLineBreakByTruncatingTail]; 90 [[noItemTextField_ cell] setLineBreakMode:NSLineBreakByTruncatingTail];
101 91
102 [noItemTextfield_ setTextColor:[NSColor controlTextColor]]; 92 [noItemTextField_ setTextColor:[NSColor controlTextColor]];
103 [noItemTextfield_ setBackgroundColor:[NSColor controlColor]]; 93 [noItemTextField_ setBackgroundColor:[NSColor controlColor]];
104 94
105 [noItemTextfield_ setDrawsBackground:NO]; 95 [noItemTextField_ setDrawsBackground:NO];
106 [noItemTextfield_ setTextColor:[NSColor controlTextColor]]; 96 [noItemTextField_ setTextColor:[NSColor controlTextColor]];
107 [noItemTextfield_ setBackgroundColor:[NSColor controlColor]]; 97 [noItemTextField_ setBackgroundColor:[NSColor controlColor]];
108 [noItemTextfield_ sizeToFit]; 98 [noItemTextField_ sizeToFit];
109 99
110 NSButton* importButton = [HyperlinkButtonCell 100 NSButton* importButton = [HyperlinkButtonCell
111 buttonWithString:l10n_util::GetNSString(IDS_BOOKMARK_BAR_IMPORT_LINK)]; 101 buttonWithString:l10n_util::GetNSString(IDS_BOOKMARK_BAR_IMPORT_LINK)];
112 importBookmarksButton_.reset([importButton retain]); 102 importBookmarksButton_.reset([importButton retain]);
113 [importBookmarksButton_ 103 [importBookmarksButton_
114 setFrame:NSMakeRect(NSMaxX([noItemTextfield_ frame]) + 104 setFrame:NSMakeRect(NSMaxX([noItemTextField_ frame]) +
115 kTextFieldTrailingPadding, 105 kTextFieldTrailingPadding,
116 kInitialElementYOrigin, CGFLOAT_MAX, 106 kInitialElementYOrigin, CGFLOAT_MAX,
117 kInitialElementHeight)]; 107 kInitialElementHeight)];
118 [importBookmarksButton_ setAutoresizingMask:NSViewMaxXMargin];
119 [importBookmarksButton_ setFont:smallSystemFont]; 108 [importBookmarksButton_ setFont:smallSystemFont];
120 [importBookmarksButton_ sizeToFit]; 109 [importBookmarksButton_ sizeToFit];
121 [noItemContainer_ addSubview:importBookmarksButton_];
122 110
123 [noItemContainer_ addSubview:noItemTextfield_]; 111 [self addSubview:noItemTextField_];
124 NSRect containerFrame = [noItemContainer_ frame]; 112 [self addSubview:importBookmarksButton_];
125 containerFrame.size.width = std::max(
126 NSWidth(containerFrame), NSMaxX([importBookmarksButton_ frame]));
127 [noItemContainer_ setFrame:containerFrame];
128
129 [self addSubview:noItemContainer_];
130 [self registerForNotificationsAndDraggedTypes]; 113 [self registerForNotificationsAndDraggedTypes];
131 } 114 }
132 return self; 115 return self;
133 } 116 }
134 117
135 - (void)registerForNotificationsAndDraggedTypes { 118 - (void)registerForNotificationsAndDraggedTypes {
136 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter]; 119 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter];
137 [defaultCenter addObserver:self 120 [defaultCenter addObserver:self
138 selector:@selector(themeDidChangeNotification:) 121 selector:@selector(themeDidChangeNotification:)
139 name:kBrowserThemeDidChangeNotification 122 name:kBrowserThemeDidChangeNotification
(...skipping 27 matching lines...) Expand all
167 } 150 }
168 151
169 // 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
170 // this is shown for the first time. 153 // this is shown for the first time.
171 - (void)updateTheme:(const ui::ThemeProvider*)themeProvider { 154 - (void)updateTheme:(const ui::ThemeProvider*)themeProvider {
172 if (!themeProvider) 155 if (!themeProvider)
173 return; 156 return;
174 157
175 NSColor* color = 158 NSColor* color =
176 themeProvider->GetNSColor(ThemeProperties::COLOR_BOOKMARK_TEXT); 159 themeProvider->GetNSColor(ThemeProperties::COLOR_BOOKMARK_TEXT);
177 [noItemTextfield_ setTextColor:color]; 160 [noItemTextField_ setTextColor:color];
178 } 161 }
179 162
180 // 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
181 // window around. 164 // window around.
182 - (BOOL)mouseDownCanMoveWindow { 165 - (BOOL)mouseDownCanMoveWindow {
183 return NO; 166 return NO;
184 } 167 }
185 168
186 - (NSTextField*)noItemTextfield { 169 - (NSTextField*)noItemTextField {
187 return noItemTextfield_; 170 return noItemTextField_;
188 }
189
190 - (NSView*)noItemContainer {
191 return noItemContainer_;
192 } 171 }
193 172
194 - (NSButton*)importBookmarksButton { 173 - (NSButton*)importBookmarksButton {
195 return importBookmarksButton_; 174 return importBookmarksButton_;
196 } 175 }
197 176
198 // 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
199 // dropIndicatorShown_ or dropIndicatorPosition_ so it can get the controller 178 // dropIndicatorShown_ or dropIndicatorPosition_ so it can get the controller
200 // to reflect the change by moving buttons around. 179 // to reflect the change by moving buttons around.
201 - (void)dropIndicatorChanged { 180 - (void)dropIndicatorChanged {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 // drop indicator if one was shown. 229 // drop indicator if one was shown.
251 if (dropIndicatorShown_) { 230 if (dropIndicatorShown_) {
252 dropIndicatorShown_ = NO; 231 dropIndicatorShown_ = NO;
253 [self dropIndicatorChanged]; 232 [self dropIndicatorChanged];
254 } 233 }
255 } 234 }
256 235
257 - (void)draggingEnded:(id<NSDraggingInfo>)info { 236 - (void)draggingEnded:(id<NSDraggingInfo>)info {
258 [controller_ draggingEnded:info]; 237 [controller_ draggingEnded:info];
259 238
260 [[BookmarkButton draggedButton] setHidden:NO];
261 if (dropIndicatorShown_) { 239 if (dropIndicatorShown_) {
262 dropIndicatorShown_ = NO; 240 dropIndicatorShown_ = NO;
263 [self dropIndicatorChanged]; 241 [self dropIndicatorChanged];
264 } 242 }
265 [controller_ draggingEnded:info]; 243 [controller_ draggingEnded:info];
266 } 244 }
267 245
268 - (BOOL)wantsPeriodicDraggingUpdates { 246 - (BOOL)wantsPeriodicDraggingUpdates {
269 return YES; 247 return YES;
270 } 248 }
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 327
350 - (NSMenu*)menu { 328 - (NSMenu*)menu {
351 return [[controller_ menuController] menuForBookmarkBar]; 329 return [[controller_ menuController] menuForBookmarkBar];
352 } 330 }
353 331
354 - (ViewID)viewID { 332 - (ViewID)viewID {
355 return VIEW_ID_BOOKMARK_BAR; 333 return VIEW_ID_BOOKMARK_BAR;
356 } 334 }
357 335
358 @end // @implementation BookmarkBarView 336 @end // @implementation BookmarkBarView
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698