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 #import "chrome/browser/ui/cocoa/extensions/toolbar_actions_bar_bubble_views_pre
senter.h" |
| 6 |
| 7 #import <Cocoa/Cocoa.h> |
| 8 |
| 9 #include "chrome/browser/ui/cocoa/bubble_anchor_helper_views.h" |
| 10 #import "chrome/browser/ui/cocoa/extensions/browser_actions_controller.h" |
| 11 #include "chrome/browser/ui/toolbar/toolbar_actions_bar_bubble_delegate.h" |
| 12 #include "chrome/browser/ui/views/toolbar/toolbar_actions_bar_bubble_views.h" |
| 13 #import "ui/gfx/mac/coordinate_conversion.h" |
| 14 #include "ui/views/widget/widget.h" |
| 15 |
| 16 ToolbarActionsBarBubbleViewsPresenter::ToolbarActionsBarBubbleViewsPresenter( |
| 17 BrowserActionsController* owner) |
| 18 : owner_(owner), active_bubble_(nullptr) {} |
| 19 |
| 20 ToolbarActionsBarBubbleViewsPresenter:: |
| 21 ~ToolbarActionsBarBubbleViewsPresenter() { |
| 22 // Child windows should never outlive the controller that owns |this|. |
| 23 DCHECK(!active_bubble_) |
| 24 << "|active_bubble_| should be cleared by OnWidgetDestroying()."; |
| 25 } |
| 26 |
| 27 void ToolbarActionsBarBubbleViewsPresenter::PresentAt( |
| 28 std::unique_ptr<ToolbarActionsBarBubbleDelegate> delegate, |
| 29 NSWindow* parent_window, |
| 30 NSPoint point_in_screen, |
| 31 bool anchored_to_action_view) { |
| 32 gfx::Point views_point = gfx::ScreenPointFromNSPoint(point_in_screen); |
| 33 // For a Cocoa browser, the presenter must pass nullptr for |anchor_view|. |
| 34 ToolbarActionsBarBubbleViews* bubble = new ToolbarActionsBarBubbleViews( |
| 35 nullptr, views_point, anchored_to_action_view, std::move(delegate)); |
| 36 bubble->set_parent_window([parent_window contentView]); |
| 37 active_bubble_ = bubble; |
| 38 views::BubbleDialogDelegateView::CreateBubble(bubble); |
| 39 bubble->GetWidget()->AddObserver(this); |
| 40 bubble->Show(); |
| 41 KeepBubbleAnchored(bubble); |
| 42 } |
| 43 |
| 44 void ToolbarActionsBarBubbleViewsPresenter::OnWidgetClosing( |
| 45 views::Widget* widget) { |
| 46 // OnWidgetClosing() gives an earlier signal than OnWidgetDestroying() but is |
| 47 // not called when the bubble is closed synchronously. Note the observer is |
| 48 // removed so it's impossible for both methods to be triggered. |
| 49 OnWidgetDestroying(widget); |
| 50 } |
| 51 |
| 52 void ToolbarActionsBarBubbleViewsPresenter::OnWidgetDestroying( |
| 53 views::Widget* widget) { |
| 54 active_bubble_ = nullptr; |
| 55 [owner_ bubbleWindowClosing:nil]; |
| 56 widget->RemoveObserver(this); |
| 57 } |
OLD | NEW |