| 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/location_bar/location_bar_view_mac.h" | 5 #import "chrome/browser/cocoa/location_bar/location_bar_view_mac.h" |
| 6 | 6 |
| 7 #include "app/l10n_util_mac.h" | 7 #include "app/l10n_util_mac.h" |
| 8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
| 9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
| 10 #include "base/nsimage_cache_mac.h" | 10 #include "base/nsimage_cache_mac.h" |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 | 277 |
| 278 void LocationBarViewMac::SetPreviewEnabledPageAction( | 278 void LocationBarViewMac::SetPreviewEnabledPageAction( |
| 279 ExtensionAction* page_action, bool preview_enabled) { | 279 ExtensionAction* page_action, bool preview_enabled) { |
| 280 DCHECK(page_action); | 280 DCHECK(page_action); |
| 281 TabContents* contents = GetTabContents(); | 281 TabContents* contents = GetTabContents(); |
| 282 if (!contents) | 282 if (!contents) |
| 283 return; | 283 return; |
| 284 page_action_views_.RefreshViews(); | 284 page_action_views_.RefreshViews(); |
| 285 [field_ setNeedsDisplay:YES]; | 285 [field_ setNeedsDisplay:YES]; |
| 286 | 286 |
| 287 LocationBarViewMac::PageActionImageView* page_action_image_view = | 287 LocationBarViewMac::PageActionImageView* page_action_image_view = NULL; |
| 288 GetPageActionImageView(page_action); | 288 for (size_t i = 0; i < page_action_views_.Count(); ++i) { |
| 289 if (page_action_views_.ViewAt(i)->page_action() == page_action) |
| 290 page_action_image_view = page_action_views_.ViewAt(i); |
| 291 } |
| 289 DCHECK(page_action_image_view); | 292 DCHECK(page_action_image_view); |
| 290 if (!page_action_image_view) | 293 if (!page_action_image_view) |
| 291 return; | 294 return; |
| 292 | 295 |
| 293 page_action_image_view->set_preview_enabled(preview_enabled); | 296 page_action_image_view->set_preview_enabled(preview_enabled); |
| 294 page_action_image_view->UpdateVisibility(contents, | 297 page_action_image_view->UpdateVisibility(contents, |
| 295 GURL(WideToUTF8(toolbar_model_->GetText()))); | 298 GURL(WideToUTF8(toolbar_model_->GetText()))); |
| 296 } | 299 } |
| 297 | 300 |
| 298 NSRect LocationBarViewMac::GetPageActionFrame(ExtensionAction* page_action) { | 301 NSPoint LocationBarViewMac::GetPageActionBubblePoint( |
| 299 const size_t index = GetPageActionIndex(page_action); | 302 ExtensionAction* page_action) { |
| 303 DCHECK(page_action); |
| 304 size_t index = 0; |
| 305 for (; index < page_action_views_.Count(); ++index) { |
| 306 if (page_action_views_.ViewAt(index)->page_action() == page_action) |
| 307 break; |
| 308 } |
| 309 DCHECK_LT(index, page_action_views_.Count()); |
| 310 if (index == page_action_views_.Count()) |
| 311 return NSZeroPoint; |
| 312 |
| 300 AutocompleteTextFieldCell* cell = [field_ autocompleteTextFieldCell]; | 313 AutocompleteTextFieldCell* cell = [field_ autocompleteTextFieldCell]; |
| 301 const NSRect iconRect = | 314 NSRect frame = [cell pageActionFrameForIndex:index inFrame:[field_ bounds]]; |
| 302 [cell pageActionFrameForIndex:index inFrame:[field_ bounds]]; | 315 if (!NSIsEmptyRect(frame)) { |
| 303 return [field_ convertRect:iconRect toView:nil]; | 316 frame = [field_ convertRect:frame toView:nil]; |
| 304 } | 317 return NSMakePoint(NSMidX(frame), NSMinY(frame)); |
| 318 } |
| 305 | 319 |
| 306 size_t LocationBarViewMac::GetPageActionIndex(ExtensionAction* page_action) { | |
| 307 DCHECK(page_action); | |
| 308 for (size_t i = 0; i < page_action_views_.Count(); ++i) { | |
| 309 if (page_action_views_.ViewAt(i)->page_action() == page_action) | |
| 310 return i; | |
| 311 } | |
| 312 NOTREACHED(); | 320 NOTREACHED(); |
| 313 return 0; | 321 return NSZeroPoint; |
| 314 } | |
| 315 | |
| 316 LocationBarViewMac::PageActionImageView* | |
| 317 LocationBarViewMac::GetPageActionImageView(ExtensionAction* page_action) { | |
| 318 DCHECK(page_action); | |
| 319 for (size_t i = 0; i < page_action_views_.Count(); ++i) { | |
| 320 if (page_action_views_.ViewAt(i)->page_action() == page_action) | |
| 321 return page_action_views_.ViewAt(i); | |
| 322 } | |
| 323 NOTREACHED(); | |
| 324 return NULL; | |
| 325 } | 322 } |
| 326 | 323 |
| 327 ExtensionAction* LocationBarViewMac::GetPageAction(size_t index) { | 324 ExtensionAction* LocationBarViewMac::GetPageAction(size_t index) { |
| 328 if (index < page_action_views_.Count()) | 325 if (index < page_action_views_.Count()) |
| 329 return page_action_views_.ViewAt(index)->page_action(); | 326 return page_action_views_.ViewAt(index)->page_action(); |
| 330 NOTREACHED(); | 327 NOTREACHED(); |
| 331 return NULL; | 328 return NULL; |
| 332 } | 329 } |
| 333 | 330 |
| 334 ExtensionAction* LocationBarViewMac::GetVisiblePageAction(size_t index) { | 331 ExtensionAction* LocationBarViewMac::GetVisiblePageAction(size_t index) { |
| (...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 931 | 928 |
| 932 // These need to change anytime the layout changes. | 929 // These need to change anytime the layout changes. |
| 933 // TODO(shess): Anytime the field editor might have changed, the | 930 // TODO(shess): Anytime the field editor might have changed, the |
| 934 // cursor rects almost certainly should have changed. The tooltips | 931 // cursor rects almost certainly should have changed. The tooltips |
| 935 // might change even when the rects don't change. | 932 // might change even when the rects don't change. |
| 936 [field_ resetFieldEditorFrameIfNeeded]; | 933 [field_ resetFieldEditorFrameIfNeeded]; |
| 937 [field_ updateCursorAndToolTipRects]; | 934 [field_ updateCursorAndToolTipRects]; |
| 938 | 935 |
| 939 [field_ setNeedsDisplay:YES]; | 936 [field_ setNeedsDisplay:YES]; |
| 940 } | 937 } |
| OLD | NEW |