Index: ui/views/bubble/bubble_frame_view.cc |
diff --git a/ui/views/bubble/bubble_frame_view.cc b/ui/views/bubble/bubble_frame_view.cc |
index 2dd002e5a7192c4fa1d47b4089a66f845eb4c08c..7d7bfd60acda22ddcd12f91efeab2183ae6ca1e7 100644 |
--- a/ui/views/bubble/bubble_frame_view.cc |
+++ b/ui/views/bubble/bubble_frame_view.cc |
@@ -29,6 +29,7 @@ |
#include "ui/views/controls/button/image_button_factory.h" |
#include "ui/views/controls/image_view.h" |
#include "ui/views/controls/label.h" |
+#include "ui/views/controls/styled_label.h" |
#include "ui/views/layout/box_layout.h" |
#include "ui/views/layout/layout_provider.h" |
#include "ui/views/resources/grit/views_resources.h" |
@@ -80,6 +81,8 @@ BubbleFrameView::BubbleFrameView(const gfx::Insets& title_margins, |
: bubble_border_(nullptr), |
title_margins_(title_margins), |
content_margins_(content_margins), |
+ title_font_list_(views::style::GetFont(style::CONTEXT_DIALOG_TITLE, |
+ views::style::STYLE_PRIMARY)), |
title_icon_(new views::ImageView()), |
title_(nullptr), |
close_(nullptr), |
@@ -87,13 +90,6 @@ BubbleFrameView::BubbleFrameView(const gfx::Insets& title_margins, |
close_button_clicked_(false) { |
AddChildView(title_icon_); |
- title_ = new Label(base::string16(), style::CONTEXT_DIALOG_TITLE); |
- title_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
- title_->set_collapse_when_hidden(true); |
- title_->SetVisible(false); |
- title_->SetMultiLine(true); |
- AddChildView(title_); |
- |
close_ = CreateCloseButton(this); |
close_->SetVisible(false); |
#if defined(OS_WIN) |
@@ -174,7 +170,7 @@ int BubbleFrameView::NonClientHitTest(const gfx::Point& point) { |
sys_rect.set_origin(gfx::Point(GetMirroredXForRect(sys_rect), 0)); |
if (sys_rect.Contains(point)) |
return HTSYSMENU; |
- if (point.y() < title_->bounds().bottom()) |
+ if (title_ && point.y() < title_->bounds().bottom()) |
return HTCAPTION; |
} |
@@ -233,14 +229,33 @@ void BubbleFrameView::UpdateWindowIcon() { |
} |
void BubbleFrameView::UpdateWindowTitle() { |
- title_->SetText(GetWidget()->widget_delegate()->GetWindowTitle()); |
- title_->SetVisible(GetWidget()->widget_delegate()->ShouldShowWindowTitle()); |
+ if (title_) { |
+ RemoveChildView(title_); |
+ delete title_; |
+ title_ = nullptr; |
+ } |
+ if (!GetWidget()->widget_delegate()->ShouldShowWindowTitle()) |
+ return; |
Peter Kasting
2017/06/07 02:40:43
Why decide not to add the title at all, rather tha
Bret
2017/06/07 20:15:41
The decision as to whether to use CreateTitleView
|
+ |
+ DialogDelegate* delegate = GetWidget()->widget_delegate()->AsDialogDelegate(); |
+ if (delegate) |
+ title_ = delegate->CreateTitleView(); |
+ if (!title_) { |
+ // No title from delegate, so use default. |
+ title_ = new StyledLabel(GetWidget()->widget_delegate()->GetWindowTitle(), |
+ nullptr); |
+ } |
+ title_->SetBaseFontList(title_font_list_); |
+ title_->SetVisible(true); |
+ AddChildView(title_); |
} |
void BubbleFrameView::SizeConstraintsChanged() {} |
void BubbleFrameView::SetTitleFontList(const gfx::FontList& font_list) { |
- title_->SetFontList(font_list); |
+ title_font_list_ = font_list; |
+ if (title_) |
+ title_->SetBaseFontList(title_font_list_); |
} |
const char* BubbleFrameView::GetClassName() const { |
@@ -251,7 +266,7 @@ gfx::Insets BubbleFrameView::GetInsets() const { |
gfx::Insets insets = content_margins_; |
const int icon_height = title_icon_->GetPreferredSize().height(); |
- const int label_height = title_->GetPreferredSize().height(); |
+ const int label_height = title_ ? title_->GetPreferredSize().height() : 0; |
const bool has_title = icon_height > 0 || label_height > 0; |
const int title_padding = has_title ? title_margins_.height() : 0; |
const int title_height = std::max(icon_height, label_height) + title_padding; |
@@ -304,7 +319,7 @@ gfx::Size BubbleFrameView::GetMaximumSize() const { |
void BubbleFrameView::Layout() { |
// The title margins may not be set, but make sure that's only the case when |
// there's no title. |
- DCHECK(!title_margins_.IsEmpty() || !title_->visible()); |
+ DCHECK(!title_margins_.IsEmpty() || !title_); |
const gfx::Rect contents_bounds = GetContentsBounds(); |
gfx::Rect bounds = contents_bounds; |
@@ -323,7 +338,7 @@ void BubbleFrameView::Layout() { |
int padding = 0; |
int title_height = title_icon_pref_size.height(); |
- if (title_->visible() && !title_->text().empty()) { |
+ if (title_ && !title_->text().empty()) { |
if (title_icon_pref_size.width() > 0) |
padding = title_margins_.left(); |
@@ -337,7 +352,8 @@ void BubbleFrameView::Layout() { |
title_icon_->SetBounds(bounds.x(), bounds.y(), title_icon_pref_size.width(), |
title_height); |
- bounds.set_width(title_->bounds().right() - bounds.x()); |
+ const int title_right = title_ ? title_->bounds().right() : 0; |
+ bounds.set_width(title_right - bounds.x()); |
bounds.set_height(title_height); |
if (footnote_container_) { |
@@ -529,7 +545,8 @@ gfx::Size BubbleFrameView::GetSizeForClientSize( |
// Accommodate the width of the title bar elements. |
int title_bar_width = title_margins_.width() + border()->GetInsets().width(); |
gfx::Size title_icon_size = title_icon_->GetPreferredSize(); |
- gfx::Size title_label_size = title_->GetPreferredSize(); |
+ gfx::Size title_label_size = |
+ title_ ? title_->GetPreferredSize() : gfx::Size(); |
if (title_icon_size.width() > 0 && title_label_size.width() > 0) |
title_bar_width += title_margins_.left(); |
title_bar_width += title_icon_size.width(); |