| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/cocoa/extensions/extension_action_context_menu.h" | 5 #import "chrome/browser/cocoa/extensions/extension_action_context_menu.h" |
| 6 | 6 |
| 7 #include "app/l10n_util_mac.h" | 7 #include "app/l10n_util_mac.h" |
| 8 #include "base/sys_string_conversions.h" | 8 #include "base/sys_string_conversions.h" |
| 9 #include "base/task.h" | 9 #include "base/task.h" |
| 10 #include "chrome/browser/browser_list.h" | 10 #include "chrome/browser/browser_list.h" |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 case kExtensionContextUninstall: { | 228 case kExtensionContextUninstall: { |
| 229 uninstaller_.reset(new AsyncUninstaller(extension_, profile_)); | 229 uninstaller_.reset(new AsyncUninstaller(extension_, profile_)); |
| 230 break; | 230 break; |
| 231 } | 231 } |
| 232 case kExtensionContextManage: { | 232 case kExtensionContextManage: { |
| 233 browser->OpenURL(GURL(chrome::kChromeUIExtensionsURL), GURL(), | 233 browser->OpenURL(GURL(chrome::kChromeUIExtensionsURL), GURL(), |
| 234 NEW_FOREGROUND_TAB, PageTransition::LINK); | 234 NEW_FOREGROUND_TAB, PageTransition::LINK); |
| 235 break; | 235 break; |
| 236 } | 236 } |
| 237 case kExtensionContextInspect: { | 237 case kExtensionContextInspect: { |
| 238 NSPoint popupPoint; | |
| 239 BrowserWindowCocoa* window = | 238 BrowserWindowCocoa* window = |
| 240 static_cast<BrowserWindowCocoa*>(browser->window()); | 239 static_cast<BrowserWindowCocoa*>(browser->window()); |
| 241 LocationBar* locationBar = window->GetLocationBar(); | 240 ToolbarController* toolbarController = |
| 242 AutocompleteTextField* field = | 241 [window->cocoa_controller() toolbarController]; |
| 243 (AutocompleteTextField*)locationBar->location_entry()-> | 242 LocationBarViewMac* locationBarView = |
| 244 GetNativeView(); | 243 [toolbarController locationBarBridge]; |
| 245 AutocompleteTextFieldCell* fieldCell = [field autocompleteTextFieldCell]; | 244 NSPoint popupPoint = locationBarView->GetPageActionBubblePoint(action_); |
| 246 DCHECK(action_); | 245 |
| 247 NSRect popupRect = | 246 // If there was no matching page action, it was a browser action. |
| 248 [fieldCell pageActionFrameForExtensionAction:action_ | 247 if (NSEqualPoints(popupPoint, NSZeroPoint)) { |
| 249 inFrame:[field bounds]]; | |
| 250 if (!NSEqualRects(popupRect, NSZeroRect)) { | |
| 251 popupRect = [[field superview] convertRect:popupRect toView:nil]; | |
| 252 popupPoint = popupRect.origin; | |
| 253 NSRect fieldFrame = [field bounds]; | |
| 254 fieldFrame = [field convertRect:fieldFrame toView:nil]; | |
| 255 popupPoint.x += fieldFrame.origin.x + popupRect.size.width / 2; | |
| 256 } else { | |
| 257 ToolbarController* toolbarController = | |
| 258 [window->cocoa_controller() toolbarController]; | |
| 259 BrowserActionsController* controller = | 248 BrowserActionsController* controller = |
| 260 [toolbarController browserActionsController]; | 249 [toolbarController browserActionsController]; |
| 261 popupPoint = [controller popupPointForBrowserAction:extension_]; | 250 popupPoint = [controller popupPointForBrowserAction:extension_]; |
| 262 } | 251 } |
| 252 |
| 263 int tabId = CurrentTabId(); | 253 int tabId = CurrentTabId(); |
| 264 GURL url = action_->GetPopupUrl(tabId); | 254 GURL url = action_->GetPopupUrl(tabId); |
| 265 DCHECK(url.is_valid()); | 255 DCHECK(url.is_valid()); |
| 266 [ExtensionPopupController showURL:url | 256 [ExtensionPopupController showURL:url |
| 267 inBrowser:BrowserList::GetLastActive() | 257 inBrowser:BrowserList::GetLastActive() |
| 268 anchoredAt:popupPoint | 258 anchoredAt:popupPoint |
| 269 arrowLocation:info_bubble::kTopRight | 259 arrowLocation:info_bubble::kTopRight |
| 270 devMode:YES]; | 260 devMode:YES]; |
| 271 break; | 261 break; |
| 272 } | 262 } |
| 273 default: | 263 default: |
| 274 NOTREACHED(); | 264 NOTREACHED(); |
| 275 break; | 265 break; |
| 276 } | 266 } |
| 277 } | 267 } |
| 278 | 268 |
| 279 - (BOOL)validateMenuItem:(NSMenuItem*)menuItem { | 269 - (BOOL)validateMenuItem:(NSMenuItem*)menuItem { |
| 280 if([menuItem isEqualTo:inspectorItem_.get()]) { | 270 if([menuItem isEqualTo:inspectorItem_.get()]) { |
| 281 return action_ && action_->HasPopup(CurrentTabId()); | 271 return action_ && action_->HasPopup(CurrentTabId()); |
| 282 } | 272 } |
| 283 return YES; | 273 return YES; |
| 284 } | 274 } |
| 285 | 275 |
| 286 @end | 276 @end |
| OLD | NEW |