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 <stddef.h> |
| 8 |
7 #include "base/mac/bundle_locations.h" | 9 #include "base/mac/bundle_locations.h" |
8 #include "base/mac/sdk_forward_declarations.h" | 10 #include "base/mac/sdk_forward_declarations.h" |
9 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
10 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
11 #include "base/strings/sys_string_conversions.h" | 13 #include "base/strings/sys_string_conversions.h" |
12 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 14 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
13 #include "chrome/browser/bookmarks/bookmark_stats.h" | 15 #include "chrome/browser/bookmarks/bookmark_stats.h" |
14 #include "chrome/browser/bookmarks/managed_bookmark_service_factory.h" | 16 #include "chrome/browser/bookmarks/managed_bookmark_service_factory.h" |
15 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 17 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
16 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
(...skipping 1088 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1105 // The "+2" is needed because, sometimes, Cocoa is off by a tad. | 1107 // The "+2" is needed because, sometimes, Cocoa is off by a tad. |
1106 // Example: for a bookmark named "Moma" or "SFGate", it is one pixel | 1108 // Example: for a bookmark named "Moma" or "SFGate", it is one pixel |
1107 // too small. For "FBL" it is 2 pixels too small. | 1109 // too small. For "FBL" it is 2 pixels too small. |
1108 // For a bookmark named "SFGateFooWoo", it is just fine. | 1110 // For a bookmark named "SFGateFooWoo", it is just fine. |
1109 - (CGFloat)widthForBookmarkButtonCell:(NSCell*)cell { | 1111 - (CGFloat)widthForBookmarkButtonCell:(NSCell*)cell { |
1110 CGFloat desired = [cell cellSize].width + 2; | 1112 CGFloat desired = [cell cellSize].width + 2; |
1111 return std::min(desired, bookmarks::kDefaultBookmarkWidth); | 1113 return std::min(desired, bookmarks::kDefaultBookmarkWidth); |
1112 } | 1114 } |
1113 | 1115 |
1114 - (IBAction)openBookmarkMenuItem:(id)sender { | 1116 - (IBAction)openBookmarkMenuItem:(id)sender { |
1115 int64 tag = [self nodeIdFromMenuTag:[sender tag]]; | 1117 int64_t tag = [self nodeIdFromMenuTag:[sender tag]]; |
1116 const BookmarkNode* node = | 1118 const BookmarkNode* node = |
1117 bookmarks::GetBookmarkNodeByID(bookmarkModel_, tag); | 1119 bookmarks::GetBookmarkNodeByID(bookmarkModel_, tag); |
1118 WindowOpenDisposition disposition = | 1120 WindowOpenDisposition disposition = |
1119 ui::WindowOpenDispositionFromNSEvent([NSApp currentEvent]); | 1121 ui::WindowOpenDispositionFromNSEvent([NSApp currentEvent]); |
1120 [self openURL:node->url() disposition:disposition]; | 1122 [self openURL:node->url() disposition:disposition]; |
1121 } | 1123 } |
1122 | 1124 |
1123 // For the given root node of the bookmark bar, show or hide (as | 1125 // For the given root node of the bookmark bar, show or hide (as |
1124 // appropriate) the "no items" container (text which says "bookmarks | 1126 // appropriate) the "no items" container (text which says "bookmarks |
1125 // go here"). | 1127 // go here"). |
(...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1891 | 1893 |
1892 // Called when our controlled frame has changed size. | 1894 // Called when our controlled frame has changed size. |
1893 - (void)frameDidChange { | 1895 - (void)frameDidChange { |
1894 if (!bookmarkModel_->loaded()) | 1896 if (!bookmarkModel_->loaded()) |
1895 return; | 1897 return; |
1896 [self updateTheme:[[[self view] window] themeProvider]]; | 1898 [self updateTheme:[[[self view] window] themeProvider]]; |
1897 [self reconfigureBookmarkBar]; | 1899 [self reconfigureBookmarkBar]; |
1898 } | 1900 } |
1899 | 1901 |
1900 // Given a NSMenuItem tag, return the appropriate bookmark node id. | 1902 // Given a NSMenuItem tag, return the appropriate bookmark node id. |
1901 - (int64)nodeIdFromMenuTag:(int32)tag { | 1903 - (int64_t)nodeIdFromMenuTag:(int32_t)tag { |
1902 return menuTagMap_[tag]; | 1904 return menuTagMap_[tag]; |
1903 } | 1905 } |
1904 | 1906 |
1905 // Create and return a new tag for the given node id. | 1907 // Create and return a new tag for the given node id. |
1906 - (int32)menuTagFromNodeId:(int64)menuid { | 1908 - (int32_t)menuTagFromNodeId:(int64_t)menuid { |
1907 int tag = seedId_++; | 1909 int tag = seedId_++; |
1908 menuTagMap_[tag] = menuid; | 1910 menuTagMap_[tag] = menuid; |
1909 return tag; | 1911 return tag; |
1910 } | 1912 } |
1911 | 1913 |
1912 // Adapt appearance of buttons to the current theme. Called after | 1914 // Adapt appearance of buttons to the current theme. Called after |
1913 // theme changes, or when our view is added to the view hierarchy. | 1915 // theme changes, or when our view is added to the view hierarchy. |
1914 // Oddly, the view pings us instead of us pinging our view. This is | 1916 // Oddly, the view pings us instead of us pinging our view. This is |
1915 // because our trigger is an [NSView viewWillMoveToWindow:], which the | 1917 // because our trigger is an [NSView viewWillMoveToWindow:], which the |
1916 // controller doesn't normally know about. Otherwise we don't have | 1918 // controller doesn't normally know about. Otherwise we don't have |
(...skipping 1021 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2938 - (id<BookmarkButtonControllerProtocol>)controllerForNode: | 2940 - (id<BookmarkButtonControllerProtocol>)controllerForNode: |
2939 (const BookmarkNode*)node { | 2941 (const BookmarkNode*)node { |
2940 // See if it's in the bar, then if it is in the hierarchy of visible | 2942 // See if it's in the bar, then if it is in the hierarchy of visible |
2941 // folder menus. | 2943 // folder menus. |
2942 if (bookmarkModel_->bookmark_bar_node() == node) | 2944 if (bookmarkModel_->bookmark_bar_node() == node) |
2943 return self; | 2945 return self; |
2944 return [folderController_ controllerForNode:node]; | 2946 return [folderController_ controllerForNode:node]; |
2945 } | 2947 } |
2946 | 2948 |
2947 @end | 2949 @end |
OLD | NEW |