| OLD | NEW |
| 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_controller.h" | 5 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" |
| 6 | 6 |
| 7 #include "base/mac/bundle_locations.h" | 7 #include "base/mac/bundle_locations.h" |
| 8 #include "base/mac/mac_util.h" | 8 #include "base/mac/mac_util.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/sys_string_conversions.h" | 10 #include "base/sys_string_conversions.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_menu_cocoa_controller.h" | 37 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_menu_cocoa_controller.h" |
| 38 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_name_folder_controller.h" | 38 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_name_folder_controller.h" |
| 39 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 39 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 40 #import "chrome/browser/ui/cocoa/event_utils.h" | 40 #import "chrome/browser/ui/cocoa/event_utils.h" |
| 41 #import "chrome/browser/ui/cocoa/menu_button.h" | 41 #import "chrome/browser/ui/cocoa/menu_button.h" |
| 42 #import "chrome/browser/ui/cocoa/presentation_mode_controller.h" | 42 #import "chrome/browser/ui/cocoa/presentation_mode_controller.h" |
| 43 #import "chrome/browser/ui/cocoa/themed_window.h" | 43 #import "chrome/browser/ui/cocoa/themed_window.h" |
| 44 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" | 44 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" |
| 45 #import "chrome/browser/ui/cocoa/view_id_util.h" | 45 #import "chrome/browser/ui/cocoa/view_id_util.h" |
| 46 #import "chrome/browser/ui/cocoa/view_resizer.h" | 46 #import "chrome/browser/ui/cocoa/view_resizer.h" |
| 47 #include "chrome/browser/ui/search/search.h" |
| 48 #include "chrome/browser/ui/search/search_ui.h" |
| 47 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" | 49 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" |
| 48 #include "chrome/common/extensions/extension_constants.h" | 50 #include "chrome/common/extensions/extension_constants.h" |
| 49 #include "chrome/common/pref_names.h" | 51 #include "chrome/common/pref_names.h" |
| 50 #include "content/public/browser/user_metrics.h" | 52 #include "content/public/browser/user_metrics.h" |
| 51 #include "content/public/browser/web_contents.h" | 53 #include "content/public/browser/web_contents.h" |
| 52 #include "content/public/browser/web_contents_view.h" | 54 #include "content/public/browser/web_contents_view.h" |
| 53 #include "grit/generated_resources.h" | 55 #include "grit/generated_resources.h" |
| 54 #include "grit/theme_resources.h" | 56 #include "grit/theme_resources.h" |
| 55 #include "grit/ui_resources.h" | 57 #include "grit/ui_resources.h" |
| 56 #include "ui/base/l10n/l10n_util_mac.h" | 58 #include "ui/base/l10n/l10n_util_mac.h" |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 delegate_ = delegate; | 251 delegate_ = delegate; |
| 250 resizeDelegate_ = resizeDelegate; | 252 resizeDelegate_ = resizeDelegate; |
| 251 folderTarget_.reset([[BookmarkFolderTarget alloc] initWithController:self]); | 253 folderTarget_.reset([[BookmarkFolderTarget alloc] initWithController:self]); |
| 252 | 254 |
| 253 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 255 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 254 folderImage_.reset( | 256 folderImage_.reset( |
| 255 rb.GetNativeImageNamed(IDR_BOOKMARK_BAR_FOLDER).CopyNSImage()); | 257 rb.GetNativeImageNamed(IDR_BOOKMARK_BAR_FOLDER).CopyNSImage()); |
| 256 defaultImage_.reset( | 258 defaultImage_.reset( |
| 257 rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).CopyNSImage()); | 259 rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).CopyNSImage()); |
| 258 | 260 |
| 261 // Disable animations if the detached bookmark bar will be shown at the |
| 262 // bottom of the new tab page. |
| 263 if ([self shouldShowAtBottomWhenDetached]) |
| 264 ignoreAnimations_ = YES; |
| 265 |
| 259 // Register for theme changes, bookmark button pulsing, ... | 266 // Register for theme changes, bookmark button pulsing, ... |
| 260 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter]; | 267 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter]; |
| 261 [defaultCenter addObserver:self | 268 [defaultCenter addObserver:self |
| 262 selector:@selector(themeDidChangeNotification:) | 269 selector:@selector(themeDidChangeNotification:) |
| 263 name:kBrowserThemeDidChangeNotification | 270 name:kBrowserThemeDidChangeNotification |
| 264 object:nil]; | 271 object:nil]; |
| 265 [defaultCenter addObserver:self | 272 [defaultCenter addObserver:self |
| 266 selector:@selector(pulseBookmarkNotification:) | 273 selector:@selector(pulseBookmarkNotification:) |
| 267 name:bookmark_button::kPulseBookmarkButtonNotification | 274 name:bookmark_button::kPulseBookmarkButtonNotification |
| 268 object:nil]; | 275 object:nil]; |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 [buttonView_ setFrame:buttonViewFrame]; | 475 [buttonView_ setFrame:buttonViewFrame]; |
| 469 } | 476 } |
| 470 | 477 |
| 471 // We don't change a preference; we only change visibility. Preference changing | 478 // We don't change a preference; we only change visibility. Preference changing |
| 472 // (global state) is handled in |BrowserWindowCocoa::ToggleBookmarkBar()|. We | 479 // (global state) is handled in |BrowserWindowCocoa::ToggleBookmarkBar()|. We |
| 473 // simply update based on what we're told. | 480 // simply update based on what we're told. |
| 474 - (void)updateVisibility { | 481 - (void)updateVisibility { |
| 475 [self showBookmarkBarWithAnimation:NO]; | 482 [self showBookmarkBarWithAnimation:NO]; |
| 476 } | 483 } |
| 477 | 484 |
| 485 - (void)updateHiddenState { |
| 486 BOOL oldHidden = [[self view] isHidden]; |
| 487 BOOL newHidden = ![self isVisible]; |
| 488 if (oldHidden != newHidden) |
| 489 [[self view] setHidden:newHidden]; |
| 490 } |
| 491 |
| 492 - (BOOL)shouldShowAtBottomWhenDetached { |
| 493 return chrome::search::IsInstantExtendedAPIEnabled(browser_->profile()); |
| 494 } |
| 495 |
| 478 - (void)setBookmarkBarEnabled:(BOOL)enabled { | 496 - (void)setBookmarkBarEnabled:(BOOL)enabled { |
| 479 if (enabled != barIsEnabled_) { | 497 if (enabled != barIsEnabled_) { |
| 480 barIsEnabled_ = enabled; | 498 barIsEnabled_ = enabled; |
| 481 [self updateVisibility]; | 499 [self updateVisibility]; |
| 482 } | 500 } |
| 483 } | 501 } |
| 484 | 502 |
| 485 - (CGFloat)getDesiredToolbarHeightCompression { | 503 - (CGFloat)getDesiredToolbarHeightCompression { |
| 486 // Some special cases.... | 504 // Some special cases.... |
| 487 if (!barIsEnabled_) | 505 if (!barIsEnabled_) |
| (...skipping 1783 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2271 // TODO(jrg): for now this is brute force. | 2289 // TODO(jrg): for now this is brute force. |
| 2272 - (void)nodeChildrenReordered:(BookmarkModel*)model | 2290 - (void)nodeChildrenReordered:(BookmarkModel*)model |
| 2273 node:(const BookmarkNode*)node { | 2291 node:(const BookmarkNode*)node { |
| 2274 [self loaded:model]; | 2292 [self loaded:model]; |
| 2275 } | 2293 } |
| 2276 | 2294 |
| 2277 #pragma mark BookmarkBarState Protocol | 2295 #pragma mark BookmarkBarState Protocol |
| 2278 | 2296 |
| 2279 // (BookmarkBarState protocol) | 2297 // (BookmarkBarState protocol) |
| 2280 - (BOOL)isVisible { | 2298 - (BOOL)isVisible { |
| 2299 if ([self shouldShowAtBottomWhenDetached] && |
| 2300 visualState_ == bookmarks::kDetachedState && |
| 2301 [self currentTabContentsHeight] < |
| 2302 chrome::search::kMinContentHeightForBottomBookmarkBar) { |
| 2303 return NO; |
| 2304 } |
| 2305 |
| 2281 return barIsEnabled_ && (visualState_ == bookmarks::kShowingState || | 2306 return barIsEnabled_ && (visualState_ == bookmarks::kShowingState || |
| 2282 visualState_ == bookmarks::kDetachedState || | 2307 visualState_ == bookmarks::kDetachedState || |
| 2283 lastVisualState_ == bookmarks::kShowingState || | 2308 lastVisualState_ == bookmarks::kShowingState || |
| 2284 lastVisualState_ == bookmarks::kDetachedState); | 2309 lastVisualState_ == bookmarks::kDetachedState); |
| 2285 } | 2310 } |
| 2286 | 2311 |
| 2287 // (BookmarkBarState protocol) | 2312 // (BookmarkBarState protocol) |
| 2288 - (BOOL)isAnimationRunning { | 2313 - (BOOL)isAnimationRunning { |
| 2289 return lastVisualState_ != bookmarks::kInvalidState; | 2314 return lastVisualState_ != bookmarks::kInvalidState; |
| 2290 } | 2315 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2331 if ([self isAnimatingFromState:bookmarks::kDetachedState]) { | 2356 if ([self isAnimatingFromState:bookmarks::kDetachedState]) { |
| 2332 return static_cast<CGFloat>( | 2357 return static_cast<CGFloat>( |
| 2333 1 - [[self animatableView] currentAnimationProgress]); | 2358 1 - [[self animatableView] currentAnimationProgress]); |
| 2334 } | 2359 } |
| 2335 return 0; | 2360 return 0; |
| 2336 } | 2361 } |
| 2337 | 2362 |
| 2338 #pragma mark BookmarkBarToolbarViewController Protocol | 2363 #pragma mark BookmarkBarToolbarViewController Protocol |
| 2339 | 2364 |
| 2340 - (int)currentTabContentsHeight { | 2365 - (int)currentTabContentsHeight { |
| 2341 WebContents* wc = chrome::GetActiveWebContents(browser_); | 2366 BrowserWindowController* browserController = |
| 2342 return wc ? wc->GetView()->GetContainerSize().height() : 0; | 2367 [BrowserWindowController browserWindowControllerForView:[self view]]; |
| 2368 return NSHeight([[browserController tabContentArea] frame]); |
| 2343 } | 2369 } |
| 2344 | 2370 |
| 2345 - (ui::ThemeProvider*)themeProvider { | 2371 - (ui::ThemeProvider*)themeProvider { |
| 2346 return ThemeServiceFactory::GetForProfile(browser_->profile()); | 2372 return ThemeServiceFactory::GetForProfile(browser_->profile()); |
| 2347 } | 2373 } |
| 2348 | 2374 |
| 2349 #pragma mark BookmarkButtonDelegate Protocol | 2375 #pragma mark BookmarkButtonDelegate Protocol |
| 2350 | 2376 |
| 2351 - (void)fillPasteboard:(NSPasteboard*)pboard | 2377 - (void)fillPasteboard:(NSPasteboard*)pboard |
| 2352 forDragOfButton:(BookmarkButton*)button { | 2378 forDragOfButton:(BookmarkButton*)button { |
| (...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2833 // to minimize touching the object passed in (likely a mock). | 2859 // to minimize touching the object passed in (likely a mock). |
| 2834 - (void)setButtonContextMenu:(id)menu { | 2860 - (void)setButtonContextMenu:(id)menu { |
| 2835 buttonContextMenu_ = menu; | 2861 buttonContextMenu_ = menu; |
| 2836 } | 2862 } |
| 2837 | 2863 |
| 2838 - (void)setIgnoreAnimations:(BOOL)ignore { | 2864 - (void)setIgnoreAnimations:(BOOL)ignore { |
| 2839 ignoreAnimations_ = ignore; | 2865 ignoreAnimations_ = ignore; |
| 2840 } | 2866 } |
| 2841 | 2867 |
| 2842 @end | 2868 @end |
| OLD | NEW |