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

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/controls/image_view.h"
15 #include "ui/views/controls/link.h"
16 #include "ui/views/layout/box_layout.h"
17 #include "ui/views/layout/layout_constants.h"
18 #include "ui/views/view.h"
19 #include "ui/views/widget/widget.h"
20
21 namespace autofill {
22
23 namespace {
24
25 // Get the view this bubble will be anchored to via |controller|.
26 views::View* GetAnchor(
27 const base::WeakPtr<NewCreditCardBubbleController>& controller) {
28 Browser* browser = chrome::FindTabbedBrowser(controller->profile(), false,
29 chrome::GetActiveDesktop());
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)->Show();
44
45 // This bubble doesn't render correctly on Windows without calling
46 // |SizeToContents()|. This must be called after showing the widget.
47 SizeToContents();
48 }
49
50 void NewCreditCardBubbleViews::Hide() {
51 GetWidget()->Close();
52 }
53
54 void NewCreditCardBubbleViews::Init() {
55 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0,
56 views::kRelatedControlVerticalSpacing));
57
58 views::View* card_container = new views::View();
59 card_container->SetLayoutManager(
60 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 10));
61
62 views::View* card_desc_view = new views::View();
63 card_desc_view->SetLayoutManager(
64 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 10));
65
66 views::ImageView* card_icon = new views::ImageView();
67 const CreditCardDescription& card_desc = controller_->CardDescription();
68 card_icon->SetImage(card_desc.icon.AsImageSkia());
69 card_desc_view->AddChildView(card_icon);
70
71 views::Label* card_name = new views::Label(card_desc.name);
72 card_name->SetHorizontalAlignment(gfx::ALIGN_LEFT);
73 card_desc_view->AddChildView(card_name);
74 card_container->AddChildView(card_desc_view);
75
76 views::Label* desc = new views::Label(card_desc.description);
77 desc->SetHorizontalAlignment(gfx::ALIGN_LEFT);
78 desc->SetMultiLine(true);
79 card_container->AddChildView(desc);
80
81 AddChildView(card_container);
82
83 views::Link* link = new views::Link(controller_->LinkText());
84 link->SetHorizontalAlignment(gfx::ALIGN_LEFT);
85 link->set_listener(this);
86 AddChildView(link);
87 }
88
89 base::string16 NewCreditCardBubbleViews::GetWindowTitle() const {
90 return controller_->TitleText();
91 }
92
93 void NewCreditCardBubbleViews::LinkClicked(views::Link* source,
94 int event_flags) {
95 if (controller_)
96 controller_->OnLinkClicked();
97 }
98
99 // static
100 base::WeakPtr<NewCreditCardBubble> NewCreditCardBubble::Create(
101 const base::WeakPtr<NewCreditCardBubbleController>& controller) {
102 NewCreditCardBubbleViews* bubble =
103 new NewCreditCardBubbleViews(controller);
104 return bubble->weak_ptr_factory_.GetWeakPtr();
105 }
106
107 NewCreditCardBubbleViews::NewCreditCardBubbleViews(
108 const base::WeakPtr<NewCreditCardBubbleController>& controller)
109 : BubbleDelegateView(GetAnchor(controller), views::BubbleBorder::TOP_RIGHT),
110 controller_(controller),
111 weak_ptr_factory_(this) {
112 set_match_title_margins(true);
113 }
114
115 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698