1 // Copyright 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "chrome/browser/ui/cocoa/location_bar/generated_credit_card_decoration.h" 6 7 #include "chrome/browser/ui/autofill/generated_credit_card_bubble_controller.h" 8 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" 9 10 using autofill::GeneratedCreditCardBubbleController; 11 12 GeneratedCreditCardDecoration::GeneratedCreditCardDecoration( 13 LocationBarViewMac* owner) : owner_(owner) { 14 } 15 16 GeneratedCreditCardDecoration::~GeneratedCreditCardDecoration() { 17 } 18 19 void GeneratedCreditCardDecoration::Update() { 20 GeneratedCreditCardBubbleController* controller = GetController(); 21 if (controller && !controller->AnchorIcon().IsEmpty()) { 22 SetVisible(true); 23 SetImage(controller->AnchorIcon().AsNSImage()); 24 } else { 25 SetVisible(false); 26 SetImage(nil); 27 } 28 } 29 30 NSPoint GeneratedCreditCardDecoration::GetBubblePointInFrame(NSRect frame) { 31 const NSRect draw_frame = GetDrawRectInFrame(frame); 32 return NSMakePoint(NSMidX(draw_frame), NSMaxY(draw_frame)); 33 } 34 35 bool GeneratedCreditCardDecoration::AcceptsMousePress() { 36 GeneratedCreditCardBubbleController* controller = GetController(); 37 return controller && !controller->IsHiding(); 38 } 39 40 bool GeneratedCreditCardDecoration::OnMousePressed(NSRect frame, 41 NSPoint location) { 42 GeneratedCreditCardBubbleController* controller = GetController(); 43 if (!controller) 44 return false; 45 46 controller->OnAnchorClicked(); 47 return true; 48 } 49 50 GeneratedCreditCardBubbleController* GeneratedCreditCardDecoration:: 51 GetController() const { 52 content::WebContents* wc = owner_->GetWebContents(); 53 if (!wc || owner_->GetToolbarModel()->input_in_progress()) { 54 return NULL; 55 } 56 57 GeneratedCreditCardBubbleController* controller = 58 GeneratedCreditCardBubbleController::FromWebContents(wc); 59 return controller; 60 } 61 62