| 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 "extension_installed_bubble_controller.h" | 5 #import "extension_installed_bubble_controller.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "base/mac_util.h" | 8 #include "base/mac_util.h" |
| 9 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
| 10 #include "chrome/browser/browser.h" | 10 #include "chrome/browser/browser.h" |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 [self close]; | 136 [self close]; |
| 137 } | 137 } |
| 138 | 138 |
| 139 // Extracted to a function here so that it can be overwritten for unit | 139 // Extracted to a function here so that it can be overwritten for unit |
| 140 // testing. | 140 // testing. |
| 141 - (void)removePageActionPreviewIfNecessary { | 141 - (void)removePageActionPreviewIfNecessary { |
| 142 DCHECK(extension_); | 142 DCHECK(extension_); |
| 143 if (!extension_->page_action() || pageActionRemoved_) | 143 if (!extension_->page_action() || pageActionRemoved_) |
| 144 return; | 144 return; |
| 145 pageActionRemoved_ = YES; | 145 pageActionRemoved_ = YES; |
| 146 BrowserWindowCocoa* window = static_cast<BrowserWindowCocoa*>( | |
| 147 browser_->window()); | |
| 148 LocationBarViewMac* locationBarView = static_cast<LocationBarViewMac*>( | |
| 149 [[window->cocoa_controller() toolbarController] locationBarBridge]); | |
| 150 | 146 |
| 147 BrowserWindowCocoa* window = |
| 148 static_cast<BrowserWindowCocoa*>(browser_->window()); |
| 149 LocationBarViewMac* locationBarView = |
| 150 [window->cocoa_controller() locationBarBridge]; |
| 151 locationBarView->SetPreviewEnabledPageAction(extension_->page_action(), | 151 locationBarView->SetPreviewEnabledPageAction(extension_->page_action(), |
| 152 false); // disables preview. | 152 false); // disables preview. |
| 153 } | 153 } |
| 154 | 154 |
| 155 // The extension installed bubble points at the browser action icon or the | 155 // The extension installed bubble points at the browser action icon or the |
| 156 // page action icon (shown as a preview), depending on the extension type. | 156 // page action icon (shown as a preview), depending on the extension type. |
| 157 // We need to calculate the location of these icons and the size of the | 157 // We need to calculate the location of these icons and the size of the |
| 158 // message itself (which varies with the title of the extension) in order | 158 // message itself (which varies with the title of the extension) in order |
| 159 // to figure out the origin point for the extension installed bubble. | 159 // to figure out the origin point for the extension installed bubble. |
| 160 // TODO(mirandac): add framework to easily test extension UI components! | 160 // TODO(mirandac): add framework to easily test extension UI components! |
| 161 - (NSPoint)calculateArrowPoint { | 161 - (NSPoint)calculateArrowPoint { |
| 162 BrowserWindowCocoa* window = | 162 BrowserWindowCocoa* window = |
| 163 static_cast<BrowserWindowCocoa*>(browser_->window()); | 163 static_cast<BrowserWindowCocoa*>(browser_->window()); |
| 164 NSPoint arrowPoint = NSZeroPoint; | 164 NSPoint arrowPoint = NSZeroPoint; |
| 165 | 165 |
| 166 switch(type_) { | 166 switch(type_) { |
| 167 case extension_installed_bubble::kBrowserAction: { | 167 case extension_installed_bubble::kBrowserAction: { |
| 168 BrowserActionsController* controller = | 168 BrowserActionsController* controller = |
| 169 [[window->cocoa_controller() toolbarController] | 169 [[window->cocoa_controller() toolbarController] |
| 170 browserActionsController]; | 170 browserActionsController]; |
| 171 arrowPoint = [controller popupPointForBrowserAction:extension_]; | 171 arrowPoint = [controller popupPointForBrowserAction:extension_]; |
| 172 break; | 172 break; |
| 173 } | 173 } |
| 174 case extension_installed_bubble::kPageAction: { | 174 case extension_installed_bubble::kPageAction: { |
| 175 LocationBarViewMac* locationBarView = | 175 LocationBarViewMac* locationBarView = |
| 176 static_cast<LocationBarViewMac*>( | 176 [window->cocoa_controller() locationBarBridge]; |
| 177 [[window->cocoa_controller() toolbarController] | 177 |
| 178 locationBarBridge]); | |
| 179 // Tell the location bar to show a preview of the page action icon, which | 178 // Tell the location bar to show a preview of the page action icon, which |
| 180 // would ordinarily only be displayed on a page of the appropriate type. | 179 // would ordinarily only be displayed on a page of the appropriate type. |
| 181 // We remove this preview when the extension installed bubble closes. | 180 // We remove this preview when the extension installed bubble closes. |
| 182 locationBarView->SetPreviewEnabledPageAction(extension_->page_action(), | 181 locationBarView->SetPreviewEnabledPageAction(extension_->page_action(), |
| 183 true); | 182 true); |
| 184 | 183 |
| 185 // Find the center of the bottom of the page action icon. | 184 // Find the center of the bottom of the page action icon. |
| 186 const NSRect frame = | 185 arrowPoint = |
| 187 locationBarView->GetPageActionFrame(extension_->page_action()); | 186 locationBarView->GetPageActionBubblePoint(extension_->page_action()); |
| 188 arrowPoint = NSMakePoint(NSMidX(frame), NSMinY(frame)); | |
| 189 break; | 187 break; |
| 190 } | 188 } |
| 191 default: { | 189 default: { |
| 192 NOTREACHED() << "Generic extension type not allowed in install bubble."; | 190 NOTREACHED() << "Generic extension type not allowed in install bubble."; |
| 193 } | 191 } |
| 194 } | 192 } |
| 195 return arrowPoint; | 193 return arrowPoint; |
| 196 } | 194 } |
| 197 | 195 |
| 198 // We want this to be a child of a browser window. addChildWindow: | 196 // We want this to be a child of a browser window. addChildWindow: |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 | 322 |
| 325 - (NSRect)getPageActionInfoMsgFrame { | 323 - (NSRect)getPageActionInfoMsgFrame { |
| 326 return [pageActionInfoMsg_ frame]; | 324 return [pageActionInfoMsg_ frame]; |
| 327 } | 325 } |
| 328 | 326 |
| 329 - (NSRect)getExtensionInstalledInfoMsgFrame { | 327 - (NSRect)getExtensionInstalledInfoMsgFrame { |
| 330 return [extensionInstalledInfoMsg_ frame]; | 328 return [extensionInstalledInfoMsg_ frame]; |
| 331 } | 329 } |
| 332 | 330 |
| 333 @end | 331 @end |
| OLD | NEW |