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

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 // Creates 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 its own Widget for the BubbleDelegateView to
19 // observe. Owns itself.
20 class BubbleAnchorViewAdapter : public views::WidgetObserver,
msw 2015/08/11 22:09:11 Yeah, this seems far from optimal... (1) Using a p
jackhou1 2015/08/12 06:02:11 SetAnchorRect would be good. Do you think it's oka
msw 2015/08/12 16:52:43 Make a public helper on WebsiteSettingsPopupView i
jackhou1 2015/08/17 04:54:19 Done. Added a static helper WebsiteSettingsPopupV
21 public content::WebContentsObserver {
22 public:
23 BubbleAnchorViewAdapter(const gfx::Point& anchor_point,
24 Profile* profile,
25 content::WebContents* web_contents,
26 const GURL& url,
27 const content::SSLStatus& ssl)
28 : anchor_view_(new views::View) {
29 // Since the view doesn't have a container Widget,
30 // View::ConvertPointToScreen will assume its origin is 0,0. Create a rect
31 // where the midpoint of the bottom edge is at the anchor point.
32 // Note that this will not work for windows to the left of the screen
33 // origin, e.g. in multi-monitor setups.
34 // TODO(jackhou): Make this adapter manage a Widget that is a child of
35 // BrowserWindowCocoa. This fixes the multi-monitor problem and is needed
36 // for bubbles that can stay open, e.g. extensions.
37 anchor_view_->SetBounds(
38 0, 0, anchor_point.x() * 2,
39 anchor_point.y() +
40 WebsiteSettingsPopupView::kLocationIconVerticalMargin);
41 views::BubbleDelegateView* bubble_view =
42 WebsiteSettingsPopupView::ShowPopup(anchor_view_.get(), profile,
43 web_contents, url, ssl);
44
45 widget_ = bubble_view->GetWidget();
46 widget_->AddObserver(this);
47 Observe(web_contents);
48 }
49
50 ~BubbleAnchorViewAdapter() override {}
51
52 // WidgetObserver:
53 void OnWidgetDestroyed(views::Widget* widget) override { delete this; }
54
55 // content::WebContentsObserver:
56 void WebContentsDestroyed() override { widget_->Close(); }
57
58 private:
59 // This view should never be (or have been) inserted into a view heirarchy.
60 scoped_ptr<views::View> anchor_view_;
61 views::Widget* widget_;
62
63 DISALLOW_COPY_AND_ASSIGN(BubbleAnchorViewAdapter);
64 };
65
66 } // namespace
67
68 namespace chrome {
69
70 void ShowWebsiteSettingsBubbleViewsAtPoint(const gfx::Point& anchor_point,
71 Profile* profile,
72 content::WebContents* web_contents,
73 const GURL& url,
74 const content::SSLStatus& ssl) {
75 new BubbleAnchorViewAdapter(anchor_point, profile, web_contents, url, ssl);
76 }
77
78 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698