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

Side by Side Diff: chrome/browser/ui/views/autofill/new_credit_card_bubble_views.cc

Issue 21668003: Implement newly saved card bubble for realz and update generated card bubble to (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 4 months 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
(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 // Get the view this bubble will be anchored to via |controller|.
27 views::View* GetAnchor(
28 const base::WeakPtr<NewCreditCardBubbleController>& controller) {
29 Browser* browser = chrome::FindTabbedBrowser(controller->profile(), false,
30 chrome::GetActiveDesktop());
31 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser);
32 return browser_view->GetToolbarView()->app_menu();
33 }
34
35 } // namespace
36
37 NewCreditCardBubbleViews::~NewCreditCardBubbleViews() {
38 if (controller_)
39 controller_->OnBubbleDestroyed();
40 }
41
42 void NewCreditCardBubbleViews::Show() {
43 // TODO(dbeam): investigate why this steals focus from the web contents.
44 views::BubbleDelegateView::CreateBubble(this)->Show();
45
46 // This bubble doesn't render correctly on Windows without calling
47 // |SizeToContents()|. This must be called after showing the widget.
48 SizeToContents();
49 }
50
51 void NewCreditCardBubbleViews::Hide() {
52 GetWidget()->Close();
53 }
54
55 gfx::Size NewCreditCardBubbleViews::GetPreferredSize() {
56 return GetPreferredSizeForTitle();
57 }
58
59 void NewCreditCardBubbleViews::Init() {
60 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0,
61 views::kRelatedControlVerticalSpacing));
62
63 views::View* card_container = new views::View();
64 card_container->SetLayoutManager(
65 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 10));
66
67 views::View* card_desc_view = new views::View();
68 card_desc_view->SetLayoutManager(
69 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 10));
70
71 views::ImageView* card_icon = new views::ImageView();
72 const CreditCardDescription& card_desc = controller_->CardDescription();
73 card_icon->SetImage(card_desc.icon.AsImageSkia());
74 card_desc_view->AddChildView(card_icon);
75
76 views::Label* card_name = new views::Label(card_desc.name);
77 card_name->SetHorizontalAlignment(gfx::ALIGN_LEFT);
78 card_desc_view->AddChildView(card_name);
79 card_container->AddChildView(card_desc_view);
80
81 views::Label* desc = new views::Label(card_desc.description);
82 desc->SetHorizontalAlignment(gfx::ALIGN_LEFT);
83 desc->SetMultiLine(true);
84 card_container->AddChildView(desc);
85
86 AddChildView(card_container);
87
88 views::Link* link = new views::Link(controller_->LinkText());
89 link->SetHorizontalAlignment(gfx::ALIGN_LEFT);
90 link->set_listener(this);
91 AddChildView(link);
92 }
93
94 base::string16 NewCreditCardBubbleViews::GetWindowTitle() const {
95 return controller_->TitleText();
96 }
97
98 void NewCreditCardBubbleViews::LinkClicked(views::Link* source,
99 int event_flags) {
100 if (controller_)
101 controller_->OnLinkClicked();
102 }
103
104 // static
105 base::WeakPtr<NewCreditCardBubble> NewCreditCardBubble::Create(
106 const base::WeakPtr<NewCreditCardBubbleController>& controller) {
107 NewCreditCardBubbleViews* bubble =
108 new NewCreditCardBubbleViews(controller);
109 return bubble->weak_ptr_factory_.GetWeakPtr();
110 }
111
112 NewCreditCardBubbleViews::NewCreditCardBubbleViews(
113 const base::WeakPtr<NewCreditCardBubbleController>& controller)
114 : BubbleDelegateView(GetAnchor(controller), views::BubbleBorder::TOP_RIGHT),
115 controller_(controller),
116 weak_ptr_factory_(this) {
117 set_margins(views::BubbleFrameView::GetTitleInsets());
118 }
119
120 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698