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

Side by Side Diff: chrome/browser/ui/views/autofill/generated_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/generated_credit_card_bubble_views.h"
6
7 #include "chrome/browser/ui/autofill/generated_credit_card_bubble_controller.h"
8 #include "chrome/browser/ui/browser_finder.h"
9 #include "chrome/browser/ui/views/frame/browser_view.h"
10 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
11 #include "ui/gfx/font.h"
12 #include "ui/gfx/insets.h"
13 #include "ui/gfx/size.h"
14 #include "ui/views/controls/styled_label.h"
15 #include "ui/views/layout/box_layout.h"
16 #include "ui/views/layout/layout_constants.h"
17 #include "ui/views/widget/widget.h"
18
19 namespace autofill {
20
21 namespace {
22
23 // Get the view this bubble will be anchored to via |controller|.
24 views::View* GetAnchor(
25 const base::WeakPtr<GeneratedCreditCardBubbleController>& controller) {
26 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(
27 chrome::FindBrowserWithWebContents(controller->web_contents()));
28 return browser_view->GetLocationBarView()->generated_credit_card_view();
29 }
30
31 } // namespace
32
33 GeneratedCreditCardBubbleViews::~GeneratedCreditCardBubbleViews() {}
34
35 void GeneratedCreditCardBubbleViews::Show() {
36 // TODO(dbeam): investigate why this steals focus from the web contents.
37 views::BubbleDelegateView::CreateBubble(this)->Show();
38
39 // This bubble doesn't render correctly on Windows without calling
40 // |SizeToContents()|. This must be called after showing the widget.
41 SizeToContents();
42 }
43
44 void GeneratedCreditCardBubbleViews::Hide() {
45 GetWidget()->Close();
46 }
47
48 bool GeneratedCreditCardBubbleViews::IsHiding() const {
49 return GetWidget() && GetWidget()->IsClosed();
50 }
51
52 base::string16 GeneratedCreditCardBubbleViews::GetWindowTitle() const {
53 return controller_->TitleText();
54 }
55
56 void GeneratedCreditCardBubbleViews::Init() {
57 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0,
58 views::kRelatedControlVerticalSpacing));
59
60 const base::string16& contents_text = controller_->ContentsText();
61 views::StyledLabel* contents = new views::StyledLabel(contents_text, this);
62
63 const std::vector<TextRange>& text_ranges = controller_->ContentsTextRanges();
64 for (size_t i = 0; i < text_ranges.size(); ++i) {
65 views::StyledLabel::RangeStyleInfo style;
66
67 if (text_ranges[i].is_link)
68 style = views::StyledLabel::RangeStyleInfo::CreateForLink();
69 else
70 style.font_style = gfx::Font::BOLD;
71
72 contents->AddStyleRange(text_ranges[i].range, style);
73 }
74
75 AddChildView(contents);
76 }
77
78 void GeneratedCreditCardBubbleViews::StyledLabelLinkClicked(const ui::Range& r,
79 int event_flags) {
80 if (controller_)
81 controller_->OnLinkClicked();
82 }
83
84 // static
85 base::WeakPtr<GeneratedCreditCardBubble> GeneratedCreditCardBubble::Create(
86 const base::WeakPtr<GeneratedCreditCardBubbleController>& controller) {
87 return (new GeneratedCreditCardBubbleViews(controller))->weak_ptr_factory_.
88 GetWeakPtr();
89 }
90
91 GeneratedCreditCardBubbleViews::GeneratedCreditCardBubbleViews(
92 const base::WeakPtr<GeneratedCreditCardBubbleController>& controller)
93 : BubbleDelegateView(GetAnchor(controller), views::BubbleBorder::TOP_RIGHT),
94 controller_(controller),
95 weak_ptr_factory_(this) {
96 set_match_title_margins(true);
97 }
98
99 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698