| OLD | NEW |
| 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/utf_string_conversions.h" | 14 #include "base/strings/sys_string_conversions.h" |
| 15 #include "chrome/browser/chooser_controller/chooser_controller.h" | 15 #include "chrome/browser/chooser_controller/chooser_controller.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_cocoa.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" | |
| 27 #include "components/bubble/bubble_controller.h" | 26 #include "components/bubble/bubble_controller.h" |
| 28 #include "components/url_formatter/elide_url.h" | |
| 29 #include "content/public/browser/native_web_keyboard_event.h" | 27 #include "content/public/browser/native_web_keyboard_event.h" |
| 30 #include "ui/base/cocoa/cocoa_base_utils.h" | 28 #include "ui/base/cocoa/cocoa_base_utils.h" |
| 31 #include "ui/base/cocoa/window_size_constants.h" | 29 #include "ui/base/cocoa/window_size_constants.h" |
| 32 #include "ui/base/l10n/l10n_util_mac.h" | |
| 33 #include "url/gurl.h" | |
| 34 #include "url/origin.h" | |
| 35 | 30 |
| 36 std::unique_ptr<BubbleUi> ChooserBubbleDelegate::BuildBubbleUi() { | 31 std::unique_ptr<BubbleUi> ChooserBubbleDelegate::BuildBubbleUi() { |
| 37 return base::WrapUnique( | 32 return base::WrapUnique( |
| 38 new ChooserBubbleUiCocoa(browser_, std::move(chooser_controller_))); | 33 new ChooserBubbleUiCocoa(browser_, std::move(chooser_controller_))); |
| 39 } | 34 } |
| 40 | 35 |
| 41 @interface ChooserBubbleUiController | 36 @interface ChooserBubbleUiController |
| 42 : BaseBubbleController<NSTableViewDataSource, NSTableViewDelegate> { | 37 : BaseBubbleController<NSTableViewDataSource, NSTableViewDelegate> { |
| 43 @private | 38 @private |
| 44 // Bridge to the C++ class that created this object. | 39 // Bridge to the C++ class that created this object. |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 [self setShouldCloseOnResignKey:NO]; | 108 [self setShouldCloseOnResignKey:NO]; |
| 114 [self setShouldOpenAsKeyWindow:YES]; | 109 [self setShouldOpenAsKeyWindow:YES]; |
| 115 [[self bubble] setArrowLocation:[self getExpectedArrowLocation]]; | 110 [[self bubble] setArrowLocation:[self getExpectedArrowLocation]]; |
| 116 bridge_ = bridge; | 111 bridge_ = bridge; |
| 117 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; | 112 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; |
| 118 [center addObserver:self | 113 [center addObserver:self |
| 119 selector:@selector(parentWindowDidMove:) | 114 selector:@selector(parentWindowDidMove:) |
| 120 name:NSWindowDidMoveNotification | 115 name:NSWindowDidMoveNotification |
| 121 object:[self getExpectedParentWindow]]; | 116 object:[self getExpectedParentWindow]]; |
| 122 | 117 |
| 123 url::Origin origin = chooserController->GetOrigin(); | 118 base::string16 chooserTitle = chooserController->GetTitle(); |
| 124 chooserContentView_.reset([[ChooserContentViewCocoa alloc] | 119 chooserContentView_.reset([[ChooserContentViewCocoa alloc] |
| 125 initWithChooserTitle: | 120 initWithChooserTitle:base::SysUTF16ToNSString(chooserTitle) |
| 126 l10n_util::GetNSStringF( | |
| 127 IDS_DEVICE_CHOOSER_PROMPT, | |
| 128 url_formatter::FormatOriginForSecurityDisplay( | |
| 129 origin, url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC)) | |
| 130 chooserController:std::move(chooserController)]); | 121 chooserController:std::move(chooserController)]); |
| 131 | 122 |
| 132 tableView_ = [chooserContentView_ tableView]; | 123 tableView_ = [chooserContentView_ tableView]; |
| 133 connectButton_ = [chooserContentView_ connectButton]; | 124 connectButton_ = [chooserContentView_ connectButton]; |
| 134 cancelButton_ = [chooserContentView_ cancelButton]; | 125 cancelButton_ = [chooserContentView_ cancelButton]; |
| 135 | 126 |
| 136 [connectButton_ setTarget:self]; | 127 [connectButton_ setTarget:self]; |
| 137 [connectButton_ setAction:@selector(onConnect:)]; | 128 [connectButton_ setAction:@selector(onConnect:)]; |
| 138 [cancelButton_ setTarget:self]; | 129 [cancelButton_ setTarget:self]; |
| 139 [cancelButton_ setAction:@selector(onCancel:)]; | 130 [cancelButton_ setAction:@selector(onCancel:)]; |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 } | 309 } |
| 319 | 310 |
| 320 void ChooserBubbleUiCocoa::UpdateAnchorPosition() { | 311 void ChooserBubbleUiCocoa::UpdateAnchorPosition() { |
| 321 if (chooser_bubble_ui_controller_) | 312 if (chooser_bubble_ui_controller_) |
| 322 [chooser_bubble_ui_controller_ updateAnchorPosition]; | 313 [chooser_bubble_ui_controller_ updateAnchorPosition]; |
| 323 } | 314 } |
| 324 | 315 |
| 325 void ChooserBubbleUiCocoa::OnBubbleClosing() { | 316 void ChooserBubbleUiCocoa::OnBubbleClosing() { |
| 326 chooser_bubble_ui_controller_ = nil; | 317 chooser_bubble_ui_controller_ = nil; |
| 327 } | 318 } |
| OLD | NEW |