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

Unified Diff: chrome/browser/ui/views/browser_dialogs_views_mac.cc

Issue 1280673003: [Mac] Enable MacViews site settings bubble behind --enable-mac-views-dialogs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@enabledialogs
Patch Set: Sync Created 5 years, 4 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/views/browser_dialogs_views_mac.cc
diff --git a/chrome/browser/ui/views/browser_dialogs_views_mac.cc b/chrome/browser/ui/views/browser_dialogs_views_mac.cc
new file mode 100644
index 0000000000000000000000000000000000000000..19c920c48a77e145a86c256bd082af9a85c241f8
--- /dev/null
+++ b/chrome/browser/ui/views/browser_dialogs_views_mac.cc
@@ -0,0 +1,79 @@
+// Copyright 2015 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.
+
+#include "chrome/browser/ui/browser_dialogs.h"
+
+#include "chrome/browser/ui/views/website_settings/website_settings_popup_view.h"
+#include "content/public/browser/web_contents_observer.h"
+#include "ui/views/widget/widget_observer.h"
+
+// This file provides definitions of desktop browser dialog-creation methods for
+// Mac where a Cocoa browser is using Views dialogs.
+
+namespace {
+
+// Takes an anchor view for a bubble and deletes it when the bubble is closed.
+// It also closes the bubble when the parent WebContents is destroyed since the
+// anchor view does not have it's own Widget for the BubbleDelegateView to
tapted 2015/08/11 01:23:19 nit: it's -> its
jackhou1 2015/08/11 03:09:23 Done.
+// watch.
tapted 2015/08/11 01:23:19 watch -> observe?
jackhou1 2015/08/11 03:09:24 Done.
+class BubbleAnchorViewDeleter : public views::WidgetObserver,
+ public content::WebContentsObserver {
+ public:
+ BubbleAnchorViewDeleter(views::View* anchor_view,
+ views::Widget* widget,
+ content::WebContents* web_contents)
+ : content::WebContentsObserver(web_contents),
+ anchor_view_(anchor_view),
+ widget_(widget) {
+ widget_->AddObserver(this);
+ }
+
+ ~BubbleAnchorViewDeleter() override {}
+
+ // WidgetObserver:
+ void OnWidgetDestroyed(views::Widget* widget) override {
+ widget_ = nullptr;
tapted 2015/08/11 01:23:19 I think this needs to call `delete this`, and the
jackhou1 2015/08/11 03:09:24 Done. Still need |widget_| to call Widget::Close()
+ delete anchor_view_;
+ }
+
+ // content::WebContentsObserver:
+ void WebContentsDestroyed() override {
tapted 2015/08/11 01:23:19 Should any navigation do this too? Maybe that's no
jackhou1 2015/08/11 03:09:23 I think that would take focus away, which closes t
+ if (widget_)
+ widget_->Close();
+ }
+
+ private:
+ views::View* anchor_view_;
tapted 2015/08/11 01:23:19 when this becomes scoped_ptr, needs a note to say
jackhou1 2015/08/11 03:09:24 Done.
+ views::Widget* widget_;
+
+ DISALLOW_COPY_AND_ASSIGN(BubbleAnchorViewDeleter);
+};
+
+} // namespace
+
+namespace chrome {
+
+void ShowWebsiteSettingsBubbleViewsAtPoint(const gfx::Point& anchor_point,
+ Profile* profile,
+ content::WebContents* web_contents,
+ const GURL& url,
+ const content::SSLStatus& ssl) {
+ // The views bubble requires an anchor views::View. Create one using the
+ // anchor point. Since the view doesn't have a container Widget,
+ // View::ConvertPointToScreen will assume it's origin is 0,0. Create a rect
tapted 2015/08/11 01:23:19 it's -> its
jackhou1 2015/08/11 03:09:23 Done.
+ // where the midpoint of the bottom edge is at the anchor point.
+ gfx::Rect anchor_view_rect(0, 0, anchor_point.x() * 2, anchor_point.y());
+ // WebsiteSettingsPopupView assumes a margin of
+ // WebsiteSettingsPopupView::kLocationIconVerticalMargin.
tapted 2015/08/11 01:23:19 This needs to be pulled out into a header file som
jackhou1 2015/08/11 03:09:24 The margin is built into the assets. kLocationIcon
+ anchor_view_rect.Inset(0, 0, 0, -5);
+
+ views::View* anchor_view = new views::View();
tapted 2015/08/11 01:23:19 I think it would be nicer to do this directly into
jackhou1 2015/08/11 03:09:24 Done.
+ anchor_view->SetBoundsRect(anchor_view_rect);
tapted 2015/08/11 01:23:19 Maybe just SetBounds(0, 0, anchor_point.x() * 2,
jackhou1 2015/08/11 03:09:24 Done.
+ views::BubbleDelegateView* bubble_view = WebsiteSettingsPopupView::ShowPopup(
+ anchor_view, profile, web_contents, url, ssl);
+ new BubbleAnchorViewDeleter(anchor_view, bubble_view->GetWidget(),
tapted 2015/08/11 01:23:19 (I think this is leaked now, but `delete this` sho
jackhou1 2015/08/11 03:09:23 Done.
+ web_contents);
+}
+
+} // namespace chrome

Powered by Google App Engine
This is Rietveld 408576698