OLD | NEW |
---|---|
(Empty) | |
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/views/autofill/new_credit_card_bubble_views.h" | |
6 | |
7 #include "chrome/browser/ui/autofill/new_credit_card_bubble_controller.h" | |
8 #include "chrome/browser/ui/browser_finder.h" | |
9 #include "chrome/browser/ui/host_desktop.h" | |
10 #include "chrome/browser/ui/views/frame/browser_view.h" | |
11 #include "chrome/browser/ui/views/toolbar_view.h" | |
12 #include "ui/gfx/insets.h" | |
13 #include "ui/gfx/size.h" | |
14 #include "ui/views/bubble/bubble_frame_view.h" | |
15 #include "ui/views/controls/image_view.h" | |
16 #include "ui/views/controls/link.h" | |
17 #include "ui/views/layout/box_layout.h" | |
18 #include "ui/views/layout/layout_constants.h" | |
19 #include "ui/views/view.h" | |
20 #include "ui/views/widget/widget.h" | |
21 | |
22 namespace autofill { | |
23 | |
24 namespace { | |
25 | |
26 views::View* GetAnchor( | |
27 const base::WeakPtr<NewCreditCardBubbleController>& controller) { | |
28 Browser* browser = chrome::FindTabbedBrowser(controller->profile(), false, | |
29 chrome::GetActiveDesktop()); | |
Evan Stade
2013/08/06 22:06:25
I feel that |browser| should be sorted out based o
Dan Beam
2013/08/07 02:30:22
popups don't have a wrench menu, which is why I us
Evan Stade
2013/08/07 23:31:21
that doesn't seem right to me, we should still sho
Dan Beam
2013/08/08 05:23:48
asked jstark@ on the bug
| |
30 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); | |
31 return browser_view->GetToolbarView()->app_menu(); | |
32 } | |
33 | |
34 } // namespace | |
35 | |
36 NewCreditCardBubbleViews::~NewCreditCardBubbleViews() { | |
37 if (controller_) | |
38 controller_->OnBubbleDestroyed(); | |
39 } | |
40 | |
41 void NewCreditCardBubbleViews::Show() { | |
42 // TODO(dbeam): investigate why this steals focus from the web contents. | |
43 views::BubbleDelegateView::CreateBubble(this); | |
44 GetWidget()->Show(); | |
45 SizeToContents(); | |
46 } | |
47 | |
48 void NewCreditCardBubbleViews::Hide() { | |
49 GetWidget()->Close(); | |
50 } | |
51 | |
52 void NewCreditCardBubbleViews::Init() { | |
53 SetLayoutManager( | |
54 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, | |
55 views::kUnrelatedControlVerticalSpacing)); | |
56 | |
57 views::Label* contents = new views::Label(controller_->ContentsText()); | |
58 contents->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
59 contents->SetMultiLine(true); | |
60 AddChildView(contents); | |
61 | |
62 views::View* card_container = new views::View(); | |
63 card_container->SetLayoutManager( | |
64 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 10)); | |
65 | |
66 views::View* card_desc_view = new views::View(); | |
67 card_desc_view->SetLayoutManager( | |
68 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 10)); | |
69 | |
70 views::ImageView* card_icon = new views::ImageView(); | |
71 const CreditCardDescription& card_desc = controller_->CardDescription(); | |
72 card_icon->SetImage(card_desc.icon.AsImageSkia()); | |
73 card_desc_view->AddChildView(card_icon); | |
74 | |
75 views::Label* card_name = new views::Label(card_desc.name); | |
76 card_name->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
77 card_desc_view->AddChildView(card_name); | |
78 card_container->AddChildView(card_desc_view); | |
79 | |
80 views::Label* desc = new views::Label(card_desc.description); | |
81 desc->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
82 desc->SetMultiLine(true); | |
83 card_container->AddChildView(desc); | |
84 | |
85 AddChildView(card_container); | |
86 | |
87 views::Link* link = new views::Link(controller_->LinkText()); | |
88 link->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
89 link->set_listener(this); | |
90 AddChildView(link); | |
91 } | |
92 | |
93 gfx::Size NewCreditCardBubbleViews::GetPreferredSize() { | |
94 return gfx::Size( | |
95 NewCreditCardBubbleViews::kContentWidth, | |
96 GetHeightForWidth(NewCreditCardBubble::kContentWidth)); | |
97 } | |
98 | |
99 void NewCreditCardBubbleViews::LinkClicked(views::Link* source, | |
100 int event_flags) { | |
101 if (controller_) | |
102 controller_->OnLinkClicked(); | |
103 } | |
104 | |
105 // static | |
106 base::WeakPtr<NewCreditCardBubble> NewCreditCardBubble::Create( | |
107 const base::WeakPtr<NewCreditCardBubbleController>& controller) { | |
108 NewCreditCardBubbleViews* bubble = | |
109 new NewCreditCardBubbleViews(controller); | |
110 return bubble->weak_ptr_factory_.GetWeakPtr(); | |
111 } | |
112 | |
113 NewCreditCardBubbleViews::NewCreditCardBubbleViews( | |
114 const base::WeakPtr<NewCreditCardBubbleController>& controller) | |
115 : BubbleDelegateView(GetAnchor(controller), views::BubbleBorder::TOP_RIGHT), | |
116 controller_(controller), | |
117 weak_ptr_factory_(this) { | |
118 // Match bookmarks bubble view's margins. | |
119 set_margins(gfx::Insets(18, 19, 18, 18)); | |
Evan Stade
2013/08/06 22:06:25
heinous. Perhaps you can create these insets via a
Dan Beam
2013/08/07 02:30:22
check what I did, see if you like
| |
120 } | |
121 | |
122 } // namespace autofill | |
OLD | NEW |