| 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/location_bar/action_box_menu_bubble_controller.
h" | 5 #import "chrome/browser/ui/cocoa/location_bar/action_box_menu_bubble_controller.
h" |
| 6 | 6 |
| 7 #include "base/mac/bundle_locations.h" | 7 #include "base/mac/bundle_locations.h" |
| 8 #include "base/mac/foundation_util.h" | 8 #include "base/mac/foundation_util.h" |
| 9 #include "base/mac/mac_util.h" | 9 #include "base/mac/mac_util.h" |
| 10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 | 93 |
| 94 @implementation ActionBoxMenuBubbleController | 94 @implementation ActionBoxMenuBubbleController |
| 95 | 95 |
| 96 - (id)initWithModel:(scoped_ptr<ActionBoxMenuModel>)model | 96 - (id)initWithModel:(scoped_ptr<ActionBoxMenuModel>)model |
| 97 parentWindow:(NSWindow*)parent | 97 parentWindow:(NSWindow*)parent |
| 98 anchoredAt:(NSPoint)point | 98 anchoredAt:(NSPoint)point |
| 99 profile:(Profile*)profile { | 99 profile:(Profile*)profile { |
| 100 // Use an arbitrary height because it will reflect the size of the content. | 100 // Use an arbitrary height because it will reflect the size of the content. |
| 101 NSRect contentRect = NSMakeRect(0, 0, kBubbleMinWidth, 150); | 101 NSRect contentRect = NSMakeRect(0, 0, kBubbleMinWidth, 150); |
| 102 // Create an empty window into which content is placed. | 102 // Create an empty window into which content is placed. |
| 103 scoped_nsobject<InfoBubbleWindow> window( | 103 base::scoped_nsobject<InfoBubbleWindow> window( |
| 104 [[InfoBubbleWindow alloc] initWithContentRect:contentRect | 104 [[InfoBubbleWindow alloc] initWithContentRect:contentRect |
| 105 styleMask:NSBorderlessWindowMask | 105 styleMask:NSBorderlessWindowMask |
| 106 backing:NSBackingStoreBuffered | 106 backing:NSBackingStoreBuffered |
| 107 defer:NO]); | 107 defer:NO]); |
| 108 [window setAllowedAnimations:info_bubble::kAnimateNone]; | 108 [window setAllowedAnimations:info_bubble::kAnimateNone]; |
| 109 if (self = [super initWithWindow:window | 109 if (self = [super initWithWindow:window |
| 110 parentWindow:parent | 110 parentWindow:parent |
| 111 anchoredAt:point]) { | 111 anchoredAt:point]) { |
| 112 profile_ = profile; | 112 profile_ = profile; |
| 113 model_.reset(model.release()); | 113 model_.reset(model.release()); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 NSView* contentView = [[self window] contentView]; | 153 NSView* contentView = [[self window] contentView]; |
| 154 | 154 |
| 155 // Reset the array of controllers and remove all the views. | 155 // Reset the array of controllers and remove all the views. |
| 156 items_.reset([[NSMutableArray alloc] init]); | 156 items_.reset([[NSMutableArray alloc] init]); |
| 157 [contentView setSubviews:[NSArray array]]; | 157 [contentView setSubviews:[NSArray array]]; |
| 158 | 158 |
| 159 // Leave some space at the bottom of the menu. | 159 // Leave some space at the bottom of the menu. |
| 160 CGFloat yOffset = kVerticalPadding; | 160 CGFloat yOffset = kVerticalPadding; |
| 161 | 161 |
| 162 // Keep track of a potential separator to resize it when we know the width. | 162 // Keep track of a potential separator to resize it when we know the width. |
| 163 scoped_nsobject<NSBox> separatorView; | 163 base::scoped_nsobject<NSBox> separatorView; |
| 164 | 164 |
| 165 // Loop over the items in reverse, constructing the menu items. | 165 // Loop over the items in reverse, constructing the menu items. |
| 166 CGFloat width = kBubbleMinWidth; | 166 CGFloat width = kBubbleMinWidth; |
| 167 CGFloat minX = NSMinX([contentView bounds]); | 167 CGFloat minX = NSMinX([contentView bounds]); |
| 168 for (int i = model_->GetItemCount() - 1; i >= 0; --i) { | 168 for (int i = model_->GetItemCount() - 1; i >= 0; --i) { |
| 169 if (model_->GetTypeAt(i) == ui::MenuModel::TYPE_SEPARATOR) { | 169 if (model_->GetTypeAt(i) == ui::MenuModel::TYPE_SEPARATOR) { |
| 170 const CGFloat kSeparatorHeight = 1.0; | 170 const CGFloat kSeparatorHeight = 1.0; |
| 171 // Only supports one separator. | 171 // Only supports one separator. |
| 172 DCHECK(!separatorView); | 172 DCHECK(!separatorView); |
| 173 yOffset += kVerticalPadding + kSeparatorHeight; | 173 yOffset += kVerticalPadding + kSeparatorHeight; |
| 174 separatorView.reset([[NSBox alloc] | 174 separatorView.reset([[NSBox alloc] |
| 175 initWithFrame:NSMakeRect(0, yOffset, width, kSeparatorHeight)]); | 175 initWithFrame:NSMakeRect(0, yOffset, width, kSeparatorHeight)]); |
| 176 [separatorView setBoxType:NSBoxCustom]; | 176 [separatorView setBoxType:NSBoxCustom]; |
| 177 ui::NativeTheme* nativeTheme = ui::NativeTheme::instance(); | 177 ui::NativeTheme* nativeTheme = ui::NativeTheme::instance(); |
| 178 [separatorView setBorderColor: | 178 [separatorView setBorderColor: |
| 179 gfx::SkColorToCalibratedNSColor(nativeTheme->GetSystemColor( | 179 gfx::SkColorToCalibratedNSColor(nativeTheme->GetSystemColor( |
| 180 ui::NativeTheme::kColorId_MenuSeparatorColor))]; | 180 ui::NativeTheme::kColorId_MenuSeparatorColor))]; |
| 181 [contentView addSubview:separatorView]; | 181 [contentView addSubview:separatorView]; |
| 182 yOffset += kVerticalPadding; | 182 yOffset += kVerticalPadding; |
| 183 } else { | 183 } else { |
| 184 // Create the item controller. Autorelease it because it will be owned | 184 // Create the item controller. Autorelease it because it will be owned |
| 185 // by the |items_| array. | 185 // by the |items_| array. |
| 186 scoped_nsobject<ActionBoxMenuItemController> itemController( | 186 base::scoped_nsobject<ActionBoxMenuItemController> itemController( |
| 187 [[ActionBoxMenuItemController alloc] | 187 [[ActionBoxMenuItemController alloc] initWithModelIndex:i |
| 188 initWithModelIndex:i | 188 menuController:self |
| 189 menuController:self | 189 profile:profile_]); |
| 190 profile:profile_]); | |
| 191 | 190 |
| 192 // Adjust the name field to fit the string. | 191 // Adjust the name field to fit the string. |
| 193 [GTMUILocalizerAndLayoutTweaker sizeToFitView:[itemController nameField]]; | 192 [GTMUILocalizerAndLayoutTweaker sizeToFitView:[itemController nameField]]; |
| 194 | 193 |
| 195 // Expand the size of the window if required to fit the menu item. | 194 // Expand the size of the window if required to fit the menu item. |
| 196 width = std::max(width, | 195 width = std::max(width, |
| 197 NSMaxX([[itemController nameField] frame]) - minX + kRightMargin); | 196 NSMaxX([[itemController nameField] frame]) - minX + kRightMargin); |
| 198 | 197 |
| 199 // Add the item to the content view. | 198 // Add the item to the content view. |
| 200 [[itemController view] setFrameOrigin:NSMakePoint(0, yOffset)]; | 199 [[itemController view] setFrameOrigin:NSMakePoint(0, yOffset)]; |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 [super accessibilityPerformAction:action]; | 464 [super accessibilityPerformAction:action]; |
| 466 } | 465 } |
| 467 | 466 |
| 468 - (NSColor*)highlightedMenuItemBackgroundColor { | 467 - (NSColor*)highlightedMenuItemBackgroundColor { |
| 469 ui::NativeTheme* nativeTheme = ui::NativeTheme::instance(); | 468 ui::NativeTheme* nativeTheme = ui::NativeTheme::instance(); |
| 470 return gfx::SkColorToCalibratedNSColor(nativeTheme->GetSystemColor( | 469 return gfx::SkColorToCalibratedNSColor(nativeTheme->GetSystemColor( |
| 471 ui::NativeTheme::kColorId_FocusedMenuItemBackgroundColor)); | 470 ui::NativeTheme::kColorId_FocusedMenuItemBackgroundColor)); |
| 472 } | 471 } |
| 473 | 472 |
| 474 @end | 473 @end |
| OLD | NEW |