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

Side by Side Diff: chrome/browser/ui/views/autofill/autofill_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: merge 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/autofill_credit_card_bubble_views.h"
6
7 #include "chrome/browser/ui/autofill/autofill_credit_card_bubble_controller.h"
8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/browser_finder.h"
10 #include "chrome/browser/ui/views/frame/browser_view.h"
11 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
12 #include "ui/gfx/font.h"
13 #include "ui/gfx/insets.h"
14 #include "ui/gfx/size.h"
15 #include "ui/views/bubble/bubble_frame_view.h"
16 #include "ui/views/controls/link.h"
17 #include "ui/views/controls/styled_label.h"
18 #include "ui/views/layout/box_layout.h"
19 #include "ui/views/layout/layout_constants.h"
20 #include "ui/views/view.h"
21 #include "ui/views/widget/widget.h"
22
23 namespace autofill {
24
25 namespace {
26
27 // Get the view this bubble will be anchored to via |controller|.
28 views::View* GetAnchor(
29 const base::WeakPtr<AutofillCreditCardBubbleController>& controller) {
30 Browser* browser =
31 chrome::FindBrowserWithWebContents(controller->web_contents());
32 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser);
33 return browser_view->GetLocationBarView()->autofill_credit_card_view();
34 }
35
36 } // namespace
37
38 AutofillCreditCardBubbleViews::~AutofillCreditCardBubbleViews() {}
39
40 void AutofillCreditCardBubbleViews::Show() {
41 // TODO(dbeam): investigate why this steals focus from the web contents.
42 views::BubbleDelegateView::CreateBubble(this);
43
44 GetWidget()->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 AutofillCreditCardBubbleViews::Hide() {
52 GetWidget()->Close();
53 }
54
55 bool AutofillCreditCardBubbleViews::IsHiding() const {
56 return GetWidget() && GetWidget()->IsClosed();
57 }
58
59 string16 AutofillCreditCardBubbleViews::GetWindowTitle() const {
60 return controller_->BubbleTitle();
61 }
62
63 void AutofillCreditCardBubbleViews::Init() {
64 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0,
65 views::kRelatedControlVerticalSpacing));
66
67 views::StyledLabel::RangeStyleInfo bold;
68 bold.font_style = gfx::Font::BOLD;
69 const std::vector<ui::Range>& ranges = controller_->BubbleTextRanges();
70
71 views::StyledLabel* contents =
72 new views::StyledLabel(controller_->BubbleText(), NULL);
73 for (size_t i = 0; i < ranges.size(); ++i) {
74 contents->AddStyleRange(ranges[i], bold);
75 }
76 AddChildView(contents);
77
78 views::Link* link = new views::Link();
79 link->SetHorizontalAlignment(gfx::ALIGN_LEFT);
80 link->SetText(controller_->LinkText());
81 link->set_listener(this);
82 AddChildView(link);
83 }
84
85 gfx::Size AutofillCreditCardBubbleViews::GetPreferredSize() {
86 return gfx::Size(
87 AutofillCreditCardBubbleViews::kContentWidth,
88 GetHeightForWidth(AutofillCreditCardBubble::kContentWidth));
89 }
90
91 void AutofillCreditCardBubbleViews::LinkClicked(views::Link* source,
92 int event_flags) {
93 if (controller_)
94 controller_->OnLinkClicked();
95 }
96
97 // static
98 base::WeakPtr<AutofillCreditCardBubble> AutofillCreditCardBubble::Create(
99 const base::WeakPtr<AutofillCreditCardBubbleController>& controller) {
100 AutofillCreditCardBubbleViews* bubble =
101 new AutofillCreditCardBubbleViews(controller);
102 return bubble->weak_ptr_factory_.GetWeakPtr();
103 }
104
105 AutofillCreditCardBubbleViews::AutofillCreditCardBubbleViews(
106 const base::WeakPtr<AutofillCreditCardBubbleController>& controller)
107 : BubbleDelegateView(GetAnchor(controller), views::BubbleBorder::TOP_RIGHT),
108 controller_(controller),
109 weak_ptr_factory_(this) {
110 // Match bookmarks bubble view's anchor view insets and margins.
111 set_anchor_view_insets(gfx::Insets(7, 0, 7, 0));
112 set_margins(gfx::Insets(0, 19, 18, 18));
113 set_move_with_anchor(true);
114 }
115
116 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698