| 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/menu_button.h" | 5 #import "chrome/browser/ui/cocoa/menu_button.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #import "chrome/browser/ui/cocoa/clickhold_button_cell.h" | 8 #import "chrome/browser/ui/cocoa/clickhold_button_cell.h" |
| 9 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" |
| 10 #include "ui/base/material_design/material_design_controller.h" |
| 9 #import "ui/base/cocoa/nsview_additions.h" | 11 #import "ui/base/cocoa/nsview_additions.h" |
| 12 #include "ui/base/material_design/material_design_controller.h" |
| 10 | 13 |
| 11 @interface MenuButton (Private) | 14 @interface MenuButton (Private) |
| 12 - (void)showMenu:(BOOL)isDragging; | 15 - (void)showMenu:(BOOL)isDragging; |
| 13 - (void)clickShowMenu:(id)sender; | 16 - (void)clickShowMenu:(id)sender; |
| 14 - (void)dragShowMenu:(id)sender; | 17 - (void)dragShowMenu:(id)sender; |
| 15 @end // @interface MenuButton (Private) | 18 @end // @interface MenuButton (Private) |
| 16 | 19 |
| 17 @implementation MenuButton | 20 @implementation MenuButton |
| 18 | 21 |
| 19 @synthesize openMenuOnClick = openMenuOnClick_; | 22 @synthesize openMenuOnClick = openMenuOnClick_; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 | 153 |
| 151 // TODO(viettrungluu): We have some fudge factors below to make things line up | 154 // TODO(viettrungluu): We have some fudge factors below to make things line up |
| 152 // (approximately). I wish I knew how to get rid of them. (Note that our view | 155 // (approximately). I wish I knew how to get rid of them. (Note that our view |
| 153 // is flipped, and that frame should be in our coordinates.) The y/height is | 156 // is flipped, and that frame should be in our coordinates.) The y/height is |
| 154 // very odd, since it doesn't seem to respond to changes the way that it | 157 // very odd, since it doesn't seem to respond to changes the way that it |
| 155 // should. I don't understand it. | 158 // should. I don't understand it. |
| 156 NSRect frame = [self menuRect]; | 159 NSRect frame = [self menuRect]; |
| 157 frame.origin.x -= 2.0; | 160 frame.origin.x -= 2.0; |
| 158 frame.size.height -= 19.0 - NSHeight(frame); | 161 frame.size.height -= 19.0 - NSHeight(frame); |
| 159 | 162 |
| 163 // The button's icon has a different relationship to its bounds in |
| 164 // Material Design, so have to adjust the menu location by that delta. |
| 165 if (ui::MaterialDesignController::IsModeMaterial()) { |
| 166 frame.origin.x -= [ToolbarController materialDesignButtonInset]; |
| 167 frame.origin.y += [ToolbarController materialDesignButtonInset]; |
| 168 } |
| 169 |
| 160 // Make our pop-up button cell and set things up. This is, as of 10.5, the | 170 // Make our pop-up button cell and set things up. This is, as of 10.5, the |
| 161 // official Apple-recommended hack. Later, perhaps |-[NSMenu | 171 // official Apple-recommended hack. Later, perhaps |-[NSMenu |
| 162 // popUpMenuPositioningItem:atLocation:inView:]| may be a better option. | 172 // popUpMenuPositioningItem:atLocation:inView:]| may be a better option. |
| 163 // However, using a pulldown has the benefit that Cocoa automatically places | 173 // However, using a pulldown has the benefit that Cocoa automatically places |
| 164 // the menu correctly even when we're at the edge of the screen (including | 174 // the menu correctly even when we're at the edge of the screen (including |
| 165 // "dragging upwards" when the button is close to the bottom of the screen). | 175 // "dragging upwards" when the button is close to the bottom of the screen). |
| 166 // A |scoped_nsobject| local variable cannot be used here because | 176 // A |scoped_nsobject| local variable cannot be used here because |
| 167 // Accessibility on 10.5 grabs the NSPopUpButtonCell without retaining it, and | 177 // Accessibility on 10.5 grabs the NSPopUpButtonCell without retaining it, and |
| 168 // uses it later. (This is fixed in 10.6.) | 178 // uses it later. (This is fixed in 10.6.) |
| 169 if (!popUpCell_.get()) { | 179 if (!popUpCell_.get()) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 195 } | 205 } |
| 196 | 206 |
| 197 // Called when the button is clicked and dragged/held. | 207 // Called when the button is clicked and dragged/held. |
| 198 - (void)dragShowMenu:(id)sender { | 208 - (void)dragShowMenu:(id)sender { |
| 199 // We shouldn't get here unless the menu is enabled. | 209 // We shouldn't get here unless the menu is enabled. |
| 200 DCHECK([self attachedMenu]); | 210 DCHECK([self attachedMenu]); |
| 201 [self showMenu:YES]; | 211 [self showMenu:YES]; |
| 202 } | 212 } |
| 203 | 213 |
| 204 @end // @implementation MenuButton (Private) | 214 @end // @implementation MenuButton (Private) |
| OLD | NEW |