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