Commit 6f452a4d authored by Elly Fong-Jones's avatar Elly Fong-Jones Committed by Commit Bot

mac: always use Views confirm bubble

The confirm bubble is used only for the "Ask Google for Spelling Suggestions?"
prompt. The Cocoa bubble has some visual defects, but the Views one looks quite
a bit better.

Bug: 747203
Change-Id: I7876819a1b4dd96d32f4491ac67187be5c941c3c
Reviewed-on: https://chromium-review.googlesource.com/889139
Commit-Queue: Elly Fong-Jones <ellyjones@chromium.org>
Reviewed-by: default avatarNico Weber <thakis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#533769}
parent 91c3dd76
......@@ -183,11 +183,6 @@ split_static_library("ui") {
"cocoa/chrome_event_processing_window.mm",
"cocoa/clickhold_button_cell.h",
"cocoa/clickhold_button_cell.mm",
"cocoa/confirm_bubble_cocoa.h",
"cocoa/confirm_bubble_cocoa.mm",
"cocoa/confirm_bubble_controller.h",
"cocoa/confirm_bubble_controller.mm",
"cocoa/confirm_bubble_views_mac.mm",
"cocoa/constrained_web_dialog_delegate_mac.mm",
"cocoa/constrained_window/constrained_window_alert.h",
"cocoa/constrained_window/constrained_window_alert.mm",
......@@ -2488,7 +2483,6 @@ split_static_library("ui") {
"cocoa/bookmarks/bookmark_editor_base_controller.mm",
"cocoa/bookmarks/bookmark_editor_controller.h",
"cocoa/bookmarks/bookmark_editor_controller.mm",
"cocoa/confirm_bubble_views_mac.mm",
"cocoa/download/download_danger_prompt_impl.cc",
"cocoa/extensions/chooser_dialog_cocoa.h",
"cocoa/extensions/chooser_dialog_cocoa.mm",
......
// Copyright (c) 2012 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.
#ifndef CHROME_BROWSER_UI_COCOA_CONFIRM_BUBBLE_COCOA_H_
#define CHROME_BROWSER_UI_COCOA_CONFIRM_BUBBLE_COCOA_H_
#import <Cocoa/Cocoa.h>
#include "base/mac/scoped_nsobject.h"
@class ConfirmBubbleController;
// A view class that implements a bubble consisting of the following items:
// * one icon ("icon")
// * one title text ("title")
// * one message text ("message")
// * one optional link ("link")
// * two optional buttons ("ok" and "cancel")
//
// This bubble is convenient when we wish to ask transient, non-blocking
// questions. Unlike a dialog, a bubble menu disappears when we click outside of
// its window to avoid blocking user operations. A bubble is laid out as
// follows:
//
// +------------------------+
// | icon title |
// | message |
// | link |
// | [Cancel] [OK] |
// +------------------------+
//
@interface ConfirmBubbleCocoa : NSView<NSTextViewDelegate> {
@private
NSView* parent_; // weak
ConfirmBubbleController* controller_; // weak
// Controls used in this bubble.
base::scoped_nsobject<NSImageView> icon_;
base::scoped_nsobject<NSTextView> titleLabel_;
base::scoped_nsobject<NSTextView> messageLabel_;
base::scoped_nsobject<NSButton> okButton_;
base::scoped_nsobject<NSButton> cancelButton_;
}
// Initializes a bubble view. Since this initializer programmatically creates a
// custom NSView (i.e. without using a nib file), this function should be called
// from loadView: of the controller object which owns this view.
- (id)initWithParent:(NSView*)parent
controller:(ConfirmBubbleController*)controller;
@end
// Exposed only for unit testing.
@interface ConfirmBubbleCocoa (ExposedForUnitTesting)
- (void)clickOk;
- (void)clickCancel;
- (void)clickLink;
@end
#endif // CHROME_BROWSER_UI_COCOA_CONFIRM_BUBBLE_COCOA_H_
// Copyright (c) 2012 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.
#import "chrome/browser/ui/cocoa/confirm_bubble_cocoa.h"
#include <utility>
#include "base/strings/string16.h"
#include "chrome/browser/themes/theme_service.h"
#import "chrome/browser/ui/cocoa/confirm_bubble_controller.h"
#include "chrome/browser/ui/confirm_bubble.h"
#include "chrome/browser/ui/confirm_bubble_model.h"
#import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSBezierPath+RoundRect.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/image/image.h"
// The width for the message text. We break lines so the specified message fits
// into this width.
const int kMaxMessageWidth = 400;
// The corner redius of this bubble view.
const int kBubbleCornerRadius = 3;
// The color for the border of this bubble view.
const float kBubbleWindowEdge = 0.7f;
// Constants used for layouting controls. These variables are copied from
// "ui/views/layout/layout_constants.h".
// Vertical spacing between a label and some control.
const int kLabelToControlVerticalSpacing = 8;
// Vertical spacing between controls that are logically related.
const int kRelatedControlVerticalSpacing = 8;
// Vertical spacing between the edge of the window and the
// top or bottom of a button.
const int kButtonVEdgeMargin = 6;
// Horizontal spacing between the edge of the window and the
// left or right of a button.
const int kButtonHEdgeMargin = 7;
// An interface that is derived from NSTextView and does not accept
// first-responder status, i.e. a NSTextView-derived class that never becomes
// the first responder. When we click a NSTextView object, it becomes the first
// responder. Unfortunately, we delete the ConfirmBubbleCocoa object anytime
// when it loses first-responder status not to prevent disturbing other
// responders.
// To prevent text views in this ConfirmBubbleCocoa object from stealing the
// first-responder status, we use this view in the ConfirmBubbleCocoa object.
@interface ConfirmBubbleTextView : NSTextView
@end
@implementation ConfirmBubbleTextView
- (BOOL)acceptsFirstResponder {
return NO;
}
@end
// Private Methods
@interface ConfirmBubbleCocoa (Private)
- (void)performLayout;
- (void)closeBubble;
@end
@implementation ConfirmBubbleCocoa
- (id)initWithParent:(NSView*)parent
controller:(ConfirmBubbleController*)controller {
// Create a NSView and set its width. We will set its position and height
// after finish layouting controls in performLayout:.
NSRect bounds =
NSMakeRect(0, 0, kMaxMessageWidth + kButtonHEdgeMargin * 2, 0);
if (self = [super initWithFrame:bounds]) {
parent_ = parent;
controller_ = controller;
[self performLayout];
}
return self;
}
- (void)drawRect:(NSRect)dirtyRect {
// Fill the background rectangle in white and draw its edge.
NSRect bounds = [self bounds];
bounds = NSInsetRect(bounds, 0.5, 0.5);
NSBezierPath* border =
[NSBezierPath gtm_bezierPathWithRoundRect:bounds
topLeftCornerRadius:kBubbleCornerRadius
topRightCornerRadius:kBubbleCornerRadius
bottomLeftCornerRadius:kBubbleCornerRadius
bottomRightCornerRadius:kBubbleCornerRadius];
[[NSColor colorWithDeviceWhite:1.0f alpha:1.0f] set];
[border fill];
[[NSColor colorWithDeviceWhite:kBubbleWindowEdge alpha:1.0f] set];
[border stroke];
}
// An NSResponder method.
- (BOOL)resignFirstResponder {
// We do not only accept this request but also close this bubble when we are
// asked to resign the first responder. This bubble should be displayed only
// while it is the first responder.
[self closeBubble];
return YES;
}
// NSControl action handlers. These handlers are called when we click a cancel
// button, a close icon, and an OK button, respectively.
- (IBAction)cancel:(id)sender {
[controller_ cancel];
[self closeBubble];
}
- (IBAction)close:(id)sender {
[self closeBubble];
}
- (IBAction)ok:(id)sender {
[controller_ accept];
[self closeBubble];
}
// An NSTextViewDelegate method. This function is called when we click a link in
// this bubble.
- (BOOL)textView:(NSTextView*)textView
clickedOnLink:(id)link
atIndex:(NSUInteger)charIndex {
[controller_ openHelpPage];
[self closeBubble];
return YES;
}
// Initializes controls specified by the ConfirmBubbleModel object and layouts
// them into this bubble. This function retrieves text and images from the
// ConfirmBubbleModel object (via the ConfirmBubbleController object) and
// layouts them programmatically. This function layouts controls in the botom-up
// order since NSView uses bottom-up coordinate.
- (void)performLayout {
NSRect frameRect = [self frame];
// Add the ok button and the cancel button to the first row if we have either
// of them.
CGFloat left = kButtonHEdgeMargin;
CGFloat right = NSWidth(frameRect) - kButtonHEdgeMargin;
CGFloat bottom = kButtonVEdgeMargin;
CGFloat height = 0;
if ([controller_ hasOkButton]) {
okButton_.reset([[NSButton alloc]
initWithFrame:NSMakeRect(0, bottom, 0, 0)]);
[okButton_.get() setBezelStyle:NSRoundedBezelStyle];
[okButton_.get() setTitle:[controller_ okButtonText]];
[okButton_.get() setTarget:self];
[okButton_.get() setAction:@selector(ok:)];
[okButton_.get() sizeToFit];
NSRect okButtonRect = [okButton_.get() frame];
right -= NSWidth(okButtonRect);
okButtonRect.origin.x = right;
[okButton_.get() setFrame:okButtonRect];
[self addSubview:okButton_.get()];
height = std::max(height, NSHeight(okButtonRect));
}
if ([controller_ hasCancelButton]) {
cancelButton_.reset([[NSButton alloc]
initWithFrame:NSMakeRect(0, bottom, 0, 0)]);
[cancelButton_.get() setBezelStyle:NSRoundedBezelStyle];
[cancelButton_.get() setTitle:[controller_ cancelButtonText]];
[cancelButton_.get() setTarget:self];
[cancelButton_.get() setAction:@selector(cancel:)];
[cancelButton_.get() sizeToFit];
NSRect cancelButtonRect = [cancelButton_.get() frame];
right -= NSWidth(cancelButtonRect) + kButtonHEdgeMargin;
cancelButtonRect.origin.x = right;
[cancelButton_.get() setFrame:cancelButtonRect];
[self addSubview:cancelButton_.get()];
height = std::max(height, NSHeight(cancelButtonRect));
}
// Add the message label (and the link label) to the second row.
left = kButtonHEdgeMargin;
right = NSWidth(frameRect);
bottom += height + kRelatedControlVerticalSpacing;
height = 0;
messageLabel_.reset([[ConfirmBubbleTextView alloc]
initWithFrame:NSMakeRect(left, bottom, kMaxMessageWidth, 0)]);
NSString* messageText = [controller_ messageText];
NSMutableDictionary* attributes = [NSMutableDictionary dictionary];
base::scoped_nsobject<NSMutableAttributedString> attributedMessage(
[[NSMutableAttributedString alloc] initWithString:messageText
attributes:attributes]);
NSString* linkText = [controller_ linkText];
if (linkText) {
base::scoped_nsobject<NSAttributedString> whiteSpace(
[[NSAttributedString alloc] initWithString:@" "]);
[attributedMessage.get() appendAttributedString:whiteSpace.get()];
[attributes setObject:[controller_ helpPageURL] forKey:NSLinkAttributeName];
base::scoped_nsobject<NSAttributedString> attributedLink(
[[NSAttributedString alloc] initWithString:linkText
attributes:attributes]);
[attributedMessage.get() appendAttributedString:attributedLink.get()];
}
[[messageLabel_.get() textStorage] setAttributedString:attributedMessage];
[messageLabel_.get() setHorizontallyResizable:NO];
[messageLabel_.get() setVerticallyResizable:YES];
[messageLabel_.get() setEditable:NO];
[messageLabel_.get() setDrawsBackground:NO];
[messageLabel_.get() setDelegate:self];
[messageLabel_.get() sizeToFit];
height = NSHeight([messageLabel_.get() frame]);
[self addSubview:messageLabel_.get()];
// Add the icon and the title label to the third row.
left = kButtonHEdgeMargin;
right = NSWidth(frameRect);
bottom += height + kLabelToControlVerticalSpacing;
titleLabel_.reset([[NSTextView alloc]
initWithFrame:NSMakeRect(left, bottom, right - left, 0)]);
[titleLabel_.get() setString:[controller_ title]];
[titleLabel_.get() setHorizontallyResizable:NO];
[titleLabel_.get() setVerticallyResizable:YES];
[titleLabel_.get() setEditable:NO];
[titleLabel_.get() setSelectable:NO];
[titleLabel_.get() setDrawsBackground:NO];
[titleLabel_.get() sizeToFit];
[self addSubview:titleLabel_.get()];
height = NSHeight([titleLabel_.get() frame]);
// Adjust the frame rectangle of this bubble so we can show all controls.
NSRect parentRect = [parent_ frame];
frameRect.size.height = bottom + height + kButtonVEdgeMargin;
frameRect.origin.x = (NSWidth(parentRect) - NSWidth(frameRect)) / 2;
frameRect.origin.y = NSHeight(parentRect) - NSHeight(frameRect);
[self setFrame:frameRect];
}
// Closes this bubble and releases all resources. This function just puts the
// owner ConfirmBubbleController object to the current autorelease pool. (This
// view will be deleted when the owner object is deleted.)
- (void)closeBubble {
[self removeFromSuperview];
[controller_ autorelease];
parent_ = nil;
controller_ = nil;
}
@end
@implementation ConfirmBubbleCocoa (ExposedForUnitTesting)
- (void)clickOk {
[self ok:self];
}
- (void)clickCancel {
[self cancel:self];
}
- (void)clickLink {
[self textView:messageLabel_.get() clickedOnLink:nil atIndex:0];
}
@end
// Copyright (c) 2012 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.
#ifndef CHROME_BROWSER_UI_COCOA_CONFIRM_BUBBLE_CONTROLLER_H_
#define CHROME_BROWSER_UI_COCOA_CONFIRM_BUBBLE_CONTROLLER_H_
#import <Cocoa/Cocoa.h>
#include <memory>
class ConfirmBubbleModel;
// A view controller that manages a bubble view and becomes a proxy between
// the view and the ConfirmBubbleModel object. This class is internally used
// in ShowConfirmBubble() and users do not have to change this class directly.
@interface ConfirmBubbleController :
NSViewController<NSTextViewDelegate> {
@private
NSView* parent_; // weak
CGPoint origin_;
std::unique_ptr<ConfirmBubbleModel> model_;
}
// Creates a ConfirmBubbleController object. The ConfirmBubbleController
// controller takes the ownership of the passed-in ConfirmBubbleModel.
- (id)initWithParent:(NSView*)parent
origin:(CGPoint)origin
model:(std::unique_ptr<ConfirmBubbleModel>)model;
// Access to the properties of the ConfirmBubbleModel object. These functions
// also converts C++ types returned by the ConfirmBubbleModel object to
// Objective-C types.
- (NSPoint)origin;
- (NSString*)title;
- (NSString*)messageText;
- (NSString*)linkText;
- (NSString*)helpPageURL;
- (NSString*)okButtonText;
- (NSString*)cancelButtonText;
- (BOOL)hasOkButton;
- (BOOL)hasCancelButton;
// Handle actions from the ConfirmBubbleCocoa object.
- (void)accept;
- (void)cancel;
- (void)openHelpPage;
@end
#endif // CHROME_BROWSER_UI_COCOA_CONFIRM_BUBBLE_CONTROLLER_H_
// Copyright (c) 2012 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.
#import "chrome/browser/ui/cocoa/confirm_bubble_controller.h"
#include <utility>
#include "base/strings/sys_string_conversions.h"
#import "chrome/browser/ui/cocoa/browser_window_controller.h"
#import "chrome/browser/ui/cocoa/confirm_bubble_cocoa.h"
#import "chrome/browser/ui/confirm_bubble_model.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/image/image.h"
@implementation ConfirmBubbleController
- (id)initWithParent:(NSView*)parent
origin:(CGPoint)origin
model:(std::unique_ptr<ConfirmBubbleModel>)model {
if ((self = [super initWithNibName:nil bundle:nil])) {
parent_ = parent;
origin_ = origin;
model_ = std::move(model);
}
return self;
}
- (void)loadView {
[self setView:[[[ConfirmBubbleCocoa alloc] initWithParent:parent_
controller:self] autorelease]];
}
- (void)windowWillClose:(NSNotification*)notification {
[self autorelease];
}
// Accessors. This functions converts the C++ types retrieved from the
// ConfirmBubbleModel object to Objective-C types, and return them.
- (NSPoint)origin {
return NSPointFromCGPoint(origin_);
}
- (NSString*)title {
return base::SysUTF16ToNSString(model_->GetTitle());
}
- (NSString*)messageText {
return base::SysUTF16ToNSString(model_->GetMessageText());
}
- (NSString*)linkText {
return base::SysUTF16ToNSString(model_->GetLinkText());
}
- (NSString*)helpPageURL {
return base::SysUTF8ToNSString(model_->GetHelpPageURL().spec());
}
- (NSString*)okButtonText {
return base::SysUTF16ToNSString(
model_->GetButtonLabel(ConfirmBubbleModel::BUTTON_OK));
}
- (NSString*)cancelButtonText {
return base::SysUTF16ToNSString(
model_->GetButtonLabel(ConfirmBubbleModel::BUTTON_CANCEL));
}
- (BOOL)hasOkButton {
return (model_->GetButtons() & ConfirmBubbleModel::BUTTON_OK) ? YES : NO;
}
- (BOOL)hasCancelButton {
return (model_->GetButtons() & ConfirmBubbleModel::BUTTON_CANCEL) ? YES : NO;
}
// Action handlers.
- (void)accept {
model_->Accept();
}
- (void)cancel {
model_->Cancel();
}
- (void)openHelpPage {
model_->OpenHelpPage();
}
@end
// Copyright (c) 2012 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.
#import "chrome/browser/ui/cocoa/confirm_bubble_controller.h"
#include <utility>
#include "base/compiler_specific.h"
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
#import "chrome/browser/ui/cocoa/confirm_bubble_cocoa.h"
#include "chrome/browser/ui/cocoa/test/cocoa_test_helper.h"
#include "chrome/browser/ui/confirm_bubble_model.h"
#import "testing/gtest_mac.h"
#import "ui/gfx/geometry/point.h"
namespace {
// The model object used in this test. This model implements all methods and
// updates its status when ConfirmBubbleController calls its methods.
class TestConfirmBubbleModel : public ConfirmBubbleModel {
public:
TestConfirmBubbleModel(bool* accept_clicked,
bool* cancel_clicked,
bool* link_clicked);
TestConfirmBubbleModel();
base::string16 GetTitle() const override;
base::string16 GetMessageText() const override;
int GetButtons() const override;
base::string16 GetButtonLabel(BubbleButton button) const override;
void Accept() override;
void Cancel() override;
base::string16 GetLinkText() const override;
void OpenHelpPage() override;
private:
bool* accept_clicked_;
bool* cancel_clicked_;
bool* link_clicked_;
};
TestConfirmBubbleModel::TestConfirmBubbleModel(bool* accept_clicked,
bool* cancel_clicked,
bool* link_clicked)
: accept_clicked_(accept_clicked),
cancel_clicked_(cancel_clicked),
link_clicked_(link_clicked) {}
base::string16 TestConfirmBubbleModel::GetTitle() const {
return base::ASCIIToUTF16("Test");
}
base::string16 TestConfirmBubbleModel::GetMessageText() const {
return base::ASCIIToUTF16("Test Message");
}
int TestConfirmBubbleModel::GetButtons() const {
return BUTTON_OK | BUTTON_CANCEL;
}
base::string16 TestConfirmBubbleModel::GetButtonLabel(
BubbleButton button) const {
return button == BUTTON_OK ? base::ASCIIToUTF16("OK")
: base::ASCIIToUTF16("Cancel");
}
void TestConfirmBubbleModel::Accept() {
*accept_clicked_ = true;
}
void TestConfirmBubbleModel::Cancel() {
*cancel_clicked_ = true;
}
base::string16 TestConfirmBubbleModel::GetLinkText() const {
return base::ASCIIToUTF16("Link");
}
void TestConfirmBubbleModel::OpenHelpPage() {
*link_clicked_ = true;
}
} // namespace
class ConfirmBubbleControllerTest : public CocoaTest {
public:
ConfirmBubbleControllerTest()
: accept_clicked_(false), cancel_clicked_(false), link_clicked_(false) {
NSView* view = [test_window() contentView];
// This model is owned by the controller created below.
model_.reset(new TestConfirmBubbleModel(&accept_clicked_, &cancel_clicked_,
&link_clicked_));
gfx::Point origin(0, 0);
controller_ =
[[ConfirmBubbleController alloc] initWithParent:view
origin:origin.ToCGPoint()
model:std::move(model_)];
[view addSubview:[controller_ view]
positioned:NSWindowAbove
relativeTo:nil];
}
ConfirmBubbleCocoa* GetBubble() const {
return (ConfirmBubbleCocoa*)[controller_ view];
}
bool accept_clicked() const { return accept_clicked_; }
bool cancel_clicked() const { return cancel_clicked_; }
bool link_clicked() const { return link_clicked_; }
private:
ConfirmBubbleController* controller_; // weak; owns self
std::unique_ptr<TestConfirmBubbleModel> model_;
bool accept_clicked_;
bool cancel_clicked_;
bool link_clicked_;
};
// Verify clicking a button or a link removes the ConfirmBubbleCocoa object and
// calls an appropriate model method.
TEST_F(ConfirmBubbleControllerTest, ClickOk) {
NSView* view = [test_window() contentView];
ConfirmBubbleCocoa* bubble = GetBubble();
bool contains_bubble_view = [[view subviews] containsObject:bubble];
EXPECT_TRUE(contains_bubble_view);
// Click its OK button and verify this view has been removed from the test
// window. Also verify TestConfirmBubbleModel::Accept() has been called.
[bubble clickOk];
contains_bubble_view = [[view subviews] containsObject:bubble];
EXPECT_FALSE(contains_bubble_view);
EXPECT_TRUE(accept_clicked());
EXPECT_FALSE(cancel_clicked());
EXPECT_FALSE(link_clicked());
}
TEST_F(ConfirmBubbleControllerTest, ClickCancel) {
NSView* view = [test_window() contentView];
ConfirmBubbleCocoa* bubble = GetBubble();
bool contains_bubble_view = [[view subviews] containsObject:bubble];
EXPECT_TRUE(contains_bubble_view);
// Click its cancel button and verify this view has been removed from the test
// window. Also verify TestConfirmBubbleModel::Cancel() has been called.
[bubble clickCancel];
contains_bubble_view = [[view subviews] containsObject:bubble];
EXPECT_FALSE(contains_bubble_view);
EXPECT_FALSE(accept_clicked());
EXPECT_TRUE(cancel_clicked());
EXPECT_FALSE(link_clicked());
}
TEST_F(ConfirmBubbleControllerTest, ClickLink) {
NSView* view = [test_window() contentView];
ConfirmBubbleCocoa* bubble = GetBubble();
bool contains_bubble_view = [[view subviews] containsObject:bubble];
EXPECT_TRUE(contains_bubble_view);
// Click its link and verify this view has been removed from the test window.
// Also verify TestConfirmBubbleModel::LinkClicked() has been called.
[bubble clickLink];
contains_bubble_view = [[view subviews] containsObject:bubble];
EXPECT_FALSE(contains_bubble_view);
EXPECT_FALSE(accept_clicked());
EXPECT_FALSE(cancel_clicked());
EXPECT_TRUE(link_clicked());
}
// Copyright 2017 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/confirm_bubble.h"
#include "chrome/browser/ui/cocoa/browser_dialogs_views_mac.h"
#import "chrome/browser/ui/cocoa/confirm_bubble_controller.h"
#include "chrome/browser/ui/confirm_bubble_model.h"
#include "chrome/browser/ui/views/confirm_bubble_views.h"
#include "components/constrained_window/constrained_window_views.h"
namespace {
void ShowConfirmBubbleViews(gfx::NativeWindow window,
std::unique_ptr<ConfirmBubbleModel> model) {
constrained_window::CreateBrowserModalDialogViews(
new ConfirmBubbleViews(std::move(model)), window)
->Show();
}
} // namespace
namespace chrome {
void ShowConfirmBubble(gfx::NativeWindow window,
gfx::NativeView anchor_view,
const gfx::Point& origin,
std::unique_ptr<ConfirmBubbleModel> model) {
if (chrome::ShowAllDialogsWithViewsToolkit()) {
ShowConfirmBubbleViews(window, std::move(model));
return;
}
// Create a custom NSViewController that manages a bubble view, and add it to
// a child to the specified |anchor_view|. This controller will be
// automatically deleted when it loses first-responder status.
ConfirmBubbleController* controller =
[[ConfirmBubbleController alloc] initWithParent:anchor_view
origin:origin.ToCGPoint()
model:std::move(model)];
[anchor_view addSubview:[controller view]
positioned:NSWindowAbove
relativeTo:nil];
[[anchor_view window] makeFirstResponder:[controller view]];
}
} // namespace chrome
......@@ -117,7 +117,6 @@ void ConfirmBubbleViews::ButtonPressed(views::Button* sender,
namespace chrome {
#if !defined(OS_MACOSX) || BUILDFLAG(MAC_VIEWS_BROWSER)
void ShowConfirmBubble(gfx::NativeWindow window,
gfx::NativeView anchor_view,
const gfx::Point& origin,
......@@ -126,6 +125,5 @@ void ShowConfirmBubble(gfx::NativeWindow window,
new ConfirmBubbleViews(std::move(model)), window)
->Show();
}
#endif // !OS_MACOSX || MAC_VIEWS_BROWSER
} // namespace chrome
......@@ -3881,7 +3881,6 @@ test("unit_tests") {
"../browser/ui/cocoa/chrome_browser_window_unittest.mm",
"../browser/ui/cocoa/clickhold_button_cell_unittest.mm",
"../browser/ui/cocoa/color_panel_cocoa_unittest.mm",
"../browser/ui/cocoa/confirm_bubble_controller_unittest.mm",
"../browser/ui/cocoa/confirm_quit_panel_controller_unittest.mm",
"../browser/ui/cocoa/constrained_window/constrained_window_alert_unittest.mm",
"../browser/ui/cocoa/constrained_window/constrained_window_button_unittest.mm",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment