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