| 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/permission_bubble/chooser_bubble_ui_cocoa.h" | 5 #import "chrome/browser/ui/cocoa/permission_bubble/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" | |
| 14 #include "base/strings/sys_string_conversions.h" | 13 #include "base/strings/sys_string_conversions.h" |
| 15 #include "chrome/browser/chooser_controller/chooser_controller.h" | 14 #include "chrome/browser/chooser_controller/chooser_controller.h" |
| 16 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 17 #include "chrome/browser/ui/browser_window.h" | 16 #include "chrome/browser/ui/browser_window.h" |
| 18 #import "chrome/browser/ui/cocoa/base_bubble_controller.h" | 17 #import "chrome/browser/ui/cocoa/base_bubble_controller.h" |
| 19 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 18 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 20 #import "chrome/browser/ui/cocoa/browser_window_utils.h" | 19 #import "chrome/browser/ui/cocoa/browser_window_utils.h" |
| 20 #import "chrome/browser/ui/cocoa/bubble_anchor_helper.h" |
| 21 #import "chrome/browser/ui/cocoa/device_chooser_content_view_cocoa.h" | 21 #import "chrome/browser/ui/cocoa/device_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/permission_bubble/chooser_bubble_delegate.h" | |
| 26 #include "components/bubble/bubble_controller.h" | 25 #include "components/bubble/bubble_controller.h" |
| 27 #include "content/public/browser/native_web_keyboard_event.h" | 26 #include "content/public/browser/native_web_keyboard_event.h" |
| 28 #include "ui/base/cocoa/cocoa_base_utils.h" | 27 #include "ui/base/cocoa/cocoa_base_utils.h" |
| 29 #include "ui/base/cocoa/window_size_constants.h" | 28 #include "ui/base/cocoa/window_size_constants.h" |
| 30 | 29 |
| 31 std::unique_ptr<BubbleUi> ChooserBubbleDelegate::BuildBubbleUi() { | |
| 32 return base::MakeUnique<ChooserBubbleUiCocoa>(browser_, | |
| 33 std::move(chooser_controller_)); | |
| 34 } | |
| 35 | |
| 36 @interface ChooserBubbleUiController | 30 @interface ChooserBubbleUiController |
| 37 : BaseBubbleController<NSTableViewDataSource, NSTableViewDelegate> { | 31 : BaseBubbleController<NSTableViewDataSource, NSTableViewDelegate> { |
| 38 @private | 32 @private |
| 39 // Bridge to the C++ class that created this object. | 33 // Bridge to the C++ class that created this object. |
| 40 ChooserBubbleUiCocoa* bridge_; // Weak. | 34 ChooserBubbleUiCocoa* bridge_; // Weak. |
| 41 bool buttonPressed_; | 35 bool buttonPressed_; |
| 42 | 36 |
| 43 base::scoped_nsobject<DeviceChooserContentViewCocoa> | 37 base::scoped_nsobject<DeviceChooserContentViewCocoa> |
| 44 deviceChooserContentView_; | 38 deviceChooserContentView_; |
| 45 NSTableView* tableView_; // Weak. | 39 NSTableView* tableView_; // Weak. |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 [deviceChooserContentView_ updateContentRowColor]; | 213 [deviceChooserContentView_ updateContentRowColor]; |
| 220 [connectButton_ setEnabled:[tableView_ numberOfSelectedRows] > 0]; | 214 [connectButton_ setEnabled:[tableView_ numberOfSelectedRows] > 0]; |
| 221 } | 215 } |
| 222 | 216 |
| 223 - (void)updateAnchorPosition { | 217 - (void)updateAnchorPosition { |
| 224 [self setParentWindow:[self getExpectedParentWindow]]; | 218 [self setParentWindow:[self getExpectedParentWindow]]; |
| 225 [self setAnchorPoint:[self getExpectedAnchorPoint]]; | 219 [self setAnchorPoint:[self getExpectedAnchorPoint]]; |
| 226 } | 220 } |
| 227 | 221 |
| 228 - (NSPoint)getExpectedAnchorPoint { | 222 - (NSPoint)getExpectedAnchorPoint { |
| 229 NSPoint anchor; | 223 return GetPermissionBubbleAnchorPointForBrowser(browser_, |
| 230 if ([self hasLocationBar]) { | 224 [self hasLocationBar]); |
| 231 LocationBarViewMac* locationBar = | |
| 232 [[[self getExpectedParentWindow] windowController] locationBarBridge]; | |
| 233 anchor = locationBar->GetPageInfoBubblePoint(); | |
| 234 } else { | |
| 235 // Center the bubble if there's no location bar. | |
| 236 NSRect contentFrame = [[[self getExpectedParentWindow] contentView] frame]; | |
| 237 anchor = NSMakePoint(NSMidX(contentFrame), NSMaxY(contentFrame)); | |
| 238 } | |
| 239 | |
| 240 return ui::ConvertPointFromWindowToScreen([self getExpectedParentWindow], | |
| 241 anchor); | |
| 242 } | 225 } |
| 243 | 226 |
| 244 - (bool)hasLocationBar { | 227 - (bool)hasLocationBar { |
| 245 return browser_->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR); | 228 return HasVisibleLocationBarForBrowser(browser_); |
| 246 } | 229 } |
| 247 | 230 |
| 248 - (info_bubble::BubbleArrowLocation)getExpectedArrowLocation { | 231 - (info_bubble::BubbleArrowLocation)getExpectedArrowLocation { |
| 249 return [self hasLocationBar] ? info_bubble::kTopLeading | 232 return [self hasLocationBar] ? info_bubble::kTopLeading |
| 250 : info_bubble::kNoArrow; | 233 : info_bubble::kNoArrow; |
| 251 } | 234 } |
| 252 | 235 |
| 253 - (NSWindow*)getExpectedParentWindow { | 236 - (NSWindow*)getExpectedParentWindow { |
| 254 DCHECK(browser_->window()); | 237 DCHECK(browser_->window()); |
| 255 return browser_->window()->GetNativeWindow(); | 238 return browser_->window()->GetNativeWindow(); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 } | 307 } |
| 325 | 308 |
| 326 void ChooserBubbleUiCocoa::UpdateAnchorPosition() { | 309 void ChooserBubbleUiCocoa::UpdateAnchorPosition() { |
| 327 if (chooser_bubble_ui_controller_) | 310 if (chooser_bubble_ui_controller_) |
| 328 [chooser_bubble_ui_controller_ updateAnchorPosition]; | 311 [chooser_bubble_ui_controller_ updateAnchorPosition]; |
| 329 } | 312 } |
| 330 | 313 |
| 331 void ChooserBubbleUiCocoa::OnBubbleClosing() { | 314 void ChooserBubbleUiCocoa::OnBubbleClosing() { |
| 332 chooser_bubble_ui_controller_ = nil; | 315 chooser_bubble_ui_controller_ = nil; |
| 333 } | 316 } |
| OLD | NEW |