Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1051)

Unified Diff: chrome/browser/ui/cocoa/extensions/toolbar_actions_bar_bubble_views_presenter.mm

Issue 2630473003: MacViews: Harmony for toolbar actions bubbles. (Closed)
Patch Set: respond to comments Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/extensions/toolbar_actions_bar_bubble_views_presenter.mm
diff --git a/chrome/browser/ui/cocoa/extensions/toolbar_actions_bar_bubble_views_presenter.mm b/chrome/browser/ui/cocoa/extensions/toolbar_actions_bar_bubble_views_presenter.mm
new file mode 100644
index 0000000000000000000000000000000000000000..15422c36c8601d7ad3a9cb1c211b1c89672628b2
--- /dev/null
+++ b/chrome/browser/ui/cocoa/extensions/toolbar_actions_bar_bubble_views_presenter.mm
@@ -0,0 +1,57 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "chrome/browser/ui/cocoa/extensions/toolbar_actions_bar_bubble_views_presenter.h"
+
+#import <Cocoa/Cocoa.h>
+
+#include "chrome/browser/ui/cocoa/bubble_anchor_helper_views.h"
+#import "chrome/browser/ui/cocoa/extensions/browser_actions_controller.h"
+#include "chrome/browser/ui/toolbar/toolbar_actions_bar_bubble_delegate.h"
+#include "chrome/browser/ui/views/toolbar/toolbar_actions_bar_bubble_views.h"
+#import "ui/gfx/mac/coordinate_conversion.h"
+#include "ui/views/widget/widget.h"
+
+ToolbarActionsBarBubbleViewsPresenter::ToolbarActionsBarBubbleViewsPresenter(
+ BrowserActionsController* owner)
+ : owner_(owner), active_bubble_(nullptr) {}
+
+ToolbarActionsBarBubbleViewsPresenter::
+ ~ToolbarActionsBarBubbleViewsPresenter() {
+ // Child windows should never outlive the controller that owns |this|.
+ DCHECK(!active_bubble_)
+ << "|active_bubble_| should be cleared by OnWidgetDestroying().";
+}
+
+void ToolbarActionsBarBubbleViewsPresenter::PresentAt(
+ std::unique_ptr<ToolbarActionsBarBubbleDelegate> delegate,
+ NSWindow* parent_window,
+ NSPoint point_in_screen,
+ bool anchored_to_action_view) {
+ gfx::Point views_point = gfx::ScreenPointFromNSPoint(point_in_screen);
+ // For a Cocoa browser, the presenter must pass nullptr for |anchor_view|.
+ ToolbarActionsBarBubbleViews* bubble = new ToolbarActionsBarBubbleViews(
+ nullptr, views_point, anchored_to_action_view, std::move(delegate));
+ bubble->set_parent_window([parent_window contentView]);
+ active_bubble_ = bubble;
+ views::BubbleDialogDelegateView::CreateBubble(bubble);
+ bubble->GetWidget()->AddObserver(this);
+ bubble->Show();
+ KeepBubbleAnchored(bubble);
+}
+
+void ToolbarActionsBarBubbleViewsPresenter::OnWidgetClosing(
+ views::Widget* widget) {
+ // OnWidgetClosing() gives an earlier signal than OnWidgetDestroying() but is
+ // not called when the bubble is closed synchronously. Note the observer is
+ // removed so it's impossible for both methods to be triggered.
+ OnWidgetDestroying(widget);
+}
+
+void ToolbarActionsBarBubbleViewsPresenter::OnWidgetDestroying(
+ views::Widget* widget) {
+ active_bubble_ = nullptr;
+ [owner_ bubbleWindowClosing:nil];
+ widget->RemoveObserver(this);
+}

Powered by Google App Engine
This is Rietveld 408576698