OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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 #include "chrome/browser/ui/cocoa/tab_dialogs_views_mac.h" | 5 #include "chrome/browser/ui/cocoa/tab_dialogs_views_mac.h" |
6 | 6 |
| 7 #include "chrome/browser/platform_util.h" |
| 8 #include "chrome/browser/ui/browser.h" |
| 9 #include "chrome/browser/ui/browser_finder.h" |
| 10 #include "chrome/browser/ui/browser_window.h" |
| 11 #include "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 12 #import "chrome/browser/ui/cocoa/bubble_anchor_helper_views.h" |
| 13 #import "chrome/browser/ui/cocoa/passwords/passwords_bubble_controller.h" |
7 #include "chrome/browser/ui/views/collected_cookies_views.h" | 14 #include "chrome/browser/ui/views/collected_cookies_views.h" |
| 15 #include "chrome/browser/ui/views/passwords/manage_passwords_bubble_view.h" |
8 #include "chrome/browser/ui/views/sync/profile_signin_confirmation_dialog_views.
h" | 16 #include "chrome/browser/ui/views/sync/profile_signin_confirmation_dialog_views.
h" |
| 17 #include "content/public/browser/web_contents.h" |
| 18 #import "ui/base/cocoa/cocoa_base_utils.h" |
| 19 #include "ui/base/material_design/material_design_controller.h" |
| 20 #import "ui/gfx/mac/coordinate_conversion.h" |
9 | 21 |
10 TabDialogsViewsMac::TabDialogsViewsMac(content::WebContents* contents) | 22 TabDialogsViewsMac::TabDialogsViewsMac(content::WebContents* contents) |
11 : TabDialogsCocoa(contents) {} | 23 : TabDialogsCocoa(contents) {} |
12 | 24 |
13 TabDialogsViewsMac::~TabDialogsViewsMac() {} | 25 TabDialogsViewsMac::~TabDialogsViewsMac() {} |
14 | 26 |
15 void TabDialogsViewsMac::ShowCollectedCookies() { | 27 void TabDialogsViewsMac::ShowCollectedCookies() { |
16 // Deletes itself on close. | 28 // Deletes itself on close. |
17 new CollectedCookiesViews(web_contents()); | 29 new CollectedCookiesViews(web_contents()); |
18 } | 30 } |
19 | 31 |
20 void TabDialogsViewsMac::ShowProfileSigninConfirmation( | 32 void TabDialogsViewsMac::ShowProfileSigninConfirmation( |
21 Browser* browser, | 33 Browser* browser, |
22 Profile* profile, | 34 Profile* profile, |
23 const std::string& username, | 35 const std::string& username, |
24 std::unique_ptr<ui::ProfileSigninConfirmationDelegate> delegate) { | 36 std::unique_ptr<ui::ProfileSigninConfirmationDelegate> delegate) { |
25 ProfileSigninConfirmationDialogViews::ShowDialog(browser, profile, username, | 37 ProfileSigninConfirmationDialogViews::ShowDialog(browser, profile, username, |
26 std::move(delegate)); | 38 std::move(delegate)); |
27 } | 39 } |
| 40 |
| 41 void TabDialogsViewsMac::ShowManagePasswordsBubble(bool user_action) { |
| 42 if (!ui::MaterialDesignController::IsSecondaryUiMaterial()) { |
| 43 TabDialogsCocoa::ShowManagePasswordsBubble(user_action); |
| 44 return; |
| 45 } |
| 46 NSWindow* window = [web_contents()->GetNativeView() window]; |
| 47 if (!window) { |
| 48 // The tab isn't active right now. |
| 49 return; |
| 50 } |
| 51 |
| 52 // Don't show the bubble again if it's already showing. A second click on the |
| 53 // location icon in the omnibox will dismiss an open bubble. This behaviour is |
| 54 // consistent with the non-Mac views implementation. |
| 55 // Note that when the browser is toolkit-views, IsBubbleShown() is checked |
| 56 // earlier because the bubble is shown on mouse release (but dismissed on |
| 57 // mouse pressed). A Cocoa browser does both on mouse pressed, so a check |
| 58 // when showing is sufficient. |
| 59 if (ManagePasswordsBubbleView::manage_password_bubble()) |
| 60 return; |
| 61 |
| 62 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); |
| 63 BrowserWindowController* bwc = |
| 64 [BrowserWindowController browserWindowControllerForWindow:window]; |
| 65 gfx::Point anchor_point = |
| 66 gfx::ScreenPointFromNSPoint(ui::ConvertPointFromWindowToScreen( |
| 67 browser->window()->GetNativeWindow(), [bwc bookmarkBubblePoint])); |
| 68 gfx::NativeView parent = |
| 69 platform_util::GetViewForWindow(browser->window()->GetNativeWindow()); |
| 70 DCHECK(parent); |
| 71 |
| 72 LocationBarBubbleDelegateView::DisplayReason reason = |
| 73 user_action ? LocationBarBubbleDelegateView::USER_GESTURE |
| 74 : LocationBarBubbleDelegateView::AUTOMATIC; |
| 75 ManagePasswordsBubbleView* bubble_view = new ManagePasswordsBubbleView( |
| 76 web_contents(), nullptr, anchor_point, reason); |
| 77 bubble_view->set_arrow(views::BubbleBorder::TOP_RIGHT); |
| 78 bubble_view->set_parent_window(parent); |
| 79 views::BubbleDialogDelegateView::CreateBubble(bubble_view); |
| 80 bubble_view->ShowForReason(reason); |
| 81 KeepBubbleAnchored(bubble_view); |
| 82 } |
| 83 |
| 84 void TabDialogsViewsMac::HideManagePasswordsBubble() { |
| 85 // Close toolkit-views bubble. |
| 86 if (!ui::MaterialDesignController::IsSecondaryUiMaterial()) { |
| 87 TabDialogsCocoa::HideManagePasswordsBubble(); |
| 88 return; |
| 89 } |
| 90 ManagePasswordsBubbleView::CloseCurrentBubble(); |
| 91 } |
OLD | NEW |