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

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

Issue 2065803002: Make ChromeExtensionChooserDialog::ShowDialog work for MacViews (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: removed TODO comments Created 4 years, 6 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 2015 The Chromium Authors. All rights reserved. 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 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 #import "chrome/browser/ui/cocoa/website_settings/chooser_bubble_ui_cocoa.h" 5 #import "chrome/browser/ui/cocoa/website_settings/chooser_bubble_ui_cocoa.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <cmath> 10 #include <cmath>
11 11
12 #include "base/mac/scoped_nsobject.h" 12 #include "base/mac/scoped_nsobject.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/strings/sys_string_conversions.h" 14 #include "base/strings/sys_string_conversions.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
17 #include "chrome/browser/ui/browser_window.h" 17 #include "chrome/browser/ui/browser_window.h"
18 #import "chrome/browser/ui/cocoa/base_bubble_controller.h" 18 #import "chrome/browser/ui/cocoa/base_bubble_controller.h"
19 #import "chrome/browser/ui/cocoa/browser_window_controller.h" 19 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
20 #import "chrome/browser/ui/cocoa/browser_window_utils.h" 20 #import "chrome/browser/ui/cocoa/browser_window_utils.h"
21 #import "chrome/browser/ui/cocoa/chooser_content_view.h" 21 #import "chrome/browser/ui/cocoa/chooser_content_view_cocoa.h"
22 #import "chrome/browser/ui/cocoa/info_bubble_view.h" 22 #import "chrome/browser/ui/cocoa/info_bubble_view.h"
23 #import "chrome/browser/ui/cocoa/info_bubble_window.h" 23 #import "chrome/browser/ui/cocoa/info_bubble_window.h"
24 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" 24 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
25 #include "chrome/browser/ui/website_settings/chooser_bubble_delegate.h" 25 #include "chrome/browser/ui/website_settings/chooser_bubble_delegate.h"
26 #include "chrome/grit/generated_resources.h" 26 #include "chrome/grit/generated_resources.h"
27 #include "components/bubble/bubble_controller.h" 27 #include "components/bubble/bubble_controller.h"
28 #include "components/url_formatter/elide_url.h" 28 #include "components/url_formatter/elide_url.h"
29 #include "content/public/browser/native_web_keyboard_event.h" 29 #include "content/public/browser/native_web_keyboard_event.h"
30 #include "ui/base/cocoa/cocoa_base_utils.h" 30 #include "ui/base/cocoa/cocoa_base_utils.h"
31 #include "ui/base/cocoa/window_size_constants.h" 31 #include "ui/base/cocoa/window_size_constants.h"
32 #include "ui/base/l10n/l10n_util.h" 32 #include "ui/base/l10n/l10n_util.h"
33 #include "ui/base/l10n/l10n_util_mac.h" 33 #include "ui/base/l10n/l10n_util_mac.h"
34 #include "url/gurl.h" 34 #include "url/gurl.h"
35 #include "url/origin.h" 35 #include "url/origin.h"
36 36
37 std::unique_ptr<BubbleUi> ChooserBubbleDelegate::BuildBubbleUi() { 37 std::unique_ptr<BubbleUi> ChooserBubbleDelegate::BuildBubbleUi() {
38 return base::WrapUnique( 38 return base::WrapUnique(
39 new ChooserBubbleUiCocoa(browser_, chooser_controller())); 39 new ChooserBubbleUiCocoa(browser_, chooser_controller()));
40 } 40 }
41 41
42 @interface ChooserBubbleUiController 42 @interface ChooserBubbleUiController
43 : BaseBubbleController<NSTableViewDataSource, NSTableViewDelegate> { 43 : BaseBubbleController<NSTableViewDataSource, NSTableViewDelegate> {
44 @private 44 @private
45 // Bridge to the C++ class that created this object. 45 // Bridge to the C++ class that created this object.
46 ChooserBubbleUiCocoa* bridge_; // Weak. 46 ChooserBubbleUiCocoa* bridge_; // Weak.
47 bool buttonPressed_; 47 bool buttonPressed_;
48 48
49 base::scoped_nsobject<ChooserContentView> chooserContentView_; 49 base::scoped_nsobject<ChooserContentViewCocoa> chooserContentViewCocoa_;
50 NSTableView* tableView_; // Weak. 50 NSTableView* tableView_; // Weak.
51 NSButton* connectButton_; // Weak. 51 NSButton* connectButton_; // Weak.
52 NSButton* cancelButton_; // Weak. 52 NSButton* cancelButton_; // Weak.
53 NSButton* helpButton_; // Weak. 53 NSButton* helpButton_; // Weak.
54 54
55 Browser* browser_; // Weak. 55 Browser* browser_; // Weak.
56 ChooserController* chooserController_; // Weak. 56 ChooserController* chooserController_; // Weak.
57 } 57 }
58 58
59 // Designated initializer. |browser| and |bridge| must both be non-nil. 59 // Designated initializer. |browser| and |bridge| must both be non-nil.
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 - (void)parentWindowDidResize:(NSNotification*)notification { 161 - (void)parentWindowDidResize:(NSNotification*)notification {
162 [self setAnchorPoint:[self getExpectedAnchorPoint]]; 162 [self setAnchorPoint:[self getExpectedAnchorPoint]];
163 } 163 }
164 164
165 - (void)parentWindowDidMove:(NSNotification*)notification { 165 - (void)parentWindowDidMove:(NSNotification*)notification {
166 DCHECK(bridge_); 166 DCHECK(bridge_);
167 [self setAnchorPoint:[self getExpectedAnchorPoint]]; 167 [self setAnchorPoint:[self getExpectedAnchorPoint]];
168 } 168 }
169 169
170 - (void)show { 170 - (void)show {
171 chooserContentView_.reset([[ChooserContentView alloc] 171 chooserContentViewCocoa_.reset([[ChooserContentViewCocoa alloc]
172 initWithChooserTitle: 172 initWithChooserTitle:
173 l10n_util::GetNSStringF( 173 l10n_util::GetNSStringF(
174 IDS_CHOOSER_BUBBLE_PROMPT, 174 IDS_CHOOSER_BUBBLE_PROMPT,
175 url_formatter::FormatOriginForSecurityDisplay( 175 url_formatter::FormatOriginForSecurityDisplay(
176 chooserController_->GetOrigin(), 176 chooserController_->GetOrigin(),
177 url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC))]); 177 url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC))]);
178 178
179 tableView_ = [chooserContentView_ tableView]; 179 tableView_ = [chooserContentViewCocoa_ tableView];
180 connectButton_ = [chooserContentView_ connectButton]; 180 connectButton_ = [chooserContentViewCocoa_ connectButton];
181 cancelButton_ = [chooserContentView_ cancelButton]; 181 cancelButton_ = [chooserContentViewCocoa_ cancelButton];
182 helpButton_ = [chooserContentView_ helpButton]; 182 helpButton_ = [chooserContentViewCocoa_ helpButton];
183 183
184 [connectButton_ setTarget:self]; 184 [connectButton_ setTarget:self];
185 [connectButton_ setAction:@selector(onConnect:)]; 185 [connectButton_ setAction:@selector(onConnect:)];
186 [cancelButton_ setTarget:self]; 186 [cancelButton_ setTarget:self];
187 [cancelButton_ setAction:@selector(onCancel:)]; 187 [cancelButton_ setAction:@selector(onCancel:)];
188 [tableView_ setDelegate:self]; 188 [tableView_ setDelegate:self];
189 [tableView_ setDataSource:self]; 189 [tableView_ setDataSource:self];
190 [helpButton_ setTarget:self]; 190 [helpButton_ setTarget:self];
191 [helpButton_ setAction:@selector(onHelpPressed:)]; 191 [helpButton_ setAction:@selector(onHelpPressed:)];
192 192
193 [[[self window] contentView] addSubview:chooserContentView_.get()]; 193 [[[self window] contentView] addSubview:chooserContentViewCocoa_.get()];
194 194
195 NSRect bubbleFrame = 195 NSRect bubbleFrame =
196 [[self window] frameRectForContentRect:[chooserContentView_ frame]]; 196 [[self window] frameRectForContentRect:[chooserContentViewCocoa_ frame]];
197 if ([[self window] isVisible]) { 197 if ([[self window] isVisible]) {
198 // Unfortunately, calling -setFrame followed by -setFrameOrigin (called 198 // Unfortunately, calling -setFrame followed by -setFrameOrigin (called
199 // within -setAnchorPoint) causes flickering. Avoid the flickering by 199 // within -setAnchorPoint) causes flickering. Avoid the flickering by
200 // manually adjusting the new frame's origin so that the top left stays the 200 // manually adjusting the new frame's origin so that the top left stays the
201 // same, and only calling -setFrame. 201 // same, and only calling -setFrame.
202 NSRect currentWindowFrame = [[self window] frame]; 202 NSRect currentWindowFrame = [[self window] frame];
203 bubbleFrame.origin = currentWindowFrame.origin; 203 bubbleFrame.origin = currentWindowFrame.origin;
204 bubbleFrame.origin.y = bubbleFrame.origin.y + 204 bubbleFrame.origin.y = bubbleFrame.origin.y +
205 currentWindowFrame.size.height - 205 currentWindowFrame.size.height -
206 bubbleFrame.size.height; 206 bubbleFrame.size.height;
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 [chooser_bubble_ui_controller_ onOptionAdded:static_cast<NSInteger>(index)]; 395 [chooser_bubble_ui_controller_ onOptionAdded:static_cast<NSInteger>(index)];
396 } 396 }
397 397
398 void ChooserBubbleUiCocoa::OnOptionRemoved(size_t index) { 398 void ChooserBubbleUiCocoa::OnOptionRemoved(size_t index) {
399 [chooser_bubble_ui_controller_ onOptionRemoved:static_cast<NSInteger>(index)]; 399 [chooser_bubble_ui_controller_ onOptionRemoved:static_cast<NSInteger>(index)];
400 } 400 }
401 401
402 void ChooserBubbleUiCocoa::OnBubbleClosing() { 402 void ChooserBubbleUiCocoa::OnBubbleClosing() {
403 chooser_bubble_ui_controller_ = nil; 403 chooser_bubble_ui_controller_ = nil;
404 } 404 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698