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

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

Issue 1280673003: [Mac] Enable MacViews site settings bubble behind --enable-mac-views-dialogs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@enabledialogs
Patch Set: Address comments. Created 5 years, 4 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 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/website_settings_bubble_contro ller.h" 5 #import "chrome/browser/ui/cocoa/website_settings/website_settings_bubble_contro ller.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #import <AppKit/AppKit.h> 9 #import <AppKit/AppKit.h>
10 10
11 #include "base/mac/bind_objc_block.h" 11 #include "base/mac/bind_objc_block.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/sys_string_conversions.h" 13 #include "base/strings/sys_string_conversions.h"
14 #import "chrome/browser/certificate_viewer.h" 14 #import "chrome/browser/certificate_viewer.h"
15 #include "chrome/browser/infobars/infobar_service.h" 15 #include "chrome/browser/infobars/infobar_service.h"
16 #include "chrome/browser/ui/browser_dialogs.h"
16 #import "chrome/browser/ui/cocoa/browser_window_controller.h" 17 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
17 #import "chrome/browser/ui/cocoa/info_bubble_view.h" 18 #import "chrome/browser/ui/cocoa/info_bubble_view.h"
18 #import "chrome/browser/ui/cocoa/info_bubble_window.h" 19 #import "chrome/browser/ui/cocoa/info_bubble_window.h"
19 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" 20 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
20 #import "chrome/browser/ui/cocoa/website_settings/permission_selector_button.h" 21 #import "chrome/browser/ui/cocoa/website_settings/permission_selector_button.h"
21 #import "chrome/browser/ui/tab_dialogs.h" 22 #import "chrome/browser/ui/tab_dialogs.h"
22 #include "chrome/browser/ui/website_settings/permission_menu_model.h" 23 #include "chrome/browser/ui/website_settings/permission_menu_model.h"
23 #include "chrome/browser/ui/website_settings/website_settings_utils.h" 24 #include "chrome/browser/ui/website_settings/website_settings_utils.h"
24 #include "chrome/common/url_constants.h" 25 #include "chrome/common/url_constants.h"
25 #include "chrome/grit/chromium_strings.h" 26 #include "chrome/grit/chromium_strings.h"
26 #include "chrome/grit/generated_resources.h" 27 #include "chrome/grit/generated_resources.h"
27 #include "content/public/browser/cert_store.h" 28 #include "content/public/browser/cert_store.h"
28 #include "content/public/browser/page_navigator.h" 29 #include "content/public/browser/page_navigator.h"
29 #include "content/public/browser/ssl_host_state_delegate.h" 30 #include "content/public/browser/ssl_host_state_delegate.h"
30 #include "content/public/browser/user_metrics.h" 31 #include "content/public/browser/user_metrics.h"
31 #include "content/public/browser/web_contents.h" 32 #include "content/public/browser/web_contents.h"
32 #include "grit/theme_resources.h" 33 #include "grit/theme_resources.h"
33 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw eaker.h" 34 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw eaker.h"
34 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" 35 #import "ui/base/cocoa/controls/hyperlink_button_cell.h"
35 #import "ui/base/cocoa/flipped_view.h" 36 #import "ui/base/cocoa/flipped_view.h"
36 #include "ui/base/l10n/l10n_util.h" 37 #include "ui/base/l10n/l10n_util.h"
37 #include "ui/base/resource/resource_bundle.h" 38 #include "ui/base/resource/resource_bundle.h"
39 #import "ui/gfx/mac/coordinate_conversion.h"
38 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" 40 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
39 41
40 namespace { 42 namespace {
41 43
42 // The default width of the window, in view coordinates. It may be larger to 44 // The default width of the window, in view coordinates. It may be larger to
43 // fit the content. 45 // fit the content.
44 const CGFloat kDefaultWindowWidth = 310; 46 const CGFloat kDefaultWindowWidth = 310;
45 47
46 // Spacing in between sections. 48 // Spacing in between sections.
47 const CGFloat kVerticalSpacing = 10; 49 const CGFloat kVerticalSpacing = 10;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 // identity has been verified. 110 // identity has been verified.
109 NSColor* IdentityVerifiedTextColor() { 111 NSColor* IdentityVerifiedTextColor() {
110 // RGB components are specified using integer RGB [0-255] values for easy 112 // RGB components are specified using integer RGB [0-255] values for easy
111 // comparison to other platforms. 113 // comparison to other platforms.
112 return [NSColor colorWithCalibratedRed:0x07/255.0 114 return [NSColor colorWithCalibratedRed:0x07/255.0
113 green:0x95/255.0 115 green:0x95/255.0
114 blue:0 116 blue:0
115 alpha:1.0]; 117 alpha:1.0];
116 } 118 }
117 119
120 // Takes in the parent window, which should be a BrowserWindow, and gets the
121 // proper anchor point for the bubble. The returned point is in screen
122 // coordinates.
123 NSPoint AnchorPointForWindow(NSWindow* parent) {
124 BrowserWindowController* controller = [parent windowController];
125 NSPoint origin = NSZeroPoint;
126 if ([controller isKindOfClass:[BrowserWindowController class]]) {
127 LocationBarViewMac* location_bar = [controller locationBarBridge];
128 if (location_bar) {
129 NSPoint bubble_point = location_bar->GetPageInfoBubblePoint();
130 origin = [parent convertBaseToScreen:bubble_point];
131 }
132 }
133 return origin;
134 }
135
118 } // namespace 136 } // namespace
119 137
120 @interface WebsiteSettingsTabSegmentedCell : NSSegmentedCell { 138 @interface WebsiteSettingsTabSegmentedCell : NSSegmentedCell {
121 @private 139 @private
122 base::scoped_nsobject<NSImage> tabstripCenterImage_; 140 base::scoped_nsobject<NSImage> tabstripCenterImage_;
123 base::scoped_nsobject<NSImage> tabstripLeftImage_; 141 base::scoped_nsobject<NSImage> tabstripLeftImage_;
124 base::scoped_nsobject<NSImage> tabstripRightImage_; 142 base::scoped_nsobject<NSImage> tabstripRightImage_;
125 143
126 base::scoped_nsobject<NSImage> tabCenterImage_; 144 base::scoped_nsobject<NSImage> tabCenterImage_;
127 base::scoped_nsobject<NSImage> tabLeftImage_; 145 base::scoped_nsobject<NSImage> tabLeftImage_;
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 windowFrame.origin.y -= NSHeight(windowFrame) - 775 windowFrame.origin.y -= NSHeight(windowFrame) -
758 NSHeight([[self window] frame]); 776 NSHeight([[self window] frame]);
759 777
760 // Resize the window. Only animate if the window is visible, otherwise it 778 // Resize the window. Only animate if the window is visible, otherwise it
761 // could be "growing" while it's opening, looking awkward. 779 // could be "growing" while it's opening, looking awkward.
762 [[self window] setFrame:windowFrame 780 [[self window] setFrame:windowFrame
763 display:YES 781 display:YES
764 animate:[[self window] isVisible]]; 782 animate:[[self window] isVisible]];
765 783
766 // Adjust the anchor for the bubble. 784 // Adjust the anchor for the bubble.
767 NSPoint anchorPoint = 785 [self setAnchorPoint:AnchorPointForWindow([self parentWindow])];
768 [self anchorPointForWindowWithHeight:NSHeight(windowFrame)
769 parentWindow:[self parentWindow]];
770 [self setAnchorPoint:anchorPoint];
771 }
772
773 // Takes in the bubble's height and the parent window, which should be a
774 // BrowserWindow, and gets the proper anchor point for the bubble. The returned
775 // point is in screen coordinates.
776 - (NSPoint)anchorPointForWindowWithHeight:(CGFloat)bubbleHeight
777 parentWindow:(NSWindow*)parent {
778 BrowserWindowController* controller = [parent windowController];
779 NSPoint origin = NSZeroPoint;
780 if ([controller isKindOfClass:[BrowserWindowController class]]) {
781 LocationBarViewMac* locationBar = [controller locationBarBridge];
782 if (locationBar) {
783 NSPoint bubblePoint = locationBar->GetPageInfoBubblePoint();
784 origin = [parent convertBaseToScreen:bubblePoint];
785 }
786 }
787 return origin;
788 } 786 }
789 787
790 // Sets properties on the given |field| to act as the title or description 788 // Sets properties on the given |field| to act as the title or description
791 // labels in the bubble. 789 // labels in the bubble.
792 - (void)configureTextFieldAsLabel:(NSTextField*)textField { 790 - (void)configureTextFieldAsLabel:(NSTextField*)textField {
793 [textField setEditable:NO]; 791 [textField setEditable:NO];
794 [textField setSelectable:YES]; 792 [textField setSelectable:YES];
795 [textField setDrawsBackground:NO]; 793 [textField setDrawsBackground:NO];
796 [textField setBezeled:NO]; 794 [textField setBezeled:NO];
797 } 795 }
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
1199 void WebsiteSettingsUIBridge::set_bubble_controller( 1197 void WebsiteSettingsUIBridge::set_bubble_controller(
1200 WebsiteSettingsBubbleController* controller) { 1198 WebsiteSettingsBubbleController* controller) {
1201 bubble_controller_ = controller; 1199 bubble_controller_ = controller;
1202 } 1200 }
1203 1201
1204 void WebsiteSettingsUIBridge::Show(gfx::NativeWindow parent, 1202 void WebsiteSettingsUIBridge::Show(gfx::NativeWindow parent,
1205 Profile* profile, 1203 Profile* profile,
1206 content::WebContents* web_contents, 1204 content::WebContents* web_contents,
1207 const GURL& url, 1205 const GURL& url,
1208 const content::SSLStatus& ssl) { 1206 const content::SSLStatus& ssl) {
1207 if (chrome::ToolkitViewsDialogsEnabled()) {
1208 chrome::ShowWebsiteSettingsBubbleViewsAtPoint(
1209 gfx::ScreenPointFromNSPoint(AnchorPointForWindow(parent)), profile,
1210 web_contents, url, ssl);
1211 return;
1212 }
1213
1209 bool is_internal_page = InternalChromePage(url); 1214 bool is_internal_page = InternalChromePage(url);
1210 1215
1211 // Create the bridge. This will be owned by the bubble controller. 1216 // Create the bridge. This will be owned by the bubble controller.
1212 WebsiteSettingsUIBridge* bridge = new WebsiteSettingsUIBridge(); 1217 WebsiteSettingsUIBridge* bridge = new WebsiteSettingsUIBridge();
1213 1218
1214 // Create the bubble controller. It will dealloc itself when it closes. 1219 // Create the bubble controller. It will dealloc itself when it closes.
1215 WebsiteSettingsBubbleController* bubble_controller = 1220 WebsiteSettingsBubbleController* bubble_controller =
1216 [[WebsiteSettingsBubbleController alloc] 1221 [[WebsiteSettingsBubbleController alloc]
1217 initWithParentWindow:parent 1222 initWithParentWindow:parent
1218 websiteSettingsUIBridge:bridge 1223 websiteSettingsUIBridge:bridge
(...skipping 28 matching lines...) Expand all
1247 } 1252 }
1248 1253
1249 void WebsiteSettingsUIBridge::SetPermissionInfo( 1254 void WebsiteSettingsUIBridge::SetPermissionInfo(
1250 const PermissionInfoList& permission_info_list) { 1255 const PermissionInfoList& permission_info_list) {
1251 [bubble_controller_ setPermissionInfo:permission_info_list]; 1256 [bubble_controller_ setPermissionInfo:permission_info_list];
1252 } 1257 }
1253 1258
1254 void WebsiteSettingsUIBridge::SetSelectedTab(TabId tab_id) { 1259 void WebsiteSettingsUIBridge::SetSelectedTab(TabId tab_id) {
1255 [bubble_controller_ setSelectedTab:tab_id]; 1260 [bubble_controller_ setSelectedTab:tab_id];
1256 } 1261 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser_dialogs.h ('k') | chrome/browser/ui/views/browser_dialogs_views_mac.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698