| OLD | NEW |
| 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 #import "chrome/browser/ui/cocoa/website_settings/permission_bubble_controller.h
" | 5 #import "chrome/browser/ui/cocoa/website_settings/permission_bubble_controller.h
" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/mac/bind_objc_block.h" | 9 #include "base/mac/bind_objc_block.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/strings/sys_string_conversions.h" | 11 #include "base/strings/sys_string_conversions.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
| 14 #include "chrome/browser/ui/browser_finder.h" | 14 #include "chrome/browser/ui/browser_finder.h" |
| 15 #include "chrome/browser/ui/browser_window.h" | 15 #include "chrome/browser/ui/browser_window.h" |
| 16 #import "chrome/browser/ui/chrome_style.h" | 16 #import "chrome/browser/ui/chrome_style.h" |
| 17 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 17 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 18 #import "chrome/browser/ui/cocoa/browser_window_utils.h" | 18 #import "chrome/browser/ui/cocoa/browser_window_utils.h" |
| 19 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h" | 19 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h" |
| 20 #import "chrome/browser/ui/cocoa/hover_close_button.h" | 20 #import "chrome/browser/ui/cocoa/hover_close_button.h" |
| 21 #import "chrome/browser/ui/cocoa/info_bubble_view.h" | 21 #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
| 22 #import "chrome/browser/ui/cocoa/info_bubble_window.h" | 22 #import "chrome/browser/ui/cocoa/info_bubble_window.h" |
| 23 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" | 23 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
| 24 #include "chrome/browser/ui/cocoa/website_settings/permission_bubble_cocoa.h" | 24 #include "chrome/browser/ui/cocoa/website_settings/permission_bubble_cocoa.h" |
| 25 #include "chrome/browser/ui/cocoa/website_settings/permission_selector_button.h" | 25 #include "chrome/browser/ui/cocoa/website_settings/permission_selector_button.h" |
| 26 #include "chrome/browser/ui/cocoa/website_settings/split_block_button.h" | 26 #include "chrome/browser/ui/cocoa/website_settings/split_block_button.h" |
| 27 #include "chrome/browser/ui/cocoa/website_settings/website_settings_utils_cocoa.
h" | 27 #include "chrome/browser/ui/cocoa/website_settings/website_settings_utils_cocoa.
h" |
| 28 #include "chrome/browser/ui/exclusive_access/exclusive_access_context.h" |
| 29 #include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h" |
| 30 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" |
| 28 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" | 31 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" |
| 29 #include "chrome/browser/ui/website_settings/permission_bubble_view.h" | 32 #include "chrome/browser/ui/website_settings/permission_bubble_view.h" |
| 30 #include "chrome/browser/ui/website_settings/permission_menu_model.h" | 33 #include "chrome/browser/ui/website_settings/permission_menu_model.h" |
| 34 #include "chrome/common/pref_names.h" |
| 31 #include "chrome/grit/generated_resources.h" | 35 #include "chrome/grit/generated_resources.h" |
| 36 #include "components/prefs/pref_service.h" |
| 32 #include "components/url_formatter/elide_url.h" | 37 #include "components/url_formatter/elide_url.h" |
| 33 #include "content/public/browser/native_web_keyboard_event.h" | 38 #include "content/public/browser/native_web_keyboard_event.h" |
| 34 #include "content/public/browser/user_metrics.h" | 39 #include "content/public/browser/user_metrics.h" |
| 35 #include "grit/components_strings.h" | 40 #include "grit/components_strings.h" |
| 36 #include "skia/ext/skia_utils_mac.h" | 41 #include "skia/ext/skia_utils_mac.h" |
| 37 #include "ui/base/cocoa/cocoa_base_utils.h" | 42 #include "ui/base/cocoa/cocoa_base_utils.h" |
| 38 #import "ui/base/cocoa/controls/hyperlink_text_view.h" | 43 #import "ui/base/cocoa/controls/hyperlink_text_view.h" |
| 39 #import "ui/base/cocoa/menu_controller.h" | 44 #import "ui/base/cocoa/menu_controller.h" |
| 40 #include "ui/base/cocoa/window_size_constants.h" | 45 #include "ui/base/cocoa/window_size_constants.h" |
| 41 #include "ui/base/l10n/l10n_util_mac.h" | 46 #include "ui/base/l10n/l10n_util_mac.h" |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 } | 445 } |
| 441 } | 446 } |
| 442 | 447 |
| 443 - (void)updateAnchorPosition { | 448 - (void)updateAnchorPosition { |
| 444 [self setParentWindow:[self getExpectedParentWindow]]; | 449 [self setParentWindow:[self getExpectedParentWindow]]; |
| 445 [self setAnchorPoint:[self getExpectedAnchorPoint]]; | 450 [self setAnchorPoint:[self getExpectedAnchorPoint]]; |
| 446 } | 451 } |
| 447 | 452 |
| 448 - (NSPoint)getExpectedAnchorPoint { | 453 - (NSPoint)getExpectedAnchorPoint { |
| 449 NSPoint anchor; | 454 NSPoint anchor; |
| 450 if ([self hasLocationBar]) { | 455 if ([self hasVisibleLocationBar]) { |
| 451 LocationBarViewMac* location_bar = | 456 LocationBarViewMac* location_bar = |
| 452 [[[self getExpectedParentWindow] windowController] locationBarBridge]; | 457 [[[self getExpectedParentWindow] windowController] locationBarBridge]; |
| 453 anchor = location_bar->GetPageInfoBubblePoint(); | 458 anchor = location_bar->GetPageInfoBubblePoint(); |
| 454 } else { | 459 } else { |
| 455 // Center the bubble if there's no location bar. | 460 // Center the bubble if there's no location bar. |
| 456 NSRect contentFrame = [[[self getExpectedParentWindow] contentView] frame]; | 461 NSRect contentFrame = [[[self getExpectedParentWindow] contentView] frame]; |
| 457 anchor = NSMakePoint(NSMidX(contentFrame), NSMaxY(contentFrame)); | 462 anchor = NSMakePoint(NSMidX(contentFrame), NSMaxY(contentFrame)); |
| 458 } | 463 } |
| 459 | 464 |
| 460 return ui::ConvertPointFromWindowToScreen([self getExpectedParentWindow], | 465 return ui::ConvertPointFromWindowToScreen([self getExpectedParentWindow], |
| 461 anchor); | 466 anchor); |
| 462 } | 467 } |
| 463 | 468 |
| 464 - (bool)hasLocationBar { | 469 - (bool)hasVisibleLocationBar { |
| 465 return browser_->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR); | 470 if (!browser_->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR)) |
| 471 return false; |
| 472 |
| 473 if (!browser_->exclusive_access_manager()->context()->IsFullscreen()) |
| 474 return true; |
| 475 |
| 476 // If the browser is in browser-initiated full screen, a preference can cause |
| 477 // the toolbar to be hidden. |
| 478 if (browser_->exclusive_access_manager() |
| 479 ->fullscreen_controller() |
| 480 ->IsFullscreenForBrowser()) { |
| 481 PrefService* prefs = browser_->profile()->GetPrefs(); |
| 482 bool show_toolbar = prefs->GetBoolean(prefs::kShowFullscreenToolbar); |
| 483 return show_toolbar; |
| 484 } |
| 485 |
| 486 // Otherwise this is fullscreen without a toolbar, so there is no visible |
| 487 // location bar. |
| 488 return false; |
| 466 } | 489 } |
| 467 | 490 |
| 468 - (info_bubble::BubbleArrowLocation)getExpectedArrowLocation { | 491 - (info_bubble::BubbleArrowLocation)getExpectedArrowLocation { |
| 469 return [self hasLocationBar] ? info_bubble::kTopLeft : info_bubble::kNoArrow; | 492 return [self hasVisibleLocationBar] ? info_bubble::kTopLeft |
| 493 : info_bubble::kNoArrow; |
| 470 } | 494 } |
| 471 | 495 |
| 472 - (NSWindow*)getExpectedParentWindow { | 496 - (NSWindow*)getExpectedParentWindow { |
| 473 DCHECK(browser_->window()); | 497 DCHECK(browser_->window()); |
| 474 return browser_->window()->GetNativeWindow(); | 498 return browser_->window()->GetNativeWindow(); |
| 475 } | 499 } |
| 476 | 500 |
| 477 - (NSView*)labelForRequest:(PermissionBubbleRequest*)request { | 501 - (NSView*)labelForRequest:(PermissionBubbleRequest*)request { |
| 478 DCHECK(request); | 502 DCHECK(request); |
| 479 base::scoped_nsobject<NSView> permissionView( | 503 base::scoped_nsobject<NSView> permissionView( |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 | 644 |
| 621 + (void)alignCenterOf:(NSView*)viewA verticallyToCenterOf:(NSView*)viewB { | 645 + (void)alignCenterOf:(NSView*)viewA verticallyToCenterOf:(NSView*)viewB { |
| 622 NSRect frameA = [viewA frame]; | 646 NSRect frameA = [viewA frame]; |
| 623 NSRect frameB = [viewB frame]; | 647 NSRect frameB = [viewB frame]; |
| 624 frameA.origin.y = | 648 frameA.origin.y = |
| 625 NSMinY(frameB) + std::floor((NSHeight(frameB) - NSHeight(frameA)) / 2); | 649 NSMinY(frameB) + std::floor((NSHeight(frameB) - NSHeight(frameA)) / 2); |
| 626 [viewA setFrameOrigin:frameA.origin]; | 650 [viewA setFrameOrigin:frameA.origin]; |
| 627 } | 651 } |
| 628 | 652 |
| 629 @end // implementation PermissionBubbleController | 653 @end // implementation PermissionBubbleController |
| OLD | NEW |