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

Side by Side Diff: chrome/browser/cocoa/location_bar_view_mac.mm

Issue 500138: [Mac] Implements popups for Page Actions, plus fixes a leak within the Browse... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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_view_mac.h" 5 #import "chrome/browser/cocoa/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/stl_util-inl.h" 9 #include "base/stl_util-inl.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "base/sys_string_conversions.h" 11 #include "base/sys_string_conversions.h"
12 #include "chrome/app/chrome_dll_resource.h" 12 #include "chrome/app/chrome_dll_resource.h"
13 #include "chrome/browser/alternate_nav_url_fetcher.h" 13 #include "chrome/browser/alternate_nav_url_fetcher.h"
14 #import "chrome/browser/app_controller_mac.h" 14 #import "chrome/browser/app_controller_mac.h"
15 #import "chrome/browser/autocomplete/autocomplete_edit_view_mac.h" 15 #import "chrome/browser/autocomplete/autocomplete_edit_view_mac.h"
16 #include "chrome/browser/browser_list.h" 16 #include "chrome/browser/browser_list.h"
17 #import "chrome/browser/cocoa/autocomplete_text_field.h" 17 #import "chrome/browser/cocoa/autocomplete_text_field.h"
18 #import "chrome/browser/cocoa/autocomplete_text_field_cell.h" 18 #import "chrome/browser/cocoa/autocomplete_text_field_cell.h"
19 #include "chrome/browser/cocoa/event_utils.h" 19 #include "chrome/browser/cocoa/event_utils.h"
20 #import "chrome/browser/cocoa/extensions/extension_popup_controller.h"
20 #include "chrome/browser/command_updater.h" 21 #include "chrome/browser/command_updater.h"
21 #include "chrome/browser/extensions/extension_browser_event_router.h" 22 #include "chrome/browser/extensions/extension_browser_event_router.h"
22 #include "chrome/browser/extensions/extensions_service.h" 23 #include "chrome/browser/extensions/extensions_service.h"
23 #include "chrome/browser/extensions/extension_tabs_module.h" 24 #include "chrome/browser/extensions/extension_tabs_module.h"
24 #include "chrome/browser/profile.h" 25 #include "chrome/browser/profile.h"
25 #include "chrome/browser/search_engines/template_url.h" 26 #include "chrome/browser/search_engines/template_url.h"
26 #include "chrome/browser/search_engines/template_url_model.h" 27 #include "chrome/browser/search_engines/template_url_model.h"
27 #include "chrome/browser/tab_contents/navigation_entry.h" 28 #include "chrome/browser/tab_contents/navigation_entry.h"
28 #include "chrome/browser/tab_contents/tab_contents.h" 29 #include "chrome/browser/tab_contents/tab_contents.h"
29 #include "chrome/common/extensions/extension.h" 30 #include "chrome/common/extensions/extension.h"
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 512
512 LocationBarViewMac::PageActionImageView::~PageActionImageView() { 513 LocationBarViewMac::PageActionImageView::~PageActionImageView() {
513 if (tracker_) 514 if (tracker_)
514 tracker_->StopTrackingImageLoad(); 515 tracker_->StopTrackingImageLoad();
515 } 516 }
516 517
517 // Overridden from LocationBarImageView. Either notify listeners or show a 518 // Overridden from LocationBarImageView. Either notify listeners or show a
518 // popup depending on the Page Action. 519 // popup depending on the Page Action.
519 bool LocationBarViewMac::PageActionImageView::OnMousePressed(NSRect bounds) { 520 bool LocationBarViewMac::PageActionImageView::OnMousePressed(NSRect bounds) {
520 if (page_action_->has_popup()) { 521 if (page_action_->has_popup()) {
521 NOTIMPLEMENTED(); 522 AutocompleteTextField* textField = owner_->GetAutocompleteTextField();
523 NSWindow* window = [textField window];
524 NSRect relativeBounds = [[window contentView] convertRect:bounds
525 fromView:textField];
526 NSPoint arrowPoint = [window convertBaseToScreen:NSMakePoint(
527 NSMinX(relativeBounds),
528 NSMinY(relativeBounds))];
529
530 // Adjust the anchor point to be at the center of the page action icon.
531 arrowPoint.x += [GetImage() size].width / 2;
Mark Mentovai 2009/12/18 21:37:25 NSWidth([GetImage() size]) / 2 ?
532
533 popupController_ =
534 [ExtensionPopupController showURL:page_action_->popup_url()
535 inBrowser:BrowserList::GetLastActive()
536 anchoredAt:arrowPoint
537 arrowLocation:kTopRight];
522 } else { 538 } else {
523 ExtensionBrowserEventRouter::GetInstance()->PageActionExecuted( 539 ExtensionBrowserEventRouter::GetInstance()->PageActionExecuted(
524 profile_, page_action_->extension_id(), page_action_->id(), 540 profile_, page_action_->extension_id(), page_action_->id(),
525 current_tab_id_, current_url_.spec(), 541 current_tab_id_, current_url_.spec(),
526 1); // TODO(pamg): Add support for middle and right buttons. 542 1); // TODO(pamg): Add support for middle and right buttons.
527 } 543 }
528 return true; 544 return true;
529 } 545 }
530 546
531 void LocationBarViewMac::PageActionImageView::OnImageLoaded(SkBitmap* image, 547 void LocationBarViewMac::PageActionImageView::OnImageLoaded(SkBitmap* image,
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 SetVisible(visible); 616 SetVisible(visible);
601 } 617 }
602 618
603 void LocationBarViewMac::PageActionImageView::Observe( 619 void LocationBarViewMac::PageActionImageView::Observe(
604 NotificationType type, 620 NotificationType type,
605 const NotificationSource& source, 621 const NotificationSource& source,
606 const NotificationDetails& details) { 622 const NotificationDetails& details) {
607 switch (type.value) { 623 switch (type.value) {
608 case NotificationType::EXTENSION_HOST_VIEW_SHOULD_CLOSE: 624 case NotificationType::EXTENSION_HOST_VIEW_SHOULD_CLOSE:
609 // If we aren't the host of the popup, then disregard the notification. 625 // If we aren't the host of the popup, then disregard the notification.
610 //if (!popup_ || Details<ExtensionHost>(popup_->host()) != details) 626 if (popupController_ &&
611 // return; 627 Details<ExtensionHost>([popupController_ host]) == details) {
612 628 HidePopup();
613 //HidePopup(); 629 }
614 NOTIMPLEMENTED();
615 break; 630 break;
616 default: 631 default:
617 NOTREACHED() << "Unexpected notification"; 632 NOTREACHED() << "Unexpected notification";
618 break; 633 break;
619 } 634 }
620 } 635 }
621 636
637 void LocationBarViewMac::PageActionImageView::HidePopup() {
638 [popupController_ close];
639 popupController_ = nil;
640 }
641
622 // PageActionViewList----------------------------------------------------------- 642 // PageActionViewList-----------------------------------------------------------
623 643
624 void LocationBarViewMac::PageActionViewList::DeleteAll() { 644 void LocationBarViewMac::PageActionViewList::DeleteAll() {
625 if (!views_.empty()) { 645 if (!views_.empty()) {
626 STLDeleteContainerPointers(views_.begin(), views_.end()); 646 STLDeleteContainerPointers(views_.begin(), views_.end());
627 views_.clear(); 647 views_.clear();
628 } 648 }
629 } 649 }
630 650
631 void LocationBarViewMac::PageActionViewList::RefreshViews() { 651 void LocationBarViewMac::PageActionViewList::RefreshViews() {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 if (views_[i]->IsVisible()) 722 if (views_[i]->IsVisible())
703 ++result; 723 ++result;
704 } 724 }
705 return result; 725 return result;
706 } 726 }
707 727
708 void LocationBarViewMac::PageActionViewList::OnMousePressed(NSRect iconFrame, 728 void LocationBarViewMac::PageActionViewList::OnMousePressed(NSRect iconFrame,
709 size_t index) { 729 size_t index) {
710 ViewAt(index)->OnMousePressed(iconFrame); 730 ViewAt(index)->OnMousePressed(iconFrame);
711 } 731 }
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/location_bar_view_mac.h ('k') | chrome/browser/extensions/extension_browser_event_router.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698