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/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 AutofillCreditCardBubbleViews::~AutofillCreditCardBubbleViews() {} | |
26 | |
27 void AutofillCreditCardBubbleViews::Show() { | |
28 // TODO(dbeam): investigate why this steals focus from the web contents. | |
29 views::BubbleDelegateView::CreateBubble(this); | |
30 | |
31 GetWidget()->Show(); | |
32 SizeToContents(); | |
33 } | |
34 | |
35 void AutofillCreditCardBubbleViews::Hide() { | |
36 GetWidget()->Close(); | |
37 } | |
38 | |
39 bool AutofillCreditCardBubbleViews::IsHiding() const { | |
40 return GetWidget() && GetWidget()->IsClosed(); | |
41 } | |
42 | |
43 string16 AutofillCreditCardBubbleViews::GetWindowTitle() const { | |
44 return controller_->BubbleTitle(); | |
45 } | |
46 | |
47 void AutofillCreditCardBubbleViews::Init() { | |
48 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, | |
49 views::kRelatedControlVerticalSpacing)); | |
50 | |
51 views::StyledLabel::RangeStyleInfo bold; | |
52 bold.font_style = gfx::Font::BOLD; | |
53 const std::vector<ui::Range>& ranges = controller_->BubbleTextRanges(); | |
54 | |
55 views::StyledLabel* contents = | |
56 new views::StyledLabel(controller_->BubbleText(), NULL); | |
57 for (size_t i = 0; i < ranges.size(); ++i) { | |
58 contents->AddStyleRange(ranges[i], bold); | |
59 } | |
60 AddChildView(contents); | |
61 | |
62 views::Link* link = new views::Link(); | |
63 link->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
64 link->SetText(controller_->LinkText()); | |
65 link->set_listener(this); | |
66 AddChildView(link); | |
67 } | |
68 | |
69 gfx::Size AutofillCreditCardBubbleViews::GetPreferredSize() { | |
70 return gfx::Size( | |
71 AutofillCreditCardBubbleViews::kContentWidth, | |
72 GetHeightForWidth(AutofillCreditCardBubble::kContentWidth)); | |
73 } | |
74 | |
75 void AutofillCreditCardBubbleViews::LinkClicked(views::Link* source, | |
76 int event_flags) { | |
77 if (controller_) | |
78 controller_->OnLinkClicked(); | |
79 } | |
80 | |
81 // static | |
82 base::WeakPtr<AutofillCreditCardBubble> AutofillCreditCardBubble::Create( | |
83 const base::WeakPtr<AutofillCreditCardBubbleController>& controller) { | |
84 AutofillCreditCardBubbleViews* bubble = | |
85 new AutofillCreditCardBubbleViews(controller); | |
86 return bubble->weak_ptr_factory_.GetWeakPtr(); | |
87 } | |
88 | |
89 AutofillCreditCardBubbleViews::AutofillCreditCardBubbleViews( | |
90 const base::WeakPtr<AutofillCreditCardBubbleController>& controller) | |
91 : BubbleDelegateView(BrowserView::GetBrowserViewForBrowser( | |
92 chrome::FindBrowserWithWebContents(controller->web_contents()))-> | |
93 GetLocationBarView()->autofill_credit_card_view(), | |
94 views::BubbleBorder::TOP_RIGHT), | |
95 controller_(controller), | |
96 weak_ptr_factory_(this) { | |
97 // Match bookmarks bubble view's anchor view insets and margins. | |
98 set_anchor_view_insets(gfx::Insets(7, 0, 7, 0)); | |
99 set_margins(gfx::Insets(0, 19, 18, 18)); | |
100 set_move_with_anchor(true); | |
101 } | |
102 | |
103 } // namespace autofill | |
OLD | NEW |