Index: chrome/browser/ui/views/autofill/autofill_credit_card_bubble_views.cc |
diff --git a/chrome/browser/ui/views/autofill/autofill_credit_card_bubble_views.cc b/chrome/browser/ui/views/autofill/autofill_credit_card_bubble_views.cc |
index fb2f2388085eae5a57c3167d40080381485a96a0..0cc51fb64f87567be141b35b8b8158dcec65b8ee 100644 |
--- a/chrome/browser/ui/views/autofill/autofill_credit_card_bubble_views.cc |
+++ b/chrome/browser/ui/views/autofill/autofill_credit_card_bubble_views.cc |
@@ -9,10 +9,12 @@ |
#include "chrome/browser/ui/browser_finder.h" |
#include "chrome/browser/ui/views/frame/browser_view.h" |
#include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
+#include "chrome/browser/ui/views/toolbar_view.h" |
#include "ui/gfx/font.h" |
#include "ui/gfx/insets.h" |
#include "ui/gfx/size.h" |
#include "ui/views/bubble/bubble_frame_view.h" |
+#include "ui/views/controls/image_view.h" |
#include "ui/views/controls/link.h" |
#include "ui/views/controls/styled_label.h" |
#include "ui/views/layout/box_layout.h" |
@@ -22,12 +24,27 @@ |
namespace autofill { |
-AutofillCreditCardBubbleViews::~AutofillCreditCardBubbleViews() {} |
+namespace { |
+ |
+views::View* GetAnchor( |
+ const base::WeakPtr<AutofillCreditCardBubbleController>& controller) { |
+ BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser( |
+ chrome::FindBrowserWithWebContents(controller->web_contents())); |
+ return controller->AnchorToSettingsMenu() ? |
+ browser_view->GetToolbarView()->app_menu() : |
+ browser_view->GetLocationBarView()->autofill_credit_card_view(); |
+} |
+ |
+} // namespace |
+ |
+AutofillCreditCardBubbleViews::~AutofillCreditCardBubbleViews() { |
+ if (controller_) |
+ controller_->OnBubbleDestroyed(); |
+} |
void AutofillCreditCardBubbleViews::Show() { |
// TODO(dbeam): investigate why this steals focus from the web contents. |
views::BubbleDelegateView::CreateBubble(this); |
- |
GetWidget()->Show(); |
SizeToContents(); |
} |
@@ -40,30 +57,63 @@ bool AutofillCreditCardBubbleViews::IsHiding() const { |
return GetWidget() && GetWidget()->IsClosed(); |
} |
-string16 AutofillCreditCardBubbleViews::GetWindowTitle() const { |
- return controller_->BubbleTitle(); |
+base::string16 AutofillCreditCardBubbleViews::GetWindowTitle() const { |
+ return controller_->TitleText(); |
} |
void AutofillCreditCardBubbleViews::Init() { |
SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, |
views::kRelatedControlVerticalSpacing)); |
- views::StyledLabel::RangeStyleInfo bold; |
- bold.font_style = gfx::Font::BOLD; |
- const std::vector<ui::Range>& ranges = controller_->BubbleTextRanges(); |
+ const base::string16& header_text = controller_->HeaderText(); |
+ if (!header_text.empty()) { |
+ views::StyledLabel* header = new views::StyledLabel(header_text, this); |
+ const std::vector<TextRange>& text_ranges = controller_->HeaderTextRanges(); |
+ for (size_t i = 0; i < text_ranges.size(); ++i) { |
+ views::StyledLabel::RangeStyleInfo range_style; |
+ if (text_ranges[i].is_link) |
+ range_style = views::StyledLabel::RangeStyleInfo::CreateForLink(); |
+ else |
+ range_style.font_style = gfx::Font::BOLD; |
+ header->AddStyleRange(text_ranges[i].range, range_style); |
+ } |
+ AddChildView(header); |
+ } |
+ |
+ const CreditCardDescription* card_desc = controller_->Description(); |
+ if (card_desc) { |
+ views::View* card_container = new views::View(); |
+ card_container->SetLayoutManager( |
+ new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 10)); |
- views::StyledLabel* contents = |
- new views::StyledLabel(controller_->BubbleText(), NULL); |
- for (size_t i = 0; i < ranges.size(); ++i) { |
- contents->AddStyleRange(ranges[i], bold); |
+ views::View* title_row = new views::View(); |
Evan Stade
2013/08/02 16:29:45
not really a title... the title is blank. Calling
Dan Beam
2013/08/06 02:41:35
Done.
|
+ title_row->SetLayoutManager( |
+ new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 10)); |
+ |
+ views::ImageView* card_icon = new views::ImageView(); |
+ card_icon->SetImage(card_desc->icon.AsImageSkia()); |
+ title_row->AddChildView(card_icon); |
+ |
+ views::Label* title = new views::Label(card_desc->title); |
Evan Stade
2013/08/02 16:29:45
ditto on CardDescription::title
Dan Beam
2013/08/06 02:41:35
Done.
|
+ title->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
+ title_row->AddChildView(title); |
+ card_container->AddChildView(title_row); |
+ |
+ views::Label* desc = new views::Label(card_desc->description); |
+ desc->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
+ desc->SetMultiLine(true); |
+ card_container->AddChildView(desc); |
+ |
+ AddChildView(card_container); |
} |
- AddChildView(contents); |
- views::Link* link = new views::Link(); |
- link->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
- link->SetText(controller_->LinkText()); |
- link->set_listener(this); |
- AddChildView(link); |
+ const base::string16& link_text = controller_->LinkText(); |
+ if (!link_text.empty()) { |
+ views::Link* link = new views::Link(link_text); |
+ link->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
+ link->set_listener(this); |
+ AddChildView(link); |
+ } |
} |
gfx::Size AutofillCreditCardBubbleViews::GetPreferredSize() { |
@@ -78,6 +128,12 @@ void AutofillCreditCardBubbleViews::LinkClicked(views::Link* source, |
controller_->OnLinkClicked(); |
} |
+void AutofillCreditCardBubbleViews::StyledLabelLinkClicked(const ui::Range& r, |
+ int event_flags) { |
+ if (controller_) |
+ controller_->OnLinkClicked(); |
+} |
+ |
// static |
base::WeakPtr<AutofillCreditCardBubble> AutofillCreditCardBubble::Create( |
const base::WeakPtr<AutofillCreditCardBubbleController>& controller) { |
@@ -88,16 +144,12 @@ base::WeakPtr<AutofillCreditCardBubble> AutofillCreditCardBubble::Create( |
AutofillCreditCardBubbleViews::AutofillCreditCardBubbleViews( |
const base::WeakPtr<AutofillCreditCardBubbleController>& controller) |
- : BubbleDelegateView(BrowserView::GetBrowserViewForBrowser( |
- chrome::FindBrowserWithWebContents(controller->web_contents()))-> |
- GetLocationBarView()->autofill_credit_card_view(), |
- views::BubbleBorder::TOP_RIGHT), |
+ : BubbleDelegateView(GetAnchor(controller), views::BubbleBorder::TOP_RIGHT), |
controller_(controller), |
weak_ptr_factory_(this) { |
- // Match bookmarks bubble view's anchor view insets and margins. |
- set_anchor_view_insets(gfx::Insets(7, 0, 7, 0)); |
- set_margins(gfx::Insets(0, 19, 18, 18)); |
- set_move_with_anchor(true); |
+ // Match bookmarks bubble view's margins. |
+ bool title_empty = controller_->TitleText().empty(); |
Evan Stade
2013/08/02 16:29:45
yea, controller_->TitleText() vs. controller_->Des
Dan Beam
2013/08/06 02:41:35
Done.
|
+ set_margins(gfx::Insets(title_empty ? 18 : 0, 19, 18, 18)); |
} |
} // namespace autofill |