OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/platform_util.h" |
| 6 #include "chrome/browser/ui/browser.h" |
| 7 #include "chrome/browser/ui/browser_finder.h" |
| 8 #include "chrome/browser/ui/browser_window.h" |
| 9 #import "chrome/browser/ui/cocoa/bubble_anchor_helper_views.h" |
| 10 #import "chrome/browser/ui/cocoa/passwords/passwords_bubble_controller.h" |
| 11 #include "chrome/browser/ui/views/passwords/manage_passwords_bubble_view.h" |
| 12 #import "ui/base/cocoa/cocoa_base_utils.h" |
| 13 #import "ui/gfx/mac/coordinate_conversion.h" |
| 14 |
| 15 void CloseViewsManagePasswordsBubbleOnCocoaBrowser() { |
| 16 ManagePasswordsBubbleView::CloseCurrentBubble(); |
| 17 } |
| 18 |
| 19 void ShowViewsManagePasswordsBubbleOnCocoaBrowser( |
| 20 NSPoint anchor, |
| 21 content::WebContents* web_contents, |
| 22 bool user_action) { |
| 23 // Don't show the bubble again if it's already showing. A second click on the |
| 24 // location icon in the omnibox will dismiss an open bubble. This behaviour is |
| 25 // consistent with the non-Mac views implementation. |
| 26 // Note that when the browser is toolkit-views, IsBubbleShown() is checked |
| 27 // earlier because the bubble is shown on mouse release (but dismissed on |
| 28 // mouse pressed). A Cocoa browser does both on mouse pressed, so a check |
| 29 // when showing is sufficient. |
| 30 if (ManagePasswordsBubbleView::manage_password_bubble()) |
| 31 return; |
| 32 |
| 33 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); |
| 34 gfx::Point anchor_point = |
| 35 gfx::ScreenPointFromNSPoint(ui::ConvertPointFromWindowToScreen( |
| 36 browser->window()->GetNativeWindow(), anchor)); |
| 37 gfx::NativeView parent = |
| 38 platform_util::GetViewForWindow(browser->window()->GetNativeWindow()); |
| 39 DCHECK(parent); |
| 40 |
| 41 LocationBarBubbleDelegateView::DisplayReason reason = |
| 42 user_action ? LocationBarBubbleDelegateView::USER_GESTURE |
| 43 : LocationBarBubbleDelegateView::AUTOMATIC; |
| 44 ManagePasswordsBubbleView* bubble_view = new ManagePasswordsBubbleView( |
| 45 web_contents, nullptr, anchor_point, reason); |
| 46 bubble_view->set_arrow(views::BubbleBorder::TOP_RIGHT); |
| 47 bubble_view->set_parent_window(parent); |
| 48 views::BubbleDialogDelegateView::CreateBubble(bubble_view); |
| 49 bubble_view->ShowForReason(reason); |
| 50 KeepBubbleAnchored(bubble_view); |
| 51 } |
OLD | NEW |