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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 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 #include "chrome/browser/ui/browser_dialogs.h"
6
7 #include "chrome/browser/ui/views/website_settings/website_settings_popup_view.h "
8 #include "content/public/browser/web_contents_observer.h"
9 #include "ui/views/widget/widget_observer.h"
10
11 // This file provides definitions of desktop browser dialog-creation methods for
12 // Mac where a Cocoa browser is using Views dialogs.
13
14 namespace {
15
16 // Takes an anchor view for a bubble and deletes it when the bubble is closed.
17 // It also closes the bubble when the parent WebContents is destroyed since the
18 // 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.
19 // watch.
tapted 2015/08/11 01:23:19 watch -> observe?
jackhou1 2015/08/11 03:09:24 Done.
20 class BubbleAnchorViewDeleter : public views::WidgetObserver,
21 public content::WebContentsObserver {
22 public:
23 BubbleAnchorViewDeleter(views::View* anchor_view,
24 views::Widget* widget,
25 content::WebContents* web_contents)
26 : content::WebContentsObserver(web_contents),
27 anchor_view_(anchor_view),
28 widget_(widget) {
29 widget_->AddObserver(this);
30 }
31
32 ~BubbleAnchorViewDeleter() override {}
33
34 // WidgetObserver:
35 void OnWidgetDestroyed(views::Widget* widget) override {
36 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()
37 delete anchor_view_;
38 }
39
40 // content::WebContentsObserver:
41 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
42 if (widget_)
43 widget_->Close();
44 }
45
46 private:
47 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.
48 views::Widget* widget_;
49
50 DISALLOW_COPY_AND_ASSIGN(BubbleAnchorViewDeleter);
51 };
52
53 } // namespace
54
55 namespace chrome {
56
57 void ShowWebsiteSettingsBubbleViewsAtPoint(const gfx::Point& anchor_point,
58 Profile* profile,
59 content::WebContents* web_contents,
60 const GURL& url,
61 const content::SSLStatus& ssl) {
62 // The views bubble requires an anchor views::View. Create one using the
63 // anchor point. Since the view doesn't have a container Widget,
64 // 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.
65 // where the midpoint of the bottom edge is at the anchor point.
66 gfx::Rect anchor_view_rect(0, 0, anchor_point.x() * 2, anchor_point.y());
67 // WebsiteSettingsPopupView assumes a margin of
68 // 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
69 anchor_view_rect.Inset(0, 0, 0, -5);
70
71 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.
72 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.
73 views::BubbleDelegateView* bubble_view = WebsiteSettingsPopupView::ShowPopup(
74 anchor_view, profile, web_contents, url, ssl);
75 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.
76 web_contents);
77 }
78
79 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698