Chromium Code Reviews| Index: chrome/browser/ui/cocoa/permission_bubble/chooser_bubble_ui_views_mac.mm |
| diff --git a/chrome/browser/ui/cocoa/permission_bubble/chooser_bubble_ui_views_mac.mm b/chrome/browser/ui/cocoa/permission_bubble/chooser_bubble_ui_views_mac.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b7a521701ac14978652a6df0b63ea945f95433fa |
| --- /dev/null |
| +++ b/chrome/browser/ui/cocoa/permission_bubble/chooser_bubble_ui_views_mac.mm |
| @@ -0,0 +1,50 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/memory/ptr_util.h" |
| +#include "chrome/browser/chooser_controller/chooser_controller.h" |
| +#include "chrome/browser/ui/browser_window.h" |
| +#include "chrome/browser/ui/cocoa/browser_window_controller.h" |
| +#import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
| +#import "chrome/browser/ui/cocoa/permission_bubble/chooser_bubble_ui_cocoa.h" |
| +#include "chrome/browser/ui/permission_bubble/chooser_bubble_delegate.h" |
| +#include "chrome/browser/ui/views/permission_bubble/chooser_bubble_ui_view.h" |
| +#import "ui/base/cocoa/cocoa_base_utils.h" |
| +#include "ui/base/material_design/material_design_controller.h" |
| +#include "ui/base/ui_features.h" |
| +#import "ui/gfx/mac/coordinate_conversion.h" |
| + |
| +namespace { |
| + |
| +// Takes in the parent window, which should be a BrowserWindow, and gets the |
| +// proper anchor point for the bubble. The returned point is in screen |
| +// coordinates. |
| +NSPoint AnchorPointForWindow(NSWindow* parent) { |
|
varkha
2017/05/02 12:25:48
Self review: simplify with inlines.
varkha
2017/05/03 05:01:20
Acknowledged.
|
| + BrowserWindowController* controller = [parent windowController]; |
| + NSPoint origin = NSZeroPoint; |
| + if ([controller isKindOfClass:[BrowserWindowController class]]) { |
| + LocationBarViewMac* location_bar = [controller locationBarBridge]; |
| + if (location_bar) { |
| + NSPoint bubble_point = location_bar->GetPageInfoBubblePoint(); |
| + origin = ui::ConvertPointFromWindowToScreen(parent, bubble_point); |
| + } |
|
tapted
2017/05/03 01:10:53
Do we need an else?
Maybe we can move this method
varkha
2017/05/03 05:01:20
Acknowledged. I'll look into this.
|
| + } |
| + return origin; |
| +} |
| + |
| +} // namespace |
| + |
| +#if !BUILDFLAG(MAC_VIEWS_BROWSER) |
|
tapted
2017/05/03 01:10:53
Can we exclude the entire file under the mac_views
varkha
2017/05/03 05:01:20
Please see if the refactoring I've done makes sens
|
| +std::unique_ptr<BubbleUi> ChooserBubbleDelegate::BuildBubbleUi() { |
| + if (ui::MaterialDesignController::IsSecondaryUiMaterial()) { |
|
varkha
2017/05/02 12:25:48
Self review: simplify by reversing the condition a
varkha
2017/05/03 05:01:20
Done.
|
| + NSWindow* parent = browser_->window()->GetNativeWindow(); |
| + gfx::Point anchor_point = |
| + gfx::ScreenPointFromNSPoint(AnchorPointForWindow(parent)); |
| + return base::MakeUnique<ChooserBubbleUiView>( |
| + browser_, std::move(chooser_controller_), anchor_point); |
| + } |
| + return base::MakeUnique<ChooserBubbleUiCocoa>(browser_, |
| + std::move(chooser_controller_)); |
| +} |
| +#endif |