| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/views/controls/menu/menu_runner_impl_cocoa.h" | 5 #import "ui/views/controls/menu/menu_runner_impl_cocoa.h" |
| 6 | 6 |
| 7 #include "base/mac/sdk_forward_declarations.h" |
| 7 #import "ui/base/cocoa/menu_controller.h" | 8 #import "ui/base/cocoa/menu_controller.h" |
| 8 #include "ui/base/models/menu_model.h" | 9 #include "ui/base/models/menu_model.h" |
| 9 #include "ui/events/event_utils.h" | 10 #include "ui/events/event_utils.h" |
| 10 #include "ui/gfx/geometry/rect.h" | 11 #include "ui/gfx/geometry/rect.h" |
| 11 #include "ui/gfx/mac/coordinate_conversion.h" | 12 #include "ui/gfx/mac/coordinate_conversion.h" |
| 12 #include "ui/views/controls/menu/menu_runner_impl_adapter.h" | 13 #include "ui/views/controls/menu/menu_runner_impl_adapter.h" |
| 13 #include "ui/views/widget/widget.h" | 14 #include "ui/views/widget/widget.h" |
| 14 | 15 |
| 15 namespace views { | 16 namespace views { |
| 16 namespace internal { | 17 namespace internal { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 34 | 35 |
| 35 // Places a temporary, hidden NSView at |screen_bounds| within |window|. Used | 36 // Places a temporary, hidden NSView at |screen_bounds| within |window|. Used |
| 36 // with -[NSMenu popUpMenuPositioningItem:atLocation:inView:] to position the | 37 // with -[NSMenu popUpMenuPositioningItem:atLocation:inView:] to position the |
| 37 // menu for a combobox. The caller must remove the returned NSView from its | 38 // menu for a combobox. The caller must remove the returned NSView from its |
| 38 // superview when the menu is closed. | 39 // superview when the menu is closed. |
| 39 base::scoped_nsobject<NSView> CreateMenuAnchorView( | 40 base::scoped_nsobject<NSView> CreateMenuAnchorView( |
| 40 NSWindow* window, | 41 NSWindow* window, |
| 41 const gfx::Rect& screen_bounds, | 42 const gfx::Rect& screen_bounds, |
| 42 NSMenuItem* checked_item) { | 43 NSMenuItem* checked_item) { |
| 43 NSRect rect = gfx::ScreenRectToNSRect(screen_bounds); | 44 NSRect rect = gfx::ScreenRectToNSRect(screen_bounds); |
| 44 rect.origin = [window convertScreenToBase:rect.origin]; | 45 rect = [window convertRectFromScreen:rect]; |
| 45 rect = [[window contentView] convertRect:rect fromView:nil]; | 46 rect = [[window contentView] convertRect:rect fromView:nil]; |
| 46 | 47 |
| 47 // If there's no checked item (e.g. Combobox::STYLE_ACTION), NSMenu will | 48 // If there's no checked item (e.g. Combobox::STYLE_ACTION), NSMenu will |
| 48 // anchor at the top left of the frame. Action buttons should anchor below. | 49 // anchor at the top left of the frame. Action buttons should anchor below. |
| 49 if (!checked_item) { | 50 if (!checked_item) { |
| 50 rect.size.height = 0; | 51 rect.size.height = 0; |
| 51 if (base::i18n::IsRTL()) | 52 if (base::i18n::IsRTL()) |
| 52 rect.origin.x += rect.size.width; | 53 rect.origin.x += rect.size.width; |
| 53 } else { | 54 } else { |
| 54 // To ensure a consistent anchoring that's vertically centered in the | 55 // To ensure a consistent anchoring that's vertically centered in the |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 | 158 |
| 158 base::TimeDelta MenuRunnerImplCocoa::GetClosingEventTime() const { | 159 base::TimeDelta MenuRunnerImplCocoa::GetClosingEventTime() const { |
| 159 return closing_event_time_; | 160 return closing_event_time_; |
| 160 } | 161 } |
| 161 | 162 |
| 162 MenuRunnerImplCocoa::~MenuRunnerImplCocoa() { | 163 MenuRunnerImplCocoa::~MenuRunnerImplCocoa() { |
| 163 } | 164 } |
| 164 | 165 |
| 165 } // namespace internal | 166 } // namespace internal |
| 166 } // namespace views | 167 } // namespace views |
| OLD | NEW |