| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/views/bubble/bubble_frame_view.h" | 5 #include "ui/views/bubble/bubble_frame_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 AddChildView(title_); | 92 AddChildView(title_); |
| 93 | 93 |
| 94 close_ = CreateCloseButton(this); | 94 close_ = CreateCloseButton(this); |
| 95 close_->SetVisible(false); | 95 close_->SetVisible(false); |
| 96 AddChildView(close_); | 96 AddChildView(close_); |
| 97 } | 97 } |
| 98 | 98 |
| 99 BubbleFrameView::~BubbleFrameView() {} | 99 BubbleFrameView::~BubbleFrameView() {} |
| 100 | 100 |
| 101 // static | 101 // static |
| 102 ImageButton* BubbleFrameView::CreateCloseButton(ButtonListener* listener) { | 102 LabelButton* BubbleFrameView::CreateCloseButton(ButtonListener* listener) { |
| 103 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 103 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 104 ImageButton* close = new ImageButton(listener); | 104 LabelButton* close = new LabelButton(listener, base::string16()); |
| 105 close->SetImage(CustomButton::STATE_NORMAL, | 105 close->SetImage(CustomButton::STATE_NORMAL, |
| 106 rb.GetImageNamed(IDR_CLOSE_DIALOG).ToImageSkia()); | 106 *rb.GetImageNamed(IDR_CLOSE_DIALOG).ToImageSkia()); |
| 107 close->SetImage(CustomButton::STATE_HOVERED, | 107 close->SetImage(CustomButton::STATE_HOVERED, |
| 108 rb.GetImageNamed(IDR_CLOSE_DIALOG_H).ToImageSkia()); | 108 *rb.GetImageNamed(IDR_CLOSE_DIALOG_H).ToImageSkia()); |
| 109 close->SetImage(CustomButton::STATE_PRESSED, | 109 close->SetImage(CustomButton::STATE_PRESSED, |
| 110 rb.GetImageNamed(IDR_CLOSE_DIALOG_P).ToImageSkia()); | 110 *rb.GetImageNamed(IDR_CLOSE_DIALOG_P).ToImageSkia()); |
| 111 close->SetBorder(nullptr); | 111 close->SetBorder(nullptr); |
| 112 close->SetSize(close->GetPreferredSize()); | 112 close->SetSize(close->GetPreferredSize()); |
| 113 #if !defined(OS_WIN) | 113 #if !defined(OS_WIN) |
| 114 // Windows will automatically create a tooltip for the close button based on | 114 // Windows will automatically create a tooltip for the close button based on |
| 115 // the HTCLOSE result from NonClientHitTest(). | 115 // the HTCLOSE result from NonClientHitTest(). |
| 116 close->SetTooltipText(l10n_util::GetStringUTF16(IDS_APP_CLOSE)); | 116 close->SetTooltipText(l10n_util::GetStringUTF16(IDS_APP_CLOSE)); |
| 117 #endif | 117 #endif |
| 118 return close; | 118 return close; |
| 119 } | 119 } |
| 120 | 120 |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 | 238 |
| 239 gfx::Insets BubbleFrameView::GetInsets() const { | 239 gfx::Insets BubbleFrameView::GetInsets() const { |
| 240 gfx::Insets insets = content_margins_; | 240 gfx::Insets insets = content_margins_; |
| 241 | 241 |
| 242 const int icon_height = title_icon_->GetPreferredSize().height(); | 242 const int icon_height = title_icon_->GetPreferredSize().height(); |
| 243 const int label_height = title_->GetPreferredSize().height(); | 243 const int label_height = title_->GetPreferredSize().height(); |
| 244 const bool has_title = icon_height > 0 || label_height > 0; | 244 const bool has_title = icon_height > 0 || label_height > 0; |
| 245 const int title_padding = has_title ? title_margins_.height() : 0; | 245 const int title_padding = has_title ? title_margins_.height() : 0; |
| 246 const int title_height = std::max(icon_height, label_height) + title_padding; | 246 const int title_height = std::max(icon_height, label_height) + title_padding; |
| 247 const int close_height = close_->visible() ? close_->height() : 0; | 247 const int close_height = close_->visible() ? close_->height() : 0; |
| 248 const int min_height = !has_title ? close_->height() : 0; | 248 insets += gfx::Insets(std::max(title_height, close_height), 0, 0, 0); |
| 249 insets += | |
| 250 gfx::Insets(std::max({title_height, close_height, min_height}), 0, 0, 0); | |
| 251 return insets; | 249 return insets; |
| 252 } | 250 } |
| 253 | 251 |
| 254 gfx::Size BubbleFrameView::GetPreferredSize() const { | 252 gfx::Size BubbleFrameView::GetPreferredSize() const { |
| 255 // Get the preferred size of the client area. | 253 // Get the preferred size of the client area. |
| 256 gfx::Size client_size = GetWidget()->client_view()->GetPreferredSize(); | 254 gfx::Size client_size = GetWidget()->client_view()->GetPreferredSize(); |
| 257 // Expand it to include the bubble border and space for the arrow. | 255 // Expand it to include the bubble border and space for the arrow. |
| 258 return GetWindowBoundsForClientBounds(gfx::Rect(client_size)).size(); | 256 return GetWindowBoundsForClientBounds(gfx::Rect(client_size)).size(); |
| 259 } | 257 } |
| 260 | 258 |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 size.Enlarge(client_insets.width(), client_insets.height()); | 512 size.Enlarge(client_insets.width(), client_insets.height()); |
| 515 size.SetToMax(gfx::Size(title_bar_width, 0)); | 513 size.SetToMax(gfx::Size(title_bar_width, 0)); |
| 516 | 514 |
| 517 if (footnote_container_) | 515 if (footnote_container_) |
| 518 size.Enlarge(0, footnote_container_->GetHeightForWidth(size.width())); | 516 size.Enlarge(0, footnote_container_->GetHeightForWidth(size.width())); |
| 519 | 517 |
| 520 return size; | 518 return size; |
| 521 } | 519 } |
| 522 | 520 |
| 523 } // namespace views | 521 } // namespace views |
| OLD | NEW |