Chromium Code Reviews| 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 if (active_bubble_) | |
|
Devlin
2017/03/09 02:49:48
When can this happen?
tapted
2017/03/09 10:24:16
Hm. good question. I don't think it can. Made a dc
| |
| 23 active_bubble_->GetWidget()->RemoveObserver(this); | |
| 24 } | |
| 25 | |
| 26 void ToolbarActionsBarBubbleViewsPresenter::PresentAt( | |
| 27 std::unique_ptr<ToolbarActionsBarBubbleDelegate> delegate, | |
| 28 NSWindow* parent_window, | |
| 29 NSPoint point_in_screen, | |
| 30 bool anchored_to_action_view) { | |
| 31 gfx::Point views_point = gfx::ScreenPointFromNSPoint(point_in_screen); | |
| 32 ToolbarActionsBarBubbleViews* bubble = new ToolbarActionsBarBubbleViews( | |
| 33 nullptr, views_point, anchored_to_action_view, std::move(delegate)); | |
| 34 bubble->set_parent_window([parent_window contentView]); | |
| 35 active_bubble_ = bubble; | |
| 36 views::BubbleDialogDelegateView::CreateBubble(bubble); | |
| 37 bubble->GetWidget()->AddObserver(this); | |
| 38 bubble->Show(); | |
| 39 KeepBubbleAnchored(bubble); | |
| 40 } | |
| 41 | |
| 42 void ToolbarActionsBarBubbleViewsPresenter::OnWidgetClosing( | |
| 43 views::Widget* widget) { | |
| 44 // OnWidgetClosing() gives an earlier signal than OnWidgetDestroying() but is | |
| 45 // not called when the bubble is closed synchronously. Note the observer is | |
| 46 // removed so it's impossible for both methods to be triggered. | |
| 47 OnWidgetDestroying(widget); | |
| 48 } | |
| 49 | |
| 50 void ToolbarActionsBarBubbleViewsPresenter::OnWidgetDestroying( | |
| 51 views::Widget* widget) { | |
| 52 active_bubble_ = nullptr; | |
| 53 [owner_ bubbleWindowClosing:nil]; | |
| 54 widget->RemoveObserver(this); | |
| 55 } | |
| OLD | NEW |