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/page_info/page_info_bubble_controller.h" | 5 #import "chrome/browser/ui/cocoa/page_info/page_info_bubble_controller.h" |
6 | 6 |
7 #import <AppKit/AppKit.h> | 7 #import <AppKit/AppKit.h> |
8 | 8 |
9 #include <cmath> | 9 #include <cmath> |
10 | 10 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 | 108 |
109 // Padding between the window frame and content for the internal page bubble. | 109 // Padding between the window frame and content for the internal page bubble. |
110 const CGFloat kInternalPageFramePadding = 10; | 110 const CGFloat kInternalPageFramePadding = 10; |
111 | 111 |
112 // Spacing between the image and text for internal pages. | 112 // Spacing between the image and text for internal pages. |
113 const CGFloat kInternalPageImageSpacing = 10; | 113 const CGFloat kInternalPageImageSpacing = 10; |
114 | 114 |
115 // ----------------------------------------------------------------------------- | 115 // ----------------------------------------------------------------------------- |
116 | 116 |
117 // NOTE: This assumes that there will never be more than one page info | 117 // NOTE: This assumes that there will never be more than one page info |
118 // popup shown, and that the one that is shown is associated with the current | 118 // bubble shown, and that the one that is shown is associated with the current |
119 // window. This matches the behaviour in views: see PageInfoPopupView. | 119 // window. This matches the behaviour in Views: see PageInfoBubbleView. |
120 bool g_is_popup_showing = false; | 120 bool g_is_bubble_showing = false; |
121 | 121 |
122 // Takes in the parent window, which should be a BrowserWindow, and gets the | 122 // Takes in the parent window, which should be a BrowserWindow, and gets the |
123 // proper anchor point for the bubble. The returned point is in screen | 123 // proper anchor point for the bubble. The returned point is in screen |
124 // coordinates. | 124 // coordinates. |
125 NSPoint AnchorPointForWindow(NSWindow* parent) { | 125 NSPoint AnchorPointForWindow(NSWindow* parent) { |
126 BrowserWindowController* controller = [parent windowController]; | 126 BrowserWindowController* controller = [parent windowController]; |
127 NSPoint origin = NSZeroPoint; | 127 NSPoint origin = NSZeroPoint; |
128 if ([controller isKindOfClass:[BrowserWindowController class]]) { | 128 if ([controller isKindOfClass:[BrowserWindowController class]]) { |
129 LocationBarViewMac* location_bar = [controller locationBarBridge]; | 129 LocationBarViewMac* location_bar = [controller locationBarBridge]; |
130 if (location_bar) { | 130 if (location_bar) { |
(...skipping 1007 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1138 controlOrigin.y)]; | 1138 controlOrigin.y)]; |
1139 [self performLayout]; | 1139 [self performLayout]; |
1140 } | 1140 } |
1141 | 1141 |
1142 @end | 1142 @end |
1143 | 1143 |
1144 PageInfoUIBridge::PageInfoUIBridge(content::WebContents* web_contents) | 1144 PageInfoUIBridge::PageInfoUIBridge(content::WebContents* web_contents) |
1145 : content::WebContentsObserver(web_contents), | 1145 : content::WebContentsObserver(web_contents), |
1146 web_contents_(web_contents), | 1146 web_contents_(web_contents), |
1147 bubble_controller_(nil) { | 1147 bubble_controller_(nil) { |
1148 DCHECK(!g_is_popup_showing); | 1148 DCHECK(!g_is_bubble_showing); |
1149 g_is_popup_showing = true; | 1149 g_is_bubble_showing = true; |
1150 } | 1150 } |
1151 | 1151 |
1152 PageInfoUIBridge::~PageInfoUIBridge() { | 1152 PageInfoUIBridge::~PageInfoUIBridge() { |
1153 DCHECK(g_is_popup_showing); | 1153 DCHECK(g_is_bubble_showing); |
1154 g_is_popup_showing = false; | 1154 g_is_bubble_showing = false; |
1155 } | 1155 } |
1156 | 1156 |
1157 void PageInfoUIBridge::set_bubble_controller( | 1157 void PageInfoUIBridge::set_bubble_controller( |
1158 PageInfoBubbleController* controller) { | 1158 PageInfoBubbleController* controller) { |
1159 bubble_controller_ = controller; | 1159 bubble_controller_ = controller; |
1160 } | 1160 } |
1161 | 1161 |
1162 void PageInfoUIBridge::Show(gfx::NativeWindow parent, | 1162 void PageInfoUIBridge::Show(gfx::NativeWindow parent, |
1163 Profile* profile, | 1163 Profile* profile, |
1164 content::WebContents* web_contents, | 1164 content::WebContents* web_contents, |
1165 const GURL& virtual_url, | 1165 const GURL& virtual_url, |
1166 const security_state::SecurityInfo& security_info) { | 1166 const security_state::SecurityInfo& security_info) { |
1167 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) { | 1167 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) { |
1168 chrome::ShowPageInfoBubbleViewsAtPoint( | 1168 chrome::ShowPageInfoBubbleViewsAtPoint( |
1169 gfx::ScreenPointFromNSPoint(AnchorPointForWindow(parent)), profile, | 1169 gfx::ScreenPointFromNSPoint(AnchorPointForWindow(parent)), profile, |
1170 web_contents, virtual_url, security_info); | 1170 web_contents, virtual_url, security_info); |
1171 return; | 1171 return; |
1172 } | 1172 } |
1173 | 1173 |
1174 // Don't show the popup if it's already being shown. Since this method is | 1174 // Don't show the bubble if it's already being shown. Since this method is |
1175 // called each time the location icon is clicked, each click toggles the popup | 1175 // called each time the location icon is clicked, each click toggles the |
1176 // in and out. | 1176 // bubble in and out. |
1177 if (g_is_popup_showing) | 1177 if (g_is_bubble_showing) |
1178 return; | 1178 return; |
1179 | 1179 |
1180 // Create the bridge. This will be owned by the bubble controller. | 1180 // Create the bridge. This will be owned by the bubble controller. |
1181 PageInfoUIBridge* bridge = new PageInfoUIBridge(web_contents); | 1181 PageInfoUIBridge* bridge = new PageInfoUIBridge(web_contents); |
1182 | 1182 |
1183 // Create the bubble controller. It will dealloc itself when it closes, | 1183 // Create the bubble controller. It will dealloc itself when it closes, |
1184 // resetting |g_is_popup_showing|. | 1184 // resetting |g_is_bubble_showing|. |
1185 PageInfoBubbleController* bubble_controller = | 1185 PageInfoBubbleController* bubble_controller = |
1186 [[PageInfoBubbleController alloc] initWithParentWindow:parent | 1186 [[PageInfoBubbleController alloc] initWithParentWindow:parent |
1187 pageInfoUIBridge:bridge | 1187 pageInfoUIBridge:bridge |
1188 webContents:web_contents | 1188 webContents:web_contents |
1189 url:virtual_url]; | 1189 url:virtual_url]; |
1190 | 1190 |
1191 if (!IsInternalURL(virtual_url)) { | 1191 if (!IsInternalURL(virtual_url)) { |
1192 // Initialize the presenter, which holds the model and controls the UI. | 1192 // Initialize the presenter, which holds the model and controls the UI. |
1193 // This is also owned by the bubble controller. | 1193 // This is also owned by the bubble controller. |
1194 PageInfo* presenter = | 1194 PageInfo* presenter = |
(...skipping 21 matching lines...) Expand all Loading... |
1216 void PageInfoUIBridge::SetCookieInfo(const CookieInfoList& cookie_info_list) { | 1216 void PageInfoUIBridge::SetCookieInfo(const CookieInfoList& cookie_info_list) { |
1217 [bubble_controller_ setCookieInfo:cookie_info_list]; | 1217 [bubble_controller_ setCookieInfo:cookie_info_list]; |
1218 } | 1218 } |
1219 | 1219 |
1220 void PageInfoUIBridge::SetPermissionInfo( | 1220 void PageInfoUIBridge::SetPermissionInfo( |
1221 const PermissionInfoList& permission_info_list, | 1221 const PermissionInfoList& permission_info_list, |
1222 ChosenObjectInfoList chosen_object_info_list) { | 1222 ChosenObjectInfoList chosen_object_info_list) { |
1223 [bubble_controller_ setPermissionInfo:permission_info_list | 1223 [bubble_controller_ setPermissionInfo:permission_info_list |
1224 andChosenObjects:std::move(chosen_object_info_list)]; | 1224 andChosenObjects:std::move(chosen_object_info_list)]; |
1225 } | 1225 } |
OLD | NEW |