| 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" | 9 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" |
| 10 #include "ui/base/material_design/material_design_controller.h" | 10 #include "ui/base/material_design/material_design_controller.h" |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 | 153 |
| 154 // 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 |
| 155 // (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 |
| 156 // 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 |
| 157 // 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 |
| 158 // should. I don't understand it. | 158 // should. I don't understand it. |
| 159 NSRect frame = [self menuRect]; | 159 NSRect frame = [self menuRect]; |
| 160 frame.origin.x -= 2.0; | 160 frame.origin.x -= 2.0; |
| 161 frame.size.height -= 19.0 - NSHeight(frame); | 161 frame.size.height -= 19.0 - NSHeight(frame); |
| 162 | 162 |
| 163 // The button's icon has a different relationship to its bounds in | 163 // The button's icon has a different relationship to its bounds, so have to |
| 164 // Material Design, so have to adjust the menu location by that delta. | 164 // adjust the menu location by that delta. |
| 165 if (ui::MaterialDesignController::IsModeMaterial()) { | 165 frame.origin.x -= [ToolbarController materialDesignButtonInset]; |
| 166 frame.origin.x -= [ToolbarController materialDesignButtonInset]; | 166 frame.origin.y += [ToolbarController materialDesignButtonInset]; |
| 167 frame.origin.y += [ToolbarController materialDesignButtonInset]; | |
| 168 } | |
| 169 | 167 |
| 170 // Make our pop-up button cell and set things up. This is, as of 10.5, the | 168 // Make our pop-up button cell and set things up. This is, as of 10.5, the |
| 171 // official Apple-recommended hack. Later, perhaps |-[NSMenu | 169 // official Apple-recommended hack. Later, perhaps |-[NSMenu |
| 172 // popUpMenuPositioningItem:atLocation:inView:]| may be a better option. | 170 // popUpMenuPositioningItem:atLocation:inView:]| may be a better option. |
| 173 // However, using a pulldown has the benefit that Cocoa automatically places | 171 // However, using a pulldown has the benefit that Cocoa automatically places |
| 174 // the menu correctly even when we're at the edge of the screen (including | 172 // the menu correctly even when we're at the edge of the screen (including |
| 175 // "dragging upwards" when the button is close to the bottom of the screen). | 173 // "dragging upwards" when the button is close to the bottom of the screen). |
| 176 // A |scoped_nsobject| local variable cannot be used here because | 174 // A |scoped_nsobject| local variable cannot be used here because |
| 177 // Accessibility on 10.5 grabs the NSPopUpButtonCell without retaining it, and | 175 // Accessibility on 10.5 grabs the NSPopUpButtonCell without retaining it, and |
| 178 // uses it later. (This is fixed in 10.6.) | 176 // uses it later. (This is fixed in 10.6.) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 205 } | 203 } |
| 206 | 204 |
| 207 // Called when the button is clicked and dragged/held. | 205 // Called when the button is clicked and dragged/held. |
| 208 - (void)dragShowMenu:(id)sender { | 206 - (void)dragShowMenu:(id)sender { |
| 209 // We shouldn't get here unless the menu is enabled. | 207 // We shouldn't get here unless the menu is enabled. |
| 210 DCHECK([self attachedMenu]); | 208 DCHECK([self attachedMenu]); |
| 211 [self showMenu:YES]; | 209 [self showMenu:YES]; |
| 212 } | 210 } |
| 213 | 211 |
| 214 @end // @implementation MenuButton (Private) | 212 @end // @implementation MenuButton (Private) |
| OLD | NEW |