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

Side by Side Diff: chrome/browser/ui/cocoa/website_settings/permission_bubble_cocoa.mm

Issue 1292353006: Mac Changes for BubbleManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mcdb-mac-3.gitbr
Patch Set: 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/cocoa/website_settings/permission_bubble_cocoa.h" 5 #include "chrome/browser/ui/cocoa/website_settings/permission_bubble_cocoa.h"
6 6
7 #include "chrome/browser/ui/browser_window.h" 7 #include "chrome/browser/ui/browser_finder.h"
8 #import "chrome/browser/ui/cocoa/base_bubble_controller.h" 8 #import "chrome/browser/ui/cocoa/base_bubble_controller.h"
9 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
10 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
11 #import "chrome/browser/ui/cocoa/website_settings/permission_bubble_controller.h " 9 #import "chrome/browser/ui/cocoa/website_settings/permission_bubble_controller.h "
12 #import "chrome/browser/ui/website_settings/permission_bubble_view.h" 10 #import "chrome/browser/ui/website_settings/permission_bubble_delegate.h"
11 #import "chrome/browser/ui/website_settings/permission_bubble_manager.h"
13 #include "content/public/browser/web_contents.h" 12 #include "content/public/browser/web_contents.h"
14 #import "ui/base/cocoa/nsview_additions.h" 13 #import "ui/base/cocoa/nsview_additions.h"
15 14
16 PermissionBubbleCocoa::PermissionBubbleCocoa(Browser* browser) 15 PermissionBubbleCocoa::PermissionBubbleCocoa(PermissionBubbleManager* manager)
17 : browser_(browser), delegate_(nullptr), bubbleController_(nil) { 16 : manager_(manager), bubbleController_(nil) {
18 DCHECK(browser); 17 DCHECK(manager_);
19 } 18 }
20 19
21 PermissionBubbleCocoa::~PermissionBubbleCocoa() { 20 PermissionBubbleCocoa::~PermissionBubbleCocoa() {
22 } 21 }
23 22
24 // static 23 // static
25 scoped_ptr<PermissionBubbleView> PermissionBubbleView::Create( 24 scoped_ptr<BubbleUI> PermissionBubbleDelegate::CreateBubble(
26 Browser* browser) { 25 PermissionBubbleManager* manager) {
27 return make_scoped_ptr(new PermissionBubbleCocoa(browser)); 26 return make_scoped_ptr(new PermissionBubbleCocoa(manager));
28 } 27 }
29 28
30 void PermissionBubbleCocoa::Show( 29 void PermissionBubbleCocoa::Show() {
31 const std::vector<PermissionBubbleRequest*>& requests,
32 const std::vector<bool>& accept_state) {
33 if (!bubbleController_) { 30 if (!bubbleController_) {
groby-ooo-7-16 2015/08/14 18:26:04 Can we migrate this out so it's shared across bubb
34 bubbleController_ = [[PermissionBubbleController alloc] 31 bubbleController_ = [[PermissionBubbleController alloc]
35 initWithParentWindow:GetParentWindow() 32 initWithBrowser:chrome::FindBrowserWithWebContents(
36 bridge:this]; 33 manager_->web_contents())
34 bridge:this];
37 } 35 }
38 36
39 [bubbleController_ showAtAnchor:GetAnchorPoint() 37 [bubbleController_ showWithManager:manager_
40 withDelegate:delegate_ 38 forRequests:manager_->requests()
41 forRequests:requests 39 acceptStates:manager_->accept_states()];
42 acceptStates:accept_state];
43 } 40 }
44 41
45 void PermissionBubbleCocoa::Hide() { 42 void PermissionBubbleCocoa::Hide() {
46 [bubbleController_ close]; 43 [bubbleController_ close];
47 } 44 }
48 45
49 bool PermissionBubbleCocoa::IsVisible() { 46 void PermissionBubbleCocoa::UpdateAnchorPosition() {
50 return bubbleController_ != nil; 47 [bubbleController_ updateAnchorPosition];
51 } 48 }
52 49
53 void PermissionBubbleCocoa::SetDelegate(Delegate* delegate) { 50 bool PermissionBubbleCocoa::CanAcceptUpdate() const {
54 if (delegate_ == delegate)
55 return;
56 delegate_ = delegate;
57 }
58
59 bool PermissionBubbleCocoa::CanAcceptRequestUpdate() {
60 return ![[[bubbleController_ window] contentView] cr_isMouseInView]; 51 return ![[[bubbleController_ window] contentView] cr_isMouseInView];
61 } 52 }
62 53
63 void PermissionBubbleCocoa::UpdateAnchorPosition() {
64 [bubbleController_ setParentWindow:GetParentWindow()];
65 [bubbleController_ setAnchorPoint:GetAnchorPoint()];
66 }
67
68 gfx::NativeWindow PermissionBubbleCocoa::GetNativeWindow() {
69 return [bubbleController_ window];
70 }
71
72 void PermissionBubbleCocoa::OnBubbleClosing() { 54 void PermissionBubbleCocoa::OnBubbleClosing() {
73 bubbleController_ = nil; 55 bubbleController_ = nil;
74 } 56 }
75
76 NSPoint PermissionBubbleCocoa::GetAnchorPoint() {
77 NSPoint anchor;
78 if (HasLocationBar()) {
79 LocationBarViewMac* location_bar =
80 [[GetParentWindow() windowController] locationBarBridge];
81 anchor = location_bar->GetPageInfoBubblePoint();
82 } else {
83 // Center the bubble if there's no location bar.
84 NSView* content_view = [GetParentWindow() contentView];
85 anchor.y = NSMaxY(content_view.frame);
86 anchor.x = NSMidX(content_view.frame);
87 }
88
89 return [GetParentWindow() convertBaseToScreen:anchor];
90 }
91
92 bool PermissionBubbleCocoa::HasLocationBar() {
93 return browser_->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR);
94 }
95
96 info_bubble::BubbleArrowLocation PermissionBubbleCocoa::GetArrowLocation() {
97 return HasLocationBar() ? info_bubble::kTopLeft : info_bubble::kNoArrow;
98 }
99
100 NSWindow* PermissionBubbleCocoa::GetParentWindow() {
101 return browser_->window()->GetNativeWindow();
102 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698