Index: chrome/browser/ui/cocoa/location_bar/generated_credit_card_decoration.mm |
diff --git a/chrome/browser/ui/cocoa/location_bar/generated_credit_card_decoration.mm b/chrome/browser/ui/cocoa/location_bar/generated_credit_card_decoration.mm |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6b3468b728cb6c30c064066ad33836a8b45b6b6f |
--- /dev/null |
+++ b/chrome/browser/ui/cocoa/location_bar/generated_credit_card_decoration.mm |
@@ -0,0 +1,74 @@ |
+// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/ui/cocoa/location_bar/generated_credit_card_decoration.h" |
+ |
+#include "chrome/browser/ui/autofill/generated_credit_card_bubble_controller.h" |
+#import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
+#include "grit/theme_resources.h" |
+ |
+GeneratedCreditCardDecoration::GeneratedCreditCardDecoration( |
+ LocationBarViewMac* owner) : owner_(owner) { |
+} |
+ |
+GeneratedCreditCardDecoration::~GeneratedCreditCardDecoration() { |
+} |
+ |
+void GeneratedCreditCardDecoration::Update() { |
+ autofill::GeneratedCreditCardBubbleController* controller = GetController(); |
+ if (controller && !controller->AnchorIcon().IsEmpty()) { |
+ SetVisible(true); |
+ SetImage(controller->AnchorIcon().AsNSImage()); |
+ } else { |
+ SetVisible(false); |
+ SetImage(NULL); |
Scott Hess - ex-Googler
2013/10/31 20:23:19
nil rather than NULL for objc objects.
groby-ooo-7-16
2013/10/31 22:55:47
Done.
|
+ } |
+} |
+ |
+NSPoint GeneratedCreditCardDecoration::GetBubblePointInFrame(NSRect frame) { |
+ const NSRect draw_frame = GetDrawRectInFrame(frame); |
+ return NSMakePoint(NSMidX(draw_frame), |
+ NSMaxY(draw_frame)); |
Scott Hess - ex-Googler
2013/10/31 20:23:19
Alignment, and probably can have NSMakePoint() as
groby-ooo-7-16
2013/10/31 22:55:47
Done.
|
+} |
+ |
+bool GeneratedCreditCardDecoration::AcceptsMousePress() { |
+ autofill::GeneratedCreditCardBubbleController* controller = GetController(); |
+ return controller && !controller->IsHiding(); |
+} |
+ |
+bool GeneratedCreditCardDecoration::OnMousePressed(NSRect frame) { |
+ autofill::GeneratedCreditCardBubbleController* controller = GetController(); |
Scott Hess - ex-Googler
2013/10/31 20:23:19
Alignment.
groby-ooo-7-16
2013/10/31 22:55:47
Done.
|
+ if (controller) { |
+ controller->OnAnchorClicked(); |
+ return true; |
+ } |
+ return false; |
Scott Hess - ex-Googler
2013/10/31 20:23:19
if (!controller)
return false;
groby-ooo-7-16
2013/10/31 22:55:47
Done.
|
+} |
+ |
+autofill::GeneratedCreditCardBubbleController* GeneratedCreditCardDecoration:: |
+ GetController() const { |
+ using autofill::GeneratedCreditCardBubbleController; |
Scott Hess - ex-Googler
2013/10/31 20:23:19
Maybe pull out to file scope so that other fns can
groby-ooo-7-16
2013/10/31 22:55:47
It is. I thought we were function level only, but
|
+ |
+ content::WebContents* wc = owner_->GetWebContents(); |
+ if (!wc || owner_->GetToolbarModel()->input_in_progress()) { |
+ return NULL; |
+ } |
+ |
+ // TODO(groby): Temporary hack to enforce visibility and controller existence. |
+ // This highlights the point that some icons probably have a per-WebContent |
+ // state and thus need a per-WebContent controller, which is best lazily |
+ // initialized. |
+ GeneratedCreditCardBubbleController* controller = |
+ GeneratedCreditCardBubbleController::FromWebContents(wc); |
+ |
+ if (!controller) { |
+ autofill::GeneratedCreditCardBubbleController::Show( |
+ wc, base::UTF8ToUTF16("foo"), base::UTF8ToUTF16("bar")); |
Scott Hess - ex-Googler
2013/10/31 20:23:19
Is the TODO actually about this line?
groby-ooo-7-16
2013/10/31 22:55:47
Yes. And they both can die - this code was for tes
|
+ controller = GeneratedCreditCardBubbleController::FromWebContents(wc); |
+ } |
+ DCHECK(controller); |
+ |
+ return autofill::GeneratedCreditCardBubbleController::FromWebContents(wc); |
Scott Hess - ex-Googler
2013/10/31 20:23:19
Is this different from controller?
groby-ooo-7-16
2013/10/31 22:55:47
Nope. Done.
|
+} |
+ |